]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDFileField.cxx
Salome HOME
Bug linked with multi node field read in parallel. The first one was modifying the...
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2015  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.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileUtilities.hxx"
25 #include "MEDFileSafeCaller.txx"
26 #include "MEDFileFieldOverView.hxx"
27
28 #include "MEDCouplingFieldDouble.hxx"
29 #include "MEDCouplingFieldDiscretization.hxx"
30
31 #include "InterpKernelAutoPtr.hxx"
32 #include "CellModel.hxx"
33
34 #include <algorithm>
35 #include <iterator>
36
37 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
38 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
39 extern med_geometry_type typmainoeud[1];
40 extern med_geometry_type typmai3[34];
41
42 using namespace MEDCoupling;
43
44 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
45 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
46
47 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
48 {
49   return new MEDFileFieldLoc(fid,locName);
50 }
51
52 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
53 {
54   return new MEDFileFieldLoc(fid,id);
55 }
56
57 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)
58 {
59   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
60 }
61
62 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
63 {
64   med_geometry_type geotype;
65   med_geometry_type sectiongeotype;
66   int nsectionmeshcell;
67   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
68   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
69   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
70   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
71   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
72   _nb_node_per_cell=cm.getNumberOfNodes();
73   _ref_coo.resize(_dim*_nb_node_per_cell);
74   _gs_coo.resize(_dim*_nb_gauss_pt);
75   _w.resize(_nb_gauss_pt);
76   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
77 }
78
79 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
80 {
81   med_geometry_type geotype;
82   med_geometry_type sectiongeotype;
83   int nsectionmeshcell;
84   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
85   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
86   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
87   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
88   _name=locName;
89   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
90   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
91   _nb_node_per_cell=cm.getNumberOfNodes();
92   _ref_coo.resize(_dim*_nb_node_per_cell);
93   _gs_coo.resize(_dim*_nb_gauss_pt);
94   _w.resize(_nb_gauss_pt);
95   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
96 }
97
98 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
99                                  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),
100                                      _w(w)
101 {
102   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
103   _dim=cm.getDimension();
104   _nb_node_per_cell=cm.getNumberOfNodes();
105   _nb_gauss_pt=_w.size();
106 }
107
108 MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const
109 {
110   return new MEDFileFieldLoc(*this);
111 }
112
113 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
114 {
115   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
116 }
117
118 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
119 {
120   return std::vector<const BigMemoryObject *>();
121 }
122
123 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
124 {
125   static const char OFF7[]="\n    ";
126   oss << "\"" << _name << "\"" << OFF7;
127   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
128   oss << "Dimension=" << _dim << OFF7;
129   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
130   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
131   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
132   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
133   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
134 }
135
136 void MEDFileFieldLoc::setName(const std::string& name)
137 {
138   _name=name;
139 }
140
141 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
142 {
143   if(_name!=other._name)
144     return false;
145   if(_dim!=other._dim)
146     return false;
147   if(_nb_gauss_pt!=other._nb_gauss_pt)
148     return false;
149   if(_nb_node_per_cell!=other._nb_node_per_cell)
150     return false;
151   if(_geo_type!=other._geo_type)
152     return false;
153   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
154     return false;
155   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
156     return false;
157   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
158     return false;
159
160   return true;
161 }
162
163 void MEDFileFieldLoc::writeLL(med_idt fid) const
164 {
165   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);
166 }
167
168 std::string MEDFileFieldLoc::repr() const
169 {
170   std::ostringstream oss; oss.precision(15);
171   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
172   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
173   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
174   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
175   oss << "\n  - Ref coords are : ";
176   int sz=_ref_coo.size();
177   if(sz%_dim==0)
178     {
179       int nbOfTuples=sz/_dim;
180       for(int i=0;i<nbOfTuples;i++)
181         {
182           oss << "(";
183           for(int j=0;j<_dim;j++)
184             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
185           oss << ") ";
186         }
187     }
188   else
189     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
190   oss << "\n  - Gauss coords in reference element : ";
191   sz=_gs_coo.size();
192   if(sz%_dim==0)
193     {
194       int nbOfTuples=sz/_dim;
195       for(int i=0;i<nbOfTuples;i++)
196         {
197           oss << "(";
198           for(int j=0;j<_dim;j++)
199             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
200           oss << ") ";
201         }
202     }
203   else
204     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
205   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
206   return oss.str();
207 }
208
209 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
210 {
211   _type=field->getTypeOfField();
212   _start=start;
213   switch(_type)
214   {
215     case ON_CELLS:
216       {
217         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,offset,offset+nbOfCells,1);
218         _end=_start+nbOfCells;
219         _nval=nbOfCells;
220         break;
221       }
222     case ON_GAUSS_NE:
223       {
224         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
225         const int *arrPtr=arr->getConstPointer();
226         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
227         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
228         _nval=nbOfCells;
229         break;
230       }
231     case ON_GAUSS_PT:
232       {
233         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
234         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
235         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
236         if(!disc2)
237           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
238         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
239         MCAuto<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
240         const int *dai2Ptr=dai2->getConstPointer();
241         int nbi=gsLoc.getWeights().size();
242         MCAuto<DataArrayInt> da2=dai->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
243         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
244         const int *da3Ptr=da3->getConstPointer();
245         if(da3->getNumberOfTuples()!=nbOfCells)
246           {//profile : for gauss even in NoProfile !!!
247             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
248             _profile=oss.str();
249             da3->setName(_profile.c_str());
250             glob.appendProfile(da3);
251           }
252         MCAuto<DataArrayInt> da4=DataArrayInt::New();
253         _nval=da3->getNbOfElems();
254         da4->alloc(_nval*nbi,1);
255         int *da4Ptr=da4->getPointer();
256         for(int i=0;i<_nval;i++)
257           {
258             int ref=dai2Ptr[offset+da3Ptr[i]];
259             for(int j=0;j<nbi;j++)
260               *da4Ptr++=ref+j;
261           }
262         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
263         _localization=oss2.str();
264         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
265         _end=_start+_nval*nbi;
266         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
267         break;
268       }
269     default:
270       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
271   }
272   start=_end;
273 }
274
275 /*!
276  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
277  * \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).
278  * \param [in] multiTypePfl is the end user profile specified in high level API
279  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
280  * \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.
281  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
282  * \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.
283  */
284 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)
285 {
286   _profile.clear();
287   _type=field->getTypeOfField();
288   std::string pflName(multiTypePfl->getName());
289   std::ostringstream oss; oss << pflName;
290   if(_type!=ON_NODES)
291     {
292       if(!isPflAlone)
293         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
294     }
295   else
296     { oss << "_NODE"; }
297   if(locIds)
298     {
299       if(pflName.empty())
300         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
301       if(_type!=ON_GAUSS_PT)
302         {
303           locIds->setName(oss.str().c_str());
304           glob.appendProfile(locIds);
305           _profile=oss.str();
306         }
307     }
308   _start=start;
309   switch(_type)
310   {
311     case ON_NODES:
312       {
313         _nval=idsInPfl->getNumberOfTuples();
314         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,arrr->getNumberOfTuples(),1);
315         _end=_start+_nval;
316         break;
317       }
318     case ON_CELLS:
319       {
320         _nval=idsInPfl->getNumberOfTuples();
321         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
322         _end=_start+_nval;
323         break;
324       }
325     case ON_GAUSS_NE:
326       {
327         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
328         MCAuto<DataArrayInt> arr2=arr->deltaShiftIndex();
329         MCAuto<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
330         arr3->computeOffsetsFull();
331         MCAuto<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
332         int trueNval=tmp->getNumberOfTuples();
333         _nval=idsInPfl->getNumberOfTuples();
334         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
335         _end=_start+trueNval;
336         break;
337       }
338     case ON_GAUSS_PT:
339       {
340         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
341         if(!disc2)
342           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
343         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
344         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
345         MCAuto<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
346         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
347         MCAuto<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
348         //
349         MCAuto<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
350         MCAuto<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
351         //
352         MCAuto<DataArrayInt> tmp=DataArrayInt::New();
353         int trueNval=0;
354         for(const int *pt=da4->begin();pt!=da4->end();pt++)
355           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
356         tmp->alloc(trueNval,1);
357         int *tmpPtr=tmp->getPointer();
358         for(const int *pt=da4->begin();pt!=da4->end();pt++)
359           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
360             *tmpPtr++=j;
361         //
362         _nval=da4->getNumberOfTuples();
363         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
364         _end=_start+trueNval;
365         oss << "_loc_" << _loc_id;
366         if(locIds)
367           {
368             MCAuto<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
369             da5->setName(oss.str().c_str());
370             glob.appendProfile(da5);
371             _profile=oss.str();
372           }
373         else
374           {
375             if(!da3->isIota(nbOfEltsInWholeMesh))
376               {
377                 da3->setName(oss.str().c_str());
378                 glob.appendProfile(da3);
379                 _profile=oss.str();
380               }
381           }
382         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
383         _localization=oss2.str();
384         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
385         break;
386       }
387     default:
388       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
389   }
390   start=_end;
391 }
392
393 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
394 {
395   _start=start;
396   _nval=arrr->getNumberOfTuples();
397   getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,_nval,1);
398   _end=_start+_nval;
399   start=_end;
400 }
401
402 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
403 {
404   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
405 }
406
407 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
408 {
409   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
410 }
411
412 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
413 {
414   return new MEDFileFieldPerMeshPerTypePerDisc(other);
415 }
416
417 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
418 {
419   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
420 }
421
422 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
423 {
424   std::vector<const BigMemoryObject *> ret(1);
425   ret[0]=(const PartDefinition*)_pd;
426   return ret;
427 }
428
429 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerType *father) const
430 {
431   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
432   ret->_father=father;
433   return ret.retn();
434 }
435
436 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
437 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
438 {
439   if(pd)
440     pd->incrRef();
441 }
442 catch(INTERP_KERNEL::Exception& e)
443 {
444     throw e;
445 }
446
447 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
448 {
449 }
450
451 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)
452 {
453 }
454
455 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
456     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
457 {
458 }
459
460 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)
461 {
462   const PartDefinition *pd(_pd);
463   if(!pd)
464     {
465       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
466       int nbi,tmp1;
467       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
468       if(_end-_start!=nbValsInFile*nbi)
469         {
470           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 !";
471           throw INTERP_KERNEL::Exception(oss.str().c_str());
472         }
473       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
474     }
475   else
476     {
477       if(!_profile.empty())
478         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
479       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
480       int profilesize,nbi;
481       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
482       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
483       if(spd)
484         {
485           int start,stop,step;
486           spd->getSlice(start,stop,step);
487           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
488           med_filter filter=MED_FILTER_INIT;
489           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
490                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
491                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
492                                    /*lastblocksize=useless because count=1*/0,&filter);
493           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
494           MEDfilterClose(&filter);
495           return ;
496         }
497       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
498       if(dpd)
499         {
500           dpd->checkConsistencyLight();
501           MCAuto<DataArrayInt> myIds(dpd->toDAI());
502           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
503           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
504           myIds->applyLin(1,-a);
505           int nbOfEltsToLoad(b-a+1);
506           med_filter filter=MED_FILTER_INIT;
507           {//TODO : manage int32 !
508             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
509             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
510             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
511                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
512                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
513                                      /*lastblocksize=useless because count=1*/0,&filter);
514             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
515             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
516             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
517             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
518           }
519           MEDfilterClose(&filter);
520         }
521       else
522         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
523     }
524 }
525
526 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
527 {
528   return _father;
529 }
530
531 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
532 {
533   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
534   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
535   std::string fieldName(nasc.getName()),meshName(getMeshName());
536   int iteration(getIteration()),order(getOrder());
537   TypeOfField type(getType());
538   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
539   int profilesize,nbi;
540   med_geometry_type mgeoti;
541   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
542   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
543   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
544   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
545   const PartDefinition *pd(_pd);
546   if(!pd)
547     {
548       _nval=zeNVal;
549     }
550   else
551     {
552       if(!_profile.empty())
553         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
554       _nval=pd->getNumberOfElems();
555     }
556   _start=start;
557   _end=start+_nval*nbi;
558   start=_end;
559   if(type==ON_CELLS && !_localization.empty())
560     {
561       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
562         setType(ON_GAUSS_PT);
563       else
564         {
565           setType(ON_GAUSS_NE);
566           _localization.clear();
567         }
568     }
569 }
570
571 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
572 {
573   std::string fieldName(nasc.getName()),meshName(getMeshName());
574   int iteration(getIteration()),order(getOrder());
575   TypeOfField type(getType());
576   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
577   med_geometry_type mgeoti;
578   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
579   if(_start>_end)
580     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
581   if(_start==_end)
582     return ;
583   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
584   if(_start<0 || _start>=arr->getNumberOfTuples())
585     {
586       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
587       throw INTERP_KERNEL::Exception(oss.str().c_str());
588     }
589   if(_end<0 || _end>arr->getNumberOfTuples())
590     {
591       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
592       throw INTERP_KERNEL::Exception(oss.str().c_str());
593     }
594   int nbOfCompo(arr->getNumberOfComponents());
595   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
596   if(arrD)
597     {
598       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
599       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
600       return ;
601     }
602   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
603   if(arrI)
604     {
605       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
606       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
607       return ;
608     }
609   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
610 }
611
612 /*!
613  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
614  */
615 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
616 {
617   int delta=_end-_start;
618   _start=newValueOfStart;
619   _end=_start+delta;
620 }
621
622 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
623 {
624   return _father->getIteration();
625 }
626
627 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
628 {
629   return _father->getOrder();
630 }
631
632 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
633 {
634   return _father->getTime();
635 }
636
637 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
638 {
639   return _father->getMeshName();
640 }
641
642 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
643 {
644   const char startLine[]="    ## ";
645   std::string startLine2(bkOffset,' ');
646   startLine2+=startLine;
647   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
648   oss << startLine2 << "Localization #" << id << "." << std::endl;
649   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
650   delete tmp;
651   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
652   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
653   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
654 }
655
656 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
657 {
658   return _type;
659 }
660
661 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
662 {
663   types.insert(_type);
664 }
665
666 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
667 {
668   _type=newType;
669 }
670
671 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
672 {
673   return _father->getGeoType();
674 }
675
676 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
677 {
678   return _father->getNumberOfComponents();
679 }
680
681 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
682 {
683   return _end-_start;
684 }
685
686 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
687 {
688   return _father->getOrCreateAndGetArray();
689 }
690
691 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
692 {
693   const MEDFileFieldPerMeshPerType *fath=_father;
694   return fath->getOrCreateAndGetArray();
695 }
696
697 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
698 {
699   return _father->getInfo();
700 }
701
702 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
703 {
704   return _profile;
705 }
706
707 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
708 {
709   _profile=newPflName;
710 }
711
712 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
713 {
714   return _localization;
715 }
716
717 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
718 {
719   _localization=newLocName;
720 }
721
722 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
723 {
724   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
725     {
726       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
727         {
728           _profile=(*it2).second;
729           return;
730         }
731     }
732 }
733
734 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
735 {
736   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
737     {
738       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
739         {
740           _localization=(*it2).second;
741           return;
742         }
743     }
744 }
745
746 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
747 {
748   if(type!=_type)
749     return ;
750   dads.push_back(std::pair<int,int>(_start,_end));
751   geoTypes.push_back(getGeoType());
752   if(_profile.empty())
753     pfls.push_back(0);
754   else
755     {
756       pfls.push_back(glob->getProfile(_profile.c_str()));
757     }
758   if(_localization.empty())
759     locs.push_back(-1);
760   else
761     {
762       locs.push_back(glob->getLocalizationId(_localization.c_str()));
763     }
764 }
765
766 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
767 {
768   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));
769   startEntryId++;
770 }
771
772 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
773 {
774   TypeOfField type=getType();
775   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
776   med_geometry_type mgeoti;
777   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
778   const DataArray *arr=getOrCreateAndGetArray();
779   if(!arr)
780     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
781   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
782   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
783   const unsigned char *locToWrite=0;
784   if(arrD)
785     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
786   else if(arrI)
787     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
788   else
789     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
790   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
791                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
792                                                    locToWrite));
793 }
794
795 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
796 {
797   type=_type;
798   pfl=_profile;
799   loc=_localization;
800   dad.first=_start; dad.second=_end;
801 }
802
803 /*!
804  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
805  *             This code corresponds to the distribution of types in the corresponding mesh.
806  * \param [out] ptToFill memory zone where the output will be stored.
807  * \return the size of data pushed into output param \a ptToFill
808  */
809 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
810 {
811   _loc_id=offset;
812   std::ostringstream oss;
813   std::size_t nbOfType=codeOfMesh.size()/3;
814   int found=-1;
815   for(std::size_t i=0;i<nbOfType && found==-1;i++)
816     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
817       found=(int)i;
818   if(found==-1)
819     {
820       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
821       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
822       throw INTERP_KERNEL::Exception(oss.str().c_str());
823     }
824   int *work=ptToFill;
825   if(_profile.empty())
826     {
827       if(_nval!=codeOfMesh[3*found+1])
828         {
829           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
830           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
831           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
832           throw INTERP_KERNEL::Exception(oss.str().c_str());
833         }
834       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
835         *work++=ii;
836     }
837   else
838     {
839       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
840       if(pfl->getNumberOfTuples()!=_nval)
841         {
842           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
843           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
844           oss << _nval;
845           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
846           throw INTERP_KERNEL::Exception(oss.str().c_str());
847         }
848       int offset2=codeOfMesh[3*found+2];
849       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
850         {
851           if(*pflId<codeOfMesh[3*found+1])
852             *work++=offset2+*pflId;
853         }
854     }
855   return _nval;
856 }
857
858 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
859 {
860   for(int i=_start;i<_end;i++)
861     *ptToFill++=i;
862   return _end-_start;
863 }
864
865 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
866 {
867   switch(type)
868   {
869     case ON_CELLS:
870       return -2;
871     case ON_GAUSS_NE:
872       return -1;
873     case ON_GAUSS_PT:
874       return locId;
875     default:
876       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
877   }
878 }
879
880 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
881 {
882   int id=0;
883   std::map<std::pair<std::string,TypeOfField>,int> m;
884   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
885   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
886     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
887       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
888   ret.resize(id);
889   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
890     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
891   return ret;
892 }
893
894 /*!
895  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
896  * 
897  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
898  * \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.
899  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
900  * \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)
901  * \param [in,out] glob if necessary by the method, new profiles can be added to it
902  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
903  * \param [out] result All new entries will be appended on it.
904  * \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 !)
905  */
906 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
907                                                        const DataArrayInt *explicitIdsInMesh,
908                                                        const std::vector<int>& newCode,
909                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
910                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
911 {
912   if(entriesOnSameDisc.empty())
913     return false;
914   TypeOfField type=entriesOnSameDisc[0]->getType();
915   int szEntities=0,szTuples=0;
916   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
917     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
918   int nbi=szTuples/szEntities;
919   if(szTuples%szEntities!=0)
920     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
921   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
922   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
923   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
924   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
925   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
926   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
927   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
928   int id=0;
929   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
930     {
931       int startOfEltIdOfChunk=(*it)->_start;
932       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
933       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
934       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
935       //
936       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
937       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
938       //
939       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
940       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
941     }
942   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
943   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
944   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
945   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
946   //
947   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
948   //
949   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
950   arrPart->renumberInPlace(renumTupleIds->begin());
951   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
952   bool ret=false;
953   const int *idIt=diffVals->begin();
954   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
955   int offset2=0;
956   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
957     {
958       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
959       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
960       int nbEntityElts=subIds->getNumberOfTuples();
961       bool ret2;
962       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
963           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
964                                       offset+offset2,
965                                       li,glob,ret2);
966       ret=ret || ret2;
967       result.push_back(eltToAdd);
968       offset2+=nbEntityElts*nbi;
969     }
970   ret=ret || li.empty();
971   return ret;
972 }
973
974 /*!
975  * \param [in] typeF type of field of new chunk
976  * \param [in] geoType the geometric type of the chunk
977  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
978  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
979  * \param [in] nbi number of integration points
980  * \param [in] offset The offset in the **global array of data**.
981  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
982  *                 to the new chunk to create.
983  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
984  * \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
985  *              and corresponding entry erased from \a entriesOnSameDisc.
986  * \return a newly allocated chunk
987  */
988 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
989                                                                                                   bool isPfl, int nbi, int offset,
990                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
991                                                                                                   MEDFileFieldGlobsReal& glob,
992                                                                                                   bool &notInExisting)
993 {
994   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
995   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
996   for(;it!=entriesOnSameDisc.end();it++)
997     {
998       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
999         {
1000           if(!isPfl)
1001             {
1002               if((*it)->_profile.empty())
1003                 break;
1004               else
1005                 if(!(*it)->_profile.empty())
1006                   {
1007                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1008                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1009                       break;
1010                   }
1011             }
1012         }
1013     }
1014   if(it==entriesOnSameDisc.end())
1015     {
1016       notInExisting=true;
1017       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1018       ret->_type=typeF;
1019       ret->_loc_id=(int)geoType;
1020       ret->_nval=nbMeshEntities;
1021       ret->_start=offset;
1022       ret->_end=ret->_start+ret->_nval*nbi;
1023       if(isPfl)
1024         {
1025           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1026           glob.appendProfile(idsOfMeshElt);
1027           ret->_profile=idsOfMeshElt->getName();
1028         }
1029       //tony treatment of localization
1030       return ret;
1031     }
1032   else
1033     {
1034       notInExisting=false;
1035       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1036       ret->_loc_id=(int)geoType;
1037       ret->setNewStart(offset);
1038       entriesOnSameDisc.erase(it);
1039       return ret;
1040     }
1041
1042 }
1043
1044 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1045 {
1046   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1047 }
1048
1049 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1050 {
1051   return new MEDFileFieldPerMeshPerType(fath,geoType);
1052 }
1053
1054 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
1055 {
1056   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1057 }
1058
1059 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
1060 {
1061   std::vector<const BigMemoryObject *> ret;
1062   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1063     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1064   return ret;
1065 }
1066
1067 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1068 {
1069   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1070   ret->_father=father;
1071   std::size_t i=0;
1072   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1073     {
1074       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1075         ret->_field_pm_pt_pd[i]=(*it)->deepCopy((MEDFileFieldPerMeshPerType *)ret);
1076     }
1077   return ret.retn();
1078 }
1079
1080 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1081 {
1082   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1083   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1084     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1085 }
1086
1087 /*!
1088  * This method is the most general one. No optimization is done here.
1089  * \param [in] multiTypePfl is the end user profile specified in high level API
1090  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1091  * \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.
1092  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1093  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1094  * \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.
1095  */
1096 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)
1097 {
1098   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1099   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1100     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1101 }
1102
1103 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1104 {
1105   _field_pm_pt_pd.resize(1);
1106   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1107   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1108 }
1109
1110 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1111 {
1112   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1113   if(!arr || !arr->isAllocated())
1114     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1115   _field_pm_pt_pd.resize(1);
1116   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1117   _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.
1118 }
1119
1120 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1121 {
1122   TypeOfField type=field->getTypeOfField();
1123   if(type!=ON_GAUSS_PT)
1124     {
1125       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1126       int sz=_field_pm_pt_pd.size();
1127       bool found=false;
1128       for(int j=0;j<sz && !found;j++)
1129         {
1130           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1131             {
1132               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1133               found=true;
1134             }
1135         }
1136       if(!found)
1137         {
1138           _field_pm_pt_pd.resize(sz+1);
1139           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1140         }
1141       std::vector<int> ret(1,(int)sz);
1142       return ret;
1143     }
1144   else
1145     {
1146       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1147       int sz2=ret2.size();
1148       std::vector<int> ret3(sz2);
1149       int k=0;
1150       for(int i=0;i<sz2;i++)
1151         {
1152           int sz=_field_pm_pt_pd.size();
1153           int locIdToFind=ret2[i];
1154           bool found=false;
1155           for(int j=0;j<sz && !found;j++)
1156             {
1157               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1158                 {
1159                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1160                   ret3[k++]=j;
1161                   found=true;
1162                 }
1163             }
1164           if(!found)
1165             {
1166               _field_pm_pt_pd.resize(sz+1);
1167               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1168               ret3[k++]=sz;
1169             }
1170         }
1171       return ret3;
1172     }
1173 }
1174
1175 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1176 {
1177   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1178   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1179   if(!disc2)
1180     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1181   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1182   if(!da)
1183     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1184   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1185   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1186   if(retTmp->presenceOfValue(-1))
1187     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1188   std::vector<int> ret(retTmp->begin(),retTmp->end());
1189   return ret;
1190 }
1191
1192 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1193 {
1194   TypeOfField type=field->getTypeOfField();
1195   if(type!=ON_GAUSS_PT)
1196     {
1197       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1198       int sz=_field_pm_pt_pd.size();
1199       bool found=false;
1200       for(int j=0;j<sz && !found;j++)
1201         {
1202           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1203             {
1204               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1205               found=true;
1206             }
1207         }
1208       if(!found)
1209         {
1210           _field_pm_pt_pd.resize(sz+1);
1211           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1212         }
1213       std::vector<int> ret(1,0);
1214       return ret;
1215     }
1216   else
1217     {
1218       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1219       int sz2=ret2.size();
1220       std::vector<int> ret3(sz2);
1221       int k=0;
1222       for(int i=0;i<sz2;i++)
1223         {
1224           int sz=_field_pm_pt_pd.size();
1225           int locIdToFind=ret2[i];
1226           bool found=false;
1227           for(int j=0;j<sz && !found;j++)
1228             {
1229               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1230                 {
1231                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1232                   ret3[k++]=j;
1233                   found=true;
1234                 }
1235             }
1236           if(!found)
1237             {
1238               _field_pm_pt_pd.resize(sz+1);
1239               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1240               ret3[k++]=sz;
1241             }
1242         }
1243       return ret3;
1244     }
1245 }
1246
1247 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1248 {
1249   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1250   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1251   if(!disc2)
1252     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1253   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1254   if(!da)
1255     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1256   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1257   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1258   if(retTmp->presenceOfValue(-1))
1259     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1260   std::vector<int> ret(retTmp->begin(),retTmp->end());
1261   return ret;
1262 }
1263
1264 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1265 {
1266   return _father;
1267 }
1268
1269 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1270 {
1271   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1272   int curDim=(int)cm.getDimension();
1273   dim=std::max(dim,curDim);
1274 }
1275
1276 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1277 {
1278   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1279     {
1280       (*it)->fillTypesOfFieldAvailable(types);
1281     }
1282 }
1283
1284 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
1285 {
1286   int sz=_field_pm_pt_pd.size();
1287   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1288   for(int i=0;i<sz;i++)
1289     {
1290       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1291     }
1292 }
1293
1294 int MEDFileFieldPerMeshPerType::getIteration() const
1295 {
1296   return _father->getIteration();
1297 }
1298
1299 int MEDFileFieldPerMeshPerType::getOrder() const
1300 {
1301   return _father->getOrder();
1302 }
1303
1304 double MEDFileFieldPerMeshPerType::getTime() const
1305 {
1306   return _father->getTime();
1307 }
1308
1309 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1310 {
1311   return _father->getMeshName();
1312 }
1313
1314 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1315 {
1316   const char startLine[]="  ## ";
1317   std::string startLine2(bkOffset,' ');
1318   std::string startLine3(startLine2);
1319   startLine3+=startLine;
1320   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1321     {
1322       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1323       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1324     }
1325   else
1326     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1327   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1328   int i=0;
1329   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1330     {
1331       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1332       if(cur)
1333         cur->simpleRepr(bkOffset,oss,i);
1334       else
1335         {
1336           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1337         }
1338     }
1339 }
1340
1341 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1342 {
1343   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1344     {
1345       globalSz+=(*it)->getNumberOfTuples();
1346     }
1347   nbOfEntries+=(int)_field_pm_pt_pd.size();
1348 }
1349
1350 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1351 {
1352   return _geo_type;
1353 }
1354
1355
1356 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1357 {
1358   return _father->getNumberOfComponents();
1359 }
1360
1361 bool MEDFileFieldPerMeshPerType::presenceOfMultiDiscPerGeoType() const
1362 {
1363   std::size_t nb(0);
1364   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1365     {
1366       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1367       if(fmtd)
1368         nb++;
1369     }
1370   return nb>1;
1371 }
1372
1373 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1374 {
1375   return _father->getOrCreateAndGetArray();
1376 }
1377
1378 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1379 {
1380   const MEDFileFieldPerMesh *fath=_father;
1381   return fath->getOrCreateAndGetArray();
1382 }
1383
1384 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1385 {
1386   return _father->getInfo();
1387 }
1388
1389 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1390 {
1391   std::vector<std::string> ret;
1392   std::set<std::string> ret2;
1393   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1394     {
1395       std::string tmp=(*it1)->getProfile();
1396       if(!tmp.empty())
1397         if(ret2.find(tmp)==ret2.end())
1398           {
1399             ret.push_back(tmp);
1400             ret2.insert(tmp);
1401           }
1402     }
1403   return ret;
1404 }
1405
1406 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1407 {
1408   std::vector<std::string> ret;
1409   std::set<std::string> ret2;
1410   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1411     {
1412       std::string tmp=(*it1)->getLocalization();
1413       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1414         if(ret2.find(tmp)==ret2.end())
1415           {
1416             ret.push_back(tmp);
1417             ret2.insert(tmp);
1418           }
1419     }
1420   return ret;
1421 }
1422
1423 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1424 {
1425   std::vector<std::string> ret;
1426   std::set<std::string> ret2;
1427   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1428     {
1429       std::string tmp=(*it1)->getProfile();
1430       if(!tmp.empty())
1431         ret.push_back(tmp);
1432     }
1433   return ret;
1434 }
1435
1436 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1437 {
1438   std::vector<std::string> ret;
1439   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1440     {
1441       std::string tmp=(*it1)->getLocalization();
1442       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1443         ret.push_back(tmp);
1444     }
1445   return ret;
1446 }
1447
1448 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1449 {
1450   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1451     (*it1)->changePflsRefsNamesGen(mapOfModif);
1452 }
1453
1454 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1455 {
1456   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1457     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1458 }
1459
1460 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1461 {
1462   if(_field_pm_pt_pd.empty())
1463     {
1464       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1465       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1466       throw INTERP_KERNEL::Exception(oss.str().c_str());
1467     }
1468   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1469     return _field_pm_pt_pd[locId];
1470   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1471   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1472   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1473   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1474   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1475 }
1476
1477 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1478 {
1479   if(_field_pm_pt_pd.empty())
1480     {
1481       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1482       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1483       throw INTERP_KERNEL::Exception(oss.str().c_str());
1484     }
1485   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1486     return _field_pm_pt_pd[locId];
1487   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1488   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1489   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1490   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1491   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1492 }
1493
1494 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
1495 {
1496   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1497     {
1498       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1499       if(meshDim!=(int)cm.getDimension())
1500         return ;
1501     }
1502   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1503     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1504 }
1505
1506 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1507 {
1508   int i=0;
1509   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1510     {
1511       (*it)->fillValues(i,startEntryId,entries);
1512     }
1513 }
1514
1515 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1516 {
1517   _field_pm_pt_pd=leaves;
1518   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1519     (*it)->setFather(this);
1520 }
1521
1522 /*!
1523  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1524  *  \param [out] its - list of pair (start,stop) kept
1525  *  \return bool - false if the type of field \a tof is not contained in \a this.
1526  */
1527 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1528 {
1529   bool ret(false);
1530   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1531   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1532     if((*it)->getType()==tof)
1533       {
1534         newPmPtPd.push_back(*it);
1535         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1536         (*it)->setNewStart(globalNum);
1537         globalNum=(*it)->getEnd();
1538         its.push_back(bgEnd);
1539         ret=true;
1540       }
1541   if(ret)
1542     _field_pm_pt_pd=newPmPtPd;
1543   return ret;
1544 }
1545
1546 /*!
1547  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1548  *  \param [out] its - list of pair (start,stop) kept
1549  *  \return bool - false if the type of field \a tof is not contained in \a this.
1550  */
1551 bool MEDFileFieldPerMeshPerType::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1552 {
1553   if(_field_pm_pt_pd.size()<=idOfDisc)
1554     return false;
1555   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1556   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1557   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1558   elt->setNewStart(globalNum);
1559   globalNum=elt->getEnd();
1560   its.push_back(bgEnd);
1561   _field_pm_pt_pd=newPmPtPd;
1562   return true;
1563 }
1564
1565 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1566 {
1567 }
1568
1569 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType)
1570 {
1571   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1572   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1573   med_geometry_type mgeoti;
1574   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1575   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1576   _field_pm_pt_pd.resize(nbProfiles);
1577   for(int i=0;i<nbProfiles;i++)
1578     {
1579       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1580     }
1581   if(type==ON_CELLS)
1582     {
1583       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1584       for(int i=0;i<nbProfiles2;i++)
1585         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1586     }
1587 }
1588
1589 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1590 {
1591   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1592     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1593 }
1594
1595 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1596 {
1597   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1598     (*it)->loadBigArray(fid,nasc);
1599 }
1600
1601 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1602 {
1603   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1604     {
1605       (*it)->copyOptionsFrom(*this);
1606       (*it)->writeLL(fid,nasc);
1607     }
1608 }
1609
1610 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1611 {
1612   switch(ikType)
1613   {
1614     case ON_CELLS:
1615       medfGeoType=typmai3[(int)ikGeoType];
1616       return MED_CELL;
1617     case ON_NODES:
1618       medfGeoType=MED_NONE;
1619       return MED_NODE;
1620     case ON_GAUSS_NE:
1621       medfGeoType=typmai3[(int)ikGeoType];
1622       return MED_NODE_ELEMENT;
1623     case ON_GAUSS_PT:
1624       medfGeoType=typmai3[(int)ikGeoType];
1625       return MED_CELL;
1626     default:
1627       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1628   }
1629   return MED_UNDEF_ENTITY_TYPE;
1630 }
1631
1632 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)
1633 {
1634   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1635 }
1636
1637 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1638 {
1639   return new MEDFileFieldPerMesh(fath,mesh);
1640 }
1641
1642 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1643 {
1644   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1645 }
1646
1647 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1648 {
1649   std::vector<const BigMemoryObject *> ret;
1650   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1651     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1652   return ret;
1653 }
1654
1655 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1656 {
1657   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1658   ret->_father=father;
1659   std::size_t i=0;
1660   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1661     {
1662       if((const MEDFileFieldPerMeshPerType *)*it)
1663         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1664     }
1665   return ret.retn();
1666 }
1667
1668 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1669 {
1670   std::string startLine(bkOffset,' ');
1671   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1672   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1673   int i=0;
1674   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1675     {
1676       const MEDFileFieldPerMeshPerType *cur=*it;
1677       if(cur)
1678         cur->simpleRepr(bkOffset,oss,i);
1679       else
1680         {
1681           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1682         }
1683     }
1684 }
1685
1686 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1687 {
1688   _mesh_name=mesh->getName();
1689   mesh->getTime(_mesh_iteration,_mesh_order);
1690 }
1691
1692 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1693 {
1694   int nbOfTypes=code.size()/3;
1695   int offset=0;
1696   for(int i=0;i<nbOfTypes;i++)
1697     {
1698       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1699       int nbOfCells=code[3*i+1];
1700       int pos=addNewEntryIfNecessary(type);
1701       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1702       offset+=nbOfCells;
1703     }
1704 }
1705
1706 /*!
1707  * This method is the most general one. No optimization is done here.
1708  * \param [in] multiTypePfl is the end user profile specified in high level API
1709  * \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].
1710  * \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.
1711  * \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.
1712  * \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.
1713  * \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.
1714  */
1715 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)
1716 {
1717   int nbOfTypes(code.size()/3);
1718   for(int i=0;i<nbOfTypes;i++)
1719     {
1720       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1721       int pos=addNewEntryIfNecessary(type);
1722       DataArrayInt *pfl=0;
1723       if(code[3*i+2]!=-1)
1724         pfl=idsPerType[code[3*i+2]];
1725       int nbOfTupes2=code2.size()/3;
1726       int found=0;
1727       for(;found<nbOfTupes2;found++)
1728         if(code[3*i]==code2[3*found])
1729           break;
1730       if(found==nbOfTupes2)
1731         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1732       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1733     }
1734 }
1735
1736 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1737 {
1738   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1739   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1740 }
1741
1742 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1743 {
1744   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1745   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1746 }
1747
1748 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1749 {
1750   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1751     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1752 }
1753
1754 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1755 {
1756   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1757     (*it)->loadBigArraysRecursively(fid,nasc);
1758 }
1759
1760 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1761 {
1762   int nbOfTypes=_field_pm_pt.size();
1763   for(int i=0;i<nbOfTypes;i++)
1764     {
1765       _field_pm_pt[i]->copyOptionsFrom(*this);
1766       _field_pm_pt[i]->writeLL(fid,nasc);
1767     }
1768 }
1769
1770 void MEDFileFieldPerMesh::getDimension(int& dim) const
1771 {
1772   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1773     (*it)->getDimension(dim);
1774 }
1775
1776 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1777 {
1778   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1779     (*it)->fillTypesOfFieldAvailable(types);
1780 }
1781
1782 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
1783 {
1784   int sz=_field_pm_pt.size();
1785   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1786   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1787   for(int i=0;i<sz;i++)
1788     {
1789       types[i]=_field_pm_pt[i]->getGeoType();
1790       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1791     }
1792   return ret;
1793 }
1794
1795 double MEDFileFieldPerMesh::getTime() const
1796 {
1797   int tmp1,tmp2;
1798   return _father->getTime(tmp1,tmp2);
1799 }
1800
1801 int MEDFileFieldPerMesh::getIteration() const
1802 {
1803   return _father->getIteration();
1804 }
1805
1806 int MEDFileFieldPerMesh::getOrder() const
1807 {
1808   return _father->getOrder();
1809 }
1810
1811 int MEDFileFieldPerMesh::getNumberOfComponents() const
1812 {
1813   return _father->getNumberOfComponents();
1814 }
1815
1816 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1817 {
1818   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1819     {
1820       const MEDFileFieldPerMeshPerType *fpmt(*it);
1821       if(!fpmt)
1822         continue;
1823       if(fpmt->presenceOfMultiDiscPerGeoType())
1824         return true;
1825     }
1826   return false;
1827 }
1828
1829 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1830 {
1831   if(!_father)
1832     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1833   return _father->getOrCreateAndGetArray();
1834 }
1835
1836 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1837 {
1838   if(!_father)
1839     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1840   return _father->getOrCreateAndGetArray();
1841 }
1842
1843 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1844 {
1845   return _father->getInfo();
1846 }
1847
1848 /*!
1849  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1850  * 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.
1851  * It returns 2 output vectors :
1852  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1853  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1854  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1855  */
1856 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)
1857 {
1858   int notNullPflsSz=0;
1859   int nbOfArrs=geoTypes.size();
1860   for(int i=0;i<nbOfArrs;i++)
1861     if(pfls[i])
1862       notNullPflsSz++;
1863   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1864   int nbOfDiffGeoTypes=geoTypes3.size();
1865   code.resize(3*nbOfDiffGeoTypes);
1866   notNullPfls.resize(notNullPflsSz);
1867   notNullPflsSz=0;
1868   int j=0;
1869   for(int i=0;i<nbOfDiffGeoTypes;i++)
1870     {
1871       int startZone=j;
1872       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1873       std::vector<const DataArrayInt *> notNullTmp;
1874       if(pfls[j])
1875         notNullTmp.push_back(pfls[j]);
1876       j++;
1877       for(;j<nbOfArrs;j++)
1878         if(geoTypes[j]==refType)
1879           {
1880             if(pfls[j])
1881               notNullTmp.push_back(pfls[j]);
1882           }
1883         else
1884           break;
1885       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1886       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1887       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1888       code[3*i]=(int)refType;
1889       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1890       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1891       if(notNullTmp.empty())
1892         code[3*i+2]=-1;
1893       else
1894         {
1895           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1896           code[3*i+2]=notNullPflsSz++;
1897         }
1898     }
1899 }
1900
1901 /*!
1902  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1903  */
1904 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)
1905 {
1906   int sz=dads.size();
1907   int ret=0;
1908   for(int i=0;i<sz;i++)
1909     {
1910       if(locs[i]==-1)
1911         {
1912           if(type!=ON_GAUSS_NE)
1913             ret+=dads[i].second-dads[i].first;
1914           else
1915             {
1916               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1917               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1918             }
1919         }
1920       else
1921         {
1922           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1923           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1924         }
1925     }
1926   return ret;
1927 }
1928
1929 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1930 {
1931   std::vector<std::string> ret;
1932   std::set<std::string> ret2;
1933   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1934     {
1935       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1936       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1937         if(ret2.find(*it2)==ret2.end())
1938           {
1939             ret.push_back(*it2);
1940             ret2.insert(*it2);
1941           }
1942     }
1943   return ret;
1944 }
1945
1946 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1947 {
1948   std::vector<std::string> ret;
1949   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1950     {
1951       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1952       ret.insert(ret.end(),tmp.begin(),tmp.end());
1953     }
1954   return ret;
1955 }
1956
1957 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1958 {
1959   std::vector<std::string> ret;
1960   std::set<std::string> ret2;
1961   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1962     {
1963       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1964       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1965         if(ret2.find(*it2)==ret2.end())
1966           {
1967             ret.push_back(*it2);
1968             ret2.insert(*it2);
1969           }
1970     }
1971   return ret;
1972 }
1973
1974 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1975 {
1976   std::vector<std::string> ret;
1977   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1978     {
1979       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1980       ret.insert(ret.end(),tmp.begin(),tmp.end());
1981     }
1982   return ret;
1983 }
1984
1985 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1986 {
1987   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1988     {
1989       if((*it).first==_mesh_name)
1990         {
1991           _mesh_name=(*it).second;
1992           return true;
1993         }
1994     }
1995   return false;
1996 }
1997
1998 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1999                                                       MEDFileFieldGlobsReal& glob)
2000 {
2001   if(_mesh_name!=meshName)
2002     return false;
2003   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2004   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2005   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2006   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2007   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2008   getUndergroundDataArrayExt(entries);
2009   DataArray *arr0=getOrCreateAndGetArray();//tony
2010   if(!arr0)
2011     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2012   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
2013   if(!arr0)
2014     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2015   int sz=0;
2016   if(!arr)
2017     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2018   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2019     {
2020       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2021         {
2022           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2023           sz+=(*it).second.second-(*it).second.first;
2024         }
2025       else
2026         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2027     }
2028   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2029   ////////////////////
2030   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2031   int *workI2=explicitIdsOldInMesh->getPointer();
2032   int sz1=0,sz2=0,sid=1;
2033   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2034   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2035   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2036     {
2037       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2038       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2039       int *workI=explicitIdsOldInArr->getPointer();
2040       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2041         {
2042           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2043           (*itL2)->setLocId(sz2);
2044           (*itL2)->_tmp_work1=(*itL2)->getStart();
2045           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2046         }
2047       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2048     }
2049   explicitIdsOldInMesh->reAlloc(sz2);
2050   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2051   ////////////////////
2052   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2053   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2054   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2055   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2056     {
2057       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2058       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2059       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2060     }
2061   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2062   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2063   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2064     {
2065       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2066       int newStart=elt->getLocId();
2067       elt->setLocId((*it)->getGeoType());
2068       elt->setNewStart(newStart);
2069       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2070       entriesKeptNew.push_back(elt);
2071       entriesKeptNew2.push_back(elt);
2072     }
2073   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2074   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2075   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2076   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2077   bool ret=false;
2078   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2079     {
2080       sid=0;
2081       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2082         {
2083           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2084           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2085           }*/
2086       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2087                                                             glob,arr2,otherEntriesNew) || ret;
2088     }
2089   if(!ret)
2090     return false;
2091   // Assign new dispatching
2092   assignNewLeaves(otherEntriesNew);
2093   arr->deepCopyFrom(*arr2);
2094   return true;
2095 }
2096
2097 /*!
2098  * \param [in,out] globalNum a global numbering counter for the renumbering.
2099  * \param [out] its - list of pair (start,stop) kept
2100  */
2101 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2102 {
2103   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret;
2104   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2105     {
2106       std::vector< std::pair<int,int> > its2;
2107       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2108         {
2109           ret.push_back(*it);
2110           its.insert(its.end(),its2.begin(),its2.end());
2111         }
2112     }
2113   _field_pm_pt=ret;
2114 }
2115
2116 /*!
2117  * \param [in,out] globalNum a global numbering counter for the renumbering.
2118  * \param [out] its - list of pair (start,stop) kept
2119  */
2120 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2121 {
2122   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret;
2123   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2124     {
2125       std::vector< std::pair<int,int> > its2;
2126       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2127         {
2128           ret.push_back(*it);
2129           its.insert(its.end(),its2.begin(),its2.end());
2130         }
2131     }
2132   _field_pm_pt=ret;
2133 }
2134
2135 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2136 {
2137   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2138   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2139     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2140   //
2141   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2142   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2143   std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2144   for(;it1!=types.end();it1++,it2++)
2145     {
2146       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2147       elt->setLeaves((*it1).second);
2148       *it2=elt;
2149     }
2150   _field_pm_pt=fieldPmPt;
2151 }
2152
2153 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2154 {
2155   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2156     (*it)->changePflsRefsNamesGen(mapOfModif);
2157 }
2158
2159 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2160 {
2161   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2162     (*it)->changeLocsRefsNamesGen(mapOfModif);
2163 }
2164
2165 /*!
2166  * \param [in] mesh is the whole mesh
2167  */
2168 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2169 {
2170   if(_field_pm_pt.empty())
2171     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2172   //
2173   std::vector< std::pair<int,int> > dads;
2174   std::vector<const DataArrayInt *> pfls;
2175   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2176   std::vector<int> locs,code;
2177   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2178   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2179     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2180   // Sort by types
2181   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2182   if(code.empty())
2183     {
2184       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2185       throw INTERP_KERNEL::Exception(oss.str().c_str());
2186     }
2187   //
2188   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2189   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2190   if(type!=ON_NODES)
2191     {
2192       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2193       if(!arr)
2194         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2195       else
2196         {
2197           MCAuto<DataArrayInt> arr2(arr);
2198           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2199         }
2200     }
2201   else
2202     {
2203       if(code.size()!=3)
2204         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2205       int nb=code[1];
2206       if(code[2]==-1)
2207         {
2208           if(nb!=mesh->getNumberOfNodes())
2209             {
2210               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2211               oss << " nodes in mesh !";
2212               throw INTERP_KERNEL::Exception(oss.str().c_str());
2213             }
2214           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2215         }
2216       else
2217         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2218     }
2219 }
2220
2221 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2222 {
2223   if(_field_pm_pt.empty())
2224     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2225   //
2226   std::vector<std::pair<int,int> > dads;
2227   std::vector<const DataArrayInt *> pfls;
2228   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2229   std::vector<int> locs,code;
2230   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2231   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2232     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2233   // Sort by types
2234   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2235   if(code.empty())
2236     {
2237       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2238       throw INTERP_KERNEL::Exception(oss.str().c_str());
2239     }
2240   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2241   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2242   if(type!=ON_NODES)
2243     {
2244       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2245       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2246     }
2247   else
2248     {
2249       if(code.size()!=3)
2250         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2251       int nb=code[1];
2252       if(code[2]==-1)
2253         {
2254           if(nb!=mesh->getNumberOfNodes())
2255             {
2256               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2257               oss << " nodes in mesh !";
2258               throw INTERP_KERNEL::Exception(oss.str().c_str());
2259             }
2260         }
2261       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2262     }
2263   //
2264   return 0;
2265 }
2266
2267 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2268 {
2269   int globalSz=0;
2270   int nbOfEntries=0;
2271   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2272     {
2273       (*it)->getSizes(globalSz,nbOfEntries);
2274     }
2275   entries.resize(nbOfEntries);
2276   nbOfEntries=0;
2277   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2278     {
2279       (*it)->fillValues(nbOfEntries,entries);
2280     }
2281 }
2282
2283 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2284 {
2285   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2286     {
2287       if((*it)->getGeoType()==typ)
2288         return (*it)->getLeafGivenLocId(locId);
2289     }
2290   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2291   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2292   oss << "Possiblities are : ";
2293   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2294     {
2295       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2296       oss << "\"" << cm2.getRepr() << "\", ";
2297     }
2298   throw INTERP_KERNEL::Exception(oss.str().c_str());
2299 }
2300
2301 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2302 {
2303   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2304     {
2305       if((*it)->getGeoType()==typ)
2306         return (*it)->getLeafGivenLocId(locId);
2307     }
2308   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2309   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2310   oss << "Possiblities are : ";
2311   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2312     {
2313       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2314       oss << "\"" << cm2.getRepr() << "\", ";
2315     }
2316   throw INTERP_KERNEL::Exception(oss.str().c_str());
2317 }
2318
2319 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2320 {
2321   int i=0;
2322   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2323   std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2324   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2325     {
2326       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2327       if(type==curType)
2328         return i;
2329       else
2330         {
2331           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2332           if(pos>pos2)
2333             it2=it+1;
2334         }
2335     }
2336   int ret=std::distance(_field_pm_pt.begin(),it2);
2337   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2338   return ret;
2339 }
2340
2341 /*!
2342  * 'dads' and 'locs' input parameters have the same number of elements
2343  * \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
2344  */
2345 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2346                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2347                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2348 {
2349   isPfl=false;
2350   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2351   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2352   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2353   const std::vector<std::string>& infos=getInfo();
2354   da->setInfoOnComponents(infos);
2355   da->setName("");
2356   if(type==ON_GAUSS_PT)
2357     {
2358       int offset=0;
2359       int nbOfArrs=dads.size();
2360       for(int i=0;i<nbOfArrs;i++)
2361         {
2362           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2363           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2364           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2365           MCAuto<DataArrayInt> di=DataArrayInt::New();
2366           di->alloc(nbOfElems,1);
2367           di->iota(offset);
2368           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2369           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2370           offset+=nbOfElems;
2371         }
2372     }
2373   arrOut=da;
2374   return ret.retn();
2375 }
2376
2377 /*!
2378  * 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.
2379  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2380  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2381  * The order of cells in the returned field is those imposed by the profile.
2382  * \param [in] mesh is the global mesh.
2383  */
2384 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2385                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2386                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2387                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2388 {
2389   if(da->isIota(mesh->getNumberOfCells()))
2390     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2391   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2392   m2->setName(mesh->getName().c_str());
2393   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2394   isPfl=true;
2395   return ret.retn();
2396 }
2397
2398 /*!
2399  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2400  */
2401 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2402                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2403                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2404 {
2405   if(da->isIota(mesh->getNumberOfNodes()))
2406     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2407   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2408   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2409   if(meshu)
2410     {
2411       if(meshu->getNodalConnectivity()==0)
2412         {
2413           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2414           int nb=da->getNbOfElems();
2415           const int *ptr=da->getConstPointer();
2416           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2417           meshuc->allocateCells(nb);
2418           for(int i=0;i<nb;i++)
2419             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2420           meshuc->finishInsertingCells();
2421           ret->setMesh(meshuc);
2422           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2423           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2424           disc->checkCoherencyBetween(meshuc,arrOut);
2425           return ret.retn();
2426         }
2427     }
2428   //
2429   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2430   isPfl=true;
2431   DataArrayInt *arr2=0;
2432   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2433   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2434   MCAuto<DataArrayInt> arr3(arr2);
2435   int nnodes=mesh2->getNumberOfNodes();
2436   if(nnodes==(int)da->getNbOfElems())
2437     {
2438       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2439       arrOut->renumberInPlace(da3->getConstPointer());
2440       mesh2->setName(mesh->getName().c_str());
2441       ret->setMesh(mesh2);
2442       return ret.retn();
2443     }
2444   else
2445     {
2446       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 !!!";
2447       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2448       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2449       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2450       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2451       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2452       throw INTERP_KERNEL::Exception(oss.str().c_str());
2453     }
2454   return 0;
2455 }
2456
2457 /*!
2458  * This method is the most light method of field retrieving.
2459  */
2460 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2461 {
2462   if(!pflIn)
2463     {
2464       pflOut=DataArrayInt::New();
2465       pflOut->alloc(nbOfElems,1);
2466       pflOut->iota(0);
2467     }
2468   else
2469     {
2470       pflOut=const_cast<DataArrayInt*>(pflIn);
2471       pflOut->incrRef();
2472     }
2473   MCAuto<DataArrayInt> safePfl(pflOut);
2474   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2475   const std::vector<std::string>& infos=getInfo();
2476   int nbOfComp=infos.size();
2477   for(int i=0;i<nbOfComp;i++)
2478     da->setInfoOnComponent(i,infos[i].c_str());
2479   safePfl->incrRef();
2480   return da.retn();
2481 }
2482
2483
2484 /// @cond INTERNAL
2485
2486 class MFFPMIter
2487 {
2488 public:
2489   static MFFPMIter *NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2490   static bool IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2491   virtual ~MFFPMIter() { }
2492   virtual void begin() = 0;
2493   virtual bool finished() const = 0;
2494   virtual void next() = 0;
2495   virtual int current() const = 0;
2496 };
2497
2498 class MFFPMIterSimple : public MFFPMIter
2499 {
2500 public:
2501   MFFPMIterSimple():_pos(0) { }
2502   void begin() { _pos=0; }
2503   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2504   void next() { _pos++; }
2505   int current() const { return _pos; }
2506 private:
2507   int _pos;
2508 };
2509
2510 class MFFPMIter2 : public MFFPMIter
2511 {
2512 public:
2513   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2514   void begin() { _it=_ids.begin(); }
2515   bool finished() const { return _it==_ids.end(); }
2516   void next() { _it++; }
2517   int current() const { return *_it; }
2518 private:
2519   std::vector<int> _ids;
2520   std::vector<int>::const_iterator _it;
2521 };
2522
2523 MFFPMIter *MFFPMIter::NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2524 {
2525   if(!entities)
2526     return new MFFPMIterSimple;
2527   else
2528     {
2529       std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2530       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2531         {
2532           if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2533             tmp.push_back((*it).second);
2534         }
2535       return new MFFPMIter2(tmp);
2536     }
2537 }
2538
2539 bool MFFPMIter::IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2540 {
2541   if(!entities)
2542     return true;
2543   else
2544     {
2545       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2546         if((*it).first==ON_NODES)
2547           return true;
2548       return false;
2549     }
2550 }
2551
2552 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2553 {
2554   std::size_t sz(cts.size());
2555   _ids.resize(sz);
2556   for(std::size_t i=0;i<sz;i++)
2557     {
2558       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2559       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2560         _ids[i]=(int)std::distance(typmai2,loc);
2561       else
2562         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2563     }
2564 }
2565
2566 /// @endcond
2567
2568 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),
2569     _father(fath)
2570 {
2571   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2572   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2573   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2574   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2575   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2576   for(iter0->begin();!iter0->finished();iter0->next())
2577     {
2578       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2579       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2580       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2581       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2582       if(nbProfile>0 || nbProfile2>0)
2583         {
2584           const PartDefinition *pd(0);
2585           if(mmu)
2586             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2587           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2588           if(nbProfile>0)
2589             _mesh_name=name0;
2590           else
2591             _mesh_name=name1;
2592         }
2593     }
2594   if(MFFPMIter::IsPresenceOfNode(entities))
2595     {
2596       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2597       if(nbProfile>0)
2598         {
2599           const PartDefinition *pd(0);
2600           if(mmu)
2601             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2602           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2603           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2604         }
2605     }
2606 }
2607
2608 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2609 {
2610   copyTinyInfoFrom(mesh);
2611 }
2612
2613 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2614 {
2615   if(id>=(int)_pfls.size())
2616     _pfls.resize(id+1);
2617   _pfls[id]=DataArrayInt::New();
2618   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2619   _pfls[id]->setName(pflName);
2620   _pfls[id]->alloc(lgth,1);
2621   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2622   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2623 }
2624
2625 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2626 {
2627   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2628   int sz;
2629   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
2630   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2631   if(i>=(int)_pfls.size())
2632     _pfls.resize(i+1);
2633   _pfls[i]=DataArrayInt::New();
2634   _pfls[i]->alloc(sz,1);
2635   _pfls[i]->setName(pflCpp.c_str());
2636   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
2637   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2638 }
2639
2640 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2641 {
2642   int nbOfPfls=_pfls.size();
2643   for(int i=0;i<nbOfPfls;i++)
2644     {
2645       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
2646       cpy->applyLin(1,1,0);
2647       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2648       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2649       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
2650     }
2651   //
2652   int nbOfLocs=_locs.size();
2653   for(int i=0;i<nbOfLocs;i++)
2654     _locs[i]->writeLL(fid);
2655 }
2656
2657 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2658 {
2659   std::vector<std::string> pfls=getPfls();
2660   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2661     {
2662       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2663       if(it2==pfls.end())
2664         {
2665           _pfls.push_back(*it);
2666         }
2667       else
2668         {
2669           int id=std::distance(pfls.begin(),it2);
2670           if(!(*it)->isEqual(*_pfls[id]))
2671             {
2672               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2673               throw INTERP_KERNEL::Exception(oss.str().c_str());
2674             }
2675         }
2676     }
2677   std::vector<std::string> locs=getLocs();
2678   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2679     {
2680       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2681       if(it2==locs.end())
2682         {
2683           _locs.push_back(*it);
2684         }
2685       else
2686         {
2687           int id=std::distance(locs.begin(),it2);
2688           if(!(*it)->isEqual(*_locs[id],eps))
2689             {
2690               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2691               throw INTERP_KERNEL::Exception(oss.str().c_str());
2692             }
2693         }
2694     }
2695 }
2696
2697 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2698 {
2699   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2700     getProfile((*it).c_str());
2701 }
2702
2703 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2704 {
2705   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2706     getLocalization((*it).c_str());
2707 }
2708
2709 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2710 {
2711   std::vector<std::string> profiles=real.getPflsReallyUsed();
2712   int sz=profiles.size();
2713   _pfls.resize(sz);
2714   for(int i=0;i<sz;i++)
2715     loadProfileInFile(fid,i,profiles[i].c_str());
2716   //
2717   std::vector<std::string> locs=real.getLocsReallyUsed();
2718   sz=locs.size();
2719   _locs.resize(sz);
2720   for(int i=0;i<sz;i++)
2721     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2722 }
2723
2724 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2725 {
2726   int nProfil=MEDnProfile(fid);
2727   for(int i=0;i<nProfil;i++)
2728     loadProfileInFile(fid,i);
2729   int sz=MEDnLocalization(fid);
2730   _locs.resize(sz);
2731   for(int i=0;i<sz;i++)
2732     {
2733       _locs[i]=MEDFileFieldLoc::New(fid,i);
2734     }
2735 }
2736
2737 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2738 {
2739   return new MEDFileFieldGlobs(fname);
2740 }
2741
2742 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2743 {
2744   return new MEDFileFieldGlobs;
2745 }
2746
2747 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2748 {
2749   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
2750 }
2751
2752 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2753 {
2754   std::vector<const BigMemoryObject *> ret;
2755   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2756     ret.push_back((const DataArrayInt *)*it);
2757   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2758     ret.push_back((const MEDFileFieldLoc *)*it);
2759   return ret;
2760 }
2761
2762 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
2763 {
2764   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2765   std::size_t i=0;
2766   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2767     {
2768       if((const DataArrayInt *)*it)
2769         ret->_pfls[i]=(*it)->deepCopy();
2770     }
2771   i=0;
2772   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2773     {
2774       if((const MEDFileFieldLoc*)*it)
2775         ret->_locs[i]=(*it)->deepCopy();
2776     }
2777   return ret.retn();
2778 }
2779
2780 /*!
2781  * \throw if a profile in \a pfls in not in \a this.
2782  * \throw if a localization in \a locs in not in \a this.
2783  * \sa MEDFileFieldGlobs::deepCpyPart
2784  */
2785 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2786 {
2787   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2788   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2789     {
2790       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2791       if(!pfl)
2792         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2793       pfl->incrRef();
2794       MCAuto<DataArrayInt> pfl2(pfl);
2795       ret->_pfls.push_back(pfl2);
2796     }
2797   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2798     {
2799       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2800       if(!loc)
2801         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2802       loc->incrRef();
2803       MCAuto<MEDFileFieldLoc> loc2(loc);
2804       ret->_locs.push_back(loc2);
2805     }
2806   ret->setFileName(getFileName());
2807   return ret.retn();
2808 }
2809
2810 /*!
2811  * \throw if a profile in \a pfls in not in \a this.
2812  * \throw if a localization in \a locs in not in \a this.
2813  * \sa MEDFileFieldGlobs::shallowCpyPart
2814  */
2815 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2816 {
2817   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2818   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2819     {
2820       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2821       if(!pfl)
2822         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2823       ret->_pfls.push_back(pfl->deepCopy());
2824     }
2825   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2826     {
2827       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2828       if(!loc)
2829         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2830       ret->_locs.push_back(loc->deepCopy());
2831     }
2832   ret->setFileName(getFileName());
2833   return ret.retn();
2834 }
2835
2836 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2837 {
2838 }
2839
2840 MEDFileFieldGlobs::MEDFileFieldGlobs()
2841 {
2842 }
2843
2844 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2845 {
2846 }
2847
2848 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2849 {
2850   oss << "Profiles :\n";
2851   std::size_t n=_pfls.size();
2852   for(std::size_t i=0;i<n;i++)
2853     {
2854       oss << "  - #" << i << " ";
2855       const DataArrayInt *pfl=_pfls[i];
2856       if(pfl)
2857         oss << "\"" << pfl->getName() << "\"\n";
2858       else
2859         oss << "EMPTY !\n";
2860     }
2861   n=_locs.size();
2862   oss << "Localizations :\n";
2863   for(std::size_t i=0;i<n;i++)
2864     {
2865       oss << "  - #" << i << " ";
2866       const MEDFileFieldLoc *loc=_locs[i];
2867       if(loc)
2868         loc->simpleRepr(oss);
2869       else
2870         oss<< "EMPTY !\n";
2871     }
2872 }
2873
2874 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2875 {
2876   _file_name=fileName;
2877 }
2878
2879 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2880 {
2881   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2882     {
2883       DataArrayInt *elt(*it);
2884       if(elt)
2885         {
2886           std::string name(elt->getName());
2887           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2888             {
2889               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2890                 {
2891                   elt->setName((*it2).second.c_str());
2892                   return;
2893                 }
2894             }
2895         }
2896     }
2897 }
2898
2899 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2900 {
2901   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2902     {
2903       MEDFileFieldLoc *elt(*it);
2904       if(elt)
2905         {
2906           std::string name(elt->getName());
2907           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2908             {
2909               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2910                 {
2911                   elt->setName((*it2).second.c_str());
2912                   return;
2913                 }
2914             }
2915         }
2916     }
2917 }
2918
2919 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2920 {
2921   if(locId<0 || locId>=(int)_locs.size())
2922     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2923   return _locs[locId]->getNbOfGaussPtPerCell();
2924 }
2925
2926 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2927 {
2928   return getLocalizationFromId(getLocalizationId(locName));
2929 }
2930
2931 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2932 {
2933   if(locId<0 || locId>=(int)_locs.size())
2934     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2935   return *_locs[locId];
2936 }
2937
2938 /// @cond INTERNAL
2939 namespace MEDCouplingImpl
2940 {
2941   class LocFinder
2942   {
2943   public:
2944     LocFinder(const std::string& loc):_loc(loc) { }
2945     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2946   private:
2947     const std::string &_loc;
2948   };
2949
2950   class PflFinder
2951   {
2952   public:
2953     PflFinder(const std::string& pfl):_pfl(pfl) { }
2954     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2955   private:
2956     const std::string& _pfl;
2957   };
2958 }
2959 /// @endcond
2960
2961 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2962 {
2963   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
2964   if(it==_locs.end())
2965     {
2966       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2967       for(it=_locs.begin();it!=_locs.end();it++)
2968         oss << "\"" << (*it)->getName() << "\", ";
2969       throw INTERP_KERNEL::Exception(oss.str().c_str());
2970     }
2971   return std::distance(_locs.begin(),it);
2972 }
2973
2974 /*!
2975  * The returned value is never null.
2976  */
2977 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2978 {
2979   std::string pflNameCpp(pflName);
2980   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
2981   if(it==_pfls.end())
2982     {
2983       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2984       for(it=_pfls.begin();it!=_pfls.end();it++)
2985         oss << "\"" << (*it)->getName() << "\", ";
2986       throw INTERP_KERNEL::Exception(oss.str().c_str());
2987     }
2988   return *it;
2989 }
2990
2991 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2992 {
2993   if(pflId<0 || pflId>=(int)_pfls.size())
2994     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2995   return _pfls[pflId];
2996 }
2997
2998 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
2999 {
3000   if(locId<0 || locId>=(int)_locs.size())
3001     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3002   return *_locs[locId];
3003 }
3004
3005 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3006 {
3007   return getLocalizationFromId(getLocalizationId(locName));
3008 }
3009
3010 /*!
3011  * The returned value is never null.
3012  */
3013 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3014 {
3015   std::string pflNameCpp(pflName);
3016   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3017   if(it==_pfls.end())
3018     {
3019       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3020       for(it=_pfls.begin();it!=_pfls.end();it++)
3021         oss << "\"" << (*it)->getName() << "\", ";
3022       throw INTERP_KERNEL::Exception(oss.str().c_str());
3023     }
3024   return *it;
3025 }
3026
3027 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3028 {
3029   if(pflId<0 || pflId>=(int)_pfls.size())
3030     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3031   return _pfls[pflId];
3032 }
3033
3034 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3035 {
3036   std::vector< MCAuto<DataArrayInt> > newPfls;
3037   int i=0;
3038   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3039     {
3040       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3041         newPfls.push_back(*it);
3042     }
3043   _pfls=newPfls;
3044 }
3045
3046 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3047 {
3048   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3049   int i=0;
3050   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3051     {
3052       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3053         newLocs.push_back(*it);
3054     }
3055   _locs=newLocs;
3056 }
3057
3058 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3059 {
3060   int sz=_pfls.size();
3061   std::vector<std::string> ret(sz);
3062   for(int i=0;i<sz;i++)
3063     ret[i]=_pfls[i]->getName();
3064   return ret;
3065 }
3066
3067 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3068 {
3069   int sz=_locs.size();
3070   std::vector<std::string> ret(sz);
3071   for(int i=0;i<sz;i++)
3072     ret[i]=_locs[i]->getName();
3073   return ret;
3074 }
3075
3076 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3077 {
3078   std::vector<std::string> v=getPfls();
3079   std::string s(pflName);
3080   return std::find(v.begin(),v.end(),s)!=v.end();
3081 }
3082
3083 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3084 {
3085   std::vector<std::string> v=getLocs();
3086   std::string s(locName);
3087   return std::find(v.begin(),v.end(),s)!=v.end();
3088 }
3089
3090 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3091 {
3092   std::map<int,std::vector<int> > m;
3093   int i=0;
3094   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3095     {
3096       const DataArrayInt *tmp=(*it);
3097       if(tmp)
3098         {
3099           m[tmp->getHashCode()].push_back(i);
3100         }
3101     }
3102   std::vector< std::vector<int> > ret;
3103   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3104     {
3105       if((*it2).second.size()>1)
3106         {
3107           std::vector<int> ret0;
3108           bool equalityOrNot=false;
3109           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3110             {
3111               std::vector<int>::const_iterator it4=it3; it4++;
3112               for(;it4!=(*it2).second.end();it4++)
3113                 {
3114                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3115                     {
3116                       if(!equalityOrNot)
3117                         ret0.push_back(*it3);
3118                       ret0.push_back(*it4);
3119                       equalityOrNot=true;
3120                     }
3121                 }
3122             }
3123           if(!ret0.empty())
3124             ret.push_back(ret0);
3125         }
3126     }
3127   return ret;
3128 }
3129
3130 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3131 {
3132   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3133 }
3134
3135 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3136 {
3137   std::string name(pfl->getName());
3138   if(name.empty())
3139     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3140   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3141     if(name==(*it)->getName())
3142       {
3143         if(!pfl->isEqual(*(*it)))
3144           {
3145             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3146             throw INTERP_KERNEL::Exception(oss.str().c_str());
3147           }
3148       }
3149   pfl->incrRef();
3150   _pfls.push_back(pfl);
3151 }
3152
3153 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)
3154 {
3155   std::string name(locName);
3156   if(name.empty())
3157     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3158   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3159   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3160     if((*it)->isName(locName))
3161       {
3162         if(!(*it)->isEqual(*obj,1e-12))
3163           {
3164             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3165             throw INTERP_KERNEL::Exception(oss.str().c_str());
3166           }
3167       }
3168   _locs.push_back(obj);
3169 }
3170
3171 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3172 {
3173   std::vector<std::string> names=getPfls();
3174   return CreateNewNameNotIn("NewPfl_",names);
3175 }
3176
3177 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3178 {
3179   std::vector<std::string> names=getLocs();
3180   return CreateNewNameNotIn("NewLoc_",names);
3181 }
3182
3183 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3184 {
3185   for(std::size_t sz=0;sz<100000;sz++)
3186     {
3187       std::ostringstream tryName;
3188       tryName << prefix << sz;
3189       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3190         return tryName.str();
3191     }
3192   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3193 }
3194
3195 /*!
3196  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3197  *  \param [in] fname - the file name.
3198  */
3199 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
3200 {
3201 }
3202
3203 /*!
3204  * Creates an empty MEDFileFieldGlobsReal.
3205  */
3206 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3207 {
3208 }
3209
3210 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3211 {
3212   return 0;
3213 }
3214
3215 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3216 {
3217   std::vector<const BigMemoryObject *> ret;
3218   ret.push_back((const MEDFileFieldGlobs *)_globals);
3219   return ret;
3220 }
3221
3222 /*!
3223  * Returns a string describing profiles and Gauss points held in \a this.
3224  *  \return std::string - the description string.
3225  */
3226 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3227 {
3228   const MEDFileFieldGlobs *glob=_globals;
3229   std::ostringstream oss2; oss2 << glob;
3230   std::string stars(oss2.str().length(),'*');
3231   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3232   if(glob)
3233     glob->simpleRepr(oss);
3234   else
3235     oss << "NO GLOBAL INFORMATION !\n";
3236 }
3237
3238 void MEDFileFieldGlobsReal::resetContent()
3239 {
3240   _globals=MEDFileFieldGlobs::New();
3241 }
3242
3243 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3244 {
3245 }
3246
3247 /*!
3248  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3249  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3250  */
3251 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3252 {
3253   _globals=other._globals;
3254 }
3255
3256 /*!
3257  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3258  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3259  */
3260 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3261 {
3262   const MEDFileFieldGlobs *otherg(other._globals);
3263   if(!otherg)
3264     return ;
3265   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3266 }
3267
3268 /*!
3269  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3270  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3271  */
3272 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3273 {
3274   const MEDFileFieldGlobs *otherg(other._globals);
3275   if(!otherg)
3276     return ;
3277   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3278 }
3279
3280 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3281 {
3282   _globals=other._globals;
3283   if((const MEDFileFieldGlobs *)_globals)
3284     _globals=other._globals->deepCopy();
3285 }
3286
3287 /*!
3288  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3289  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3290  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3291  *         \a this and \a other MEDFileFieldGlobsReal.
3292  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3293  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3294  */
3295 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3296 {
3297   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3298   if(thisGlobals==otherGlobals)
3299     return ;
3300   if(!thisGlobals)
3301     {
3302       _globals=other._globals;
3303       return ;
3304     }
3305   _globals->appendGlobs(*other._globals,eps);
3306 }
3307
3308 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3309 {
3310   checkGlobsPflsPartCoherency();
3311   checkGlobsLocsPartCoherency();
3312 }
3313
3314 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3315 {
3316   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3317 }
3318
3319 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3320 {
3321   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3322 }
3323
3324 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3325 {
3326   contentNotNull()->loadProfileInFile(fid,id,pflName);
3327 }
3328
3329 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3330 {
3331   contentNotNull()->loadProfileInFile(fid,id);
3332 }
3333
3334 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3335 {
3336   contentNotNull()->loadGlobals(fid,*this);
3337 }
3338
3339 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3340 {
3341   contentNotNull()->loadAllGlobals(fid);
3342 }
3343
3344 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3345 {
3346   contentNotNull()->writeGlobals(fid,opt);
3347 }
3348
3349 /*!
3350  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3351  * or getPflsReallyUsedMulti().
3352  *  \return std::vector<std::string> - a sequence of names of all profiles.
3353  */
3354 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3355 {
3356   return contentNotNull()->getPfls();
3357 }
3358
3359 /*!
3360  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3361  * or getLocsReallyUsedMulti().
3362  *  \return std::vector<std::string> - a sequence of names of all localizations.
3363  */
3364 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3365 {
3366   return contentNotNull()->getLocs();
3367 }
3368
3369 /*!
3370  * Checks if the profile with a given name exists.
3371  *  \param [in] pflName - the profile name of interest.
3372  *  \return bool - \c true if the profile named \a pflName exists.
3373  */
3374 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3375 {
3376   return contentNotNull()->existsPfl(pflName);
3377 }
3378
3379 /*!
3380  * Checks if the localization with a given name exists.
3381  *  \param [in] locName - the localization name of interest.
3382  *  \return bool - \c true if the localization named \a locName exists.
3383  */
3384 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3385 {
3386   return contentNotNull()->existsLoc(locName);
3387 }
3388
3389 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3390 {
3391   return contentNotNull()->createNewNameOfPfl();
3392 }
3393
3394 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3395 {
3396   return contentNotNull()->createNewNameOfLoc();
3397 }
3398
3399 /*!
3400  * Sets the name of a MED file.
3401  *  \param [inout] fileName - the file name.
3402  */
3403 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3404 {
3405   contentNotNull()->setFileName(fileName);
3406 }
3407
3408 /*!
3409  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3410  * in the same order.
3411  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3412  *          Each item of this sequence is a vector containing ids of equal profiles.
3413  */
3414 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3415 {
3416   return contentNotNull()->whichAreEqualProfiles();
3417 }
3418
3419 /*!
3420  * Finds equal localizations.
3421  *  \param [in] eps - a precision used to compare real values of the localizations.
3422  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3423  *          Each item of this sequence is a vector containing ids of equal localizations.
3424  */
3425 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3426 {
3427   return contentNotNull()->whichAreEqualLocs(eps);
3428 }
3429
3430 /*!
3431  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3432  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3433  *        this sequence is a pair whose 
3434  *        - the first item is a vector of profile names to replace by the second item,
3435  *        - the second item is a profile name to replace every profile name of the first item.
3436  */
3437 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3438 {
3439   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3440 }
3441
3442 /*!
3443  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3444  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3445  *        this sequence is a pair whose 
3446  *        - the first item is a vector of localization names to replace by the second item,
3447  *        - the second item is a localization name to replace every localization name of the first item.
3448  */
3449 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3450 {
3451   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3452 }
3453
3454 /*!
3455  * Replaces references to some profiles (a reference is a profile name) by references
3456  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3457  * them-selves accordingly. <br>
3458  * This method is a generalization of changePflName().
3459  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3460  *        this sequence is a pair whose 
3461  *        - the first item is a vector of profile names to replace by the second item,
3462  *        - the second item is a profile name to replace every profile of the first item.
3463  * \sa changePflsRefsNamesGen()
3464  * \sa changePflName()
3465  */
3466 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3467 {
3468   changePflsRefsNamesGen(mapOfModif);
3469   changePflsNamesInStruct(mapOfModif);
3470 }
3471
3472 /*!
3473  * Replaces references to some localizations (a reference is a localization name) by references
3474  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3475  * them-selves accordingly. <br>
3476  * This method is a generalization of changeLocName().
3477  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3478  *        this sequence is a pair whose 
3479  *        - the first item is a vector of localization names to replace by the second item,
3480  *        - the second item is a localization name to replace every localization of the first item.
3481  * \sa changeLocsRefsNamesGen()
3482  * \sa changeLocName()
3483  */
3484 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3485 {
3486   changeLocsRefsNamesGen(mapOfModif);
3487   changeLocsNamesInStruct(mapOfModif);
3488 }
3489
3490 /*!
3491  * Renames the profile having a given name and updates references to this profile.
3492  *  \param [in] oldName - the name of the profile to rename.
3493  *  \param [in] newName - a new name of the profile.
3494  * \sa changePflsNames().
3495  */
3496 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3497 {
3498   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3499   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3500   mapOfModif[0]=p;
3501   changePflsNames(mapOfModif);
3502 }
3503
3504 /*!
3505  * Renames the localization having a given name and updates references to this localization.
3506  *  \param [in] oldName - the name of the localization to rename.
3507  *  \param [in] newName - a new name of the localization.
3508  * \sa changeLocsNames().
3509  */
3510 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3511 {
3512   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3513   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3514   mapOfModif[0]=p;
3515   changeLocsNames(mapOfModif);
3516 }
3517
3518 /*!
3519  * Removes duplicated profiles. Returns a map used to update references to removed 
3520  * profiles via changePflsRefsNamesGen().
3521  * Equal profiles are found using whichAreEqualProfiles().
3522  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3523  *          a sequence describing the performed replacements of profiles. Each element of
3524  *          this sequence is a pair whose
3525  *          - the first item is a vector of profile names replaced by the second item,
3526  *          - the second item is a profile name replacing every profile of the first item.
3527  */
3528 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3529 {
3530   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3531   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3532   int i=0;
3533   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3534     {
3535       std::vector< std::string > tmp((*it).size());
3536       int j=0;
3537       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3538         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3539       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3540       ret[i]=p;
3541       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3542       killProfileIds(tmp2);
3543     }
3544   changePflsRefsNamesGen(ret);
3545   return ret;
3546 }
3547
3548 /*!
3549  * Removes duplicated localizations. Returns a map used to update references to removed 
3550  * localizations via changeLocsRefsNamesGen().
3551  * Equal localizations are found using whichAreEqualLocs().
3552  *  \param [in] eps - a precision used to compare real values of the localizations.
3553  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3554  *          a sequence describing the performed replacements of localizations. Each element of
3555  *          this sequence is a pair whose
3556  *          - the first item is a vector of localization names replaced by the second item,
3557  *          - the second item is a localization name replacing every localization of the first item.
3558  */
3559 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3560 {
3561   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3562   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3563   int i=0;
3564   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3565     {
3566       std::vector< std::string > tmp((*it).size());
3567       int j=0;
3568       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3569         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3570       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3571       ret[i]=p;
3572       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3573       killLocalizationIds(tmp2);
3574     }
3575   changeLocsRefsNamesGen(ret);
3576   return ret;
3577 }
3578
3579 /*!
3580  * Returns number of Gauss points per cell in a given localization.
3581  *  \param [in] locId - an id of the localization of interest.
3582  *  \return int - the number of the Gauss points per cell.
3583  */
3584 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3585 {
3586   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3587 }
3588
3589 /*!
3590  * Returns an id of a localization by its name.
3591  *  \param [in] loc - the localization name of interest.
3592  *  \return int - the id of the localization.
3593  *  \throw If there is no a localization named \a loc.
3594  */
3595 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3596 {
3597   return contentNotNull()->getLocalizationId(loc);
3598 }
3599
3600 /*!
3601  * Returns the name of the MED file.
3602  *  \return const std::string&  - the MED file name.
3603  */
3604 std::string MEDFileFieldGlobsReal::getFileName() const
3605 {
3606   return contentNotNull()->getFileName();
3607 }
3608
3609 /*!
3610  * Returns a localization object by its name.
3611  *  \param [in] locName - the name of the localization of interest.
3612  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3613  *  \throw If there is no a localization named \a locName.
3614  */
3615 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3616 {
3617   return contentNotNull()->getLocalization(locName);
3618 }
3619
3620 /*!
3621  * Returns a localization object by its id.
3622  *  \param [in] locId - the id of the localization of interest.
3623  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3624  *  \throw If there is no a localization with id \a locId.
3625  */
3626 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3627 {
3628   return contentNotNull()->getLocalizationFromId(locId);
3629 }
3630
3631 /*!
3632  * Returns a profile array by its name.
3633  *  \param [in] pflName - the name of the profile of interest.
3634  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3635  *  \throw If there is no a profile named \a pflName.
3636  */
3637 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3638 {
3639   return contentNotNull()->getProfile(pflName);
3640 }
3641
3642 /*!
3643  * Returns a profile array by its id.
3644  *  \param [in] pflId - the id of the profile of interest.
3645  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3646  *  \throw If there is no a profile with id \a pflId.
3647  */
3648 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3649 {
3650   return contentNotNull()->getProfileFromId(pflId);
3651 }
3652
3653 /*!
3654  * Returns a localization object, apt for modification, by its id.
3655  *  \param [in] locId - the id of the localization of interest.
3656  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3657  *          having the id \a locId.
3658  *  \throw If there is no a localization with id \a locId.
3659  */
3660 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3661 {
3662   return contentNotNull()->getLocalizationFromId(locId);
3663 }
3664
3665 /*!
3666  * Returns a localization object, apt for modification, by its name.
3667  *  \param [in] locName - the name of the localization of interest.
3668  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3669  *          having the name \a locName.
3670  *  \throw If there is no a localization named \a locName.
3671  */
3672 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3673 {
3674   return contentNotNull()->getLocalization(locName);
3675 }
3676
3677 /*!
3678  * Returns a profile array, apt for modification, by its name.
3679  *  \param [in] pflName - the name of the profile of interest.
3680  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3681  *  \throw If there is no a profile named \a pflName.
3682  */
3683 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3684 {
3685   return contentNotNull()->getProfile(pflName);
3686 }
3687
3688 /*!
3689  * Returns a profile array, apt for modification, by its id.
3690  *  \param [in] pflId - the id of the profile of interest.
3691  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3692  *  \throw If there is no a profile with id \a pflId.
3693  */
3694 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3695 {
3696   return contentNotNull()->getProfileFromId(pflId);
3697 }
3698
3699 /*!
3700  * Removes profiles given by their ids. No data is updated to track this removal.
3701  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3702  */
3703 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3704 {
3705   contentNotNull()->killProfileIds(pflIds);
3706 }
3707
3708 /*!
3709  * Removes localizations given by their ids. No data is updated to track this removal.
3710  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3711  */
3712 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3713 {
3714   contentNotNull()->killLocalizationIds(locIds);
3715 }
3716
3717 /*!
3718  * Stores a profile array.
3719  *  \param [in] pfl - the profile array to store.
3720  *  \throw If the name of \a pfl is empty.
3721  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3722  *         different ids.
3723  */
3724 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3725 {
3726   contentNotNull()->appendProfile(pfl);
3727 }
3728
3729 /*!
3730  * Adds a new localization of Gauss points.
3731  *  \param [in] locName - the name of the new localization.
3732  *  \param [in] geoType - a geometrical type of the reference cell.
3733  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3734  *         must be \c nbOfNodesPerCell * \c dimOfType.
3735  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3736  *         must be  _wg_.size() * \c dimOfType.
3737  *  \param [in] w - the weights of Gauss points.
3738  *  \throw If \a locName is empty.
3739  *  \throw If a localization with the name \a locName already exists but is
3740  *         different form the new one.
3741  */
3742 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)
3743 {
3744   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3745 }
3746
3747 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3748 {
3749   MEDFileFieldGlobs *g(_globals);
3750   if(!g)
3751     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3752   return g;
3753 }
3754
3755 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3756 {
3757   const MEDFileFieldGlobs *g(_globals);
3758   if(!g)
3759     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3760   return g;
3761 }
3762
3763 //= MEDFileFieldNameScope
3764
3765 MEDFileFieldNameScope::MEDFileFieldNameScope()
3766 {
3767 }
3768
3769 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3770 {
3771 }
3772
3773 /*!
3774  * Returns the name of \a this field.
3775  *  \return std::string - a string containing the field name.
3776  */
3777 std::string MEDFileFieldNameScope::getName() const
3778 {
3779   return _name;
3780 }
3781
3782 /*!
3783  * Sets name of \a this field
3784  *  \param [in] name - the new field name.
3785  */
3786 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3787 {
3788   _name=fieldName;
3789 }
3790
3791 std::string MEDFileFieldNameScope::getDtUnit() const
3792 {
3793   return _dt_unit;
3794 }
3795
3796 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3797 {
3798   _dt_unit=dtUnit;
3799 }
3800
3801 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3802 {
3803   _name=other._name;
3804   _dt_unit=other._dt_unit;
3805 }
3806
3807 //= MEDFileAnyTypeField1TSWithoutSDA
3808
3809 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3810 {
3811   _field_per_mesh.resize(other._field_per_mesh.size());
3812   std::size_t i=0;
3813   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3814     {
3815       if((const MEDFileFieldPerMesh *)*it)
3816         _field_per_mesh[i]=(*it)->deepCopy(this);
3817     }
3818 }
3819
3820 /*!
3821  * Prints a string describing \a this field into a stream. This string is outputted 
3822  * by \c print Python command.
3823  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3824  *  \param [in,out] oss - the out stream.
3825  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3826  *          info id printed, else, not.
3827  */
3828 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3829 {
3830   std::string startOfLine(bkOffset,' ');
3831   oss << startOfLine << "Field ";
3832   if(bkOffset==0)
3833     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3834   oss << "on one time Step ";
3835   if(f1tsId>=0)
3836     oss << "(" << f1tsId << ") ";
3837   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3838   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3839   const DataArray *arr=getUndergroundDataArray();
3840   if(arr)
3841     {
3842       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3843       if(f1tsId<0)
3844         {
3845           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3846           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3847             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3848         }
3849       if(arr->isAllocated())
3850         {
3851           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3852         }
3853       else
3854         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3855     }
3856   else
3857     {
3858       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3859     }
3860   oss << startOfLine << "----------------------" << std::endl;
3861   if(!_field_per_mesh.empty())
3862     {
3863       int i=0;
3864       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3865         {
3866           const MEDFileFieldPerMesh *cur=(*it2);
3867           if(cur)
3868             cur->simpleRepr(bkOffset,oss,i);
3869           else
3870             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3871         }
3872     }
3873   else
3874     {
3875       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3876     }
3877   oss << startOfLine << "----------------------" << std::endl;
3878 }
3879
3880 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3881 {
3882   const DataArray *arr(getUndergroundDataArray());
3883   if(!arr)
3884     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3885   int nbOfCompo=arr->getNumberOfComponents();
3886   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3887   for(int i=0;i<nbOfCompo;i++)
3888     {
3889       ret[i]=deepCopy();
3890       std::vector<int> v(1,i);
3891       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
3892       ret[i]->setArray(arr2);
3893     }
3894   return ret;
3895 }
3896
3897 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)
3898 {
3899 }
3900
3901 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3902 {
3903 }
3904
3905 /*!
3906  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3907  * empty. Returns -1 if this in on nodes.
3908  *  \return int - the dimension of \a this.
3909  */
3910 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3911 {
3912   int ret=-2;
3913   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3914     (*it)->getDimension(ret);
3915   return ret;
3916 }
3917
3918 /*!
3919  * Returns the mesh name.
3920  *  \return std::string - a string holding the mesh name.
3921  *  \throw If \c _field_per_mesh.empty()
3922  */
3923 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3924 {
3925   if(_field_per_mesh.empty())
3926     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3927   return _field_per_mesh[0]->getMeshName();
3928 }
3929
3930 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3931 {
3932   std::string oldName(getMeshName());
3933   std::vector< std::pair<std::string,std::string> > v(1);
3934   v[0].first=oldName; v[0].second=newMeshName;
3935   changeMeshNames(v);
3936 }
3937
3938 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3939 {
3940   bool ret=false;
3941   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3942     {
3943       MEDFileFieldPerMesh *cur(*it);
3944       if(cur)
3945         ret=cur->changeMeshNames(modifTab) || ret;
3946     }
3947   return ret;
3948 }
3949
3950 /*!
3951  * Returns the number of iteration of the state of underlying mesh.
3952  *  \return int - the iteration number.
3953  *  \throw If \c _field_per_mesh.empty()
3954  */
3955 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3956 {
3957   if(_field_per_mesh.empty())
3958     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3959   return _field_per_mesh[0]->getMeshIteration();
3960 }
3961
3962 /*!
3963  * Returns the order number of iteration of the state of underlying mesh.
3964  *  \return int - the order number.
3965  *  \throw If \c _field_per_mesh.empty()
3966  */
3967 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3968 {
3969   if(_field_per_mesh.empty())
3970     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3971   return _field_per_mesh[0]->getMeshOrder();
3972 }
3973
3974 /*!
3975  * Checks if \a this field is tagged by a given iteration number and a given
3976  * iteration order number.
3977  *  \param [in] iteration - the iteration number of interest.
3978  *  \param [in] order - the iteration order number of interest.
3979  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3980  *          \a this->getOrder() == \a order.
3981  */
3982 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3983 {
3984   return iteration==_iteration && order==_order;
3985 }
3986
3987 /*!
3988  * Returns number of iteration and order number of iteration when
3989  * \a this field has been calculated.
3990  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3991  *          order number.
3992  */
3993 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3994 {
3995   std::pair<int,int> p;
3996   fillIteration(p);
3997   return p;
3998 }
3999
4000 /*!
4001  * Returns number of iteration and order number of iteration when
4002  * \a this field has been calculated.
4003  *  \param [in,out] p - a pair returning the iteration number and the iteration
4004  *          order number.
4005  */
4006 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4007 {
4008   p.first=_iteration;
4009   p.second=_order;
4010 }
4011
4012 /*!
4013  * Returns all types of spatial discretization of \a this field.
4014  *  \param [in,out] types - a sequence of types of \a this field.
4015  */
4016 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4017 {
4018   std::set<TypeOfField> types2;
4019   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4020     {
4021       (*it)->fillTypesOfFieldAvailable(types2);
4022     }
4023   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4024   std::copy(types2.begin(),types2.end(),bi);
4025 }
4026
4027 /*!
4028  * Returns all types of spatial discretization of \a this field.
4029  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4030  *          of \a this field.
4031  */
4032 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4033 {
4034   std::vector<TypeOfField> ret;
4035   fillTypesOfFieldAvailable(ret);
4036   return ret;
4037 }
4038
4039 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4040 {
4041   std::vector<std::string> ret;
4042   std::set<std::string> ret2;
4043   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4044     {
4045       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4046       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4047         if(ret2.find(*it2)==ret2.end())
4048           {
4049             ret.push_back(*it2);
4050             ret2.insert(*it2);
4051           }
4052     }
4053   return ret;
4054 }
4055
4056 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4057 {
4058   std::vector<std::string> ret;
4059   std::set<std::string> ret2;
4060   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4061     {
4062       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4063       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4064         if(ret2.find(*it2)==ret2.end())
4065           {
4066             ret.push_back(*it2);
4067             ret2.insert(*it2);
4068           }
4069     }
4070   return ret;
4071 }
4072
4073 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4074 {
4075   std::vector<std::string> ret;
4076   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4077     {
4078       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4079       ret.insert(ret.end(),tmp.begin(),tmp.end());
4080     }
4081   return ret;
4082 }
4083
4084 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4085 {
4086   std::vector<std::string> ret;
4087   std::set<std::string> ret2;
4088   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4089     {
4090       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4091       ret.insert(ret.end(),tmp.begin(),tmp.end());
4092     }
4093   return ret;
4094 }
4095
4096 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4097 {
4098   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4099     (*it)->changePflsRefsNamesGen(mapOfModif);
4100 }
4101
4102 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4103 {
4104   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4105     (*it)->changeLocsRefsNamesGen(mapOfModif);
4106 }
4107
4108 /*!
4109  * Returns all attributes of parts of \a this field lying on a given mesh.
4110  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4111  * item of every of returned sequences refers to the _i_-th part of \a this field.
4112  * Thus all sequences returned by this method are of the same length equal to number
4113  * of different types of supporting entities.<br>
4114  * A field part can include sub-parts with several different spatial discretizations,
4115  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4116  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4117  * of a nested sequence corresponds to a type of spatial discretization.<br>
4118  * This method allows for iteration over MEDFile DataStructure without any overhead.
4119  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4120  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4121  *          not checked if \a mname == \c NULL).
4122  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4123  *          a field part is returned. 
4124  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4125  *          This sequence is of the same length as \a types. 
4126  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4127  *          discretization. A profile name can be empty.
4128  *          Length of this and of nested sequences is the same as that of \a typesF.
4129  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4130  *          discretization. A localization name can be empty.
4131  *          Length of this and of nested sequences is the same as that of \a typesF.
4132  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4133  *          of ids of tuples within the data array, per each type of spatial
4134  *          discretization within one mesh entity type. 
4135  *          Length of this and of nested sequences is the same as that of \a typesF.
4136  *  \throw If no field is lying on \a mname.
4137  */
4138 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
4139 {
4140   int meshId=0;
4141   if(!mname.empty())
4142     meshId=getMeshIdFromMeshName(mname);
4143   else
4144     if(_field_per_mesh.empty())
4145       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4146   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4147 }
4148
4149 /*!
4150  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4151  * maximal absolute dimension and values returned via the out parameter \a levs are 
4152  * dimensions relative to the maximal absolute dimension. <br>
4153  * This method is designed for MEDFileField1TS instances that have a discretization
4154  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4155  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4156  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4157  * Only these 3 discretizations will be taken into account here. If \a this is
4158  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4159  * This method is useful to make the link between the dimension of the underlying mesh
4160  * and the levels of \a this, because it is possible that the highest dimension of \a this
4161  * field is not equal to the dimension of the underlying mesh.
4162  * 
4163  * Let's consider the following case:
4164  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4165  * TETRA4, HEXA8, TRI3 and SEG2.
4166  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4167  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4168  *
4169  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4170  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4171  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4172  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4173  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4174  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4175  * For example<br>
4176  * to retrieve the highest level of
4177  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4178  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4179  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4180  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4181  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4182  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4183  *          not checked if \a mname == \c NULL).
4184  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4185  *          absolute one. They are in decreasing order. This sequence is cleared before
4186  *          filling it in.
4187  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4188  *  \throw If no field is lying on \a mname.
4189  */
4190 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4191 {
4192   levs.clear();
4193   int meshId=getMeshIdFromMeshName(mname);
4194   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4195   std::vector< std::vector<TypeOfField> > typesF;
4196   std::vector< std::vector<std::string> > pfls, locs;
4197   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4198   if(types.empty())
4199     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4200   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4201   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4202     return -1;
4203   st.erase(INTERP_KERNEL::NORM_ERROR);
4204   std::set<int> ret1;
4205   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4206     {
4207       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4208       ret1.insert((int)cm.getDimension());
4209     }
4210   int ret=*std::max_element(ret1.begin(),ret1.end());
4211   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4212   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4213   return ret;
4214 }
4215
4216 /*!
4217  * \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.
4218  * \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.
4219  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4220  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4221  */
4222 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4223 {
4224   int mid=getMeshIdFromMeshName(mName);
4225   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4226 }
4227
4228 /*!
4229  * \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.
4230  * \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.
4231  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4232  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4233  */
4234 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4235 {
4236   int mid=getMeshIdFromMeshName(mName);
4237   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4238 }
4239
4240 /*!
4241  * \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.
4242  */
4243 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4244 {
4245   if(_field_per_mesh.empty())
4246     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4247   if(mName.empty())
4248     return 0;
4249   std::string mName2(mName);
4250   int ret=0;
4251   std::vector<std::string> msg;
4252   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4253     if(mName2==(*it)->getMeshName())
4254       return ret;
4255     else
4256       msg.push_back((*it)->getMeshName());
4257   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4258   oss << "Possible meshes are : ";
4259   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4260     oss << "\"" << (*it2) << "\" ";
4261   throw INTERP_KERNEL::Exception(oss.str().c_str());
4262 }
4263
4264 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4265 {
4266   if(!mesh)
4267     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4268   std::string tmp(mesh->getName());
4269   if(tmp.empty())
4270     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4271   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4272   int i=0;
4273   for(;it!=_field_per_mesh.end();it++,i++)
4274     {
4275       if((*it)->getMeshName()==tmp)
4276         return i;
4277     }
4278   int sz=_field_per_mesh.size();
4279   _field_per_mesh.resize(sz+1);
4280   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4281   return sz;
4282 }
4283
4284 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4285                                                                    MEDFileFieldGlobsReal& glob)
4286 {
4287   bool ret=false;
4288   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4289     {
4290       MEDFileFieldPerMesh *fpm(*it);
4291       if(fpm)
4292         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4293     }
4294   return ret;
4295 }
4296
4297 /*!
4298  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4299  * splitting that leads to single spatial discretization of this.
4300  *
4301  * \sa splitMultiDiscrPerGeoTypes
4302  */
4303 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4304 {
4305   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4306   std::vector< std::vector<TypeOfField> > typesF;
4307   std::vector< std::vector<std::string> > pfls,locs;
4308   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4309   std::set<TypeOfField> allEnt;
4310   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4311     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4312       allEnt.insert(*it2);
4313   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4314   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4315   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4316     {
4317       std::vector< std::pair<int,int> > its;
4318       ret[i]=shallowCpy();
4319       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4320       ret[i]->updateData(newLgth,its);
4321     }
4322   return ret;
4323 }
4324
4325 /*!
4326  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4327  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4328  *
4329  * \sa splitDiscretizations
4330  */
4331 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4332 {
4333   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4334   std::vector< std::vector<TypeOfField> > typesF;
4335   std::vector< std::vector<std::string> > pfls,locs;
4336   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4337   std::set<TypeOfField> allEnt;
4338   std::size_t nbOfMDPGT(0),ii(0);
4339   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4340     {
4341       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4342       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4343         allEnt.insert(*it2);
4344     }
4345   if(allEnt.size()!=1)
4346     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4347   if(nbOfMDPGT==0)
4348     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4349   if(nbOfMDPGT==1)
4350     {
4351       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4352       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4353       return ret0;
4354     }
4355   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4356   for(std::size_t i=0;i<nbOfMDPGT;i++)
4357     {
4358       std::vector< std::pair<int,int> > its;
4359       ret[i]=shallowCpy();
4360       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4361       ret[i]->updateData(newLgth,its);
4362     }
4363   return ret;
4364 }
4365
4366 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4367 {
4368   int globalCounter(0);
4369   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4370     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4371   return globalCounter;
4372 }
4373
4374 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4375 {
4376   int globalCounter(0);
4377   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4378     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4379   return globalCounter;
4380 }
4381
4382 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4383 {
4384   if(_nb_of_tuples_to_be_allocated>=0)
4385     {
4386       _nb_of_tuples_to_be_allocated=newLgth;
4387       const DataArray *oldArr(getUndergroundDataArray());
4388       if(oldArr)
4389         {
4390           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4391           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4392           setArray(newArr);
4393           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4394         }
4395       return ;
4396     }
4397   if(_nb_of_tuples_to_be_allocated==-1)
4398     return ;
4399   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4400     {
4401       const DataArray *oldArr(getUndergroundDataArray());
4402       if(!oldArr || !oldArr->isAllocated())
4403         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4404       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4405       newArr->alloc(newLgth,getNumberOfComponents());
4406       if(oldArr)
4407         newArr->copyStringInfoFrom(*oldArr);
4408       int pos=0;
4409       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4410         {
4411           if((*it).second<(*it).first)
4412             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4413           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4414           pos+=(*it).second-(*it).first;
4415         }
4416       setArray(newArr);
4417       return ;
4418     }
4419   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4420 }
4421
4422 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4423 {
4424   if(_field_per_mesh.empty())
4425     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4426   if(_field_per_mesh.size()>1)
4427     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4428   _field_per_mesh[0]->copyOptionsFrom(opts);
4429   _field_per_mesh[0]->writeLL(fid,nasc);
4430 }
4431
4432 /*!
4433  * 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.
4434  * If false is returned the memory allocation is not required.
4435  */
4436 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4437 {
4438   if(_nb_of_tuples_to_be_allocated>=0)
4439     {
4440       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4441       _nb_of_tuples_to_be_allocated=-2;
4442       return true;
4443     }
4444   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4445     return false;
4446   if(_nb_of_tuples_to_be_allocated==-1)
4447     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4448   if(_nb_of_tuples_to_be_allocated<-3)
4449     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4450   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4451 }
4452
4453 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4454 {
4455   med_int numdt,numit;
4456   med_float dt;
4457   med_int nmesh;
4458   med_bool localMesh;
4459   med_int meshnumdt,meshnumit;
4460   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4461   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4462   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4463   if(_iteration!=numdt || _order!=numit)
4464     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4465   _field_per_mesh.resize(nmesh);
4466   //
4467   MEDFileMesh *mm(0);
4468   if(ms)
4469     {
4470       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4471       mm=ms->getMeshWithName(meshNameCpp);
4472     }
4473   //
4474   for(int i=0;i<nmesh;i++)
4475     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4476   _nb_of_tuples_to_be_allocated=0;
4477   for(int i=0;i<nmesh;i++)
4478     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4479 }
4480
4481 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4482 {
4483   allocIfNecessaryTheArrayToReceiveDataFromFile();
4484   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4485     (*it)->loadBigArraysRecursively(fid,nasc);
4486 }
4487
4488 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4489 {
4490   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4491     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4492       (*it)->loadBigArraysRecursively(fid,nasc);
4493 }
4494
4495 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4496 {
4497   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4498   loadBigArraysRecursively(fid,nasc);
4499 }
4500
4501 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4502 {
4503   DataArray *thisArr(getUndergroundDataArray());
4504   if(thisArr && thisArr->isAllocated())
4505     {
4506       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4507       thisArr->desallocate();
4508     }
4509 }
4510
4511 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4512 {
4513   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
4514 }
4515
4516 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4517 {
4518   std::vector<const BigMemoryObject *> ret;
4519   if(getUndergroundDataArray())
4520     ret.push_back(getUndergroundDataArray());
4521   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4522     ret.push_back((const MEDFileFieldPerMesh *)*it);
4523   return ret;
4524 }
4525
4526 /*!
4527  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4528  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4529  * "Sort By Type"), if not, an exception is thrown. 
4530  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4531  *  \param [in] arr - the array of values.
4532  *  \param [in,out] glob - the global data where profiles and localization present in
4533  *          \a field, if any, are added.
4534  *  \throw If the name of \a field is empty.
4535  *  \throw If the data array of \a field is not set.
4536  *  \throw If \a this->_arr is already allocated but has different number of components
4537  *         than \a field.
4538  *  \throw If the underlying mesh of \a field has no name.
4539  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4540  */
4541 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4542 {
4543   const MEDCouplingMesh *mesh=field->getMesh();
4544   //
4545   TypeOfField type=field->getTypeOfField();
4546   std::vector<DataArrayInt *> dummy;
4547   int start=copyTinyInfoFrom(field,arr);
4548   int pos=addNewEntryIfNecessary(mesh);
4549   if(type!=ON_NODES)
4550     {
4551       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4552       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4553     }
4554   else
4555     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4556 }
4557
4558 /*!
4559  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4560  * of a given mesh are used as the support of the given field (a real support is not used). 
4561  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4562  * Order of underlying mesh entities of the given field specified by \a profile parameter
4563  * is not prescribed; this method permutes field values to have them sorted by element
4564  * type as required for writing to MED file. A new profile is added only if no equal
4565  * profile is missing. 
4566  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4567  *  \param [in] arrOfVals - the values of the field \a field used.
4568  *  \param [in] mesh - the supporting mesh of \a field.
4569  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4570  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4571  *  \param [in,out] glob - the global data where profiles and localization present in
4572  *          \a field, if any, are added.
4573  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4574  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4575  *  \throw If the data array of \a field is not set.
4576  *  \throw If \a this->_arr is already allocated but has different number of components
4577  *         than \a field.
4578  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4579  *  \sa setFieldNoProfileSBT()
4580  */
4581 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4582 {
4583   if(!field)
4584     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4585   if(!arrOfVals || !arrOfVals->isAllocated())
4586     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4587   TypeOfField type=field->getTypeOfField();
4588   std::vector<DataArrayInt *> idsInPflPerType;
4589   std::vector<DataArrayInt *> idsPerType;
4590   std::vector<int> code,code2;
4591   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4592   if(type!=ON_NODES)
4593     {
4594       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4595       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4596       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4597       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4598       // start of check
4599       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
4600       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4601       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4602         {
4603           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4604           throw INTERP_KERNEL::Exception(oss.str().c_str());
4605         }
4606       // end of check
4607       int start=copyTinyInfoFrom(field,arrOfVals);
4608       code2=m->getDistributionOfTypes();
4609       //
4610       int pos=addNewEntryIfNecessary(m);
4611       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4612     }
4613   else
4614     {
4615       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4616         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4617       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4618       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4619       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4620       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4621         {
4622           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4623           throw INTERP_KERNEL::Exception(oss.str().c_str());
4624         }
4625       int start=copyTinyInfoFrom(field,arrOfVals);
4626       int pos=addNewEntryIfNecessary(m);
4627       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4628     }
4629 }
4630
4631 /*!
4632  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4633  */
4634 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4635 {
4636   if(_nb_of_tuples_to_be_allocated>=0)
4637     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 !");
4638   DataArray *arr(getOrCreateAndGetArray());
4639   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4640   _nb_of_tuples_to_be_allocated=-3;
4641 }
4642
4643 /*!
4644  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4645  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4646  * larger by the size of \a field. Returns an id of the first not filled
4647  * tuple of \a this->_arr.
4648  *  \param [in] field - the field to copy the info on components and the name from.
4649  *  \return int - the id of first not initialized tuple of \a this->_arr.
4650  *  \throw If the name of \a field is empty.
4651  *  \throw If the data array of \a field is not set.
4652  *  \throw If \a this->_arr is already allocated but has different number of components
4653  *         than \a field.
4654  */
4655 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4656 {
4657   if(!field)
4658     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4659   std::string name(field->getName());
4660   setName(name.c_str());
4661   setDtUnit(field->getTimeUnit());
4662   if(name.empty())
4663     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4664   if(!arr)
4665     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4666   if(!arr->isAllocated())
4667     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4668   _dt=field->getTime(_iteration,_order);
4669   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4670   if(!getOrCreateAndGetArray()->isAllocated())
4671     {
4672       allocNotFromFile(arr->getNumberOfTuples());
4673       return 0;
4674     }
4675   else
4676     {
4677       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4678       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4679       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4680       _nb_of_tuples_to_be_allocated=-3;
4681       return oldNbOfTuples;
4682     }
4683 }
4684
4685 /*!
4686  * Returns number of components in \a this field
4687  *  \return int - the number of components.
4688  */
4689 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4690 {
4691   return getOrCreateAndGetArray()->getNumberOfComponents();
4692 }
4693
4694 /*!
4695  * Change info on components in \a this.
4696  * \throw If size of \a infos is not equal to the number of components already in \a this.
4697  */
4698 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4699 {
4700   DataArray *arr=getOrCreateAndGetArray();
4701   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4702 }
4703
4704 /*!
4705  * Returns info on components of \a this field.
4706  *  \return const std::vector<std::string>& - a sequence of strings each being an
4707  *          information on _i_-th component.
4708  */
4709 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4710 {
4711   const DataArray *arr=getOrCreateAndGetArray();
4712   return arr->getInfoOnComponents();
4713 }
4714
4715 /*!
4716  * Returns a mutable info on components of \a this field.
4717  *  \return std::vector<std::string>& - a sequence of strings each being an
4718  *          information on _i_-th component.
4719  */
4720 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4721 {
4722   DataArray *arr=getOrCreateAndGetArray();
4723   return arr->getInfoOnComponents();
4724 }
4725
4726 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4727 {
4728   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4729     {
4730       const MEDFileFieldPerMesh *fpm(*it);
4731       if(!fpm)
4732         continue;
4733       if(fpm->presenceOfMultiDiscPerGeoType())
4734         return true;
4735     }
4736   return false;
4737 }
4738
4739 /*!
4740  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4741  *  \param [in] type - a spatial discretization of the new field.
4742  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4743  *  \param [in] mName - a name of the supporting mesh.
4744  *  \param [in] renumPol - specifies how to permute values of the result field according to
4745  *          the optional numbers of cells and nodes, if any. The valid values are
4746  *          - 0 - do not permute.
4747  *          - 1 - permute cells.
4748  *          - 2 - permute nodes.
4749  *          - 3 - permute cells and nodes.
4750  *
4751  *  \param [in] glob - the global data storing profiles and localization.
4752  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4753  *          caller is to delete this field using decrRef() as it is no more needed. 
4754  *  \throw If the MED file is not readable.
4755  *  \throw If there is no mesh named \a mName in the MED file.
4756  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4757  *  \throw If no field of \a this is lying on the mesh \a mName.
4758  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4759  */
4760 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4761 {
4762   MCAuto<MEDFileMesh> mm;
4763   if(mName.empty())
4764     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4765   else
4766     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4767   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4768 }
4769
4770 /*!
4771  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4772  *  \param [in] type - a spatial discretization of the new field.
4773  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4774  *  \param [in] renumPol - specifies how to permute values of the result field according to
4775  *          the optional numbers of cells and nodes, if any. The valid values are
4776  *          - 0 - do not permute.
4777  *          - 1 - permute cells.
4778  *          - 2 - permute nodes.
4779  *          - 3 - permute cells and nodes.
4780  *
4781  *  \param [in] glob - the global data storing profiles and localization.
4782  *  \param [in] mesh - the supporting mesh.
4783  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4784  *          caller is to delete this field using decrRef() as it is no more needed. 
4785  *  \throw If the MED file is not readable.
4786  *  \throw If no field of \a this is lying on \a mesh.
4787  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4788  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4789  */
4790 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4791 {
4792   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
4793   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4794   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4795   if(meshDimRelToMax==1)
4796     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4797   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4798 }
4799
4800 /*!
4801  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4802  * given mesh. 
4803  *  \param [in] type - a spatial discretization of the new field.
4804  *  \param [in] mName - a name of the supporting mesh.
4805  *  \param [in] renumPol - specifies how to permute values of the result field according to
4806  *          the optional numbers of cells and nodes, if any. The valid values are
4807  *          - 0 - do not permute.
4808  *          - 1 - permute cells.
4809  *          - 2 - permute nodes.
4810  *          - 3 - permute cells and nodes.
4811  *
4812  *  \param [in] glob - the global data storing profiles and localization.
4813  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4814  *          caller is to delete this field using decrRef() as it is no more needed. 
4815  *  \throw If the MED file is not readable.
4816  *  \throw If there is no mesh named \a mName in the MED file.
4817  *  \throw If there are no mesh entities in the mesh.
4818  *  \throw If no field values of the given \a type are available.
4819  */
4820 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4821 {
4822   MCAuto<MEDFileMesh> mm;
4823   if(mName.empty())
4824     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4825   else
4826     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4827   int absDim=getDimension();
4828   int meshDimRelToMax=absDim-mm->getMeshDimension();
4829   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4830 }
4831
4832 /*!
4833  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4834  *  \param [in] type - a spatial discretization of the new field.
4835  *  \param [in] renumPol - specifies how to permute values of the result field according to
4836  *          the optional numbers of cells and nodes, if any. The valid values are
4837  *          - 0 - do not permute.
4838  *          - 1 - permute cells.
4839  *          - 2 - permute nodes.
4840  *          - 3 - permute cells and nodes.
4841  *
4842  *  \param [in] glob - the global data storing profiles and localization.
4843  *  \param [in] mesh - the supporting mesh.
4844  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4845  *         field according to \a renumPol.
4846  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4847  *         field according to \a renumPol.
4848  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4849  *          caller is to delete this field using decrRef() as it is no more needed. 
4850  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4851  *  \throw If no field of \a this is lying on \a mesh.
4852  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4853  */
4854 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
4855 {
4856   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4857   int meshId=getMeshIdFromMeshName(mesh->getName());
4858   bool isPfl=false;
4859   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4860   switch(renumPol)
4861   {
4862     case 0:
4863       {
4864         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4865         return ret.retn();
4866       }
4867     case 3:
4868     case 1:
4869       {
4870         if(isPfl)
4871           throw INTERP_KERNEL::Exception(msg1);
4872         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4873         if(cellRenum)
4874           {
4875             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4876               {
4877                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4878                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4879                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4880               }
4881             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4882             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4883             std::vector<DataArray *> arrOut2(1,arrOut);
4884             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4885             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4886             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4887           }
4888         if(renumPol==1)
4889           return ret.retn();
4890       }
4891     case 2:
4892       {
4893         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4894         if(isPfl)
4895           throw INTERP_KERNEL::Exception(msg1);
4896         if(nodeRenum)
4897           {
4898             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4899               {
4900                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4901                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4902                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4903               }
4904             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4905             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4906               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4907             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4908           }
4909         return ret.retn();
4910       }
4911     default:
4912       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4913   }
4914 }
4915
4916 /*!
4917  * Returns values and a profile of the field of a given type lying on a given support.
4918  *  \param [in] type - a spatial discretization of the field.
4919  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4920  *  \param [in] mesh - the supporting mesh.
4921  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4922  *          field of interest lies on. If the field lies on all entities of the given
4923  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4924  *          using decrRef() as it is no more needed.  
4925  *  \param [in] glob - the global data storing profiles and localization.
4926  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4927  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4928  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4929  *  \throw If no field of \a this is lying on \a mesh.
4930  *  \throw If no field values of the given \a type are available.
4931  */
4932 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4933 {
4934   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4935   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4936   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4937   ret->setName(nasc.getName().c_str());
4938   return ret.retn();
4939 }
4940
4941 //= MEDFileField1TSWithoutSDA
4942
4943 /*!
4944  * Throws if a given value is not a valid (non-extended) relative dimension.
4945  *  \param [in] meshDimRelToMax - the relative dimension value.
4946  *  \throw If \a meshDimRelToMax > 0.
4947  */
4948 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4949 {
4950   if(meshDimRelToMax>0)
4951     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4952 }
4953
4954 /*!
4955  * Checks if elements of a given mesh are in the order suitable for writing 
4956  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4957  * vector describing types of elements and their number.
4958  *  \param [in] mesh - the mesh to check.
4959  *  \return std::vector<int> - a vector holding for each element type (1) item of
4960  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4961  *          These values are in full-interlace mode.
4962  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4963  */
4964 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4965 {
4966   if(!mesh)
4967     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4968   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4969   int nbOfTypes=geoTypes.size();
4970   std::vector<int> code(3*nbOfTypes);
4971   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
4972   arr1->alloc(nbOfTypes,1);
4973   int *arrPtr=arr1->getPointer();
4974   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4975   for(int i=0;i<nbOfTypes;i++,it++)
4976     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4977   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4978   const int *arrPtr2=arr2->getConstPointer();
4979   int i=0;
4980   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4981     {
4982       int pos=arrPtr2[i];
4983       int nbCells=mesh->getNumberOfCellsWithType(*it);
4984       code[3*pos]=(int)(*it);
4985       code[3*pos+1]=nbCells;
4986       code[3*pos+2]=-1;//no profiles
4987     }
4988   std::vector<const DataArrayInt *> idsPerType;//no profiles
4989   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4990   if(da)
4991     {
4992       da->decrRef();
4993       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4994     }
4995   return code;
4996 }
4997
4998 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4999 {
5000   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5001 }
5002
5003 /*!
5004  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5005  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5006  * item of every of returned sequences refers to the _i_-th part of \a this field.
5007  * Thus all sequences returned by this method are of the same length equal to number
5008  * of different types of supporting entities.<br>
5009  * A field part can include sub-parts with several different spatial discretizations,
5010  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5011  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5012  * of a nested sequence corresponds to a type of spatial discretization.<br>
5013  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5014  * The overhead is due to selecting values into new instances of DataArrayDouble.
5015  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5016  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5017  *          not checked if \a mname == \c NULL).
5018  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5019  *          a field part is returned. 
5020  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5021  *          A field part can include sub-parts with several different spatial discretizations,
5022  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5023  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5024  *          This sequence is of the same length as \a types. 
5025  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5026  *          discretization. A profile name can be empty.
5027  *          Length of this and of nested sequences is the same as that of \a typesF.
5028  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5029  *          discretization. A localization name can be empty.
5030  *          Length of this and of nested sequences is the same as that of \a typesF.
5031  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5032  *          per each type of spatial discretization within one mesh entity type.
5033  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5034  *          Length of this and of nested sequences is the same as that of \a typesF.
5035  *  \throw If no field is lying on \a mname.
5036  */
5037 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
5038 {
5039   int meshId=0;
5040   if(!mname.empty())
5041     meshId=getMeshIdFromMeshName(mname);
5042   else
5043     if(_field_per_mesh.empty())
5044       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5045   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5046   int nbOfRet=ret0.size();
5047   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5048   for(int i=0;i<nbOfRet;i++)
5049     {
5050       const std::vector< std::pair<int,int> >& p=ret0[i];
5051       int nbOfRet1=p.size();
5052       ret[i].resize(nbOfRet1);
5053       for(int j=0;j<nbOfRet1;j++)
5054         {
5055           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5056           ret[i][j]=tmp;
5057         }
5058     }
5059   return ret;
5060 }
5061
5062 /*!
5063  * Returns a pointer to the underground DataArrayDouble instance. So the
5064  * caller should not decrRef() it. This method allows for a direct access to the field
5065  * values. This method is quite unusable if there is more than a nodal field or a cell
5066  * field on single geometric cell type. 
5067  *  \return DataArrayDouble * - the pointer to the field values array.
5068  */
5069 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
5070 {
5071   const DataArrayDouble *ret=_arr;
5072   if(ret)
5073     return const_cast<DataArrayDouble *>(ret);
5074   else
5075     return 0;
5076 }
5077
5078 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5079 {
5080   return TYPE_STR;
5081 }
5082
5083 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5084 {
5085   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5086   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5087   ret->deepCpyLeavesFrom(*this);
5088   const DataArrayDouble *arr(_arr);
5089   if(arr)
5090     {
5091       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5092       ret->setArray(arr2);
5093     }
5094   return ret.retn();
5095 }
5096
5097 /*!
5098  * Returns a pointer to the underground DataArrayDouble instance. So the
5099  * caller should not decrRef() it. This method allows for a direct access to the field
5100  * values. This method is quite unusable if there is more than a nodal field or a cell
5101  * field on single geometric cell type. 
5102  *  \return DataArrayDouble * - the pointer to the field values array.
5103  */
5104 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
5105 {
5106   return getUndergroundDataArrayDouble();
5107 }
5108
5109 /*!
5110  * Returns a pointer to the underground DataArrayDouble instance and a
5111  * sequence describing parameters of a support of each part of \a this field. The
5112  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5113  * direct access to the field values. This method is intended for the field lying on one
5114  * mesh only.
5115  *  \param [in,out] entries - the sequence describing parameters of a support of each
5116  *         part of \a this field. Each item of this sequence consists of two parts. The
5117  *         first part describes a type of mesh entity and an id of discretization of a
5118  *         current field part. The second part describes a range of values [begin,end)
5119  *         within the returned array relating to the current field part.
5120  *  \return DataArrayDouble * - the pointer to the field values array.
5121  *  \throw If the number of underlying meshes is not equal to 1.
5122  *  \throw If no field values are available.
5123  *  \sa getUndergroundDataArray()
5124  */
5125 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5126 {
5127   if(_field_per_mesh.size()!=1)
5128     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5129   if(_field_per_mesh[0]==0)
5130     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5131   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5132   return getUndergroundDataArrayDouble();
5133 }
5134
5135 /*!
5136  * Returns a pointer to the underground DataArrayDouble instance and a
5137  * sequence describing parameters of a support of each part of \a this field. The
5138  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5139  * direct access to the field values. This method is intended for the field lying on one
5140  * mesh only.
5141  *  \param [in,out] entries - the sequence describing parameters of a support of each
5142  *         part of \a this field. Each item of this sequence consists of two parts. The
5143  *         first part describes a type of mesh entity and an id of discretization of a
5144  *         current field part. The second part describes a range of values [begin,end)
5145  *         within the returned array relating to the current field part.
5146  *  \return DataArrayDouble * - the pointer to the field values array.
5147  *  \throw If the number of underlying meshes is not equal to 1.
5148  *  \throw If no field values are available.
5149  *  \sa getUndergroundDataArray()
5150  */
5151 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5152 {
5153   return getUndergroundDataArrayDoubleExt(entries);
5154 }
5155
5156 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5157 {
5158   DataArrayDouble *arr(getOrCreateAndGetArrayDouble());
5159   arr->setInfoAndChangeNbOfCompo(infos);
5160 }
5161
5162 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5163 {
5164 }
5165
5166 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5167 {
5168   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5169   ret->deepCpyLeavesFrom(*this);
5170   return ret.retn();
5171 }
5172
5173 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5174 {
5175   MCAuto<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5176   if((const DataArrayDouble *)_arr)
5177     ret->_arr=_arr->deepCopy();
5178   return ret.retn();
5179 }
5180
5181 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
5182 {
5183   if(!arr)
5184     {
5185       _nb_of_tuples_to_be_allocated=-1;
5186       _arr=0;
5187       return ;
5188     }
5189   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
5190   if(!arrC)
5191     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
5192   else
5193     _nb_of_tuples_to_be_allocated=-3;
5194   arrC->incrRef();
5195   _arr=arrC;
5196 }
5197
5198 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5199 {
5200   return DataArrayDouble::New();
5201 }
5202
5203 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
5204 {
5205   DataArrayDouble *ret=_arr;
5206   if(ret)
5207     return ret;
5208   _arr=DataArrayDouble::New();
5209   return _arr;
5210 }
5211
5212 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
5213 {
5214   return getOrCreateAndGetArrayDouble();
5215 }
5216
5217 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
5218 {
5219   const DataArrayDouble *ret=_arr;
5220   if(ret)
5221     return ret;
5222   DataArrayDouble *ret2=DataArrayDouble::New();
5223   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
5224   return ret2;
5225 }
5226
5227 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
5228 {
5229   return getOrCreateAndGetArrayDouble();
5230 }
5231
5232 //= MEDFileIntField1TSWithoutSDA
5233
5234 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5235 {
5236   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5237 }
5238
5239 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5240 {
5241 }
5242
5243 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5244                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5245 {
5246   DataArrayInt *arr(getOrCreateAndGetArrayInt());
5247   arr->setInfoAndChangeNbOfCompo(infos);
5248 }
5249
5250 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5251 {
5252   return TYPE_STR;
5253 }
5254
5255 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5256 {
5257   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5258   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5259   ret->deepCpyLeavesFrom(*this);
5260   const DataArrayInt *arr(_arr);
5261   if(arr)
5262     {
5263       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5264       ret->setArray(arr2);
5265     }
5266   return ret.retn();
5267 }
5268
5269 /*!
5270  * Returns a pointer to the underground DataArrayInt instance. So the
5271  * caller should not decrRef() it. This method allows for a direct access to the field
5272  * values. This method is quite unusable if there is more than a nodal field or a cell
5273  * field on single geometric cell type. 
5274  *  \return DataArrayInt * - the pointer to the field values array.
5275  */
5276 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
5277 {
5278   return getUndergroundDataArrayInt();
5279 }
5280
5281 /*!
5282  * Returns a pointer to the underground DataArrayInt instance. So the
5283  * caller should not decrRef() it. This method allows for a direct access to the field
5284  * values. This method is quite unusable if there is more than a nodal field or a cell
5285  * field on single geometric cell type. 
5286  *  \return DataArrayInt * - the pointer to the field values array.
5287  */
5288 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5289 {
5290   const DataArrayInt *ret=_arr;
5291   if(ret)
5292     return const_cast<DataArrayInt *>(ret);
5293   else
5294     return 0;
5295 }
5296
5297 /*!
5298  * Returns a pointer to the underground DataArrayInt instance and a
5299  * sequence describing parameters of a support of each part of \a this field. The
5300  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5301  * direct access to the field values. This method is intended for the field lying on one
5302  * mesh only.
5303  *  \param [in,out] entries - the sequence describing parameters of a support of each
5304  *         part of \a this field. Each item of this sequence consists of two parts. The
5305  *         first part describes a type of mesh entity and an id of discretization of a
5306  *         current field part. The second part describes a range of values [begin,end)
5307  *         within the returned array relating to the current field part.
5308  *  \return DataArrayInt * - the pointer to the field values array.
5309  *  \throw If the number of underlying meshes is not equal to 1.
5310  *  \throw If no field values are available.
5311  *  \sa getUndergroundDataArray()
5312  */
5313 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5314 {
5315   return getUndergroundDataArrayIntExt(entries);
5316 }
5317
5318 /*!
5319  * Returns a pointer to the underground DataArrayInt instance and a
5320  * sequence describing parameters of a support of each part of \a this field. The
5321  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5322  * direct access to the field values. This method is intended for the field lying on one
5323  * mesh only.
5324  *  \param [in,out] entries - the sequence describing parameters of a support of each
5325  *         part of \a this field. Each item of this sequence consists of two parts. The
5326  *         first part describes a type of mesh entity and an id of discretization of a
5327  *         current field part. The second part describes a range of values [begin,end)
5328  *         within the returned array relating to the current field part.
5329  *  \return DataArrayInt * - the pointer to the field values array.
5330  *  \throw If the number of underlying meshes is not equal to 1.
5331  *  \throw If no field values are available.
5332  *  \sa getUndergroundDataArray()
5333  */
5334 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5335 {
5336   if(_field_per_mesh.size()!=1)
5337     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5338   if(_field_per_mesh[0]==0)
5339     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5340   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5341   return getUndergroundDataArrayInt();
5342 }
5343
5344 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5345 {
5346   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5347   ret->deepCpyLeavesFrom(*this);
5348   return ret.retn();
5349 }
5350
5351 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5352 {
5353   MCAuto<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5354   if((const DataArrayInt *)_arr)
5355     ret->_arr=_arr->deepCopy();
5356   return ret.retn();
5357 }
5358
5359 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5360 {
5361   if(!arr)
5362     {
5363       _nb_of_tuples_to_be_allocated=-1;
5364       _arr=0;
5365       return ;
5366     }
5367   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5368   if(!arrC)
5369     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5370   else
5371     _nb_of_tuples_to_be_allocated=-3;
5372   arrC->incrRef();
5373   _arr=arrC;
5374 }
5375
5376 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5377 {
5378   return DataArrayInt::New();
5379 }
5380
5381 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5382 {
5383   DataArrayInt *ret=_arr;
5384   if(ret)
5385     return ret;
5386   _arr=DataArrayInt::New();
5387   return _arr;
5388 }
5389
5390 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5391 {
5392   return getOrCreateAndGetArrayInt();
5393 }
5394
5395 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5396 {
5397   const DataArrayInt *ret=_arr;
5398   if(ret)
5399     return ret;
5400   DataArrayInt *ret2=DataArrayInt::New();
5401   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5402   return ret2;
5403 }
5404
5405 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5406 {
5407   return getOrCreateAndGetArrayInt();
5408 }
5409
5410 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5411 {
5412 }
5413
5414 //= MEDFileAnyTypeField1TS
5415
5416 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5417 {
5418   med_field_type typcha;
5419   //
5420   std::vector<std::string> infos;
5421   std::string dtunit,fieldName;
5422   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5423   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5424   switch(typcha)
5425   {
5426     case MED_FLOAT64:
5427       {
5428         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5429         break;
5430       }
5431     case MED_INT32:
5432       {
5433         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5434         break;
5435       }
5436     default:
5437       {
5438         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
5439         throw INTERP_KERNEL::Exception(oss.str().c_str());
5440       }
5441   }
5442   ret->setDtUnit(dtunit.c_str());
5443   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5444   //
5445   med_int numdt,numit;
5446   med_float dt;
5447   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5448   ret->setTime(numdt,numit,dt);
5449   ret->_csit=1;
5450   if(loadAll)
5451     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5452   else
5453     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5454   return ret.retn();
5455 }
5456
5457 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5458 try:MEDFileFieldGlobsReal(fileName)
5459 {
5460   MEDFileUtilities::CheckFileForRead(fileName);
5461   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5462   _content=BuildContentFrom(fid,fileName,loadAll,ms);
5463   loadGlobals(fid);
5464 }
5465 catch(INTERP_KERNEL::Exception& e)
5466 {
5467     throw e;
5468 }
5469
5470 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5471 {
5472   med_field_type typcha;
5473   std::vector<std::string> infos;
5474   std::string dtunit;
5475   int iii=-1;
5476   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5477   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5478   switch(typcha)
5479   {
5480     case MED_FLOAT64:
5481       {
5482         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5483         break;
5484       }
5485     case MED_INT32:
5486       {
5487         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5488         break;
5489       }
5490     default:
5491       {
5492         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5493         throw INTERP_KERNEL::Exception(oss.str().c_str());
5494       }
5495   }
5496   ret->setDtUnit(dtunit.c_str());
5497   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5498   //
5499   if(nbSteps<1)
5500     {
5501       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5502       throw INTERP_KERNEL::Exception(oss.str().c_str());
5503     }
5504   //
5505   med_int numdt,numit;
5506   med_float dt;
5507   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5508   ret->setTime(numdt,numit,dt);
5509   ret->_csit=1;
5510   if(loadAll)
5511     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5512   else
5513     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5514   return ret.retn();
5515 }
5516
5517 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5518 try:MEDFileFieldGlobsReal(fileName)
5519 {
5520   MEDFileUtilities::CheckFileForRead(fileName);
5521   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5522   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
5523   loadGlobals(fid);
5524 }
5525 catch(INTERP_KERNEL::Exception& e)
5526 {
5527     throw e;
5528 }
5529
5530 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5531 {
5532   if(!c)
5533     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5534   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5535     {
5536       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New();
5537       ret->setFileName(fileName);
5538       ret->_content=c; c->incrRef();
5539       return ret.retn();
5540     }
5541   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5542     {
5543       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5544       ret->setFileName(fileName);
5545       ret->_content=c; c->incrRef();
5546       return ret.retn();
5547     }
5548   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5549 }
5550
5551 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5552 {
5553   MEDFileUtilities::CheckFileForRead(fileName);
5554   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5555   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
5556   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5557   ret->loadGlobals(fid);
5558   return ret.retn();
5559 }
5560
5561 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5562 {
5563   MEDFileUtilities::CheckFileForRead(fileName);
5564   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5565   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
5566   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5567   ret->loadGlobals(fid);
5568   return ret.retn();
5569 }
5570
5571 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5572 {
5573   MEDFileUtilities::CheckFileForRead(fileName);
5574   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5575   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll,0);
5576   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5577   ret->loadGlobals(fid);
5578   return ret.retn();
5579 }
5580
5581 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5582 {
5583   med_field_type typcha;
5584   std::vector<std::string> infos;
5585   std::string dtunit;
5586   int iii=-1;
5587   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5588   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5589   switch(typcha)
5590   {
5591     case MED_FLOAT64:
5592       {
5593         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5594         break;
5595       }
5596     case MED_INT32:
5597       {
5598         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5599         break;
5600       }
5601     default:
5602       {
5603         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName,iteration,order) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5604         throw INTERP_KERNEL::Exception(oss.str().c_str());
5605       }
5606   }
5607   ret->setDtUnit(dtunit.c_str());
5608   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5609   //
5610   bool found=false;
5611   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5612   for(int i=0;i<nbOfStep2 && !found;i++)
5613     {
5614       med_int numdt,numit;
5615       med_float dt;
5616       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5617       if(numdt==iteration && numit==order)
5618         {
5619           found=true;
5620           ret->_csit=i+1;
5621         }
5622       else
5623         dtits[i]=std::pair<int,int>(numdt,numit);
5624     }
5625   if(!found)
5626     {
5627       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5628       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5629         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5630       throw INTERP_KERNEL::Exception(oss.str().c_str());
5631     }
5632   if(loadAll)
5633     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5634   else
5635     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5636   return ret.retn();
5637 }
5638
5639 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5640 try:MEDFileFieldGlobsReal(fileName)
5641 {
5642   MEDFileUtilities::CheckFileForRead(fileName);
5643   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5644   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll,ms);
5645   loadGlobals(fid);
5646 }
5647 catch(INTERP_KERNEL::Exception& e)
5648 {
5649     throw e;
5650 }
5651
5652 /*!
5653  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5654  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5655  *
5656  * \warning this is a shallow copy constructor
5657  */
5658 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5659 {
5660   if(!shallowCopyOfContent)
5661     {
5662       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5663       otherPtr->incrRef();
5664       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5665     }
5666   else
5667     {
5668       _content=other.shallowCpy();
5669     }
5670 }
5671
5672 int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, const std::string& fileName, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5673 {
5674   if(checkFieldId)
5675     {
5676       int nbFields=MEDnField(fid);
5677       if(fieldIdCFormat>=nbFields)
5678         {
5679           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5680           throw INTERP_KERNEL::Exception(oss.str().c_str());
5681         }
5682     }
5683   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5684   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5685   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5686   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5687   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5688   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5689   med_bool localMesh;
5690   int nbOfStep;
5691   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5692   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5693   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5694   infos.clear(); infos.resize(ncomp);
5695   for(int j=0;j<ncomp;j++)
5696     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5697   return nbOfStep;
5698 }
5699
5700 /*!
5701  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5702  * 
5703  * \param [out]
5704  * \return in case of success the number of time steps available for the field with name \a fieldName.
5705  */
5706 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fileName, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5707 {
5708   int nbFields=MEDnField(fid);
5709   bool found=false;
5710   std::vector<std::string> fns(nbFields);
5711   int nbOfStep2=-1;
5712   for(int i=0;i<nbFields && !found;i++)
5713     {
5714       std::string tmp;
5715       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5716       fns[i]=tmp;
5717       found=(tmp==fieldName);
5718       if(found)
5719         posCFormat=i;
5720     }
5721   if(!found)
5722     {
5723       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5724       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5725         oss << "\"" << *it << "\" ";
5726       throw INTERP_KERNEL::Exception(oss.str().c_str());
5727     }
5728   return nbOfStep2;
5729 }
5730
5731 /*!
5732  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5733  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5734  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5735  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5736  * to keep a valid instance.
5737  * 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.
5738  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5739  * 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.
5740  *
5741  * \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.
5742  * \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.
5743  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5744  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5745  * \param [in] newLocName is the new localization name.
5746  * \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.
5747  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5748  */
5749 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5750 {
5751   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5752   std::string oldPflName=disc->getProfile();
5753   std::vector<std::string> vv=getPflsReallyUsedMulti();
5754   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5755   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5756     {
5757       disc->setProfile(newPflName);
5758       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5759       pfl->setName(newPflName);
5760     }
5761   else
5762     {
5763       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5764       throw INTERP_KERNEL::Exception(oss.str().c_str());
5765     }
5766 }
5767
5768 /*!
5769  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5770  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5771  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5772  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5773  * to keep a valid instance.
5774  * 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.
5775  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5776  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5777  * 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.
5778  *
5779  * \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.
5780  * \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.
5781  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5782  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5783  * \param [in] newLocName is the new localization name.
5784  * \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.
5785  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5786  */
5787 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5788 {
5789   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5790   std::string oldLocName=disc->getLocalization();
5791   std::vector<std::string> vv=getLocsReallyUsedMulti();
5792   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5793   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5794     {
5795       disc->setLocalization(newLocName);
5796       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5797       loc.setName(newLocName);
5798     }
5799   else
5800     {
5801       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5802       throw INTERP_KERNEL::Exception(oss.str().c_str());
5803     }
5804 }
5805
5806 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5807 {
5808   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5809   if(!ret)
5810     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5811   return ret;
5812 }
5813
5814 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5815 {
5816   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5817   if(!ret)
5818     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5819   return ret;
5820 }
5821
5822 /*!
5823  * Writes \a this field into a MED file specified by its name.
5824  *  \param [in] fileName - the MED file name.
5825  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5826  * - 2 - erase; an existing file is removed.
5827  * - 1 - append; same data should not be present in an existing file.
5828  * - 0 - overwrite; same data present in an existing file is overwritten.
5829  *  \throw If the field name is not set.
5830  *  \throw If no field data is set.
5831  *  \throw If \a mode == 1 and the same data is present in an existing file.
5832  */
5833 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5834 {
5835   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5836   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5837   writeLL(fid);
5838 }
5839
5840 /*!
5841  * This method alloc the arrays and load potentially huge arrays contained in this field.
5842  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5843  * This method can be also called to refresh or reinit values from a file.
5844  * 
5845  * \throw If the fileName is not set or points to a non readable MED file.
5846  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5847  */
5848 void MEDFileAnyTypeField1TS::loadArrays()
5849 {
5850   if(getFileName().empty())
5851     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5852   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5853   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5854 }
5855
5856 /*!
5857  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5858  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5859  * this method does not throw if \a this does not come from file read.
5860  * 
5861  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5862  */
5863 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5864 {
5865   if(!getFileName().empty())
5866     {
5867       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5868       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5869     }
5870 }
5871
5872 /*!
5873  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5874  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5875  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5876  * 
5877  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5878  */
5879 void MEDFileAnyTypeField1TS::unloadArrays()
5880 {
5881   contentNotNullBase()->unloadArrays();
5882 }
5883
5884 /*!
5885  * 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.
5886  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5887  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5888  * 
5889  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5890  */
5891 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5892 {
5893   if(!getFileName().empty())
5894     contentNotNullBase()->unloadArrays();
5895 }
5896
5897 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5898 {
5899   int nbComp=getNumberOfComponents();
5900   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5901   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5902   for(int i=0;i<nbComp;i++)
5903     {
5904       std::string info=getInfo()[i];
5905       std::string c,u;
5906       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5907       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5908       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5909     }
5910   if(getName().empty())
5911     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5912   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
5913   writeGlobals(fid,*this);
5914   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5915 }
5916
5917 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5918 {
5919   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5920 }
5921
5922 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5923 {
5924   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5925   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5926   return ret;
5927 }
5928
5929 /*!
5930  * Returns a string describing \a this field. This string is outputted 
5931  * by \c print Python command.
5932  */
5933 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5934 {
5935   std::ostringstream oss;
5936   contentNotNullBase()->simpleRepr(0,oss,-1);
5937   simpleReprGlobs(oss);
5938   return oss.str();
5939 }
5940
5941 /*!
5942  * This method returns all profiles whose name is non empty used.
5943  * \b WARNING If profile is used several times it will be reported \b only \b once.
5944  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5945  */
5946 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5947 {
5948   return contentNotNullBase()->getPflsReallyUsed2();
5949 }
5950
5951 /*!
5952  * This method returns all localizations whose name is non empty used.
5953  * \b WARNING If localization is used several times it will be reported \b only \b once.
5954  */
5955 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5956 {
5957   return contentNotNullBase()->getLocsReallyUsed2();
5958 }
5959
5960 /*!
5961  * This method returns all profiles whose name is non empty used.
5962  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5963  */
5964 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5965 {
5966   return contentNotNullBase()->getPflsReallyUsedMulti2();
5967 }
5968
5969 /*!
5970  * This method returns all localizations whose name is non empty used.
5971  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5972  */
5973 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5974 {
5975   return contentNotNullBase()->getLocsReallyUsedMulti2();
5976 }
5977
5978 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5979 {
5980   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5981 }
5982
5983 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5984 {
5985   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5986 }
5987
5988 int MEDFileAnyTypeField1TS::getDimension() const
5989 {
5990   return contentNotNullBase()->getDimension();
5991 }
5992
5993 int MEDFileAnyTypeField1TS::getIteration() const
5994 {
5995   return contentNotNullBase()->getIteration();
5996 }
5997
5998 int MEDFileAnyTypeField1TS::getOrder() const
5999 {
6000   return contentNotNullBase()->getOrder();
6001 }
6002
6003 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6004 {
6005   return contentNotNullBase()->getTime(iteration,order);
6006 }
6007
6008 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6009 {
6010   contentNotNullBase()->setTime(iteration,order,val);
6011 }
6012
6013 std::string MEDFileAnyTypeField1TS::getName() const
6014 {
6015   return contentNotNullBase()->getName();
6016 }
6017
6018 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6019 {
6020   contentNotNullBase()->setName(name);
6021 }
6022
6023 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6024 {
6025   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6026 }
6027
6028 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6029 {
6030   return contentNotNullBase()->getDtUnit();
6031 }
6032
6033 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6034 {
6035   contentNotNullBase()->setDtUnit(dtUnit);
6036 }
6037
6038 std::string MEDFileAnyTypeField1TS::getMeshName() const
6039 {
6040   return contentNotNullBase()->getMeshName();
6041 }
6042
6043 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6044 {
6045   contentNotNullBase()->setMeshName(newMeshName);
6046 }
6047
6048 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6049 {
6050   return contentNotNullBase()->changeMeshNames(modifTab);
6051 }
6052
6053 int MEDFileAnyTypeField1TS::getMeshIteration() const
6054 {
6055   return contentNotNullBase()->getMeshIteration();
6056 }
6057
6058 int MEDFileAnyTypeField1TS::getMeshOrder() const
6059 {
6060   return contentNotNullBase()->getMeshOrder();
6061 }
6062
6063 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6064 {
6065   return contentNotNullBase()->getNumberOfComponents();
6066 }
6067
6068 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6069 {
6070   return contentNotNullBase()->isDealingTS(iteration,order);
6071 }
6072
6073 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6074 {
6075   return contentNotNullBase()->getDtIt();
6076 }
6077
6078 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6079 {
6080   contentNotNullBase()->fillIteration(p);
6081 }
6082
6083 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6084 {
6085   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6086 }
6087
6088 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6089 {
6090   contentNotNullBase()->setInfo(infos);
6091 }
6092
6093 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6094 {
6095   return contentNotNullBase()->getInfo();
6096 }
6097 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6098 {
6099   return contentNotNullBase()->getInfo();
6100 }
6101
6102 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6103 {
6104   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6105 }
6106
6107 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6108 {
6109   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6110 }
6111
6112 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6113 {
6114   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6115 }
6116
6117 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6118 {
6119   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6120 }
6121
6122 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6123 {
6124   return contentNotNullBase()->getTypesOfFieldAvailable();
6125 }
6126
6127 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,
6128                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6129 {
6130   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6131 }
6132
6133 /*!
6134  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6135  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6136  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6137  */
6138 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6139 {
6140   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6141   if(!content)
6142     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6143   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6144   std::size_t sz(contentsSplit.size());
6145   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6146   for(std::size_t i=0;i<sz;i++)
6147     {
6148       ret[i]=shallowCpy();
6149       ret[i]->_content=contentsSplit[i];
6150     }
6151   return ret;
6152 }
6153
6154 /*!
6155  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6156  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6157  */
6158 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6159 {
6160   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6161   if(!content)
6162     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6163   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6164   std::size_t sz(contentsSplit.size());
6165   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6166   for(std::size_t i=0;i<sz;i++)
6167     {
6168       ret[i]=shallowCpy();
6169       ret[i]->_content=contentsSplit[i];
6170     }
6171   return ret;
6172 }
6173
6174 /*!
6175  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6176  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6177  */
6178 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6179 {
6180   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6181   if(!content)
6182     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6183   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6184   std::size_t sz(contentsSplit.size());
6185   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6186   for(std::size_t i=0;i<sz;i++)
6187     {
6188       ret[i]=shallowCpy();
6189       ret[i]->_content=contentsSplit[i];
6190     }
6191   return ret;
6192 }
6193
6194 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6195 {
6196   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6197   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6198     ret->_content=_content->deepCopy();
6199   ret->deepCpyGlobs(*this);
6200   return ret.retn();
6201 }
6202
6203 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6204 {
6205   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6206 }
6207
6208 //= MEDFileField1TS
6209
6210 /*!
6211  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6212  * the first field that has been read from a specified MED file.
6213  *  \param [in] fileName - the name of the MED file to read.
6214  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6215  *          is to delete this field using decrRef() as it is no more needed.
6216  *  \throw If reading the file fails.
6217  */
6218 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6219 {
6220   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,loadAll,0));
6221   ret->contentNotNull();
6222   return ret.retn();
6223 }
6224
6225 /*!
6226  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6227  * a given field that has been read from a specified MED file.
6228  *  \param [in] fileName - the name of the MED file to read.
6229  *  \param [in] fieldName - the name of the field to read.
6230  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6231  *          is to delete this field using decrRef() as it is no more needed.
6232  *  \throw If reading the file fails.
6233  *  \throw If there is no field named \a fieldName in the file.
6234  */
6235 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6236 {
6237   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,loadAll,0));
6238   ret->contentNotNull();
6239   return ret.retn();
6240 }
6241
6242 /*!
6243  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6244  * a given field that has been read from a specified MED file.
6245  *  \param [in] fileName - the name of the MED file to read.
6246  *  \param [in] fieldName - the name of the field to read.
6247  *  \param [in] iteration - the iteration number of a required time step.
6248  *  \param [in] order - the iteration order number of required time step.
6249  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6250  *          is to delete this field using decrRef() as it is no more needed.
6251  *  \throw If reading the file fails.
6252  *  \throw If there is no field named \a fieldName in the file.
6253  *  \throw If the required time step is missing from the file.
6254  */
6255 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6256 {
6257   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll,0));
6258   ret->contentNotNull();
6259   return ret.retn();
6260 }
6261
6262 /*!
6263  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6264  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6265  *
6266  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6267  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6268  * \warning this is a shallow copy constructor
6269  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6270  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6271  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6272  *          is to delete this field using decrRef() as it is no more needed.
6273  */
6274 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6275 {
6276   MCAuto<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
6277   ret->contentNotNull();
6278   return ret.retn();
6279 }
6280
6281 /*!
6282  * Returns a new empty instance of MEDFileField1TS.
6283  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6284  *          is to delete this field using decrRef() as it is no more needed.
6285  */
6286 MEDFileField1TS *MEDFileField1TS::New()
6287 {
6288   MCAuto<MEDFileField1TS> ret=new MEDFileField1TS;
6289   ret->contentNotNull();
6290   return ret.retn();
6291 }
6292
6293 /*!
6294  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6295  * following the given input policy.
6296  *
6297  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6298  *                            By default (true) the globals are deeply copied.
6299  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6300  */
6301 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6302 {
6303   MCAuto<MEDFileIntField1TS> ret;
6304   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6305   if(content)
6306     {
6307       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6308       if(!contc)
6309         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6310       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6311       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6312     }
6313   else
6314     ret=MEDFileIntField1TS::New();
6315   if(isDeepCpyGlobs)
6316     ret->deepCpyGlobs(*this);
6317   else
6318     ret->shallowCpyGlobs(*this);
6319   return ret.retn();
6320 }
6321
6322 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6323 {
6324   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6325   if(!pt)
6326     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6327   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6328   if(!ret)
6329     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 !");
6330   return ret;
6331 }
6332
6333 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6334 {
6335   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6336   if(!pt)
6337     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6338   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6339   if(!ret)
6340     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 !");
6341   return ret;
6342 }
6343
6344 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6345 {
6346   if(!f)
6347     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6348   if(!((DataArray*)arr))
6349     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6350   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6351   if(!arrOutC)
6352     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6353   f->setArray(arrOutC);
6354 }
6355
6356 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6357 {
6358   if(!((DataArray*)arr))
6359     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6360   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6361   if(!arrOutC)
6362     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6363   arrOutC->incrRef();
6364   return arrOutC;
6365 }
6366
6367 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6368 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6369 {
6370 }
6371 catch(INTERP_KERNEL::Exception& e)
6372 { throw e; }
6373
6374 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6375 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6376 {
6377 }
6378 catch(INTERP_KERNEL::Exception& e)
6379 { throw e; }
6380
6381 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6382 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6383 {
6384 }
6385 catch(INTERP_KERNEL::Exception& e)
6386 { throw e; }
6387
6388 /*!
6389  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6390  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6391  *
6392  * \warning this is a shallow copy constructor
6393  */
6394 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6395 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6396 {
6397 }
6398 catch(INTERP_KERNEL::Exception& e)
6399 { throw e; }
6400
6401 MEDFileField1TS::MEDFileField1TS()
6402 {
6403   _content=new MEDFileField1TSWithoutSDA;
6404 }
6405
6406 /*!
6407  * Returns a new MEDCouplingFieldDouble of a given type lying on
6408  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6409  * has not been constructed via file reading, an exception is thrown.
6410  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6411  *  \param [in] type - a spatial discretization of interest.
6412  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6413  *  \param [in] renumPol - specifies how to permute values of the result field according to
6414  *          the optional numbers of cells and nodes, if any. The valid values are
6415  *          - 0 - do not permute.
6416  *          - 1 - permute cells.
6417  *          - 2 - permute nodes.
6418  *          - 3 - permute cells and nodes.
6419  *
6420  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6421  *          caller is to delete this field using decrRef() as it is no more needed. 
6422  *  \throw If \a this field has not been constructed via file reading.
6423  *  \throw If the MED file is not readable.
6424  *  \throw If there is no mesh in the MED file.
6425  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6426  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6427  *  \sa getFieldOnMeshAtLevel()
6428  */
6429 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6430 {
6431   if(getFileName().empty())
6432     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6433   MCAuto<DataArray> arrOut;
6434   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6435   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6436   return ret.retn();
6437 }
6438
6439 /*!
6440  * Returns a new MEDCouplingFieldDouble of a given type lying on
6441  * the top level cells of the first mesh in MED file. If \a this field 
6442  * has not been constructed via file reading, an exception is thrown.
6443  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6444  *  \param [in] type - a spatial discretization of interest.
6445  *  \param [in] renumPol - specifies how to permute values of the result field according to
6446  *          the optional numbers of cells and nodes, if any. The valid values are
6447  *          - 0 - do not permute.
6448  *          - 1 - permute cells.
6449  *          - 2 - permute nodes.
6450  *          - 3 - permute cells and nodes.
6451  *
6452  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6453  *          caller is to delete this field using decrRef() as it is no more needed. 
6454  *  \throw If \a this field has not been constructed via file reading.
6455  *  \throw If the MED file is not readable.
6456  *  \throw If there is no mesh in the MED file.
6457  *  \throw If no field values of the given \a type.
6458  *  \throw If no field values lying on the top level support.
6459  *  \sa getFieldAtLevel()
6460  */
6461 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6462 {
6463   if(getFileName().empty())
6464     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6465   MCAuto<DataArray> arrOut;
6466   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6467   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6468   return ret.retn();
6469 }
6470
6471 /*!
6472  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6473  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6474  *  \param [in] type - a spatial discretization of the new field.
6475  *  \param [in] mesh - the supporting mesh.
6476  *  \param [in] renumPol - specifies how to permute values of the result field according to
6477  *          the optional numbers of cells and nodes, if any. The valid values are
6478  *          - 0 - do not permute.
6479  *          - 1 - permute cells.
6480  *          - 2 - permute nodes.
6481  *          - 3 - permute cells and nodes.
6482  *
6483  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6484  *          caller is to delete this field using decrRef() as it is no more needed. 
6485  *  \throw If no field of \a this is lying on \a mesh.
6486  *  \throw If the mesh is empty.
6487  *  \throw If no field values of the given \a type are available.
6488  *  \sa getFieldAtLevel()
6489  *  \sa getFieldOnMeshAtLevel() 
6490  */
6491 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6492 {
6493   MCAuto<DataArray> arrOut;
6494   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6495   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6496   return ret.retn();
6497 }
6498
6499 /*!
6500  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6501  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6502  *  \param [in] type - a spatial discretization of interest.
6503  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6504  *  \param [in] mesh - the supporting mesh.
6505  *  \param [in] renumPol - specifies how to permute values of the result field according to
6506  *          the optional numbers of cells and nodes, if any. The valid values are
6507  *          - 0 - do not permute.
6508  *          - 1 - permute cells.
6509  *          - 2 - permute nodes.
6510  *          - 3 - permute cells and nodes.
6511  *
6512  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6513  *          caller is to delete this field using decrRef() as it is no more needed. 
6514  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6515  *  \throw If no field of \a this is lying on \a mesh.
6516  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6517  *  \sa getFieldAtLevel()
6518  *  \sa getFieldOnMeshAtLevel() 
6519  */
6520 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6521 {
6522   MCAuto<DataArray> arrOut;
6523   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6524   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6525   return ret.retn();
6526 }
6527
6528 /*!
6529  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6530  * This method is called "Old" because in MED3 norm a field has only one meshName
6531  * attached, so this method is for readers of MED2 files. If \a this field 
6532  * has not been constructed via file reading, an exception is thrown.
6533  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6534  *  \param [in] type - a spatial discretization of interest.
6535  *  \param [in] mName - a name of the supporting mesh.
6536  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6537  *  \param [in] renumPol - specifies how to permute values of the result field according to
6538  *          the optional numbers of cells and nodes, if any. The valid values are
6539  *          - 0 - do not permute.
6540  *          - 1 - permute cells.
6541  *          - 2 - permute nodes.
6542  *          - 3 - permute cells and nodes.
6543  *
6544  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6545  *          caller is to delete this field using decrRef() as it is no more needed. 
6546  *  \throw If the MED file is not readable.
6547  *  \throw If there is no mesh named \a mName in the MED file.
6548  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6549  *  \throw If \a this field has not been constructed via file reading.
6550  *  \throw If no field of \a this is lying on the mesh named \a mName.
6551  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6552  *  \sa getFieldAtLevel()
6553  */
6554 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6555 {
6556   if(getFileName().empty())
6557     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6558   MCAuto<DataArray> arrOut;
6559   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6560   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6561   return ret.retn();
6562 }
6563
6564 /*!
6565  * Returns values and a profile of the field of a given type lying on a given support.
6566  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6567  *  \param [in] type - a spatial discretization of the field.
6568  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6569  *  \param [in] mesh - the supporting mesh.
6570  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6571  *          field of interest lies on. If the field lies on all entities of the given
6572  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6573  *          using decrRef() as it is no more needed.  
6574  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6575  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6576  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6577  *  \throw If no field of \a this is lying on \a mesh.
6578  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6579  */
6580 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6581 {
6582   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6583   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6584 }
6585
6586 /*!
6587  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6588  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6589  * "Sort By Type"), if not, an exception is thrown. 
6590  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6591  *  \param [in] field - the field to add to \a this.
6592  *  \throw If the name of \a field is empty.
6593  *  \throw If the data array of \a field is not set.
6594  *  \throw If the data array is already allocated but has different number of components
6595  *         than \a field.
6596  *  \throw If the underlying mesh of \a field has no name.
6597  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6598  */
6599 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6600 {
6601   setFileName("");
6602   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6603 }
6604
6605 /*!
6606  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6607  * can be an aggregation of several MEDCouplingFieldDouble instances.
6608  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6609  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6610  * and \a profile.
6611  *
6612  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6613  * A new profile is added only if no equal profile is missing.
6614  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6615  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6616  *  \param [in] mesh - the supporting mesh of \a field.
6617  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6618  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6619  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6620  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6621  *  \throw If the data array of \a field is not set.
6622  *  \throw If the data array of \a this is already allocated but has different number of
6623  *         components than \a field.
6624  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6625  *  \sa setFieldNoProfileSBT()
6626  */
6627 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6628 {
6629   setFileName("");
6630   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6631 }
6632
6633 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6634 {
6635   return new MEDFileField1TS(*this);
6636 }
6637
6638 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6639 {
6640   return contentNotNull()->getUndergroundDataArrayDouble();
6641 }
6642
6643 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6644 {
6645   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6646 }
6647
6648 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6649                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6650 {
6651   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6652 }
6653
6654 //= MEDFileIntField1TS
6655
6656 MEDFileIntField1TS *MEDFileIntField1TS::New()
6657 {
6658   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6659   ret->contentNotNull();
6660   return ret.retn();
6661 }
6662
6663 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6664 {
6665   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6666   ret->contentNotNull();
6667   return ret.retn();
6668 }
6669
6670 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6671 {
6672   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6673   ret->contentNotNull();
6674   return ret.retn();
6675 }
6676
6677 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6678 {
6679   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6680   ret->contentNotNull();
6681   return ret.retn();
6682 }
6683
6684 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6685 {
6686   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6687   ret->contentNotNull();
6688   return ret.retn();
6689 }
6690
6691 MEDFileIntField1TS::MEDFileIntField1TS()
6692 {
6693   _content=new MEDFileIntField1TSWithoutSDA;
6694 }
6695
6696 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6697 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6698 {
6699 }
6700 catch(INTERP_KERNEL::Exception& e)
6701 { throw e; }
6702
6703 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6704 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6705 {
6706 }
6707 catch(INTERP_KERNEL::Exception& e)
6708 { throw e; }
6709
6710 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6711 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6712 {
6713 }
6714 catch(INTERP_KERNEL::Exception& e)
6715 { throw e; }
6716
6717 /*!
6718  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6719  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6720  *
6721  * \warning this is a shallow copy constructor
6722  */
6723 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6724 {
6725 }
6726
6727 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6728 {
6729   return new MEDFileIntField1TS(*this);
6730 }
6731
6732 /*!
6733  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6734  * following the given input policy.
6735  *
6736  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6737  *                            By default (true) the globals are deeply copied.
6738  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6739  */
6740 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6741 {
6742   MCAuto<MEDFileField1TS> ret;
6743   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6744   if(content)
6745     {
6746       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6747       if(!contc)
6748         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6749       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6750       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6751     }
6752   else
6753     ret=MEDFileField1TS::New();
6754   if(isDeepCpyGlobs)
6755     ret->deepCpyGlobs(*this);
6756   else
6757     ret->shallowCpyGlobs(*this);
6758   return ret.retn();
6759 }
6760
6761 /*!
6762  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6763  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6764  * "Sort By Type"), if not, an exception is thrown. 
6765  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6766  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6767  *  \param [in] arrOfVals - the values of the field \a field used.
6768  *  \throw If the name of \a field is empty.
6769  *  \throw If the data array of \a field is not set.
6770  *  \throw If the data array is already allocated but has different number of components
6771  *         than \a field.
6772  *  \throw If the underlying mesh of \a field has no name.
6773  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6774  */
6775 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6776 {
6777   setFileName("");
6778   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6779 }
6780
6781 /*!
6782  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6783  * can be an aggregation of several MEDCouplingFieldDouble instances.
6784  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6785  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6786  * and \a profile.
6787  *
6788  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6789  * A new profile is added only if no equal profile is missing.
6790  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6791  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6792  *  \param [in] arrOfVals - the values of the field \a field used.
6793  *  \param [in] mesh - the supporting mesh of \a field.
6794  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6795  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6796  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6797  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6798  *  \throw If the data array of \a field is not set.
6799  *  \throw If the data array of \a this is already allocated but has different number of
6800  *         components than \a field.
6801  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6802  *  \sa setFieldNoProfileSBT()
6803  */
6804 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6805 {
6806   setFileName("");
6807   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6808 }
6809
6810 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6811 {
6812   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6813   if(!pt)
6814     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6815   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6816   if(!ret)
6817     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 !");
6818   return ret;
6819 }
6820
6821 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6822 {
6823   if(getFileName().empty())
6824     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6825   MCAuto<DataArray> arrOut2;
6826   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6827   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6828   if(!arrOutC)
6829     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6830   arrOut=arrOutC;
6831   arrOut->incrRef();  // arrOut2 dies at the end of the func
6832   return ret.retn();
6833 }
6834
6835 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
6836 {
6837   if(!((DataArray *)arr))
6838     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6839   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6840   if(!arrC)
6841     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6842   arrC->incrRef();
6843   return arrC;
6844 }
6845
6846 /*!
6847  * Returns a new MEDCouplingFieldDouble of a given type lying on
6848  * the top level cells of the first mesh in MED file. If \a this field 
6849  * has not been constructed via file reading, an exception is thrown.
6850  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6851  *  \param [in] type - a spatial discretization of interest.
6852  *  \param [out] arrOut - the DataArrayInt containing values of field.
6853  *  \param [in] renumPol - specifies how to permute values of the result field according to
6854  *          the optional numbers of cells and nodes, if any. The valid values are
6855  *          - 0 - do not permute.
6856  *          - 1 - permute cells.
6857  *          - 2 - permute nodes.
6858  *          - 3 - permute cells and nodes.
6859  *
6860  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6861  *          caller is to delete this field using decrRef() as it is no more needed. 
6862  *  \throw If \a this field has not been constructed via file reading.
6863  *  \throw If the MED file is not readable.
6864  *  \throw If there is no mesh in the MED file.
6865  *  \throw If no field values of the given \a type.
6866  *  \throw If no field values lying on the top level support.
6867  *  \sa getFieldAtLevel()
6868  */
6869 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6870 {
6871   if(getFileName().empty())
6872     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6873   MCAuto<DataArray> arr;
6874   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6875   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6876   return ret.retn();
6877 }
6878
6879 /*!
6880  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6881  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6882  *  \param [in] type - a spatial discretization of the new field.
6883  *  \param [in] mesh - the supporting mesh.
6884  *  \param [out] arrOut - the DataArrayInt containing values of field.
6885  *  \param [in] renumPol - specifies how to permute values of the result field according to
6886  *          the optional numbers of cells and nodes, if any. The valid values are
6887  *          - 0 - do not permute.
6888  *          - 1 - permute cells.
6889  *          - 2 - permute nodes.
6890  *          - 3 - permute cells and nodes.
6891  *
6892  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6893  *          caller is to delete this field using decrRef() as it is no more needed. 
6894  *  \throw If no field of \a this is lying on \a mesh.
6895  *  \throw If the mesh is empty.
6896  *  \throw If no field values of the given \a type are available.
6897  *  \sa getFieldAtLevel()
6898  *  \sa getFieldOnMeshAtLevel() 
6899  */
6900 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6901 {
6902   MCAuto<DataArray> arr;
6903   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6904   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6905   return ret.retn();
6906 }
6907
6908 /*!
6909  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6910  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6911  *  \param [in] type - a spatial discretization of interest.
6912  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6913  *  \param [out] arrOut - the DataArrayInt containing values of field.
6914  *  \param [in] mesh - the supporting mesh.
6915  *  \param [in] renumPol - specifies how to permute values of the result field according to
6916  *          the optional numbers of cells and nodes, if any. The valid values are
6917  *          - 0 - do not permute.
6918  *          - 1 - permute cells.
6919  *          - 2 - permute nodes.
6920  *          - 3 - permute cells and nodes.
6921  *
6922  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6923  *          caller is to delete this field using decrRef() as it is no more needed. 
6924  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6925  *  \throw If no field of \a this is lying on \a mesh.
6926  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6927  *  \sa getFieldAtLevel()
6928  *  \sa getFieldOnMeshAtLevel() 
6929  */
6930 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6931 {
6932   MCAuto<DataArray> arr;
6933   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6934   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6935   return ret.retn();
6936 }
6937
6938 /*!
6939  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6940  * This method is called "Old" because in MED3 norm a field has only one meshName
6941  * attached, so this method is for readers of MED2 files. If \a this field 
6942  * has not been constructed via file reading, an exception is thrown.
6943  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6944  *  \param [in] type - a spatial discretization of interest.
6945  *  \param [in] mName - a name of the supporting mesh.
6946  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6947  *  \param [out] arrOut - the DataArrayInt containing values of field.
6948  *  \param [in] renumPol - specifies how to permute values of the result field according to
6949  *          the optional numbers of cells and nodes, if any. The valid values are
6950  *          - 0 - do not permute.
6951  *          - 1 - permute cells.
6952  *          - 2 - permute nodes.
6953  *          - 3 - permute cells and nodes.
6954  *
6955  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6956  *          caller is to delete this field using decrRef() as it is no more needed. 
6957  *  \throw If the MED file is not readable.
6958  *  \throw If there is no mesh named \a mName in the MED file.
6959  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6960  *  \throw If \a this field has not been constructed via file reading.
6961  *  \throw If no field of \a this is lying on the mesh named \a mName.
6962  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6963  *  \sa getFieldAtLevel()
6964  */
6965 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6966 {
6967   if(getFileName().empty())
6968     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6969   MCAuto<DataArray> arr;
6970   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6971   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6972   return ret.retn();
6973 }
6974
6975 /*!
6976  * Returns values and a profile of the field of a given type lying on a given support.
6977  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6978  *  \param [in] type - a spatial discretization of the field.
6979  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6980  *  \param [in] mesh - the supporting mesh.
6981  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6982  *          field of interest lies on. If the field lies on all entities of the given
6983  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6984  *          using decrRef() as it is no more needed.  
6985  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6986  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6987  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6988  *  \throw If no field of \a this is lying on \a mesh.
6989  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6990  */
6991 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6992 {
6993   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6994   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6995 }
6996
6997 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
6998 {
6999   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7000   if(!pt)
7001     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7002   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7003   if(!ret)
7004     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 !");
7005   return ret;
7006 }
7007
7008 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7009 {
7010   return contentNotNull()->getUndergroundDataArrayInt();
7011 }
7012
7013 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7014
7015 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7016 {
7017 }
7018
7019 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7020 {
7021 }
7022
7023 /*!
7024  * \param [in] fieldId field id in C mode
7025  */
7026 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7027 {
7028   med_field_type typcha;
7029   std::string dtunitOut;
7030   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
7031   setDtUnit(dtunitOut.c_str());
7032   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7033 }
7034
7035 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)
7036 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7037 {
7038   setDtUnit(dtunit.c_str());
7039   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7040 }
7041 catch(INTERP_KERNEL::Exception& e)
7042 {
7043     throw e;
7044 }
7045
7046 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7047 {
7048   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7049   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7050     ret+=(*it).capacity();
7051   return ret;
7052 }
7053
7054 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7055 {
7056   std::vector<const BigMemoryObject *> ret;
7057   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7058     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7059   return ret;
7060 }
7061
7062 /*!
7063  * 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
7064  * NULL.
7065  */
7066 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7067 {
7068   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7069   ret->setInfo(_infos);
7070   int sz=(int)_time_steps.size();
7071   for(const int *id=startIds;id!=endIds;id++)
7072     {
7073       if(*id>=0 && *id<sz)
7074         {
7075           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7076           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7077           if(tse)
7078             {
7079               tse->incrRef();
7080               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7081             }
7082           ret->pushBackTimeStep(tse2);
7083         }
7084       else
7085         {
7086           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7087           oss << " ! Should be in [0," << sz << ") !";
7088           throw INTERP_KERNEL::Exception(oss.str().c_str());
7089         }
7090     }
7091   if(ret->getNumberOfTS()>0)
7092     ret->synchronizeNameScope();
7093   ret->copyNameScope(*this);
7094   return ret.retn();
7095 }
7096
7097 /*!
7098  * 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
7099  * NULL.
7100  */
7101 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7102 {
7103   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7104   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7105   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7106   ret->setInfo(_infos);
7107   int sz=(int)_time_steps.size();
7108   int j=bg;
7109   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7110     {
7111       if(j>=0 && j<sz)
7112         {
7113           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7114           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7115           if(tse)
7116             {
7117               tse->incrRef();
7118               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7119             }
7120           ret->pushBackTimeStep(tse2);
7121         }
7122       else
7123         {
7124           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7125           oss << " ! Should be in [0," << sz << ") !";
7126           throw INTERP_KERNEL::Exception(oss.str().c_str());
7127         }
7128     }
7129   if(ret->getNumberOfTS()>0)
7130     ret->synchronizeNameScope();
7131   ret->copyNameScope(*this);
7132   return ret.retn();
7133 }
7134
7135 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7136 {
7137   int id=0;
7138   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7139   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7140     {
7141       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7142       if(!cur)
7143         continue;
7144       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7145       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7146         ids->pushBackSilent(id);
7147     }
7148   return buildFromTimeStepIds(ids->begin(),ids->end());
7149 }
7150
7151 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7152 {
7153   int id=0;
7154   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7155   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7156     {
7157       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7158       if(!cur)
7159         continue;
7160       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7161       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7162         ids->pushBackSilent(id);
7163     }
7164   return buildFromTimeStepIds(ids->begin(),ids->end());
7165 }
7166
7167 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7168 {
7169   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7170     {
7171       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7172       if(!cur)
7173         continue;
7174       if(cur->presenceOfMultiDiscPerGeoType())
7175         return true;
7176     }
7177   return false;
7178 }
7179
7180 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7181 {
7182   return _infos;
7183 }
7184
7185 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7186 {
7187   _infos=info;
7188 }
7189
7190 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7191 {
7192   int ret=0;
7193   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7194     {
7195       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7196       if(pt->isDealingTS(iteration,order))
7197         return ret;
7198     }
7199   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7200   std::vector< std::pair<int,int> > vp=getIterations();
7201   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7202     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7203   throw INTERP_KERNEL::Exception(oss.str().c_str());
7204 }
7205
7206 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7207 {
7208   return *_time_steps[getTimeStepPos(iteration,order)];
7209 }
7210
7211 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7212 {
7213   return *_time_steps[getTimeStepPos(iteration,order)];
7214 }
7215
7216 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7217 {
7218   if(_time_steps.empty())
7219     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7220   return _time_steps[0]->getMeshName();
7221 }
7222
7223 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7224 {
7225   std::string oldName(getMeshName());
7226   std::vector< std::pair<std::string,std::string> > v(1);
7227   v[0].first=oldName; v[0].second=newMeshName;
7228   changeMeshNames(v);
7229 }
7230
7231 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7232 {
7233   bool ret=false;
7234   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7235     {
7236       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7237       if(cur)
7238         ret=cur->changeMeshNames(modifTab) || ret;
7239     }
7240   return ret;
7241 }
7242
7243 /*!
7244  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7245  */
7246 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7247 {
7248   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7249 }
7250
7251 /*!
7252  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7253  */
7254 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7255 {
7256   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7257 }
7258
7259 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7260                                                                        MEDFileFieldGlobsReal& glob)
7261 {
7262   bool ret=false;
7263   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7264     {
7265       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7266       if(f1ts)
7267         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7268     }
7269   return ret;
7270 }
7271
7272 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7273 {
7274   std::string startLine(bkOffset,' ');
7275   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7276   if(fmtsId>=0)
7277     oss << " (" << fmtsId << ")";
7278   oss << " has the following name: \"" << _name << "\"." << std::endl;
7279   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7280   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7281     {
7282       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7283     }
7284   int i=0;
7285   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7286     {
7287       std::string chapter(17,'0'+i);
7288       oss << startLine << chapter << std::endl;
7289       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7290       if(cur)
7291         cur->simpleRepr(bkOffset+2,oss,i);
7292       else
7293         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7294       oss << startLine << chapter << std::endl;
7295     }
7296 }
7297
7298 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7299 {
7300   std::size_t sz=_time_steps.size();
7301   std::vector< std::pair<int,int> > ret(sz);
7302   ret1.resize(sz);
7303   for(std::size_t i=0;i<sz;i++)
7304     {
7305       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7306       if(f1ts)
7307         {
7308           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7309         }
7310       else
7311         {
7312           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7313           throw INTERP_KERNEL::Exception(oss.str().c_str());
7314         }
7315     }
7316   return ret;
7317 }
7318
7319 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7320 {
7321   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7322   if(!tse2)
7323     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7324   checkCoherencyOfType(tse2);
7325   if(_time_steps.empty())
7326     {
7327       setName(tse2->getName().c_str());
7328       setInfo(tse2->getInfo());
7329     }
7330   checkThatComponentsMatch(tse2->getInfo());
7331   _time_steps.push_back(tse);
7332 }
7333
7334 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7335 {
7336   std::size_t nbOfCompo=_infos.size();
7337   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7338     {
7339       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7340       if(cur)
7341         {
7342           if((cur->getInfo()).size()!=nbOfCompo)
7343             {
7344               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7345               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7346               throw INTERP_KERNEL::Exception(oss.str().c_str());
7347             }
7348           cur->copyNameScope(*this);
7349         }
7350     }
7351 }
7352
7353 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)
7354 {
7355   _time_steps.resize(nbPdt);
7356   for(int i=0;i<nbPdt;i++)
7357     {
7358       std::vector< std::pair<int,int> > ts;
7359       med_int numdt=0,numo=0;
7360       med_int meshIt=0,meshOrder=0;
7361       med_float dt=0.0;
7362       MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder));
7363       switch(fieldTyp)
7364       {
7365         case MED_FLOAT64:
7366           {
7367             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7368             break;
7369           }
7370         case MED_INT32:
7371           {
7372             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7373             break;
7374           }
7375         default:
7376           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7377       }
7378       if(loadAll)
7379         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7380       else
7381         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7382     }
7383 }
7384
7385 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7386 {
7387   if(_time_steps.empty())
7388     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7389   checkThatNbOfCompoOfTSMatchThis();
7390   std::vector<std::string> infos(getInfo());
7391   int nbComp=infos.size();
7392   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7393   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7394   for(int i=0;i<nbComp;i++)
7395     {
7396       std::string info=infos[i];
7397       std::string c,u;
7398       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7399       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7400       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7401     }
7402   if(_name.empty())
7403     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7404   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7405   int nbOfTS=_time_steps.size();
7406   for(int i=0;i<nbOfTS;i++)
7407     _time_steps[i]->writeLL(fid,opts,*this);
7408 }
7409
7410 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7411 {
7412   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7413     {
7414       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7415       if(elt)
7416         elt->loadBigArraysRecursively(fid,nasc);
7417     }
7418 }
7419
7420 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7421 {
7422   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7423     {
7424       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7425       if(elt)
7426         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7427     }
7428 }
7429
7430 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7431 {
7432   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7433     {
7434       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7435       if(elt)
7436         elt->unloadArrays();
7437     }
7438 }
7439
7440 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7441 {
7442   return _time_steps.size();
7443 }
7444
7445 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7446 {
7447   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7448   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7449     {
7450       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7451       if(tmp)
7452         newTS.push_back(*it);
7453     }
7454   _time_steps=newTS;
7455 }
7456
7457 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7458 {
7459   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7460   int maxId=(int)_time_steps.size();
7461   int ii=0;
7462   std::set<int> idsToDel;
7463   for(const int *id=startIds;id!=endIds;id++,ii++)
7464     {
7465       if(*id>=0 && *id<maxId)
7466         {
7467           idsToDel.insert(*id);
7468         }
7469       else
7470         {
7471           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7472           throw INTERP_KERNEL::Exception(oss.str().c_str());
7473         }
7474     }
7475   for(int iii=0;iii<maxId;iii++)
7476     if(idsToDel.find(iii)==idsToDel.end())
7477       newTS.push_back(_time_steps[iii]);
7478   _time_steps=newTS;
7479 }
7480
7481 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7482 {
7483   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7484   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7485   if(nbOfEntriesToKill==0)
7486     return ;
7487   std::size_t sz=_time_steps.size();
7488   std::vector<bool> b(sz,true);
7489   int j=bg;
7490   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7491     b[j]=false;
7492   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7493   for(std::size_t i=0;i<sz;i++)
7494     if(b[i])
7495       newTS.push_back(_time_steps[i]);
7496   _time_steps=newTS;
7497 }
7498
7499 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7500 {
7501   int ret=0;
7502   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7503   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7504     {
7505       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7506       if(tmp)
7507         {
7508           int it2,ord;
7509           tmp->getTime(it2,ord);
7510           if(it2==iteration && order==ord)
7511             return ret;
7512           else
7513             oss << "(" << it2 << ","  << ord << "), ";
7514         }
7515     }
7516   throw INTERP_KERNEL::Exception(oss.str().c_str());
7517 }
7518
7519 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7520 {
7521   int ret=0;
7522   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7523   oss.precision(15);
7524   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7525     {
7526       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7527       if(tmp)
7528         {
7529           int it2,ord;
7530           double ti=tmp->getTime(it2,ord);
7531           if(fabs(time-ti)<eps)
7532             return ret;
7533           else
7534             oss << ti << ", ";
7535         }
7536     }
7537   throw INTERP_KERNEL::Exception(oss.str().c_str());
7538 }
7539
7540 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7541 {
7542   int lgth=_time_steps.size();
7543   std::vector< std::pair<int,int> > ret(lgth);
7544   for(int i=0;i<lgth;i++)
7545     _time_steps[i]->fillIteration(ret[i]);
7546   return ret;
7547 }
7548
7549 /*!
7550  * 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'
7551  * This method returns two things.
7552  * - The absolute dimension of 'this' in first parameter. 
7553  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7554  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7555  *
7556  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7557  * Only these 3 discretizations will be taken into account here.
7558  *
7559  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7560  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7561  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7562  *
7563  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7564  * 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'.
7565  * 
7566  * Let's consider the typical following case :
7567  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7568  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7569  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7570  *   TETRA4 and SEG2
7571  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7572  *
7573  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7574  * 
7575  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7576  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7577  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7578  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7579  */
7580 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7581 {
7582   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7583 }
7584
7585 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7586 {
7587   if(pos<0 || pos>=(int)_time_steps.size())
7588     {
7589       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7590       throw INTERP_KERNEL::Exception(oss.str().c_str());
7591     }
7592   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7593   if(item==0)
7594     {
7595       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7596       oss << "\nTry to use following method eraseEmptyTS !";
7597       throw INTERP_KERNEL::Exception(oss.str().c_str());
7598     }
7599   return item;
7600 }
7601
7602 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7603 {
7604   if(pos<0 || pos>=(int)_time_steps.size())
7605     {
7606       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7607       throw INTERP_KERNEL::Exception(oss.str().c_str());
7608     }
7609   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7610   if(item==0)
7611     {
7612       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7613       oss << "\nTry to use following method eraseEmptyTS !";
7614       throw INTERP_KERNEL::Exception(oss.str().c_str());
7615     }
7616   return item;
7617 }
7618
7619 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7620 {
7621   std::vector<std::string> ret;
7622   std::set<std::string> ret2;
7623   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7624     {
7625       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7626       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7627         if(ret2.find(*it2)==ret2.end())
7628           {
7629             ret.push_back(*it2);
7630             ret2.insert(*it2);
7631           }
7632     }
7633   return ret;
7634 }
7635
7636 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7637 {
7638   std::vector<std::string> ret;
7639   std::set<std::string> ret2;
7640   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7641     {
7642       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7643       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7644         if(ret2.find(*it2)==ret2.end())
7645           {
7646             ret.push_back(*it2);
7647             ret2.insert(*it2);
7648           }
7649     }
7650   return ret;
7651 }
7652
7653 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7654 {
7655   std::vector<std::string> ret;
7656   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7657     {
7658       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7659       ret.insert(ret.end(),tmp.begin(),tmp.end());
7660     }
7661   return ret;
7662 }
7663
7664 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7665 {
7666   std::vector<std::string> ret;
7667   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7668     {
7669       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7670       ret.insert(ret.end(),tmp.begin(),tmp.end());
7671     }
7672   return ret;
7673 }
7674
7675 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7676 {
7677   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7678     (*it)->changePflsRefsNamesGen2(mapOfModif);
7679 }
7680
7681 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7682 {
7683   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7684     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7685 }
7686
7687 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7688 {
7689   int lgth=_time_steps.size();
7690   std::vector< std::vector<TypeOfField> > ret(lgth);
7691   for(int i=0;i<lgth;i++)
7692     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7693   return ret;
7694 }
7695
7696 /*!
7697  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7698  */
7699 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
7700 {
7701   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7702 }
7703
7704 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7705 {
7706   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7707   std::size_t i=0;
7708   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7709     {
7710       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7711         ret->_time_steps[i]=(*it)->deepCopy();
7712     }
7713   return ret.retn();
7714 }
7715
7716 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7717 {
7718   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7719   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7720   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7721   for(std::size_t i=0;i<sz;i++)
7722     {
7723       ret[i]=shallowCpy();
7724       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7725     }
7726   for(std::size_t i=0;i<sz2;i++)
7727     {
7728       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7729       if(ret1.size()!=sz)
7730         {
7731           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7732           throw INTERP_KERNEL::Exception(oss.str().c_str());
7733         }
7734       ts[i]=ret1;
7735     }
7736   for(std::size_t i=0;i<sz;i++)
7737     for(std::size_t j=0;j<sz2;j++)
7738       ret[i]->_time_steps[j]=ts[j][i];
7739   return ret;
7740 }
7741
7742 /*!
7743  * This method splits into discretization each time steps in \a this.
7744  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7745  */
7746 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7747 {
7748   std::size_t sz(_time_steps.size());
7749   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7750   for(std::size_t i=0;i<sz;i++)
7751     {
7752       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7753       if(!timeStep)
7754         {
7755           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7756           throw INTERP_KERNEL::Exception(oss.str().c_str());
7757         }
7758       items[i]=timeStep->splitDiscretizations();  
7759     }
7760   //
7761   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7762   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7763   std::vector< TypeOfField > types;
7764   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7765     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7766       {
7767         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7768         if(ts.size()!=1)
7769           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7770         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7771         if(it2==types.end())
7772           types.push_back(ts[0]);
7773       }
7774   ret.resize(types.size()); ret2.resize(types.size());
7775   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7776     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7777       {
7778         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7779         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7780         ret2[pos].push_back(*it1);
7781       }
7782   for(std::size_t i=0;i<types.size();i++)
7783     {
7784       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7785       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7786         elt->pushBackTimeStep(*it1);//also updates infos in elt
7787       ret[i]=elt;
7788       elt->MEDFileFieldNameScope::operator=(*this);
7789     }
7790   return ret;
7791 }
7792
7793 /*!
7794  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7795  */
7796 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7797 {
7798   std::size_t sz(_time_steps.size());
7799   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7800   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7801   for(std::size_t i=0;i<sz;i++)
7802     {
7803       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7804       if(!timeStep)
7805         {
7806           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7807           throw INTERP_KERNEL::Exception(oss.str().c_str());
7808         }
7809       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7810       if(szOut==std::numeric_limits<std::size_t>::max())
7811         szOut=items[i].size();
7812       else
7813         if(items[i].size()!=szOut)
7814           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7815     }
7816   if(szOut==std::numeric_limits<std::size_t>::max())
7817     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7818   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7819   for(std::size_t i=0;i<szOut;i++)
7820     {
7821       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7822       for(std::size_t j=0;j<sz;j++)
7823         elt->pushBackTimeStep(items[j][i]);
7824       ret[i]=elt;
7825       elt->MEDFileFieldNameScope::operator=(*this);
7826     }
7827   return ret;
7828 }
7829
7830 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7831 {
7832   _name=field->getName();
7833   if(_name.empty())
7834     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7835   if(!arr)
7836     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7837   _infos=arr->getInfoOnComponents();
7838 }
7839
7840 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7841 {
7842   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7843   if(_name!=field->getName())
7844     {
7845       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7846       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7847       throw INTERP_KERNEL::Exception(oss.str().c_str());
7848     }
7849   if(!arr)
7850     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7851   checkThatComponentsMatch(arr->getInfoOnComponents());
7852 }
7853
7854 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7855 {
7856   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7857   if(getInfo().size()!=compos.size())
7858     {
7859       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7860       oss << " number of components of element to append (" << compos.size() << ") !";
7861       throw INTERP_KERNEL::Exception(oss.str().c_str());
7862     }
7863   if(_infos!=compos)
7864     {
7865       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7866       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7867       oss << " But compo in input fields are : ";
7868       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7869       oss << " !";
7870       throw INTERP_KERNEL::Exception(oss.str().c_str());
7871     }
7872 }
7873
7874 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7875 {
7876   std::size_t sz=_infos.size();
7877   int j=0;
7878   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7879     {
7880       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7881       if(elt)
7882         if(elt->getInfo().size()!=sz)
7883           {
7884             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7885             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7886             throw INTERP_KERNEL::Exception(oss.str().c_str());
7887           }
7888     }
7889 }
7890
7891 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7892 {
7893   if(!field)
7894     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7895   if(!_time_steps.empty())
7896     checkCoherencyOfTinyInfo(field,arr);
7897   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7898   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7899   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7900   copyTinyInfoFrom(field,arr);
7901   _time_steps.push_back(obj);
7902 }
7903
7904 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7905 {
7906   if(!field)
7907     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7908   if(!_time_steps.empty())
7909     checkCoherencyOfTinyInfo(field,arr);
7910   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7911   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7912   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7913   copyTinyInfoFrom(field,arr);
7914   _time_steps.push_back(obj);
7915 }
7916
7917 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
7918 {
7919   int sz=(int)_time_steps.size();
7920   if(i<0 || i>=sz)
7921     {
7922       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7923       throw INTERP_KERNEL::Exception(oss.str().c_str());
7924     }
7925   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7926   if(tsPtr)
7927     {
7928       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7929         {
7930           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7931           throw INTERP_KERNEL::Exception(oss.str().c_str());
7932         }
7933     }
7934   _time_steps[i]=ts;
7935 }
7936
7937 //= MEDFileFieldMultiTSWithoutSDA
7938
7939 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)
7940 {
7941   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
7942 }
7943
7944 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7945 {
7946 }
7947
7948 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7949 {
7950 }
7951
7952 /*!
7953  * \param [in] fieldId field id in C mode
7954  */
7955 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7956 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
7957 {
7958 }
7959 catch(INTERP_KERNEL::Exception& e)
7960 { throw e; }
7961
7962 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)
7963 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
7964 {
7965 }
7966 catch(INTERP_KERNEL::Exception& e)
7967 { throw e; }
7968
7969 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7970 {
7971   return new MEDFileField1TSWithoutSDA;
7972 }
7973
7974 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7975 {
7976   if(!f1ts)
7977     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7978   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7979   if(!f1tsC)
7980     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7981 }
7982
7983 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7984 {
7985   return MEDFileField1TSWithoutSDA::TYPE_STR;
7986 }
7987
7988 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7989 {
7990   return new MEDFileFieldMultiTSWithoutSDA(*this);
7991 }
7992
7993 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
7994 {
7995   return new MEDFileFieldMultiTSWithoutSDA;
7996 }
7997
7998 /*!
7999  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8000  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8001  */
8002 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
8003 {
8004   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8005   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8006   if(!myF1TSC)
8007     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8008   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8009 }
8010
8011 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8012 {
8013   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8014   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8015   int i=0;
8016   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8017     {
8018       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8019       if(eltToConv)
8020         {
8021           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8022           if(!eltToConvC)
8023             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8024           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8025           ret->setIteration(i,elt);
8026         }
8027     }
8028   return ret.retn();
8029 }
8030
8031 //= MEDFileAnyTypeFieldMultiTS
8032
8033 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8034 {
8035 }
8036
8037 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8038 try:MEDFileFieldGlobsReal(fileName)
8039 {
8040   MEDFileUtilities::CheckFileForRead(fileName);
8041   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8042   _content=BuildContentFrom(fid,fileName,loadAll,ms);
8043   loadGlobals(fid);
8044 }
8045 catch(INTERP_KERNEL::Exception& e)
8046 {
8047     throw e;
8048 }
8049
8050 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8051 {
8052   med_field_type typcha;
8053   std::vector<std::string> infos;
8054   std::string dtunit;
8055   int i=-1;
8056   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
8057   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8058   switch(typcha)
8059   {
8060     case MED_FLOAT64:
8061       {
8062         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8063         break;
8064       }
8065     case MED_INT32:
8066       {
8067         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8068         break;
8069       }
8070     default:
8071       {
8072         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
8073         throw INTERP_KERNEL::Exception(oss.str().c_str());
8074       }
8075   }
8076   ret->setDtUnit(dtunit.c_str());
8077   return ret.retn();
8078 }
8079
8080 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8081 {
8082   med_field_type typcha;
8083   //
8084   std::vector<std::string> infos;
8085   std::string dtunit,fieldName;
8086   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
8087   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8088   switch(typcha)
8089   {
8090     case MED_FLOAT64:
8091       {
8092         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8093         break;
8094       }
8095     case MED_INT32:
8096       {
8097         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8098         break;
8099       }
8100     default:
8101       {
8102         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
8103         throw INTERP_KERNEL::Exception(oss.str().c_str());
8104       }
8105   }
8106   ret->setDtUnit(dtunit.c_str());
8107   return ret.retn();
8108 }
8109
8110 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
8111 {
8112   if(!c)
8113     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8114   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8115     {
8116       MCAuto<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
8117       ret->setFileName(fileName);
8118       ret->_content=c;  c->incrRef();
8119       return ret.retn();
8120     }
8121   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8122     {
8123       MCAuto<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
8124       ret->setFileName(fileName);
8125       ret->_content=c;  c->incrRef();
8126       return ret.retn();
8127     }
8128   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8129 }
8130
8131 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8132 try:MEDFileFieldGlobsReal(fileName)
8133 {
8134   MEDFileUtilities::CheckFileForRead(fileName);
8135   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8136   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms,entities);
8137   loadGlobals(fid);
8138 }
8139 catch(INTERP_KERNEL::Exception& e)
8140 {
8141     throw e;
8142 }
8143
8144 //= MEDFileIntFieldMultiTSWithoutSDA
8145
8146 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)
8147 {
8148   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8149 }
8150
8151 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8152 {
8153 }
8154
8155 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8156 {
8157 }
8158
8159 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)
8160 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8161 {
8162 }
8163 catch(INTERP_KERNEL::Exception& e)
8164 { throw e; }
8165
8166 /*!
8167  * \param [in] fieldId field id in C mode
8168  */
8169 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8170 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8171 {
8172 }
8173 catch(INTERP_KERNEL::Exception& e)
8174 { throw e; }
8175
8176 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8177 {
8178   return new MEDFileIntField1TSWithoutSDA;
8179 }
8180
8181 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8182 {
8183   if(!f1ts)
8184     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8185   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8186   if(!f1tsC)
8187     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8188 }
8189
8190 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8191 {
8192   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8193 }
8194
8195 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8196 {
8197   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8198 }
8199
8200 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8201 {
8202   return new MEDFileIntFieldMultiTSWithoutSDA;
8203 }
8204
8205 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8206 {
8207   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8208   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8209   int i=0;
8210   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8211     {
8212       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8213       if(eltToConv)
8214         {
8215           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8216           if(!eltToConvC)
8217             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8218           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8219           ret->setIteration(i,elt);
8220         }
8221     }
8222   return ret.retn();
8223 }
8224
8225 //= MEDFileAnyTypeFieldMultiTS
8226
8227 /*!
8228  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8229  * that has been read from a specified MED file.
8230  *  \param [in] fileName - the name of the MED file to read.
8231  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8232  *          is to delete this field using decrRef() as it is no more needed.
8233  *  \throw If reading the file fails.
8234  */
8235 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8236 {
8237   MEDFileUtilities::CheckFileForRead(fileName);
8238   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8239   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
8240   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8241   ret->loadGlobals(fid);
8242   return ret.retn();
8243 }
8244
8245 /*!
8246  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8247  * that has been read from a specified MED file.
8248  *  \param [in] fileName - the name of the MED file to read.
8249  *  \param [in] fieldName - the name of the field to read.
8250  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8251  *          is to delete this field using decrRef() as it is no more needed.
8252  *  \throw If reading the file fails.
8253  *  \throw If there is no field named \a fieldName in the file.
8254  */
8255 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8256 {
8257   MEDFileUtilities::CheckFileForRead(fileName);
8258   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8259   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fileName,fieldName,loadAll,0,0));
8260   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8261   ret->loadGlobals(fid);
8262   return ret.retn();
8263 }
8264
8265 /*!
8266  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8267  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8268  *
8269  * \warning this is a shallow copy constructor
8270  */
8271 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8272 {
8273   if(!shallowCopyOfContent)
8274     {
8275       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8276       otherPtr->incrRef();
8277       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8278     }
8279   else
8280     {
8281       _content=other.shallowCpy();
8282     }
8283 }
8284
8285 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8286 {
8287   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8288   if(!ret)
8289     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8290   return ret;
8291 }
8292
8293 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8294 {
8295   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8296   if(!ret)
8297     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8298   return ret;
8299 }
8300
8301 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8302 {
8303   return contentNotNullBase()->getPflsReallyUsed2();
8304 }
8305
8306 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8307 {
8308   return contentNotNullBase()->getLocsReallyUsed2();
8309 }
8310
8311 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8312 {
8313   return contentNotNullBase()->getPflsReallyUsedMulti2();
8314 }
8315
8316 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8317 {
8318   return contentNotNullBase()->getLocsReallyUsedMulti2();
8319 }
8320
8321 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8322 {
8323   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8324 }
8325
8326 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8327 {
8328   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8329 }
8330
8331 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8332 {
8333   return contentNotNullBase()->getNumberOfTS();
8334 }
8335
8336 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8337 {
8338   contentNotNullBase()->eraseEmptyTS();
8339 }
8340
8341 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8342 {
8343   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8344 }
8345
8346 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8347 {
8348   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8349 }
8350
8351 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8352 {
8353   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8354   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8355   ret->_content=c;
8356   return ret.retn();
8357 }
8358
8359 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8360 {
8361   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8362   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8363   ret->_content=c;
8364   return ret.retn();
8365 }
8366
8367 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8368 {
8369   return contentNotNullBase()->getIterations();
8370 }
8371
8372 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8373 {
8374   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8375     pushBackTimeStep(*it);
8376 }
8377
8378 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8379 {
8380   if(!fmts)
8381     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8382   int nbOfTS(fmts->getNumberOfTS());
8383   for(int i=0;i<nbOfTS;i++)
8384     {
8385       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8386       pushBackTimeStep(elt);
8387     }
8388 }
8389
8390 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8391 {
8392   if(!f1ts)
8393     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8394   checkCoherencyOfType(f1ts);
8395   f1ts->incrRef();
8396   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8397   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8398   c->incrRef();
8399   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8400   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8401     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8402   _content->pushBackTimeStep(cSafe);
8403   appendGlobs(*f1ts,1e-12);
8404 }
8405
8406 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8407 {
8408   contentNotNullBase()->synchronizeNameScope();
8409 }
8410
8411 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8412 {
8413   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8414 }
8415
8416 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8417 {
8418   return contentNotNullBase()->getPosGivenTime(time,eps);
8419 }
8420
8421 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8422 {
8423   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8424 }
8425
8426 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8427 {
8428   return contentNotNullBase()->getTypesOfFieldAvailable();
8429 }
8430
8431 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
8432 {
8433   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8434 }
8435
8436 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8437 {
8438   return contentNotNullBase()->getName();
8439 }
8440
8441 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8442 {
8443   contentNotNullBase()->setName(name);
8444 }
8445
8446 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8447 {
8448   return contentNotNullBase()->getDtUnit();
8449 }
8450
8451 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8452 {
8453   contentNotNullBase()->setDtUnit(dtUnit);
8454 }
8455
8456 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8457 {
8458   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8459 }
8460
8461 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8462 {
8463   return contentNotNullBase()->getTimeSteps(ret1);
8464 }
8465
8466 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8467 {
8468   return contentNotNullBase()->getMeshName();
8469 }
8470
8471 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8472 {
8473   contentNotNullBase()->setMeshName(newMeshName);
8474 }
8475
8476 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8477 {
8478   return contentNotNullBase()->changeMeshNames(modifTab);
8479 }
8480
8481 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8482 {
8483   return contentNotNullBase()->getInfo();
8484 }
8485
8486 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8487 {
8488   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8489 }
8490
8491 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8492 {
8493   return contentNotNullBase()->setInfo(info);
8494 }
8495
8496 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8497 {
8498   const std::vector<std::string> ret=getInfo();
8499   return (int)ret.size();
8500 }
8501
8502 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8503 {
8504   writeGlobals(fid,*this);
8505   contentNotNullBase()->writeLL(fid,*this);
8506 }
8507
8508 /*!
8509  * Writes \a this field into a MED file specified by its name.
8510  *  \param [in] fileName - the MED file name.
8511  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8512  * - 2 - erase; an existing file is removed.
8513  * - 1 - append; same data should not be present in an existing file.
8514  * - 0 - overwrite; same data present in an existing file is overwritten.
8515  *  \throw If the field name is not set.
8516  *  \throw If no field data is set.
8517  *  \throw If \a mode == 1 and the same data is present in an existing file.
8518  */
8519 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8520 {
8521   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8522   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8523   writeLL(fid);
8524 }
8525
8526 /*!
8527  * This method alloc the arrays and load potentially huge arrays contained in this field.
8528  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8529  * This method can be also called to refresh or reinit values from a file.
8530  * 
8531  * \throw If the fileName is not set or points to a non readable MED file.
8532  */
8533 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8534 {
8535   if(getFileName().empty())
8536     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8537   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8538   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8539 }
8540
8541 /*!
8542  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8543  * But once data loaded once, this method does nothing.
8544  * 
8545  * \throw If the fileName is not set or points to a non readable MED file.
8546  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8547  */
8548 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8549 {
8550   if(!getFileName().empty())
8551     {
8552       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8553       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8554     }
8555 }
8556
8557 /*!
8558  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8559  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8560  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8561  * 
8562  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8563  */
8564 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8565 {
8566   contentNotNullBase()->unloadArrays();
8567 }
8568
8569 /*!
8570  * 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.
8571  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8572  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8573  * 
8574  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8575  */
8576 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8577 {
8578   if(!getFileName().empty())
8579     contentNotNullBase()->unloadArrays();
8580 }
8581
8582 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8583 {
8584   std::ostringstream oss;
8585   contentNotNullBase()->simpleRepr(0,oss,-1);
8586   simpleReprGlobs(oss);
8587   return oss.str();
8588 }
8589
8590 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8591 {
8592   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8593 }
8594
8595 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8596 {
8597   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8598   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8599   return ret;
8600 }
8601
8602 /*!
8603  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8604  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8605  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8606  */
8607 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8608 {
8609   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8610   if(!content)
8611     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8612   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8613   std::size_t sz(contentsSplit.size());
8614   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8615   for(std::size_t i=0;i<sz;i++)
8616     {
8617       ret[i]=shallowCpy();
8618       ret[i]->_content=contentsSplit[i];
8619     }
8620   return ret;
8621 }
8622
8623 /*!
8624  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8625  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8626  */
8627 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8628 {
8629   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8630   if(!content)
8631     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8632   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8633   std::size_t sz(contentsSplit.size());
8634   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8635   for(std::size_t i=0;i<sz;i++)
8636     {
8637       ret[i]=shallowCpy();
8638       ret[i]->_content=contentsSplit[i];
8639     }
8640   return ret;
8641 }
8642
8643 /*!
8644  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8645  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8646  */
8647 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8648 {
8649   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8650   if(!content)
8651     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8652   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8653   std::size_t sz(contentsSplit.size());
8654   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8655   for(std::size_t i=0;i<sz;i++)
8656     {
8657       ret[i]=shallowCpy();
8658       ret[i]->_content=contentsSplit[i];
8659     }
8660   return ret;
8661 }
8662
8663 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8664 {
8665   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8666   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8667     ret->_content=_content->deepCopy();
8668   ret->deepCpyGlobs(*this);
8669   return ret.retn();
8670 }
8671
8672 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8673 {
8674   return _content;
8675 }
8676
8677 /*!
8678  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8679  *  \param [in] iteration - the iteration number of a required time step.
8680  *  \param [in] order - the iteration order number of required time step.
8681  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8682  *          delete this field using decrRef() as it is no more needed.
8683  *  \throw If there is no required time step in \a this field.
8684  */
8685 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8686 {
8687   int pos=getPosOfTimeStep(iteration,order);
8688   return getTimeStepAtPos(pos);
8689 }
8690
8691 /*!
8692  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8693  *  \param [in] time - the time of the time step of interest.
8694  *  \param [in] eps - a precision used to compare time values.
8695  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8696  *          delete this field using decrRef() as it is no more needed.
8697  *  \throw If there is no required time step in \a this field.
8698  */
8699 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8700 {
8701   int pos=getPosGivenTime(time,eps);
8702   return getTimeStepAtPos(pos);
8703 }
8704
8705 /*!
8706  * 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.
8707  * The float64 value of time attached to the pair of integers are not considered here.
8708  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8709  *
8710  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8711  * \throw If there is a null pointer in \a vectFMTS.
8712  */
8713 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8714 {
8715   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8716   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8717   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8718   while(!lstFMTS.empty())
8719     {
8720       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8721       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8722       if(!curIt)
8723         throw INTERP_KERNEL::Exception(msg);
8724       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8725       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8726       elt.push_back(curIt); it=lstFMTS.erase(it);
8727       while(it!=lstFMTS.end())
8728         {
8729           curIt=*it;
8730           if(!curIt)
8731             throw INTERP_KERNEL::Exception(msg);
8732           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8733           if(refIts==curIts)
8734             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8735           else
8736             it++;
8737         }
8738       ret.push_back(elt);
8739     }
8740   return ret;
8741 }
8742
8743 /*!
8744  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8745  * All returned instances in a subvector can be safely loaded, rendered along time
8746  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8747  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8748  * 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).
8749  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8750  * 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.
8751  *
8752  * \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().
8753  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8754  * \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.
8755  * \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.
8756  *
8757  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8758  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8759  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8760  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8761  * \throw If mesh is null.
8762  * \throw If an element in \a vectFMTS is null.
8763  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8764  */
8765 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
8766 {
8767   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8768   if(!mesh)
8769     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8770   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8771   if(vectFMTS.empty())
8772     return ret;
8773   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8774   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8775   if(!frstElt)
8776     throw INTERP_KERNEL::Exception(msg);
8777   std::size_t i=0;
8778   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8779   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8780   for(;it!=vectFMTS.end();it++,i++)
8781     {
8782       if(!(*it))
8783         throw INTERP_KERNEL::Exception(msg);
8784       TypeOfField tof0,tof1;
8785       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8786         {
8787           if(tof1!=ON_NODES)
8788             vectFMTSNotNodes.push_back(*it);
8789           else
8790             vectFMTSNodes.push_back(*it);
8791         }
8792       else
8793         vectFMTSNotNodes.push_back(*it);
8794     }
8795   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
8796   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8797   ret=retCell;
8798   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8799     {
8800       i=0;
8801       bool isFetched(false);
8802       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8803         {
8804           if((*it0).empty())
8805             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8806           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8807             { ret[i].push_back(*it2); isFetched=true; }
8808         }
8809       if(!isFetched)
8810         {
8811           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8812           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8813           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8814         }
8815     }
8816   fsc=cmps;
8817   return ret;
8818 }
8819
8820 /*!
8821  * 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.
8822  * \param [out] cmps - same size than the returned vector.
8823  */
8824 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
8825 {
8826   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8827   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8828   while(!lstFMTS.empty())
8829     {
8830       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8831       MEDFileAnyTypeFieldMultiTS *ref(*it);
8832       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8833       elt.push_back(ref); it=lstFMTS.erase(it);
8834       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8835       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8836       while(it!=lstFMTS.end())
8837         {
8838           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8839           if(cmp->isEqual(curIt))
8840             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8841           else
8842             it++;
8843         }
8844       ret.push_back(elt); cmps.push_back(cmp);
8845     }
8846   return ret;
8847 }
8848
8849 /*!
8850  * 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.
8851  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8852  *
8853  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8854  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8855  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8856  * \thorw If \a f0 and \a f1 do not have the same times steps.
8857  * \throw If mesh is null.
8858  * \throw If \a f0 or \a f1 is null.
8859  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8860  */
8861 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8862 {
8863   if(!mesh)
8864     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8865   if(!f0 || !f1)
8866     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8867   if(f0->getMeshName()!=mesh->getName())
8868     {
8869       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8870       throw INTERP_KERNEL::Exception(oss.str().c_str());
8871     }
8872   if(f1->getMeshName()!=mesh->getName())
8873     {
8874       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8875       throw INTERP_KERNEL::Exception(oss.str().c_str());
8876     }
8877   int nts=f0->getNumberOfTS();
8878   if(nts!=f1->getNumberOfTS())
8879     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8880   if(nts==0)
8881     return nts;
8882   for(int i=0;i<nts;i++)
8883     {
8884       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8885       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8886       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8887       if(tofs0.size()!=1 || tofs1.size()!=1)
8888         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8889       if(i!=0)
8890         {
8891           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8892             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8893         }
8894       else
8895         { tof0=tofs0[0]; tof1=tofs1[0]; }
8896       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8897         {
8898           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() << ") !";
8899           throw INTERP_KERNEL::Exception(oss.str().c_str());
8900         }
8901       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8902         {
8903           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() << ") !";
8904           throw INTERP_KERNEL::Exception(oss.str().c_str());
8905         }
8906       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8907         {
8908           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() << ") !";
8909           throw INTERP_KERNEL::Exception(oss.str().c_str());
8910         }
8911     }
8912   return nts;
8913 }
8914
8915 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8916 {
8917   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8918 }
8919
8920 //= MEDFileFieldMultiTS
8921
8922 /*!
8923  * Returns a new empty instance of MEDFileFieldMultiTS.
8924  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8925  *          is to delete this field using decrRef() as it is no more needed.
8926  */
8927 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8928 {
8929   return new MEDFileFieldMultiTS;
8930 }
8931
8932 /*!
8933  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8934  * that has been read from a specified MED file.
8935  *  \param [in] fileName - the name of the MED file to read.
8936  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8937  *          is to delete this field using decrRef() as it is no more needed.
8938  *  \throw If reading the file fails.
8939  */
8940 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8941 {
8942   MCAuto<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
8943   ret->contentNotNull();//to check that content type matches with \a this type.
8944   return ret.retn();
8945 }
8946
8947 /*!
8948  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8949  * that has been read from a specified MED file.
8950  *  \param [in] fileName - the name of the MED file to read.
8951  *  \param [in] fieldName - the name of the field to read.
8952  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8953  *          is to delete this field using decrRef() as it is no more needed.
8954  *  \throw If reading the file fails.
8955  *  \throw If there is no field named \a fieldName in the file.
8956  */
8957 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8958 {
8959   MCAuto<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
8960   ret->contentNotNull();//to check that content type matches with \a this type.
8961   return ret.retn();
8962 }
8963
8964 /*!
8965  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8966  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8967  *
8968  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8969  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8970  * \warning this is a shallow copy constructor
8971  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8972  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8973  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8974  *          is to delete this field using decrRef() as it is no more needed.
8975  */
8976 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8977 {
8978   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8979 }
8980
8981 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
8982 {
8983   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0,&entities));
8984   ret->contentNotNull();//to check that content type matches with \a this type.
8985   return ret.retn();
8986 }
8987
8988 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8989 {
8990   return new MEDFileFieldMultiTS(*this);
8991 }
8992
8993 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
8994 {
8995   if(!f1ts)
8996     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8997   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8998   if(!f1tsC)
8999     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9000 }
9001
9002 /*!
9003  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9004  * following the given input policy.
9005  *
9006  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9007  *                            By default (true) the globals are deeply copied.
9008  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9009  */
9010 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9011 {
9012   MCAuto<MEDFileIntFieldMultiTS> ret;
9013   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9014   if(content)
9015     {
9016       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9017       if(!contc)
9018         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9019       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9020       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
9021     }
9022   else
9023     ret=MEDFileIntFieldMultiTS::New();
9024   if(isDeepCpyGlobs)
9025     ret->deepCpyGlobs(*this);
9026   else
9027     ret->shallowCpyGlobs(*this);
9028   return ret.retn();
9029 }
9030
9031 /*!
9032  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9033  *  \param [in] pos - a time step id.
9034  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9035  *          delete this field using decrRef() as it is no more needed.
9036  *  \throw If \a pos is not a valid time step id.
9037  */
9038 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9039 {
9040   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9041   if(!item)
9042     {
9043       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9044       throw INTERP_KERNEL::Exception(oss.str().c_str());
9045     }
9046   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9047   if(itemC)
9048     {
9049       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9050       ret->shallowCpyGlobs(*this);
9051       return ret.retn();
9052     }
9053   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9054   throw INTERP_KERNEL::Exception(oss.str().c_str());
9055 }
9056
9057 /*!
9058  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9059  * mesh entities of a given dimension of the first mesh in MED file.
9060  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9061  *  \param [in] type - a spatial discretization of interest.
9062  *  \param [in] iteration - the iteration number of a required time step.
9063  *  \param [in] order - the iteration order number of required time step.
9064  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9065  *  \param [in] renumPol - specifies how to permute values of the result field according to
9066  *          the optional numbers of cells and nodes, if any. The valid values are
9067  *          - 0 - do not permute.
9068  *          - 1 - permute cells.
9069  *          - 2 - permute nodes.
9070  *          - 3 - permute cells and nodes.
9071  *
9072  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9073  *          caller is to delete this field using decrRef() as it is no more needed. 
9074  *  \throw If the MED file is not readable.
9075  *  \throw If there is no mesh in the MED file.
9076  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9077  *  \throw If no field values of the required parameters are available.
9078  */
9079 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9080 {
9081   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9082   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9083   if(!myF1TSC)
9084     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9085   MCAuto<DataArray> arrOut;
9086   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9087   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9088   return ret.retn();
9089 }
9090
9091 /*!
9092  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9093  * the top level cells of the first mesh in MED file.
9094  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9095  *  \param [in] type - a spatial discretization of interest.
9096  *  \param [in] iteration - the iteration number of a required time step.
9097  *  \param [in] order - the iteration order number of required time step.
9098  *  \param [in] renumPol - specifies how to permute values of the result field according to
9099  *          the optional numbers of cells and nodes, if any. The valid values are
9100  *          - 0 - do not permute.
9101  *          - 1 - permute cells.
9102  *          - 2 - permute nodes.
9103  *          - 3 - permute cells and nodes.
9104  *
9105  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9106  *          caller is to delete this field using decrRef() as it is no more needed. 
9107  *  \throw If the MED file is not readable.
9108  *  \throw If there is no mesh in the MED file.
9109  *  \throw If no field values of the required parameters are available.
9110  */
9111 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9112 {
9113   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9114   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9115   if(!myF1TSC)
9116     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9117   MCAuto<DataArray> arrOut;
9118   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9119   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9120   return ret.retn();
9121 }
9122
9123 /*!
9124  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9125  * a given support.
9126  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9127  *  \param [in] type - a spatial discretization of interest.
9128  *  \param [in] iteration - the iteration number of a required time step.
9129  *  \param [in] order - the iteration order number of required time step.
9130  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9131  *  \param [in] mesh - the supporting mesh.
9132  *  \param [in] renumPol - specifies how to permute values of the result field according to
9133  *          the optional numbers of cells and nodes, if any. The valid values are
9134  *          - 0 - do not permute.
9135  *          - 1 - permute cells.
9136  *          - 2 - permute nodes.
9137  *          - 3 - permute cells and nodes.
9138  *
9139  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9140  *          caller is to delete this field using decrRef() as it is no more needed. 
9141  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9142  *  \throw If no field of \a this is lying on \a mesh.
9143  *  \throw If no field values of the required parameters are available.
9144  */
9145 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9146 {
9147   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9148   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9149   if(!myF1TSC)
9150     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9151   MCAuto<DataArray> arrOut;
9152   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9153   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9154   return ret.retn();
9155 }
9156
9157 /*!
9158  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9159  * given support. 
9160  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9161  *  \param [in] type - a spatial discretization of the new field.
9162  *  \param [in] iteration - the iteration number of a required time step.
9163  *  \param [in] order - the iteration order number of required time step.
9164  *  \param [in] mesh - the supporting mesh.
9165  *  \param [in] renumPol - specifies how to permute values of the result field according to
9166  *          the optional numbers of cells and nodes, if any. The valid values are
9167  *          - 0 - do not permute.
9168  *          - 1 - permute cells.
9169  *          - 2 - permute nodes.
9170  *          - 3 - permute cells and nodes.
9171  *
9172  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9173  *          caller is to delete this field using decrRef() as it is no more needed. 
9174  *  \throw If no field of \a this is lying on \a mesh.
9175  *  \throw If no field values of the required parameters are available.
9176  */
9177 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9178 {
9179   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9180   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9181   if(!myF1TSC)
9182     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9183   MCAuto<DataArray> arrOut;
9184   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9185   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9186   return ret.retn();
9187 }
9188
9189 /*!
9190  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9191  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9192  * This method is useful for MED2 file format when field on different mesh was autorized.
9193  */
9194 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9195 {
9196   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9197   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9198   if(!myF1TSC)
9199     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9200   MCAuto<DataArray> arrOut;
9201   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9202   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9203   return ret.retn();
9204 }
9205
9206 /*!
9207  * Returns values and a profile of the field of a given type, of a given time step,
9208  * lying on a given support.
9209  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9210  *  \param [in] type - a spatial discretization of the field.
9211  *  \param [in] iteration - the iteration number of a required time step.
9212  *  \param [in] order - the iteration order number of required time step.
9213  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9214  *  \param [in] mesh - the supporting mesh.
9215  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9216  *          field of interest lies on. If the field lies on all entities of the given
9217  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9218  *          using decrRef() as it is no more needed.  
9219  *  \param [in] glob - the global data storing profiles and localization.
9220  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9221  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9222  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9223  *  \throw If no field of \a this is lying on \a mesh.
9224  *  \throw If no field values of the required parameters are available.
9225  */
9226 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9227 {
9228   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9229   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9230   if(!myF1TSC)
9231     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9232   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9233   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9234 }
9235
9236 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9237 {
9238   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9239   if(!pt)
9240     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9241   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9242   if(!ret)
9243     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 !");
9244   return ret;
9245 }
9246
9247 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9248 {
9249   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9250   if(!pt)
9251     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9252   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9253   if(!ret)
9254     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 !");
9255   return ret;
9256 }
9257
9258 /*!
9259  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9260  * the given field is checked if its elements are sorted suitable for writing to MED file
9261  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9262  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9263  *  \param [in] field - the field to add to \a this.
9264  *  \throw If the name of \a field is empty.
9265  *  \throw If the data array of \a field is not set.
9266  *  \throw If existing time steps have different name or number of components than \a field.
9267  *  \throw If the underlying mesh of \a field has no name.
9268  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9269  */
9270 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9271 {
9272   const DataArrayDouble *arr=0;
9273   if(field)
9274     arr=field->getArray();
9275   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9276 }
9277
9278 /*!
9279  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9280  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9281  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9282  * and \a profile.
9283  *
9284  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9285  * A new profile is added only if no equal profile is missing.
9286  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9287  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9288  *  \param [in] mesh - the supporting mesh of \a field.
9289  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9290  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9291  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9292  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9293  *  \throw If the data array of \a field is not set.
9294  *  \throw If the data array of \a this is already allocated but has different number of
9295  *         components than \a field.
9296  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9297  *  \sa setFieldNoProfileSBT()
9298  */
9299 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9300 {
9301   const DataArrayDouble *arr=0;
9302   if(field)
9303     arr=field->getArray();
9304   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9305 }
9306
9307 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9308 {
9309   _content=new MEDFileFieldMultiTSWithoutSDA;
9310 }
9311
9312 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9313 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9314 {
9315 }
9316 catch(INTERP_KERNEL::Exception& e)
9317 { throw e; }
9318
9319 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9320 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9321 {
9322 }
9323 catch(INTERP_KERNEL::Exception& e)
9324 { throw e; }
9325
9326 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9327 {
9328 }
9329
9330 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
9331 {
9332   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9333 }
9334
9335 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9336 {
9337   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9338 }
9339
9340 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9341 {
9342   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9343 }
9344
9345 //= MEDFileAnyTypeFieldMultiTSIterator
9346
9347 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9348 {
9349   if(fmts)
9350     {
9351       fmts->incrRef();
9352       _nb_iter=fmts->getNumberOfTS();
9353     }
9354 }
9355
9356 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9357 {
9358 }
9359
9360 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9361 {
9362   if(_iter_id<_nb_iter)
9363     {
9364       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9365       if(fmts)
9366         return fmts->getTimeStepAtPos(_iter_id++);
9367       else
9368         return 0;
9369     }
9370   else
9371     return 0;
9372 }
9373
9374 //= MEDFileIntFieldMultiTS
9375
9376 /*!
9377  * Returns a new empty instance of MEDFileFieldMultiTS.
9378  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9379  *          is to delete this field using decrRef() as it is no more needed.
9380  */
9381 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9382 {
9383   return new MEDFileIntFieldMultiTS;
9384 }
9385
9386 /*!
9387  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9388  * that has been read from a specified MED file.
9389  *  \param [in] fileName - the name of the MED file to read.
9390  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9391  *          is to delete this field using decrRef() as it is no more needed.
9392  *  \throw If reading the file fails.
9393  */
9394 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9395 {
9396   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9397   ret->contentNotNull();//to check that content type matches with \a this type.
9398   return ret.retn();
9399 }
9400
9401 /*!
9402  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9403  * that has been read from a specified MED file.
9404  *  \param [in] fileName - the name of the MED file to read.
9405  *  \param [in] fieldName - the name of the field to read.
9406  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9407  *          is to delete this field using decrRef() as it is no more needed.
9408  *  \throw If reading the file fails.
9409  *  \throw If there is no field named \a fieldName in the file.
9410  */
9411 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9412 {
9413   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9414   ret->contentNotNull();//to check that content type matches with \a this type.
9415   return ret.retn();
9416 }
9417
9418 /*!
9419  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9420  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9421  *
9422  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9423  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9424  * \warning this is a shallow copy constructor
9425  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9426  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9427  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9428  *          is to delete this field using decrRef() as it is no more needed.
9429  */
9430 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9431 {
9432   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9433 }
9434
9435 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9436 {
9437   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0,&entities);
9438   ret->contentNotNull();//to check that content type matches with \a this type.
9439   return ret.retn();
9440 }
9441
9442 /*!
9443  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9444  * following the given input policy.
9445  *
9446  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9447  *                            By default (true) the globals are deeply copied.
9448  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9449  */
9450 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9451 {
9452   MCAuto<MEDFileFieldMultiTS> ret;
9453   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9454   if(content)
9455     {
9456       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9457       if(!contc)
9458         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9459       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9460       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9461     }
9462   else
9463     ret=MEDFileFieldMultiTS::New();
9464   if(isDeepCpyGlobs)
9465     ret->deepCpyGlobs(*this);
9466   else
9467     ret->shallowCpyGlobs(*this);
9468   return ret.retn();
9469 }
9470
9471 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9472 {
9473   return new MEDFileIntFieldMultiTS(*this);
9474 }
9475
9476 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9477 {
9478   if(!f1ts)
9479     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9480   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9481   if(!f1tsC)
9482     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9483 }
9484
9485 /*!
9486  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9487  * mesh entities of a given dimension of the first mesh in MED file.
9488  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9489  *  \param [in] type - a spatial discretization of interest.
9490  *  \param [in] iteration - the iteration number of a required time step.
9491  *  \param [in] order - the iteration order number of required time step.
9492  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9493  *  \param [out] arrOut - the DataArrayInt containing values of field.
9494  *  \param [in] renumPol - specifies how to permute values of the result field according to
9495  *          the optional numbers of cells and nodes, if any. The valid values are
9496  *          - 0 - do not permute.
9497  *          - 1 - permute cells.
9498  *          - 2 - permute nodes.
9499  *          - 3 - permute cells and nodes.
9500  *
9501  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9502  *          caller is to delete this field using decrRef() as it is no more needed. 
9503  *  \throw If the MED file is not readable.
9504  *  \throw If there is no mesh in the MED file.
9505  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9506  *  \throw If no field values of the required parameters are available.
9507  */
9508 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9509 {
9510   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9511   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9512   if(!myF1TSC)
9513     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9514   MCAuto<DataArray> arr;
9515   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9516   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9517   return ret.retn();
9518 }
9519
9520 /*!
9521  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9522  * the top level cells of the first mesh in MED file.
9523  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9524  *  \param [in] type - a spatial discretization of interest.
9525  *  \param [in] iteration - the iteration number of a required time step.
9526  *  \param [in] order - the iteration order number of required time step.
9527  *  \param [out] arrOut - the DataArrayInt containing values of field.
9528  *  \param [in] renumPol - specifies how to permute values of the result field according to
9529  *          the optional numbers of cells and nodes, if any. The valid values are
9530  *          - 0 - do not permute.
9531  *          - 1 - permute cells.
9532  *          - 2 - permute nodes.
9533  *          - 3 - permute cells and nodes.
9534  *
9535  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9536  *          caller is to delete this field using decrRef() as it is no more needed. 
9537  *  \throw If the MED file is not readable.
9538  *  \throw If there is no mesh in the MED file.
9539  *  \throw If no field values of the required parameters are available.
9540  */
9541 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9542 {
9543   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9544   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9545   if(!myF1TSC)
9546     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9547   MCAuto<DataArray> arr;
9548   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9549   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9550   return ret.retn();
9551 }
9552
9553 /*!
9554  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9555  * a given support.
9556  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9557  *  \param [in] type - a spatial discretization of interest.
9558  *  \param [in] iteration - the iteration number of a required time step.
9559  *  \param [in] order - the iteration order number of required time step.
9560  *  \param [out] arrOut - the DataArrayInt containing values of field.
9561  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9562  *  \param [in] mesh - the supporting mesh.
9563  *  \param [in] renumPol - specifies how to permute values of the result field according to
9564  *          the optional numbers of cells and nodes, if any. The valid values are
9565  *          - 0 - do not permute.
9566  *          - 1 - permute cells.
9567  *          - 2 - permute nodes.
9568  *          - 3 - permute cells and nodes.
9569  *
9570  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9571  *          caller is to delete this field using decrRef() as it is no more needed. 
9572  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9573  *  \throw If no field of \a this is lying on \a mesh.
9574  *  \throw If no field values of the required parameters are available.
9575  */
9576 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9577 {
9578   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9579   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9580   if(!myF1TSC)
9581     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9582   MCAuto<DataArray> arr;
9583   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9584   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9585   return ret.retn();
9586 }
9587
9588 /*!
9589  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9590  * given support. 
9591  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9592  *  \param [in] type - a spatial discretization of the new field.
9593  *  \param [in] iteration - the iteration number of a required time step.
9594  *  \param [in] order - the iteration order number of required time step.
9595  *  \param [in] mesh - the supporting mesh.
9596  *  \param [out] arrOut - the DataArrayInt containing values of field.
9597  *  \param [in] renumPol - specifies how to permute values of the result field according to
9598  *          the optional numbers of cells and nodes, if any. The valid values are
9599  *          - 0 - do not permute.
9600  *          - 1 - permute cells.
9601  *          - 2 - permute nodes.
9602  *          - 3 - permute cells and nodes.
9603  *
9604  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9605  *          caller is to delete this field using decrRef() as it is no more needed. 
9606  *  \throw If no field of \a this is lying on \a mesh.
9607  *  \throw If no field values of the required parameters are available.
9608  */
9609 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9610 {
9611   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9612   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9613   if(!myF1TSC)
9614     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9615   MCAuto<DataArray> arr;
9616   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9617   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9618   return ret.retn();
9619 }
9620
9621 /*!
9622  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9623  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9624  * This method is useful for MED2 file format when field on different mesh was autorized.
9625  */
9626 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9627 {
9628   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9629   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9630   if(!myF1TSC)
9631     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9632   MCAuto<DataArray> arr;
9633   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9634   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9635   return ret.retn();
9636 }
9637
9638 /*!
9639  * Returns values and a profile of the field of a given type, of a given time step,
9640  * lying on a given support.
9641  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9642  *  \param [in] type - a spatial discretization of the field.
9643  *  \param [in] iteration - the iteration number of a required time step.
9644  *  \param [in] order - the iteration order number of required time step.
9645  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9646  *  \param [in] mesh - the supporting mesh.
9647  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9648  *          field of interest lies on. If the field lies on all entities of the given
9649  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9650  *          using decrRef() as it is no more needed.  
9651  *  \param [in] glob - the global data storing profiles and localization.
9652  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9653  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9654  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9655  *  \throw If no field of \a this is lying on \a mesh.
9656  *  \throw If no field values of the required parameters are available.
9657  */
9658 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9659 {
9660   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9661   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9662   if(!myF1TSC)
9663     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9664   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9665   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9666 }
9667
9668 /*!
9669  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9670  *  \param [in] pos - a time step id.
9671  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9672  *          delete this field using decrRef() as it is no more needed.
9673  *  \throw If \a pos is not a valid time step id.
9674  */
9675 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9676 {
9677   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9678   if(!item)
9679     {
9680       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9681       throw INTERP_KERNEL::Exception(oss.str().c_str());
9682     }
9683   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9684   if(itemC)
9685     {
9686       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9687       ret->shallowCpyGlobs(*this);
9688       return ret.retn();
9689     }
9690   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9691   throw INTERP_KERNEL::Exception(oss.str().c_str());
9692 }
9693
9694 /*!
9695  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9696  * the given field is checked if its elements are sorted suitable for writing to MED file
9697  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9698  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9699  *  \param [in] field - the field to add to \a this.
9700  *  \throw If the name of \a field is empty.
9701  *  \throw If the data array of \a field is not set.
9702  *  \throw If existing time steps have different name or number of components than \a field.
9703  *  \throw If the underlying mesh of \a field has no name.
9704  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9705  */
9706 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9707 {
9708   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9709 }
9710
9711 /*!
9712  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9713  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9714  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9715  * and \a profile.
9716  *
9717  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9718  * A new profile is added only if no equal profile is missing.
9719  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9720  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9721  *  \param [in] arrOfVals - the values of the field \a field used.
9722  *  \param [in] mesh - the supporting mesh of \a field.
9723  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9724  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9725  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9726  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9727  *  \throw If the data array of \a field is not set.
9728  *  \throw If the data array of \a this is already allocated but has different number of
9729  *         components than \a field.
9730  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9731  *  \sa setFieldNoProfileSBT()
9732  */
9733 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9734 {
9735   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9736 }
9737
9738 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9739 {
9740   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9741   if(!pt)
9742     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9743   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9744   if(!ret)
9745     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 !");
9746   return ret;
9747 }
9748
9749 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9750 {
9751   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9752   if(!pt)
9753     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9754   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9755   if(!ret)
9756     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 !");
9757   return ret;
9758 }
9759
9760 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9761 {
9762   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9763 }
9764
9765 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9766 {
9767 }
9768
9769 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9770 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9771 {
9772 }
9773 catch(INTERP_KERNEL::Exception& e)
9774 { throw e; }
9775
9776 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9777 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9778 {
9779 }
9780 catch(INTERP_KERNEL::Exception& e)
9781 { throw e; }
9782
9783 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9784 {
9785   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9786 }
9787
9788 //= MEDFileFields
9789
9790 MEDFileFields *MEDFileFields::New()
9791 {
9792   return new MEDFileFields;
9793 }
9794
9795 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9796 {
9797   return new MEDFileFields(fileName,loadAll,0,0);
9798 }
9799
9800 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9801 {
9802   return new MEDFileFields(fileName,loadAll,ms,0);
9803 }
9804
9805 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9806 {
9807   return new MEDFileFields(fileName,loadAll,0,&entities);
9808 }
9809
9810 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9811 {
9812   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9813   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9814   return ret;
9815 }
9816
9817 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9818 {
9819   std::vector<const BigMemoryObject *> ret;
9820   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9821     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9822   return ret;
9823 }
9824
9825 MEDFileFields *MEDFileFields::deepCopy() const
9826 {
9827   MCAuto<MEDFileFields> ret=shallowCpy();
9828   std::size_t i=0;
9829   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9830     {
9831       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9832         ret->_fields[i]=(*it)->deepCopy();
9833     }
9834   ret->deepCpyGlobs(*this);
9835   return ret.retn();
9836 }
9837
9838 MEDFileFields *MEDFileFields::shallowCpy() const
9839 {
9840   return new MEDFileFields(*this);
9841 }
9842
9843 /*!
9844  * 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
9845  * 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.
9846  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9847  *
9848  * \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.
9849  * \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.
9850  * 
9851  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9852  */
9853 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9854 {
9855   std::set< std::pair<int,int> > s;
9856   bool firstShot=true;
9857   areThereSomeForgottenTS=false;
9858   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9859     {
9860       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9861         continue;
9862       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9863       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9864       if(firstShot)
9865         { s=s1; firstShot=false; }
9866       else
9867         {
9868           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9869           if(s!=s2)
9870             areThereSomeForgottenTS=true;
9871           s=s2;
9872         }
9873     }
9874   std::vector< std::pair<int,int> > ret;
9875   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9876   return ret;
9877 }
9878
9879 int MEDFileFields::getNumberOfFields() const
9880 {
9881   return _fields.size();
9882 }
9883
9884 std::vector<std::string> MEDFileFields::getFieldsNames() const
9885 {
9886   std::vector<std::string> ret(_fields.size());
9887   int i=0;
9888   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9889     {
9890       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9891       if(f)
9892         {
9893           ret[i]=f->getName();
9894         }
9895       else
9896         {
9897           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9898           throw INTERP_KERNEL::Exception(oss.str().c_str());
9899         }
9900     }
9901   return ret;
9902 }
9903
9904 std::vector<std::string> MEDFileFields::getMeshesNames() const
9905 {
9906   std::vector<std::string> ret;
9907   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9908     {
9909       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9910       if(cur)
9911         ret.push_back(cur->getMeshName());
9912     }
9913   return ret;
9914 }
9915
9916 std::string MEDFileFields::simpleRepr() const
9917 {
9918   std::ostringstream oss;
9919   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9920   simpleRepr(0,oss);
9921   return oss.str();
9922 }
9923
9924 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9925 {
9926   int nbOfFields=getNumberOfFields();
9927   std::string startLine(bkOffset,' ');
9928   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9929   int i=0;
9930   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9931     {
9932       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9933       if(cur)
9934         {
9935           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9936         }
9937       else
9938         {
9939           oss << startLine << "  - not defined !" << std::endl;
9940         }
9941     }
9942   i=0;
9943   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9944     {
9945       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9946       std::string chapter(17,'0'+i);
9947       oss << startLine << chapter << std::endl;
9948       if(cur)
9949         {
9950           cur->simpleRepr(bkOffset+2,oss,i);
9951         }
9952       else
9953         {
9954           oss << startLine << "  - not defined !" << std::endl;
9955         }
9956       oss << startLine << chapter << std::endl;
9957     }
9958   simpleReprGlobs(oss);
9959 }
9960
9961 MEDFileFields::MEDFileFields()
9962 {
9963 }
9964
9965 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9966 try:MEDFileFieldGlobsReal(fileName)
9967 {
9968   MEDFileUtilities::CheckFileForRead(fileName);
9969   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
9970   int nbFields(MEDnField(fid));
9971   _fields.resize(nbFields);
9972   med_field_type typcha;
9973   for(int i=0;i<nbFields;i++)
9974     {
9975       std::vector<std::string> infos;
9976       std::string fieldName,dtunit;
9977       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
9978       switch(typcha)
9979       {
9980         case MED_FLOAT64:
9981           {
9982             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9983             break;
9984           }
9985         case MED_INT32:
9986           {
9987             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9988             break;
9989           }
9990         default:
9991           {
9992             std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << fileName << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
9993             throw INTERP_KERNEL::Exception(oss.str().c_str());
9994           }
9995       }
9996     }
9997   loadAllGlobals(fid);
9998 }
9999 catch(INTERP_KERNEL::Exception& e)
10000 {
10001     throw e;
10002 }
10003
10004 void MEDFileFields::writeLL(med_idt fid) const
10005 {
10006   int i=0;
10007   writeGlobals(fid,*this);
10008   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10009     {
10010       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10011       if(!elt)
10012         {
10013           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10014           throw INTERP_KERNEL::Exception(oss.str().c_str());
10015         }
10016       elt->writeLL(fid,*this);
10017     }
10018 }
10019
10020 void MEDFileFields::write(const std::string& fileName, int mode) const
10021 {
10022   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
10023   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
10024   writeLL(fid);
10025 }
10026
10027 /*!
10028  * This method alloc the arrays and load potentially huge arrays contained in this field.
10029  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10030  * This method can be also called to refresh or reinit values from a file.
10031  * 
10032  * \throw If the fileName is not set or points to a non readable MED file.
10033  */
10034 void MEDFileFields::loadArrays()
10035 {
10036   if(getFileName().empty())
10037     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10038   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10039   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10040     {
10041       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10042       if(elt)
10043         elt->loadBigArraysRecursively(fid,*elt);
10044     }
10045 }
10046
10047 /*!
10048  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10049  * But once data loaded once, this method does nothing.
10050  * 
10051  * \throw If the fileName is not set or points to a non readable MED file.
10052  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10053  */
10054 void MEDFileFields::loadArraysIfNecessary()
10055 {
10056   if(!getFileName().empty())
10057     {
10058       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10059       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10060         {
10061           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10062           if(elt)
10063             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10064         }
10065     }
10066 }
10067
10068 /*!
10069  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10070  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10071  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10072  * 
10073  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10074  */
10075 void MEDFileFields::unloadArrays()
10076 {
10077   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10078     {
10079       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10080       if(elt)
10081         elt->unloadArrays();
10082     }
10083 }
10084
10085 /*!
10086  * 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.
10087  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10088  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10089  * 
10090  * \sa MEDFileFields::loadArraysIfNecessary
10091  */
10092 void MEDFileFields::unloadArraysWithoutDataLoss()
10093 {
10094   if(!getFileName().empty())
10095     unloadArrays();
10096 }
10097
10098 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10099 {
10100   std::vector<std::string> ret;
10101   std::set<std::string> ret2;
10102   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10103     {
10104       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10105       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10106         if(ret2.find(*it2)==ret2.end())
10107           {
10108             ret.push_back(*it2);
10109             ret2.insert(*it2);
10110           }
10111     }
10112   return ret;
10113 }
10114
10115 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10116 {
10117   std::vector<std::string> ret;
10118   std::set<std::string> ret2;
10119   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10120     {
10121       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10122       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10123         if(ret2.find(*it2)==ret2.end())
10124           {
10125             ret.push_back(*it2);
10126             ret2.insert(*it2);
10127           }
10128     }
10129   return ret;
10130 }
10131
10132 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10133 {
10134   std::vector<std::string> ret;
10135   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10136     {
10137       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
10138       ret.insert(ret.end(),tmp.begin(),tmp.end());
10139     }
10140   return ret;
10141 }
10142
10143 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10144 {
10145   std::vector<std::string> ret;
10146   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10147     {
10148       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10149       ret.insert(ret.end(),tmp.begin(),tmp.end());
10150     }
10151   return ret;
10152 }
10153
10154 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10155 {
10156   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10157     (*it)->changePflsRefsNamesGen2(mapOfModif);
10158 }
10159
10160 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10161 {
10162   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10163     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10164 }
10165
10166 void MEDFileFields::resize(int newSize)
10167 {
10168   _fields.resize(newSize);
10169 }
10170
10171 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10172 {
10173   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10174     pushField(*it);
10175 }
10176
10177 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10178 {
10179   if(!field)
10180     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10181   _fields.push_back(field->getContent());
10182   appendGlobs(*field,1e-12);
10183 }
10184
10185 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10186 {
10187   if(!field)
10188     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10189   if(i>=(int)_fields.size())
10190     _fields.resize(i+1);
10191   _fields[i]=field->getContent();
10192   appendGlobs(*field,1e-12);
10193 }
10194
10195 void MEDFileFields::destroyFieldAtPos(int i)
10196 {
10197   destroyFieldsAtPos(&i,&i+1);
10198 }
10199
10200 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10201 {
10202   std::vector<bool> b(_fields.size(),true);
10203   for(const int *i=startIds;i!=endIds;i++)
10204     {
10205       if(*i<0 || *i>=(int)_fields.size())
10206         {
10207           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10208           throw INTERP_KERNEL::Exception(oss.str().c_str());
10209         }
10210       b[*i]=false;
10211     }
10212   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10213   std::size_t j=0;
10214   for(std::size_t i=0;i<_fields.size();i++)
10215     if(b[i])
10216       fields[j++]=_fields[i];
10217   _fields=fields;
10218 }
10219
10220 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10221 {
10222   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10223   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
10224   std::vector<bool> b(_fields.size(),true);
10225   int k=bg;
10226   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10227     {
10228       if(k<0 || k>=(int)_fields.size())
10229         {
10230           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10231           throw INTERP_KERNEL::Exception(oss.str().c_str());
10232         }
10233       b[k]=false;
10234     }
10235   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10236   std::size_t j=0;
10237   for(std::size_t i=0;i<_fields.size();i++)
10238     if(b[i])
10239       fields[j++]=_fields[i];
10240   _fields=fields;
10241 }
10242
10243 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10244 {
10245   bool ret=false;
10246   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10247     {
10248       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10249       if(cur)
10250         ret=cur->changeMeshNames(modifTab) || ret;
10251     }
10252   return ret;
10253 }
10254
10255 /*!
10256  * \param [in] meshName the name of the mesh that will be renumbered.
10257  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10258  *             This code corresponds to the distribution of types in the corresponding mesh.
10259  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10260  * \param [in] renumO2N the old to new renumber array.
10261  * \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 
10262  *         field in \a this.
10263  */
10264 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10265 {
10266   bool ret=false;
10267   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10268     {
10269       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10270       if(fmts)
10271         {
10272           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10273         }
10274     }
10275   return ret;
10276 }
10277
10278 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10279 {
10280   if(i<0 || i>=(int)_fields.size())
10281     {
10282       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10283       throw INTERP_KERNEL::Exception(oss.str().c_str());
10284     }
10285   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10286   if(!fmts)
10287     return 0;
10288   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
10289   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
10290   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
10291   if(fmtsC)
10292     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10293   else if(fmtsC2)
10294     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10295   else
10296     {
10297       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10298       throw INTERP_KERNEL::Exception(oss.str().c_str());
10299     }
10300   ret->shallowCpyGlobs(*this);
10301   return ret.retn();
10302 }
10303
10304 /*!
10305  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10306  * This method is accessible in python using __getitem__ with a list in input.
10307  * \return a new object that the caller should deal with.
10308  */
10309 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10310 {
10311   MCAuto<MEDFileFields> ret=shallowCpy();
10312   std::size_t sz=std::distance(startIds,endIds);
10313   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10314   int j=0;
10315   for(const int *i=startIds;i!=endIds;i++,j++)
10316     {
10317       if(*i<0 || *i>=(int)_fields.size())
10318         {
10319           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10320           throw INTERP_KERNEL::Exception(oss.str().c_str());
10321         }
10322       fields[j]=_fields[*i];
10323     }
10324   ret->_fields=fields;
10325   return ret.retn();
10326 }
10327
10328 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10329 {
10330   return getFieldAtPos(getPosFromFieldName(fieldName));
10331 }
10332
10333 /*!
10334  * This method removes, if any, fields in \a this having no time steps.
10335  * 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.
10336  * 
10337  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10338  */
10339 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10340 {
10341   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10342   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10343     {
10344       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10345       if(elt)
10346         {
10347           if(elt->getNumberOfTS()>0)
10348             newFields.push_back(*it);
10349         }
10350     }
10351   if(_fields.size()==newFields.size())
10352     return false;
10353   _fields=newFields;
10354   return true;
10355 }
10356
10357 /*!
10358  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10359  * This method can be seen as a filter applied on \a this, that returns an object containing
10360  * 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
10361  * shallow copied from \a this.
10362  * 
10363  * \param [in] meshName - the name of the mesh on w
10364  * \return a new object that the caller should deal with.
10365  */
10366 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10367 {
10368   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10369   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10370     {
10371       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10372       if(!cur)
10373         continue;
10374       if(cur->getMeshName()==meshName)
10375         {
10376           cur->incrRef();
10377           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10378           ret->_fields.push_back(cur2);
10379         }
10380     }
10381   ret->shallowCpyOnlyUsedGlobs(*this);
10382   return ret.retn();
10383 }
10384
10385 /*!
10386  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10387  * Input time steps are specified using a pair of integer (iteration, order).
10388  * 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,
10389  * but for each multitimestep only the time steps in \a timeSteps are kept.
10390  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10391  * 
10392  * The returned object points to shallow copy of elements in \a this.
10393  * 
10394  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10395  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10396  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10397  */
10398 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10399 {
10400   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10401   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10402     {
10403       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10404       if(!cur)
10405         continue;
10406       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10407       ret->_fields.push_back(elt);
10408     }
10409   ret->shallowCpyOnlyUsedGlobs(*this);
10410   return ret.retn();
10411 }
10412
10413 /*!
10414  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10415  */
10416 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10417 {
10418   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10419   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10420     {
10421       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10422       if(!cur)
10423         continue;
10424       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10425       if(elt->getNumberOfTS()!=0)
10426         ret->_fields.push_back(elt);
10427     }
10428   ret->shallowCpyOnlyUsedGlobs(*this);
10429   return ret.retn();
10430 }
10431
10432 MEDFileFieldsIterator *MEDFileFields::iterator()
10433 {
10434   return new MEDFileFieldsIterator(this);
10435 }
10436
10437 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10438 {
10439   std::string tmp(fieldName);
10440   std::vector<std::string> poss;
10441   for(std::size_t i=0;i<_fields.size();i++)
10442     {
10443       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10444       if(f)
10445         {
10446           std::string fname(f->getName());
10447           if(tmp==fname)
10448             return i;
10449           else
10450             poss.push_back(fname);
10451         }
10452     }
10453   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10454   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10455   oss << " !";
10456   throw INTERP_KERNEL::Exception(oss.str().c_str());
10457 }
10458
10459 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10460 {
10461   if(fs)
10462     {
10463       fs->incrRef();
10464       _nb_iter=fs->getNumberOfFields();
10465     }
10466 }
10467
10468 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10469 {
10470 }
10471
10472 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10473 {
10474   if(_iter_id<_nb_iter)
10475     {
10476       MEDFileFields *fs(_fs);
10477       if(fs)
10478         return fs->getFieldAtPos(_iter_id++);
10479       else
10480         return 0;
10481     }
10482   else
10483     return 0;
10484 }