]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDFileField.cxx
Salome HOME
Useful extractPart method on MEDFileField series.
[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 /*!
6368  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6369  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6370  *
6371  * \return A new object that the caller is responsible to deallocate.
6372  */
6373 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6374 {
6375   if(!mm)
6376     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6377   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6378   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6379   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6380     {
6381       if((*it0)!=ON_NODES)
6382         {
6383           std::vector<int> levs;
6384           getNonEmptyLevels(mm->getName(),levs);
6385           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6386             {
6387               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6388               if(it2!=extractDef.end())
6389                 {
6390                   MCAuto<DataArrayInt> t((*it2).second);
6391                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6392                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6393                   ret->setFieldNoProfileSBT(fOut);
6394                 }
6395             }
6396         }
6397       else
6398         {
6399           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6400           if(it2==extractDef.end())
6401             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6402           MCAuto<DataArrayInt> t((*it2).second);
6403           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6404           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6405           DataArrayDouble *arr(f->getArray());
6406           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6407           fOut->setArray(newArr);
6408           ret->setFieldNoProfileSBT(fOut);
6409         }
6410     }
6411   return ret.retn();
6412 }
6413
6414 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6415 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6416 {
6417 }
6418 catch(INTERP_KERNEL::Exception& e)
6419 { throw e; }
6420
6421 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6422 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6423 {
6424 }
6425 catch(INTERP_KERNEL::Exception& e)
6426 { throw e; }
6427
6428 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6429 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6430 {
6431 }
6432 catch(INTERP_KERNEL::Exception& e)
6433 { throw e; }
6434
6435 /*!
6436  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6437  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6438  *
6439  * \warning this is a shallow copy constructor
6440  */
6441 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6442 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6443 {
6444 }
6445 catch(INTERP_KERNEL::Exception& e)
6446 { throw e; }
6447
6448 MEDFileField1TS::MEDFileField1TS()
6449 {
6450   _content=new MEDFileField1TSWithoutSDA;
6451 }
6452
6453 /*!
6454  * Returns a new MEDCouplingFieldDouble of a given type lying on
6455  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6456  * has not been constructed via file reading, an exception is thrown.
6457  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6458  *  \param [in] type - a spatial discretization of interest.
6459  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6460  *  \param [in] renumPol - specifies how to permute values of the result field according to
6461  *          the optional numbers of cells and nodes, if any. The valid values are
6462  *          - 0 - do not permute.
6463  *          - 1 - permute cells.
6464  *          - 2 - permute nodes.
6465  *          - 3 - permute cells and nodes.
6466  *
6467  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6468  *          caller is to delete this field using decrRef() as it is no more needed. 
6469  *  \throw If \a this field has not been constructed via file reading.
6470  *  \throw If the MED file is not readable.
6471  *  \throw If there is no mesh in the MED file.
6472  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6473  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6474  *  \sa getFieldOnMeshAtLevel()
6475  */
6476 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6477 {
6478   if(getFileName().empty())
6479     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6480   MCAuto<DataArray> arrOut;
6481   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6482   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6483   return ret.retn();
6484 }
6485
6486 /*!
6487  * Returns a new MEDCouplingFieldDouble of a given type lying on
6488  * the top level cells of the first mesh in MED file. If \a this field 
6489  * has not been constructed via file reading, an exception is thrown.
6490  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6491  *  \param [in] type - a spatial discretization of interest.
6492  *  \param [in] renumPol - specifies how to permute values of the result field according to
6493  *          the optional numbers of cells and nodes, if any. The valid values are
6494  *          - 0 - do not permute.
6495  *          - 1 - permute cells.
6496  *          - 2 - permute nodes.
6497  *          - 3 - permute cells and nodes.
6498  *
6499  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6500  *          caller is to delete this field using decrRef() as it is no more needed. 
6501  *  \throw If \a this field has not been constructed via file reading.
6502  *  \throw If the MED file is not readable.
6503  *  \throw If there is no mesh in the MED file.
6504  *  \throw If no field values of the given \a type.
6505  *  \throw If no field values lying on the top level support.
6506  *  \sa getFieldAtLevel()
6507  */
6508 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6509 {
6510   if(getFileName().empty())
6511     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6512   MCAuto<DataArray> arrOut;
6513   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6514   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6515   return ret.retn();
6516 }
6517
6518 /*!
6519  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6520  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6521  *  \param [in] type - a spatial discretization of the new field.
6522  *  \param [in] mesh - the supporting mesh.
6523  *  \param [in] renumPol - specifies how to permute values of the result field according to
6524  *          the optional numbers of cells and nodes, if any. The valid values are
6525  *          - 0 - do not permute.
6526  *          - 1 - permute cells.
6527  *          - 2 - permute nodes.
6528  *          - 3 - permute cells and nodes.
6529  *
6530  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6531  *          caller is to delete this field using decrRef() as it is no more needed. 
6532  *  \throw If no field of \a this is lying on \a mesh.
6533  *  \throw If the mesh is empty.
6534  *  \throw If no field values of the given \a type are available.
6535  *  \sa getFieldAtLevel()
6536  *  \sa getFieldOnMeshAtLevel() 
6537  */
6538 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6539 {
6540   MCAuto<DataArray> arrOut;
6541   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6542   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6543   return ret.retn();
6544 }
6545
6546 /*!
6547  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6548  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6549  *  \param [in] type - a spatial discretization of interest.
6550  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6551  *  \param [in] mesh - the supporting mesh.
6552  *  \param [in] renumPol - specifies how to permute values of the result field according to
6553  *          the optional numbers of cells and nodes, if any. The valid values are
6554  *          - 0 - do not permute.
6555  *          - 1 - permute cells.
6556  *          - 2 - permute nodes.
6557  *          - 3 - permute cells and nodes.
6558  *
6559  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6560  *          caller is to delete this field using decrRef() as it is no more needed. 
6561  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6562  *  \throw If no field of \a this is lying on \a mesh.
6563  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6564  *  \sa getFieldAtLevel()
6565  *  \sa getFieldOnMeshAtLevel() 
6566  */
6567 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6568 {
6569   MCAuto<DataArray> arrOut;
6570   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6571   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6572   return ret.retn();
6573 }
6574
6575 /*!
6576  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6577  * This method is called "Old" because in MED3 norm a field has only one meshName
6578  * attached, so this method is for readers of MED2 files. If \a this field 
6579  * has not been constructed via file reading, an exception is thrown.
6580  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6581  *  \param [in] type - a spatial discretization of interest.
6582  *  \param [in] mName - a name of the supporting mesh.
6583  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6584  *  \param [in] renumPol - specifies how to permute values of the result field according to
6585  *          the optional numbers of cells and nodes, if any. The valid values are
6586  *          - 0 - do not permute.
6587  *          - 1 - permute cells.
6588  *          - 2 - permute nodes.
6589  *          - 3 - permute cells and nodes.
6590  *
6591  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6592  *          caller is to delete this field using decrRef() as it is no more needed. 
6593  *  \throw If the MED file is not readable.
6594  *  \throw If there is no mesh named \a mName in the MED file.
6595  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6596  *  \throw If \a this field has not been constructed via file reading.
6597  *  \throw If no field of \a this is lying on the mesh named \a mName.
6598  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6599  *  \sa getFieldAtLevel()
6600  */
6601 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6602 {
6603   if(getFileName().empty())
6604     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6605   MCAuto<DataArray> arrOut;
6606   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6607   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6608   return ret.retn();
6609 }
6610
6611 /*!
6612  * Returns values and a profile of the field of a given type lying on a given support.
6613  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6614  *  \param [in] type - a spatial discretization of the field.
6615  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6616  *  \param [in] mesh - the supporting mesh.
6617  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6618  *          field of interest lies on. If the field lies on all entities of the given
6619  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6620  *          using decrRef() as it is no more needed.  
6621  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6622  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6623  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6624  *  \throw If no field of \a this is lying on \a mesh.
6625  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6626  */
6627 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6628 {
6629   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6630   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6631 }
6632
6633 /*!
6634  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6635  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6636  * "Sort By Type"), if not, an exception is thrown. 
6637  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6638  *  \param [in] field - the field to add to \a this.
6639  *  \throw If the name of \a field is empty.
6640  *  \throw If the data array of \a field is not set.
6641  *  \throw If the data array is already allocated but has different number of components
6642  *         than \a field.
6643  *  \throw If the underlying mesh of \a field has no name.
6644  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6645  */
6646 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6647 {
6648   setFileName("");
6649   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6650 }
6651
6652 /*!
6653  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6654  * can be an aggregation of several MEDCouplingFieldDouble instances.
6655  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6656  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6657  * and \a profile.
6658  *
6659  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6660  * A new profile is added only if no equal profile is missing.
6661  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6662  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6663  *  \param [in] mesh - the supporting mesh of \a field.
6664  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6665  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6666  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6667  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6668  *  \throw If the data array of \a field is not set.
6669  *  \throw If the data array of \a this is already allocated but has different number of
6670  *         components than \a field.
6671  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6672  *  \sa setFieldNoProfileSBT()
6673  */
6674 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6675 {
6676   setFileName("");
6677   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6678 }
6679
6680 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6681 {
6682   return new MEDFileField1TS(*this);
6683 }
6684
6685 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6686 {
6687   return contentNotNull()->getUndergroundDataArrayDouble();
6688 }
6689
6690 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6691 {
6692   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6693 }
6694
6695 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6696                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6697 {
6698   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6699 }
6700
6701 //= MEDFileIntField1TS
6702
6703 MEDFileIntField1TS *MEDFileIntField1TS::New()
6704 {
6705   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6706   ret->contentNotNull();
6707   return ret.retn();
6708 }
6709
6710 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6711 {
6712   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6713   ret->contentNotNull();
6714   return ret.retn();
6715 }
6716
6717 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6718 {
6719   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6720   ret->contentNotNull();
6721   return ret.retn();
6722 }
6723
6724 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6725 {
6726   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6727   ret->contentNotNull();
6728   return ret.retn();
6729 }
6730
6731 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6732 {
6733   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6734   ret->contentNotNull();
6735   return ret.retn();
6736 }
6737
6738 MEDFileIntField1TS::MEDFileIntField1TS()
6739 {
6740   _content=new MEDFileIntField1TSWithoutSDA;
6741 }
6742
6743 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6744 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6745 {
6746 }
6747 catch(INTERP_KERNEL::Exception& e)
6748 { throw e; }
6749
6750 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6751 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6752 {
6753 }
6754 catch(INTERP_KERNEL::Exception& e)
6755 { throw e; }
6756
6757 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6758 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6759 {
6760 }
6761 catch(INTERP_KERNEL::Exception& e)
6762 { throw e; }
6763
6764 /*!
6765  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6766  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6767  *
6768  * \warning this is a shallow copy constructor
6769  */
6770 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6771 {
6772 }
6773
6774 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6775 {
6776   return new MEDFileIntField1TS(*this);
6777 }
6778
6779 /*!
6780  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6781  * following the given input policy.
6782  *
6783  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6784  *                            By default (true) the globals are deeply copied.
6785  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6786  */
6787 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6788 {
6789   MCAuto<MEDFileField1TS> ret;
6790   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6791   if(content)
6792     {
6793       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6794       if(!contc)
6795         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6796       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6797       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6798     }
6799   else
6800     ret=MEDFileField1TS::New();
6801   if(isDeepCpyGlobs)
6802     ret->deepCpyGlobs(*this);
6803   else
6804     ret->shallowCpyGlobs(*this);
6805   return ret.retn();
6806 }
6807
6808 /*!
6809  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6810  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6811  * "Sort By Type"), if not, an exception is thrown. 
6812  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6813  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6814  *  \param [in] arrOfVals - the values of the field \a field used.
6815  *  \throw If the name of \a field is empty.
6816  *  \throw If the data array of \a field is not set.
6817  *  \throw If the data array is already allocated but has different number of components
6818  *         than \a field.
6819  *  \throw If the underlying mesh of \a field has no name.
6820  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6821  */
6822 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6823 {
6824   setFileName("");
6825   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6826 }
6827
6828 /*!
6829  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6830  * can be an aggregation of several MEDCouplingFieldDouble instances.
6831  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6832  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6833  * and \a profile.
6834  *
6835  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6836  * A new profile is added only if no equal profile is missing.
6837  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6838  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6839  *  \param [in] arrOfVals - the values of the field \a field used.
6840  *  \param [in] mesh - the supporting mesh of \a field.
6841  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6842  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6843  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6844  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6845  *  \throw If the data array of \a field is not set.
6846  *  \throw If the data array of \a this is already allocated but has different number of
6847  *         components than \a field.
6848  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6849  *  \sa setFieldNoProfileSBT()
6850  */
6851 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6852 {
6853   setFileName("");
6854   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6855 }
6856
6857 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6858 {
6859   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6860   if(!pt)
6861     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6862   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6863   if(!ret)
6864     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 !");
6865   return ret;
6866 }
6867
6868 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6869 {
6870   if(getFileName().empty())
6871     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6872   MCAuto<DataArray> arrOut2;
6873   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6874   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6875   if(!arrOutC)
6876     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6877   arrOut=arrOutC;
6878   arrOut->incrRef();  // arrOut2 dies at the end of the func
6879   return ret.retn();
6880 }
6881
6882 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
6883 {
6884   if(!((DataArray *)arr))
6885     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6886   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6887   if(!arrC)
6888     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6889   arrC->incrRef();
6890   return arrC;
6891 }
6892
6893 /*!
6894  * Returns a new MEDCouplingFieldDouble of a given type lying on
6895  * the top level cells of the first mesh in MED file. If \a this field 
6896  * has not been constructed via file reading, an exception is thrown.
6897  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6898  *  \param [in] type - a spatial discretization of interest.
6899  *  \param [out] arrOut - the DataArrayInt containing values of field.
6900  *  \param [in] renumPol - specifies how to permute values of the result field according to
6901  *          the optional numbers of cells and nodes, if any. The valid values are
6902  *          - 0 - do not permute.
6903  *          - 1 - permute cells.
6904  *          - 2 - permute nodes.
6905  *          - 3 - permute cells and nodes.
6906  *
6907  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6908  *          caller is to delete this field using decrRef() as it is no more needed. 
6909  *  \throw If \a this field has not been constructed via file reading.
6910  *  \throw If the MED file is not readable.
6911  *  \throw If there is no mesh in the MED file.
6912  *  \throw If no field values of the given \a type.
6913  *  \throw If no field values lying on the top level support.
6914  *  \sa getFieldAtLevel()
6915  */
6916 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6917 {
6918   if(getFileName().empty())
6919     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6920   MCAuto<DataArray> arr;
6921   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6922   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6923   return ret.retn();
6924 }
6925
6926 /*!
6927  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6928  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6929  *  \param [in] type - a spatial discretization of the new field.
6930  *  \param [in] mesh - the supporting mesh.
6931  *  \param [out] arrOut - the DataArrayInt containing values of field.
6932  *  \param [in] renumPol - specifies how to permute values of the result field according to
6933  *          the optional numbers of cells and nodes, if any. The valid values are
6934  *          - 0 - do not permute.
6935  *          - 1 - permute cells.
6936  *          - 2 - permute nodes.
6937  *          - 3 - permute cells and nodes.
6938  *
6939  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6940  *          caller is to delete this field using decrRef() as it is no more needed. 
6941  *  \throw If no field of \a this is lying on \a mesh.
6942  *  \throw If the mesh is empty.
6943  *  \throw If no field values of the given \a type are available.
6944  *  \sa getFieldAtLevel()
6945  *  \sa getFieldOnMeshAtLevel() 
6946  */
6947 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6948 {
6949   MCAuto<DataArray> arr;
6950   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6951   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6952   return ret.retn();
6953 }
6954
6955 /*!
6956  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6957  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6958  *  \param [in] type - a spatial discretization of interest.
6959  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6960  *  \param [out] arrOut - the DataArrayInt containing values of field.
6961  *  \param [in] mesh - the supporting mesh.
6962  *  \param [in] renumPol - specifies how to permute values of the result field according to
6963  *          the optional numbers of cells and nodes, if any. The valid values are
6964  *          - 0 - do not permute.
6965  *          - 1 - permute cells.
6966  *          - 2 - permute nodes.
6967  *          - 3 - permute cells and nodes.
6968  *
6969  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6970  *          caller is to delete this field using decrRef() as it is no more needed. 
6971  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6972  *  \throw If no field of \a this is lying on \a mesh.
6973  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6974  *  \sa getFieldAtLevel()
6975  *  \sa getFieldOnMeshAtLevel() 
6976  */
6977 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6978 {
6979   MCAuto<DataArray> arr;
6980   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6981   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6982   return ret.retn();
6983 }
6984
6985 /*!
6986  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6987  * This method is called "Old" because in MED3 norm a field has only one meshName
6988  * attached, so this method is for readers of MED2 files. If \a this field 
6989  * has not been constructed via file reading, an exception is thrown.
6990  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6991  *  \param [in] type - a spatial discretization of interest.
6992  *  \param [in] mName - a name of the supporting mesh.
6993  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6994  *  \param [out] arrOut - the DataArrayInt containing values of field.
6995  *  \param [in] renumPol - specifies how to permute values of the result field according to
6996  *          the optional numbers of cells and nodes, if any. The valid values are
6997  *          - 0 - do not permute.
6998  *          - 1 - permute cells.
6999  *          - 2 - permute nodes.
7000  *          - 3 - permute cells and nodes.
7001  *
7002  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7003  *          caller is to delete this field using decrRef() as it is no more needed. 
7004  *  \throw If the MED file is not readable.
7005  *  \throw If there is no mesh named \a mName in the MED file.
7006  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7007  *  \throw If \a this field has not been constructed via file reading.
7008  *  \throw If no field of \a this is lying on the mesh named \a mName.
7009  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7010  *  \sa getFieldAtLevel()
7011  */
7012 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
7013 {
7014   if(getFileName().empty())
7015     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7016   MCAuto<DataArray> arr;
7017   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
7018   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7019   return ret.retn();
7020 }
7021
7022 /*!
7023  * Returns values and a profile of the field of a given type lying on a given support.
7024  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7025  *  \param [in] type - a spatial discretization of the field.
7026  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7027  *  \param [in] mesh - the supporting mesh.
7028  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7029  *          field of interest lies on. If the field lies on all entities of the given
7030  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7031  *          using decrRef() as it is no more needed.  
7032  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7033  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7034  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7035  *  \throw If no field of \a this is lying on \a mesh.
7036  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7037  */
7038 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7039 {
7040   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7041   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7042 }
7043
7044 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7045 {
7046   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7047   if(!pt)
7048     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7049   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7050   if(!ret)
7051     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 !");
7052   return ret;
7053 }
7054
7055 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7056 {
7057   return contentNotNull()->getUndergroundDataArrayInt();
7058 }
7059
7060 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7061
7062 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7063 {
7064 }
7065
7066 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7067 {
7068 }
7069
7070 /*!
7071  * \param [in] fieldId field id in C mode
7072  */
7073 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7074 {
7075   med_field_type typcha;
7076   std::string dtunitOut;
7077   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
7078   setDtUnit(dtunitOut.c_str());
7079   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7080 }
7081
7082 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)
7083 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7084 {
7085   setDtUnit(dtunit.c_str());
7086   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7087 }
7088 catch(INTERP_KERNEL::Exception& e)
7089 {
7090     throw e;
7091 }
7092
7093 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7094 {
7095   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7096   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7097     ret+=(*it).capacity();
7098   return ret;
7099 }
7100
7101 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7102 {
7103   std::vector<const BigMemoryObject *> ret;
7104   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7105     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7106   return ret;
7107 }
7108
7109 /*!
7110  * 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
7111  * NULL.
7112  */
7113 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7114 {
7115   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7116   ret->setInfo(_infos);
7117   int sz=(int)_time_steps.size();
7118   for(const int *id=startIds;id!=endIds;id++)
7119     {
7120       if(*id>=0 && *id<sz)
7121         {
7122           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7123           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7124           if(tse)
7125             {
7126               tse->incrRef();
7127               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7128             }
7129           ret->pushBackTimeStep(tse2);
7130         }
7131       else
7132         {
7133           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7134           oss << " ! Should be in [0," << sz << ") !";
7135           throw INTERP_KERNEL::Exception(oss.str().c_str());
7136         }
7137     }
7138   if(ret->getNumberOfTS()>0)
7139     ret->synchronizeNameScope();
7140   ret->copyNameScope(*this);
7141   return ret.retn();
7142 }
7143
7144 /*!
7145  * 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
7146  * NULL.
7147  */
7148 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7149 {
7150   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7151   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7152   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7153   ret->setInfo(_infos);
7154   int sz=(int)_time_steps.size();
7155   int j=bg;
7156   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7157     {
7158       if(j>=0 && j<sz)
7159         {
7160           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7161           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7162           if(tse)
7163             {
7164               tse->incrRef();
7165               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7166             }
7167           ret->pushBackTimeStep(tse2);
7168         }
7169       else
7170         {
7171           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7172           oss << " ! Should be in [0," << sz << ") !";
7173           throw INTERP_KERNEL::Exception(oss.str().c_str());
7174         }
7175     }
7176   if(ret->getNumberOfTS()>0)
7177     ret->synchronizeNameScope();
7178   ret->copyNameScope(*this);
7179   return ret.retn();
7180 }
7181
7182 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7183 {
7184   int id=0;
7185   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7186   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7187     {
7188       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7189       if(!cur)
7190         continue;
7191       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7192       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7193         ids->pushBackSilent(id);
7194     }
7195   return buildFromTimeStepIds(ids->begin(),ids->end());
7196 }
7197
7198 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7199 {
7200   int id=0;
7201   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7202   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7203     {
7204       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7205       if(!cur)
7206         continue;
7207       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7208       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7209         ids->pushBackSilent(id);
7210     }
7211   return buildFromTimeStepIds(ids->begin(),ids->end());
7212 }
7213
7214 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7215 {
7216   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7217     {
7218       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7219       if(!cur)
7220         continue;
7221       if(cur->presenceOfMultiDiscPerGeoType())
7222         return true;
7223     }
7224   return false;
7225 }
7226
7227 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7228 {
7229   return _infos;
7230 }
7231
7232 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7233 {
7234   _infos=info;
7235 }
7236
7237 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7238 {
7239   int ret=0;
7240   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7241     {
7242       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7243       if(pt->isDealingTS(iteration,order))
7244         return ret;
7245     }
7246   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7247   std::vector< std::pair<int,int> > vp=getIterations();
7248   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7249     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7250   throw INTERP_KERNEL::Exception(oss.str().c_str());
7251 }
7252
7253 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7254 {
7255   return *_time_steps[getTimeStepPos(iteration,order)];
7256 }
7257
7258 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7259 {
7260   return *_time_steps[getTimeStepPos(iteration,order)];
7261 }
7262
7263 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7264 {
7265   if(_time_steps.empty())
7266     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7267   return _time_steps[0]->getMeshName();
7268 }
7269
7270 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7271 {
7272   std::string oldName(getMeshName());
7273   std::vector< std::pair<std::string,std::string> > v(1);
7274   v[0].first=oldName; v[0].second=newMeshName;
7275   changeMeshNames(v);
7276 }
7277
7278 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7279 {
7280   bool ret=false;
7281   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7282     {
7283       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7284       if(cur)
7285         ret=cur->changeMeshNames(modifTab) || ret;
7286     }
7287   return ret;
7288 }
7289
7290 /*!
7291  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7292  */
7293 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7294 {
7295   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7296 }
7297
7298 /*!
7299  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7300  */
7301 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7302 {
7303   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7304 }
7305
7306 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7307                                                                        MEDFileFieldGlobsReal& glob)
7308 {
7309   bool ret=false;
7310   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7311     {
7312       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7313       if(f1ts)
7314         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7315     }
7316   return ret;
7317 }
7318
7319 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7320 {
7321   std::string startLine(bkOffset,' ');
7322   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7323   if(fmtsId>=0)
7324     oss << " (" << fmtsId << ")";
7325   oss << " has the following name: \"" << _name << "\"." << std::endl;
7326   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7327   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7328     {
7329       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7330     }
7331   int i=0;
7332   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7333     {
7334       std::string chapter(17,'0'+i);
7335       oss << startLine << chapter << std::endl;
7336       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7337       if(cur)
7338         cur->simpleRepr(bkOffset+2,oss,i);
7339       else
7340         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7341       oss << startLine << chapter << std::endl;
7342     }
7343 }
7344
7345 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7346 {
7347   std::size_t sz=_time_steps.size();
7348   std::vector< std::pair<int,int> > ret(sz);
7349   ret1.resize(sz);
7350   for(std::size_t i=0;i<sz;i++)
7351     {
7352       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7353       if(f1ts)
7354         {
7355           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7356         }
7357       else
7358         {
7359           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7360           throw INTERP_KERNEL::Exception(oss.str().c_str());
7361         }
7362     }
7363   return ret;
7364 }
7365
7366 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7367 {
7368   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7369   if(!tse2)
7370     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7371   checkCoherencyOfType(tse2);
7372   if(_time_steps.empty())
7373     {
7374       setName(tse2->getName().c_str());
7375       setInfo(tse2->getInfo());
7376     }
7377   checkThatComponentsMatch(tse2->getInfo());
7378   _time_steps.push_back(tse);
7379 }
7380
7381 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7382 {
7383   std::size_t nbOfCompo=_infos.size();
7384   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7385     {
7386       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7387       if(cur)
7388         {
7389           if((cur->getInfo()).size()!=nbOfCompo)
7390             {
7391               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7392               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7393               throw INTERP_KERNEL::Exception(oss.str().c_str());
7394             }
7395           cur->copyNameScope(*this);
7396         }
7397     }
7398 }
7399
7400 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)
7401 {
7402   _time_steps.resize(nbPdt);
7403   for(int i=0;i<nbPdt;i++)
7404     {
7405       std::vector< std::pair<int,int> > ts;
7406       med_int numdt=0,numo=0;
7407       med_int meshIt=0,meshOrder=0;
7408       med_float dt=0.0;
7409       MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder));
7410       switch(fieldTyp)
7411       {
7412         case MED_FLOAT64:
7413           {
7414             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7415             break;
7416           }
7417         case MED_INT32:
7418           {
7419             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7420             break;
7421           }
7422         default:
7423           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7424       }
7425       if(loadAll)
7426         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7427       else
7428         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7429     }
7430 }
7431
7432 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7433 {
7434   if(_time_steps.empty())
7435     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7436   checkThatNbOfCompoOfTSMatchThis();
7437   std::vector<std::string> infos(getInfo());
7438   int nbComp=infos.size();
7439   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7440   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7441   for(int i=0;i<nbComp;i++)
7442     {
7443       std::string info=infos[i];
7444       std::string c,u;
7445       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7446       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7447       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7448     }
7449   if(_name.empty())
7450     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7451   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7452   int nbOfTS=_time_steps.size();
7453   for(int i=0;i<nbOfTS;i++)
7454     _time_steps[i]->writeLL(fid,opts,*this);
7455 }
7456
7457 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7458 {
7459   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7460     {
7461       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7462       if(elt)
7463         elt->loadBigArraysRecursively(fid,nasc);
7464     }
7465 }
7466
7467 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7468 {
7469   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7470     {
7471       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7472       if(elt)
7473         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7474     }
7475 }
7476
7477 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7478 {
7479   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7480     {
7481       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7482       if(elt)
7483         elt->unloadArrays();
7484     }
7485 }
7486
7487 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7488 {
7489   return _time_steps.size();
7490 }
7491
7492 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7493 {
7494   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7495   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7496     {
7497       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7498       if(tmp)
7499         newTS.push_back(*it);
7500     }
7501   _time_steps=newTS;
7502 }
7503
7504 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7505 {
7506   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7507   int maxId=(int)_time_steps.size();
7508   int ii=0;
7509   std::set<int> idsToDel;
7510   for(const int *id=startIds;id!=endIds;id++,ii++)
7511     {
7512       if(*id>=0 && *id<maxId)
7513         {
7514           idsToDel.insert(*id);
7515         }
7516       else
7517         {
7518           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7519           throw INTERP_KERNEL::Exception(oss.str().c_str());
7520         }
7521     }
7522   for(int iii=0;iii<maxId;iii++)
7523     if(idsToDel.find(iii)==idsToDel.end())
7524       newTS.push_back(_time_steps[iii]);
7525   _time_steps=newTS;
7526 }
7527
7528 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7529 {
7530   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7531   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7532   if(nbOfEntriesToKill==0)
7533     return ;
7534   std::size_t sz=_time_steps.size();
7535   std::vector<bool> b(sz,true);
7536   int j=bg;
7537   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7538     b[j]=false;
7539   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7540   for(std::size_t i=0;i<sz;i++)
7541     if(b[i])
7542       newTS.push_back(_time_steps[i]);
7543   _time_steps=newTS;
7544 }
7545
7546 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7547 {
7548   int ret=0;
7549   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7550   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7551     {
7552       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7553       if(tmp)
7554         {
7555           int it2,ord;
7556           tmp->getTime(it2,ord);
7557           if(it2==iteration && order==ord)
7558             return ret;
7559           else
7560             oss << "(" << it2 << ","  << ord << "), ";
7561         }
7562     }
7563   throw INTERP_KERNEL::Exception(oss.str().c_str());
7564 }
7565
7566 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7567 {
7568   int ret=0;
7569   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7570   oss.precision(15);
7571   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7572     {
7573       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7574       if(tmp)
7575         {
7576           int it2,ord;
7577           double ti=tmp->getTime(it2,ord);
7578           if(fabs(time-ti)<eps)
7579             return ret;
7580           else
7581             oss << ti << ", ";
7582         }
7583     }
7584   throw INTERP_KERNEL::Exception(oss.str().c_str());
7585 }
7586
7587 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7588 {
7589   int lgth=_time_steps.size();
7590   std::vector< std::pair<int,int> > ret(lgth);
7591   for(int i=0;i<lgth;i++)
7592     _time_steps[i]->fillIteration(ret[i]);
7593   return ret;
7594 }
7595
7596 /*!
7597  * 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'
7598  * This method returns two things.
7599  * - The absolute dimension of 'this' in first parameter. 
7600  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7601  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7602  *
7603  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7604  * Only these 3 discretizations will be taken into account here.
7605  *
7606  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7607  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7608  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7609  *
7610  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7611  * 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'.
7612  * 
7613  * Let's consider the typical following case :
7614  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7615  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7616  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7617  *   TETRA4 and SEG2
7618  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7619  *
7620  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7621  * 
7622  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7623  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7624  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7625  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7626  */
7627 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7628 {
7629   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7630 }
7631
7632 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7633 {
7634   if(pos<0 || pos>=(int)_time_steps.size())
7635     {
7636       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7637       throw INTERP_KERNEL::Exception(oss.str().c_str());
7638     }
7639   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7640   if(item==0)
7641     {
7642       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7643       oss << "\nTry to use following method eraseEmptyTS !";
7644       throw INTERP_KERNEL::Exception(oss.str().c_str());
7645     }
7646   return item;
7647 }
7648
7649 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7650 {
7651   if(pos<0 || pos>=(int)_time_steps.size())
7652     {
7653       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7654       throw INTERP_KERNEL::Exception(oss.str().c_str());
7655     }
7656   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7657   if(item==0)
7658     {
7659       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7660       oss << "\nTry to use following method eraseEmptyTS !";
7661       throw INTERP_KERNEL::Exception(oss.str().c_str());
7662     }
7663   return item;
7664 }
7665
7666 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7667 {
7668   std::vector<std::string> ret;
7669   std::set<std::string> ret2;
7670   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7671     {
7672       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7673       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7674         if(ret2.find(*it2)==ret2.end())
7675           {
7676             ret.push_back(*it2);
7677             ret2.insert(*it2);
7678           }
7679     }
7680   return ret;
7681 }
7682
7683 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7684 {
7685   std::vector<std::string> ret;
7686   std::set<std::string> ret2;
7687   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7688     {
7689       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7690       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7691         if(ret2.find(*it2)==ret2.end())
7692           {
7693             ret.push_back(*it2);
7694             ret2.insert(*it2);
7695           }
7696     }
7697   return ret;
7698 }
7699
7700 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7701 {
7702   std::vector<std::string> ret;
7703   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7704     {
7705       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7706       ret.insert(ret.end(),tmp.begin(),tmp.end());
7707     }
7708   return ret;
7709 }
7710
7711 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7712 {
7713   std::vector<std::string> ret;
7714   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7715     {
7716       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7717       ret.insert(ret.end(),tmp.begin(),tmp.end());
7718     }
7719   return ret;
7720 }
7721
7722 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7723 {
7724   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7725     (*it)->changePflsRefsNamesGen2(mapOfModif);
7726 }
7727
7728 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7729 {
7730   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7731     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7732 }
7733
7734 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7735 {
7736   int lgth=_time_steps.size();
7737   std::vector< std::vector<TypeOfField> > ret(lgth);
7738   for(int i=0;i<lgth;i++)
7739     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7740   return ret;
7741 }
7742
7743 /*!
7744  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7745  */
7746 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
7747 {
7748   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7749 }
7750
7751 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7752 {
7753   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7754   std::size_t i=0;
7755   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7756     {
7757       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7758         ret->_time_steps[i]=(*it)->deepCopy();
7759     }
7760   return ret.retn();
7761 }
7762
7763 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7764 {
7765   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7766   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7767   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7768   for(std::size_t i=0;i<sz;i++)
7769     {
7770       ret[i]=shallowCpy();
7771       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7772     }
7773   for(std::size_t i=0;i<sz2;i++)
7774     {
7775       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7776       if(ret1.size()!=sz)
7777         {
7778           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7779           throw INTERP_KERNEL::Exception(oss.str().c_str());
7780         }
7781       ts[i]=ret1;
7782     }
7783   for(std::size_t i=0;i<sz;i++)
7784     for(std::size_t j=0;j<sz2;j++)
7785       ret[i]->_time_steps[j]=ts[j][i];
7786   return ret;
7787 }
7788
7789 /*!
7790  * This method splits into discretization each time steps in \a this.
7791  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7792  */
7793 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7794 {
7795   std::size_t sz(_time_steps.size());
7796   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7797   for(std::size_t i=0;i<sz;i++)
7798     {
7799       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7800       if(!timeStep)
7801         {
7802           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7803           throw INTERP_KERNEL::Exception(oss.str().c_str());
7804         }
7805       items[i]=timeStep->splitDiscretizations();  
7806     }
7807   //
7808   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7809   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7810   std::vector< TypeOfField > types;
7811   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7812     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7813       {
7814         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7815         if(ts.size()!=1)
7816           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7817         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7818         if(it2==types.end())
7819           types.push_back(ts[0]);
7820       }
7821   ret.resize(types.size()); ret2.resize(types.size());
7822   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7823     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7824       {
7825         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7826         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7827         ret2[pos].push_back(*it1);
7828       }
7829   for(std::size_t i=0;i<types.size();i++)
7830     {
7831       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7832       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7833         elt->pushBackTimeStep(*it1);//also updates infos in elt
7834       ret[i]=elt;
7835       elt->MEDFileFieldNameScope::operator=(*this);
7836     }
7837   return ret;
7838 }
7839
7840 /*!
7841  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7842  */
7843 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7844 {
7845   std::size_t sz(_time_steps.size());
7846   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7847   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7848   for(std::size_t i=0;i<sz;i++)
7849     {
7850       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7851       if(!timeStep)
7852         {
7853           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7854           throw INTERP_KERNEL::Exception(oss.str().c_str());
7855         }
7856       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7857       if(szOut==std::numeric_limits<std::size_t>::max())
7858         szOut=items[i].size();
7859       else
7860         if(items[i].size()!=szOut)
7861           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7862     }
7863   if(szOut==std::numeric_limits<std::size_t>::max())
7864     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7865   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7866   for(std::size_t i=0;i<szOut;i++)
7867     {
7868       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7869       for(std::size_t j=0;j<sz;j++)
7870         elt->pushBackTimeStep(items[j][i]);
7871       ret[i]=elt;
7872       elt->MEDFileFieldNameScope::operator=(*this);
7873     }
7874   return ret;
7875 }
7876
7877 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7878 {
7879   _name=field->getName();
7880   if(_name.empty())
7881     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7882   if(!arr)
7883     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7884   _infos=arr->getInfoOnComponents();
7885 }
7886
7887 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7888 {
7889   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7890   if(_name!=field->getName())
7891     {
7892       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7893       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7894       throw INTERP_KERNEL::Exception(oss.str().c_str());
7895     }
7896   if(!arr)
7897     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7898   checkThatComponentsMatch(arr->getInfoOnComponents());
7899 }
7900
7901 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7902 {
7903   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7904   if(getInfo().size()!=compos.size())
7905     {
7906       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7907       oss << " number of components of element to append (" << compos.size() << ") !";
7908       throw INTERP_KERNEL::Exception(oss.str().c_str());
7909     }
7910   if(_infos!=compos)
7911     {
7912       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7913       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7914       oss << " But compo in input fields are : ";
7915       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7916       oss << " !";
7917       throw INTERP_KERNEL::Exception(oss.str().c_str());
7918     }
7919 }
7920
7921 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7922 {
7923   std::size_t sz=_infos.size();
7924   int j=0;
7925   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7926     {
7927       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7928       if(elt)
7929         if(elt->getInfo().size()!=sz)
7930           {
7931             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7932             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7933             throw INTERP_KERNEL::Exception(oss.str().c_str());
7934           }
7935     }
7936 }
7937
7938 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7939 {
7940   if(!field)
7941     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7942   if(!_time_steps.empty())
7943     checkCoherencyOfTinyInfo(field,arr);
7944   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7945   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7946   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7947   copyTinyInfoFrom(field,arr);
7948   _time_steps.push_back(obj);
7949 }
7950
7951 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7952 {
7953   if(!field)
7954     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7955   if(!_time_steps.empty())
7956     checkCoherencyOfTinyInfo(field,arr);
7957   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7958   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7959   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7960   copyTinyInfoFrom(field,arr);
7961   _time_steps.push_back(obj);
7962 }
7963
7964 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
7965 {
7966   int sz=(int)_time_steps.size();
7967   if(i<0 || i>=sz)
7968     {
7969       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7970       throw INTERP_KERNEL::Exception(oss.str().c_str());
7971     }
7972   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7973   if(tsPtr)
7974     {
7975       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7976         {
7977           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7978           throw INTERP_KERNEL::Exception(oss.str().c_str());
7979         }
7980     }
7981   _time_steps[i]=ts;
7982 }
7983
7984 //= MEDFileFieldMultiTSWithoutSDA
7985
7986 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)
7987 {
7988   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
7989 }
7990
7991 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7992 {
7993 }
7994
7995 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7996 {
7997 }
7998
7999 /*!
8000  * \param [in] fieldId field id in C mode
8001  */
8002 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8003 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8004 {
8005 }
8006 catch(INTERP_KERNEL::Exception& e)
8007 { throw e; }
8008
8009 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)
8010 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8011 {
8012 }
8013 catch(INTERP_KERNEL::Exception& e)
8014 { throw e; }
8015
8016 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8017 {
8018   return new MEDFileField1TSWithoutSDA;
8019 }
8020
8021 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8022 {
8023   if(!f1ts)
8024     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8025   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8026   if(!f1tsC)
8027     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8028 }
8029
8030 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8031 {
8032   return MEDFileField1TSWithoutSDA::TYPE_STR;
8033 }
8034
8035 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8036 {
8037   return new MEDFileFieldMultiTSWithoutSDA(*this);
8038 }
8039
8040 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8041 {
8042   return new MEDFileFieldMultiTSWithoutSDA;
8043 }
8044
8045 /*!
8046  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8047  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8048  */
8049 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
8050 {
8051   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8052   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8053   if(!myF1TSC)
8054     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8055   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8056 }
8057
8058 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8059 {
8060   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8061   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8062   int i=0;
8063   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8064     {
8065       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8066       if(eltToConv)
8067         {
8068           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8069           if(!eltToConvC)
8070             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8071           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8072           ret->setIteration(i,elt);
8073         }
8074     }
8075   return ret.retn();
8076 }
8077
8078 //= MEDFileAnyTypeFieldMultiTS
8079
8080 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8081 {
8082 }
8083
8084 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8085 try:MEDFileFieldGlobsReal(fileName)
8086 {
8087   MEDFileUtilities::CheckFileForRead(fileName);
8088   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8089   _content=BuildContentFrom(fid,fileName,loadAll,ms);
8090   loadGlobals(fid);
8091 }
8092 catch(INTERP_KERNEL::Exception& e)
8093 {
8094     throw e;
8095 }
8096
8097 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)
8098 {
8099   med_field_type typcha;
8100   std::vector<std::string> infos;
8101   std::string dtunit;
8102   int i=-1;
8103   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
8104   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8105   switch(typcha)
8106   {
8107     case MED_FLOAT64:
8108       {
8109         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8110         break;
8111       }
8112     case MED_INT32:
8113       {
8114         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8115         break;
8116       }
8117     default:
8118       {
8119         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] !";
8120         throw INTERP_KERNEL::Exception(oss.str().c_str());
8121       }
8122   }
8123   ret->setDtUnit(dtunit.c_str());
8124   return ret.retn();
8125 }
8126
8127 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8128 {
8129   med_field_type typcha;
8130   //
8131   std::vector<std::string> infos;
8132   std::string dtunit,fieldName;
8133   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
8134   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8135   switch(typcha)
8136   {
8137     case MED_FLOAT64:
8138       {
8139         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8140         break;
8141       }
8142     case MED_INT32:
8143       {
8144         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8145         break;
8146       }
8147     default:
8148       {
8149         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] !";
8150         throw INTERP_KERNEL::Exception(oss.str().c_str());
8151       }
8152   }
8153   ret->setDtUnit(dtunit.c_str());
8154   return ret.retn();
8155 }
8156
8157 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
8158 {
8159   if(!c)
8160     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8161   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8162     {
8163       MCAuto<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
8164       ret->setFileName(fileName);
8165       ret->_content=c;  c->incrRef();
8166       return ret.retn();
8167     }
8168   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8169     {
8170       MCAuto<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
8171       ret->setFileName(fileName);
8172       ret->_content=c;  c->incrRef();
8173       return ret.retn();
8174     }
8175   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8176 }
8177
8178 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)
8179 try:MEDFileFieldGlobsReal(fileName)
8180 {
8181   MEDFileUtilities::CheckFileForRead(fileName);
8182   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8183   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms,entities);
8184   loadGlobals(fid);
8185 }
8186 catch(INTERP_KERNEL::Exception& e)
8187 {
8188     throw e;
8189 }
8190
8191 //= MEDFileIntFieldMultiTSWithoutSDA
8192
8193 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)
8194 {
8195   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8196 }
8197
8198 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8199 {
8200 }
8201
8202 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8203 {
8204 }
8205
8206 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)
8207 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8208 {
8209 }
8210 catch(INTERP_KERNEL::Exception& e)
8211 { throw e; }
8212
8213 /*!
8214  * \param [in] fieldId field id in C mode
8215  */
8216 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8217 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8218 {
8219 }
8220 catch(INTERP_KERNEL::Exception& e)
8221 { throw e; }
8222
8223 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8224 {
8225   return new MEDFileIntField1TSWithoutSDA;
8226 }
8227
8228 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8229 {
8230   if(!f1ts)
8231     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8232   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8233   if(!f1tsC)
8234     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8235 }
8236
8237 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8238 {
8239   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8240 }
8241
8242 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8243 {
8244   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8245 }
8246
8247 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8248 {
8249   return new MEDFileIntFieldMultiTSWithoutSDA;
8250 }
8251
8252 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8253 {
8254   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8255   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8256   int i=0;
8257   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8258     {
8259       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8260       if(eltToConv)
8261         {
8262           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8263           if(!eltToConvC)
8264             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8265           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8266           ret->setIteration(i,elt);
8267         }
8268     }
8269   return ret.retn();
8270 }
8271
8272 //= MEDFileAnyTypeFieldMultiTS
8273
8274 /*!
8275  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8276  * that has been read from a specified MED file.
8277  *  \param [in] fileName - the name of the MED file to read.
8278  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8279  *          is to delete this field using decrRef() as it is no more needed.
8280  *  \throw If reading the file fails.
8281  */
8282 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8283 {
8284   MEDFileUtilities::CheckFileForRead(fileName);
8285   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8286   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
8287   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8288   ret->loadGlobals(fid);
8289   return ret.retn();
8290 }
8291
8292 /*!
8293  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8294  * that has been read from a specified MED file.
8295  *  \param [in] fileName - the name of the MED file to read.
8296  *  \param [in] fieldName - the name of the field to read.
8297  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8298  *          is to delete this field using decrRef() as it is no more needed.
8299  *  \throw If reading the file fails.
8300  *  \throw If there is no field named \a fieldName in the file.
8301  */
8302 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8303 {
8304   MEDFileUtilities::CheckFileForRead(fileName);
8305   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8306   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fileName,fieldName,loadAll,0,0));
8307   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8308   ret->loadGlobals(fid);
8309   return ret.retn();
8310 }
8311
8312 /*!
8313  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8314  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8315  *
8316  * \warning this is a shallow copy constructor
8317  */
8318 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8319 {
8320   if(!shallowCopyOfContent)
8321     {
8322       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8323       otherPtr->incrRef();
8324       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8325     }
8326   else
8327     {
8328       _content=other.shallowCpy();
8329     }
8330 }
8331
8332 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8333 {
8334   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8335   if(!ret)
8336     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8337   return ret;
8338 }
8339
8340 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8341 {
8342   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8343   if(!ret)
8344     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8345   return ret;
8346 }
8347
8348 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8349 {
8350   return contentNotNullBase()->getPflsReallyUsed2();
8351 }
8352
8353 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8354 {
8355   return contentNotNullBase()->getLocsReallyUsed2();
8356 }
8357
8358 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8359 {
8360   return contentNotNullBase()->getPflsReallyUsedMulti2();
8361 }
8362
8363 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8364 {
8365   return contentNotNullBase()->getLocsReallyUsedMulti2();
8366 }
8367
8368 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8369 {
8370   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8371 }
8372
8373 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8374 {
8375   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8376 }
8377
8378 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8379 {
8380   return contentNotNullBase()->getNumberOfTS();
8381 }
8382
8383 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8384 {
8385   contentNotNullBase()->eraseEmptyTS();
8386 }
8387
8388 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8389 {
8390   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8391 }
8392
8393 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8394 {
8395   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8396 }
8397
8398 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8399 {
8400   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8401   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8402   ret->_content=c;
8403   return ret.retn();
8404 }
8405
8406 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8407 {
8408   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8409   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8410   ret->_content=c;
8411   return ret.retn();
8412 }
8413
8414 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8415 {
8416   return contentNotNullBase()->getIterations();
8417 }
8418
8419 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8420 {
8421   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8422     pushBackTimeStep(*it);
8423 }
8424
8425 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8426 {
8427   if(!fmts)
8428     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8429   int nbOfTS(fmts->getNumberOfTS());
8430   for(int i=0;i<nbOfTS;i++)
8431     {
8432       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8433       pushBackTimeStep(elt);
8434     }
8435 }
8436
8437 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8438 {
8439   if(!f1ts)
8440     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8441   checkCoherencyOfType(f1ts);
8442   f1ts->incrRef();
8443   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8444   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8445   c->incrRef();
8446   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8447   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8448     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8449   _content->pushBackTimeStep(cSafe);
8450   appendGlobs(*f1ts,1e-12);
8451 }
8452
8453 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8454 {
8455   contentNotNullBase()->synchronizeNameScope();
8456 }
8457
8458 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8459 {
8460   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8461 }
8462
8463 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8464 {
8465   return contentNotNullBase()->getPosGivenTime(time,eps);
8466 }
8467
8468 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8469 {
8470   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8471 }
8472
8473 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8474 {
8475   return contentNotNullBase()->getTypesOfFieldAvailable();
8476 }
8477
8478 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
8479 {
8480   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8481 }
8482
8483 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8484 {
8485   return contentNotNullBase()->getName();
8486 }
8487
8488 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8489 {
8490   contentNotNullBase()->setName(name);
8491 }
8492
8493 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8494 {
8495   return contentNotNullBase()->getDtUnit();
8496 }
8497
8498 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8499 {
8500   contentNotNullBase()->setDtUnit(dtUnit);
8501 }
8502
8503 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8504 {
8505   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8506 }
8507
8508 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8509 {
8510   return contentNotNullBase()->getTimeSteps(ret1);
8511 }
8512
8513 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8514 {
8515   return contentNotNullBase()->getMeshName();
8516 }
8517
8518 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8519 {
8520   contentNotNullBase()->setMeshName(newMeshName);
8521 }
8522
8523 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8524 {
8525   return contentNotNullBase()->changeMeshNames(modifTab);
8526 }
8527
8528 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8529 {
8530   return contentNotNullBase()->getInfo();
8531 }
8532
8533 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8534 {
8535   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8536 }
8537
8538 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8539 {
8540   return contentNotNullBase()->setInfo(info);
8541 }
8542
8543 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8544 {
8545   const std::vector<std::string> ret=getInfo();
8546   return (int)ret.size();
8547 }
8548
8549 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8550 {
8551   writeGlobals(fid,*this);
8552   contentNotNullBase()->writeLL(fid,*this);
8553 }
8554
8555 /*!
8556  * Writes \a this field into a MED file specified by its name.
8557  *  \param [in] fileName - the MED file name.
8558  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8559  * - 2 - erase; an existing file is removed.
8560  * - 1 - append; same data should not be present in an existing file.
8561  * - 0 - overwrite; same data present in an existing file is overwritten.
8562  *  \throw If the field name is not set.
8563  *  \throw If no field data is set.
8564  *  \throw If \a mode == 1 and the same data is present in an existing file.
8565  */
8566 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8567 {
8568   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8569   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8570   writeLL(fid);
8571 }
8572
8573 /*!
8574  * This method alloc the arrays and load potentially huge arrays contained in this field.
8575  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8576  * This method can be also called to refresh or reinit values from a file.
8577  * 
8578  * \throw If the fileName is not set or points to a non readable MED file.
8579  */
8580 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8581 {
8582   if(getFileName().empty())
8583     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8584   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8585   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8586 }
8587
8588 /*!
8589  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8590  * But once data loaded once, this method does nothing.
8591  * 
8592  * \throw If the fileName is not set or points to a non readable MED file.
8593  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8594  */
8595 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8596 {
8597   if(!getFileName().empty())
8598     {
8599       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8600       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8601     }
8602 }
8603
8604 /*!
8605  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8606  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8607  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8608  * 
8609  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8610  */
8611 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8612 {
8613   contentNotNullBase()->unloadArrays();
8614 }
8615
8616 /*!
8617  * 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.
8618  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8619  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8620  * 
8621  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8622  */
8623 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8624 {
8625   if(!getFileName().empty())
8626     contentNotNullBase()->unloadArrays();
8627 }
8628
8629 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8630 {
8631   std::ostringstream oss;
8632   contentNotNullBase()->simpleRepr(0,oss,-1);
8633   simpleReprGlobs(oss);
8634   return oss.str();
8635 }
8636
8637 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8638 {
8639   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8640 }
8641
8642 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8643 {
8644   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8645   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8646   return ret;
8647 }
8648
8649 /*!
8650  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8651  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8652  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8653  */
8654 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8655 {
8656   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8657   if(!content)
8658     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8659   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8660   std::size_t sz(contentsSplit.size());
8661   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8662   for(std::size_t i=0;i<sz;i++)
8663     {
8664       ret[i]=shallowCpy();
8665       ret[i]->_content=contentsSplit[i];
8666     }
8667   return ret;
8668 }
8669
8670 /*!
8671  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8672  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8673  */
8674 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8675 {
8676   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8677   if(!content)
8678     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8679   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8680   std::size_t sz(contentsSplit.size());
8681   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8682   for(std::size_t i=0;i<sz;i++)
8683     {
8684       ret[i]=shallowCpy();
8685       ret[i]->_content=contentsSplit[i];
8686     }
8687   return ret;
8688 }
8689
8690 /*!
8691  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8692  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8693  */
8694 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8695 {
8696   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8697   if(!content)
8698     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8699   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8700   std::size_t sz(contentsSplit.size());
8701   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8702   for(std::size_t i=0;i<sz;i++)
8703     {
8704       ret[i]=shallowCpy();
8705       ret[i]->_content=contentsSplit[i];
8706     }
8707   return ret;
8708 }
8709
8710 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8711 {
8712   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8713   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8714     ret->_content=_content->deepCopy();
8715   ret->deepCpyGlobs(*this);
8716   return ret.retn();
8717 }
8718
8719 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8720 {
8721   return _content;
8722 }
8723
8724 /*!
8725  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8726  *  \param [in] iteration - the iteration number of a required time step.
8727  *  \param [in] order - the iteration order number of required time step.
8728  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8729  *          delete this field using decrRef() as it is no more needed.
8730  *  \throw If there is no required time step in \a this field.
8731  */
8732 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8733 {
8734   int pos=getPosOfTimeStep(iteration,order);
8735   return getTimeStepAtPos(pos);
8736 }
8737
8738 /*!
8739  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8740  *  \param [in] time - the time of the time step of interest.
8741  *  \param [in] eps - a precision used to compare time values.
8742  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8743  *          delete this field using decrRef() as it is no more needed.
8744  *  \throw If there is no required time step in \a this field.
8745  */
8746 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8747 {
8748   int pos=getPosGivenTime(time,eps);
8749   return getTimeStepAtPos(pos);
8750 }
8751
8752 /*!
8753  * 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.
8754  * The float64 value of time attached to the pair of integers are not considered here.
8755  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8756  *
8757  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8758  * \throw If there is a null pointer in \a vectFMTS.
8759  */
8760 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8761 {
8762   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8763   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8764   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8765   while(!lstFMTS.empty())
8766     {
8767       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8768       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8769       if(!curIt)
8770         throw INTERP_KERNEL::Exception(msg);
8771       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8772       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8773       elt.push_back(curIt); it=lstFMTS.erase(it);
8774       while(it!=lstFMTS.end())
8775         {
8776           curIt=*it;
8777           if(!curIt)
8778             throw INTERP_KERNEL::Exception(msg);
8779           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8780           if(refIts==curIts)
8781             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8782           else
8783             it++;
8784         }
8785       ret.push_back(elt);
8786     }
8787   return ret;
8788 }
8789
8790 /*!
8791  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8792  * All returned instances in a subvector can be safely loaded, rendered along time
8793  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8794  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8795  * 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).
8796  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8797  * 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.
8798  *
8799  * \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().
8800  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8801  * \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.
8802  * \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.
8803  *
8804  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8805  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8806  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8807  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8808  * \throw If mesh is null.
8809  * \throw If an element in \a vectFMTS is null.
8810  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8811  */
8812 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
8813 {
8814   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8815   if(!mesh)
8816     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8817   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8818   if(vectFMTS.empty())
8819     return ret;
8820   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8821   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8822   if(!frstElt)
8823     throw INTERP_KERNEL::Exception(msg);
8824   std::size_t i=0;
8825   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8826   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8827   for(;it!=vectFMTS.end();it++,i++)
8828     {
8829       if(!(*it))
8830         throw INTERP_KERNEL::Exception(msg);
8831       TypeOfField tof0,tof1;
8832       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8833         {
8834           if(tof1!=ON_NODES)
8835             vectFMTSNotNodes.push_back(*it);
8836           else
8837             vectFMTSNodes.push_back(*it);
8838         }
8839       else
8840         vectFMTSNotNodes.push_back(*it);
8841     }
8842   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
8843   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8844   ret=retCell;
8845   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8846     {
8847       i=0;
8848       bool isFetched(false);
8849       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8850         {
8851           if((*it0).empty())
8852             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8853           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8854             { ret[i].push_back(*it2); isFetched=true; }
8855         }
8856       if(!isFetched)
8857         {
8858           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8859           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8860           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8861         }
8862     }
8863   fsc=cmps;
8864   return ret;
8865 }
8866
8867 /*!
8868  * 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.
8869  * \param [out] cmps - same size than the returned vector.
8870  */
8871 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
8872 {
8873   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8874   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8875   while(!lstFMTS.empty())
8876     {
8877       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8878       MEDFileAnyTypeFieldMultiTS *ref(*it);
8879       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8880       elt.push_back(ref); it=lstFMTS.erase(it);
8881       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8882       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8883       while(it!=lstFMTS.end())
8884         {
8885           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8886           if(cmp->isEqual(curIt))
8887             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8888           else
8889             it++;
8890         }
8891       ret.push_back(elt); cmps.push_back(cmp);
8892     }
8893   return ret;
8894 }
8895
8896 /*!
8897  * 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.
8898  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8899  *
8900  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8901  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8902  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8903  * \thorw If \a f0 and \a f1 do not have the same times steps.
8904  * \throw If mesh is null.
8905  * \throw If \a f0 or \a f1 is null.
8906  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8907  */
8908 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8909 {
8910   if(!mesh)
8911     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8912   if(!f0 || !f1)
8913     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8914   if(f0->getMeshName()!=mesh->getName())
8915     {
8916       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8917       throw INTERP_KERNEL::Exception(oss.str().c_str());
8918     }
8919   if(f1->getMeshName()!=mesh->getName())
8920     {
8921       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8922       throw INTERP_KERNEL::Exception(oss.str().c_str());
8923     }
8924   int nts=f0->getNumberOfTS();
8925   if(nts!=f1->getNumberOfTS())
8926     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8927   if(nts==0)
8928     return nts;
8929   for(int i=0;i<nts;i++)
8930     {
8931       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8932       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8933       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8934       if(tofs0.size()!=1 || tofs1.size()!=1)
8935         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8936       if(i!=0)
8937         {
8938           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8939             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8940         }
8941       else
8942         { tof0=tofs0[0]; tof1=tofs1[0]; }
8943       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8944         {
8945           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() << ") !";
8946           throw INTERP_KERNEL::Exception(oss.str().c_str());
8947         }
8948       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8949         {
8950           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() << ") !";
8951           throw INTERP_KERNEL::Exception(oss.str().c_str());
8952         }
8953       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8954         {
8955           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() << ") !";
8956           throw INTERP_KERNEL::Exception(oss.str().c_str());
8957         }
8958     }
8959   return nts;
8960 }
8961
8962 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8963 {
8964   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8965 }
8966
8967 //= MEDFileFieldMultiTS
8968
8969 /*!
8970  * Returns a new empty instance of MEDFileFieldMultiTS.
8971  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8972  *          is to delete this field using decrRef() as it is no more needed.
8973  */
8974 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8975 {
8976   return new MEDFileFieldMultiTS;
8977 }
8978
8979 /*!
8980  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8981  * that has been read from a specified MED file.
8982  *  \param [in] fileName - the name of the MED file to read.
8983  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8984  *          is to delete this field using decrRef() as it is no more needed.
8985  *  \throw If reading the file fails.
8986  */
8987 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8988 {
8989   MCAuto<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
8990   ret->contentNotNull();//to check that content type matches with \a this type.
8991   return ret.retn();
8992 }
8993
8994 /*!
8995  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8996  * that has been read from a specified MED file.
8997  *  \param [in] fileName - the name of the MED file to read.
8998  *  \param [in] fieldName - the name of the field to read.
8999  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9000  *          is to delete this field using decrRef() as it is no more needed.
9001  *  \throw If reading the file fails.
9002  *  \throw If there is no field named \a fieldName in the file.
9003  */
9004 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9005 {
9006   MCAuto<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
9007   ret->contentNotNull();//to check that content type matches with \a this type.
9008   return ret.retn();
9009 }
9010
9011 /*!
9012  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9013  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9014  *
9015  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9016  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9017  * \warning this is a shallow copy constructor
9018  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9019  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9020  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9021  *          is to delete this field using decrRef() as it is no more needed.
9022  */
9023 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9024 {
9025   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9026 }
9027
9028 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9029 {
9030   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0,&entities));
9031   ret->contentNotNull();//to check that content type matches with \a this type.
9032   return ret.retn();
9033 }
9034
9035 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9036 {
9037   return new MEDFileFieldMultiTS(*this);
9038 }
9039
9040 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9041 {
9042   if(!f1ts)
9043     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9044   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9045   if(!f1tsC)
9046     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9047 }
9048
9049 /*!
9050  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9051  * following the given input policy.
9052  *
9053  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9054  *                            By default (true) the globals are deeply copied.
9055  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9056  */
9057 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9058 {
9059   MCAuto<MEDFileIntFieldMultiTS> ret;
9060   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9061   if(content)
9062     {
9063       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9064       if(!contc)
9065         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9066       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9067       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
9068     }
9069   else
9070     ret=MEDFileIntFieldMultiTS::New();
9071   if(isDeepCpyGlobs)
9072     ret->deepCpyGlobs(*this);
9073   else
9074     ret->shallowCpyGlobs(*this);
9075   return ret.retn();
9076 }
9077
9078 /*!
9079  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9080  *  \param [in] pos - a time step id.
9081  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9082  *          delete this field using decrRef() as it is no more needed.
9083  *  \throw If \a pos is not a valid time step id.
9084  */
9085 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9086 {
9087   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9088   if(!item)
9089     {
9090       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9091       throw INTERP_KERNEL::Exception(oss.str().c_str());
9092     }
9093   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9094   if(itemC)
9095     {
9096       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9097       ret->shallowCpyGlobs(*this);
9098       return ret.retn();
9099     }
9100   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9101   throw INTERP_KERNEL::Exception(oss.str().c_str());
9102 }
9103
9104 /*!
9105  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9106  * mesh entities of a given dimension of the first mesh in MED file.
9107  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9108  *  \param [in] type - a spatial discretization of interest.
9109  *  \param [in] iteration - the iteration number of a required time step.
9110  *  \param [in] order - the iteration order number of required time step.
9111  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9112  *  \param [in] renumPol - specifies how to permute values of the result field according to
9113  *          the optional numbers of cells and nodes, if any. The valid values are
9114  *          - 0 - do not permute.
9115  *          - 1 - permute cells.
9116  *          - 2 - permute nodes.
9117  *          - 3 - permute cells and nodes.
9118  *
9119  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9120  *          caller is to delete this field using decrRef() as it is no more needed. 
9121  *  \throw If the MED file is not readable.
9122  *  \throw If there is no mesh in the MED file.
9123  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9124  *  \throw If no field values of the required parameters are available.
9125  */
9126 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9127 {
9128   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9129   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9130   if(!myF1TSC)
9131     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9132   MCAuto<DataArray> arrOut;
9133   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9134   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9135   return ret.retn();
9136 }
9137
9138 /*!
9139  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9140  * the top level cells of the first mesh in MED file.
9141  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9142  *  \param [in] type - a spatial discretization of interest.
9143  *  \param [in] iteration - the iteration number of a required time step.
9144  *  \param [in] order - the iteration order number of required time step.
9145  *  \param [in] renumPol - specifies how to permute values of the result field according to
9146  *          the optional numbers of cells and nodes, if any. The valid values are
9147  *          - 0 - do not permute.
9148  *          - 1 - permute cells.
9149  *          - 2 - permute nodes.
9150  *          - 3 - permute cells and nodes.
9151  *
9152  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9153  *          caller is to delete this field using decrRef() as it is no more needed. 
9154  *  \throw If the MED file is not readable.
9155  *  \throw If there is no mesh in the MED file.
9156  *  \throw If no field values of the required parameters are available.
9157  */
9158 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9159 {
9160   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9161   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9162   if(!myF1TSC)
9163     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9164   MCAuto<DataArray> arrOut;
9165   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9166   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9167   return ret.retn();
9168 }
9169
9170 /*!
9171  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9172  * a given support.
9173  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9174  *  \param [in] type - a spatial discretization of interest.
9175  *  \param [in] iteration - the iteration number of a required time step.
9176  *  \param [in] order - the iteration order number of required time step.
9177  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9178  *  \param [in] mesh - the supporting mesh.
9179  *  \param [in] renumPol - specifies how to permute values of the result field according to
9180  *          the optional numbers of cells and nodes, if any. The valid values are
9181  *          - 0 - do not permute.
9182  *          - 1 - permute cells.
9183  *          - 2 - permute nodes.
9184  *          - 3 - permute cells and nodes.
9185  *
9186  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9187  *          caller is to delete this field using decrRef() as it is no more needed. 
9188  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9189  *  \throw If no field of \a this is lying on \a mesh.
9190  *  \throw If no field values of the required parameters are available.
9191  */
9192 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9193 {
9194   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9195   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9196   if(!myF1TSC)
9197     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9198   MCAuto<DataArray> arrOut;
9199   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9200   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9201   return ret.retn();
9202 }
9203
9204 /*!
9205  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9206  * given support. 
9207  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9208  *  \param [in] type - a spatial discretization of the new field.
9209  *  \param [in] iteration - the iteration number of a required time step.
9210  *  \param [in] order - the iteration order number of required time step.
9211  *  \param [in] mesh - the supporting mesh.
9212  *  \param [in] renumPol - specifies how to permute values of the result field according to
9213  *          the optional numbers of cells and nodes, if any. The valid values are
9214  *          - 0 - do not permute.
9215  *          - 1 - permute cells.
9216  *          - 2 - permute nodes.
9217  *          - 3 - permute cells and nodes.
9218  *
9219  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9220  *          caller is to delete this field using decrRef() as it is no more needed. 
9221  *  \throw If no field of \a this is lying on \a mesh.
9222  *  \throw If no field values of the required parameters are available.
9223  */
9224 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9225 {
9226   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9227   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9228   if(!myF1TSC)
9229     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9230   MCAuto<DataArray> arrOut;
9231   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9232   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9233   return ret.retn();
9234 }
9235
9236 /*!
9237  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9238  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9239  * This method is useful for MED2 file format when field on different mesh was autorized.
9240  */
9241 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9242 {
9243   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9244   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9245   if(!myF1TSC)
9246     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9247   MCAuto<DataArray> arrOut;
9248   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9249   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9250   return ret.retn();
9251 }
9252
9253 /*!
9254  * Returns values and a profile of the field of a given type, of a given time step,
9255  * lying on a given support.
9256  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9257  *  \param [in] type - a spatial discretization of the field.
9258  *  \param [in] iteration - the iteration number of a required time step.
9259  *  \param [in] order - the iteration order number of required time step.
9260  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9261  *  \param [in] mesh - the supporting mesh.
9262  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9263  *          field of interest lies on. If the field lies on all entities of the given
9264  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9265  *          using decrRef() as it is no more needed.  
9266  *  \param [in] glob - the global data storing profiles and localization.
9267  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9268  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9269  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9270  *  \throw If no field of \a this is lying on \a mesh.
9271  *  \throw If no field values of the required parameters are available.
9272  */
9273 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9274 {
9275   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9276   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9277   if(!myF1TSC)
9278     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9279   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9280   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9281 }
9282
9283 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9284 {
9285   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9286   if(!pt)
9287     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9288   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9289   if(!ret)
9290     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 !");
9291   return ret;
9292 }
9293
9294 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9295 {
9296   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9297   if(!pt)
9298     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9299   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9300   if(!ret)
9301     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 !");
9302   return ret;
9303 }
9304
9305 /*!
9306  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9307  * the given field is checked if its elements are sorted suitable for writing to MED file
9308  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9309  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9310  *  \param [in] field - the field to add to \a this.
9311  *  \throw If the name of \a field is empty.
9312  *  \throw If the data array of \a field is not set.
9313  *  \throw If existing time steps have different name or number of components than \a field.
9314  *  \throw If the underlying mesh of \a field has no name.
9315  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9316  */
9317 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9318 {
9319   const DataArrayDouble *arr=0;
9320   if(field)
9321     arr=field->getArray();
9322   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9323 }
9324
9325 /*!
9326  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9327  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9328  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9329  * and \a profile.
9330  *
9331  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9332  * A new profile is added only if no equal profile is missing.
9333  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9334  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9335  *  \param [in] mesh - the supporting mesh of \a field.
9336  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9337  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9338  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9339  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9340  *  \throw If the data array of \a field is not set.
9341  *  \throw If the data array of \a this is already allocated but has different number of
9342  *         components than \a field.
9343  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9344  *  \sa setFieldNoProfileSBT()
9345  */
9346 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9347 {
9348   const DataArrayDouble *arr=0;
9349   if(field)
9350     arr=field->getArray();
9351   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9352 }
9353
9354 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9355 {
9356   _content=new MEDFileFieldMultiTSWithoutSDA;
9357 }
9358
9359 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9360 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9361 {
9362 }
9363 catch(INTERP_KERNEL::Exception& e)
9364 { throw e; }
9365
9366 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)
9367 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9368 {
9369 }
9370 catch(INTERP_KERNEL::Exception& e)
9371 { throw e; }
9372
9373 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9374 {
9375 }
9376
9377 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
9378 {
9379   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9380 }
9381
9382 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9383 {
9384   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9385 }
9386
9387 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9388 {
9389   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9390 }
9391
9392 /*!
9393  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9394  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9395  *
9396  * \return A new object that the caller is responsible to deallocate.
9397  */
9398 MEDFileFieldMultiTS *MEDFileFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9399 {
9400   if(!mm)
9401     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9402   MCAuto<MEDFileFieldMultiTS> fmtsOut(MEDFileFieldMultiTS::New());
9403   int nbTS(getNumberOfTS());
9404   for(int i=0;i<nbTS;i++)
9405     {
9406       MCAuto<MEDFileField1TS> f1ts(getTimeStepAtPos(i));
9407       MCAuto<MEDFileField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9408       fmtsOut->pushBackTimeStep(f1tsOut);
9409     }
9410   return fmtsOut.retn();
9411 }
9412
9413 //= MEDFileAnyTypeFieldMultiTSIterator
9414
9415 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9416 {
9417   if(fmts)
9418     {
9419       fmts->incrRef();
9420       _nb_iter=fmts->getNumberOfTS();
9421     }
9422 }
9423
9424 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9425 {
9426 }
9427
9428 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9429 {
9430   if(_iter_id<_nb_iter)
9431     {
9432       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9433       if(fmts)
9434         return fmts->getTimeStepAtPos(_iter_id++);
9435       else
9436         return 0;
9437     }
9438   else
9439     return 0;
9440 }
9441
9442 //= MEDFileIntFieldMultiTS
9443
9444 /*!
9445  * Returns a new empty instance of MEDFileFieldMultiTS.
9446  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9447  *          is to delete this field using decrRef() as it is no more needed.
9448  */
9449 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9450 {
9451   return new MEDFileIntFieldMultiTS;
9452 }
9453
9454 /*!
9455  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9456  * that has been read from a specified MED file.
9457  *  \param [in] fileName - the name of the MED file to read.
9458  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9459  *          is to delete this field using decrRef() as it is no more needed.
9460  *  \throw If reading the file fails.
9461  */
9462 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9463 {
9464   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9465   ret->contentNotNull();//to check that content type matches with \a this type.
9466   return ret.retn();
9467 }
9468
9469 /*!
9470  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9471  * that has been read from a specified MED file.
9472  *  \param [in] fileName - the name of the MED file to read.
9473  *  \param [in] fieldName - the name of the field to read.
9474  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9475  *          is to delete this field using decrRef() as it is no more needed.
9476  *  \throw If reading the file fails.
9477  *  \throw If there is no field named \a fieldName in the file.
9478  */
9479 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9480 {
9481   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9482   ret->contentNotNull();//to check that content type matches with \a this type.
9483   return ret.retn();
9484 }
9485
9486 /*!
9487  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9488  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9489  *
9490  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9491  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9492  * \warning this is a shallow copy constructor
9493  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9494  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9495  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9496  *          is to delete this field using decrRef() as it is no more needed.
9497  */
9498 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9499 {
9500   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9501 }
9502
9503 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9504 {
9505   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0,&entities);
9506   ret->contentNotNull();//to check that content type matches with \a this type.
9507   return ret.retn();
9508 }
9509
9510 /*!
9511  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9512  * following the given input policy.
9513  *
9514  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9515  *                            By default (true) the globals are deeply copied.
9516  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9517  */
9518 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9519 {
9520   MCAuto<MEDFileFieldMultiTS> ret;
9521   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9522   if(content)
9523     {
9524       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9525       if(!contc)
9526         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9527       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9528       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9529     }
9530   else
9531     ret=MEDFileFieldMultiTS::New();
9532   if(isDeepCpyGlobs)
9533     ret->deepCpyGlobs(*this);
9534   else
9535     ret->shallowCpyGlobs(*this);
9536   return ret.retn();
9537 }
9538
9539 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9540 {
9541   return new MEDFileIntFieldMultiTS(*this);
9542 }
9543
9544 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9545 {
9546   if(!f1ts)
9547     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9548   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9549   if(!f1tsC)
9550     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9551 }
9552
9553 /*!
9554  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9555  * mesh entities of a given dimension of the first mesh in MED file.
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 [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9561  *  \param [out] arrOut - the DataArrayInt containing values of field.
9562  *  \param [in] renumPol - specifies how to permute values of the result field according to
9563  *          the optional numbers of cells and nodes, if any. The valid values are
9564  *          - 0 - do not permute.
9565  *          - 1 - permute cells.
9566  *          - 2 - permute nodes.
9567  *          - 3 - permute cells and nodes.
9568  *
9569  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9570  *          caller is to delete this field using decrRef() as it is no more needed. 
9571  *  \throw If the MED file is not readable.
9572  *  \throw If there is no mesh in the MED file.
9573  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9574  *  \throw If no field values of the required parameters are available.
9575  */
9576 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, 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("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9582   MCAuto<DataArray> arr;
9583   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9584   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9585   return ret.retn();
9586 }
9587
9588 /*!
9589  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9590  * the top level cells of the first mesh in MED file.
9591  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9592  *  \param [in] type - a spatial discretization of interest.
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 [out] arrOut - the DataArrayInt containing values of field.
9596  *  \param [in] renumPol - specifies how to permute values of the result field according to
9597  *          the optional numbers of cells and nodes, if any. The valid values are
9598  *          - 0 - do not permute.
9599  *          - 1 - permute cells.
9600  *          - 2 - permute nodes.
9601  *          - 3 - permute cells and nodes.
9602  *
9603  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9604  *          caller is to delete this field using decrRef() as it is no more needed. 
9605  *  \throw If the MED file is not readable.
9606  *  \throw If there is no mesh in the MED file.
9607  *  \throw If no field values of the required parameters are available.
9608  */
9609 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, 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("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9615   MCAuto<DataArray> arr;
9616   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9617   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9618   return ret.retn();
9619 }
9620
9621 /*!
9622  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9623  * a given support.
9624  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9625  *  \param [in] type - a spatial discretization of interest.
9626  *  \param [in] iteration - the iteration number of a required time step.
9627  *  \param [in] order - the iteration order number of required time step.
9628  *  \param [out] arrOut - the DataArrayInt containing values of field.
9629  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9630  *  \param [in] mesh - the supporting mesh.
9631  *  \param [in] renumPol - specifies how to permute values of the result field according to
9632  *          the optional numbers of cells and nodes, if any. The valid values are
9633  *          - 0 - do not permute.
9634  *          - 1 - permute cells.
9635  *          - 2 - permute nodes.
9636  *          - 3 - permute cells and nodes.
9637  *
9638  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9639  *          caller is to delete this field using decrRef() as it is no more needed. 
9640  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9641  *  \throw If no field of \a this is lying on \a mesh.
9642  *  \throw If no field values of the required parameters are available.
9643  */
9644 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9645 {
9646   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9647   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9648   if(!myF1TSC)
9649     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9650   MCAuto<DataArray> arr;
9651   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9652   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9653   return ret.retn();
9654 }
9655
9656 /*!
9657  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9658  * given support. 
9659  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9660  *  \param [in] type - a spatial discretization of the new field.
9661  *  \param [in] iteration - the iteration number of a required time step.
9662  *  \param [in] order - the iteration order number of required time step.
9663  *  \param [in] mesh - the supporting mesh.
9664  *  \param [out] arrOut - the DataArrayInt containing values of field.
9665  *  \param [in] renumPol - specifies how to permute values of the result field according to
9666  *          the optional numbers of cells and nodes, if any. The valid values are
9667  *          - 0 - do not permute.
9668  *          - 1 - permute cells.
9669  *          - 2 - permute nodes.
9670  *          - 3 - permute cells and nodes.
9671  *
9672  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9673  *          caller is to delete this field using decrRef() as it is no more needed. 
9674  *  \throw If no field of \a this is lying on \a mesh.
9675  *  \throw If no field values of the required parameters are available.
9676  */
9677 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9678 {
9679   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9680   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9681   if(!myF1TSC)
9682     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9683   MCAuto<DataArray> arr;
9684   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9685   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9686   return ret.retn();
9687 }
9688
9689 /*!
9690  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9691  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9692  * This method is useful for MED2 file format when field on different mesh was autorized.
9693  */
9694 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9695 {
9696   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9697   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9698   if(!myF1TSC)
9699     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9700   MCAuto<DataArray> arr;
9701   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9702   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9703   return ret.retn();
9704 }
9705
9706 /*!
9707  * Returns values and a profile of the field of a given type, of a given time step,
9708  * lying on a given support.
9709  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9710  *  \param [in] type - a spatial discretization of the field.
9711  *  \param [in] iteration - the iteration number of a required time step.
9712  *  \param [in] order - the iteration order number of required time step.
9713  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9714  *  \param [in] mesh - the supporting mesh.
9715  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9716  *          field of interest lies on. If the field lies on all entities of the given
9717  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9718  *          using decrRef() as it is no more needed.  
9719  *  \param [in] glob - the global data storing profiles and localization.
9720  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9721  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9722  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9723  *  \throw If no field of \a this is lying on \a mesh.
9724  *  \throw If no field values of the required parameters are available.
9725  */
9726 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9727 {
9728   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9729   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9730   if(!myF1TSC)
9731     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9732   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9733   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9734 }
9735
9736 /*!
9737  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9738  *  \param [in] pos - a time step id.
9739  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9740  *          delete this field using decrRef() as it is no more needed.
9741  *  \throw If \a pos is not a valid time step id.
9742  */
9743 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9744 {
9745   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9746   if(!item)
9747     {
9748       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9749       throw INTERP_KERNEL::Exception(oss.str().c_str());
9750     }
9751   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9752   if(itemC)
9753     {
9754       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9755       ret->shallowCpyGlobs(*this);
9756       return ret.retn();
9757     }
9758   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9759   throw INTERP_KERNEL::Exception(oss.str().c_str());
9760 }
9761
9762 /*!
9763  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9764  * the given field is checked if its elements are sorted suitable for writing to MED file
9765  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9766  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9767  *  \param [in] field - the field to add to \a this.
9768  *  \throw If the name of \a field is empty.
9769  *  \throw If the data array of \a field is not set.
9770  *  \throw If existing time steps have different name or number of components than \a field.
9771  *  \throw If the underlying mesh of \a field has no name.
9772  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9773  */
9774 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9775 {
9776   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9777 }
9778
9779 /*!
9780  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9781  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9782  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9783  * and \a profile.
9784  *
9785  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9786  * A new profile is added only if no equal profile is missing.
9787  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9788  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9789  *  \param [in] arrOfVals - the values of the field \a field used.
9790  *  \param [in] mesh - the supporting mesh of \a field.
9791  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9792  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9793  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9794  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9795  *  \throw If the data array of \a field is not set.
9796  *  \throw If the data array of \a this is already allocated but has different number of
9797  *         components than \a field.
9798  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9799  *  \sa setFieldNoProfileSBT()
9800  */
9801 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9802 {
9803   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9804 }
9805
9806 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9807 {
9808   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9809   if(!pt)
9810     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9811   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9812   if(!ret)
9813     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 !");
9814   return ret;
9815 }
9816
9817 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9818 {
9819   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9820   if(!pt)
9821     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9822   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9823   if(!ret)
9824     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 !");
9825   return ret;
9826 }
9827
9828 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9829 {
9830   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9831 }
9832
9833 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9834 {
9835 }
9836
9837 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9838 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9839 {
9840 }
9841 catch(INTERP_KERNEL::Exception& e)
9842 { throw e; }
9843
9844 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)
9845 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9846 {
9847 }
9848 catch(INTERP_KERNEL::Exception& e)
9849 { throw e; }
9850
9851 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9852 {
9853   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9854 }
9855
9856 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9857 {
9858   throw INTERP_KERNEL::Exception("*MEDFileIntFieldMultiTS::extractPart : not implemented yet for int !");
9859 }
9860
9861 //= MEDFileFields
9862
9863 MEDFileFields *MEDFileFields::New()
9864 {
9865   return new MEDFileFields;
9866 }
9867
9868 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9869 {
9870   return new MEDFileFields(fileName,loadAll,0,0);
9871 }
9872
9873 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9874 {
9875   return new MEDFileFields(fileName,loadAll,ms,0);
9876 }
9877
9878 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9879 {
9880   return new MEDFileFields(fileName,loadAll,0,&entities);
9881 }
9882
9883 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9884 {
9885   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9886   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9887   return ret;
9888 }
9889
9890 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9891 {
9892   std::vector<const BigMemoryObject *> ret;
9893   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9894     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9895   return ret;
9896 }
9897
9898 MEDFileFields *MEDFileFields::deepCopy() const
9899 {
9900   MCAuto<MEDFileFields> ret=shallowCpy();
9901   std::size_t i=0;
9902   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9903     {
9904       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9905         ret->_fields[i]=(*it)->deepCopy();
9906     }
9907   ret->deepCpyGlobs(*this);
9908   return ret.retn();
9909 }
9910
9911 MEDFileFields *MEDFileFields::shallowCpy() const
9912 {
9913   return new MEDFileFields(*this);
9914 }
9915
9916 /*!
9917  * 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
9918  * 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.
9919  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9920  *
9921  * \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.
9922  * \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.
9923  * 
9924  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9925  */
9926 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9927 {
9928   std::set< std::pair<int,int> > s;
9929   bool firstShot=true;
9930   areThereSomeForgottenTS=false;
9931   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9932     {
9933       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9934         continue;
9935       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9936       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9937       if(firstShot)
9938         { s=s1; firstShot=false; }
9939       else
9940         {
9941           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9942           if(s!=s2)
9943             areThereSomeForgottenTS=true;
9944           s=s2;
9945         }
9946     }
9947   std::vector< std::pair<int,int> > ret;
9948   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9949   return ret;
9950 }
9951
9952 int MEDFileFields::getNumberOfFields() const
9953 {
9954   return _fields.size();
9955 }
9956
9957 std::vector<std::string> MEDFileFields::getFieldsNames() const
9958 {
9959   std::vector<std::string> ret(_fields.size());
9960   int i=0;
9961   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9962     {
9963       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9964       if(f)
9965         {
9966           ret[i]=f->getName();
9967         }
9968       else
9969         {
9970           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9971           throw INTERP_KERNEL::Exception(oss.str().c_str());
9972         }
9973     }
9974   return ret;
9975 }
9976
9977 std::vector<std::string> MEDFileFields::getMeshesNames() const
9978 {
9979   std::vector<std::string> ret;
9980   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9981     {
9982       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9983       if(cur)
9984         ret.push_back(cur->getMeshName());
9985     }
9986   return ret;
9987 }
9988
9989 std::string MEDFileFields::simpleRepr() const
9990 {
9991   std::ostringstream oss;
9992   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9993   simpleRepr(0,oss);
9994   return oss.str();
9995 }
9996
9997 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9998 {
9999   int nbOfFields=getNumberOfFields();
10000   std::string startLine(bkOffset,' ');
10001   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10002   int i=0;
10003   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10004     {
10005       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10006       if(cur)
10007         {
10008           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10009         }
10010       else
10011         {
10012           oss << startLine << "  - not defined !" << std::endl;
10013         }
10014     }
10015   i=0;
10016   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10017     {
10018       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10019       std::string chapter(17,'0'+i);
10020       oss << startLine << chapter << std::endl;
10021       if(cur)
10022         {
10023           cur->simpleRepr(bkOffset+2,oss,i);
10024         }
10025       else
10026         {
10027           oss << startLine << "  - not defined !" << std::endl;
10028         }
10029       oss << startLine << chapter << std::endl;
10030     }
10031   simpleReprGlobs(oss);
10032 }
10033
10034 MEDFileFields::MEDFileFields()
10035 {
10036 }
10037
10038 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
10039 try:MEDFileFieldGlobsReal(fileName)
10040 {
10041   MEDFileUtilities::CheckFileForRead(fileName);
10042   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
10043   int nbFields(MEDnField(fid));
10044   _fields.resize(nbFields);
10045   med_field_type typcha;
10046   for(int i=0;i<nbFields;i++)
10047     {
10048       std::vector<std::string> infos;
10049       std::string fieldName,dtunit;
10050       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
10051       switch(typcha)
10052       {
10053         case MED_FLOAT64:
10054           {
10055             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10056             break;
10057           }
10058         case MED_INT32:
10059           {
10060             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10061             break;
10062           }
10063         default:
10064           {
10065             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] !";
10066             throw INTERP_KERNEL::Exception(oss.str().c_str());
10067           }
10068       }
10069     }
10070   loadAllGlobals(fid);
10071 }
10072 catch(INTERP_KERNEL::Exception& e)
10073 {
10074     throw e;
10075 }
10076
10077 void MEDFileFields::writeLL(med_idt fid) const
10078 {
10079   int i=0;
10080   writeGlobals(fid,*this);
10081   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10082     {
10083       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10084       if(!elt)
10085         {
10086           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10087           throw INTERP_KERNEL::Exception(oss.str().c_str());
10088         }
10089       elt->writeLL(fid,*this);
10090     }
10091 }
10092
10093 void MEDFileFields::write(const std::string& fileName, int mode) const
10094 {
10095   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
10096   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
10097   writeLL(fid);
10098 }
10099
10100 /*!
10101  * This method alloc the arrays and load potentially huge arrays contained in this field.
10102  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10103  * This method can be also called to refresh or reinit values from a file.
10104  * 
10105  * \throw If the fileName is not set or points to a non readable MED file.
10106  */
10107 void MEDFileFields::loadArrays()
10108 {
10109   if(getFileName().empty())
10110     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10111   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10112   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10113     {
10114       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10115       if(elt)
10116         elt->loadBigArraysRecursively(fid,*elt);
10117     }
10118 }
10119
10120 /*!
10121  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10122  * But once data loaded once, this method does nothing.
10123  * 
10124  * \throw If the fileName is not set or points to a non readable MED file.
10125  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10126  */
10127 void MEDFileFields::loadArraysIfNecessary()
10128 {
10129   if(!getFileName().empty())
10130     {
10131       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10132       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10133         {
10134           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10135           if(elt)
10136             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10137         }
10138     }
10139 }
10140
10141 /*!
10142  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10143  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10144  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10145  * 
10146  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10147  */
10148 void MEDFileFields::unloadArrays()
10149 {
10150   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10151     {
10152       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10153       if(elt)
10154         elt->unloadArrays();
10155     }
10156 }
10157
10158 /*!
10159  * 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.
10160  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10161  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10162  * 
10163  * \sa MEDFileFields::loadArraysIfNecessary
10164  */
10165 void MEDFileFields::unloadArraysWithoutDataLoss()
10166 {
10167   if(!getFileName().empty())
10168     unloadArrays();
10169 }
10170
10171 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10172 {
10173   std::vector<std::string> ret;
10174   std::set<std::string> ret2;
10175   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10176     {
10177       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10178       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10179         if(ret2.find(*it2)==ret2.end())
10180           {
10181             ret.push_back(*it2);
10182             ret2.insert(*it2);
10183           }
10184     }
10185   return ret;
10186 }
10187
10188 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10189 {
10190   std::vector<std::string> ret;
10191   std::set<std::string> ret2;
10192   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10193     {
10194       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10195       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10196         if(ret2.find(*it2)==ret2.end())
10197           {
10198             ret.push_back(*it2);
10199             ret2.insert(*it2);
10200           }
10201     }
10202   return ret;
10203 }
10204
10205 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10206 {
10207   std::vector<std::string> ret;
10208   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10209     {
10210       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
10211       ret.insert(ret.end(),tmp.begin(),tmp.end());
10212     }
10213   return ret;
10214 }
10215
10216 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10217 {
10218   std::vector<std::string> ret;
10219   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10220     {
10221       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10222       ret.insert(ret.end(),tmp.begin(),tmp.end());
10223     }
10224   return ret;
10225 }
10226
10227 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10228 {
10229   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10230     (*it)->changePflsRefsNamesGen2(mapOfModif);
10231 }
10232
10233 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10234 {
10235   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10236     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10237 }
10238
10239 void MEDFileFields::resize(int newSize)
10240 {
10241   _fields.resize(newSize);
10242 }
10243
10244 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10245 {
10246   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10247     pushField(*it);
10248 }
10249
10250 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10251 {
10252   if(!field)
10253     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10254   _fields.push_back(field->getContent());
10255   appendGlobs(*field,1e-12);
10256 }
10257
10258 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10259 {
10260   if(!field)
10261     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10262   if(i>=(int)_fields.size())
10263     _fields.resize(i+1);
10264   _fields[i]=field->getContent();
10265   appendGlobs(*field,1e-12);
10266 }
10267
10268 void MEDFileFields::destroyFieldAtPos(int i)
10269 {
10270   destroyFieldsAtPos(&i,&i+1);
10271 }
10272
10273 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10274 {
10275   std::vector<bool> b(_fields.size(),true);
10276   for(const int *i=startIds;i!=endIds;i++)
10277     {
10278       if(*i<0 || *i>=(int)_fields.size())
10279         {
10280           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10281           throw INTERP_KERNEL::Exception(oss.str().c_str());
10282         }
10283       b[*i]=false;
10284     }
10285   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10286   std::size_t j=0;
10287   for(std::size_t i=0;i<_fields.size();i++)
10288     if(b[i])
10289       fields[j++]=_fields[i];
10290   _fields=fields;
10291 }
10292
10293 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10294 {
10295   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10296   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
10297   std::vector<bool> b(_fields.size(),true);
10298   int k=bg;
10299   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10300     {
10301       if(k<0 || k>=(int)_fields.size())
10302         {
10303           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10304           throw INTERP_KERNEL::Exception(oss.str().c_str());
10305         }
10306       b[k]=false;
10307     }
10308   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10309   std::size_t j=0;
10310   for(std::size_t i=0;i<_fields.size();i++)
10311     if(b[i])
10312       fields[j++]=_fields[i];
10313   _fields=fields;
10314 }
10315
10316 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10317 {
10318   bool ret=false;
10319   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10320     {
10321       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10322       if(cur)
10323         ret=cur->changeMeshNames(modifTab) || ret;
10324     }
10325   return ret;
10326 }
10327
10328 /*!
10329  * \param [in] meshName the name of the mesh that will be renumbered.
10330  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10331  *             This code corresponds to the distribution of types in the corresponding mesh.
10332  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10333  * \param [in] renumO2N the old to new renumber array.
10334  * \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 
10335  *         field in \a this.
10336  */
10337 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10338 {
10339   bool ret=false;
10340   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10341     {
10342       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10343       if(fmts)
10344         {
10345           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10346         }
10347     }
10348   return ret;
10349 }
10350
10351 /*!
10352  * Return an extraction of \a this using \a extractDef map to specify the extraction.
10353  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
10354  *
10355  * \return A new object that the caller is responsible to deallocate.
10356  */
10357 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
10358 {
10359   if(!mm)
10360     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
10361   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
10362   int nbFields(getNumberOfFields());
10363   for(int i=0;i<nbFields;i++)
10364     {
10365       MEDFileAnyTypeFieldMultiTS *fmts(getFieldAtPos(i));
10366       if(!fmts)
10367         {
10368           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
10369           throw INTERP_KERNEL::Exception(oss.str().c_str());
10370         }
10371       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
10372       fsOut->pushField(fmtsOut);
10373     }
10374   return fsOut.retn();
10375 }
10376
10377 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10378 {
10379   if(i<0 || i>=(int)_fields.size())
10380     {
10381       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10382       throw INTERP_KERNEL::Exception(oss.str().c_str());
10383     }
10384   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10385   if(!fmts)
10386     return 0;
10387   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
10388   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
10389   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
10390   if(fmtsC)
10391     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10392   else if(fmtsC2)
10393     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10394   else
10395     {
10396       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10397       throw INTERP_KERNEL::Exception(oss.str().c_str());
10398     }
10399   ret->shallowCpyGlobs(*this);
10400   return ret.retn();
10401 }
10402
10403 /*!
10404  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10405  * This method is accessible in python using __getitem__ with a list in input.
10406  * \return a new object that the caller should deal with.
10407  */
10408 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10409 {
10410   MCAuto<MEDFileFields> ret=shallowCpy();
10411   std::size_t sz=std::distance(startIds,endIds);
10412   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10413   int j=0;
10414   for(const int *i=startIds;i!=endIds;i++,j++)
10415     {
10416       if(*i<0 || *i>=(int)_fields.size())
10417         {
10418           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10419           throw INTERP_KERNEL::Exception(oss.str().c_str());
10420         }
10421       fields[j]=_fields[*i];
10422     }
10423   ret->_fields=fields;
10424   return ret.retn();
10425 }
10426
10427 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10428 {
10429   return getFieldAtPos(getPosFromFieldName(fieldName));
10430 }
10431
10432 /*!
10433  * This method removes, if any, fields in \a this having no time steps.
10434  * 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.
10435  * 
10436  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10437  */
10438 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10439 {
10440   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10441   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10442     {
10443       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10444       if(elt)
10445         {
10446           if(elt->getNumberOfTS()>0)
10447             newFields.push_back(*it);
10448         }
10449     }
10450   if(_fields.size()==newFields.size())
10451     return false;
10452   _fields=newFields;
10453   return true;
10454 }
10455
10456 /*!
10457  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10458  * This method can be seen as a filter applied on \a this, that returns an object containing
10459  * 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
10460  * shallow copied from \a this.
10461  * 
10462  * \param [in] meshName - the name of the mesh on w
10463  * \return a new object that the caller should deal with.
10464  */
10465 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10466 {
10467   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10468   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10469     {
10470       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10471       if(!cur)
10472         continue;
10473       if(cur->getMeshName()==meshName)
10474         {
10475           cur->incrRef();
10476           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10477           ret->_fields.push_back(cur2);
10478         }
10479     }
10480   ret->shallowCpyOnlyUsedGlobs(*this);
10481   return ret.retn();
10482 }
10483
10484 /*!
10485  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10486  * Input time steps are specified using a pair of integer (iteration, order).
10487  * 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,
10488  * but for each multitimestep only the time steps in \a timeSteps are kept.
10489  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10490  * 
10491  * The returned object points to shallow copy of elements in \a this.
10492  * 
10493  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10494  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10495  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10496  */
10497 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10498 {
10499   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10500   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10501     {
10502       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10503       if(!cur)
10504         continue;
10505       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10506       ret->_fields.push_back(elt);
10507     }
10508   ret->shallowCpyOnlyUsedGlobs(*this);
10509   return ret.retn();
10510 }
10511
10512 /*!
10513  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10514  */
10515 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10516 {
10517   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10518   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10519     {
10520       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10521       if(!cur)
10522         continue;
10523       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10524       if(elt->getNumberOfTS()!=0)
10525         ret->_fields.push_back(elt);
10526     }
10527   ret->shallowCpyOnlyUsedGlobs(*this);
10528   return ret.retn();
10529 }
10530
10531 MEDFileFieldsIterator *MEDFileFields::iterator()
10532 {
10533   return new MEDFileFieldsIterator(this);
10534 }
10535
10536 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10537 {
10538   std::string tmp(fieldName);
10539   std::vector<std::string> poss;
10540   for(std::size_t i=0;i<_fields.size();i++)
10541     {
10542       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10543       if(f)
10544         {
10545           std::string fname(f->getName());
10546           if(tmp==fname)
10547             return i;
10548           else
10549             poss.push_back(fname);
10550         }
10551     }
10552   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10553   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10554   oss << " !";
10555   throw INTERP_KERNEL::Exception(oss.str().c_str());
10556 }
10557
10558 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10559 {
10560   if(fs)
10561     {
10562       fs->incrRef();
10563       _nb_iter=fs->getNumberOfFields();
10564     }
10565 }
10566
10567 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10568 {
10569 }
10570
10571 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10572 {
10573   if(_iter_id<_nb_iter)
10574     {
10575       MEDFileFields *fs(_fs);
10576       if(fs)
10577         return fs->getFieldAtPos(_iter_id++);
10578       else
10579         return 0;
10580     }
10581   else
10582     return 0;
10583 }