Salome HOME
MEDLoader bug fix. Detected by FLICA non regression tests.
[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(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
407 {
408   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
409 }
410
411 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *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(MEDFileFieldPerMeshPerType *father) const
434 {
435   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
436   ret->_father=father;
437   return ret.retn();
438 }
439
440 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *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(MEDFileFieldPerMeshPerType *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 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
531 {
532   return _father;
533 }
534
535 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
536 {
537   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
538   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
539   std::string fieldName(nasc.getName()),meshName(getMeshName());
540   int iteration(getIteration()),order(getOrder());
541   TypeOfField type(getType());
542   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
543   int profilesize,nbi;
544   med_geometry_type mgeoti;
545   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
546   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
547   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
548   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
549   const PartDefinition *pd(_pd);
550   if(!pd)
551     {
552       _nval=zeNVal;
553     }
554   else
555     {
556       if(!_profile.empty())
557         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
558       _nval=pd->getNumberOfElems();
559     }
560   _start=start;
561   _end=start+_nval*nbi;
562   start=_end;
563   if(type==ON_CELLS && !_localization.empty())
564     {
565       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
566         setType(ON_GAUSS_PT);
567       else
568         {
569           setType(ON_GAUSS_NE);
570           _localization.clear();
571         }
572     }
573 }
574
575 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
576 {
577   std::string fieldName(nasc.getName()),meshName(getMeshName());
578   int iteration(getIteration()),order(getOrder());
579   TypeOfField type(getType());
580   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
581   med_geometry_type mgeoti;
582   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
583   if(_start>_end)
584     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
585   if(_start==_end)
586     return ;
587   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
588   if(_start<0 || _start>=arr->getNumberOfTuples())
589     {
590       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
591       throw INTERP_KERNEL::Exception(oss.str());
592     }
593   if(_end<0 || _end>arr->getNumberOfTuples())
594     {
595       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
596       throw INTERP_KERNEL::Exception(oss.str());
597     }
598   int nbOfCompo(arr->getNumberOfComponents());
599   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
600   if(arrD)
601     {
602       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
603       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
604       return ;
605     }
606   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
607   if(arrI)
608     {
609       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
610       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
611       return ;
612     }
613   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
614 }
615
616 /*!
617  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
618  */
619 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
620 {
621   int delta=_end-_start;
622   _start=newValueOfStart;
623   _end=_start+delta;
624 }
625
626 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
627 {
628   return _father->getIteration();
629 }
630
631 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
632 {
633   return _father->getOrder();
634 }
635
636 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
637 {
638   return _father->getTime();
639 }
640
641 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
642 {
643   return _father->getMeshName();
644 }
645
646 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
647 {
648   const char startLine[]="    ## ";
649   std::string startLine2(bkOffset,' ');
650   startLine2+=startLine;
651   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
652   oss << startLine2 << "Localization #" << id << "." << std::endl;
653   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
654   delete tmp;
655   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
656   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
657   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
658 }
659
660 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
661 {
662   return _type;
663 }
664
665 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
666 {
667   types.insert(_type);
668 }
669
670 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
671 {
672   _type=newType;
673 }
674
675 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
676 {
677   return _father->getGeoType();
678 }
679
680 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
681 {
682   return _father->getNumberOfComponents();
683 }
684
685 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
686 {
687   return _end-_start;
688 }
689
690 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
691 {
692   return _father->getOrCreateAndGetArray();
693 }
694
695 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
696 {
697   const MEDFileFieldPerMeshPerType *fath=_father;
698   return fath->getOrCreateAndGetArray();
699 }
700
701 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
702 {
703   return _father->getInfo();
704 }
705
706 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
707 {
708   return _profile;
709 }
710
711 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
712 {
713   _profile=newPflName;
714 }
715
716 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
717 {
718   return _localization;
719 }
720
721 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
722 {
723   _localization=newLocName;
724 }
725
726 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
727 {
728   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
729     {
730       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
731         {
732           _profile=(*it2).second;
733           return;
734         }
735     }
736 }
737
738 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
739 {
740   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
741     {
742       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
743         {
744           _localization=(*it2).second;
745           return;
746         }
747     }
748 }
749
750 void MEDFileFieldPerMeshPerTypePerDisc::getFieldAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
751 {
752   if(type!=_type)
753     return ;
754   dads.push_back(std::pair<int,int>(_start,_end));
755   geoTypes.push_back(getGeoType());
756   if(_profile.empty())
757     pfls.push_back(0);
758   else
759     {
760       pfls.push_back(glob->getProfile(_profile.c_str()));
761     }
762   if(_localization.empty())
763     locs.push_back(-1);
764   else
765     {
766       locs.push_back(glob->getLocalizationId(_localization.c_str()));
767     }
768 }
769
770 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
771 {
772   entries[startEntryId]=std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int> ,std::pair<int,int> >(std::pair<INTERP_KERNEL::NormalizedCellType,int>(getGeoType(),discId),std::pair<int,int>(_start,_end));
773   startEntryId++;
774 }
775
776 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
777 {
778   TypeOfField type=getType();
779   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
780   med_geometry_type mgeoti;
781   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
782   const DataArray *arr=getOrCreateAndGetArray();
783   if(!arr)
784     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
785   if(!arr->isAllocated())
786     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
787   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
788   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
789   const unsigned char *locToWrite=0;
790   if(arrD)
791     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
792   else if(arrI)
793     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
794   else
795     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
796   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
797                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
798                                                    locToWrite));
799 }
800
801 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
802 {
803   type=_type;
804   pfl=_profile;
805   loc=_localization;
806   dad.first=_start; dad.second=_end;
807 }
808
809 /*!
810  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
811  *             This code corresponds to the distribution of types in the corresponding mesh.
812  * \param [out] ptToFill memory zone where the output will be stored.
813  * \return the size of data pushed into output param \a ptToFill
814  */
815 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
816 {
817   _loc_id=offset;
818   std::ostringstream oss;
819   std::size_t nbOfType=codeOfMesh.size()/3;
820   int found=-1;
821   for(std::size_t i=0;i<nbOfType && found==-1;i++)
822     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
823       found=(int)i;
824   if(found==-1)
825     {
826       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
827       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
828       throw INTERP_KERNEL::Exception(oss.str());
829     }
830   int *work=ptToFill;
831   if(_profile.empty())
832     {
833       if(_nval!=codeOfMesh[3*found+1])
834         {
835           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
836           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
837           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
838           throw INTERP_KERNEL::Exception(oss.str());
839         }
840       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
841         *work++=ii;
842     }
843   else
844     {
845       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
846       if(pfl->getNumberOfTuples()!=_nval)
847         {
848           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
849           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
850           oss << _nval;
851           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
852           throw INTERP_KERNEL::Exception(oss.str());
853         }
854       int offset2=codeOfMesh[3*found+2];
855       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
856         {
857           if(*pflId<codeOfMesh[3*found+1])
858             *work++=offset2+*pflId;
859         }
860     }
861   return _nval;
862 }
863
864 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
865 {
866   for(int i=_start;i<_end;i++)
867     *ptToFill++=i;
868   return _end-_start;
869 }
870
871 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
872 {
873   switch(type)
874   {
875     case ON_CELLS:
876       return -2;
877     case ON_GAUSS_NE:
878       return -1;
879     case ON_GAUSS_PT:
880       return locId;
881     default:
882       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
883   }
884 }
885
886 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
887 {
888   int id=0;
889   std::map<std::pair<std::string,TypeOfField>,int> m;
890   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
891   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
892     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
893       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
894   ret.resize(id);
895   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
896     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
897   return ret;
898 }
899
900 /*!
901  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
902  * 
903  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
904  * \param [in] entriesOnSameDisc some entries **on same localization** if not the result can be invalid. The _start and _end on them are relative to \a arr parameter.
905  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
906  * \param [in] newCode one of the input parameter to explicit the new geo type dispatch (in classical format same than those asked by MEDFileFields::renumberEntitiesLyingOnMesh)
907  * \param [in,out] glob if necessary by the method, new profiles can be added to it
908  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
909  * \param [out] result All new entries will be appended on it.
910  * \return false if the configuration of renumbering leads to an unnecessary resplit of input \a entriesOnSameDisc. If not true is returned (the most general case !)
911  */
912 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
913                                                        const DataArrayInt *explicitIdsInMesh,
914                                                        const std::vector<int>& newCode,
915                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
916                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
917 {
918   if(entriesOnSameDisc.empty())
919     return false;
920   TypeOfField type=entriesOnSameDisc[0]->getType();
921   int szEntities=0,szTuples=0;
922   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
923     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
924   int nbi=szTuples/szEntities;
925   if(szTuples%szEntities!=0)
926     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
927   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
928   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
929   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
930   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
931   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
932   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
933   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
934   int id=0;
935   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
936     {
937       int startOfEltIdOfChunk=(*it)->_start;
938       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
939       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
940       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
941       //
942       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
943       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
944       //
945       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
946       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
947     }
948   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
949   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
950   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
951   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
952   //
953   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
954   //
955   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
956   arrPart->renumberInPlace(renumTupleIds->begin());
957   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
958   bool ret=false;
959   const int *idIt=diffVals->begin();
960   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
961   int offset2=0;
962   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
963     {
964       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
965       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
966       int nbEntityElts=subIds->getNumberOfTuples();
967       bool ret2;
968       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
969           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
970                                       offset+offset2,
971                                       li,glob,ret2);
972       ret=ret || ret2;
973       result.push_back(eltToAdd);
974       offset2+=nbEntityElts*nbi;
975     }
976   ret=ret || li.empty();
977   return ret;
978 }
979
980 /*!
981  * \param [in] typeF type of field of new chunk
982  * \param [in] geoType the geometric type of the chunk
983  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
984  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
985  * \param [in] nbi number of integration points
986  * \param [in] offset The offset in the **global array of data**.
987  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
988  *                 to the new chunk to create.
989  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
990  * \param [out] notInExisting If false the return newly allocated entry is not coming from \a entriesOnSameDisc. If true the output comes from copy of \a entriesOnSameDisc
991  *              and corresponding entry erased from \a entriesOnSameDisc.
992  * \return a newly allocated chunk
993  */
994 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
995                                                                                                   bool isPfl, int nbi, int offset,
996                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
997                                                                                                   MEDFileFieldGlobsReal& glob,
998                                                                                                   bool &notInExisting)
999 {
1000   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1001   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1002   for(;it!=entriesOnSameDisc.end();it++)
1003     {
1004       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1005         {
1006           if(!isPfl)
1007             {
1008               if((*it)->_profile.empty())
1009                 break;
1010               else
1011                 if(!(*it)->_profile.empty())
1012                   {
1013                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1014                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1015                       break;
1016                   }
1017             }
1018         }
1019     }
1020   if(it==entriesOnSameDisc.end())
1021     {
1022       notInExisting=true;
1023       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1024       ret->_type=typeF;
1025       ret->_loc_id=(int)geoType;
1026       ret->_nval=nbMeshEntities;
1027       ret->_start=offset;
1028       ret->_end=ret->_start+ret->_nval*nbi;
1029       if(isPfl)
1030         {
1031           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1032           glob.appendProfile(idsOfMeshElt);
1033           ret->_profile=idsOfMeshElt->getName();
1034         }
1035       //tony treatment of localization
1036       return ret;
1037     }
1038   else
1039     {
1040       notInExisting=false;
1041       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1042       ret->_loc_id=(int)geoType;
1043       ret->setNewStart(offset);
1044       entriesOnSameDisc.erase(it);
1045       return ret;
1046     }
1047
1048 }
1049
1050 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1051 {
1052   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1053 }
1054
1055 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1056 {
1057   return new MEDFileFieldPerMeshPerType(fath,geoType);
1058 }
1059
1060 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
1061 {
1062   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1063 }
1064
1065 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
1066 {
1067   std::vector<const BigMemoryObject *> ret;
1068   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1069     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1070   return ret;
1071 }
1072
1073 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1074 {
1075   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1076   ret->_father=father;
1077   std::size_t i=0;
1078   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1079     {
1080       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1081         ret->_field_pm_pt_pd[i]=(*it)->deepCopy((MEDFileFieldPerMeshPerType *)ret);
1082     }
1083   return ret.retn();
1084 }
1085
1086 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1087 {
1088   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1089   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1090     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1091 }
1092
1093 /*!
1094  * This method is the most general one. No optimization is done here.
1095  * \param [in] multiTypePfl is the end user profile specified in high level API
1096  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1097  * \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.
1098  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1099  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1100  * \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.
1101  */
1102 void MEDFileFieldPerMeshPerType::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)
1103 {
1104   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1105   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1106     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1107 }
1108
1109 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1110 {
1111   _field_pm_pt_pd.resize(1);
1112   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1113   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1114 }
1115
1116 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1117 {
1118   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1119   if(!arr || !arr->isAllocated())
1120     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1121   _field_pm_pt_pd.resize(1);
1122   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1123   _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.
1124 }
1125
1126 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1127 {
1128   TypeOfField type=field->getTypeOfField();
1129   if(type!=ON_GAUSS_PT)
1130     {
1131       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1132       int sz=_field_pm_pt_pd.size();
1133       bool found=false;
1134       for(int j=0;j<sz && !found;j++)
1135         {
1136           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1137             {
1138               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1139               found=true;
1140             }
1141         }
1142       if(!found)
1143         {
1144           _field_pm_pt_pd.resize(sz+1);
1145           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1146         }
1147       std::vector<int> ret(1,(int)sz);
1148       return ret;
1149     }
1150   else
1151     {
1152       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1153       int sz2=ret2.size();
1154       std::vector<int> ret3(sz2);
1155       int k=0;
1156       for(int i=0;i<sz2;i++)
1157         {
1158           int sz=_field_pm_pt_pd.size();
1159           int locIdToFind=ret2[i];
1160           bool found=false;
1161           for(int j=0;j<sz && !found;j++)
1162             {
1163               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1164                 {
1165                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1166                   ret3[k++]=j;
1167                   found=true;
1168                 }
1169             }
1170           if(!found)
1171             {
1172               _field_pm_pt_pd.resize(sz+1);
1173               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1174               ret3[k++]=sz;
1175             }
1176         }
1177       return ret3;
1178     }
1179 }
1180
1181 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1182 {
1183   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1184   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1185   if(!disc2)
1186     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1187   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1188   if(!da)
1189     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1190   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1191   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1192   if(retTmp->presenceOfValue(-1))
1193     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1194   std::vector<int> ret(retTmp->begin(),retTmp->end());
1195   return ret;
1196 }
1197
1198 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1199 {
1200   TypeOfField type=field->getTypeOfField();
1201   if(type!=ON_GAUSS_PT)
1202     {
1203       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1204       int sz=_field_pm_pt_pd.size();
1205       bool found=false;
1206       for(int j=0;j<sz && !found;j++)
1207         {
1208           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1209             {
1210               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1211               found=true;
1212             }
1213         }
1214       if(!found)
1215         {
1216           _field_pm_pt_pd.resize(sz+1);
1217           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1218         }
1219       std::vector<int> ret(1,0);
1220       return ret;
1221     }
1222   else
1223     {
1224       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1225       int sz2=ret2.size();
1226       std::vector<int> ret3(sz2);
1227       int k=0;
1228       for(int i=0;i<sz2;i++)
1229         {
1230           int sz=_field_pm_pt_pd.size();
1231           int locIdToFind=ret2[i];
1232           bool found=false;
1233           for(int j=0;j<sz && !found;j++)
1234             {
1235               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1236                 {
1237                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1238                   ret3[k++]=j;
1239                   found=true;
1240                 }
1241             }
1242           if(!found)
1243             {
1244               _field_pm_pt_pd.resize(sz+1);
1245               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1246               ret3[k++]=sz;
1247             }
1248         }
1249       return ret3;
1250     }
1251 }
1252
1253 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1254 {
1255   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1256   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1257   if(!disc2)
1258     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1259   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1260   if(!da)
1261     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1262   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1263   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1264   if(retTmp->presenceOfValue(-1))
1265     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1266   std::vector<int> ret(retTmp->begin(),retTmp->end());
1267   return ret;
1268 }
1269
1270 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1271 {
1272   return _father;
1273 }
1274
1275 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1276 {
1277   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1278   int curDim((int)cm.getDimension());
1279   dim=std::max(dim,curDim);
1280 }
1281
1282 bool MEDFileFieldPerMeshPerType::isUniqueLevel(int& dim) const
1283 {
1284   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1285   int curDim((int)cm.getDimension());
1286   if(dim!=std::numeric_limits<int>::max())
1287     {
1288       if(dim!=curDim)
1289         return false;
1290     }
1291   else
1292     dim=curDim;
1293   return true;
1294 }
1295
1296 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1297 {
1298   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1299     {
1300       (*it)->fillTypesOfFieldAvailable(types);
1301     }
1302 }
1303
1304 void MEDFileFieldPerMeshPerType::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1305 {
1306   int sz=_field_pm_pt_pd.size();
1307   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1308   for(int i=0;i<sz;i++)
1309     {
1310       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1311     }
1312 }
1313
1314 int MEDFileFieldPerMeshPerType::getIteration() const
1315 {
1316   return _father->getIteration();
1317 }
1318
1319 int MEDFileFieldPerMeshPerType::getOrder() const
1320 {
1321   return _father->getOrder();
1322 }
1323
1324 double MEDFileFieldPerMeshPerType::getTime() const
1325 {
1326   return _father->getTime();
1327 }
1328
1329 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1330 {
1331   return _father->getMeshName();
1332 }
1333
1334 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1335 {
1336   const char startLine[]="  ## ";
1337   std::string startLine2(bkOffset,' ');
1338   std::string startLine3(startLine2);
1339   startLine3+=startLine;
1340   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1341     {
1342       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1343       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1344     }
1345   else
1346     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1347   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1348   int i=0;
1349   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1350     {
1351       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1352       if(cur)
1353         cur->simpleRepr(bkOffset,oss,i);
1354       else
1355         {
1356           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1357         }
1358     }
1359 }
1360
1361 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1362 {
1363   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1364     {
1365       globalSz+=(*it)->getNumberOfTuples();
1366     }
1367   nbOfEntries+=(int)_field_pm_pt_pd.size();
1368 }
1369
1370 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1371 {
1372   return _geo_type;
1373 }
1374
1375
1376 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1377 {
1378   return _father->getNumberOfComponents();
1379 }
1380
1381 bool MEDFileFieldPerMeshPerType::presenceOfMultiDiscPerGeoType() const
1382 {
1383   std::size_t nb(0);
1384   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1385     {
1386       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1387       if(fmtd)
1388         nb++;
1389     }
1390   return nb>1;
1391 }
1392
1393 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1394 {
1395   return _father->getOrCreateAndGetArray();
1396 }
1397
1398 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1399 {
1400   const MEDFileFieldPerMesh *fath=_father;
1401   return fath->getOrCreateAndGetArray();
1402 }
1403
1404 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1405 {
1406   return _father->getInfo();
1407 }
1408
1409 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1410 {
1411   std::vector<std::string> ret;
1412   std::set<std::string> ret2;
1413   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1414     {
1415       std::string tmp=(*it1)->getProfile();
1416       if(!tmp.empty())
1417         if(ret2.find(tmp)==ret2.end())
1418           {
1419             ret.push_back(tmp);
1420             ret2.insert(tmp);
1421           }
1422     }
1423   return ret;
1424 }
1425
1426 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1427 {
1428   std::vector<std::string> ret;
1429   std::set<std::string> ret2;
1430   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1431     {
1432       std::string tmp=(*it1)->getLocalization();
1433       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1434         if(ret2.find(tmp)==ret2.end())
1435           {
1436             ret.push_back(tmp);
1437             ret2.insert(tmp);
1438           }
1439     }
1440   return ret;
1441 }
1442
1443 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1444 {
1445   std::vector<std::string> ret;
1446   std::set<std::string> ret2;
1447   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1448     {
1449       std::string tmp=(*it1)->getProfile();
1450       if(!tmp.empty())
1451         ret.push_back(tmp);
1452     }
1453   return ret;
1454 }
1455
1456 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1457 {
1458   std::vector<std::string> ret;
1459   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1460     {
1461       std::string tmp=(*it1)->getLocalization();
1462       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1463         ret.push_back(tmp);
1464     }
1465   return ret;
1466 }
1467
1468 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1469 {
1470   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1471     (*it1)->changePflsRefsNamesGen(mapOfModif);
1472 }
1473
1474 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1475 {
1476   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1477     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1478 }
1479
1480 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1481 {
1482   if(_field_pm_pt_pd.empty())
1483     {
1484       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1485       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1486       throw INTERP_KERNEL::Exception(oss.str());
1487     }
1488   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1489     return _field_pm_pt_pd[locId];
1490   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1491   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1492   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1493   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1494   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1495 }
1496
1497 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1498 {
1499   if(_field_pm_pt_pd.empty())
1500     {
1501       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1502       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1503       throw INTERP_KERNEL::Exception(oss.str());
1504     }
1505   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1506     return _field_pm_pt_pd[locId];
1507   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1508   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1509   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1510   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1511   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1512 }
1513
1514 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
1515 {
1516   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1517     {
1518       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1519       if(meshDim!=(int)cm.getDimension())
1520         return ;
1521     }
1522   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1523     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1524 }
1525
1526 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1527 {
1528   int i=0;
1529   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1530     {
1531       (*it)->fillValues(i,startEntryId,entries);
1532     }
1533 }
1534
1535 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1536 {
1537   _field_pm_pt_pd=leaves;
1538   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1539     (*it)->setFather(this);
1540 }
1541
1542 /*!
1543  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1544  *  \param [out] its - list of pair (start,stop) kept
1545  *  \return bool - false if the type of field \a tof is not contained in \a this.
1546  */
1547 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1548 {
1549   bool ret(false);
1550   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1551   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1552     if((*it)->getType()==tof)
1553       {
1554         newPmPtPd.push_back(*it);
1555         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1556         (*it)->setNewStart(globalNum);
1557         globalNum=(*it)->getEnd();
1558         its.push_back(bgEnd);
1559         ret=true;
1560       }
1561   if(ret)
1562     _field_pm_pt_pd=newPmPtPd;
1563   return ret;
1564 }
1565
1566 /*!
1567  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1568  *  \param [out] its - list of pair (start,stop) kept
1569  *  \return bool - false if the type of field \a tof is not contained in \a this.
1570  */
1571 bool MEDFileFieldPerMeshPerType::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1572 {
1573   if(_field_pm_pt_pd.size()<=idOfDisc)
1574     return false;
1575   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1576   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1577   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1578   elt->setNewStart(globalNum);
1579   globalNum=elt->getEnd();
1580   its.push_back(bgEnd);
1581   _field_pm_pt_pd=newPmPtPd;
1582   return true;
1583 }
1584
1585 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType)
1586 {
1587   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1588   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1589   med_geometry_type mgeoti;
1590   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1591   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1592   _field_pm_pt_pd.resize(nbProfiles);
1593   for(int i=0;i<nbProfiles;i++)
1594     {
1595       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1596     }
1597   if(type==ON_CELLS)
1598     {
1599       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1600       for(int i=0;i<nbProfiles2;i++)
1601         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1602     }
1603 }
1604
1605 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1606 {
1607   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1608     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1609 }
1610
1611 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1612 {
1613   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1614     (*it)->loadBigArray(fid,nasc);
1615 }
1616
1617 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1618 {
1619   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1620     {
1621       (*it)->copyOptionsFrom(*this);
1622       (*it)->writeLL(fid,nasc);
1623     }
1624 }
1625
1626 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1627 {
1628   switch(ikType)
1629   {
1630     case ON_CELLS:
1631       medfGeoType=typmai3[(int)ikGeoType];
1632       return MED_CELL;
1633     case ON_NODES:
1634       medfGeoType=MED_NONE;
1635       return MED_NODE;
1636     case ON_GAUSS_NE:
1637       medfGeoType=typmai3[(int)ikGeoType];
1638       return MED_NODE_ELEMENT;
1639     case ON_GAUSS_PT:
1640       medfGeoType=typmai3[(int)ikGeoType];
1641       return MED_CELL;
1642     default:
1643       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1644   }
1645   return MED_UNDEF_ENTITY_TYPE;
1646 }
1647
1648 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
1649 {
1650   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1651 }
1652
1653 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1654 {
1655   return new MEDFileFieldPerMesh(fath,mesh);
1656 }
1657
1658 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1659 {
1660   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1661 }
1662
1663 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1664 {
1665   std::vector<const BigMemoryObject *> ret;
1666   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1667     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1668   return ret;
1669 }
1670
1671 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1672 {
1673   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1674   ret->_father=father;
1675   std::size_t i=0;
1676   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1677     {
1678       if((const MEDFileFieldPerMeshPerType *)*it)
1679         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1680     }
1681   return ret.retn();
1682 }
1683
1684 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1685 {
1686   std::string startLine(bkOffset,' ');
1687   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1688   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1689   int i=0;
1690   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1691     {
1692       const MEDFileFieldPerMeshPerType *cur=*it;
1693       if(cur)
1694         cur->simpleRepr(bkOffset,oss,i);
1695       else
1696         {
1697           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1698         }
1699     }
1700 }
1701
1702 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1703 {
1704   _mesh_name=mesh->getName();
1705   mesh->getTime(_mesh_iteration,_mesh_order);
1706 }
1707
1708 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1709 {
1710   int nbOfTypes=code.size()/3;
1711   int offset=0;
1712   for(int i=0;i<nbOfTypes;i++)
1713     {
1714       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1715       int nbOfCells=code[3*i+1];
1716       int pos=addNewEntryIfNecessary(type);
1717       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1718       offset+=nbOfCells;
1719     }
1720 }
1721
1722 /*!
1723  * This method is the most general one. No optimization is done here.
1724  * \param [in] multiTypePfl is the end user profile specified in high level API
1725  * \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].
1726  * \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.
1727  * \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.
1728  * \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.
1729  * \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.
1730  */
1731 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)
1732 {
1733   int nbOfTypes(code.size()/3);
1734   for(int i=0;i<nbOfTypes;i++)
1735     {
1736       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1737       int pos=addNewEntryIfNecessary(type);
1738       DataArrayInt *pfl=0;
1739       if(code[3*i+2]!=-1)
1740         pfl=idsPerType[code[3*i+2]];
1741       int nbOfTupes2=code2.size()/3;
1742       int found=0;
1743       for(;found<nbOfTupes2;found++)
1744         if(code[3*i]==code2[3*found])
1745           break;
1746       if(found==nbOfTupes2)
1747         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1748       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1749     }
1750 }
1751
1752 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1753 {
1754   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1755   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1756 }
1757
1758 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1759 {
1760   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1761   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1762 }
1763
1764 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1765 {
1766   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1767     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1768 }
1769
1770 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1771 {
1772   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1773     (*it)->loadBigArraysRecursively(fid,nasc);
1774 }
1775
1776 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1777 {
1778   int nbOfTypes=_field_pm_pt.size();
1779   for(int i=0;i<nbOfTypes;i++)
1780     {
1781       _field_pm_pt[i]->copyOptionsFrom(*this);
1782       _field_pm_pt[i]->writeLL(fid,nasc);
1783     }
1784 }
1785
1786 void MEDFileFieldPerMesh::getDimension(int& dim) const
1787 {
1788   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1789     (*it)->getDimension(dim);
1790 }
1791
1792 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
1793 {
1794   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1795     if(!(*it)->isUniqueLevel(dim))
1796       return false;
1797   return true;
1798 }
1799
1800 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1801 {
1802   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1803     (*it)->fillTypesOfFieldAvailable(types);
1804 }
1805
1806 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
1807 {
1808   int sz=_field_pm_pt.size();
1809   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1810   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1811   for(int i=0;i<sz;i++)
1812     {
1813       types[i]=_field_pm_pt[i]->getGeoType();
1814       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1815     }
1816   return ret;
1817 }
1818
1819 double MEDFileFieldPerMesh::getTime() const
1820 {
1821   int tmp1,tmp2;
1822   return _father->getTime(tmp1,tmp2);
1823 }
1824
1825 int MEDFileFieldPerMesh::getIteration() const
1826 {
1827   return _father->getIteration();
1828 }
1829
1830 int MEDFileFieldPerMesh::getOrder() const
1831 {
1832   return _father->getOrder();
1833 }
1834
1835 int MEDFileFieldPerMesh::getNumberOfComponents() const
1836 {
1837   return _father->getNumberOfComponents();
1838 }
1839
1840 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1841 {
1842   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1843     {
1844       const MEDFileFieldPerMeshPerType *fpmt(*it);
1845       if(!fpmt)
1846         continue;
1847       if(fpmt->presenceOfMultiDiscPerGeoType())
1848         return true;
1849     }
1850   return false;
1851 }
1852
1853 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1854 {
1855   if(!_father)
1856     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1857   return _father->getOrCreateAndGetArray();
1858 }
1859
1860 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1861 {
1862   if(!_father)
1863     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1864   return _father->getOrCreateAndGetArray();
1865 }
1866
1867 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1868 {
1869   return _father->getInfo();
1870 }
1871
1872 /*!
1873  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1874  * 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.
1875  * It returns 2 output vectors :
1876  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1877  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1878  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1879  */
1880 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)
1881 {
1882   int notNullPflsSz=0;
1883   int nbOfArrs=geoTypes.size();
1884   for(int i=0;i<nbOfArrs;i++)
1885     if(pfls[i])
1886       notNullPflsSz++;
1887   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1888   int nbOfDiffGeoTypes=geoTypes3.size();
1889   code.resize(3*nbOfDiffGeoTypes);
1890   notNullPfls.resize(notNullPflsSz);
1891   notNullPflsSz=0;
1892   int j=0;
1893   for(int i=0;i<nbOfDiffGeoTypes;i++)
1894     {
1895       int startZone=j;
1896       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1897       std::vector<const DataArrayInt *> notNullTmp;
1898       if(pfls[j])
1899         notNullTmp.push_back(pfls[j]);
1900       j++;
1901       for(;j<nbOfArrs;j++)
1902         if(geoTypes[j]==refType)
1903           {
1904             if(pfls[j])
1905               notNullTmp.push_back(pfls[j]);
1906           }
1907         else
1908           break;
1909       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1910       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1911       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1912       code[3*i]=(int)refType;
1913       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1914       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1915       if(notNullTmp.empty())
1916         code[3*i+2]=-1;
1917       else
1918         {
1919           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1920           code[3*i+2]=notNullPflsSz++;
1921         }
1922     }
1923 }
1924
1925 /*!
1926  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1927  */
1928 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)
1929 {
1930   int sz=dads.size();
1931   int ret=0;
1932   for(int i=0;i<sz;i++)
1933     {
1934       if(locs[i]==-1)
1935         {
1936           if(type!=ON_GAUSS_NE)
1937             ret+=dads[i].second-dads[i].first;
1938           else
1939             {
1940               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1941               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1942             }
1943         }
1944       else
1945         {
1946           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1947           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1948         }
1949     }
1950   return ret;
1951 }
1952
1953 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1954 {
1955   std::vector<std::string> ret;
1956   std::set<std::string> ret2;
1957   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1958     {
1959       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1960       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1961         if(ret2.find(*it2)==ret2.end())
1962           {
1963             ret.push_back(*it2);
1964             ret2.insert(*it2);
1965           }
1966     }
1967   return ret;
1968 }
1969
1970 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1971 {
1972   std::vector<std::string> ret;
1973   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1974     {
1975       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1976       ret.insert(ret.end(),tmp.begin(),tmp.end());
1977     }
1978   return ret;
1979 }
1980
1981 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1982 {
1983   std::vector<std::string> ret;
1984   std::set<std::string> ret2;
1985   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1986     {
1987       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1988       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1989         if(ret2.find(*it2)==ret2.end())
1990           {
1991             ret.push_back(*it2);
1992             ret2.insert(*it2);
1993           }
1994     }
1995   return ret;
1996 }
1997
1998 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1999 {
2000   std::vector<std::string> ret;
2001   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2002     {
2003       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2004       ret.insert(ret.end(),tmp.begin(),tmp.end());
2005     }
2006   return ret;
2007 }
2008
2009 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2010 {
2011   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2012     {
2013       if((*it).first==_mesh_name)
2014         {
2015           _mesh_name=(*it).second;
2016           return true;
2017         }
2018     }
2019   return false;
2020 }
2021
2022 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2023                                                       MEDFileFieldGlobsReal& glob)
2024 {
2025   if(_mesh_name!=meshName)
2026     return false;
2027   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2028   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2029   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2030   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2031   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2032   getUndergroundDataArrayExt(entries);
2033   DataArray *arr0(getOrCreateAndGetArray());//tony
2034   if(!arr0)
2035     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2036   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2037   if(!arr0)
2038     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2039   int sz=0;
2040   if(!arr)
2041     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2042   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2043     {
2044       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2045         {
2046           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2047           sz+=(*it).second.second-(*it).second.first;
2048         }
2049       else
2050         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2051     }
2052   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2053   ////////////////////
2054   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2055   int *workI2=explicitIdsOldInMesh->getPointer();
2056   int sz1=0,sz2=0,sid=1;
2057   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2058   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2059   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2060     {
2061       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2062       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2063       int *workI=explicitIdsOldInArr->getPointer();
2064       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2065         {
2066           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2067           (*itL2)->setLocId(sz2);
2068           (*itL2)->_tmp_work1=(*itL2)->getStart();
2069           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2070         }
2071       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2072     }
2073   explicitIdsOldInMesh->reAlloc(sz2);
2074   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2075   ////////////////////
2076   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2077   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2078   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2079   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2080     {
2081       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2082       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2083       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2084     }
2085   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2086   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2087   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2088     {
2089       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2090       int newStart=elt->getLocId();
2091       elt->setLocId((*it)->getGeoType());
2092       elt->setNewStart(newStart);
2093       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2094       entriesKeptNew.push_back(elt);
2095       entriesKeptNew2.push_back(elt);
2096     }
2097   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2098   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2099   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2100   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2101   bool ret=false;
2102   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2103     {
2104       sid=0;
2105       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2106         {
2107           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2108           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2109           }*/
2110       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2111                                                             glob,arr2,otherEntriesNew) || ret;
2112     }
2113   if(!ret)
2114     return false;
2115   // Assign new dispatching
2116   assignNewLeaves(otherEntriesNew);
2117   arr->deepCopyFrom(*arr2);
2118   return true;
2119 }
2120
2121 /*!
2122  * \param [in,out] globalNum a global numbering counter for the renumbering.
2123  * \param [out] its - list of pair (start,stop) kept
2124  */
2125 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2126 {
2127   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret;
2128   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2129     {
2130       std::vector< std::pair<int,int> > its2;
2131       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2132         {
2133           ret.push_back(*it);
2134           its.insert(its.end(),its2.begin(),its2.end());
2135         }
2136     }
2137   _field_pm_pt=ret;
2138 }
2139
2140 /*!
2141  * \param [in,out] globalNum a global numbering counter for the renumbering.
2142  * \param [out] its - list of pair (start,stop) kept
2143  */
2144 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2145 {
2146   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret;
2147   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2148     {
2149       std::vector< std::pair<int,int> > its2;
2150       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2151         {
2152           ret.push_back(*it);
2153           its.insert(its.end(),its2.begin(),its2.end());
2154         }
2155     }
2156   _field_pm_pt=ret;
2157 }
2158
2159 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2160 {
2161   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2162   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2163     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2164   //
2165   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2166   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2167   std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2168   for(;it1!=types.end();it1++,it2++)
2169     {
2170       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2171       elt->setLeaves((*it1).second);
2172       *it2=elt;
2173     }
2174   _field_pm_pt=fieldPmPt;
2175 }
2176
2177 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2178 {
2179   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2180     (*it)->changePflsRefsNamesGen(mapOfModif);
2181 }
2182
2183 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2184 {
2185   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2186     (*it)->changeLocsRefsNamesGen(mapOfModif);
2187 }
2188
2189 /*!
2190  * \param [in] mesh is the whole mesh
2191  */
2192 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2193 {
2194   if(_field_pm_pt.empty())
2195     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2196   //
2197   std::vector< std::pair<int,int> > dads;
2198   std::vector<const DataArrayInt *> pfls;
2199   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2200   std::vector<int> locs,code;
2201   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2202   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2203     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2204   // Sort by types
2205   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2206   if(code.empty())
2207     {
2208       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2209       throw INTERP_KERNEL::Exception(oss.str());
2210     }
2211   //
2212   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2213   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2214   if(type!=ON_NODES)
2215     {
2216       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2217       if(!arr)
2218         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2219       else
2220         {
2221           MCAuto<DataArrayInt> arr2(arr);
2222           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2223         }
2224     }
2225   else
2226     {
2227       if(code.size()!=3)
2228         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2229       int nb=code[1];
2230       if(code[2]==-1)
2231         {
2232           if(nb!=mesh->getNumberOfNodes())
2233             {
2234               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2235               oss << " nodes in mesh !";
2236               throw INTERP_KERNEL::Exception(oss.str());
2237             }
2238           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2239         }
2240       else
2241         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2242     }
2243 }
2244
2245 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2246 {
2247   if(_field_pm_pt.empty())
2248     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2249   //
2250   std::vector<std::pair<int,int> > dads;
2251   std::vector<const DataArrayInt *> pfls;
2252   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2253   std::vector<int> locs,code;
2254   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2255   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2256     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2257   // Sort by types
2258   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2259   if(code.empty())
2260     {
2261       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2262       throw INTERP_KERNEL::Exception(oss.str());
2263     }
2264   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2265   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2266   if(type!=ON_NODES)
2267     {
2268       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2269       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2270     }
2271   else
2272     {
2273       if(code.size()!=3)
2274         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2275       int nb=code[1];
2276       if(code[2]==-1)
2277         {
2278           if(nb!=mesh->getNumberOfNodes())
2279             {
2280               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2281               oss << " nodes in mesh !";
2282               throw INTERP_KERNEL::Exception(oss.str());
2283             }
2284         }
2285       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2286     }
2287   //
2288   return 0;
2289 }
2290
2291 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2292 {
2293   int globalSz=0;
2294   int nbOfEntries=0;
2295   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2296     {
2297       (*it)->getSizes(globalSz,nbOfEntries);
2298     }
2299   entries.resize(nbOfEntries);
2300   nbOfEntries=0;
2301   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2302     {
2303       (*it)->fillValues(nbOfEntries,entries);
2304     }
2305 }
2306
2307 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2308 {
2309   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2310     {
2311       if((*it)->getGeoType()==typ)
2312         return (*it)->getLeafGivenLocId(locId);
2313     }
2314   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2315   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2316   oss << "Possiblities are : ";
2317   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2318     {
2319       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2320       oss << "\"" << cm2.getRepr() << "\", ";
2321     }
2322   throw INTERP_KERNEL::Exception(oss.str());
2323 }
2324
2325 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2326 {
2327   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2328     {
2329       if((*it)->getGeoType()==typ)
2330         return (*it)->getLeafGivenLocId(locId);
2331     }
2332   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2333   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2334   oss << "Possiblities are : ";
2335   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2336     {
2337       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2338       oss << "\"" << cm2.getRepr() << "\", ";
2339     }
2340   throw INTERP_KERNEL::Exception(oss.str());
2341 }
2342
2343 /*!
2344  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2345  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2346  * \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.
2347  * \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.
2348  */
2349 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)
2350 {
2351   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2352   if(pms.empty())
2353     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2354   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2355     {
2356       if(!(*it).second)
2357         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2358       if(!(*it).second->getProfile().empty())
2359         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2360       if(!(*it).second->getLocalization().empty())
2361         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2362     }
2363   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2364   std::size_t i(0);
2365   std::vector< std::pair<int,int> > filteredDTS;
2366   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2367     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2368       if((*it2).first==gt)
2369         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2370   if(pms.size()!=filteredDTS.size())
2371     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2372   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2373   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2374   int zeStart(start),nval(0);
2375   for(;it1!=pms.end();it1++,it2++)
2376     {
2377       if((*it1).first!=(*it2).first)
2378         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2379       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2380       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2381       start+=e1-s1;
2382       nval+=((*it1).second)->getNumberOfVals();
2383     }
2384   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2385   return ret;
2386 }
2387
2388 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)
2389 {
2390   MCAuto<MEDFileFieldPerMeshPerType> ret(new MEDFileFieldPerMeshPerType(father,gt));
2391   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
2392   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2393     {
2394       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
2395         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
2396     }
2397   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
2398     {
2399       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2400       ret->_field_pm_pt_pd.push_back(agg);
2401     }
2402   return ret;
2403 }
2404
2405 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)
2406 {
2407   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2408   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2409   std::size_t i(0);
2410   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2411     {
2412       const std::vector< MCAuto< MEDFileFieldPerMeshPerType > >& v((*it)->_field_pm_pt);
2413       for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2414         {
2415           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2416           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,*it2));
2417         }
2418     }
2419   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2420     {
2421       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2422       ret->_field_pm_pt.push_back(agg);
2423     }
2424   return ret;
2425 }
2426
2427 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2428 {
2429   int i=0;
2430   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2431   std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2432   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2433     {
2434       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2435       if(type==curType)
2436         return i;
2437       else
2438         {
2439           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2440           if(pos>pos2)
2441             it2=it+1;
2442         }
2443     }
2444   int ret=std::distance(_field_pm_pt.begin(),it2);
2445   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2446   return ret;
2447 }
2448
2449 /*!
2450  * 'dads' and 'locs' input parameters have the same number of elements
2451  * \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
2452  */
2453 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2454                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2455                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2456 {
2457   isPfl=false;
2458   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2459   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2460   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2461   const std::vector<std::string>& infos=getInfo();
2462   da->setInfoOnComponents(infos);
2463   da->setName("");
2464   if(type==ON_GAUSS_PT)
2465     {
2466       int offset=0;
2467       int nbOfArrs=dads.size();
2468       for(int i=0;i<nbOfArrs;i++)
2469         {
2470           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2471           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2472           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2473           MCAuto<DataArrayInt> di=DataArrayInt::New();
2474           di->alloc(nbOfElems,1);
2475           di->iota(offset);
2476           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2477           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2478           offset+=nbOfElems;
2479         }
2480     }
2481   arrOut=da;
2482   return ret.retn();
2483 }
2484
2485 /*!
2486  * 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.
2487  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2488  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2489  * The order of cells in the returned field is those imposed by the profile.
2490  * \param [in] mesh is the global mesh.
2491  */
2492 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2493                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2494                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2495                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2496 {
2497   if(da->isIota(mesh->getNumberOfCells()))
2498     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2499   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2500   m2->setName(mesh->getName().c_str());
2501   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2502   isPfl=true;
2503   return ret.retn();
2504 }
2505
2506 /*!
2507  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2508  */
2509 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2510                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2511                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2512 {
2513   if(da->isIota(mesh->getNumberOfNodes()))
2514     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2515   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2516   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2517   if(meshu)
2518     {
2519       if(meshu->getNodalConnectivity()==0)
2520         {
2521           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2522           int nb=da->getNbOfElems();
2523           const int *ptr=da->getConstPointer();
2524           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2525           meshuc->allocateCells(nb);
2526           for(int i=0;i<nb;i++)
2527             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2528           meshuc->finishInsertingCells();
2529           ret->setMesh(meshuc);
2530           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2531           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2532           disc->checkCoherencyBetween(meshuc,arrOut);
2533           return ret.retn();
2534         }
2535     }
2536   //
2537   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2538   isPfl=true;
2539   DataArrayInt *arr2=0;
2540   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2541   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2542   MCAuto<DataArrayInt> arr3(arr2);
2543   int nnodes=mesh2->getNumberOfNodes();
2544   if(nnodes==(int)da->getNbOfElems())
2545     {
2546       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2547       arrOut->renumberInPlace(da3->getConstPointer());
2548       mesh2->setName(mesh->getName().c_str());
2549       ret->setMesh(mesh2);
2550       return ret.retn();
2551     }
2552   else
2553     {
2554       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 !!!";
2555       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2556       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2557       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2558       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2559       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2560       throw INTERP_KERNEL::Exception(oss.str());
2561     }
2562   return 0;
2563 }
2564
2565 /*!
2566  * This method is the most light method of field retrieving.
2567  */
2568 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2569 {
2570   if(!pflIn)
2571     {
2572       pflOut=DataArrayInt::New();
2573       pflOut->alloc(nbOfElems,1);
2574       pflOut->iota(0);
2575     }
2576   else
2577     {
2578       pflOut=const_cast<DataArrayInt*>(pflIn);
2579       pflOut->incrRef();
2580     }
2581   MCAuto<DataArrayInt> safePfl(pflOut);
2582   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2583   const std::vector<std::string>& infos=getInfo();
2584   int nbOfComp=infos.size();
2585   for(int i=0;i<nbOfComp;i++)
2586     da->setInfoOnComponent(i,infos[i].c_str());
2587   safePfl->incrRef();
2588   return da.retn();
2589 }
2590
2591
2592 /// @cond INTERNAL
2593
2594 class MFFPMIter
2595 {
2596 public:
2597   static MFFPMIter *NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2598   static bool IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2599   virtual ~MFFPMIter() { }
2600   virtual void begin() = 0;
2601   virtual bool finished() const = 0;
2602   virtual void next() = 0;
2603   virtual int current() const = 0;
2604 };
2605
2606 class MFFPMIterSimple : public MFFPMIter
2607 {
2608 public:
2609   MFFPMIterSimple():_pos(0) { }
2610   void begin() { _pos=0; }
2611   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2612   void next() { _pos++; }
2613   int current() const { return _pos; }
2614 private:
2615   int _pos;
2616 };
2617
2618 class MFFPMIter2 : public MFFPMIter
2619 {
2620 public:
2621   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2622   void begin() { _it=_ids.begin(); }
2623   bool finished() const { return _it==_ids.end(); }
2624   void next() { _it++; }
2625   int current() const { return *_it; }
2626 private:
2627   std::vector<int> _ids;
2628   std::vector<int>::const_iterator _it;
2629 };
2630
2631 MFFPMIter *MFFPMIter::NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2632 {
2633   if(!entities)
2634     return new MFFPMIterSimple;
2635   else
2636     {
2637       std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2638       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2639         {
2640           if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2641             tmp.push_back((*it).second);
2642         }
2643       return new MFFPMIter2(tmp);
2644     }
2645 }
2646
2647 bool MFFPMIter::IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2648 {
2649   if(!entities)
2650     return true;
2651   else
2652     {
2653       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2654         if((*it).first==ON_NODES)
2655           return true;
2656       return false;
2657     }
2658 }
2659
2660 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2661 {
2662   std::size_t sz(cts.size());
2663   _ids.resize(sz);
2664   for(std::size_t i=0;i<sz;i++)
2665     {
2666       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2667       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2668         _ids[i]=(int)std::distance(typmai2,loc);
2669       else
2670         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2671     }
2672 }
2673
2674 /// @endcond
2675
2676 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2677     _father(fath)
2678 {
2679   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2680   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2681   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2682   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2683   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2684   for(iter0->begin();!iter0->finished();iter0->next())
2685     {
2686       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2687       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2688       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2689       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2690       if(nbProfile>0 || nbProfile2>0)
2691         {
2692           const PartDefinition *pd(0);
2693           if(mmu)
2694             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2695           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2696           if(nbProfile>0)
2697             _mesh_name=name0;
2698           else
2699             _mesh_name=name1;
2700         }
2701     }
2702   if(MFFPMIter::IsPresenceOfNode(entities))
2703     {
2704       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2705       if(nbProfile>0)
2706         {
2707           const PartDefinition *pd(0);
2708           if(mmu)
2709             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2710           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2711           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2712         }
2713     }
2714 }
2715
2716 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2717 {
2718   copyTinyInfoFrom(mesh);
2719 }
2720
2721 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2722 {
2723   if(id>=(int)_pfls.size())
2724     _pfls.resize(id+1);
2725   _pfls[id]=DataArrayInt::New();
2726   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2727   _pfls[id]->setName(pflName);
2728   _pfls[id]->alloc(lgth,1);
2729   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2730   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2731 }
2732
2733 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2734 {
2735   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2736   int sz;
2737   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
2738   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2739   if(i>=(int)_pfls.size())
2740     _pfls.resize(i+1);
2741   _pfls[i]=DataArrayInt::New();
2742   _pfls[i]->alloc(sz,1);
2743   _pfls[i]->setName(pflCpp.c_str());
2744   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
2745   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2746 }
2747
2748 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2749 {
2750   int nbOfPfls=_pfls.size();
2751   for(int i=0;i<nbOfPfls;i++)
2752     {
2753       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
2754       cpy->applyLin(1,1,0);
2755       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2756       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2757       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
2758     }
2759   //
2760   int nbOfLocs=_locs.size();
2761   for(int i=0;i<nbOfLocs;i++)
2762     _locs[i]->writeLL(fid);
2763 }
2764
2765 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2766 {
2767   std::vector<std::string> pfls=getPfls();
2768   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2769     {
2770       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2771       if(it2==pfls.end())
2772         {
2773           _pfls.push_back(*it);
2774         }
2775       else
2776         {
2777           int id=std::distance(pfls.begin(),it2);
2778           if(!(*it)->isEqual(*_pfls[id]))
2779             {
2780               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2781               throw INTERP_KERNEL::Exception(oss.str());
2782             }
2783         }
2784     }
2785   std::vector<std::string> locs=getLocs();
2786   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2787     {
2788       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2789       if(it2==locs.end())
2790         {
2791           _locs.push_back(*it);
2792         }
2793       else
2794         {
2795           int id=std::distance(locs.begin(),it2);
2796           if(!(*it)->isEqual(*_locs[id],eps))
2797             {
2798               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2799               throw INTERP_KERNEL::Exception(oss.str());
2800             }
2801         }
2802     }
2803 }
2804
2805 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2806 {
2807   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2808     getProfile((*it).c_str());
2809 }
2810
2811 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2812 {
2813   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2814     getLocalization((*it).c_str());
2815 }
2816
2817 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2818 {
2819   std::vector<std::string> profiles=real.getPflsReallyUsed();
2820   int sz=profiles.size();
2821   _pfls.resize(sz);
2822   for(int i=0;i<sz;i++)
2823     loadProfileInFile(fid,i,profiles[i].c_str());
2824   //
2825   std::vector<std::string> locs=real.getLocsReallyUsed();
2826   sz=locs.size();
2827   _locs.resize(sz);
2828   for(int i=0;i<sz;i++)
2829     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2830 }
2831
2832 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2833 {
2834   int nProfil=MEDnProfile(fid);
2835   for(int i=0;i<nProfil;i++)
2836     loadProfileInFile(fid,i);
2837   int sz=MEDnLocalization(fid);
2838   _locs.resize(sz);
2839   for(int i=0;i<sz;i++)
2840     {
2841       _locs[i]=MEDFileFieldLoc::New(fid,i);
2842     }
2843 }
2844
2845 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
2846 {
2847   return new MEDFileFieldGlobs(fid);
2848 }
2849
2850 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2851 {
2852   return new MEDFileFieldGlobs;
2853 }
2854
2855 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2856 {
2857   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
2858 }
2859
2860 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2861 {
2862   std::vector<const BigMemoryObject *> ret;
2863   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2864     ret.push_back((const DataArrayInt *)*it);
2865   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2866     ret.push_back((const MEDFileFieldLoc *)*it);
2867   return ret;
2868 }
2869
2870 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
2871 {
2872   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2873   std::size_t i=0;
2874   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2875     {
2876       if((const DataArrayInt *)*it)
2877         ret->_pfls[i]=(*it)->deepCopy();
2878     }
2879   i=0;
2880   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2881     {
2882       if((const MEDFileFieldLoc*)*it)
2883         ret->_locs[i]=(*it)->deepCopy();
2884     }
2885   return ret.retn();
2886 }
2887
2888 /*!
2889  * \throw if a profile in \a pfls in not in \a this.
2890  * \throw if a localization in \a locs in not in \a this.
2891  * \sa MEDFileFieldGlobs::deepCpyPart
2892  */
2893 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2894 {
2895   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2896   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2897     {
2898       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2899       if(!pfl)
2900         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2901       pfl->incrRef();
2902       MCAuto<DataArrayInt> pfl2(pfl);
2903       ret->_pfls.push_back(pfl2);
2904     }
2905   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2906     {
2907       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2908       if(!loc)
2909         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2910       loc->incrRef();
2911       MCAuto<MEDFileFieldLoc> loc2(loc);
2912       ret->_locs.push_back(loc2);
2913     }
2914   ret->setFileName(getFileName());
2915   return ret.retn();
2916 }
2917
2918 /*!
2919  * \throw if a profile in \a pfls in not in \a this.
2920  * \throw if a localization in \a locs in not in \a this.
2921  * \sa MEDFileFieldGlobs::shallowCpyPart
2922  */
2923 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2924 {
2925   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2926   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2927     {
2928       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2929       if(!pfl)
2930         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2931       ret->_pfls.push_back(pfl->deepCopy());
2932     }
2933   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2934     {
2935       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2936       if(!loc)
2937         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2938       ret->_locs.push_back(loc->deepCopy());
2939     }
2940   ret->setFileName(getFileName());
2941   return ret.retn();
2942 }
2943
2944 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
2945 {
2946 }
2947
2948 MEDFileFieldGlobs::MEDFileFieldGlobs()
2949 {
2950 }
2951
2952 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2953 {
2954 }
2955
2956 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2957 {
2958   oss << "Profiles :\n";
2959   std::size_t n=_pfls.size();
2960   for(std::size_t i=0;i<n;i++)
2961     {
2962       oss << "  - #" << i << " ";
2963       const DataArrayInt *pfl=_pfls[i];
2964       if(pfl)
2965         oss << "\"" << pfl->getName() << "\"\n";
2966       else
2967         oss << "EMPTY !\n";
2968     }
2969   n=_locs.size();
2970   oss << "Localizations :\n";
2971   for(std::size_t i=0;i<n;i++)
2972     {
2973       oss << "  - #" << i << " ";
2974       const MEDFileFieldLoc *loc=_locs[i];
2975       if(loc)
2976         loc->simpleRepr(oss);
2977       else
2978         oss<< "EMPTY !\n";
2979     }
2980 }
2981
2982 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2983 {
2984   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2985     {
2986       DataArrayInt *elt(*it);
2987       if(elt)
2988         {
2989           std::string name(elt->getName());
2990           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2991             {
2992               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2993                 {
2994                   elt->setName((*it2).second.c_str());
2995                   return;
2996                 }
2997             }
2998         }
2999     }
3000 }
3001
3002 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3003 {
3004   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3005     {
3006       MEDFileFieldLoc *elt(*it);
3007       if(elt)
3008         {
3009           std::string name(elt->getName());
3010           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3011             {
3012               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3013                 {
3014                   elt->setName((*it2).second.c_str());
3015                   return;
3016                 }
3017             }
3018         }
3019     }
3020 }
3021
3022 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3023 {
3024   if(locId<0 || locId>=(int)_locs.size())
3025     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3026   return _locs[locId]->getNbOfGaussPtPerCell();
3027 }
3028
3029 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3030 {
3031   return getLocalizationFromId(getLocalizationId(locName));
3032 }
3033
3034 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3035 {
3036   if(locId<0 || locId>=(int)_locs.size())
3037     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3038   return *_locs[locId];
3039 }
3040
3041 /// @cond INTERNAL
3042 namespace MEDCouplingImpl
3043 {
3044   class LocFinder
3045   {
3046   public:
3047     LocFinder(const std::string& loc):_loc(loc) { }
3048     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3049   private:
3050     const std::string &_loc;
3051   };
3052
3053   class PflFinder
3054   {
3055   public:
3056     PflFinder(const std::string& pfl):_pfl(pfl) { }
3057     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3058   private:
3059     const std::string& _pfl;
3060   };
3061 }
3062 /// @endcond
3063
3064 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3065 {
3066   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3067   if(it==_locs.end())
3068     {
3069       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3070       for(it=_locs.begin();it!=_locs.end();it++)
3071         oss << "\"" << (*it)->getName() << "\", ";
3072       throw INTERP_KERNEL::Exception(oss.str());
3073     }
3074   return std::distance(_locs.begin(),it);
3075 }
3076
3077 /*!
3078  * The returned value is never null.
3079  */
3080 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3081 {
3082   std::string pflNameCpp(pflName);
3083   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3084   if(it==_pfls.end())
3085     {
3086       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3087       for(it=_pfls.begin();it!=_pfls.end();it++)
3088         oss << "\"" << (*it)->getName() << "\", ";
3089       throw INTERP_KERNEL::Exception(oss.str());
3090     }
3091   return *it;
3092 }
3093
3094 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3095 {
3096   if(pflId<0 || pflId>=(int)_pfls.size())
3097     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3098   return _pfls[pflId];
3099 }
3100
3101 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3102 {
3103   if(locId<0 || locId>=(int)_locs.size())
3104     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3105   return *_locs[locId];
3106 }
3107
3108 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3109 {
3110   return getLocalizationFromId(getLocalizationId(locName));
3111 }
3112
3113 /*!
3114  * The returned value is never null.
3115  */
3116 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3117 {
3118   std::string pflNameCpp(pflName);
3119   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3120   if(it==_pfls.end())
3121     {
3122       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3123       for(it=_pfls.begin();it!=_pfls.end();it++)
3124         oss << "\"" << (*it)->getName() << "\", ";
3125       throw INTERP_KERNEL::Exception(oss.str());
3126     }
3127   return *it;
3128 }
3129
3130 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3131 {
3132   if(pflId<0 || pflId>=(int)_pfls.size())
3133     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3134   return _pfls[pflId];
3135 }
3136
3137 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3138 {
3139   std::vector< MCAuto<DataArrayInt> > newPfls;
3140   int i=0;
3141   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3142     {
3143       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3144         newPfls.push_back(*it);
3145     }
3146   _pfls=newPfls;
3147 }
3148
3149 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3150 {
3151   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3152   int i=0;
3153   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3154     {
3155       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3156         newLocs.push_back(*it);
3157     }
3158   _locs=newLocs;
3159 }
3160
3161 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3162 {
3163   int sz=_pfls.size();
3164   std::vector<std::string> ret(sz);
3165   for(int i=0;i<sz;i++)
3166     ret[i]=_pfls[i]->getName();
3167   return ret;
3168 }
3169
3170 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3171 {
3172   int sz=_locs.size();
3173   std::vector<std::string> ret(sz);
3174   for(int i=0;i<sz;i++)
3175     ret[i]=_locs[i]->getName();
3176   return ret;
3177 }
3178
3179 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3180 {
3181   std::vector<std::string> v=getPfls();
3182   std::string s(pflName);
3183   return std::find(v.begin(),v.end(),s)!=v.end();
3184 }
3185
3186 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3187 {
3188   std::vector<std::string> v=getLocs();
3189   std::string s(locName);
3190   return std::find(v.begin(),v.end(),s)!=v.end();
3191 }
3192
3193 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3194 {
3195   std::map<int,std::vector<int> > m;
3196   int i=0;
3197   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3198     {
3199       const DataArrayInt *tmp=(*it);
3200       if(tmp)
3201         {
3202           m[tmp->getHashCode()].push_back(i);
3203         }
3204     }
3205   std::vector< std::vector<int> > ret;
3206   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3207     {
3208       if((*it2).second.size()>1)
3209         {
3210           std::vector<int> ret0;
3211           bool equalityOrNot=false;
3212           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3213             {
3214               std::vector<int>::const_iterator it4=it3; it4++;
3215               for(;it4!=(*it2).second.end();it4++)
3216                 {
3217                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3218                     {
3219                       if(!equalityOrNot)
3220                         ret0.push_back(*it3);
3221                       ret0.push_back(*it4);
3222                       equalityOrNot=true;
3223                     }
3224                 }
3225             }
3226           if(!ret0.empty())
3227             ret.push_back(ret0);
3228         }
3229     }
3230   return ret;
3231 }
3232
3233 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3234 {
3235   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3236 }
3237
3238 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3239 {
3240   std::string name(pfl->getName());
3241   if(name.empty())
3242     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3243   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3244     if(name==(*it)->getName())
3245       {
3246         if(!pfl->isEqual(*(*it)))
3247           {
3248             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3249             throw INTERP_KERNEL::Exception(oss.str());
3250           }
3251       }
3252   pfl->incrRef();
3253   _pfls.push_back(pfl);
3254 }
3255
3256 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)
3257 {
3258   std::string name(locName);
3259   if(name.empty())
3260     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3261   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3262   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3263     if((*it)->isName(locName))
3264       {
3265         if(!(*it)->isEqual(*obj,1e-12))
3266           {
3267             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3268             throw INTERP_KERNEL::Exception(oss.str());
3269           }
3270       }
3271   _locs.push_back(obj);
3272 }
3273
3274 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3275 {
3276   std::vector<std::string> names=getPfls();
3277   return CreateNewNameNotIn("NewPfl_",names);
3278 }
3279
3280 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3281 {
3282   std::vector<std::string> names=getLocs();
3283   return CreateNewNameNotIn("NewLoc_",names);
3284 }
3285
3286 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3287 {
3288   for(std::size_t sz=0;sz<100000;sz++)
3289     {
3290       std::ostringstream tryName;
3291       tryName << prefix << sz;
3292       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3293         return tryName.str();
3294     }
3295   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3296 }
3297
3298 /*!
3299  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3300  *  \param [in] fname - the file name.
3301  */
3302 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3303 {
3304 }
3305
3306 /*!
3307  * Creates an empty MEDFileFieldGlobsReal.
3308  */
3309 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3310 {
3311 }
3312
3313 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3314 {
3315   return 0;
3316 }
3317
3318 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3319 {
3320   std::vector<const BigMemoryObject *> ret;
3321   ret.push_back((const MEDFileFieldGlobs *)_globals);
3322   return ret;
3323 }
3324
3325 /*!
3326  * Returns a string describing profiles and Gauss points held in \a this.
3327  *  \return std::string - the description string.
3328  */
3329 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3330 {
3331   const MEDFileFieldGlobs *glob=_globals;
3332   std::ostringstream oss2; oss2 << glob;
3333   std::string stars(oss2.str().length(),'*');
3334   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3335   if(glob)
3336     glob->simpleRepr(oss);
3337   else
3338     oss << "NO GLOBAL INFORMATION !\n";
3339 }
3340
3341 void MEDFileFieldGlobsReal::resetContent()
3342 {
3343   _globals=MEDFileFieldGlobs::New();
3344 }
3345
3346 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3347 {
3348 }
3349
3350 /*!
3351  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3352  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3353  */
3354 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3355 {
3356   _globals=other._globals;
3357 }
3358
3359 /*!
3360  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3361  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3362  */
3363 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3364 {
3365   const MEDFileFieldGlobs *otherg(other._globals);
3366   if(!otherg)
3367     return ;
3368   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3369 }
3370
3371 /*!
3372  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3373  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3374  */
3375 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3376 {
3377   const MEDFileFieldGlobs *otherg(other._globals);
3378   if(!otherg)
3379     return ;
3380   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3381 }
3382
3383 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3384 {
3385   _globals=other._globals;
3386   if((const MEDFileFieldGlobs *)_globals)
3387     _globals=other._globals->deepCopy();
3388 }
3389
3390 /*!
3391  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3392  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3393  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3394  *         \a this and \a other MEDFileFieldGlobsReal.
3395  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3396  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3397  */
3398 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3399 {
3400   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3401   if(thisGlobals==otherGlobals)
3402     return ;
3403   if(!thisGlobals)
3404     {
3405       _globals=other._globals;
3406       return ;
3407     }
3408   _globals->appendGlobs(*other._globals,eps);
3409 }
3410
3411 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3412 {
3413   checkGlobsPflsPartCoherency();
3414   checkGlobsLocsPartCoherency();
3415 }
3416
3417 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3418 {
3419   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3420 }
3421
3422 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3423 {
3424   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3425 }
3426
3427 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3428 {
3429   contentNotNull()->loadProfileInFile(fid,id,pflName);
3430 }
3431
3432 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3433 {
3434   contentNotNull()->loadProfileInFile(fid,id);
3435 }
3436
3437 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3438 {
3439   contentNotNull()->loadGlobals(fid,*this);
3440 }
3441
3442 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3443 {
3444   contentNotNull()->loadAllGlobals(fid);
3445 }
3446
3447 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3448 {
3449   contentNotNull()->writeGlobals(fid,opt);
3450 }
3451
3452 /*!
3453  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3454  * or getPflsReallyUsedMulti().
3455  *  \return std::vector<std::string> - a sequence of names of all profiles.
3456  */
3457 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3458 {
3459   return contentNotNull()->getPfls();
3460 }
3461
3462 /*!
3463  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3464  * or getLocsReallyUsedMulti().
3465  *  \return std::vector<std::string> - a sequence of names of all localizations.
3466  */
3467 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3468 {
3469   return contentNotNull()->getLocs();
3470 }
3471
3472 /*!
3473  * Checks if the profile with a given name exists.
3474  *  \param [in] pflName - the profile name of interest.
3475  *  \return bool - \c true if the profile named \a pflName exists.
3476  */
3477 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3478 {
3479   return contentNotNull()->existsPfl(pflName);
3480 }
3481
3482 /*!
3483  * Checks if the localization with a given name exists.
3484  *  \param [in] locName - the localization name of interest.
3485  *  \return bool - \c true if the localization named \a locName exists.
3486  */
3487 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3488 {
3489   return contentNotNull()->existsLoc(locName);
3490 }
3491
3492 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3493 {
3494   return contentNotNull()->createNewNameOfPfl();
3495 }
3496
3497 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3498 {
3499   return contentNotNull()->createNewNameOfLoc();
3500 }
3501
3502 /*!
3503  * Sets the name of a MED file.
3504  *  \param [inout] fileName - the file name.
3505  */
3506 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3507 {
3508   contentNotNull()->setFileName(fileName);
3509 }
3510
3511 /*!
3512  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3513  * in the same order.
3514  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3515  *          Each item of this sequence is a vector containing ids of equal profiles.
3516  */
3517 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3518 {
3519   return contentNotNull()->whichAreEqualProfiles();
3520 }
3521
3522 /*!
3523  * Finds equal localizations.
3524  *  \param [in] eps - a precision used to compare real values of the localizations.
3525  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3526  *          Each item of this sequence is a vector containing ids of equal localizations.
3527  */
3528 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3529 {
3530   return contentNotNull()->whichAreEqualLocs(eps);
3531 }
3532
3533 /*!
3534  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3535  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3536  *        this sequence is a pair whose 
3537  *        - the first item is a vector of profile names to replace by the second item,
3538  *        - the second item is a profile name to replace every profile name of the first item.
3539  */
3540 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3541 {
3542   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3543 }
3544
3545 /*!
3546  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3547  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3548  *        this sequence is a pair whose 
3549  *        - the first item is a vector of localization names to replace by the second item,
3550  *        - the second item is a localization name to replace every localization name of the first item.
3551  */
3552 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3553 {
3554   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3555 }
3556
3557 /*!
3558  * Replaces references to some profiles (a reference is a profile name) by references
3559  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3560  * them-selves accordingly. <br>
3561  * This method is a generalization of changePflName().
3562  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3563  *        this sequence is a pair whose 
3564  *        - the first item is a vector of profile names to replace by the second item,
3565  *        - the second item is a profile name to replace every profile of the first item.
3566  * \sa changePflsRefsNamesGen()
3567  * \sa changePflName()
3568  */
3569 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3570 {
3571   changePflsRefsNamesGen(mapOfModif);
3572   changePflsNamesInStruct(mapOfModif);
3573 }
3574
3575 /*!
3576  * Replaces references to some localizations (a reference is a localization name) by references
3577  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3578  * them-selves accordingly. <br>
3579  * This method is a generalization of changeLocName().
3580  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3581  *        this sequence is a pair whose 
3582  *        - the first item is a vector of localization names to replace by the second item,
3583  *        - the second item is a localization name to replace every localization of the first item.
3584  * \sa changeLocsRefsNamesGen()
3585  * \sa changeLocName()
3586  */
3587 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3588 {
3589   changeLocsRefsNamesGen(mapOfModif);
3590   changeLocsNamesInStruct(mapOfModif);
3591 }
3592
3593 /*!
3594  * Renames the profile having a given name and updates references to this profile.
3595  *  \param [in] oldName - the name of the profile to rename.
3596  *  \param [in] newName - a new name of the profile.
3597  * \sa changePflsNames().
3598  */
3599 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3600 {
3601   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3602   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3603   mapOfModif[0]=p;
3604   changePflsNames(mapOfModif);
3605 }
3606
3607 /*!
3608  * Renames the localization having a given name and updates references to this localization.
3609  *  \param [in] oldName - the name of the localization to rename.
3610  *  \param [in] newName - a new name of the localization.
3611  * \sa changeLocsNames().
3612  */
3613 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3614 {
3615   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3616   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3617   mapOfModif[0]=p;
3618   changeLocsNames(mapOfModif);
3619 }
3620
3621 /*!
3622  * Removes duplicated profiles. Returns a map used to update references to removed 
3623  * profiles via changePflsRefsNamesGen().
3624  * Equal profiles are found using whichAreEqualProfiles().
3625  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3626  *          a sequence describing the performed replacements of profiles. Each element of
3627  *          this sequence is a pair whose
3628  *          - the first item is a vector of profile names replaced by the second item,
3629  *          - the second item is a profile name replacing every profile of the first item.
3630  */
3631 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3632 {
3633   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3634   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3635   int i=0;
3636   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3637     {
3638       std::vector< std::string > tmp((*it).size());
3639       int j=0;
3640       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3641         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3642       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3643       ret[i]=p;
3644       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3645       killProfileIds(tmp2);
3646     }
3647   changePflsRefsNamesGen(ret);
3648   return ret;
3649 }
3650
3651 /*!
3652  * Removes duplicated localizations. Returns a map used to update references to removed 
3653  * localizations via changeLocsRefsNamesGen().
3654  * Equal localizations are found using whichAreEqualLocs().
3655  *  \param [in] eps - a precision used to compare real values of the localizations.
3656  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3657  *          a sequence describing the performed replacements of localizations. Each element of
3658  *          this sequence is a pair whose
3659  *          - the first item is a vector of localization names replaced by the second item,
3660  *          - the second item is a localization name replacing every localization of the first item.
3661  */
3662 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3663 {
3664   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3665   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3666   int i=0;
3667   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3668     {
3669       std::vector< std::string > tmp((*it).size());
3670       int j=0;
3671       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3672         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3673       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3674       ret[i]=p;
3675       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3676       killLocalizationIds(tmp2);
3677     }
3678   changeLocsRefsNamesGen(ret);
3679   return ret;
3680 }
3681
3682 /*!
3683  * Returns number of Gauss points per cell in a given localization.
3684  *  \param [in] locId - an id of the localization of interest.
3685  *  \return int - the number of the Gauss points per cell.
3686  */
3687 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3688 {
3689   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3690 }
3691
3692 /*!
3693  * Returns an id of a localization by its name.
3694  *  \param [in] loc - the localization name of interest.
3695  *  \return int - the id of the localization.
3696  *  \throw If there is no a localization named \a loc.
3697  */
3698 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3699 {
3700   return contentNotNull()->getLocalizationId(loc);
3701 }
3702
3703 /*!
3704  * Returns the name of the MED file.
3705  *  \return const std::string&  - the MED file name.
3706  */
3707 std::string MEDFileFieldGlobsReal::getFileName() const
3708 {
3709   return contentNotNull()->getFileName();
3710 }
3711
3712 /*!
3713  * Returns a localization object by its name.
3714  *  \param [in] locName - the name of the localization of interest.
3715  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3716  *  \throw If there is no a localization named \a locName.
3717  */
3718 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3719 {
3720   return contentNotNull()->getLocalization(locName);
3721 }
3722
3723 /*!
3724  * Returns a localization object by its id.
3725  *  \param [in] locId - the id of the localization of interest.
3726  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3727  *  \throw If there is no a localization with id \a locId.
3728  */
3729 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3730 {
3731   return contentNotNull()->getLocalizationFromId(locId);
3732 }
3733
3734 /*!
3735  * Returns a profile array by its name.
3736  *  \param [in] pflName - the name of the profile of interest.
3737  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3738  *  \throw If there is no a profile named \a pflName.
3739  */
3740 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3741 {
3742   return contentNotNull()->getProfile(pflName);
3743 }
3744
3745 /*!
3746  * Returns a profile array by its id.
3747  *  \param [in] pflId - the id of the profile of interest.
3748  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3749  *  \throw If there is no a profile with id \a pflId.
3750  */
3751 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3752 {
3753   return contentNotNull()->getProfileFromId(pflId);
3754 }
3755
3756 /*!
3757  * Returns a localization object, apt for modification, by its id.
3758  *  \param [in] locId - the id of the localization of interest.
3759  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3760  *          having the id \a locId.
3761  *  \throw If there is no a localization with id \a locId.
3762  */
3763 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3764 {
3765   return contentNotNull()->getLocalizationFromId(locId);
3766 }
3767
3768 /*!
3769  * Returns a localization object, apt for modification, by its name.
3770  *  \param [in] locName - the name of the localization of interest.
3771  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3772  *          having the name \a locName.
3773  *  \throw If there is no a localization named \a locName.
3774  */
3775 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3776 {
3777   return contentNotNull()->getLocalization(locName);
3778 }
3779
3780 /*!
3781  * Returns a profile array, apt for modification, by its name.
3782  *  \param [in] pflName - the name of the profile of interest.
3783  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3784  *  \throw If there is no a profile named \a pflName.
3785  */
3786 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3787 {
3788   return contentNotNull()->getProfile(pflName);
3789 }
3790
3791 /*!
3792  * Returns a profile array, apt for modification, by its id.
3793  *  \param [in] pflId - the id of the profile of interest.
3794  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3795  *  \throw If there is no a profile with id \a pflId.
3796  */
3797 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3798 {
3799   return contentNotNull()->getProfileFromId(pflId);
3800 }
3801
3802 /*!
3803  * Removes profiles given by their ids. No data is updated to track this removal.
3804  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3805  */
3806 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3807 {
3808   contentNotNull()->killProfileIds(pflIds);
3809 }
3810
3811 /*!
3812  * Removes localizations given by their ids. No data is updated to track this removal.
3813  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3814  */
3815 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3816 {
3817   contentNotNull()->killLocalizationIds(locIds);
3818 }
3819
3820 /*!
3821  * Stores a profile array.
3822  *  \param [in] pfl - the profile array to store.
3823  *  \throw If the name of \a pfl is empty.
3824  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3825  *         different ids.
3826  */
3827 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3828 {
3829   contentNotNull()->appendProfile(pfl);
3830 }
3831
3832 /*!
3833  * Adds a new localization of Gauss points.
3834  *  \param [in] locName - the name of the new localization.
3835  *  \param [in] geoType - a geometrical type of the reference cell.
3836  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3837  *         must be \c nbOfNodesPerCell * \c dimOfType.
3838  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3839  *         must be  _wg_.size() * \c dimOfType.
3840  *  \param [in] w - the weights of Gauss points.
3841  *  \throw If \a locName is empty.
3842  *  \throw If a localization with the name \a locName already exists but is
3843  *         different form the new one.
3844  */
3845 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)
3846 {
3847   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3848 }
3849
3850 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3851 {
3852   MEDFileFieldGlobs *g(_globals);
3853   if(!g)
3854     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3855   return g;
3856 }
3857
3858 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3859 {
3860   const MEDFileFieldGlobs *g(_globals);
3861   if(!g)
3862     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3863   return g;
3864 }
3865
3866 //= MEDFileFieldNameScope
3867
3868 MEDFileFieldNameScope::MEDFileFieldNameScope()
3869 {
3870 }
3871
3872 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3873 {
3874 }
3875
3876 /*!
3877  * Returns the name of \a this field.
3878  *  \return std::string - a string containing the field name.
3879  */
3880 std::string MEDFileFieldNameScope::getName() const
3881 {
3882   return _name;
3883 }
3884
3885 /*!
3886  * Sets name of \a this field
3887  *  \param [in] name - the new field name.
3888  */
3889 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3890 {
3891   _name=fieldName;
3892 }
3893
3894 std::string MEDFileFieldNameScope::getDtUnit() const
3895 {
3896   return _dt_unit;
3897 }
3898
3899 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3900 {
3901   _dt_unit=dtUnit;
3902 }
3903
3904 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3905 {
3906   _name=other._name;
3907   _dt_unit=other._dt_unit;
3908 }
3909
3910 //= MEDFileAnyTypeField1TSWithoutSDA
3911
3912 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3913 {
3914   _field_per_mesh.resize(other._field_per_mesh.size());
3915   std::size_t i=0;
3916   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3917     {
3918       if((const MEDFileFieldPerMesh *)*it)
3919         _field_per_mesh[i]=(*it)->deepCopy(this);
3920     }
3921 }
3922
3923 /*!
3924  * Prints a string describing \a this field into a stream. This string is outputted 
3925  * by \c print Python command.
3926  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3927  *  \param [in,out] oss - the out stream.
3928  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3929  *          info id printed, else, not.
3930  */
3931 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3932 {
3933   std::string startOfLine(bkOffset,' ');
3934   oss << startOfLine << "Field ";
3935   if(bkOffset==0)
3936     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3937   oss << "on one time Step ";
3938   if(f1tsId>=0)
3939     oss << "(" << f1tsId << ") ";
3940   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3941   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3942   const DataArray *arr=getUndergroundDataArray();
3943   if(arr)
3944     {
3945       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3946       if(f1tsId<0)
3947         {
3948           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3949           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3950             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3951         }
3952       if(arr->isAllocated())
3953         {
3954           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3955         }
3956       else
3957         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3958     }
3959   else
3960     {
3961       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3962     }
3963   oss << startOfLine << "----------------------" << std::endl;
3964   if(!_field_per_mesh.empty())
3965     {
3966       int i=0;
3967       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3968         {
3969           const MEDFileFieldPerMesh *cur=(*it2);
3970           if(cur)
3971             cur->simpleRepr(bkOffset,oss,i);
3972           else
3973             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3974         }
3975     }
3976   else
3977     {
3978       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3979     }
3980   oss << startOfLine << "----------------------" << std::endl;
3981 }
3982
3983 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3984 {
3985   const DataArray *arr(getUndergroundDataArray());
3986   if(!arr)
3987     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3988   int nbOfCompo=arr->getNumberOfComponents();
3989   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3990   for(int i=0;i<nbOfCompo;i++)
3991     {
3992       ret[i]=deepCopy();
3993       std::vector<int> v(1,i);
3994       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
3995       ret[i]->setArray(arr2);
3996     }
3997   return ret;
3998 }
3999
4000 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)
4001 {
4002 }
4003
4004 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4005 {
4006 }
4007
4008 /*!
4009  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4010  * empty. Returns -1 if this in on nodes.
4011  *  \return int - the dimension of \a this.
4012  */
4013 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4014 {
4015   int ret=-2;
4016   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4017     (*it)->getDimension(ret);
4018   return ret;
4019 }
4020
4021 /*!
4022  * Returns the mesh name.
4023  *  \return std::string - a string holding the mesh name.
4024  *  \throw If \c _field_per_mesh.empty()
4025  */
4026 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
4027 {
4028   if(_field_per_mesh.empty())
4029     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
4030   return _field_per_mesh[0]->getMeshName();
4031 }
4032
4033 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
4034 {
4035   std::string oldName(getMeshName());
4036   std::vector< std::pair<std::string,std::string> > v(1);
4037   v[0].first=oldName; v[0].second=newMeshName;
4038   changeMeshNames(v);
4039 }
4040
4041 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4042 {
4043   bool ret=false;
4044   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4045     {
4046       MEDFileFieldPerMesh *cur(*it);
4047       if(cur)
4048         ret=cur->changeMeshNames(modifTab) || ret;
4049     }
4050   return ret;
4051 }
4052
4053 /*!
4054  * Returns the number of iteration of the state of underlying mesh.
4055  *  \return int - the iteration number.
4056  *  \throw If \c _field_per_mesh.empty()
4057  */
4058 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4059 {
4060   if(_field_per_mesh.empty())
4061     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4062   return _field_per_mesh[0]->getMeshIteration();
4063 }
4064
4065 /*!
4066  * Returns the order number of iteration of the state of underlying mesh.
4067  *  \return int - the order number.
4068  *  \throw If \c _field_per_mesh.empty()
4069  */
4070 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4071 {
4072   if(_field_per_mesh.empty())
4073     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4074   return _field_per_mesh[0]->getMeshOrder();
4075 }
4076
4077 /*!
4078  * Checks if \a this field is tagged by a given iteration number and a given
4079  * iteration order number.
4080  *  \param [in] iteration - the iteration number of interest.
4081  *  \param [in] order - the iteration order number of interest.
4082  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4083  *          \a this->getOrder() == \a order.
4084  */
4085 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4086 {
4087   return iteration==_iteration && order==_order;
4088 }
4089
4090 /*!
4091  * Returns number of iteration and order number of iteration when
4092  * \a this field has been calculated.
4093  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4094  *          order number.
4095  */
4096 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4097 {
4098   std::pair<int,int> p;
4099   fillIteration(p);
4100   return p;
4101 }
4102
4103 /*!
4104  * Returns number of iteration and order number of iteration when
4105  * \a this field has been calculated.
4106  *  \param [in,out] p - a pair returning the iteration number and the iteration
4107  *          order number.
4108  */
4109 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4110 {
4111   p.first=_iteration;
4112   p.second=_order;
4113 }
4114
4115 /*!
4116  * Returns all types of spatial discretization of \a this field.
4117  *  \param [in,out] types - a sequence of types of \a this field.
4118  */
4119 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4120 {
4121   std::set<TypeOfField> types2;
4122   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4123     {
4124       (*it)->fillTypesOfFieldAvailable(types2);
4125     }
4126   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4127   std::copy(types2.begin(),types2.end(),bi);
4128 }
4129
4130 /*!
4131  * Returns all types of spatial discretization of \a this field.
4132  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4133  *          of \a this field.
4134  */
4135 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4136 {
4137   std::vector<TypeOfField> ret;
4138   fillTypesOfFieldAvailable(ret);
4139   return ret;
4140 }
4141
4142 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4143 {
4144   std::vector<std::string> ret;
4145   std::set<std::string> ret2;
4146   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4147     {
4148       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4149       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4150         if(ret2.find(*it2)==ret2.end())
4151           {
4152             ret.push_back(*it2);
4153             ret2.insert(*it2);
4154           }
4155     }
4156   return ret;
4157 }
4158
4159 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4160 {
4161   std::vector<std::string> ret;
4162   std::set<std::string> ret2;
4163   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4164     {
4165       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4166       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4167         if(ret2.find(*it2)==ret2.end())
4168           {
4169             ret.push_back(*it2);
4170             ret2.insert(*it2);
4171           }
4172     }
4173   return ret;
4174 }
4175
4176 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4177 {
4178   std::vector<std::string> ret;
4179   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4180     {
4181       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4182       ret.insert(ret.end(),tmp.begin(),tmp.end());
4183     }
4184   return ret;
4185 }
4186
4187 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4188 {
4189   std::vector<std::string> ret;
4190   std::set<std::string> ret2;
4191   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4192     {
4193       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4194       ret.insert(ret.end(),tmp.begin(),tmp.end());
4195     }
4196   return ret;
4197 }
4198
4199 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4200 {
4201   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4202     (*it)->changePflsRefsNamesGen(mapOfModif);
4203 }
4204
4205 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4206 {
4207   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4208     (*it)->changeLocsRefsNamesGen(mapOfModif);
4209 }
4210
4211 /*!
4212  * Returns all attributes of parts of \a this field lying on a given mesh.
4213  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4214  * item of every of returned sequences refers to the _i_-th part of \a this field.
4215  * Thus all sequences returned by this method are of the same length equal to number
4216  * of different types of supporting entities.<br>
4217  * A field part can include sub-parts with several different spatial discretizations,
4218  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4219  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4220  * of a nested sequence corresponds to a type of spatial discretization.<br>
4221  * This method allows for iteration over MEDFile DataStructure without any overhead.
4222  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4223  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4224  *          not checked if \a mname == \c NULL).
4225  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4226  *          a field part is returned. 
4227  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4228  *          This sequence is of the same length as \a types. 
4229  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4230  *          discretization. A profile name can be empty.
4231  *          Length of this and of nested sequences is the same as that of \a typesF.
4232  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4233  *          discretization. A localization name can be empty.
4234  *          Length of this and of nested sequences is the same as that of \a typesF.
4235  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4236  *          of ids of tuples within the data array, per each type of spatial
4237  *          discretization within one mesh entity type. 
4238  *          Length of this and of nested sequences is the same as that of \a typesF.
4239  *  \throw If no field is lying on \a mname.
4240  */
4241 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
4242 {
4243   int meshId=0;
4244   if(!mname.empty())
4245     meshId=getMeshIdFromMeshName(mname);
4246   else
4247     if(_field_per_mesh.empty())
4248       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4249   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4250 }
4251
4252 /*!
4253  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4254  * maximal absolute dimension and values returned via the out parameter \a levs are 
4255  * dimensions relative to the maximal absolute dimension. <br>
4256  * This method is designed for MEDFileField1TS instances that have a discretization
4257  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4258  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4259  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4260  * Only these 3 discretizations will be taken into account here. If \a this is
4261  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4262  * This method is useful to make the link between the dimension of the underlying mesh
4263  * and the levels of \a this, because it is possible that the highest dimension of \a this
4264  * field is not equal to the dimension of the underlying mesh.
4265  * 
4266  * Let's consider the following case:
4267  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4268  * TETRA4, HEXA8, TRI3 and SEG2.
4269  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4270  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4271  *
4272  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4273  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4274  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4275  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4276  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4277  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4278  * For example<br>
4279  * to retrieve the highest level of
4280  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4281  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4282  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4283  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4284  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4285  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4286  *          not checked if \a mname == \c NULL).
4287  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4288  *          absolute one. They are in decreasing order. This sequence is cleared before
4289  *          filling it in.
4290  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4291  *  \throw If no field is lying on \a mname.
4292  */
4293 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4294 {
4295   levs.clear();
4296   int meshId=getMeshIdFromMeshName(mname);
4297   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4298   std::vector< std::vector<TypeOfField> > typesF;
4299   std::vector< std::vector<std::string> > pfls, locs;
4300   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4301   if(types.empty())
4302     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4303   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4304   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4305     return -1;
4306   st.erase(INTERP_KERNEL::NORM_ERROR);
4307   std::set<int> ret1;
4308   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4309     {
4310       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4311       ret1.insert((int)cm.getDimension());
4312     }
4313   int ret=*std::max_element(ret1.begin(),ret1.end());
4314   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4315   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4316   return ret;
4317 }
4318
4319 /*!
4320  * \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.
4321  * \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.
4322  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4323  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4324  */
4325 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4326 {
4327   int mid=getMeshIdFromMeshName(mName);
4328   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4329 }
4330
4331 /*!
4332  * \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.
4333  * \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.
4334  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4335  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4336  */
4337 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4338 {
4339   int mid=getMeshIdFromMeshName(mName);
4340   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4341 }
4342
4343 /*!
4344  * \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.
4345  */
4346 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4347 {
4348   if(_field_per_mesh.empty())
4349     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4350   if(mName.empty())
4351     return 0;
4352   std::string mName2(mName);
4353   int ret=0;
4354   std::vector<std::string> msg;
4355   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4356     if(mName2==(*it)->getMeshName())
4357       return ret;
4358     else
4359       msg.push_back((*it)->getMeshName());
4360   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4361   oss << "Possible meshes are : ";
4362   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4363     oss << "\"" << (*it2) << "\" ";
4364   throw INTERP_KERNEL::Exception(oss.str());
4365 }
4366
4367 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4368 {
4369   if(!mesh)
4370     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4371   std::string tmp(mesh->getName());
4372   if(tmp.empty())
4373     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4374   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4375   int i=0;
4376   for(;it!=_field_per_mesh.end();it++,i++)
4377     {
4378       if((*it)->getMeshName()==tmp)
4379         return i;
4380     }
4381   int sz=_field_per_mesh.size();
4382   _field_per_mesh.resize(sz+1);
4383   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4384   return sz;
4385 }
4386
4387 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4388                                                                    MEDFileFieldGlobsReal& glob)
4389 {
4390   bool ret=false;
4391   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4392     {
4393       MEDFileFieldPerMesh *fpm(*it);
4394       if(fpm)
4395         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4396     }
4397   return ret;
4398 }
4399
4400 /*!
4401  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4402  * splitting that leads to single spatial discretization of this.
4403  *
4404  * \sa splitMultiDiscrPerGeoTypes
4405  */
4406 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4407 {
4408   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4409   std::vector< std::vector<TypeOfField> > typesF;
4410   std::vector< std::vector<std::string> > pfls,locs;
4411   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4412   std::set<TypeOfField> allEnt;
4413   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4414     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4415       allEnt.insert(*it2);
4416   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4417   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4418   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4419     {
4420       std::vector< std::pair<int,int> > its;
4421       ret[i]=shallowCpy();
4422       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4423       ret[i]->updateData(newLgth,its);
4424     }
4425   return ret;
4426 }
4427
4428 /*!
4429  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4430  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4431  *
4432  * \sa splitDiscretizations
4433  */
4434 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4435 {
4436   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4437   std::vector< std::vector<TypeOfField> > typesF;
4438   std::vector< std::vector<std::string> > pfls,locs;
4439   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4440   std::set<TypeOfField> allEnt;
4441   std::size_t nbOfMDPGT(0),ii(0);
4442   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4443     {
4444       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4445       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4446         allEnt.insert(*it2);
4447     }
4448   if(allEnt.size()!=1)
4449     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4450   if(nbOfMDPGT==0)
4451     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4452   if(nbOfMDPGT==1)
4453     {
4454       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4455       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4456       return ret0;
4457     }
4458   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4459   for(std::size_t i=0;i<nbOfMDPGT;i++)
4460     {
4461       std::vector< std::pair<int,int> > its;
4462       ret[i]=shallowCpy();
4463       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4464       ret[i]->updateData(newLgth,its);
4465     }
4466   return ret;
4467 }
4468
4469 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4470 {
4471   int globalCounter(0);
4472   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4473     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4474   return globalCounter;
4475 }
4476
4477 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4478 {
4479   int globalCounter(0);
4480   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4481     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4482   return globalCounter;
4483 }
4484
4485 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4486 {
4487   if(_nb_of_tuples_to_be_allocated>=0)
4488     {
4489       _nb_of_tuples_to_be_allocated=newLgth;
4490       const DataArray *oldArr(getUndergroundDataArray());
4491       if(oldArr)
4492         {
4493           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4494           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4495           setArray(newArr);
4496           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4497         }
4498       return ;
4499     }
4500   if(_nb_of_tuples_to_be_allocated==-1)
4501     return ;
4502   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4503     {
4504       const DataArray *oldArr(getUndergroundDataArray());
4505       if(!oldArr || !oldArr->isAllocated())
4506         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4507       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4508       newArr->alloc(newLgth,getNumberOfComponents());
4509       if(oldArr)
4510         newArr->copyStringInfoFrom(*oldArr);
4511       int pos=0;
4512       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4513         {
4514           if((*it).second<(*it).first)
4515             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4516           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4517           pos+=(*it).second-(*it).first;
4518         }
4519       setArray(newArr);
4520       return ;
4521     }
4522   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4523 }
4524
4525 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4526 {
4527   if(_field_per_mesh.empty())
4528     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4529   if(_field_per_mesh.size()>1)
4530     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4531   _field_per_mesh[0]->copyOptionsFrom(opts);
4532   _field_per_mesh[0]->writeLL(fid,nasc);
4533 }
4534
4535 /*!
4536  * 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.
4537  * If false is returned the memory allocation is not required.
4538  */
4539 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4540 {
4541   if(_nb_of_tuples_to_be_allocated>=0)
4542     {
4543       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4544       _nb_of_tuples_to_be_allocated=-2;
4545       return true;
4546     }
4547   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4548     return false;
4549   if(_nb_of_tuples_to_be_allocated==-1)
4550     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4551   if(_nb_of_tuples_to_be_allocated<-3)
4552     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4553   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4554 }
4555
4556 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4557 {
4558   med_int numdt,numit;
4559   med_float dt;
4560   med_int nmesh;
4561   med_bool localMesh;
4562   med_int meshnumdt,meshnumit;
4563   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4564   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4565   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4566   if(_iteration!=numdt || _order!=numit)
4567     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4568   _field_per_mesh.resize(nmesh);
4569   //
4570   MEDFileMesh *mm(0);
4571   if(ms)
4572     {
4573       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4574       mm=ms->getMeshWithName(meshNameCpp);
4575     }
4576   //
4577   for(int i=0;i<nmesh;i++)
4578     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4579   _nb_of_tuples_to_be_allocated=0;
4580   for(int i=0;i<nmesh;i++)
4581     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4582 }
4583
4584 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4585 {
4586   allocIfNecessaryTheArrayToReceiveDataFromFile();
4587   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4588     (*it)->loadBigArraysRecursively(fid,nasc);
4589 }
4590
4591 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4592 {
4593   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4594     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4595       (*it)->loadBigArraysRecursively(fid,nasc);
4596 }
4597
4598 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4599 {
4600   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4601   loadBigArraysRecursively(fid,nasc);
4602 }
4603
4604 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4605 {
4606   DataArray *thisArr(getUndergroundDataArray());
4607   if(thisArr && thisArr->isAllocated())
4608     {
4609       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4610       thisArr->desallocate();
4611     }
4612 }
4613
4614 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4615 {
4616   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
4617 }
4618
4619 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4620 {
4621   std::vector<const BigMemoryObject *> ret;
4622   if(getUndergroundDataArray())
4623     ret.push_back(getUndergroundDataArray());
4624   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4625     ret.push_back((const MEDFileFieldPerMesh *)*it);
4626   return ret;
4627 }
4628
4629 /*!
4630  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4631  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4632  * "Sort By Type"), if not, an exception is thrown. 
4633  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4634  *  \param [in] arr - the array of values.
4635  *  \param [in,out] glob - the global data where profiles and localization present in
4636  *          \a field, if any, are added.
4637  *  \throw If the name of \a field is empty.
4638  *  \throw If the data array of \a field is not set.
4639  *  \throw If \a this->_arr is already allocated but has different number of components
4640  *         than \a field.
4641  *  \throw If the underlying mesh of \a field has no name.
4642  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4643  */
4644 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4645 {
4646   const MEDCouplingMesh *mesh=field->getMesh();
4647   //
4648   TypeOfField type=field->getTypeOfField();
4649   std::vector<DataArrayInt *> dummy;
4650   int start=copyTinyInfoFrom(field,arr);
4651   int pos=addNewEntryIfNecessary(mesh);
4652   if(type!=ON_NODES)
4653     {
4654       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4655       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4656     }
4657   else
4658     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4659 }
4660
4661 /*!
4662  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4663  * of a given mesh are used as the support of the given field (a real support is not used). 
4664  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4665  * Order of underlying mesh entities of the given field specified by \a profile parameter
4666  * is not prescribed; this method permutes field values to have them sorted by element
4667  * type as required for writing to MED file. A new profile is added only if no equal
4668  * profile is missing. 
4669  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4670  *  \param [in] arrOfVals - the values of the field \a field used.
4671  *  \param [in] mesh - the supporting mesh of \a field.
4672  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4673  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4674  *  \param [in,out] glob - the global data where profiles and localization present in
4675  *          \a field, if any, are added.
4676  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4677  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4678  *  \throw If the data array of \a field is not set.
4679  *  \throw If \a this->_arr is already allocated but has different number of components
4680  *         than \a field.
4681  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4682  *  \sa setFieldNoProfileSBT()
4683  */
4684 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4685 {
4686   if(!field)
4687     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4688   if(!arrOfVals || !arrOfVals->isAllocated())
4689     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4690   TypeOfField type=field->getTypeOfField();
4691   std::vector<DataArrayInt *> idsInPflPerType;
4692   std::vector<DataArrayInt *> idsPerType;
4693   std::vector<int> code,code2;
4694   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4695   if(type!=ON_NODES)
4696     {
4697       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4698       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4699       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4700       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4701       // start of check
4702       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
4703       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4704       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4705         {
4706           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4707           throw INTERP_KERNEL::Exception(oss.str());
4708         }
4709       // end of check
4710       int start=copyTinyInfoFrom(field,arrOfVals);
4711       code2=m->getDistributionOfTypes();
4712       //
4713       int pos=addNewEntryIfNecessary(m);
4714       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4715     }
4716   else
4717     {
4718       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4719         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4720       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4721       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4722       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4723       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4724         {
4725           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4726           throw INTERP_KERNEL::Exception(oss.str());
4727         }
4728       int start=copyTinyInfoFrom(field,arrOfVals);
4729       int pos=addNewEntryIfNecessary(m);
4730       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4731     }
4732 }
4733
4734 /*!
4735  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4736  */
4737 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4738 {
4739   if(_nb_of_tuples_to_be_allocated>=0)
4740     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 !");
4741   DataArray *arr(getOrCreateAndGetArray());
4742   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4743   _nb_of_tuples_to_be_allocated=-3;
4744 }
4745
4746 /*!
4747  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4748  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4749  * larger by the size of \a field. Returns an id of the first not filled
4750  * tuple of \a this->_arr.
4751  *  \param [in] field - the field to copy the info on components and the name from.
4752  *  \return int - the id of first not initialized tuple of \a this->_arr.
4753  *  \throw If the name of \a field is empty.
4754  *  \throw If the data array of \a field is not set.
4755  *  \throw If \a this->_arr is already allocated but has different number of components
4756  *         than \a field.
4757  */
4758 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4759 {
4760   if(!field)
4761     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4762   std::string name(field->getName());
4763   setName(name.c_str());
4764   setDtUnit(field->getTimeUnit());
4765   if(name.empty())
4766     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4767   if(!arr)
4768     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4769   if(!arr->isAllocated())
4770     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4771   _dt=field->getTime(_iteration,_order);
4772   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4773   if(!getOrCreateAndGetArray()->isAllocated())
4774     {
4775       allocNotFromFile(arr->getNumberOfTuples());
4776       return 0;
4777     }
4778   else
4779     {
4780       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4781       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4782       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4783       _nb_of_tuples_to_be_allocated=-3;
4784       return oldNbOfTuples;
4785     }
4786 }
4787
4788 /*!
4789  * Returns number of components in \a this field
4790  *  \return int - the number of components.
4791  */
4792 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4793 {
4794   return getOrCreateAndGetArray()->getNumberOfComponents();
4795 }
4796
4797 /*!
4798  * Change info on components in \a this.
4799  * \throw If size of \a infos is not equal to the number of components already in \a this.
4800  */
4801 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4802 {
4803   DataArray *arr=getOrCreateAndGetArray();
4804   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4805 }
4806
4807 /*!
4808  * Returns info on components of \a this field.
4809  *  \return const std::vector<std::string>& - a sequence of strings each being an
4810  *          information on _i_-th component.
4811  */
4812 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4813 {
4814   const DataArray *arr=getOrCreateAndGetArray();
4815   return arr->getInfoOnComponents();
4816 }
4817
4818 /*!
4819  * Returns a mutable info on components of \a this field.
4820  *  \return std::vector<std::string>& - a sequence of strings each being an
4821  *          information on _i_-th component.
4822  */
4823 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4824 {
4825   DataArray *arr=getOrCreateAndGetArray();
4826   return arr->getInfoOnComponents();
4827 }
4828
4829 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4830 {
4831   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4832     {
4833       const MEDFileFieldPerMesh *fpm(*it);
4834       if(!fpm)
4835         continue;
4836       if(fpm->presenceOfMultiDiscPerGeoType())
4837         return true;
4838     }
4839   return false;
4840 }
4841
4842 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4843 {
4844   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 !";
4845   if(_field_per_mesh.empty())
4846     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
4847   if(_field_per_mesh.size()>1)
4848     throw INTERP_KERNEL::Exception(MSG0);
4849   if(_field_per_mesh[0].isNull())
4850     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
4851   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
4852   std::set<TypeOfField> types;
4853   pm->fillTypesOfFieldAvailable(types);
4854   if(types.size()!=1)
4855     throw INTERP_KERNEL::Exception(MSG0);
4856   TypeOfField type(*types.begin());
4857   int meshDimRelToMax(0);
4858   if(type==ON_NODES)
4859     meshDimRelToMax=0;
4860   else
4861     {
4862       int myDim(std::numeric_limits<int>::max());
4863       bool isUnique(pm->isUniqueLevel(myDim));
4864       if(!isUnique)
4865         throw INTERP_KERNEL::Exception(MSG0);
4866       meshDimRelToMax=myDim-mesh->getMeshDimension();
4867       if(meshDimRelToMax>0)
4868         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
4869     }
4870   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
4871 }
4872
4873 /*!
4874  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4875  *  \param [in] type - a spatial discretization of the new field.
4876  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4877  *  \param [in] mName - a name of the supporting mesh.
4878  *  \param [in] renumPol - specifies how to permute values of the result field according to
4879  *          the optional numbers of cells and nodes, if any. The valid values are
4880  *          - 0 - do not permute.
4881  *          - 1 - permute cells.
4882  *          - 2 - permute nodes.
4883  *          - 3 - permute cells and nodes.
4884  *
4885  *  \param [in] glob - the global data storing profiles and localization.
4886  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4887  *          caller is to delete this field using decrRef() as it is no more needed. 
4888  *  \throw If the MED file is not readable.
4889  *  \throw If there is no mesh named \a mName in the MED file.
4890  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4891  *  \throw If no field of \a this is lying on the mesh \a mName.
4892  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4893  */
4894 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4895 {
4896   MCAuto<MEDFileMesh> mm;
4897   if(mName.empty())
4898     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4899   else
4900     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4901   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4902 }
4903
4904 /*!
4905  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4906  *  \param [in] type - a spatial discretization of the new field.
4907  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4908  *  \param [in] renumPol - specifies how to permute values of the result field according to
4909  *          the optional numbers of cells and nodes, if any. The valid values are
4910  *          - 0 - do not permute.
4911  *          - 1 - permute cells.
4912  *          - 2 - permute nodes.
4913  *          - 3 - permute cells and nodes.
4914  *
4915  *  \param [in] glob - the global data storing profiles and localization.
4916  *  \param [in] mesh - the supporting mesh.
4917  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4918  *          caller is to delete this field using decrRef() as it is no more needed. 
4919  *  \throw If the MED file is not readable.
4920  *  \throw If no field of \a this is lying on \a mesh.
4921  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4922  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4923  */
4924 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4925 {
4926   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
4927   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
4928   if(meshDimRelToMax==1)
4929     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4930   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4931 }
4932
4933 /*!
4934  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4935  * given mesh. 
4936  *  \param [in] type - a spatial discretization of the new field.
4937  *  \param [in] mName - a name of the supporting mesh.
4938  *  \param [in] renumPol - specifies how to permute values of the result field according to
4939  *          the optional numbers of cells and nodes, if any. The valid values are
4940  *          - 0 - do not permute.
4941  *          - 1 - permute cells.
4942  *          - 2 - permute nodes.
4943  *          - 3 - permute cells and nodes.
4944  *
4945  *  \param [in] glob - the global data storing profiles and localization.
4946  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4947  *          caller is to delete this field using decrRef() as it is no more needed. 
4948  *  \throw If the MED file is not readable.
4949  *  \throw If there is no mesh named \a mName in the MED file.
4950  *  \throw If there are no mesh entities in the mesh.
4951  *  \throw If no field values of the given \a type are available.
4952  */
4953 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4954 {
4955   MCAuto<MEDFileMesh> mm;
4956   if(mName.empty())
4957     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4958   else
4959     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4960   int absDim=getDimension();
4961   int meshDimRelToMax=absDim-mm->getMeshDimension();
4962   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4963 }
4964
4965 /*!
4966  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4967  *  \param [in] type - a spatial discretization of the new field.
4968  *  \param [in] renumPol - specifies how to permute values of the result field according to
4969  *          the optional numbers of cells and nodes, if any. The valid values are
4970  *          - 0 - do not permute.
4971  *          - 1 - permute cells.
4972  *          - 2 - permute nodes.
4973  *          - 3 - permute cells and nodes.
4974  *
4975  *  \param [in] glob - the global data storing profiles and localization.
4976  *  \param [in] mesh - the supporting mesh.
4977  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4978  *         field according to \a renumPol.
4979  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4980  *         field according to \a renumPol.
4981  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4982  *          caller is to delete this field using decrRef() as it is no more needed. 
4983  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4984  *  \throw If no field of \a this is lying on \a mesh.
4985  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4986  */
4987 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
4988 {
4989   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4990   int meshId=getMeshIdFromMeshName(mesh->getName());
4991   bool isPfl=false;
4992   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4993   switch(renumPol)
4994   {
4995     case 0:
4996       {
4997         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4998         return ret.retn();
4999       }
5000     case 3:
5001     case 1:
5002       {
5003         if(isPfl)
5004           throw INTERP_KERNEL::Exception(msg1);
5005         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5006         if(cellRenum)
5007           {
5008             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5009               {
5010                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5011                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5012                 throw INTERP_KERNEL::Exception(oss.str());
5013               }
5014             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5015             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5016             std::vector<DataArray *> arrOut2(1,arrOut);
5017             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5018             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5019             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5020           }
5021         if(renumPol==1)
5022           return ret.retn();
5023       }
5024     case 2:
5025       {
5026         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5027         if(isPfl)
5028           throw INTERP_KERNEL::Exception(msg1);
5029         if(nodeRenum)
5030           {
5031             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5032               {
5033                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5034                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5035                 throw INTERP_KERNEL::Exception(oss.str());
5036               }
5037             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5038             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5039               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5040             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5041           }
5042         return ret.retn();
5043       }
5044     default:
5045       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5046   }
5047 }
5048
5049 /*!
5050  * Returns values and a profile of the field of a given type lying on a given support.
5051  *  \param [in] type - a spatial discretization of the field.
5052  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5053  *  \param [in] mesh - the supporting mesh.
5054  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5055  *          field of interest lies on. If the field lies on all entities of the given
5056  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5057  *          using decrRef() as it is no more needed.  
5058  *  \param [in] glob - the global data storing profiles and localization.
5059  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5060  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5061  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5062  *  \throw If no field of \a this is lying on \a mesh.
5063  *  \throw If no field values of the given \a type are available.
5064  */
5065 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5066 {
5067   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5068   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
5069   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5070   ret->setName(nasc.getName().c_str());
5071   return ret.retn();
5072 }
5073
5074 //= MEDFileField1TSWithoutSDA
5075
5076 /*!
5077  * Throws if a given value is not a valid (non-extended) relative dimension.
5078  *  \param [in] meshDimRelToMax - the relative dimension value.
5079  *  \throw If \a meshDimRelToMax > 0.
5080  */
5081 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5082 {
5083   if(meshDimRelToMax>0)
5084     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5085 }
5086
5087 /*!
5088  * Checks if elements of a given mesh are in the order suitable for writing 
5089  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5090  * vector describing types of elements and their number.
5091  *  \param [in] mesh - the mesh to check.
5092  *  \return std::vector<int> - a vector holding for each element type (1) item of
5093  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5094  *          These values are in full-interlace mode.
5095  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5096  */
5097 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5098 {
5099   if(!mesh)
5100     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5101   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5102   int nbOfTypes=geoTypes.size();
5103   std::vector<int> code(3*nbOfTypes);
5104   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5105   arr1->alloc(nbOfTypes,1);
5106   int *arrPtr=arr1->getPointer();
5107   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5108   for(int i=0;i<nbOfTypes;i++,it++)
5109     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5110   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5111   const int *arrPtr2=arr2->getConstPointer();
5112   int i=0;
5113   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5114     {
5115       int pos=arrPtr2[i];
5116       int nbCells=mesh->getNumberOfCellsWithType(*it);
5117       code[3*pos]=(int)(*it);
5118       code[3*pos+1]=nbCells;
5119       code[3*pos+2]=-1;//no profiles
5120     }
5121   std::vector<const DataArrayInt *> idsPerType;//no profiles
5122   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5123   if(da)
5124     {
5125       da->decrRef();
5126       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5127     }
5128   return code;
5129 }
5130
5131 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5132 {
5133   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5134 }
5135
5136 /*!
5137  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5138  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5139  * item of every of returned sequences refers to the _i_-th part of \a this field.
5140  * Thus all sequences returned by this method are of the same length equal to number
5141  * of different types of supporting entities.<br>
5142  * A field part can include sub-parts with several different spatial discretizations,
5143  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5144  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5145  * of a nested sequence corresponds to a type of spatial discretization.<br>
5146  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5147  * The overhead is due to selecting values into new instances of DataArrayDouble.
5148  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5149  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5150  *          not checked if \a mname == \c NULL).
5151  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5152  *          a field part is returned. 
5153  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5154  *          A field part can include sub-parts with several different spatial discretizations,
5155  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5156  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5157  *          This sequence is of the same length as \a types. 
5158  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5159  *          discretization. A profile name can be empty.
5160  *          Length of this and of nested sequences is the same as that of \a typesF.
5161  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5162  *          discretization. A localization name can be empty.
5163  *          Length of this and of nested sequences is the same as that of \a typesF.
5164  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5165  *          per each type of spatial discretization within one mesh entity type.
5166  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5167  *          Length of this and of nested sequences is the same as that of \a typesF.
5168  *  \throw If no field is lying on \a mname.
5169  */
5170 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
5171 {
5172   int meshId=0;
5173   if(!mname.empty())
5174     meshId=getMeshIdFromMeshName(mname);
5175   else
5176     if(_field_per_mesh.empty())
5177       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5178   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5179   int nbOfRet=ret0.size();
5180   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5181   for(int i=0;i<nbOfRet;i++)
5182     {
5183       const std::vector< std::pair<int,int> >& p=ret0[i];
5184       int nbOfRet1=p.size();
5185       ret[i].resize(nbOfRet1);
5186       for(int j=0;j<nbOfRet1;j++)
5187         {
5188           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5189           ret[i][j]=tmp;
5190         }
5191     }
5192   return ret;
5193 }
5194
5195 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5196 {
5197   return TYPE_STR;
5198 }
5199
5200 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5201 {
5202   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5203   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5204   ret->deepCpyLeavesFrom(*this);
5205   const DataArrayDouble *arr(_arr);
5206   if(arr)
5207     {
5208       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5209       ret->setArray(arr2);
5210     }
5211   return ret.retn();
5212 }
5213
5214 /*!
5215  * Returns a pointer to the underground DataArrayDouble instance and a
5216  * sequence describing parameters of a support of each part of \a this field. The
5217  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5218  * direct access to the field values. This method is intended for the field lying on one
5219  * mesh only.
5220  *  \param [in,out] entries - the sequence describing parameters of a support of each
5221  *         part of \a this field. Each item of this sequence consists of two parts. The
5222  *         first part describes a type of mesh entity and an id of discretization of a
5223  *         current field part. The second part describes a range of values [begin,end)
5224  *         within the returned array relating to the current field part.
5225  *  \return DataArrayDouble * - the pointer to the field values array.
5226  *  \throw If the number of underlying meshes is not equal to 1.
5227  *  \throw If no field values are available.
5228  *  \sa getUndergroundDataArray()
5229  */
5230 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5231 {
5232   if(_field_per_mesh.size()!=1)
5233     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5234   if(_field_per_mesh[0]==0)
5235     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5236   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5237   return getUndergroundDataArrayTemplate();
5238 }
5239
5240 /*!
5241  * Returns a pointer to the underground DataArrayDouble instance and a
5242  * sequence describing parameters of a support of each part of \a this field. The
5243  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5244  * direct access to the field values. This method is intended for the field lying on one
5245  * mesh only.
5246  *  \param [in,out] entries - the sequence describing parameters of a support of each
5247  *         part of \a this field. Each item of this sequence consists of two parts. The
5248  *         first part describes a type of mesh entity and an id of discretization of a
5249  *         current field part. The second part describes a range of values [begin,end)
5250  *         within the returned array relating to the current field part.
5251  *  \return DataArrayDouble * - the pointer to the field values array.
5252  *  \throw If the number of underlying meshes is not equal to 1.
5253  *  \throw If no field values are available.
5254  *  \sa getUndergroundDataArray()
5255  */
5256 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5257 {
5258   return getUndergroundDataArrayDoubleExt(entries);
5259 }
5260
5261 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,csit,iteration,order)
5262 {
5263   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5264   arr->setInfoAndChangeNbOfCompo(infos);
5265 }
5266
5267 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5268 {
5269 }
5270
5271 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5272 {
5273   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5274   ret->deepCpyLeavesFrom(*this);
5275   return ret.retn();
5276 }
5277
5278 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5279 {
5280   MCAuto<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5281   if((const DataArrayDouble *)_arr)
5282     ret->_arr=_arr->deepCopy();
5283   return ret.retn();
5284 }
5285
5286 //= MEDFileIntField1TSWithoutSDA
5287
5288 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5289 {
5290   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5291 }
5292
5293 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<int>()
5294 {
5295 }
5296
5297 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5298                                                            const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,csit,iteration,order)
5299 {
5300   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5301   arr->setInfoAndChangeNbOfCompo(infos);
5302 }
5303
5304 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5305 {
5306   return TYPE_STR;
5307 }
5308
5309 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5310 {
5311   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5312   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5313   ret->deepCpyLeavesFrom(*this);
5314   const DataArrayInt *arr(_arr);
5315   if(arr)
5316     {
5317       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5318       ret->setArray(arr2);
5319     }
5320   return ret.retn();
5321 }
5322
5323 /*!
5324  * Returns a pointer to the underground DataArrayInt instance and a
5325  * sequence describing parameters of a support of each part of \a this field. The
5326  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5327  * direct access to the field values. This method is intended for the field lying on one
5328  * mesh only.
5329  *  \param [in,out] entries - the sequence describing parameters of a support of each
5330  *         part of \a this field. Each item of this sequence consists of two parts. The
5331  *         first part describes a type of mesh entity and an id of discretization of a
5332  *         current field part. The second part describes a range of values [begin,end)
5333  *         within the returned array relating to the current field part.
5334  *  \return DataArrayInt * - the pointer to the field values array.
5335  *  \throw If the number of underlying meshes is not equal to 1.
5336  *  \throw If no field values are available.
5337  *  \sa getUndergroundDataArray()
5338  */
5339 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5340 {
5341   return getUndergroundDataArrayIntExt(entries);
5342 }
5343
5344 /*!
5345  * Returns a pointer to the underground DataArrayInt instance and a
5346  * sequence describing parameters of a support of each part of \a this field. The
5347  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5348  * direct access to the field values. This method is intended for the field lying on one
5349  * mesh only.
5350  *  \param [in,out] entries - the sequence describing parameters of a support of each
5351  *         part of \a this field. Each item of this sequence consists of two parts. The
5352  *         first part describes a type of mesh entity and an id of discretization of a
5353  *         current field part. The second part describes a range of values [begin,end)
5354  *         within the returned array relating to the current field part.
5355  *  \return DataArrayInt * - the pointer to the field values array.
5356  *  \throw If the number of underlying meshes is not equal to 1.
5357  *  \throw If no field values are available.
5358  *  \sa getUndergroundDataArray()
5359  */
5360 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5361 {
5362   if(_field_per_mesh.size()!=1)
5363     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5364   if(_field_per_mesh[0]==0)
5365     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5366   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5367   return getUndergroundDataArrayTemplate();
5368 }
5369
5370 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5371 {
5372   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5373   ret->deepCpyLeavesFrom(*this);
5374   return ret.retn();
5375 }
5376
5377 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5378 {
5379   MCAuto<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5380   if((const DataArrayInt *)_arr)
5381     ret->_arr=_arr->deepCopy();
5382   return ret.retn();
5383 }
5384
5385 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5386 {
5387 }
5388
5389 //= MEDFileAnyTypeField1TS
5390
5391 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5392 {
5393   med_field_type typcha;
5394   //
5395   std::vector<std::string> infos;
5396   std::string dtunit,fieldName;
5397   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
5398   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5399   switch(typcha)
5400   {
5401     case MED_FLOAT64:
5402       {
5403         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5404         break;
5405       }
5406     case MED_INT32:
5407       {
5408         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5409         break;
5410       }
5411     default:
5412       {
5413         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] !";
5414         throw INTERP_KERNEL::Exception(oss.str());
5415       }
5416   }
5417   ret->setDtUnit(dtunit.c_str());
5418   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5419   //
5420   med_int numdt,numit;
5421   med_float dt;
5422   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5423   ret->setTime(numdt,numit,dt);
5424   ret->_csit=1;
5425   if(loadAll)
5426     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5427   else
5428     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5429   return ret.retn();
5430 }
5431
5432 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5433 try:MEDFileFieldGlobsReal(fid)
5434 {
5435   _content=BuildContentFrom(fid,loadAll,ms);
5436   loadGlobals(fid);
5437 }
5438 catch(INTERP_KERNEL::Exception& e)
5439 {
5440     throw e;
5441 }
5442
5443 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5444 {
5445   med_field_type typcha;
5446   std::vector<std::string> infos;
5447   std::string dtunit;
5448   int iii=-1;
5449   int nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit);
5450   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5451   switch(typcha)
5452   {
5453     case MED_FLOAT64:
5454       {
5455         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5456         break;
5457       }
5458     case MED_INT32:
5459       {
5460         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5461         break;
5462       }
5463     default:
5464       {
5465         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] !";
5466         throw INTERP_KERNEL::Exception(oss.str());
5467       }
5468   }
5469   ret->setDtUnit(dtunit.c_str());
5470   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5471   //
5472   if(nbSteps<1)
5473     {
5474       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5475       throw INTERP_KERNEL::Exception(oss.str());
5476     }
5477   //
5478   med_int numdt,numit;
5479   med_float dt;
5480   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5481   ret->setTime(numdt,numit,dt);
5482   ret->_csit=1;
5483   if(loadAll)
5484     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5485   else
5486     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5487   return ret.retn();
5488 }
5489
5490 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5491 try:MEDFileFieldGlobsReal(fid)
5492 {
5493   _content=BuildContentFrom(fid,fieldName,loadAll,ms);
5494   loadGlobals(fid);
5495 }
5496 catch(INTERP_KERNEL::Exception& e)
5497 {
5498     throw e;
5499 }
5500
5501 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
5502 {
5503   if(!c)
5504     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5505   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5506     {
5507       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
5508       ret->_content=c; c->incrRef();
5509       return ret.retn();
5510     }
5511   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5512     {
5513       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
5514       ret->_content=c; c->incrRef();
5515       return ret.retn();
5516     }
5517   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5518 }
5519
5520 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
5521 {
5522   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
5523   ret->setFileName(FileNameFromFID(fid));
5524   return ret;
5525 }
5526
5527 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5528 {
5529   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5530   return New(fid,loadAll);
5531 }
5532
5533 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
5534 {
5535   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
5536   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5537   ret->loadGlobals(fid);
5538   return ret.retn();
5539 }
5540
5541 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5542 {
5543   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5544   return New(fid,fieldName,loadAll);
5545 }
5546
5547 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
5548 {
5549   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0));
5550   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5551   ret->loadGlobals(fid);
5552   return ret.retn();
5553 }
5554
5555 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5556 {
5557   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5558   return New(fid,fieldName,iteration,order,loadAll);
5559 }
5560
5561 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
5562 {
5563   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0));
5564   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5565   ret->loadGlobals(fid);
5566   return ret.retn();
5567 }
5568
5569 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5570 {
5571   med_field_type typcha;
5572   std::vector<std::string> infos;
5573   std::string dtunit;
5574   int iii(-1);
5575   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit));
5576   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5577   switch(typcha)
5578   {
5579     case MED_FLOAT64:
5580       {
5581         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5582         break;
5583       }
5584     case MED_INT32:
5585       {
5586         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5587         break;
5588       }
5589     default:
5590       {
5591         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] !";
5592         throw INTERP_KERNEL::Exception(oss.str());
5593       }
5594   }
5595   ret->setDtUnit(dtunit.c_str());
5596   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5597   //
5598   bool found=false;
5599   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5600   for(int i=0;i<nbOfStep2 && !found;i++)
5601     {
5602       med_int numdt,numit;
5603       med_float dt;
5604       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5605       if(numdt==iteration && numit==order)
5606         {
5607           found=true;
5608           ret->_csit=i+1;
5609         }
5610       else
5611         dtits[i]=std::pair<int,int>(numdt,numit);
5612     }
5613   if(!found)
5614     {
5615       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
5616       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5617         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5618       throw INTERP_KERNEL::Exception(oss.str());
5619     }
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, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5628 try:MEDFileFieldGlobsReal(fid)
5629 {
5630   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms);
5631   loadGlobals(fid);
5632 }
5633 catch(INTERP_KERNEL::Exception& e)
5634 {
5635     throw e;
5636 }
5637
5638 /*!
5639  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5640  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5641  *
5642  * \warning this is a shallow copy constructor
5643  */
5644 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5645 {
5646   if(!shallowCopyOfContent)
5647     {
5648       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5649       otherPtr->incrRef();
5650       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5651     }
5652   else
5653     {
5654       _content=other.shallowCpy();
5655     }
5656 }
5657
5658 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)
5659 {
5660   if(checkFieldId)
5661     {
5662       int nbFields=MEDnField(fid);
5663       if(fieldIdCFormat>=nbFields)
5664         {
5665           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5666           throw INTERP_KERNEL::Exception(oss.str());
5667         }
5668     }
5669   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5670   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5671   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5672   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5673   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5674   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5675   med_bool localMesh;
5676   int nbOfStep;
5677   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5678   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5679   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5680   infos.clear(); infos.resize(ncomp);
5681   for(int j=0;j<ncomp;j++)
5682     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5683   return nbOfStep;
5684 }
5685
5686 /*!
5687  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5688  * 
5689  * \param [out]
5690  * \return in case of success the number of time steps available for the field with name \a fieldName.
5691  */
5692 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5693 {
5694   int nbFields=MEDnField(fid);
5695   bool found=false;
5696   std::vector<std::string> fns(nbFields);
5697   int nbOfStep2(-1);
5698   for(int i=0;i<nbFields && !found;i++)
5699     {
5700       std::string tmp;
5701       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut);
5702       fns[i]=tmp;
5703       found=(tmp==fieldName);
5704       if(found)
5705         posCFormat=i;
5706     }
5707   if(!found)
5708     {
5709       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
5710       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5711         oss << "\"" << *it << "\" ";
5712       throw INTERP_KERNEL::Exception(oss.str());
5713     }
5714   return nbOfStep2;
5715 }
5716
5717 /*!
5718  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5719  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5720  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5721  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5722  * to keep a valid instance.
5723  * 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.
5724  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5725  * 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.
5726  *
5727  * \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.
5728  * \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.
5729  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5730  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5731  * \param [in] newLocName is the new localization name.
5732  * \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.
5733  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5734  */
5735 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5736 {
5737   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5738   std::string oldPflName=disc->getProfile();
5739   std::vector<std::string> vv=getPflsReallyUsedMulti();
5740   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5741   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5742     {
5743       disc->setProfile(newPflName);
5744       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5745       pfl->setName(newPflName);
5746     }
5747   else
5748     {
5749       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5750       throw INTERP_KERNEL::Exception(oss.str());
5751     }
5752 }
5753
5754 /*!
5755  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5756  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5757  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5758  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5759  * to keep a valid instance.
5760  * 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.
5761  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5762  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5763  * 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.
5764  *
5765  * \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.
5766  * \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.
5767  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5768  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5769  * \param [in] newLocName is the new localization name.
5770  * \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.
5771  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5772  */
5773 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5774 {
5775   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5776   std::string oldLocName=disc->getLocalization();
5777   std::vector<std::string> vv=getLocsReallyUsedMulti();
5778   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5779   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5780     {
5781       disc->setLocalization(newLocName);
5782       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5783       loc.setName(newLocName);
5784     }
5785   else
5786     {
5787       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5788       throw INTERP_KERNEL::Exception(oss.str());
5789     }
5790 }
5791
5792 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5793 {
5794   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5795   if(!ret)
5796     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5797   return ret;
5798 }
5799
5800 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5801 {
5802   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5803   if(!ret)
5804     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5805   return ret;
5806 }
5807
5808 /*!
5809  * This method alloc the arrays and load potentially huge arrays contained in this field.
5810  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5811  * This method can be also called to refresh or reinit values from a file.
5812  * 
5813  * \throw If the fileName is not set or points to a non readable MED file.
5814  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5815  */
5816 void MEDFileAnyTypeField1TS::loadArrays()
5817 {
5818   if(getFileName().empty())
5819     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5820   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
5821   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5822 }
5823
5824 /*!
5825  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5826  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5827  * this method does not throw if \a this does not come from file read.
5828  * 
5829  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5830  */
5831 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5832 {
5833   if(!getFileName().empty())
5834     {
5835       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
5836       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5837     }
5838 }
5839
5840 /*!
5841  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5842  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5843  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5844  * 
5845  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5846  */
5847 void MEDFileAnyTypeField1TS::unloadArrays()
5848 {
5849   contentNotNullBase()->unloadArrays();
5850 }
5851
5852 /*!
5853  * 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.
5854  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5855  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5856  * 
5857  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5858  */
5859 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5860 {
5861   if(!getFileName().empty())
5862     contentNotNullBase()->unloadArrays();
5863 }
5864
5865 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5866 {
5867   int nbComp(getNumberOfComponents());
5868   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
5869   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
5870   for(int i=0;i<nbComp;i++)
5871     {
5872       std::string info=getInfo()[i];
5873       std::string c,u;
5874       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5875       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5876       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5877     }
5878   if(getName().empty())
5879     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5880   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
5881   writeGlobals(fid,*this);
5882   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5883 }
5884
5885 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5886 {
5887   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5888 }
5889
5890 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5891 {
5892   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5893   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5894   return ret;
5895 }
5896
5897 /*!
5898  * Returns a string describing \a this field. This string is outputted 
5899  * by \c print Python command.
5900  */
5901 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5902 {
5903   std::ostringstream oss;
5904   contentNotNullBase()->simpleRepr(0,oss,-1);
5905   simpleReprGlobs(oss);
5906   return oss.str();
5907 }
5908
5909 /*!
5910  * This method returns all profiles whose name is non empty used.
5911  * \b WARNING If profile is used several times it will be reported \b only \b once.
5912  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5913  */
5914 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5915 {
5916   return contentNotNullBase()->getPflsReallyUsed2();
5917 }
5918
5919 /*!
5920  * This method returns all localizations whose name is non empty used.
5921  * \b WARNING If localization is used several times it will be reported \b only \b once.
5922  */
5923 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5924 {
5925   return contentNotNullBase()->getLocsReallyUsed2();
5926 }
5927
5928 /*!
5929  * This method returns all profiles whose name is non empty used.
5930  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5931  */
5932 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5933 {
5934   return contentNotNullBase()->getPflsReallyUsedMulti2();
5935 }
5936
5937 /*!
5938  * This method returns all localizations whose name is non empty used.
5939  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5940  */
5941 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5942 {
5943   return contentNotNullBase()->getLocsReallyUsedMulti2();
5944 }
5945
5946 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5947 {
5948   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5949 }
5950
5951 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5952 {
5953   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5954 }
5955
5956 int MEDFileAnyTypeField1TS::getDimension() const
5957 {
5958   return contentNotNullBase()->getDimension();
5959 }
5960
5961 int MEDFileAnyTypeField1TS::getIteration() const
5962 {
5963   return contentNotNullBase()->getIteration();
5964 }
5965
5966 int MEDFileAnyTypeField1TS::getOrder() const
5967 {
5968   return contentNotNullBase()->getOrder();
5969 }
5970
5971 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5972 {
5973   return contentNotNullBase()->getTime(iteration,order);
5974 }
5975
5976 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5977 {
5978   contentNotNullBase()->setTime(iteration,order,val);
5979 }
5980
5981 std::string MEDFileAnyTypeField1TS::getName() const
5982 {
5983   return contentNotNullBase()->getName();
5984 }
5985
5986 void MEDFileAnyTypeField1TS::setName(const std::string& name)
5987 {
5988   contentNotNullBase()->setName(name);
5989 }
5990
5991 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5992 {
5993   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5994 }
5995
5996 std::string MEDFileAnyTypeField1TS::getDtUnit() const
5997 {
5998   return contentNotNullBase()->getDtUnit();
5999 }
6000
6001 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6002 {
6003   contentNotNullBase()->setDtUnit(dtUnit);
6004 }
6005
6006 std::string MEDFileAnyTypeField1TS::getMeshName() const
6007 {
6008   return contentNotNullBase()->getMeshName();
6009 }
6010
6011 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6012 {
6013   contentNotNullBase()->setMeshName(newMeshName);
6014 }
6015
6016 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6017 {
6018   return contentNotNullBase()->changeMeshNames(modifTab);
6019 }
6020
6021 int MEDFileAnyTypeField1TS::getMeshIteration() const
6022 {
6023   return contentNotNullBase()->getMeshIteration();
6024 }
6025
6026 int MEDFileAnyTypeField1TS::getMeshOrder() const
6027 {
6028   return contentNotNullBase()->getMeshOrder();
6029 }
6030
6031 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6032 {
6033   return contentNotNullBase()->getNumberOfComponents();
6034 }
6035
6036 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6037 {
6038   return contentNotNullBase()->isDealingTS(iteration,order);
6039 }
6040
6041 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6042 {
6043   return contentNotNullBase()->getDtIt();
6044 }
6045
6046 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6047 {
6048   contentNotNullBase()->fillIteration(p);
6049 }
6050
6051 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6052 {
6053   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6054 }
6055
6056 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6057 {
6058   contentNotNullBase()->setInfo(infos);
6059 }
6060
6061 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6062 {
6063   return contentNotNullBase()->getInfo();
6064 }
6065 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6066 {
6067   return contentNotNullBase()->getInfo();
6068 }
6069
6070 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6071 {
6072   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6073 }
6074
6075 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6076 {
6077   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6078 }
6079
6080 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6081 {
6082   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6083 }
6084
6085 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6086 {
6087   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6088 }
6089
6090 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6091 {
6092   return contentNotNullBase()->getTypesOfFieldAvailable();
6093 }
6094
6095 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,
6096                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6097 {
6098   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6099 }
6100
6101 /*!
6102  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6103  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6104  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6105  */
6106 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6107 {
6108   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6109   if(!content)
6110     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6111   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6112   std::size_t sz(contentsSplit.size());
6113   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6114   for(std::size_t i=0;i<sz;i++)
6115     {
6116       ret[i]=shallowCpy();
6117       ret[i]->_content=contentsSplit[i];
6118     }
6119   return ret;
6120 }
6121
6122 /*!
6123  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6124  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6125  */
6126 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6127 {
6128   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6129   if(!content)
6130     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6131   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6132   std::size_t sz(contentsSplit.size());
6133   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6134   for(std::size_t i=0;i<sz;i++)
6135     {
6136       ret[i]=shallowCpy();
6137       ret[i]->_content=contentsSplit[i];
6138     }
6139   return ret;
6140 }
6141
6142 /*!
6143  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6144  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6145  */
6146 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6147 {
6148   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6149   if(!content)
6150     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6151   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6152   std::size_t sz(contentsSplit.size());
6153   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6154   for(std::size_t i=0;i<sz;i++)
6155     {
6156       ret[i]=shallowCpy();
6157       ret[i]->_content=contentsSplit[i];
6158     }
6159   return ret;
6160 }
6161
6162 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6163 {
6164   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6165   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6166     ret->_content=_content->deepCopy();
6167   ret->deepCpyGlobs(*this);
6168   return ret.retn();
6169 }
6170
6171 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6172 {
6173   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6174 }
6175
6176 //= MEDFileField1TS
6177
6178 /*!
6179  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6180  * the first field that has been read from a specified MED file.
6181  *  \param [in] fileName - the name of the MED file to read.
6182  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6183  *          is to delete this field using decrRef() as it is no more needed.
6184  *  \throw If reading the file fails.
6185  */
6186 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6187 {
6188   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6189   return New(fid,loadAll);
6190 }
6191
6192 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, bool loadAll)
6193 {
6194   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,loadAll,0));
6195   ret->contentNotNull();
6196   return ret.retn();
6197 }
6198
6199 /*!
6200  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6201  * a given field that has been read from a specified MED file.
6202  *  \param [in] fileName - the name of the MED file to read.
6203  *  \param [in] fieldName - the name of the field to read.
6204  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6205  *          is to delete this field using decrRef() as it is no more needed.
6206  *  \throw If reading the file fails.
6207  *  \throw If there is no field named \a fieldName in the file.
6208  */
6209 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6210 {
6211   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6212   return New(fid,fieldName,loadAll);
6213 }
6214
6215 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6216 {
6217   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,loadAll,0));
6218   ret->contentNotNull();
6219   return ret.retn();
6220 }
6221
6222 /*!
6223  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6224  * a given field that has been read from a specified MED file.
6225  *  \param [in] fileName - the name of the MED file to read.
6226  *  \param [in] fieldName - the name of the field to read.
6227  *  \param [in] iteration - the iteration number of a required time step.
6228  *  \param [in] order - the iteration order number of required time step.
6229  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6230  *          is to delete this field using decrRef() as it is no more needed.
6231  *  \throw If reading the file fails.
6232  *  \throw If there is no field named \a fieldName in the file.
6233  *  \throw If the required time step is missing from the file.
6234  */
6235 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6236 {
6237   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6238   return New(fid,fieldName,iteration,order,loadAll);
6239 }
6240
6241 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6242 {
6243   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,iteration,order,loadAll,0));
6244   ret->contentNotNull();
6245   return ret.retn();
6246 }
6247
6248 /*!
6249  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6250  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6251  *
6252  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6253  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6254  * \warning this is a shallow copy constructor
6255  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6256  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6257  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6258  *          is to delete this field using decrRef() as it is no more needed.
6259  */
6260 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6261 {
6262   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(other,shallowCopyOfContent));
6263   ret->contentNotNull();
6264   return ret.retn();
6265 }
6266
6267 /*!
6268  * Returns a new empty instance of MEDFileField1TS.
6269  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6270  *          is to delete this field using decrRef() as it is no more needed.
6271  */
6272 MEDFileField1TS *MEDFileField1TS::New()
6273 {
6274   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS);
6275   ret->contentNotNull();
6276   return ret.retn();
6277 }
6278
6279 /*!
6280  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6281  * following the given input policy.
6282  *
6283  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6284  *                            By default (true) the globals are deeply copied.
6285  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6286  */
6287 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6288 {
6289   MCAuto<MEDFileIntField1TS> ret;
6290   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6291   if(content)
6292     {
6293       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6294       if(!contc)
6295         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6296       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6297       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6298     }
6299   else
6300     ret=MEDFileIntField1TS::New();
6301   if(isDeepCpyGlobs)
6302     ret->deepCpyGlobs(*this);
6303   else
6304     ret->shallowCpyGlobs(*this);
6305   return ret.retn();
6306 }
6307
6308 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6309 {
6310   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6311   if(!pt)
6312     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6313   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6314   if(!ret)
6315     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 !");
6316   return ret;
6317 }
6318
6319 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6320 {
6321   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6322   if(!pt)
6323     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6324   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6325   if(!ret)
6326     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 !");
6327   return ret;
6328 }
6329
6330 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6331 {
6332   if(!f)
6333     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6334   if(arr.isNull())
6335     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6336   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6337   if(!arrOutC)
6338     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6339   f->setArray(arrOutC);
6340 }
6341
6342 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6343 {
6344   if(arr.isNull())
6345     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6346   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6347   if(!arrOutC)
6348     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6349   arrOutC->incrRef();
6350   return arrOutC;
6351 }
6352
6353 /*!
6354  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6355  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6356  *
6357  * \return A new object that the caller is responsible to deallocate.
6358  * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
6359  */
6360 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6361 {
6362   if(!mm)
6363     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6364   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6365   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6366   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6367     {
6368       if((*it0)!=ON_NODES)
6369         {
6370           std::vector<int> levs;
6371           getNonEmptyLevels(mm->getName(),levs);
6372           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6373             {
6374               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6375               if(it2!=extractDef.end())
6376                 {
6377                   MCAuto<DataArrayInt> t((*it2).second);
6378                   if(t.isNull())
6379                     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6380                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6381                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6382                   ret->setFieldNoProfileSBT(fOut);
6383                 }
6384             }
6385         }
6386       else
6387         {
6388           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6389           if(it2==extractDef.end())
6390             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6391           MCAuto<DataArrayInt> t((*it2).second);
6392           if(t.isNull())
6393             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6394           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6395           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6396           DataArrayDouble *arr(f->getArray());
6397           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6398           fOut->setArray(newArr);
6399           ret->setFieldNoProfileSBT(fOut);
6400         }
6401     }
6402   return ret.retn();
6403 }
6404
6405 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6406 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6407 {
6408 }
6409 catch(INTERP_KERNEL::Exception& e)
6410 { throw e; }
6411
6412 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6413 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6414 {
6415 }
6416 catch(INTERP_KERNEL::Exception& e)
6417 { throw e; }
6418
6419 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6420 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6421 {
6422 }
6423 catch(INTERP_KERNEL::Exception& e)
6424 { throw e; }
6425
6426 /*!
6427  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6428  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6429  *
6430  * \warning this is a shallow copy constructor
6431  */
6432 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6433 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6434 {
6435 }
6436 catch(INTERP_KERNEL::Exception& e)
6437 { throw e; }
6438
6439 MEDFileField1TS::MEDFileField1TS()
6440 {
6441   _content=new MEDFileField1TSWithoutSDA;
6442 }
6443
6444 /*!
6445  * 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
6446  * method should be called (getFieldOnMeshAtLevel for example).
6447  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6448  *
6449  * \param [in] mesh - the mesh the field is lying on
6450  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6451  *          caller is to delete this field using decrRef() as it is no more needed. 
6452  */
6453 MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
6454 {
6455   MCAuto<DataArray> arrOut;
6456   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6457   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6458   return ret.retn();
6459 }
6460
6461 /*!
6462  * Returns a new MEDCouplingFieldDouble of a given type lying on
6463  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6464  * has not been constructed via file reading, an exception is thrown.
6465  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6466  *  \param [in] type - a spatial discretization of interest.
6467  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6468  *  \param [in] renumPol - specifies how to permute values of the result field according to
6469  *          the optional numbers of cells and nodes, if any. The valid values are
6470  *          - 0 - do not permute.
6471  *          - 1 - permute cells.
6472  *          - 2 - permute nodes.
6473  *          - 3 - permute cells and nodes.
6474  *
6475  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6476  *          caller is to delete this field using decrRef() as it is no more needed. 
6477  *  \throw If \a this field has not been constructed via file reading.
6478  *  \throw If the MED file is not readable.
6479  *  \throw If there is no mesh in the MED file.
6480  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6481  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6482  *  \sa getFieldOnMeshAtLevel()
6483  */
6484 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6485 {
6486   if(getFileName().empty())
6487     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6488   MCAuto<DataArray> arrOut;
6489   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
6490   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6491   return ret.retn();
6492 }
6493
6494 /*!
6495  * Returns a new MEDCouplingFieldDouble of a given type lying on
6496  * the top level cells of the first mesh in MED file. If \a this field 
6497  * has not been constructed via file reading, an exception is thrown.
6498  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6499  *  \param [in] type - a spatial discretization of interest.
6500  *  \param [in] renumPol - specifies how to permute values of the result field according to
6501  *          the optional numbers of cells and nodes, if any. The valid values are
6502  *          - 0 - do not permute.
6503  *          - 1 - permute cells.
6504  *          - 2 - permute nodes.
6505  *          - 3 - permute cells and nodes.
6506  *
6507  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6508  *          caller is to delete this field using decrRef() as it is no more needed. 
6509  *  \throw If \a this field has not been constructed via file reading.
6510  *  \throw If the MED file is not readable.
6511  *  \throw If there is no mesh in the MED file.
6512  *  \throw If no field values of the given \a type.
6513  *  \throw If no field values lying on the top level support.
6514  *  \sa getFieldAtLevel()
6515  */
6516 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6517 {
6518   if(getFileName().empty())
6519     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6520   MCAuto<DataArray> arrOut;
6521   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
6522   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6523   return ret.retn();
6524 }
6525
6526 /*!
6527  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6528  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6529  *  \param [in] type - a spatial discretization of the new field.
6530  *  \param [in] mesh - the supporting mesh.
6531  *  \param [in] renumPol - specifies how to permute values of the result field according to
6532  *          the optional numbers of cells and nodes, if any. The valid values are
6533  *          - 0 - do not permute.
6534  *          - 1 - permute cells.
6535  *          - 2 - permute nodes.
6536  *          - 3 - permute cells and nodes.
6537  *
6538  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6539  *          caller is to delete this field using decrRef() as it is no more needed. 
6540  *  \throw If no field of \a this is lying on \a mesh.
6541  *  \throw If the mesh is empty.
6542  *  \throw If no field values of the given \a type are available.
6543  *  \sa getFieldAtLevel()
6544  *  \sa getFieldOnMeshAtLevel() 
6545  */
6546 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6547 {
6548   MCAuto<DataArray> arrOut;
6549   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
6550   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6551   return ret.retn();
6552 }
6553
6554 /*!
6555  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6556  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6557  *  \param [in] type - a spatial discretization of interest.
6558  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6559  *  \param [in] mesh - the supporting mesh.
6560  *  \param [in] renumPol - specifies how to permute values of the result field according to
6561  *          the optional numbers of cells and nodes, if any. The valid values are
6562  *          - 0 - do not permute.
6563  *          - 1 - permute cells.
6564  *          - 2 - permute nodes.
6565  *          - 3 - permute cells and nodes.
6566  *
6567  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6568  *          caller is to delete this field using decrRef() as it is no more needed. 
6569  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6570  *  \throw If no field of \a this is lying on \a mesh.
6571  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6572  *  \sa getFieldAtLevel()
6573  *  \sa getFieldOnMeshAtLevel() 
6574  */
6575 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6576 {
6577   MCAuto<DataArray> arrOut;
6578   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
6579   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6580   return ret.retn();
6581 }
6582
6583 /*!
6584  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6585  * This method is called "Old" because in MED3 norm a field has only one meshName
6586  * attached, so this method is for readers of MED2 files. If \a this field 
6587  * has not been constructed via file reading, an exception is thrown.
6588  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6589  *  \param [in] type - a spatial discretization of interest.
6590  *  \param [in] mName - a name of the supporting mesh.
6591  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6592  *  \param [in] renumPol - specifies how to permute values of the result field according to
6593  *          the optional numbers of cells and nodes, if any. The valid values are
6594  *          - 0 - do not permute.
6595  *          - 1 - permute cells.
6596  *          - 2 - permute nodes.
6597  *          - 3 - permute cells and nodes.
6598  *
6599  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6600  *          caller is to delete this field using decrRef() as it is no more needed. 
6601  *  \throw If the MED file is not readable.
6602  *  \throw If there is no mesh named \a mName in the MED file.
6603  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6604  *  \throw If \a this field has not been constructed via file reading.
6605  *  \throw If no field of \a this is lying on the mesh named \a mName.
6606  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6607  *  \sa getFieldAtLevel()
6608  */
6609 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6610 {
6611   if(getFileName().empty())
6612     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6613   MCAuto<DataArray> arrOut;
6614   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
6615   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6616   return ret.retn();
6617 }
6618
6619 /*!
6620  * Returns values and a profile of the field of a given type lying on a given support.
6621  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6622  *  \param [in] type - a spatial discretization of the field.
6623  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6624  *  \param [in] mesh - the supporting mesh.
6625  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6626  *          field of interest lies on. If the field lies on all entities of the given
6627  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6628  *          using decrRef() as it is no more needed.  
6629  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6630  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6631  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6632  *  \throw If no field of \a this is lying on \a mesh.
6633  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6634  */
6635 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6636 {
6637   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6638   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6639 }
6640
6641 /*!
6642  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6643  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6644  * "Sort By Type"), if not, an exception is thrown. 
6645  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6646  *  \param [in] field - the field to add to \a this.
6647  *  \throw If the name of \a field is empty.
6648  *  \throw If the data array of \a field is not set.
6649  *  \throw If the data array is already allocated but has different number of components
6650  *         than \a field.
6651  *  \throw If the underlying mesh of \a field has no name.
6652  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6653  */
6654 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6655 {
6656   setFileName("");
6657   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6658 }
6659
6660 /*!
6661  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6662  * can be an aggregation of several MEDCouplingFieldDouble instances.
6663  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6664  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6665  * and \a profile.
6666  *
6667  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6668  * A new profile is added only if no equal profile is missing.
6669  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6670  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6671  *  \param [in] mesh - the supporting mesh of \a field.
6672  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6673  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6674  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6675  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6676  *  \throw If the data array of \a field is not set.
6677  *  \throw If the data array of \a this is already allocated but has different number of
6678  *         components than \a field.
6679  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6680  *  \sa setFieldNoProfileSBT()
6681  */
6682 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6683 {
6684   setFileName("");
6685   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6686 }
6687
6688 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6689 {
6690   return new MEDFileField1TS(*this);
6691 }
6692
6693 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6694 {
6695   return contentNotNull()->getUndergroundDataArrayTemplate();
6696 }
6697
6698 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6699 {
6700   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6701 }
6702
6703 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6704                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6705 {
6706   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6707 }
6708
6709 //= MEDFileIntField1TS
6710
6711 MEDFileIntField1TS *MEDFileIntField1TS::New()
6712 {
6713   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS);
6714   ret->contentNotNull();
6715   return ret.retn();
6716 }
6717
6718 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6719 {
6720   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6721   return MEDFileIntField1TS::New(fid,loadAll);
6722 }
6723
6724 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, bool loadAll)
6725 {
6726   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,loadAll,0));
6727   ret->contentNotNull();
6728   return ret.retn();
6729 }
6730
6731 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6732 {
6733   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6734   return MEDFileIntField1TS::New(fid,fieldName,loadAll);
6735 }
6736
6737 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6738 {
6739   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,loadAll,0));
6740   ret->contentNotNull();
6741   return ret.retn();
6742 }
6743
6744 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6745 {
6746   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6747   return MEDFileIntField1TS::New(fid,fieldName,iteration,order,loadAll);
6748 }
6749
6750 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6751 {
6752   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,iteration,order,loadAll,0));
6753   ret->contentNotNull();
6754   return ret.retn();
6755 }
6756
6757 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6758 {
6759   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6760   ret->contentNotNull();
6761   return ret.retn();
6762 }
6763
6764 MEDFileIntField1TS::MEDFileIntField1TS()
6765 {
6766   _content=new MEDFileIntField1TSWithoutSDA;
6767 }
6768
6769 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6770 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6771 {
6772 }
6773 catch(INTERP_KERNEL::Exception& e)
6774 { throw e; }
6775
6776 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6777 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6778 {
6779 }
6780 catch(INTERP_KERNEL::Exception& e)
6781 { throw e; }
6782
6783 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6784 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6785 {
6786 }
6787 catch(INTERP_KERNEL::Exception& e)
6788 { throw e; }
6789
6790 /*!
6791  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6792  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6793  *
6794  * \warning this is a shallow copy constructor
6795  */
6796 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6797 {
6798 }
6799
6800 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6801 {
6802   return new MEDFileIntField1TS(*this);
6803 }
6804
6805 /*!
6806  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6807  * following the given input policy.
6808  *
6809  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6810  *                            By default (true) the globals are deeply copied.
6811  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6812  */
6813 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6814 {
6815   MCAuto<MEDFileField1TS> ret;
6816   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6817   if(content)
6818     {
6819       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6820       if(!contc)
6821         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6822       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6823       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
6824     }
6825   else
6826     ret=MEDFileField1TS::New();
6827   if(isDeepCpyGlobs)
6828     ret->deepCpyGlobs(*this);
6829   else
6830     ret->shallowCpyGlobs(*this);
6831   return ret.retn();
6832 }
6833
6834 /*!
6835  * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
6836  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6837  * "Sort By Type"), if not, an exception is thrown. 
6838  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6839  *  \param [in] field - the field to add to \a this.
6840  *  \throw If the name of \a field is empty.
6841  *  \throw If the data array of \a field is not set.
6842  *  \throw If the data array is already allocated but has different number of components
6843  *         than \a field.
6844  *  \throw If the underlying mesh of \a field has no name.
6845  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6846  */
6847 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
6848 {
6849   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
6850   setFileName("");
6851   contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
6852 }
6853
6854 /*!
6855  * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6856  * can be an aggregation of several MEDCouplingFieldDouble instances.
6857  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6858  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6859  * and \a profile.
6860  *
6861  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6862  * A new profile is added only if no equal profile is missing.
6863  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6864  *  \param [in] field - the field to add to \a this.
6865  *  \param [in] mesh - the supporting mesh of \a field.
6866  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6867  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6868  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6869  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6870  *  \throw If the data array of \a field is not set.
6871  *  \throw If the data array of \a this is already allocated but has different number of
6872  *         components than \a field.
6873  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6874  *  \sa setFieldNoProfileSBT()
6875  */
6876 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6877 {
6878   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
6879   setFileName("");
6880   contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6881 }
6882
6883 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6884 {
6885   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6886   if(!pt)
6887     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6888   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6889   if(!ret)
6890     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 !");
6891   return ret;
6892 }
6893
6894 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6895 {
6896   if(getFileName().empty())
6897     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6898   MCAuto<DataArray> arrOut;
6899   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
6900   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
6901   return ret2.retn();
6902 }
6903
6904 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
6905 {
6906   if(arr.isNull())
6907     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6908   DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
6909   if(!arrC)
6910     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6911   arrC->incrRef();
6912   return arrC;
6913 }
6914
6915 MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6916 {
6917   int t1,t2;
6918   double t0(f->getTime(t1,t2));
6919   MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
6920   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
6921   MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
6922   ret->setTime(t0,t1,t2); ret->setArray(arr2);
6923   return ret.retn();
6924 }
6925
6926 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
6927 {
6928   if(!f)
6929     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
6930   int t1,t2;
6931   double t0(f->getTime(t1,t2));
6932   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
6933   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
6934   ret->setTime(t0,t1,t2);
6935   return ret;
6936 }
6937
6938 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6939 {
6940   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
6941 }
6942
6943 /*!
6944  * 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
6945  * method should be called (getFieldOnMeshAtLevel for example).
6946  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6947  *
6948  * \param [in] mesh - the mesh the field is lying on
6949  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
6950  *          caller is to delete this field using decrRef() as it is no more needed. 
6951  */
6952 MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
6953 {
6954   MCAuto<DataArray> arrOut;
6955   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6956   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
6957   return ret2.retn();
6958 }
6959
6960 /*!
6961  * Returns a new MEDCouplingFieldInt of a given type lying on
6962  * the top level cells of the first mesh in MED file. If \a this field 
6963  * has not been constructed via file reading, an exception is thrown.
6964  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6965  *  \param [in] type - a spatial discretization of interest.
6966  *  \param [in] renumPol - specifies how to permute values of the result field according to
6967  *          the optional numbers of cells and nodes, if any. The valid values are
6968  *          - 0 - do not permute.
6969  *          - 1 - permute cells.
6970  *          - 2 - permute nodes.
6971  *          - 3 - permute cells and nodes.
6972  *
6973  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
6974  *          caller is to delete this field using decrRef() as it is no more needed. 
6975  *  \throw If \a this field has not been constructed via file reading.
6976  *  \throw If the MED file is not readable.
6977  *  \throw If there is no mesh in the MED file.
6978  *  \throw If no field values of the given \a type.
6979  *  \throw If no field values lying on the top level support.
6980  *  \sa getFieldAtLevel()
6981  */
6982 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6983 {
6984   if(getFileName().empty())
6985     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6986   MCAuto<DataArray> arrOut;
6987   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
6988   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
6989   return ret2.retn();
6990 }
6991
6992 /*!
6993  * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
6994  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6995  *  \param [in] type - a spatial discretization of the new field.
6996  *  \param [in] mesh - the supporting mesh.
6997  *  \param [in] renumPol - specifies how to permute values of the result field according to
6998  *          the optional numbers of cells and nodes, if any. The valid values are
6999  *          - 0 - do not permute.
7000  *          - 1 - permute cells.
7001  *          - 2 - permute nodes.
7002  *          - 3 - permute cells and nodes.
7003  *
7004  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7005  *          caller is to delete this field using decrRef() as it is no more needed. 
7006  *  \throw If no field of \a this is lying on \a mesh.
7007  *  \throw If the mesh is empty.
7008  *  \throw If no field values of the given \a type are available.
7009  *  \sa getFieldAtLevel()
7010  *  \sa getFieldOnMeshAtLevel() 
7011  */
7012 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7013 {
7014   MCAuto<DataArray> arrOut;
7015   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7016   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7017   return ret2.retn();
7018 }
7019
7020 /*!
7021  * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
7022  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7023  *  \param [in] type - a spatial discretization of interest.
7024  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7025  *  \param [in] mesh - the supporting mesh.
7026  *  \param [in] renumPol - specifies how to permute values of the result field according to
7027  *          the optional numbers of cells and nodes, if any. The valid values are
7028  *          - 0 - do not permute.
7029  *          - 1 - permute cells.
7030  *          - 2 - permute nodes.
7031  *          - 3 - permute cells and nodes.
7032  *
7033  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7034  *          caller is to delete this field using decrRef() as it is no more needed. 
7035  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7036  *  \throw If no field of \a this is lying on \a mesh.
7037  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7038  *  \sa getFieldAtLevel()
7039  *  \sa getFieldOnMeshAtLevel() 
7040  */
7041 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7042 {
7043   MCAuto<DataArray> arrOut;
7044   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7045   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7046   return ret2.retn();
7047 }
7048
7049 /*!
7050  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7051  * This method is called "Old" because in MED3 norm a field has only one meshName
7052  * attached, so this method is for readers of MED2 files. If \a this field 
7053  * has not been constructed via file reading, an exception is thrown.
7054  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7055  *  \param [in] type - a spatial discretization of interest.
7056  *  \param [in] mName - a name of the supporting mesh.
7057  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7058  *  \param [in] renumPol - specifies how to permute values of the result field according to
7059  *          the optional numbers of cells and nodes, if any. The valid values are
7060  *          - 0 - do not permute.
7061  *          - 1 - permute cells.
7062  *          - 2 - permute nodes.
7063  *          - 3 - permute cells and nodes.
7064  *
7065  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7066  *          caller is to delete this field using decrRef() as it is no more needed. 
7067  *  \throw If the MED file is not readable.
7068  *  \throw If there is no mesh named \a mName in the MED file.
7069  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7070  *  \throw If \a this field has not been constructed via file reading.
7071  *  \throw If no field of \a this is lying on the mesh named \a mName.
7072  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7073  *  \sa getFieldAtLevel()
7074  */
7075 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7076 {
7077   if(getFileName().empty())
7078     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7079   MCAuto<DataArray> arrOut;
7080   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
7081   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7082   return ret2.retn();
7083 }
7084
7085 /*!
7086  * Returns values and a profile of the field of a given type lying on a given support.
7087  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7088  *  \param [in] type - a spatial discretization of the field.
7089  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7090  *  \param [in] mesh - the supporting mesh.
7091  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7092  *          field of interest lies on. If the field lies on all entities of the given
7093  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7094  *          using decrRef() as it is no more needed.  
7095  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7096  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7097  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7098  *  \throw If no field of \a this is lying on \a mesh.
7099  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7100  */
7101 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7102 {
7103   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7104   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7105 }
7106
7107 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7108 {
7109   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7110   if(!pt)
7111     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7112   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7113   if(!ret)
7114     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 !");
7115   return ret;
7116 }
7117
7118 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7119 {
7120   return contentNotNull()->getUndergroundDataArrayTemplate();
7121 }
7122
7123 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7124
7125 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7126 {
7127 }
7128
7129 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7130 {
7131 }
7132
7133 /*!
7134  * \param [in] fieldId field id in C mode
7135  */
7136 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7137 {
7138   med_field_type typcha;
7139   std::string dtunitOut;
7140   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut));
7141   setDtUnit(dtunitOut.c_str());
7142   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7143 }
7144
7145 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 std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7146 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7147 {
7148   setDtUnit(dtunit.c_str());
7149   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7150 }
7151 catch(INTERP_KERNEL::Exception& e)
7152 {
7153     throw e;
7154 }
7155
7156 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7157 {
7158   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7159   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7160     ret+=(*it).capacity();
7161   return ret;
7162 }
7163
7164 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7165 {
7166   std::vector<const BigMemoryObject *> ret;
7167   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7168     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7169   return ret;
7170 }
7171
7172 /*!
7173  * 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
7174  * NULL.
7175  */
7176 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7177 {
7178   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7179   ret->setInfo(_infos);
7180   int sz=(int)_time_steps.size();
7181   for(const int *id=startIds;id!=endIds;id++)
7182     {
7183       if(*id>=0 && *id<sz)
7184         {
7185           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7186           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7187           if(tse)
7188             {
7189               tse->incrRef();
7190               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7191             }
7192           ret->pushBackTimeStep(tse2);
7193         }
7194       else
7195         {
7196           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7197           oss << " ! Should be in [0," << sz << ") !";
7198           throw INTERP_KERNEL::Exception(oss.str());
7199         }
7200     }
7201   if(ret->getNumberOfTS()>0)
7202     ret->synchronizeNameScope();
7203   ret->copyNameScope(*this);
7204   return ret.retn();
7205 }
7206
7207 /*!
7208  * 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
7209  * NULL.
7210  */
7211 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7212 {
7213   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7214   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7215   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7216   ret->setInfo(_infos);
7217   int sz=(int)_time_steps.size();
7218   int j=bg;
7219   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7220     {
7221       if(j>=0 && j<sz)
7222         {
7223           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7224           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7225           if(tse)
7226             {
7227               tse->incrRef();
7228               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7229             }
7230           ret->pushBackTimeStep(tse2);
7231         }
7232       else
7233         {
7234           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7235           oss << " ! Should be in [0," << sz << ") !";
7236           throw INTERP_KERNEL::Exception(oss.str());
7237         }
7238     }
7239   if(ret->getNumberOfTS()>0)
7240     ret->synchronizeNameScope();
7241   ret->copyNameScope(*this);
7242   return ret.retn();
7243 }
7244
7245 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7246 {
7247   int id=0;
7248   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7249   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7250     {
7251       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7252       if(!cur)
7253         continue;
7254       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7255       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7256         ids->pushBackSilent(id);
7257     }
7258   return buildFromTimeStepIds(ids->begin(),ids->end());
7259 }
7260
7261 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7262 {
7263   int id=0;
7264   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7265   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7266     {
7267       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7268       if(!cur)
7269         continue;
7270       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7271       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7272         ids->pushBackSilent(id);
7273     }
7274   return buildFromTimeStepIds(ids->begin(),ids->end());
7275 }
7276
7277 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7278 {
7279   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7280     {
7281       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7282       if(!cur)
7283         continue;
7284       if(cur->presenceOfMultiDiscPerGeoType())
7285         return true;
7286     }
7287   return false;
7288 }
7289
7290 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7291 {
7292   return _infos;
7293 }
7294
7295 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7296 {
7297   _infos=info;
7298 }
7299
7300 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7301 {
7302   int ret=0;
7303   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7304     {
7305       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7306       if(pt->isDealingTS(iteration,order))
7307         return ret;
7308     }
7309   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7310   std::vector< std::pair<int,int> > vp=getIterations();
7311   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7312     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7313   throw INTERP_KERNEL::Exception(oss.str());
7314 }
7315
7316 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7317 {
7318   return *_time_steps[getTimeStepPos(iteration,order)];
7319 }
7320
7321 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7322 {
7323   return *_time_steps[getTimeStepPos(iteration,order)];
7324 }
7325
7326 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7327 {
7328   if(_time_steps.empty())
7329     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7330   return _time_steps[0]->getMeshName();
7331 }
7332
7333 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7334 {
7335   std::string oldName(getMeshName());
7336   std::vector< std::pair<std::string,std::string> > v(1);
7337   v[0].first=oldName; v[0].second=newMeshName;
7338   changeMeshNames(v);
7339 }
7340
7341 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7342 {
7343   bool ret=false;
7344   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7345     {
7346       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7347       if(cur)
7348         ret=cur->changeMeshNames(modifTab) || ret;
7349     }
7350   return ret;
7351 }
7352
7353 /*!
7354  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7355  */
7356 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7357 {
7358   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7359 }
7360
7361 /*!
7362  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7363  */
7364 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7365 {
7366   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7367 }
7368
7369 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7370                                                                        MEDFileFieldGlobsReal& glob)
7371 {
7372   bool ret=false;
7373   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7374     {
7375       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7376       if(f1ts)
7377         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7378     }
7379   return ret;
7380 }
7381
7382 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7383 {
7384   std::string startLine(bkOffset,' ');
7385   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7386   if(fmtsId>=0)
7387     oss << " (" << fmtsId << ")";
7388   oss << " has the following name: \"" << _name << "\"." << std::endl;
7389   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7390   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7391     {
7392       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7393     }
7394   int i=0;
7395   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7396     {
7397       std::string chapter(17,'0'+i);
7398       oss << startLine << chapter << std::endl;
7399       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7400       if(cur)
7401         cur->simpleRepr(bkOffset+2,oss,i);
7402       else
7403         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7404       oss << startLine << chapter << std::endl;
7405     }
7406 }
7407
7408 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7409 {
7410   std::size_t sz=_time_steps.size();
7411   std::vector< std::pair<int,int> > ret(sz);
7412   ret1.resize(sz);
7413   for(std::size_t i=0;i<sz;i++)
7414     {
7415       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7416       if(f1ts)
7417         {
7418           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7419         }
7420       else
7421         {
7422           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7423           throw INTERP_KERNEL::Exception(oss.str());
7424         }
7425     }
7426   return ret;
7427 }
7428
7429 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7430 {
7431   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7432   if(!tse2)
7433     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7434   checkCoherencyOfType(tse2);
7435   if(_time_steps.empty())
7436     {
7437       setName(tse2->getName().c_str());
7438       setInfo(tse2->getInfo());
7439     }
7440   checkThatComponentsMatch(tse2->getInfo());
7441   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7442     setDtUnit(tse->getDtUnit());
7443   _time_steps.push_back(tse);
7444 }
7445
7446 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7447 {
7448   std::size_t nbOfCompo=_infos.size();
7449   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7450     {
7451       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7452       if(cur)
7453         {
7454           if((cur->getInfo()).size()!=nbOfCompo)
7455             {
7456               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7457               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7458               throw INTERP_KERNEL::Exception(oss.str());
7459             }
7460           cur->copyNameScope(*this);
7461         }
7462     }
7463 }
7464
7465 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7466 {
7467   _time_steps.resize(nbPdt);
7468   for(int i=0;i<nbPdt;i++)
7469     {
7470       std::vector< std::pair<int,int> > ts;
7471       med_int numdt=0,numo=0;
7472       med_float dt=0.0;
7473       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
7474       switch(fieldTyp)
7475       {
7476         case MED_FLOAT64:
7477           {
7478             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7479             break;
7480           }
7481         case MED_INT32:
7482           {
7483             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7484             break;
7485           }
7486         default:
7487           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7488       }
7489       if(loadAll)
7490         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7491       else
7492         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7493       synchronizeNameScope();
7494     }
7495 }
7496
7497 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7498 {
7499   if(_time_steps.empty())
7500     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7501   checkThatNbOfCompoOfTSMatchThis();
7502   std::vector<std::string> infos(getInfo());
7503   int nbComp=infos.size();
7504   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7505   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7506   for(int i=0;i<nbComp;i++)
7507     {
7508       std::string info=infos[i];
7509       std::string c,u;
7510       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7511       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7512       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7513     }
7514   if(_name.empty())
7515     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7516   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7517   int nbOfTS=_time_steps.size();
7518   for(int i=0;i<nbOfTS;i++)
7519     _time_steps[i]->writeLL(fid,opts,*this);
7520 }
7521
7522 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7523 {
7524   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7525     {
7526       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7527       if(elt)
7528         elt->loadBigArraysRecursively(fid,nasc);
7529     }
7530 }
7531
7532 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7533 {
7534   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7535     {
7536       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7537       if(elt)
7538         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7539     }
7540 }
7541
7542 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7543 {
7544   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7545     {
7546       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7547       if(elt)
7548         elt->unloadArrays();
7549     }
7550 }
7551
7552 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7553 {
7554   return _time_steps.size();
7555 }
7556
7557 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7558 {
7559   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7560   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7561     {
7562       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7563       if(tmp)
7564         newTS.push_back(*it);
7565     }
7566   _time_steps=newTS;
7567 }
7568
7569 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7570 {
7571   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7572   int maxId=(int)_time_steps.size();
7573   int ii=0;
7574   std::set<int> idsToDel;
7575   for(const int *id=startIds;id!=endIds;id++,ii++)
7576     {
7577       if(*id>=0 && *id<maxId)
7578         {
7579           idsToDel.insert(*id);
7580         }
7581       else
7582         {
7583           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7584           throw INTERP_KERNEL::Exception(oss.str());
7585         }
7586     }
7587   for(int iii=0;iii<maxId;iii++)
7588     if(idsToDel.find(iii)==idsToDel.end())
7589       newTS.push_back(_time_steps[iii]);
7590   _time_steps=newTS;
7591 }
7592
7593 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7594 {
7595   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7596   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7597   if(nbOfEntriesToKill==0)
7598     return ;
7599   std::size_t sz=_time_steps.size();
7600   std::vector<bool> b(sz,true);
7601   int j=bg;
7602   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7603     b[j]=false;
7604   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7605   for(std::size_t i=0;i<sz;i++)
7606     if(b[i])
7607       newTS.push_back(_time_steps[i]);
7608   _time_steps=newTS;
7609 }
7610
7611 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7612 {
7613   int ret=0;
7614   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7615   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7616     {
7617       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7618       if(tmp)
7619         {
7620           int it2,ord;
7621           tmp->getTime(it2,ord);
7622           if(it2==iteration && order==ord)
7623             return ret;
7624           else
7625             oss << "(" << it2 << ","  << ord << "), ";
7626         }
7627     }
7628   throw INTERP_KERNEL::Exception(oss.str());
7629 }
7630
7631 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7632 {
7633   int ret=0;
7634   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7635   oss.precision(15);
7636   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7637     {
7638       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7639       if(tmp)
7640         {
7641           int it2,ord;
7642           double ti=tmp->getTime(it2,ord);
7643           if(fabs(time-ti)<eps)
7644             return ret;
7645           else
7646             oss << ti << ", ";
7647         }
7648     }
7649   throw INTERP_KERNEL::Exception(oss.str());
7650 }
7651
7652 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7653 {
7654   int lgth=_time_steps.size();
7655   std::vector< std::pair<int,int> > ret(lgth);
7656   for(int i=0;i<lgth;i++)
7657     _time_steps[i]->fillIteration(ret[i]);
7658   return ret;
7659 }
7660
7661 /*!
7662  * 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'
7663  * This method returns two things.
7664  * - The absolute dimension of 'this' in first parameter. 
7665  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7666  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7667  *
7668  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7669  * Only these 3 discretizations will be taken into account here.
7670  *
7671  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7672  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7673  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7674  *
7675  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7676  * 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'.
7677  * 
7678  * Let's consider the typical following case :
7679  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7680  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7681  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7682  *   TETRA4 and SEG2
7683  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7684  *
7685  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7686  * 
7687  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7688  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7689  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7690  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7691  */
7692 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7693 {
7694   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7695 }
7696
7697 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7698 {
7699   if(pos<0 || pos>=(int)_time_steps.size())
7700     {
7701       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7702       throw INTERP_KERNEL::Exception(oss.str());
7703     }
7704   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7705   if(item==0)
7706     {
7707       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7708       oss << "\nTry to use following method eraseEmptyTS !";
7709       throw INTERP_KERNEL::Exception(oss.str());
7710     }
7711   return item;
7712 }
7713
7714 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7715 {
7716   if(pos<0 || pos>=(int)_time_steps.size())
7717     {
7718       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7719       throw INTERP_KERNEL::Exception(oss.str());
7720     }
7721   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7722   if(item==0)
7723     {
7724       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7725       oss << "\nTry to use following method eraseEmptyTS !";
7726       throw INTERP_KERNEL::Exception(oss.str());
7727     }
7728   return item;
7729 }
7730
7731 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7732 {
7733   std::vector<std::string> ret;
7734   std::set<std::string> ret2;
7735   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7736     {
7737       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7738       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7739         if(ret2.find(*it2)==ret2.end())
7740           {
7741             ret.push_back(*it2);
7742             ret2.insert(*it2);
7743           }
7744     }
7745   return ret;
7746 }
7747
7748 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7749 {
7750   std::vector<std::string> ret;
7751   std::set<std::string> ret2;
7752   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7753     {
7754       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7755       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7756         if(ret2.find(*it2)==ret2.end())
7757           {
7758             ret.push_back(*it2);
7759             ret2.insert(*it2);
7760           }
7761     }
7762   return ret;
7763 }
7764
7765 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7766 {
7767   std::vector<std::string> ret;
7768   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7769     {
7770       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7771       ret.insert(ret.end(),tmp.begin(),tmp.end());
7772     }
7773   return ret;
7774 }
7775
7776 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7777 {
7778   std::vector<std::string> ret;
7779   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7780     {
7781       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7782       ret.insert(ret.end(),tmp.begin(),tmp.end());
7783     }
7784   return ret;
7785 }
7786
7787 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7788 {
7789   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7790     (*it)->changePflsRefsNamesGen2(mapOfModif);
7791 }
7792
7793 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7794 {
7795   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7796     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7797 }
7798
7799 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7800 {
7801   int lgth=_time_steps.size();
7802   std::vector< std::vector<TypeOfField> > ret(lgth);
7803   for(int i=0;i<lgth;i++)
7804     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7805   return ret;
7806 }
7807
7808 /*!
7809  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7810  */
7811 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
7812 {
7813   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7814 }
7815
7816 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7817 {
7818   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7819   std::size_t i=0;
7820   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7821     {
7822       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7823         ret->_time_steps[i]=(*it)->deepCopy();
7824     }
7825   return ret.retn();
7826 }
7827
7828 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7829 {
7830   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7831   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7832   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7833   for(std::size_t i=0;i<sz;i++)
7834     {
7835       ret[i]=shallowCpy();
7836       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7837     }
7838   for(std::size_t i=0;i<sz2;i++)
7839     {
7840       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7841       if(ret1.size()!=sz)
7842         {
7843           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7844           throw INTERP_KERNEL::Exception(oss.str());
7845         }
7846       ts[i]=ret1;
7847     }
7848   for(std::size_t i=0;i<sz;i++)
7849     for(std::size_t j=0;j<sz2;j++)
7850       ret[i]->_time_steps[j]=ts[j][i];
7851   return ret;
7852 }
7853
7854 /*!
7855  * This method splits into discretization each time steps in \a this.
7856  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7857  */
7858 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7859 {
7860   std::size_t sz(_time_steps.size());
7861   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7862   for(std::size_t i=0;i<sz;i++)
7863     {
7864       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7865       if(!timeStep)
7866         {
7867           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7868           throw INTERP_KERNEL::Exception(oss.str());
7869         }
7870       items[i]=timeStep->splitDiscretizations();  
7871     }
7872   //
7873   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7874   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7875   std::vector< TypeOfField > types;
7876   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7877     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7878       {
7879         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7880         if(ts.size()!=1)
7881           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7882         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7883         if(it2==types.end())
7884           types.push_back(ts[0]);
7885       }
7886   ret.resize(types.size()); ret2.resize(types.size());
7887   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7888     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7889       {
7890         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7891         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7892         ret2[pos].push_back(*it1);
7893       }
7894   for(std::size_t i=0;i<types.size();i++)
7895     {
7896       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7897       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7898         elt->pushBackTimeStep(*it1);//also updates infos in elt
7899       ret[i]=elt;
7900       elt->MEDFileFieldNameScope::operator=(*this);
7901     }
7902   return ret;
7903 }
7904
7905 /*!
7906  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7907  */
7908 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7909 {
7910   std::size_t sz(_time_steps.size());
7911   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7912   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7913   for(std::size_t i=0;i<sz;i++)
7914     {
7915       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7916       if(!timeStep)
7917         {
7918           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7919           throw INTERP_KERNEL::Exception(oss.str());
7920         }
7921       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7922       if(szOut==std::numeric_limits<std::size_t>::max())
7923         szOut=items[i].size();
7924       else
7925         if(items[i].size()!=szOut)
7926           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7927     }
7928   if(szOut==std::numeric_limits<std::size_t>::max())
7929     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7930   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7931   for(std::size_t i=0;i<szOut;i++)
7932     {
7933       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7934       for(std::size_t j=0;j<sz;j++)
7935         elt->pushBackTimeStep(items[j][i]);
7936       ret[i]=elt;
7937       elt->MEDFileFieldNameScope::operator=(*this);
7938     }
7939   return ret;
7940 }
7941
7942 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7943 {
7944   _name=field->getName();
7945   if(_name.empty())
7946     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7947   if(!arr)
7948     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7949   _infos=arr->getInfoOnComponents();
7950 }
7951
7952 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7953 {
7954   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7955   if(_name!=field->getName())
7956     {
7957       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7958       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7959       throw INTERP_KERNEL::Exception(oss.str());
7960     }
7961   if(!arr)
7962     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7963   checkThatComponentsMatch(arr->getInfoOnComponents());
7964 }
7965
7966 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7967 {
7968   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7969   if(getInfo().size()!=compos.size())
7970     {
7971       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7972       oss << " number of components of element to append (" << compos.size() << ") !";
7973       throw INTERP_KERNEL::Exception(oss.str());
7974     }
7975   if(_infos!=compos)
7976     {
7977       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7978       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7979       oss << " But compo in input fields are : ";
7980       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7981       oss << " !";
7982       throw INTERP_KERNEL::Exception(oss.str());
7983     }
7984 }
7985
7986 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7987 {
7988   std::size_t sz=_infos.size();
7989   int j=0;
7990   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7991     {
7992       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7993       if(elt)
7994         if(elt->getInfo().size()!=sz)
7995           {
7996             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7997             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7998             throw INTERP_KERNEL::Exception(oss.str());
7999           }
8000     }
8001 }
8002
8003 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
8004 {
8005   if(!field)
8006     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8007   if(!_time_steps.empty())
8008     checkCoherencyOfTinyInfo(field,arr);
8009   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8010   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8011   objC->setFieldNoProfileSBT(field,arr,glob,*this);
8012   copyTinyInfoFrom(field,arr);
8013   _time_steps.push_back(obj);
8014 }
8015
8016 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
8017 {
8018   if(!field)
8019     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8020   if(!_time_steps.empty())
8021     checkCoherencyOfTinyInfo(field,arr);
8022   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8023   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8024   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
8025   copyTinyInfoFrom(field,arr);
8026   _time_steps.push_back(obj);
8027 }
8028
8029 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8030 {
8031   int sz=(int)_time_steps.size();
8032   if(i<0 || i>=sz)
8033     {
8034       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8035       throw INTERP_KERNEL::Exception(oss.str());
8036     }
8037   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8038   if(tsPtr)
8039     {
8040       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8041         {
8042           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8043           throw INTERP_KERNEL::Exception(oss.str());
8044         }
8045     }
8046   _time_steps[i]=ts;
8047 }
8048
8049 //= MEDFileFieldMultiTSWithoutSDA
8050
8051 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 std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8052 {
8053   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8054 }
8055
8056 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
8057 {
8058 }
8059
8060 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8061 {
8062 }
8063
8064 /*!
8065  * \param [in] fieldId field id in C mode
8066  */
8067 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8068 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8069 {
8070 }
8071 catch(INTERP_KERNEL::Exception& e)
8072 { throw e; }
8073
8074 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 std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8075 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8076 {
8077 }
8078 catch(INTERP_KERNEL::Exception& e)
8079 { throw e; }
8080
8081 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8082 {
8083   return new MEDFileField1TSWithoutSDA;
8084 }
8085
8086 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8087 {
8088   if(!f1ts)
8089     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8090   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8091   if(!f1tsC)
8092     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8093 }
8094
8095 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8096 {
8097   return MEDFileField1TSWithoutSDA::TYPE_STR;
8098 }
8099
8100 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8101 {
8102   return new MEDFileFieldMultiTSWithoutSDA(*this);
8103 }
8104
8105 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8106 {
8107   return new MEDFileFieldMultiTSWithoutSDA;
8108 }
8109
8110 /*!
8111  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8112  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8113  */
8114 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
8115 {
8116   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8117   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8118   if(!myF1TSC)
8119     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8120   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8121 }
8122
8123 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8124 {
8125   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8126   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8127   int i=0;
8128   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8129     {
8130       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8131       if(eltToConv)
8132         {
8133           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8134           if(!eltToConvC)
8135             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8136           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8137           ret->setIteration(i,elt);
8138         }
8139     }
8140   return ret.retn();
8141 }
8142
8143 //= MEDFileAnyTypeFieldMultiTS
8144
8145 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8146 {
8147 }
8148
8149 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8150 try:MEDFileFieldGlobsReal(fid)
8151 {
8152   _content=BuildContentFrom(fid,loadAll,ms);
8153   loadGlobals(fid);
8154 }
8155 catch(INTERP_KERNEL::Exception& e)
8156 {
8157     throw e;
8158 }
8159
8160 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8161 {
8162   med_field_type typcha;
8163   std::vector<std::string> infos;
8164   std::string dtunit;
8165   int i(-1);
8166   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit);
8167   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8168   switch(typcha)
8169   {
8170     case MED_FLOAT64:
8171       {
8172         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8173         break;
8174       }
8175     case MED_INT32:
8176       {
8177         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8178         break;
8179       }
8180     default:
8181       {
8182         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] !";
8183         throw INTERP_KERNEL::Exception(oss.str());
8184       }
8185   }
8186   ret->setDtUnit(dtunit.c_str());
8187   return ret.retn();
8188 }
8189
8190 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8191 {
8192   med_field_type typcha;
8193   //
8194   std::vector<std::string> infos;
8195   std::string dtunit,fieldName;
8196   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
8197   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8198   switch(typcha)
8199   {
8200     case MED_FLOAT64:
8201       {
8202         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8203         break;
8204       }
8205     case MED_INT32:
8206       {
8207         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8208         break;
8209       }
8210     default:
8211       {
8212         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] !";
8213         throw INTERP_KERNEL::Exception(oss.str());
8214       }
8215   }
8216   ret->setDtUnit(dtunit.c_str());
8217   return ret.retn();
8218 }
8219
8220 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8221 {
8222   if(!c)
8223     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8224   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8225     {
8226       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8227       ret->_content=c;  c->incrRef();
8228       return ret.retn();
8229     }
8230   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8231     {
8232       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8233       ret->_content=c;  c->incrRef();
8234       return ret.retn();
8235     }
8236   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8237 }
8238
8239 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8240 {
8241   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8242   std::string fileName(FileNameFromFID(fid));
8243   ret->setFileName(fileName);
8244   return ret;
8245 }
8246
8247 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8248 try:MEDFileFieldGlobsReal(fid)
8249 {
8250   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8251   loadGlobals(fid);
8252 }
8253 catch(INTERP_KERNEL::Exception& e)
8254 {
8255     throw e;
8256 }
8257
8258 //= MEDFileIntFieldMultiTSWithoutSDA
8259
8260 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 std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8261 {
8262   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8263 }
8264
8265 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8266 {
8267 }
8268
8269 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8270 {
8271 }
8272
8273 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 std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8274 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8275 {
8276 }
8277 catch(INTERP_KERNEL::Exception& e)
8278 { throw e; }
8279
8280 /*!
8281  * \param [in] fieldId field id in C mode
8282  */
8283 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8284 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8285 {
8286 }
8287 catch(INTERP_KERNEL::Exception& e)
8288 { throw e; }
8289
8290 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8291 {
8292   return new MEDFileIntField1TSWithoutSDA;
8293 }
8294
8295 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8296 {
8297   if(!f1ts)
8298     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8299   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8300   if(!f1tsC)
8301     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8302 }
8303
8304 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8305 {
8306   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8307 }
8308
8309 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8310 {
8311   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8312 }
8313
8314 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8315 {
8316   return new MEDFileIntFieldMultiTSWithoutSDA;
8317 }
8318
8319 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8320 {
8321   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8322   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8323   int i=0;
8324   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8325     {
8326       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8327       if(eltToConv)
8328         {
8329           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8330           if(!eltToConvC)
8331             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8332           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8333           ret->setIteration(i,elt);
8334         }
8335     }
8336   return ret.retn();
8337 }
8338
8339 //= MEDFileAnyTypeFieldMultiTS
8340
8341 /*!
8342  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8343  * that has been read from a specified MED file.
8344  *  \param [in] fileName - the name of the MED file to read.
8345  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8346  *          is to delete this field using decrRef() as it is no more needed.
8347  *  \throw If reading the file fails.
8348  */
8349 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8350 {
8351   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8352   return New(fid,loadAll);
8353 }
8354
8355 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8356 {
8357   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8358   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8359   ret->loadGlobals(fid);
8360   return ret.retn();
8361 }
8362
8363 /*!
8364  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8365  * that has been read from a specified MED file.
8366  *  \param [in] fileName - the name of the MED file to read.
8367  *  \param [in] fieldName - the name of the field to read.
8368  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8369  *          is to delete this field using decrRef() as it is no more needed.
8370  *  \throw If reading the file fails.
8371  *  \throw If there is no field named \a fieldName in the file.
8372  */
8373 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8374 {
8375   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8376   return New(fid,fieldName,loadAll);
8377 }
8378
8379 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8380 {
8381   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8382   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8383   ret->loadGlobals(fid);
8384   return ret.retn();
8385 }
8386
8387 /*!
8388  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8389  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8390  *
8391  * \warning this is a shallow copy constructor
8392  */
8393 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8394 {
8395   if(!shallowCopyOfContent)
8396     {
8397       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8398       otherPtr->incrRef();
8399       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8400     }
8401   else
8402     {
8403       _content=other.shallowCpy();
8404     }
8405 }
8406
8407 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8408 {
8409   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8410   if(!ret)
8411     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8412   return ret;
8413 }
8414
8415 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8416 {
8417   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8418   if(!ret)
8419     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8420   return ret;
8421 }
8422
8423 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8424 {
8425   return contentNotNullBase()->getPflsReallyUsed2();
8426 }
8427
8428 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8429 {
8430   return contentNotNullBase()->getLocsReallyUsed2();
8431 }
8432
8433 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8434 {
8435   return contentNotNullBase()->getPflsReallyUsedMulti2();
8436 }
8437
8438 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8439 {
8440   return contentNotNullBase()->getLocsReallyUsedMulti2();
8441 }
8442
8443 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8444 {
8445   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8446 }
8447
8448 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8449 {
8450   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8451 }
8452
8453 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8454 {
8455   return contentNotNullBase()->getNumberOfTS();
8456 }
8457
8458 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8459 {
8460   contentNotNullBase()->eraseEmptyTS();
8461 }
8462
8463 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8464 {
8465   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8466 }
8467
8468 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8469 {
8470   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8471 }
8472
8473 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8474 {
8475   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8476   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8477   ret->_content=c;
8478   return ret.retn();
8479 }
8480
8481 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8482 {
8483   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8484   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8485   ret->_content=c;
8486   return ret.retn();
8487 }
8488
8489 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8490 {
8491   return contentNotNullBase()->getIterations();
8492 }
8493
8494 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8495 {
8496   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8497     pushBackTimeStep(*it);
8498 }
8499
8500 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8501 {
8502   if(!fmts)
8503     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8504   int nbOfTS(fmts->getNumberOfTS());
8505   for(int i=0;i<nbOfTS;i++)
8506     {
8507       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8508       pushBackTimeStep(elt);
8509     }
8510 }
8511
8512 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8513 {
8514   if(!f1ts)
8515     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8516   checkCoherencyOfType(f1ts);
8517   f1ts->incrRef();
8518   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8519   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8520   c->incrRef();
8521   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8522   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8523     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8524   _content->pushBackTimeStep(cSafe);
8525   appendGlobs(*f1ts,1e-12);
8526 }
8527
8528 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8529 {
8530   contentNotNullBase()->synchronizeNameScope();
8531 }
8532
8533 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8534 {
8535   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8536 }
8537
8538 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8539 {
8540   return contentNotNullBase()->getPosGivenTime(time,eps);
8541 }
8542
8543 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8544 {
8545   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8546 }
8547
8548 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8549 {
8550   return contentNotNullBase()->getTypesOfFieldAvailable();
8551 }
8552
8553 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
8554 {
8555   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8556 }
8557
8558 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8559 {
8560   return contentNotNullBase()->getName();
8561 }
8562
8563 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8564 {
8565   contentNotNullBase()->setName(name);
8566 }
8567
8568 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8569 {
8570   return contentNotNullBase()->getDtUnit();
8571 }
8572
8573 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8574 {
8575   contentNotNullBase()->setDtUnit(dtUnit);
8576 }
8577
8578 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8579 {
8580   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8581 }
8582
8583 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8584 {
8585   return contentNotNullBase()->getTimeSteps(ret1);
8586 }
8587
8588 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8589 {
8590   return contentNotNullBase()->getMeshName();
8591 }
8592
8593 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8594 {
8595   contentNotNullBase()->setMeshName(newMeshName);
8596 }
8597
8598 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8599 {
8600   return contentNotNullBase()->changeMeshNames(modifTab);
8601 }
8602
8603 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8604 {
8605   return contentNotNullBase()->getInfo();
8606 }
8607
8608 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8609 {
8610   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8611 }
8612
8613 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8614 {
8615   return contentNotNullBase()->setInfo(info);
8616 }
8617
8618 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8619 {
8620   const std::vector<std::string> ret=getInfo();
8621   return (int)ret.size();
8622 }
8623
8624 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8625 {
8626   writeGlobals(fid,*this);
8627   contentNotNullBase()->writeLL(fid,*this);
8628 }
8629
8630 /*!
8631  * This method alloc the arrays and load potentially huge arrays contained in this field.
8632  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8633  * This method can be also called to refresh or reinit values from a file.
8634  * 
8635  * \throw If the fileName is not set or points to a non readable MED file.
8636  */
8637 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8638 {
8639   if(getFileName().empty())
8640     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8641   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8642   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8643 }
8644
8645 /*!
8646  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8647  * But once data loaded once, this method does nothing.
8648  * 
8649  * \throw If the fileName is not set or points to a non readable MED file.
8650  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8651  */
8652 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8653 {
8654   if(!getFileName().empty())
8655     {
8656       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8657       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8658     }
8659 }
8660
8661 /*!
8662  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8663  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8664  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8665  * 
8666  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8667  */
8668 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8669 {
8670   contentNotNullBase()->unloadArrays();
8671 }
8672
8673 /*!
8674  * 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.
8675  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8676  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8677  * 
8678  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8679  */
8680 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8681 {
8682   if(!getFileName().empty())
8683     contentNotNullBase()->unloadArrays();
8684 }
8685
8686 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8687 {
8688   std::ostringstream oss;
8689   contentNotNullBase()->simpleRepr(0,oss,-1);
8690   simpleReprGlobs(oss);
8691   return oss.str();
8692 }
8693
8694 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8695 {
8696   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8697 }
8698
8699 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8700 {
8701   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8702   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8703   return ret;
8704 }
8705
8706 /*!
8707  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8708  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8709  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8710  */
8711 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8712 {
8713   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8714   if(!content)
8715     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8716   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8717   std::size_t sz(contentsSplit.size());
8718   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8719   for(std::size_t i=0;i<sz;i++)
8720     {
8721       ret[i]=shallowCpy();
8722       ret[i]->_content=contentsSplit[i];
8723     }
8724   return ret;
8725 }
8726
8727 /*!
8728  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8729  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8730  */
8731 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8732 {
8733   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8734   if(!content)
8735     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8736   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8737   std::size_t sz(contentsSplit.size());
8738   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8739   for(std::size_t i=0;i<sz;i++)
8740     {
8741       ret[i]=shallowCpy();
8742       ret[i]->_content=contentsSplit[i];
8743     }
8744   return ret;
8745 }
8746
8747 /*!
8748  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8749  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8750  */
8751 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8752 {
8753   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8754   if(!content)
8755     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8756   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8757   std::size_t sz(contentsSplit.size());
8758   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8759   for(std::size_t i=0;i<sz;i++)
8760     {
8761       ret[i]=shallowCpy();
8762       ret[i]->_content=contentsSplit[i];
8763     }
8764   return ret;
8765 }
8766
8767 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8768 {
8769   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8770   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8771     ret->_content=_content->deepCopy();
8772   ret->deepCpyGlobs(*this);
8773   return ret.retn();
8774 }
8775
8776 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8777 {
8778   return _content;
8779 }
8780
8781 /*!
8782  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8783  *  \param [in] iteration - the iteration number of a required time step.
8784  *  \param [in] order - the iteration order number of required time step.
8785  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8786  *          delete this field using decrRef() as it is no more needed.
8787  *  \throw If there is no required time step in \a this field.
8788  */
8789 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8790 {
8791   int pos=getPosOfTimeStep(iteration,order);
8792   return getTimeStepAtPos(pos);
8793 }
8794
8795 /*!
8796  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8797  *  \param [in] time - the time of the time step of interest.
8798  *  \param [in] eps - a precision used to compare time values.
8799  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8800  *          delete this field using decrRef() as it is no more needed.
8801  *  \throw If there is no required time step in \a this field.
8802  */
8803 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8804 {
8805   int pos=getPosGivenTime(time,eps);
8806   return getTimeStepAtPos(pos);
8807 }
8808
8809 /*!
8810  * 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.
8811  * The float64 value of time attached to the pair of integers are not considered here.
8812  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8813  *
8814  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8815  * \throw If there is a null pointer in \a vectFMTS.
8816  */
8817 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8818 {
8819   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8820   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8821   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8822   while(!lstFMTS.empty())
8823     {
8824       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8825       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8826       if(!curIt)
8827         throw INTERP_KERNEL::Exception(msg);
8828       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8829       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8830       elt.push_back(curIt); it=lstFMTS.erase(it);
8831       while(it!=lstFMTS.end())
8832         {
8833           curIt=*it;
8834           if(!curIt)
8835             throw INTERP_KERNEL::Exception(msg);
8836           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8837           if(refIts==curIts)
8838             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8839           else
8840             it++;
8841         }
8842       ret.push_back(elt);
8843     }
8844   return ret;
8845 }
8846
8847 /*!
8848  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8849  * All returned instances in a subvector can be safely loaded, rendered along time
8850  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8851  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8852  * 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).
8853  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8854  * 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.
8855  *
8856  * \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().
8857  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8858  * \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.
8859  * \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.
8860  *
8861  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8862  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8863  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8864  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8865  * \throw If mesh is null.
8866  * \throw If an element in \a vectFMTS is null.
8867  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8868  */
8869 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
8870 {
8871   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8872   if(!mesh)
8873     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8874   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8875   if(vectFMTS.empty())
8876     return ret;
8877   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8878   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8879   if(!frstElt)
8880     throw INTERP_KERNEL::Exception(msg);
8881   std::size_t i=0;
8882   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8883   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8884   for(;it!=vectFMTS.end();it++,i++)
8885     {
8886       if(!(*it))
8887         throw INTERP_KERNEL::Exception(msg);
8888       TypeOfField tof0,tof1;
8889       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8890         {
8891           if(tof1!=ON_NODES)
8892             vectFMTSNotNodes.push_back(*it);
8893           else
8894             vectFMTSNodes.push_back(*it);
8895         }
8896       else
8897         vectFMTSNotNodes.push_back(*it);
8898     }
8899   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
8900   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8901   ret=retCell;
8902   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8903     {
8904       i=0;
8905       bool isFetched(false);
8906       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8907         {
8908           if((*it0).empty())
8909             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8910           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8911             { ret[i].push_back(*it2); isFetched=true; }
8912         }
8913       if(!isFetched)
8914         {
8915           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8916           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8917           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8918         }
8919     }
8920   fsc=cmps;
8921   return ret;
8922 }
8923
8924 /*!
8925  * 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.
8926  * \param [out] cmps - same size than the returned vector.
8927  */
8928 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
8929 {
8930   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8931   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8932   while(!lstFMTS.empty())
8933     {
8934       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8935       MEDFileAnyTypeFieldMultiTS *ref(*it);
8936       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8937       elt.push_back(ref); it=lstFMTS.erase(it);
8938       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8939       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8940       while(it!=lstFMTS.end())
8941         {
8942           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8943           if(cmp->isEqual(curIt))
8944             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8945           else
8946             it++;
8947         }
8948       ret.push_back(elt); cmps.push_back(cmp);
8949     }
8950   return ret;
8951 }
8952
8953 /*!
8954  * 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.
8955  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8956  *
8957  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8958  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8959  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8960  * \thorw If \a f0 and \a f1 do not have the same times steps.
8961  * \throw If mesh is null.
8962  * \throw If \a f0 or \a f1 is null.
8963  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8964  */
8965 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8966 {
8967   if(!mesh)
8968     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8969   if(!f0 || !f1)
8970     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8971   if(f0->getMeshName()!=mesh->getName())
8972     {
8973       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8974       throw INTERP_KERNEL::Exception(oss.str());
8975     }
8976   if(f1->getMeshName()!=mesh->getName())
8977     {
8978       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8979       throw INTERP_KERNEL::Exception(oss.str());
8980     }
8981   int nts=f0->getNumberOfTS();
8982   if(nts!=f1->getNumberOfTS())
8983     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8984   if(nts==0)
8985     return nts;
8986   for(int i=0;i<nts;i++)
8987     {
8988       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8989       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8990       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8991       if(tofs0.size()!=1 || tofs1.size()!=1)
8992         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8993       if(i!=0)
8994         {
8995           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8996             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8997         }
8998       else
8999         { tof0=tofs0[0]; tof1=tofs1[0]; }
9000       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
9001         {
9002           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() << ") !";
9003           throw INTERP_KERNEL::Exception(oss.str());
9004         }
9005       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
9006         {
9007           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() << ") !";
9008           throw INTERP_KERNEL::Exception(oss.str());
9009         }
9010       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
9011         {
9012           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() << ") !";
9013           throw INTERP_KERNEL::Exception(oss.str());
9014         }
9015     }
9016   return nts;
9017 }
9018
9019 /*!
9020  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9021  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9022  *
9023  * \return A new object that the caller is responsible to deallocate.
9024  */
9025 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9026 {
9027   if(!mm)
9028     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9029   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
9030   int nbTS(getNumberOfTS());
9031   for(int i=0;i<nbTS;i++)
9032     {
9033       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
9034       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9035       fmtsOut->pushBackTimeStep(f1tsOut);
9036     }
9037   return fmtsOut.retn();
9038 }
9039
9040 template<class T>
9041 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9042 {
9043   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
9044   if(f1tss.empty())
9045     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
9046   std::size_t sz(f1tss.size()),i(0);
9047   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
9048   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
9049     {
9050       typename MLFieldTraits<T>::F1TSType const *elt(*it);
9051       if(!elt)
9052         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
9053       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
9054     }
9055   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
9056   if(!retc)
9057     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
9058   retc->aggregate(f1tsw,dts);
9059   ret->setDtUnit(f1tss[0]->getDtUnit());
9060   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
9061 }
9062
9063 template<class T>
9064 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9065 {
9066   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
9067   if(fmtss.empty())
9068     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
9069   std::size_t sz(fmtss.size());
9070   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9071     {
9072       typename MLFieldTraits<T>::FMTSType const *elt(*it);
9073       if(!elt)
9074         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
9075     }
9076   int nbTS(fmtss[0]->getNumberOfTS());
9077   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9078     if((*it)->getNumberOfTS()!=nbTS)
9079       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
9080   for(int iterTS=0;iterTS<nbTS;iterTS++)
9081     {
9082       std::size_t i(0);
9083       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
9084       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
9085       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
9086         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
9087       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
9088       ret->pushBackTimeStep(f1ts);
9089       ret->setDtUnit(f1ts->getDtUnit());
9090     }
9091   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
9092 }
9093
9094 /*!
9095  * \a dts and \a ftmss are expected to have same size.
9096  */
9097 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9098 {
9099   if(fmtss.empty())
9100     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
9101   std::size_t sz(fmtss.size());
9102   std::vector<const MEDFileFieldMultiTS *> fmtss1;
9103   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
9104   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9105     {
9106       if(!(*it))
9107         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
9108       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
9109       if(elt1)
9110         {
9111           fmtss1.push_back(elt1);
9112           continue;
9113         }
9114       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
9115       if(elt2)
9116         {
9117           fmtss2.push_back(elt2);
9118           continue;
9119         }
9120       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
9121     }
9122   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
9123     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
9124   if(fmtss1.size()==sz)
9125     return AggregateHelperFMTS<double>(fmtss1,dts);
9126   if(fmtss2.size()!=sz)
9127     return AggregateHelperFMTS<int>(fmtss2,dts);
9128   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9129 }
9130
9131 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9132 {
9133   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9134 }
9135
9136 //= MEDFileFieldMultiTS
9137
9138 /*!
9139  * Returns a new empty instance of MEDFileFieldMultiTS.
9140  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9141  *          is to delete this field using decrRef() as it is no more needed.
9142  */
9143 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9144 {
9145   return new MEDFileFieldMultiTS;
9146 }
9147
9148 /*!
9149  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9150  * that has been read from a specified MED file.
9151  *  \param [in] fileName - the name of the MED file to read.
9152  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9153  *          is to delete this field using decrRef() as it is no more needed.
9154  *  \throw If reading the file fails.
9155  */
9156 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9157 {
9158   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9159   return New(fid,loadAll);
9160 }
9161
9162 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, bool loadAll)
9163 {
9164   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,loadAll,0));
9165   ret->contentNotNull();//to check that content type matches with \a this type.
9166   return ret.retn();
9167 }
9168
9169 /*!
9170  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9171  * that has been read from a specified MED file.
9172  *  \param [in] fileName - the name of the MED file to read.
9173  *  \param [in] fieldName - the name of the field to read.
9174  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9175  *          is to delete this field using decrRef() as it is no more needed.
9176  *  \throw If reading the file fails.
9177  *  \throw If there is no field named \a fieldName in the file.
9178  */
9179 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9180 {
9181   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9182   return New(fid,fieldName,loadAll);
9183 }
9184
9185 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9186 {
9187   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0));
9188   ret->contentNotNull();//to check that content type matches with \a this type.
9189   return ret.retn();
9190 }
9191
9192 /*!
9193  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9194  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9195  *
9196  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9197  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9198  * \warning this is a shallow copy constructor
9199  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9200  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9201  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9202  *          is to delete this field using decrRef() as it is no more needed.
9203  */
9204 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9205 {
9206   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9207 }
9208
9209 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9210 {
9211   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9212   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0,&entities));
9213   ret->contentNotNull();//to check that content type matches with \a this type.
9214   return ret.retn();
9215 }
9216
9217 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9218 {
9219   return new MEDFileFieldMultiTS(*this);
9220 }
9221
9222 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9223 {
9224   if(!f1ts)
9225     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9226   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9227   if(!f1tsC)
9228     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9229 }
9230
9231 /*!
9232  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9233  * following the given input policy.
9234  *
9235  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9236  *                            By default (true) the globals are deeply copied.
9237  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9238  */
9239 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9240 {
9241   MCAuto<MEDFileIntFieldMultiTS> ret;
9242   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9243   if(content)
9244     {
9245       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9246       if(!contc)
9247         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9248       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9249       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
9250     }
9251   else
9252     ret=MEDFileIntFieldMultiTS::New();
9253   if(isDeepCpyGlobs)
9254     ret->deepCpyGlobs(*this);
9255   else
9256     ret->shallowCpyGlobs(*this);
9257   return ret.retn();
9258 }
9259
9260 /*!
9261  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9262  *  \param [in] pos - a time step id.
9263  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9264  *          delete this field using decrRef() as it is no more needed.
9265  *  \throw If \a pos is not a valid time step id.
9266  */
9267 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9268 {
9269   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9270   if(!item)
9271     {
9272       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9273       throw INTERP_KERNEL::Exception(oss.str());
9274     }
9275   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9276   if(itemC)
9277     {
9278       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9279       ret->shallowCpyGlobs(*this);
9280       return ret.retn();
9281     }
9282   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9283   throw INTERP_KERNEL::Exception(oss.str());
9284 }
9285
9286 /*!
9287  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9288  * mesh entities of a given dimension of the first mesh in MED file.
9289  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9290  *  \param [in] type - a spatial discretization of interest.
9291  *  \param [in] iteration - the iteration number of a required time step.
9292  *  \param [in] order - the iteration order number of required time step.
9293  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9294  *  \param [in] renumPol - specifies how to permute values of the result field according to
9295  *          the optional numbers of cells and nodes, if any. The valid values are
9296  *          - 0 - do not permute.
9297  *          - 1 - permute cells.
9298  *          - 2 - permute nodes.
9299  *          - 3 - permute cells and nodes.
9300  *
9301  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9302  *          caller is to delete this field using decrRef() as it is no more needed. 
9303  *  \throw If the MED file is not readable.
9304  *  \throw If there is no mesh in the MED file.
9305  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9306  *  \throw If no field values of the required parameters are available.
9307  */
9308 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9309 {
9310   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9311   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9312   if(!myF1TSC)
9313     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9314   MCAuto<DataArray> arrOut;
9315   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9316   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9317   return ret.retn();
9318 }
9319
9320 /*!
9321  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9322  * the top level cells of the first mesh in MED file.
9323  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9324  *  \param [in] type - a spatial discretization of interest.
9325  *  \param [in] iteration - the iteration number of a required time step.
9326  *  \param [in] order - the iteration order number of required time step.
9327  *  \param [in] renumPol - specifies how to permute values of the result field according to
9328  *          the optional numbers of cells and nodes, if any. The valid values are
9329  *          - 0 - do not permute.
9330  *          - 1 - permute cells.
9331  *          - 2 - permute nodes.
9332  *          - 3 - permute cells and nodes.
9333  *
9334  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9335  *          caller is to delete this field using decrRef() as it is no more needed. 
9336  *  \throw If the MED file is not readable.
9337  *  \throw If there is no mesh in the MED file.
9338  *  \throw If no field values of the required parameters are available.
9339  */
9340 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9341 {
9342   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9343   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9344   if(!myF1TSC)
9345     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9346   MCAuto<DataArray> arrOut;
9347   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9348   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9349   return ret.retn();
9350 }
9351
9352 /*!
9353  * 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
9354  * method should be called (getFieldOnMeshAtLevel for example).
9355  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9356  *
9357  * \param [in] iteration - the iteration number of a required time step.
9358  * \param [in] order - the iteration order number of required time step.
9359  * \param [in] mesh - the mesh the field is lying on
9360  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9361  *          caller is to delete this field using decrRef() as it is no more needed. 
9362  */
9363 MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9364 {
9365   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9366   MCAuto<DataArray> arrOut;
9367   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9368   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9369   return ret.retn();
9370 }
9371
9372 /*!
9373  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9374  * a given support.
9375  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9376  *  \param [in] type - a spatial discretization of interest.
9377  *  \param [in] iteration - the iteration number of a required time step.
9378  *  \param [in] order - the iteration order number of required time step.
9379  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9380  *  \param [in] mesh - the supporting mesh.
9381  *  \param [in] renumPol - specifies how to permute values of the result field according to
9382  *          the optional numbers of cells and nodes, if any. The valid values are
9383  *          - 0 - do not permute.
9384  *          - 1 - permute cells.
9385  *          - 2 - permute nodes.
9386  *          - 3 - permute cells and nodes.
9387  *
9388  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9389  *          caller is to delete this field using decrRef() as it is no more needed. 
9390  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9391  *  \throw If no field of \a this is lying on \a mesh.
9392  *  \throw If no field values of the required parameters are available.
9393  */
9394 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9395 {
9396   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9397   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9398   if(!myF1TSC)
9399     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9400   MCAuto<DataArray> arrOut;
9401   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9402   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9403   return ret.retn();
9404 }
9405
9406 /*!
9407  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9408  * given support. 
9409  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9410  *  \param [in] type - a spatial discretization of the new field.
9411  *  \param [in] iteration - the iteration number of a required time step.
9412  *  \param [in] order - the iteration order number of required time step.
9413  *  \param [in] mesh - the supporting mesh.
9414  *  \param [in] renumPol - specifies how to permute values of the result field according to
9415  *          the optional numbers of cells and nodes, if any. The valid values are
9416  *          - 0 - do not permute.
9417  *          - 1 - permute cells.
9418  *          - 2 - permute nodes.
9419  *          - 3 - permute cells and nodes.
9420  *
9421  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9422  *          caller is to delete this field using decrRef() as it is no more needed. 
9423  *  \throw If no field of \a this is lying on \a mesh.
9424  *  \throw If no field values of the required parameters are available.
9425  */
9426 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9427 {
9428   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9429   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9430   if(!myF1TSC)
9431     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9432   MCAuto<DataArray> arrOut;
9433   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9434   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9435   return ret.retn();
9436 }
9437
9438 /*!
9439  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9440  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9441  * This method is useful for MED2 file format when field on different mesh was autorized.
9442  */
9443 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9444 {
9445   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9446   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9447   if(!myF1TSC)
9448     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9449   MCAuto<DataArray> arrOut;
9450   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9451   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9452   return ret.retn();
9453 }
9454
9455 /*!
9456  * Returns values and a profile of the field of a given type, of a given time step,
9457  * lying on a given support.
9458  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9459  *  \param [in] type - a spatial discretization of the field.
9460  *  \param [in] iteration - the iteration number of a required time step.
9461  *  \param [in] order - the iteration order number of required time step.
9462  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9463  *  \param [in] mesh - the supporting mesh.
9464  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9465  *          field of interest lies on. If the field lies on all entities of the given
9466  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9467  *          using decrRef() as it is no more needed.  
9468  *  \param [in] glob - the global data storing profiles and localization.
9469  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9470  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9471  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9472  *  \throw If no field of \a this is lying on \a mesh.
9473  *  \throw If no field values of the required parameters are available.
9474  */
9475 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9476 {
9477   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9478   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9479   if(!myF1TSC)
9480     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9481   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9482   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9483 }
9484
9485 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9486 {
9487   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9488   if(!pt)
9489     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9490   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9491   if(!ret)
9492     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 !");
9493   return ret;
9494 }
9495
9496 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9497 {
9498   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9499   if(!pt)
9500     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9501   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9502   if(!ret)
9503     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 !");
9504   return ret;
9505 }
9506
9507 /*!
9508  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9509  * the given field is checked if its elements are sorted suitable for writing to MED file
9510  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9511  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9512  *  \param [in] field - the field to add to \a this.
9513  *  \throw If the name of \a field is empty.
9514  *  \throw If the data array of \a field is not set.
9515  *  \throw If existing time steps have different name or number of components than \a field.
9516  *  \throw If the underlying mesh of \a field has no name.
9517  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9518  */
9519 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9520 {
9521   const DataArrayDouble *arr=0;
9522   if(field)
9523     arr=field->getArray();
9524   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9525 }
9526
9527 /*!
9528  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9529  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9530  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9531  * and \a profile.
9532  *
9533  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9534  * A new profile is added only if no equal profile is missing.
9535  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9536  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9537  *  \param [in] mesh - the supporting mesh of \a field.
9538  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9539  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9540  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9541  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9542  *  \throw If the data array of \a field is not set.
9543  *  \throw If the data array of \a this is already allocated but has different number of
9544  *         components than \a field.
9545  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9546  *  \sa setFieldNoProfileSBT()
9547  */
9548 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9549 {
9550   const DataArrayDouble *arr=0;
9551   if(field)
9552     arr=field->getArray();
9553   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9554 }
9555
9556 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9557 {
9558   _content=new MEDFileFieldMultiTSWithoutSDA;
9559 }
9560
9561 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
9562 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
9563 {
9564 }
9565 catch(INTERP_KERNEL::Exception& e)
9566 { throw e; }
9567
9568 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9569 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
9570 {
9571 }
9572 catch(INTERP_KERNEL::Exception& e)
9573 { throw e; }
9574
9575 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9576 {
9577 }
9578
9579 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
9580 {
9581   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9582 }
9583
9584 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9585 {
9586   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9587 }
9588
9589 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9590 {
9591   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9592 }
9593
9594 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
9595 {
9596   return MEDFileFieldMultiTS::New();
9597 }
9598
9599 //= MEDFileAnyTypeFieldMultiTSIterator
9600
9601 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9602 {
9603   if(fmts)
9604     {
9605       fmts->incrRef();
9606       _nb_iter=fmts->getNumberOfTS();
9607     }
9608 }
9609
9610 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9611 {
9612 }
9613
9614 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9615 {
9616   if(_iter_id<_nb_iter)
9617     {
9618       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9619       if(fmts)
9620         return fmts->getTimeStepAtPos(_iter_id++);
9621       else
9622         return 0;
9623     }
9624   else
9625     return 0;
9626 }
9627
9628 //= MEDFileIntFieldMultiTS
9629
9630 /*!
9631  * Returns a new empty instance of MEDFileFieldMultiTS.
9632  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9633  *          is to delete this field using decrRef() as it is no more needed.
9634  */
9635 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9636 {
9637   return new MEDFileIntFieldMultiTS;
9638 }
9639
9640 /*!
9641  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9642  * that has been read from a specified MED file.
9643  *  \param [in] fileName - the name of the MED file to read.
9644  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9645  *          is to delete this field using decrRef() as it is no more needed.
9646  *  \throw If reading the file fails.
9647  */
9648 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9649 {
9650   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9651   return New(fid,loadAll);
9652 }
9653
9654 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, bool loadAll)
9655 {
9656   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,loadAll,0));
9657   ret->contentNotNull();//to check that content type matches with \a this type.
9658   return ret.retn();
9659 }
9660
9661 /*!
9662  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9663  * that has been read from a specified MED file.
9664  *  \param [in] fileName - the name of the MED file to read.
9665  *  \param [in] fieldName - the name of the field to read.
9666  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9667  *          is to delete this field using decrRef() as it is no more needed.
9668  *  \throw If reading the file fails.
9669  *  \throw If there is no field named \a fieldName in the file.
9670  */
9671 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9672 {
9673   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9674   return New(fid,fieldName,loadAll);
9675 }
9676
9677 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9678 {
9679   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0));
9680   ret->contentNotNull();//to check that content type matches with \a this type.
9681   return ret.retn();
9682 }
9683
9684 /*!
9685  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9686  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9687  *
9688  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9689  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9690  * \warning this is a shallow copy constructor
9691  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9692  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9693  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9694  *          is to delete this field using decrRef() as it is no more needed.
9695  */
9696 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9697 {
9698   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9699 }
9700
9701 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9702 {
9703   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9704   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0,&entities));
9705   ret->contentNotNull();//to check that content type matches with \a this type.
9706   return ret.retn();
9707 }
9708
9709 /*!
9710  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9711  * following the given input policy.
9712  *
9713  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9714  *                            By default (true) the globals are deeply copied.
9715  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9716  */
9717 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9718 {
9719   MCAuto<MEDFileFieldMultiTS> ret;
9720   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9721   if(content)
9722     {
9723       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9724       if(!contc)
9725         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9726       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9727       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
9728     }
9729   else
9730     ret=MEDFileFieldMultiTS::New();
9731   if(isDeepCpyGlobs)
9732     ret->deepCpyGlobs(*this);
9733   else
9734     ret->shallowCpyGlobs(*this);
9735   return ret.retn();
9736 }
9737
9738 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9739 {
9740   return new MEDFileIntFieldMultiTS(*this);
9741 }
9742
9743 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9744 {
9745   if(!f1ts)
9746     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9747   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9748   if(!f1tsC)
9749     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9750 }
9751
9752 /*!
9753  * 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
9754  * method should be called (getFieldOnMeshAtLevel for example).
9755  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9756  *
9757  * \param [in] iteration - the iteration number of a required time step.
9758  * \param [in] order - the iteration order number of required time step.
9759  * \param [in] mesh - the mesh the field is lying on
9760  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
9761  *          caller is to delete this field using decrRef() as it is no more needed. 
9762  */
9763 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9764 {
9765   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9766   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9767   if(!myF1TSC)
9768     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
9769   MCAuto<DataArray> arrOut;
9770   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9771   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
9772   return ret2.retn();
9773 }
9774
9775 /*!
9776  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9777  * mesh entities of a given dimension of the first mesh in MED file.
9778  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9779  *  \param [in] type - a spatial discretization of interest.
9780  *  \param [in] iteration - the iteration number of a required time step.
9781  *  \param [in] order - the iteration order number of required time step.
9782  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9783  *  \param [in] renumPol - specifies how to permute values of the result field according to
9784  *          the optional numbers of cells and nodes, if any. The valid values are
9785  *          - 0 - do not permute.
9786  *          - 1 - permute cells.
9787  *          - 2 - permute nodes.
9788  *          - 3 - permute cells and nodes.
9789  *
9790  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9791  *          caller is to delete this field using decrRef() as it is no more needed. 
9792  *  \throw If the MED file is not readable.
9793  *  \throw If there is no mesh in the MED file.
9794  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9795  *  \throw If no field values of the required parameters are available.
9796  */
9797 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9798 {
9799   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9800   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9801   if(!myF1TSC)
9802     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9803   MCAuto<DataArray> arr;
9804   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
9805   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9806   return ret2.retn();
9807 }
9808
9809 /*!
9810  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9811  * the top level cells of the first mesh in MED file.
9812  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9813  *  \param [in] type - a spatial discretization of interest.
9814  *  \param [in] iteration - the iteration number of a required time step.
9815  *  \param [in] order - the iteration order number of required time step.
9816  *  \param [in] renumPol - specifies how to permute values of the result field according to
9817  *          the optional numbers of cells and nodes, if any. The valid values are
9818  *          - 0 - do not permute.
9819  *          - 1 - permute cells.
9820  *          - 2 - permute nodes.
9821  *          - 3 - permute cells and nodes.
9822  *
9823  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9824  *          caller is to delete this field using decrRef() as it is no more needed. 
9825  *  \throw If the MED file is not readable.
9826  *  \throw If there is no mesh in the MED file.
9827  *  \throw If no field values of the required parameters are available.
9828  */
9829 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9830 {
9831   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9832   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9833   if(!myF1TSC)
9834     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9835   MCAuto<DataArray> arr;
9836   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
9837   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9838   return ret2.retn();
9839 }
9840
9841 /*!
9842  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9843  * a given support.
9844  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9845  *  \param [in] type - a spatial discretization of interest.
9846  *  \param [in] iteration - the iteration number of a required time step.
9847  *  \param [in] order - the iteration order number of required time step.
9848  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9849  *  \param [in] mesh - the supporting mesh.
9850  *  \param [in] renumPol - specifies how to permute values of the result field according to
9851  *          the optional numbers of cells and nodes, if any. The valid values are
9852  *          - 0 - do not permute.
9853  *          - 1 - permute cells.
9854  *          - 2 - permute nodes.
9855  *          - 3 - permute cells and nodes.
9856  *
9857  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9858  *          caller is to delete this field using decrRef() as it is no more needed. 
9859  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9860  *  \throw If no field of \a this is lying on \a mesh.
9861  *  \throw If no field values of the required parameters are available.
9862  */
9863 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9864 {
9865   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9866   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9867   if(!myF1TSC)
9868     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9869   MCAuto<DataArray> arr;
9870   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
9871   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9872   return ret2.retn();
9873 }
9874
9875 /*!
9876  * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
9877  * given support. 
9878  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9879  *  \param [in] type - a spatial discretization of the new field.
9880  *  \param [in] iteration - the iteration number of a required time step.
9881  *  \param [in] order - the iteration order number of required time step.
9882  *  \param [in] mesh - the supporting mesh.
9883  *  \param [out] arrOut - the DataArrayInt containing values of field.
9884  *  \param [in] renumPol - specifies how to permute values of the result field according to
9885  *          the optional numbers of cells and nodes, if any. The valid values are
9886  *          - 0 - do not permute.
9887  *          - 1 - permute cells.
9888  *          - 2 - permute nodes.
9889  *          - 3 - permute cells and nodes.
9890  *
9891  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9892  *          caller is to delete this field using decrRef() as it is no more needed. 
9893  *  \throw If no field of \a this is lying on \a mesh.
9894  *  \throw If no field values of the required parameters are available.
9895  */
9896 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9897 {
9898   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9899   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9900   if(!myF1TSC)
9901     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9902   MCAuto<DataArray> arr;
9903   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
9904   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9905   return ret2.retn();
9906 }
9907
9908 /*!
9909  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9910  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9911  * This method is useful for MED2 file format when field on different mesh was autorized.
9912  */
9913 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
9914 {
9915   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9916   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9917   if(!myF1TSC)
9918     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9919   MCAuto<DataArray> arr;
9920   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
9921   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9922   return ret2.retn();
9923 }
9924
9925 /*!
9926  * Returns values and a profile of the field of a given type, of a given time step,
9927  * lying on a given support.
9928  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9929  *  \param [in] type - a spatial discretization of the field.
9930  *  \param [in] iteration - the iteration number of a required time step.
9931  *  \param [in] order - the iteration order number of required time step.
9932  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9933  *  \param [in] mesh - the supporting mesh.
9934  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9935  *          field of interest lies on. If the field lies on all entities of the given
9936  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9937  *          using decrRef() as it is no more needed.  
9938  *  \param [in] glob - the global data storing profiles and localization.
9939  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9940  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9941  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9942  *  \throw If no field of \a this is lying on \a mesh.
9943  *  \throw If no field values of the required parameters are available.
9944  */
9945 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9946 {
9947   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9948   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9949   if(!myF1TSC)
9950     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9951   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9952   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9953 }
9954
9955 /*!
9956  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9957  *  \param [in] pos - a time step id.
9958  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9959  *          delete this field using decrRef() as it is no more needed.
9960  *  \throw If \a pos is not a valid time step id.
9961  */
9962 MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9963 {
9964   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9965   if(!item)
9966     {
9967       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9968       throw INTERP_KERNEL::Exception(oss.str());
9969     }
9970   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9971   if(itemC)
9972     {
9973       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9974       ret->shallowCpyGlobs(*this);
9975       return ret.retn();
9976     }
9977   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9978   throw INTERP_KERNEL::Exception(oss.str());
9979 }
9980
9981 /*!
9982  * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
9983  * the given field is checked if its elements are sorted suitable for writing to MED file
9984  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9985  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9986  *  \param [in] field - the field to add to \a this.
9987  *  \throw If the name of \a field is empty.
9988  *  \throw If the data array of \a field is not set.
9989  *  \throw If existing time steps have different name or number of components than \a field.
9990  *  \throw If the underlying mesh of \a field has no name.
9991  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9992  */
9993 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
9994 {
9995   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
9996   contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
9997 }
9998
9999 /*!
10000  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
10001  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10002  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10003  * and \a profile.
10004  *
10005  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10006  * A new profile is added only if no equal profile is missing.
10007  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10008  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
10009  *  \param [in] arrOfVals - the values of the field \a field used.
10010  *  \param [in] mesh - the supporting mesh of \a field.
10011  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10012  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10013  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10014  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10015  *  \throw If the data array of \a field is not set.
10016  *  \throw If the data array of \a this is already allocated but has different number of
10017  *         components than \a field.
10018  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10019  *  \sa setFieldNoProfileSBT()
10020  */
10021 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10022 {
10023   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10024   contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
10025 }
10026
10027 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
10028 {
10029   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10030   if(!pt)
10031     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
10032   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10033   if(!ret)
10034     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 !");
10035   return ret;
10036 }
10037
10038 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
10039 {
10040   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10041   if(!pt)
10042     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
10043   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10044   if(!ret)
10045     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 !");
10046   return ret;
10047 }
10048
10049 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
10050 {
10051   _content=new MEDFileIntFieldMultiTSWithoutSDA;
10052 }
10053
10054 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10055 {
10056 }
10057
10058 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10059 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10060 {
10061 }
10062 catch(INTERP_KERNEL::Exception& e)
10063 { throw e; }
10064
10065 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
10066 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10067 {
10068 }
10069 catch(INTERP_KERNEL::Exception& e)
10070 { throw e; }
10071
10072 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10073 {
10074   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10075 }
10076
10077 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
10078 {
10079   return MEDFileIntFieldMultiTS::New();
10080 }
10081
10082 //= MEDFileFields
10083
10084 MEDFileFields *MEDFileFields::New()
10085 {
10086   return new MEDFileFields;
10087 }
10088
10089 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
10090 {
10091   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10092   return New(fid,loadAll);
10093 }
10094
10095 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
10096 {
10097   return new MEDFileFields(fid,loadAll,0,0);
10098 }
10099
10100 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10101 {
10102   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10103   return new MEDFileFields(fid,loadAll,ms,0);
10104 }
10105
10106 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10107 {
10108   MEDFileUtilities::CheckFileForRead(fileName);
10109   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10110   return new MEDFileFields(fid,loadAll,0,&entities);
10111 }
10112
10113 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
10114 {
10115   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
10116   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
10117   return ret;
10118 }
10119
10120 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
10121 {
10122   std::vector<const BigMemoryObject *> ret;
10123   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10124     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
10125   return ret;
10126 }
10127
10128 MEDFileFields *MEDFileFields::deepCopy() const
10129 {
10130   MCAuto<MEDFileFields> ret(shallowCpy());
10131   std::size_t i(0);
10132   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10133     {
10134       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10135         ret->_fields[i]=(*it)->deepCopy();
10136     }
10137   ret->deepCpyGlobs(*this);
10138   return ret.retn();
10139 }
10140
10141 MEDFileFields *MEDFileFields::shallowCpy() const
10142 {
10143   return new MEDFileFields(*this);
10144 }
10145
10146 /*!
10147  * 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
10148  * 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.
10149  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
10150  *
10151  * \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.
10152  * \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.
10153  * 
10154  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10155  */
10156 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
10157 {
10158   std::set< std::pair<int,int> > s;
10159   bool firstShot=true;
10160   areThereSomeForgottenTS=false;
10161   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10162     {
10163       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10164         continue;
10165       std::vector< std::pair<int,int> > v=(*it)->getIterations();
10166       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
10167       if(firstShot)
10168         { s=s1; firstShot=false; }
10169       else
10170         {
10171           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
10172           if(s!=s2)
10173             areThereSomeForgottenTS=true;
10174           s=s2;
10175         }
10176     }
10177   std::vector< std::pair<int,int> > ret;
10178   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
10179   return ret;
10180 }
10181
10182 int MEDFileFields::getNumberOfFields() const
10183 {
10184   return _fields.size();
10185 }
10186
10187 std::vector<std::string> MEDFileFields::getFieldsNames() const
10188 {
10189   std::vector<std::string> ret(_fields.size());
10190   int i(0);
10191   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10192     {
10193       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
10194       if(f)
10195         {
10196           ret[i]=f->getName();
10197         }
10198       else
10199         {
10200           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
10201           throw INTERP_KERNEL::Exception(oss.str());
10202         }
10203     }
10204   return ret;
10205 }
10206
10207 std::vector<std::string> MEDFileFields::getMeshesNames() const
10208 {
10209   std::vector<std::string> ret;
10210   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10211     {
10212       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10213       if(cur)
10214         ret.push_back(cur->getMeshName());
10215     }
10216   return ret;
10217 }
10218
10219 std::string MEDFileFields::simpleRepr() const
10220 {
10221   std::ostringstream oss;
10222   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10223   simpleRepr(0,oss);
10224   return oss.str();
10225 }
10226
10227 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10228 {
10229   int nbOfFields(getNumberOfFields());
10230   std::string startLine(bkOffset,' ');
10231   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10232   int i=0;
10233   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10234     {
10235       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10236       if(cur)
10237         {
10238           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10239         }
10240       else
10241         {
10242           oss << startLine << "  - not defined !" << std::endl;
10243         }
10244     }
10245   i=0;
10246   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10247     {
10248       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10249       std::string chapter(17,'0'+i);
10250       oss << startLine << chapter << std::endl;
10251       if(cur)
10252         {
10253           cur->simpleRepr(bkOffset+2,oss,i);
10254         }
10255       else
10256         {
10257           oss << startLine << "  - not defined !" << std::endl;
10258         }
10259       oss << startLine << chapter << std::endl;
10260     }
10261   simpleReprGlobs(oss);
10262 }
10263
10264 MEDFileFields::MEDFileFields()
10265 {
10266 }
10267
10268 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
10269 try:MEDFileFieldGlobsReal(fid)
10270 {
10271   int nbFields(MEDnField(fid));
10272   _fields.resize(nbFields);
10273   med_field_type typcha;
10274   for(int i=0;i<nbFields;i++)
10275     {
10276       std::vector<std::string> infos;
10277       std::string fieldName,dtunit;
10278       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit));
10279       switch(typcha)
10280       {
10281         case MED_FLOAT64:
10282           {
10283             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10284             break;
10285           }
10286         case MED_INT32:
10287           {
10288             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10289             break;
10290           }
10291         default:
10292           {
10293             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] !";
10294             throw INTERP_KERNEL::Exception(oss.str());
10295           }
10296       }
10297     }
10298   loadAllGlobals(fid);
10299 }
10300 catch(INTERP_KERNEL::Exception& e)
10301 {
10302     throw e;
10303 }
10304
10305 void MEDFileFields::writeLL(med_idt fid) const
10306 {
10307   int i=0;
10308   writeGlobals(fid,*this);
10309   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10310     {
10311       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10312       if(!elt)
10313         {
10314           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10315           throw INTERP_KERNEL::Exception(oss.str());
10316         }
10317       elt->writeLL(fid,*this);
10318     }
10319 }
10320
10321 /*!
10322  * This method alloc the arrays and load potentially huge arrays contained in this field.
10323  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10324  * This method can be also called to refresh or reinit values from a file.
10325  * 
10326  * \throw If the fileName is not set or points to a non readable MED file.
10327  */
10328 void MEDFileFields::loadArrays()
10329 {
10330   if(getFileName().empty())
10331     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10332   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10333   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10334     {
10335       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10336       if(elt)
10337         elt->loadBigArraysRecursively(fid,*elt);
10338     }
10339 }
10340
10341 /*!
10342  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10343  * But once data loaded once, this method does nothing.
10344  * 
10345  * \throw If the fileName is not set or points to a non readable MED file.
10346  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10347  */
10348 void MEDFileFields::loadArraysIfNecessary()
10349 {
10350   if(!getFileName().empty())
10351     {
10352       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10353       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10354         {
10355           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10356           if(elt)
10357             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10358         }
10359     }
10360 }
10361
10362 /*!
10363  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10364  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10365  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10366  * 
10367  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10368  */
10369 void MEDFileFields::unloadArrays()
10370 {
10371   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10372     {
10373       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10374       if(elt)
10375         elt->unloadArrays();
10376     }
10377 }
10378
10379 /*!
10380  * 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.
10381  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10382  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10383  * 
10384  * \sa MEDFileFields::loadArraysIfNecessary
10385  */
10386 void MEDFileFields::unloadArraysWithoutDataLoss()
10387 {
10388   if(!getFileName().empty())
10389     unloadArrays();
10390 }
10391
10392 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10393 {
10394   std::vector<std::string> ret;
10395   std::set<std::string> ret2;
10396   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10397     {
10398       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10399       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10400         if(ret2.find(*it2)==ret2.end())
10401           {
10402             ret.push_back(*it2);
10403             ret2.insert(*it2);
10404           }
10405     }
10406   return ret;
10407 }
10408
10409 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10410 {
10411   std::vector<std::string> ret;
10412   std::set<std::string> ret2;
10413   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10414     {
10415       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10416       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10417         if(ret2.find(*it2)==ret2.end())
10418           {
10419             ret.push_back(*it2);
10420             ret2.insert(*it2);
10421           }
10422     }
10423   return ret;
10424 }
10425
10426 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10427 {
10428   std::vector<std::string> ret;
10429   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10430     {
10431       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
10432       ret.insert(ret.end(),tmp.begin(),tmp.end());
10433     }
10434   return ret;
10435 }
10436
10437 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10438 {
10439   std::vector<std::string> ret;
10440   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10441     {
10442       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10443       ret.insert(ret.end(),tmp.begin(),tmp.end());
10444     }
10445   return ret;
10446 }
10447
10448 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10449 {
10450   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10451     (*it)->changePflsRefsNamesGen2(mapOfModif);
10452 }
10453
10454 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10455 {
10456   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10457     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10458 }
10459
10460 void MEDFileFields::resize(int newSize)
10461 {
10462   _fields.resize(newSize);
10463 }
10464
10465 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10466 {
10467   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10468     pushField(*it);
10469 }
10470
10471 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10472 {
10473   if(!field)
10474     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10475   _fields.push_back(field->getContent());
10476   appendGlobs(*field,1e-12);
10477 }
10478
10479 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10480 {
10481   if(!field)
10482     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10483   if(i>=(int)_fields.size())
10484     _fields.resize(i+1);
10485   _fields[i]=field->getContent();
10486   appendGlobs(*field,1e-12);
10487 }
10488
10489 void MEDFileFields::destroyFieldAtPos(int i)
10490 {
10491   destroyFieldsAtPos(&i,&i+1);
10492 }
10493
10494 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10495 {
10496   std::vector<bool> b(_fields.size(),true);
10497   for(const int *i=startIds;i!=endIds;i++)
10498     {
10499       if(*i<0 || *i>=(int)_fields.size())
10500         {
10501           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10502           throw INTERP_KERNEL::Exception(oss.str());
10503         }
10504       b[*i]=false;
10505     }
10506   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10507   std::size_t j=0;
10508   for(std::size_t i=0;i<_fields.size();i++)
10509     if(b[i])
10510       fields[j++]=_fields[i];
10511   _fields=fields;
10512 }
10513
10514 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10515 {
10516   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10517   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
10518   std::vector<bool> b(_fields.size(),true);
10519   int k=bg;
10520   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10521     {
10522       if(k<0 || k>=(int)_fields.size())
10523         {
10524           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10525           throw INTERP_KERNEL::Exception(oss.str());
10526         }
10527       b[k]=false;
10528     }
10529   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10530   std::size_t j(0);
10531   for(std::size_t i=0;i<_fields.size();i++)
10532     if(b[i])
10533       fields[j++]=_fields[i];
10534   _fields=fields;
10535 }
10536
10537 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10538 {
10539   bool ret(false);
10540   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10541     {
10542       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10543       if(cur)
10544         ret=cur->changeMeshNames(modifTab) || ret;
10545     }
10546   return ret;
10547 }
10548
10549 /*!
10550  * \param [in] meshName the name of the mesh that will be renumbered.
10551  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10552  *             This code corresponds to the distribution of types in the corresponding mesh.
10553  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10554  * \param [in] renumO2N the old to new renumber array.
10555  * \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 
10556  *         field in \a this.
10557  */
10558 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10559 {
10560   bool ret(false);
10561   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10562     {
10563       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10564       if(fmts)
10565         {
10566           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10567         }
10568     }
10569   return ret;
10570 }
10571
10572 /*!
10573  * Return an extraction of \a this using \a extractDef map to specify the extraction.
10574  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
10575  *
10576  * \return A new object that the caller is responsible to deallocate.
10577  */
10578 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
10579 {
10580   if(!mm)
10581     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
10582   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
10583   int nbFields(getNumberOfFields());
10584   for(int i=0;i<nbFields;i++)
10585     {
10586       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
10587       if(!fmts)
10588         {
10589           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
10590           throw INTERP_KERNEL::Exception(oss.str());
10591         }
10592       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
10593       fsOut->pushField(fmtsOut);
10594     }
10595   return fsOut.retn();
10596 }
10597
10598 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10599 {
10600   if(i<0 || i>=(int)_fields.size())
10601     {
10602       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10603       throw INTERP_KERNEL::Exception(oss.str());
10604     }
10605   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10606   if(!fmts)
10607     return 0;
10608   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
10609   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
10610   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
10611   if(fmtsC)
10612     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10613   else if(fmtsC2)
10614     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10615   else
10616     {
10617       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10618       throw INTERP_KERNEL::Exception(oss.str());
10619     }
10620   ret->shallowCpyGlobs(*this);
10621   return ret.retn();
10622 }
10623
10624 /*!
10625  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10626  * This method is accessible in python using __getitem__ with a list in input.
10627  * \return a new object that the caller should deal with.
10628  */
10629 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10630 {
10631   MCAuto<MEDFileFields> ret=shallowCpy();
10632   std::size_t sz=std::distance(startIds,endIds);
10633   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10634   int j=0;
10635   for(const int *i=startIds;i!=endIds;i++,j++)
10636     {
10637       if(*i<0 || *i>=(int)_fields.size())
10638         {
10639           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10640           throw INTERP_KERNEL::Exception(oss.str());
10641         }
10642       fields[j]=_fields[*i];
10643     }
10644   ret->_fields=fields;
10645   return ret.retn();
10646 }
10647
10648 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10649 {
10650   return getFieldAtPos(getPosFromFieldName(fieldName));
10651 }
10652
10653 /*!
10654  * This method removes, if any, fields in \a this having no time steps.
10655  * 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.
10656  * 
10657  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10658  */
10659 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10660 {
10661   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10662   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10663     {
10664       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10665       if(elt)
10666         {
10667           if(elt->getNumberOfTS()>0)
10668             newFields.push_back(*it);
10669         }
10670     }
10671   if(_fields.size()==newFields.size())
10672     return false;
10673   _fields=newFields;
10674   return true;
10675 }
10676
10677 /*!
10678  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10679  * This method can be seen as a filter applied on \a this, that returns an object containing
10680  * 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
10681  * shallow copied from \a this.
10682  * 
10683  * \param [in] meshName - the name of the mesh on w
10684  * \return a new object that the caller should deal with.
10685  */
10686 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10687 {
10688   MCAuto<MEDFileFields> ret(MEDFileFields::New());
10689   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10690     {
10691       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10692       if(!cur)
10693         continue;
10694       if(cur->getMeshName()==meshName)
10695         {
10696           cur->incrRef();
10697           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10698           ret->_fields.push_back(cur2);
10699         }
10700     }
10701   ret->shallowCpyOnlyUsedGlobs(*this);
10702   return ret.retn();
10703 }
10704
10705 /*!
10706  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10707  * Input time steps are specified using a pair of integer (iteration, order).
10708  * 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,
10709  * but for each multitimestep only the time steps in \a timeSteps are kept.
10710  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10711  * 
10712  * The returned object points to shallow copy of elements in \a this.
10713  * 
10714  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10715  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10716  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10717  */
10718 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10719 {
10720   MCAuto<MEDFileFields> ret(MEDFileFields::New());
10721   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10722     {
10723       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10724       if(!cur)
10725         continue;
10726       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10727       ret->_fields.push_back(elt);
10728     }
10729   ret->shallowCpyOnlyUsedGlobs(*this);
10730   return ret.retn();
10731 }
10732
10733 /*!
10734  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10735  */
10736 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10737 {
10738   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10739   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10740     {
10741       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10742       if(!cur)
10743         continue;
10744       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10745       if(elt->getNumberOfTS()!=0)
10746         ret->_fields.push_back(elt);
10747     }
10748   ret->shallowCpyOnlyUsedGlobs(*this);
10749   return ret.retn();
10750 }
10751
10752 MEDFileFieldsIterator *MEDFileFields::iterator()
10753 {
10754   return new MEDFileFieldsIterator(this);
10755 }
10756
10757 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10758 {
10759   std::string tmp(fieldName);
10760   std::vector<std::string> poss;
10761   for(std::size_t i=0;i<_fields.size();i++)
10762     {
10763       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
10764       if(f)
10765         {
10766           std::string fname(f->getName());
10767           if(tmp==fname)
10768             return i;
10769           else
10770             poss.push_back(fname);
10771         }
10772     }
10773   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10774   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10775   oss << " !";
10776   throw INTERP_KERNEL::Exception(oss.str());
10777 }
10778
10779 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10780 {
10781   if(fs)
10782     {
10783       fs->incrRef();
10784       _nb_iter=fs->getNumberOfFields();
10785     }
10786 }
10787
10788 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10789 {
10790 }
10791
10792 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10793 {
10794   if(_iter_id<_nb_iter)
10795     {
10796       MEDFileFields *fs(_fs);
10797       if(fs)
10798         return fs->getFieldAtPos(_iter_id++);
10799       else
10800         return 0;
10801     }
10802   else
10803     return 0;
10804 }