]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDFileField.cxx
Salome HOME
Warning hunting
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.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   if(!arr->isAllocated())
782     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
783   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
784   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
785   const unsigned char *locToWrite=0;
786   if(arrD)
787     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
788   else if(arrI)
789     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
790   else
791     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
792   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
793                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
794                                                    locToWrite));
795 }
796
797 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
798 {
799   type=_type;
800   pfl=_profile;
801   loc=_localization;
802   dad.first=_start; dad.second=_end;
803 }
804
805 /*!
806  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
807  *             This code corresponds to the distribution of types in the corresponding mesh.
808  * \param [out] ptToFill memory zone where the output will be stored.
809  * \return the size of data pushed into output param \a ptToFill
810  */
811 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
812 {
813   _loc_id=offset;
814   std::ostringstream oss;
815   std::size_t nbOfType=codeOfMesh.size()/3;
816   int found=-1;
817   for(std::size_t i=0;i<nbOfType && found==-1;i++)
818     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
819       found=(int)i;
820   if(found==-1)
821     {
822       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
823       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
824       throw INTERP_KERNEL::Exception(oss.str().c_str());
825     }
826   int *work=ptToFill;
827   if(_profile.empty())
828     {
829       if(_nval!=codeOfMesh[3*found+1])
830         {
831           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
832           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
833           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
834           throw INTERP_KERNEL::Exception(oss.str().c_str());
835         }
836       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
837         *work++=ii;
838     }
839   else
840     {
841       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
842       if(pfl->getNumberOfTuples()!=_nval)
843         {
844           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
845           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
846           oss << _nval;
847           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
848           throw INTERP_KERNEL::Exception(oss.str().c_str());
849         }
850       int offset2=codeOfMesh[3*found+2];
851       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
852         {
853           if(*pflId<codeOfMesh[3*found+1])
854             *work++=offset2+*pflId;
855         }
856     }
857   return _nval;
858 }
859
860 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
861 {
862   for(int i=_start;i<_end;i++)
863     *ptToFill++=i;
864   return _end-_start;
865 }
866
867 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
868 {
869   switch(type)
870   {
871     case ON_CELLS:
872       return -2;
873     case ON_GAUSS_NE:
874       return -1;
875     case ON_GAUSS_PT:
876       return locId;
877     default:
878       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
879   }
880 }
881
882 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
883 {
884   int id=0;
885   std::map<std::pair<std::string,TypeOfField>,int> m;
886   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
887   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
888     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
889       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
890   ret.resize(id);
891   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
892     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
893   return ret;
894 }
895
896 /*!
897  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
898  * 
899  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
900  * \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.
901  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
902  * \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)
903  * \param [in,out] glob if necessary by the method, new profiles can be added to it
904  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
905  * \param [out] result All new entries will be appended on it.
906  * \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 !)
907  */
908 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
909                                                        const DataArrayInt *explicitIdsInMesh,
910                                                        const std::vector<int>& newCode,
911                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
912                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
913 {
914   if(entriesOnSameDisc.empty())
915     return false;
916   TypeOfField type=entriesOnSameDisc[0]->getType();
917   int szEntities=0,szTuples=0;
918   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
919     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
920   int nbi=szTuples/szEntities;
921   if(szTuples%szEntities!=0)
922     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
923   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
924   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
925   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
926   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
927   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
928   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
929   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
930   int id=0;
931   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
932     {
933       int startOfEltIdOfChunk=(*it)->_start;
934       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
935       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
936       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
937       //
938       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
939       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
940       //
941       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
942       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
943     }
944   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
945   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
946   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
947   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
948   //
949   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
950   //
951   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
952   arrPart->renumberInPlace(renumTupleIds->begin());
953   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
954   bool ret=false;
955   const int *idIt=diffVals->begin();
956   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
957   int offset2=0;
958   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
959     {
960       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
961       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
962       int nbEntityElts=subIds->getNumberOfTuples();
963       bool ret2;
964       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
965           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
966                                       offset+offset2,
967                                       li,glob,ret2);
968       ret=ret || ret2;
969       result.push_back(eltToAdd);
970       offset2+=nbEntityElts*nbi;
971     }
972   ret=ret || li.empty();
973   return ret;
974 }
975
976 /*!
977  * \param [in] typeF type of field of new chunk
978  * \param [in] geoType the geometric type of the chunk
979  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
980  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
981  * \param [in] nbi number of integration points
982  * \param [in] offset The offset in the **global array of data**.
983  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
984  *                 to the new chunk to create.
985  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
986  * \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
987  *              and corresponding entry erased from \a entriesOnSameDisc.
988  * \return a newly allocated chunk
989  */
990 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
991                                                                                                   bool isPfl, int nbi, int offset,
992                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
993                                                                                                   MEDFileFieldGlobsReal& glob,
994                                                                                                   bool &notInExisting)
995 {
996   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
997   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
998   for(;it!=entriesOnSameDisc.end();it++)
999     {
1000       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1001         {
1002           if(!isPfl)
1003             {
1004               if((*it)->_profile.empty())
1005                 break;
1006               else
1007                 if(!(*it)->_profile.empty())
1008                   {
1009                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1010                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1011                       break;
1012                   }
1013             }
1014         }
1015     }
1016   if(it==entriesOnSameDisc.end())
1017     {
1018       notInExisting=true;
1019       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1020       ret->_type=typeF;
1021       ret->_loc_id=(int)geoType;
1022       ret->_nval=nbMeshEntities;
1023       ret->_start=offset;
1024       ret->_end=ret->_start+ret->_nval*nbi;
1025       if(isPfl)
1026         {
1027           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1028           glob.appendProfile(idsOfMeshElt);
1029           ret->_profile=idsOfMeshElt->getName();
1030         }
1031       //tony treatment of localization
1032       return ret;
1033     }
1034   else
1035     {
1036       notInExisting=false;
1037       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1038       ret->_loc_id=(int)geoType;
1039       ret->setNewStart(offset);
1040       entriesOnSameDisc.erase(it);
1041       return ret;
1042     }
1043
1044 }
1045
1046 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1047 {
1048   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1049 }
1050
1051 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1052 {
1053   return new MEDFileFieldPerMeshPerType(fath,geoType);
1054 }
1055
1056 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
1057 {
1058   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1059 }
1060
1061 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
1062 {
1063   std::vector<const BigMemoryObject *> ret;
1064   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1065     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1066   return ret;
1067 }
1068
1069 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1070 {
1071   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1072   ret->_father=father;
1073   std::size_t i=0;
1074   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1075     {
1076       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1077         ret->_field_pm_pt_pd[i]=(*it)->deepCopy((MEDFileFieldPerMeshPerType *)ret);
1078     }
1079   return ret.retn();
1080 }
1081
1082 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1083 {
1084   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1085   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1086     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1087 }
1088
1089 /*!
1090  * This method is the most general one. No optimization is done here.
1091  * \param [in] multiTypePfl is the end user profile specified in high level API
1092  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1093  * \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.
1094  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1095  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1096  * \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.
1097  */
1098 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)
1099 {
1100   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1101   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1102     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1103 }
1104
1105 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1106 {
1107   _field_pm_pt_pd.resize(1);
1108   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1109   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1110 }
1111
1112 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1113 {
1114   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1115   if(!arr || !arr->isAllocated())
1116     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1117   _field_pm_pt_pd.resize(1);
1118   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1119   _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.
1120 }
1121
1122 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1123 {
1124   TypeOfField type=field->getTypeOfField();
1125   if(type!=ON_GAUSS_PT)
1126     {
1127       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1128       int sz=_field_pm_pt_pd.size();
1129       bool found=false;
1130       for(int j=0;j<sz && !found;j++)
1131         {
1132           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1133             {
1134               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1135               found=true;
1136             }
1137         }
1138       if(!found)
1139         {
1140           _field_pm_pt_pd.resize(sz+1);
1141           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1142         }
1143       std::vector<int> ret(1,(int)sz);
1144       return ret;
1145     }
1146   else
1147     {
1148       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1149       int sz2=ret2.size();
1150       std::vector<int> ret3(sz2);
1151       int k=0;
1152       for(int i=0;i<sz2;i++)
1153         {
1154           int sz=_field_pm_pt_pd.size();
1155           int locIdToFind=ret2[i];
1156           bool found=false;
1157           for(int j=0;j<sz && !found;j++)
1158             {
1159               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1160                 {
1161                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1162                   ret3[k++]=j;
1163                   found=true;
1164                 }
1165             }
1166           if(!found)
1167             {
1168               _field_pm_pt_pd.resize(sz+1);
1169               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1170               ret3[k++]=sz;
1171             }
1172         }
1173       return ret3;
1174     }
1175 }
1176
1177 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1178 {
1179   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1180   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1181   if(!disc2)
1182     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1183   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1184   if(!da)
1185     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1186   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1187   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1188   if(retTmp->presenceOfValue(-1))
1189     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1190   std::vector<int> ret(retTmp->begin(),retTmp->end());
1191   return ret;
1192 }
1193
1194 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1195 {
1196   TypeOfField type=field->getTypeOfField();
1197   if(type!=ON_GAUSS_PT)
1198     {
1199       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1200       int sz=_field_pm_pt_pd.size();
1201       bool found=false;
1202       for(int j=0;j<sz && !found;j++)
1203         {
1204           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1205             {
1206               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1207               found=true;
1208             }
1209         }
1210       if(!found)
1211         {
1212           _field_pm_pt_pd.resize(sz+1);
1213           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1214         }
1215       std::vector<int> ret(1,0);
1216       return ret;
1217     }
1218   else
1219     {
1220       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1221       int sz2=ret2.size();
1222       std::vector<int> ret3(sz2);
1223       int k=0;
1224       for(int i=0;i<sz2;i++)
1225         {
1226           int sz=_field_pm_pt_pd.size();
1227           int locIdToFind=ret2[i];
1228           bool found=false;
1229           for(int j=0;j<sz && !found;j++)
1230             {
1231               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1232                 {
1233                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1234                   ret3[k++]=j;
1235                   found=true;
1236                 }
1237             }
1238           if(!found)
1239             {
1240               _field_pm_pt_pd.resize(sz+1);
1241               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1242               ret3[k++]=sz;
1243             }
1244         }
1245       return ret3;
1246     }
1247 }
1248
1249 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1250 {
1251   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1252   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1253   if(!disc2)
1254     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1255   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1256   if(!da)
1257     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1258   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1259   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1260   if(retTmp->presenceOfValue(-1))
1261     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1262   std::vector<int> ret(retTmp->begin(),retTmp->end());
1263   return ret;
1264 }
1265
1266 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1267 {
1268   return _father;
1269 }
1270
1271 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1272 {
1273   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1274   int curDim=(int)cm.getDimension();
1275   dim=std::max(dim,curDim);
1276 }
1277
1278 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1279 {
1280   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1281     {
1282       (*it)->fillTypesOfFieldAvailable(types);
1283     }
1284 }
1285
1286 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
1287 {
1288   int sz=_field_pm_pt_pd.size();
1289   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1290   for(int i=0;i<sz;i++)
1291     {
1292       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1293     }
1294 }
1295
1296 int MEDFileFieldPerMeshPerType::getIteration() const
1297 {
1298   return _father->getIteration();
1299 }
1300
1301 int MEDFileFieldPerMeshPerType::getOrder() const
1302 {
1303   return _father->getOrder();
1304 }
1305
1306 double MEDFileFieldPerMeshPerType::getTime() const
1307 {
1308   return _father->getTime();
1309 }
1310
1311 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1312 {
1313   return _father->getMeshName();
1314 }
1315
1316 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1317 {
1318   const char startLine[]="  ## ";
1319   std::string startLine2(bkOffset,' ');
1320   std::string startLine3(startLine2);
1321   startLine3+=startLine;
1322   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1323     {
1324       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1325       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1326     }
1327   else
1328     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1329   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1330   int i=0;
1331   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1332     {
1333       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1334       if(cur)
1335         cur->simpleRepr(bkOffset,oss,i);
1336       else
1337         {
1338           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1339         }
1340     }
1341 }
1342
1343 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1344 {
1345   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1346     {
1347       globalSz+=(*it)->getNumberOfTuples();
1348     }
1349   nbOfEntries+=(int)_field_pm_pt_pd.size();
1350 }
1351
1352 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1353 {
1354   return _geo_type;
1355 }
1356
1357
1358 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1359 {
1360   return _father->getNumberOfComponents();
1361 }
1362
1363 bool MEDFileFieldPerMeshPerType::presenceOfMultiDiscPerGeoType() const
1364 {
1365   std::size_t nb(0);
1366   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1367     {
1368       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1369       if(fmtd)
1370         nb++;
1371     }
1372   return nb>1;
1373 }
1374
1375 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1376 {
1377   return _father->getOrCreateAndGetArray();
1378 }
1379
1380 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1381 {
1382   const MEDFileFieldPerMesh *fath=_father;
1383   return fath->getOrCreateAndGetArray();
1384 }
1385
1386 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1387 {
1388   return _father->getInfo();
1389 }
1390
1391 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1392 {
1393   std::vector<std::string> ret;
1394   std::set<std::string> ret2;
1395   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1396     {
1397       std::string tmp=(*it1)->getProfile();
1398       if(!tmp.empty())
1399         if(ret2.find(tmp)==ret2.end())
1400           {
1401             ret.push_back(tmp);
1402             ret2.insert(tmp);
1403           }
1404     }
1405   return ret;
1406 }
1407
1408 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1409 {
1410   std::vector<std::string> ret;
1411   std::set<std::string> ret2;
1412   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1413     {
1414       std::string tmp=(*it1)->getLocalization();
1415       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1416         if(ret2.find(tmp)==ret2.end())
1417           {
1418             ret.push_back(tmp);
1419             ret2.insert(tmp);
1420           }
1421     }
1422   return ret;
1423 }
1424
1425 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1426 {
1427   std::vector<std::string> ret;
1428   std::set<std::string> ret2;
1429   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1430     {
1431       std::string tmp=(*it1)->getProfile();
1432       if(!tmp.empty())
1433         ret.push_back(tmp);
1434     }
1435   return ret;
1436 }
1437
1438 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1439 {
1440   std::vector<std::string> ret;
1441   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1442     {
1443       std::string tmp=(*it1)->getLocalization();
1444       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1445         ret.push_back(tmp);
1446     }
1447   return ret;
1448 }
1449
1450 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1451 {
1452   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1453     (*it1)->changePflsRefsNamesGen(mapOfModif);
1454 }
1455
1456 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1457 {
1458   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1459     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1460 }
1461
1462 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1463 {
1464   if(_field_pm_pt_pd.empty())
1465     {
1466       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1467       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1468       throw INTERP_KERNEL::Exception(oss.str().c_str());
1469     }
1470   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1471     return _field_pm_pt_pd[locId];
1472   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1473   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1474   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1475   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1476   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1477 }
1478
1479 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1480 {
1481   if(_field_pm_pt_pd.empty())
1482     {
1483       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1484       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1485       throw INTERP_KERNEL::Exception(oss.str().c_str());
1486     }
1487   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1488     return _field_pm_pt_pd[locId];
1489   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1490   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1491   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1492   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1493   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1494 }
1495
1496 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
1497 {
1498   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1499     {
1500       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1501       if(meshDim!=(int)cm.getDimension())
1502         return ;
1503     }
1504   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1505     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1506 }
1507
1508 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1509 {
1510   int i=0;
1511   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1512     {
1513       (*it)->fillValues(i,startEntryId,entries);
1514     }
1515 }
1516
1517 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1518 {
1519   _field_pm_pt_pd=leaves;
1520   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1521     (*it)->setFather(this);
1522 }
1523
1524 /*!
1525  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1526  *  \param [out] its - list of pair (start,stop) kept
1527  *  \return bool - false if the type of field \a tof is not contained in \a this.
1528  */
1529 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1530 {
1531   bool ret(false);
1532   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1533   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1534     if((*it)->getType()==tof)
1535       {
1536         newPmPtPd.push_back(*it);
1537         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1538         (*it)->setNewStart(globalNum);
1539         globalNum=(*it)->getEnd();
1540         its.push_back(bgEnd);
1541         ret=true;
1542       }
1543   if(ret)
1544     _field_pm_pt_pd=newPmPtPd;
1545   return ret;
1546 }
1547
1548 /*!
1549  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1550  *  \param [out] its - list of pair (start,stop) kept
1551  *  \return bool - false if the type of field \a tof is not contained in \a this.
1552  */
1553 bool MEDFileFieldPerMeshPerType::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1554 {
1555   if(_field_pm_pt_pd.size()<=idOfDisc)
1556     return false;
1557   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1558   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1559   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1560   elt->setNewStart(globalNum);
1561   globalNum=elt->getEnd();
1562   its.push_back(bgEnd);
1563   _field_pm_pt_pd=newPmPtPd;
1564   return true;
1565 }
1566
1567 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1568 {
1569 }
1570
1571 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType)
1572 {
1573   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1574   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1575   med_geometry_type mgeoti;
1576   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1577   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1578   _field_pm_pt_pd.resize(nbProfiles);
1579   for(int i=0;i<nbProfiles;i++)
1580     {
1581       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1582     }
1583   if(type==ON_CELLS)
1584     {
1585       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1586       for(int i=0;i<nbProfiles2;i++)
1587         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1588     }
1589 }
1590
1591 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1592 {
1593   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1594     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1595 }
1596
1597 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1598 {
1599   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1600     (*it)->loadBigArray(fid,nasc);
1601 }
1602
1603 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1604 {
1605   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1606     {
1607       (*it)->copyOptionsFrom(*this);
1608       (*it)->writeLL(fid,nasc);
1609     }
1610 }
1611
1612 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1613 {
1614   switch(ikType)
1615   {
1616     case ON_CELLS:
1617       medfGeoType=typmai3[(int)ikGeoType];
1618       return MED_CELL;
1619     case ON_NODES:
1620       medfGeoType=MED_NONE;
1621       return MED_NODE;
1622     case ON_GAUSS_NE:
1623       medfGeoType=typmai3[(int)ikGeoType];
1624       return MED_NODE_ELEMENT;
1625     case ON_GAUSS_PT:
1626       medfGeoType=typmai3[(int)ikGeoType];
1627       return MED_CELL;
1628     default:
1629       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1630   }
1631   return MED_UNDEF_ENTITY_TYPE;
1632 }
1633
1634 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)
1635 {
1636   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1637 }
1638
1639 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1640 {
1641   return new MEDFileFieldPerMesh(fath,mesh);
1642 }
1643
1644 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1645 {
1646   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1647 }
1648
1649 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1650 {
1651   std::vector<const BigMemoryObject *> ret;
1652   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1653     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1654   return ret;
1655 }
1656
1657 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1658 {
1659   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1660   ret->_father=father;
1661   std::size_t i=0;
1662   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1663     {
1664       if((const MEDFileFieldPerMeshPerType *)*it)
1665         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1666     }
1667   return ret.retn();
1668 }
1669
1670 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1671 {
1672   std::string startLine(bkOffset,' ');
1673   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1674   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1675   int i=0;
1676   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1677     {
1678       const MEDFileFieldPerMeshPerType *cur=*it;
1679       if(cur)
1680         cur->simpleRepr(bkOffset,oss,i);
1681       else
1682         {
1683           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1684         }
1685     }
1686 }
1687
1688 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1689 {
1690   _mesh_name=mesh->getName();
1691   mesh->getTime(_mesh_iteration,_mesh_order);
1692 }
1693
1694 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1695 {
1696   int nbOfTypes=code.size()/3;
1697   int offset=0;
1698   for(int i=0;i<nbOfTypes;i++)
1699     {
1700       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1701       int nbOfCells=code[3*i+1];
1702       int pos=addNewEntryIfNecessary(type);
1703       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1704       offset+=nbOfCells;
1705     }
1706 }
1707
1708 /*!
1709  * This method is the most general one. No optimization is done here.
1710  * \param [in] multiTypePfl is the end user profile specified in high level API
1711  * \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].
1712  * \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.
1713  * \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.
1714  * \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.
1715  * \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.
1716  */
1717 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)
1718 {
1719   int nbOfTypes(code.size()/3);
1720   for(int i=0;i<nbOfTypes;i++)
1721     {
1722       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1723       int pos=addNewEntryIfNecessary(type);
1724       DataArrayInt *pfl=0;
1725       if(code[3*i+2]!=-1)
1726         pfl=idsPerType[code[3*i+2]];
1727       int nbOfTupes2=code2.size()/3;
1728       int found=0;
1729       for(;found<nbOfTupes2;found++)
1730         if(code[3*i]==code2[3*found])
1731           break;
1732       if(found==nbOfTupes2)
1733         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1734       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1735     }
1736 }
1737
1738 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1739 {
1740   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1741   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1742 }
1743
1744 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1745 {
1746   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1747   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1748 }
1749
1750 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1751 {
1752   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1753     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1754 }
1755
1756 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1757 {
1758   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1759     (*it)->loadBigArraysRecursively(fid,nasc);
1760 }
1761
1762 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1763 {
1764   int nbOfTypes=_field_pm_pt.size();
1765   for(int i=0;i<nbOfTypes;i++)
1766     {
1767       _field_pm_pt[i]->copyOptionsFrom(*this);
1768       _field_pm_pt[i]->writeLL(fid,nasc);
1769     }
1770 }
1771
1772 void MEDFileFieldPerMesh::getDimension(int& dim) const
1773 {
1774   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1775     (*it)->getDimension(dim);
1776 }
1777
1778 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1779 {
1780   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1781     (*it)->fillTypesOfFieldAvailable(types);
1782 }
1783
1784 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
1785 {
1786   int sz=_field_pm_pt.size();
1787   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1788   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1789   for(int i=0;i<sz;i++)
1790     {
1791       types[i]=_field_pm_pt[i]->getGeoType();
1792       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1793     }
1794   return ret;
1795 }
1796
1797 double MEDFileFieldPerMesh::getTime() const
1798 {
1799   int tmp1,tmp2;
1800   return _father->getTime(tmp1,tmp2);
1801 }
1802
1803 int MEDFileFieldPerMesh::getIteration() const
1804 {
1805   return _father->getIteration();
1806 }
1807
1808 int MEDFileFieldPerMesh::getOrder() const
1809 {
1810   return _father->getOrder();
1811 }
1812
1813 int MEDFileFieldPerMesh::getNumberOfComponents() const
1814 {
1815   return _father->getNumberOfComponents();
1816 }
1817
1818 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1819 {
1820   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1821     {
1822       const MEDFileFieldPerMeshPerType *fpmt(*it);
1823       if(!fpmt)
1824         continue;
1825       if(fpmt->presenceOfMultiDiscPerGeoType())
1826         return true;
1827     }
1828   return false;
1829 }
1830
1831 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1832 {
1833   if(!_father)
1834     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1835   return _father->getOrCreateAndGetArray();
1836 }
1837
1838 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1839 {
1840   if(!_father)
1841     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1842   return _father->getOrCreateAndGetArray();
1843 }
1844
1845 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1846 {
1847   return _father->getInfo();
1848 }
1849
1850 /*!
1851  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1852  * 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.
1853  * It returns 2 output vectors :
1854  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1855  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1856  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1857  */
1858 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)
1859 {
1860   int notNullPflsSz=0;
1861   int nbOfArrs=geoTypes.size();
1862   for(int i=0;i<nbOfArrs;i++)
1863     if(pfls[i])
1864       notNullPflsSz++;
1865   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1866   int nbOfDiffGeoTypes=geoTypes3.size();
1867   code.resize(3*nbOfDiffGeoTypes);
1868   notNullPfls.resize(notNullPflsSz);
1869   notNullPflsSz=0;
1870   int j=0;
1871   for(int i=0;i<nbOfDiffGeoTypes;i++)
1872     {
1873       int startZone=j;
1874       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1875       std::vector<const DataArrayInt *> notNullTmp;
1876       if(pfls[j])
1877         notNullTmp.push_back(pfls[j]);
1878       j++;
1879       for(;j<nbOfArrs;j++)
1880         if(geoTypes[j]==refType)
1881           {
1882             if(pfls[j])
1883               notNullTmp.push_back(pfls[j]);
1884           }
1885         else
1886           break;
1887       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1888       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1889       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1890       code[3*i]=(int)refType;
1891       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1892       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1893       if(notNullTmp.empty())
1894         code[3*i+2]=-1;
1895       else
1896         {
1897           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1898           code[3*i+2]=notNullPflsSz++;
1899         }
1900     }
1901 }
1902
1903 /*!
1904  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1905  */
1906 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)
1907 {
1908   int sz=dads.size();
1909   int ret=0;
1910   for(int i=0;i<sz;i++)
1911     {
1912       if(locs[i]==-1)
1913         {
1914           if(type!=ON_GAUSS_NE)
1915             ret+=dads[i].second-dads[i].first;
1916           else
1917             {
1918               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1919               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1920             }
1921         }
1922       else
1923         {
1924           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1925           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1926         }
1927     }
1928   return ret;
1929 }
1930
1931 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1932 {
1933   std::vector<std::string> ret;
1934   std::set<std::string> ret2;
1935   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1936     {
1937       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1938       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1939         if(ret2.find(*it2)==ret2.end())
1940           {
1941             ret.push_back(*it2);
1942             ret2.insert(*it2);
1943           }
1944     }
1945   return ret;
1946 }
1947
1948 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1949 {
1950   std::vector<std::string> ret;
1951   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1952     {
1953       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1954       ret.insert(ret.end(),tmp.begin(),tmp.end());
1955     }
1956   return ret;
1957 }
1958
1959 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1960 {
1961   std::vector<std::string> ret;
1962   std::set<std::string> ret2;
1963   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1964     {
1965       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1966       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1967         if(ret2.find(*it2)==ret2.end())
1968           {
1969             ret.push_back(*it2);
1970             ret2.insert(*it2);
1971           }
1972     }
1973   return ret;
1974 }
1975
1976 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1977 {
1978   std::vector<std::string> ret;
1979   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1980     {
1981       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1982       ret.insert(ret.end(),tmp.begin(),tmp.end());
1983     }
1984   return ret;
1985 }
1986
1987 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1988 {
1989   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1990     {
1991       if((*it).first==_mesh_name)
1992         {
1993           _mesh_name=(*it).second;
1994           return true;
1995         }
1996     }
1997   return false;
1998 }
1999
2000 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2001                                                       MEDFileFieldGlobsReal& glob)
2002 {
2003   if(_mesh_name!=meshName)
2004     return false;
2005   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2006   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2007   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2008   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2009   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2010   getUndergroundDataArrayExt(entries);
2011   DataArray *arr0=getOrCreateAndGetArray();//tony
2012   if(!arr0)
2013     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2014   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
2015   if(!arr0)
2016     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2017   int sz=0;
2018   if(!arr)
2019     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2020   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2021     {
2022       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2023         {
2024           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2025           sz+=(*it).second.second-(*it).second.first;
2026         }
2027       else
2028         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2029     }
2030   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2031   ////////////////////
2032   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2033   int *workI2=explicitIdsOldInMesh->getPointer();
2034   int sz1=0,sz2=0,sid=1;
2035   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2036   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2037   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2038     {
2039       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2040       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2041       int *workI=explicitIdsOldInArr->getPointer();
2042       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2043         {
2044           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2045           (*itL2)->setLocId(sz2);
2046           (*itL2)->_tmp_work1=(*itL2)->getStart();
2047           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2048         }
2049       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2050     }
2051   explicitIdsOldInMesh->reAlloc(sz2);
2052   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2053   ////////////////////
2054   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2055   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2056   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2057   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2058     {
2059       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2060       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2061       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2062     }
2063   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2064   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2065   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2066     {
2067       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2068       int newStart=elt->getLocId();
2069       elt->setLocId((*it)->getGeoType());
2070       elt->setNewStart(newStart);
2071       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2072       entriesKeptNew.push_back(elt);
2073       entriesKeptNew2.push_back(elt);
2074     }
2075   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2076   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2077   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2078   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2079   bool ret=false;
2080   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2081     {
2082       sid=0;
2083       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2084         {
2085           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2086           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2087           }*/
2088       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2089                                                             glob,arr2,otherEntriesNew) || ret;
2090     }
2091   if(!ret)
2092     return false;
2093   // Assign new dispatching
2094   assignNewLeaves(otherEntriesNew);
2095   arr->deepCopyFrom(*arr2);
2096   return true;
2097 }
2098
2099 /*!
2100  * \param [in,out] globalNum a global numbering counter for the renumbering.
2101  * \param [out] its - list of pair (start,stop) kept
2102  */
2103 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2104 {
2105   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret;
2106   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2107     {
2108       std::vector< std::pair<int,int> > its2;
2109       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2110         {
2111           ret.push_back(*it);
2112           its.insert(its.end(),its2.begin(),its2.end());
2113         }
2114     }
2115   _field_pm_pt=ret;
2116 }
2117
2118 /*!
2119  * \param [in,out] globalNum a global numbering counter for the renumbering.
2120  * \param [out] its - list of pair (start,stop) kept
2121  */
2122 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2123 {
2124   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret;
2125   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2126     {
2127       std::vector< std::pair<int,int> > its2;
2128       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2129         {
2130           ret.push_back(*it);
2131           its.insert(its.end(),its2.begin(),its2.end());
2132         }
2133     }
2134   _field_pm_pt=ret;
2135 }
2136
2137 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2138 {
2139   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2140   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2141     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2142   //
2143   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2144   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2145   std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2146   for(;it1!=types.end();it1++,it2++)
2147     {
2148       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2149       elt->setLeaves((*it1).second);
2150       *it2=elt;
2151     }
2152   _field_pm_pt=fieldPmPt;
2153 }
2154
2155 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2156 {
2157   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2158     (*it)->changePflsRefsNamesGen(mapOfModif);
2159 }
2160
2161 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2162 {
2163   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2164     (*it)->changeLocsRefsNamesGen(mapOfModif);
2165 }
2166
2167 /*!
2168  * \param [in] mesh is the whole mesh
2169  */
2170 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2171 {
2172   if(_field_pm_pt.empty())
2173     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2174   //
2175   std::vector< std::pair<int,int> > dads;
2176   std::vector<const DataArrayInt *> pfls;
2177   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2178   std::vector<int> locs,code;
2179   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2180   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2181     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2182   // Sort by types
2183   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2184   if(code.empty())
2185     {
2186       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2187       throw INTERP_KERNEL::Exception(oss.str().c_str());
2188     }
2189   //
2190   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2191   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2192   if(type!=ON_NODES)
2193     {
2194       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2195       if(!arr)
2196         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2197       else
2198         {
2199           MCAuto<DataArrayInt> arr2(arr);
2200           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2201         }
2202     }
2203   else
2204     {
2205       if(code.size()!=3)
2206         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2207       int nb=code[1];
2208       if(code[2]==-1)
2209         {
2210           if(nb!=mesh->getNumberOfNodes())
2211             {
2212               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2213               oss << " nodes in mesh !";
2214               throw INTERP_KERNEL::Exception(oss.str().c_str());
2215             }
2216           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2217         }
2218       else
2219         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2220     }
2221 }
2222
2223 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2224 {
2225   if(_field_pm_pt.empty())
2226     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2227   //
2228   std::vector<std::pair<int,int> > dads;
2229   std::vector<const DataArrayInt *> pfls;
2230   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2231   std::vector<int> locs,code;
2232   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2233   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2234     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2235   // Sort by types
2236   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2237   if(code.empty())
2238     {
2239       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2240       throw INTERP_KERNEL::Exception(oss.str().c_str());
2241     }
2242   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2243   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2244   if(type!=ON_NODES)
2245     {
2246       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2247       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2248     }
2249   else
2250     {
2251       if(code.size()!=3)
2252         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2253       int nb=code[1];
2254       if(code[2]==-1)
2255         {
2256           if(nb!=mesh->getNumberOfNodes())
2257             {
2258               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2259               oss << " nodes in mesh !";
2260               throw INTERP_KERNEL::Exception(oss.str().c_str());
2261             }
2262         }
2263       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2264     }
2265   //
2266   return 0;
2267 }
2268
2269 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2270 {
2271   int globalSz=0;
2272   int nbOfEntries=0;
2273   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2274     {
2275       (*it)->getSizes(globalSz,nbOfEntries);
2276     }
2277   entries.resize(nbOfEntries);
2278   nbOfEntries=0;
2279   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2280     {
2281       (*it)->fillValues(nbOfEntries,entries);
2282     }
2283 }
2284
2285 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2286 {
2287   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2288     {
2289       if((*it)->getGeoType()==typ)
2290         return (*it)->getLeafGivenLocId(locId);
2291     }
2292   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2293   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2294   oss << "Possiblities are : ";
2295   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2296     {
2297       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2298       oss << "\"" << cm2.getRepr() << "\", ";
2299     }
2300   throw INTERP_KERNEL::Exception(oss.str().c_str());
2301 }
2302
2303 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2304 {
2305   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2306     {
2307       if((*it)->getGeoType()==typ)
2308         return (*it)->getLeafGivenLocId(locId);
2309     }
2310   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2311   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2312   oss << "Possiblities are : ";
2313   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2314     {
2315       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2316       oss << "\"" << cm2.getRepr() << "\", ";
2317     }
2318   throw INTERP_KERNEL::Exception(oss.str().c_str());
2319 }
2320
2321 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2322 {
2323   int i=0;
2324   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2325   std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2326   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2327     {
2328       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2329       if(type==curType)
2330         return i;
2331       else
2332         {
2333           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2334           if(pos>pos2)
2335             it2=it+1;
2336         }
2337     }
2338   int ret=std::distance(_field_pm_pt.begin(),it2);
2339   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2340   return ret;
2341 }
2342
2343 /*!
2344  * 'dads' and 'locs' input parameters have the same number of elements
2345  * \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
2346  */
2347 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2348                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2349                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2350 {
2351   isPfl=false;
2352   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2353   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2354   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2355   const std::vector<std::string>& infos=getInfo();
2356   da->setInfoOnComponents(infos);
2357   da->setName("");
2358   if(type==ON_GAUSS_PT)
2359     {
2360       int offset=0;
2361       int nbOfArrs=dads.size();
2362       for(int i=0;i<nbOfArrs;i++)
2363         {
2364           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2365           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2366           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2367           MCAuto<DataArrayInt> di=DataArrayInt::New();
2368           di->alloc(nbOfElems,1);
2369           di->iota(offset);
2370           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2371           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2372           offset+=nbOfElems;
2373         }
2374     }
2375   arrOut=da;
2376   return ret.retn();
2377 }
2378
2379 /*!
2380  * 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.
2381  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2382  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2383  * The order of cells in the returned field is those imposed by the profile.
2384  * \param [in] mesh is the global mesh.
2385  */
2386 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2387                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2388                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2389                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2390 {
2391   if(da->isIota(mesh->getNumberOfCells()))
2392     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2393   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2394   m2->setName(mesh->getName().c_str());
2395   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2396   isPfl=true;
2397   return ret.retn();
2398 }
2399
2400 /*!
2401  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2402  */
2403 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2404                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2405                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2406 {
2407   if(da->isIota(mesh->getNumberOfNodes()))
2408     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2409   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2410   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2411   if(meshu)
2412     {
2413       if(meshu->getNodalConnectivity()==0)
2414         {
2415           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2416           int nb=da->getNbOfElems();
2417           const int *ptr=da->getConstPointer();
2418           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2419           meshuc->allocateCells(nb);
2420           for(int i=0;i<nb;i++)
2421             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2422           meshuc->finishInsertingCells();
2423           ret->setMesh(meshuc);
2424           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2425           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2426           disc->checkCoherencyBetween(meshuc,arrOut);
2427           return ret.retn();
2428         }
2429     }
2430   //
2431   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2432   isPfl=true;
2433   DataArrayInt *arr2=0;
2434   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2435   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2436   MCAuto<DataArrayInt> arr3(arr2);
2437   int nnodes=mesh2->getNumberOfNodes();
2438   if(nnodes==(int)da->getNbOfElems())
2439     {
2440       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2441       arrOut->renumberInPlace(da3->getConstPointer());
2442       mesh2->setName(mesh->getName().c_str());
2443       ret->setMesh(mesh2);
2444       return ret.retn();
2445     }
2446   else
2447     {
2448       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 !!!";
2449       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2450       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2451       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2452       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2453       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2454       throw INTERP_KERNEL::Exception(oss.str().c_str());
2455     }
2456   return 0;
2457 }
2458
2459 /*!
2460  * This method is the most light method of field retrieving.
2461  */
2462 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2463 {
2464   if(!pflIn)
2465     {
2466       pflOut=DataArrayInt::New();
2467       pflOut->alloc(nbOfElems,1);
2468       pflOut->iota(0);
2469     }
2470   else
2471     {
2472       pflOut=const_cast<DataArrayInt*>(pflIn);
2473       pflOut->incrRef();
2474     }
2475   MCAuto<DataArrayInt> safePfl(pflOut);
2476   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2477   const std::vector<std::string>& infos=getInfo();
2478   int nbOfComp=infos.size();
2479   for(int i=0;i<nbOfComp;i++)
2480     da->setInfoOnComponent(i,infos[i].c_str());
2481   safePfl->incrRef();
2482   return da.retn();
2483 }
2484
2485
2486 /// @cond INTERNAL
2487
2488 class MFFPMIter
2489 {
2490 public:
2491   static MFFPMIter *NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2492   static bool IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2493   virtual ~MFFPMIter() { }
2494   virtual void begin() = 0;
2495   virtual bool finished() const = 0;
2496   virtual void next() = 0;
2497   virtual int current() const = 0;
2498 };
2499
2500 class MFFPMIterSimple : public MFFPMIter
2501 {
2502 public:
2503   MFFPMIterSimple():_pos(0) { }
2504   void begin() { _pos=0; }
2505   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2506   void next() { _pos++; }
2507   int current() const { return _pos; }
2508 private:
2509   int _pos;
2510 };
2511
2512 class MFFPMIter2 : public MFFPMIter
2513 {
2514 public:
2515   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2516   void begin() { _it=_ids.begin(); }
2517   bool finished() const { return _it==_ids.end(); }
2518   void next() { _it++; }
2519   int current() const { return *_it; }
2520 private:
2521   std::vector<int> _ids;
2522   std::vector<int>::const_iterator _it;
2523 };
2524
2525 MFFPMIter *MFFPMIter::NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2526 {
2527   if(!entities)
2528     return new MFFPMIterSimple;
2529   else
2530     {
2531       std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2532       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2533         {
2534           if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2535             tmp.push_back((*it).second);
2536         }
2537       return new MFFPMIter2(tmp);
2538     }
2539 }
2540
2541 bool MFFPMIter::IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2542 {
2543   if(!entities)
2544     return true;
2545   else
2546     {
2547       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2548         if((*it).first==ON_NODES)
2549           return true;
2550       return false;
2551     }
2552 }
2553
2554 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2555 {
2556   std::size_t sz(cts.size());
2557   _ids.resize(sz);
2558   for(std::size_t i=0;i<sz;i++)
2559     {
2560       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2561       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2562         _ids[i]=(int)std::distance(typmai2,loc);
2563       else
2564         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2565     }
2566 }
2567
2568 /// @endcond
2569
2570 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),
2571     _father(fath)
2572 {
2573   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2574   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2575   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2576   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2577   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2578   for(iter0->begin();!iter0->finished();iter0->next())
2579     {
2580       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2581       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2582       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2583       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2584       if(nbProfile>0 || nbProfile2>0)
2585         {
2586           const PartDefinition *pd(0);
2587           if(mmu)
2588             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2589           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2590           if(nbProfile>0)
2591             _mesh_name=name0;
2592           else
2593             _mesh_name=name1;
2594         }
2595     }
2596   if(MFFPMIter::IsPresenceOfNode(entities))
2597     {
2598       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2599       if(nbProfile>0)
2600         {
2601           const PartDefinition *pd(0);
2602           if(mmu)
2603             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2604           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2605           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2606         }
2607     }
2608 }
2609
2610 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2611 {
2612   copyTinyInfoFrom(mesh);
2613 }
2614
2615 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2616 {
2617   if(id>=(int)_pfls.size())
2618     _pfls.resize(id+1);
2619   _pfls[id]=DataArrayInt::New();
2620   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2621   _pfls[id]->setName(pflName);
2622   _pfls[id]->alloc(lgth,1);
2623   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2624   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2625 }
2626
2627 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2628 {
2629   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2630   int sz;
2631   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
2632   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2633   if(i>=(int)_pfls.size())
2634     _pfls.resize(i+1);
2635   _pfls[i]=DataArrayInt::New();
2636   _pfls[i]->alloc(sz,1);
2637   _pfls[i]->setName(pflCpp.c_str());
2638   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
2639   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2640 }
2641
2642 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2643 {
2644   int nbOfPfls=_pfls.size();
2645   for(int i=0;i<nbOfPfls;i++)
2646     {
2647       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
2648       cpy->applyLin(1,1,0);
2649       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2650       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2651       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
2652     }
2653   //
2654   int nbOfLocs=_locs.size();
2655   for(int i=0;i<nbOfLocs;i++)
2656     _locs[i]->writeLL(fid);
2657 }
2658
2659 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2660 {
2661   std::vector<std::string> pfls=getPfls();
2662   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2663     {
2664       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2665       if(it2==pfls.end())
2666         {
2667           _pfls.push_back(*it);
2668         }
2669       else
2670         {
2671           int id=std::distance(pfls.begin(),it2);
2672           if(!(*it)->isEqual(*_pfls[id]))
2673             {
2674               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2675               throw INTERP_KERNEL::Exception(oss.str().c_str());
2676             }
2677         }
2678     }
2679   std::vector<std::string> locs=getLocs();
2680   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2681     {
2682       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2683       if(it2==locs.end())
2684         {
2685           _locs.push_back(*it);
2686         }
2687       else
2688         {
2689           int id=std::distance(locs.begin(),it2);
2690           if(!(*it)->isEqual(*_locs[id],eps))
2691             {
2692               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2693               throw INTERP_KERNEL::Exception(oss.str().c_str());
2694             }
2695         }
2696     }
2697 }
2698
2699 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2700 {
2701   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2702     getProfile((*it).c_str());
2703 }
2704
2705 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2706 {
2707   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2708     getLocalization((*it).c_str());
2709 }
2710
2711 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2712 {
2713   std::vector<std::string> profiles=real.getPflsReallyUsed();
2714   int sz=profiles.size();
2715   _pfls.resize(sz);
2716   for(int i=0;i<sz;i++)
2717     loadProfileInFile(fid,i,profiles[i].c_str());
2718   //
2719   std::vector<std::string> locs=real.getLocsReallyUsed();
2720   sz=locs.size();
2721   _locs.resize(sz);
2722   for(int i=0;i<sz;i++)
2723     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2724 }
2725
2726 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2727 {
2728   int nProfil=MEDnProfile(fid);
2729   for(int i=0;i<nProfil;i++)
2730     loadProfileInFile(fid,i);
2731   int sz=MEDnLocalization(fid);
2732   _locs.resize(sz);
2733   for(int i=0;i<sz;i++)
2734     {
2735       _locs[i]=MEDFileFieldLoc::New(fid,i);
2736     }
2737 }
2738
2739 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2740 {
2741   return new MEDFileFieldGlobs(fname);
2742 }
2743
2744 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2745 {
2746   return new MEDFileFieldGlobs;
2747 }
2748
2749 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2750 {
2751   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
2752 }
2753
2754 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2755 {
2756   std::vector<const BigMemoryObject *> ret;
2757   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2758     ret.push_back((const DataArrayInt *)*it);
2759   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2760     ret.push_back((const MEDFileFieldLoc *)*it);
2761   return ret;
2762 }
2763
2764 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
2765 {
2766   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2767   std::size_t i=0;
2768   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2769     {
2770       if((const DataArrayInt *)*it)
2771         ret->_pfls[i]=(*it)->deepCopy();
2772     }
2773   i=0;
2774   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2775     {
2776       if((const MEDFileFieldLoc*)*it)
2777         ret->_locs[i]=(*it)->deepCopy();
2778     }
2779   return ret.retn();
2780 }
2781
2782 /*!
2783  * \throw if a profile in \a pfls in not in \a this.
2784  * \throw if a localization in \a locs in not in \a this.
2785  * \sa MEDFileFieldGlobs::deepCpyPart
2786  */
2787 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2788 {
2789   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2790   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2791     {
2792       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2793       if(!pfl)
2794         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2795       pfl->incrRef();
2796       MCAuto<DataArrayInt> pfl2(pfl);
2797       ret->_pfls.push_back(pfl2);
2798     }
2799   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2800     {
2801       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2802       if(!loc)
2803         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2804       loc->incrRef();
2805       MCAuto<MEDFileFieldLoc> loc2(loc);
2806       ret->_locs.push_back(loc2);
2807     }
2808   ret->setFileName(getFileName());
2809   return ret.retn();
2810 }
2811
2812 /*!
2813  * \throw if a profile in \a pfls in not in \a this.
2814  * \throw if a localization in \a locs in not in \a this.
2815  * \sa MEDFileFieldGlobs::shallowCpyPart
2816  */
2817 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2818 {
2819   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2820   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2821     {
2822       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2823       if(!pfl)
2824         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2825       ret->_pfls.push_back(pfl->deepCopy());
2826     }
2827   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2828     {
2829       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2830       if(!loc)
2831         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2832       ret->_locs.push_back(loc->deepCopy());
2833     }
2834   ret->setFileName(getFileName());
2835   return ret.retn();
2836 }
2837
2838 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2839 {
2840 }
2841
2842 MEDFileFieldGlobs::MEDFileFieldGlobs()
2843 {
2844 }
2845
2846 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2847 {
2848 }
2849
2850 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2851 {
2852   oss << "Profiles :\n";
2853   std::size_t n=_pfls.size();
2854   for(std::size_t i=0;i<n;i++)
2855     {
2856       oss << "  - #" << i << " ";
2857       const DataArrayInt *pfl=_pfls[i];
2858       if(pfl)
2859         oss << "\"" << pfl->getName() << "\"\n";
2860       else
2861         oss << "EMPTY !\n";
2862     }
2863   n=_locs.size();
2864   oss << "Localizations :\n";
2865   for(std::size_t i=0;i<n;i++)
2866     {
2867       oss << "  - #" << i << " ";
2868       const MEDFileFieldLoc *loc=_locs[i];
2869       if(loc)
2870         loc->simpleRepr(oss);
2871       else
2872         oss<< "EMPTY !\n";
2873     }
2874 }
2875
2876 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2877 {
2878   _file_name=fileName;
2879 }
2880
2881 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2882 {
2883   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2884     {
2885       DataArrayInt *elt(*it);
2886       if(elt)
2887         {
2888           std::string name(elt->getName());
2889           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2890             {
2891               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2892                 {
2893                   elt->setName((*it2).second.c_str());
2894                   return;
2895                 }
2896             }
2897         }
2898     }
2899 }
2900
2901 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2902 {
2903   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2904     {
2905       MEDFileFieldLoc *elt(*it);
2906       if(elt)
2907         {
2908           std::string name(elt->getName());
2909           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2910             {
2911               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2912                 {
2913                   elt->setName((*it2).second.c_str());
2914                   return;
2915                 }
2916             }
2917         }
2918     }
2919 }
2920
2921 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2922 {
2923   if(locId<0 || locId>=(int)_locs.size())
2924     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2925   return _locs[locId]->getNbOfGaussPtPerCell();
2926 }
2927
2928 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2929 {
2930   return getLocalizationFromId(getLocalizationId(locName));
2931 }
2932
2933 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2934 {
2935   if(locId<0 || locId>=(int)_locs.size())
2936     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2937   return *_locs[locId];
2938 }
2939
2940 /// @cond INTERNAL
2941 namespace MEDCouplingImpl
2942 {
2943   class LocFinder
2944   {
2945   public:
2946     LocFinder(const std::string& loc):_loc(loc) { }
2947     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2948   private:
2949     const std::string &_loc;
2950   };
2951
2952   class PflFinder
2953   {
2954   public:
2955     PflFinder(const std::string& pfl):_pfl(pfl) { }
2956     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2957   private:
2958     const std::string& _pfl;
2959   };
2960 }
2961 /// @endcond
2962
2963 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2964 {
2965   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
2966   if(it==_locs.end())
2967     {
2968       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2969       for(it=_locs.begin();it!=_locs.end();it++)
2970         oss << "\"" << (*it)->getName() << "\", ";
2971       throw INTERP_KERNEL::Exception(oss.str().c_str());
2972     }
2973   return std::distance(_locs.begin(),it);
2974 }
2975
2976 /*!
2977  * The returned value is never null.
2978  */
2979 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2980 {
2981   std::string pflNameCpp(pflName);
2982   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
2983   if(it==_pfls.end())
2984     {
2985       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2986       for(it=_pfls.begin();it!=_pfls.end();it++)
2987         oss << "\"" << (*it)->getName() << "\", ";
2988       throw INTERP_KERNEL::Exception(oss.str().c_str());
2989     }
2990   return *it;
2991 }
2992
2993 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2994 {
2995   if(pflId<0 || pflId>=(int)_pfls.size())
2996     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2997   return _pfls[pflId];
2998 }
2999
3000 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3001 {
3002   if(locId<0 || locId>=(int)_locs.size())
3003     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3004   return *_locs[locId];
3005 }
3006
3007 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3008 {
3009   return getLocalizationFromId(getLocalizationId(locName));
3010 }
3011
3012 /*!
3013  * The returned value is never null.
3014  */
3015 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3016 {
3017   std::string pflNameCpp(pflName);
3018   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3019   if(it==_pfls.end())
3020     {
3021       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3022       for(it=_pfls.begin();it!=_pfls.end();it++)
3023         oss << "\"" << (*it)->getName() << "\", ";
3024       throw INTERP_KERNEL::Exception(oss.str().c_str());
3025     }
3026   return *it;
3027 }
3028
3029 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3030 {
3031   if(pflId<0 || pflId>=(int)_pfls.size())
3032     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3033   return _pfls[pflId];
3034 }
3035
3036 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3037 {
3038   std::vector< MCAuto<DataArrayInt> > newPfls;
3039   int i=0;
3040   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3041     {
3042       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3043         newPfls.push_back(*it);
3044     }
3045   _pfls=newPfls;
3046 }
3047
3048 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3049 {
3050   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3051   int i=0;
3052   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3053     {
3054       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3055         newLocs.push_back(*it);
3056     }
3057   _locs=newLocs;
3058 }
3059
3060 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3061 {
3062   int sz=_pfls.size();
3063   std::vector<std::string> ret(sz);
3064   for(int i=0;i<sz;i++)
3065     ret[i]=_pfls[i]->getName();
3066   return ret;
3067 }
3068
3069 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3070 {
3071   int sz=_locs.size();
3072   std::vector<std::string> ret(sz);
3073   for(int i=0;i<sz;i++)
3074     ret[i]=_locs[i]->getName();
3075   return ret;
3076 }
3077
3078 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3079 {
3080   std::vector<std::string> v=getPfls();
3081   std::string s(pflName);
3082   return std::find(v.begin(),v.end(),s)!=v.end();
3083 }
3084
3085 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3086 {
3087   std::vector<std::string> v=getLocs();
3088   std::string s(locName);
3089   return std::find(v.begin(),v.end(),s)!=v.end();
3090 }
3091
3092 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3093 {
3094   std::map<int,std::vector<int> > m;
3095   int i=0;
3096   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3097     {
3098       const DataArrayInt *tmp=(*it);
3099       if(tmp)
3100         {
3101           m[tmp->getHashCode()].push_back(i);
3102         }
3103     }
3104   std::vector< std::vector<int> > ret;
3105   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3106     {
3107       if((*it2).second.size()>1)
3108         {
3109           std::vector<int> ret0;
3110           bool equalityOrNot=false;
3111           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3112             {
3113               std::vector<int>::const_iterator it4=it3; it4++;
3114               for(;it4!=(*it2).second.end();it4++)
3115                 {
3116                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3117                     {
3118                       if(!equalityOrNot)
3119                         ret0.push_back(*it3);
3120                       ret0.push_back(*it4);
3121                       equalityOrNot=true;
3122                     }
3123                 }
3124             }
3125           if(!ret0.empty())
3126             ret.push_back(ret0);
3127         }
3128     }
3129   return ret;
3130 }
3131
3132 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3133 {
3134   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3135 }
3136
3137 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3138 {
3139   std::string name(pfl->getName());
3140   if(name.empty())
3141     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3142   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3143     if(name==(*it)->getName())
3144       {
3145         if(!pfl->isEqual(*(*it)))
3146           {
3147             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3148             throw INTERP_KERNEL::Exception(oss.str().c_str());
3149           }
3150       }
3151   pfl->incrRef();
3152   _pfls.push_back(pfl);
3153 }
3154
3155 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)
3156 {
3157   std::string name(locName);
3158   if(name.empty())
3159     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3160   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3161   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3162     if((*it)->isName(locName))
3163       {
3164         if(!(*it)->isEqual(*obj,1e-12))
3165           {
3166             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3167             throw INTERP_KERNEL::Exception(oss.str().c_str());
3168           }
3169       }
3170   _locs.push_back(obj);
3171 }
3172
3173 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3174 {
3175   std::vector<std::string> names=getPfls();
3176   return CreateNewNameNotIn("NewPfl_",names);
3177 }
3178
3179 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3180 {
3181   std::vector<std::string> names=getLocs();
3182   return CreateNewNameNotIn("NewLoc_",names);
3183 }
3184
3185 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3186 {
3187   for(std::size_t sz=0;sz<100000;sz++)
3188     {
3189       std::ostringstream tryName;
3190       tryName << prefix << sz;
3191       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3192         return tryName.str();
3193     }
3194   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3195 }
3196
3197 /*!
3198  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3199  *  \param [in] fname - the file name.
3200  */
3201 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
3202 {
3203 }
3204
3205 /*!
3206  * Creates an empty MEDFileFieldGlobsReal.
3207  */
3208 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3209 {
3210 }
3211
3212 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3213 {
3214   return 0;
3215 }
3216
3217 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3218 {
3219   std::vector<const BigMemoryObject *> ret;
3220   ret.push_back((const MEDFileFieldGlobs *)_globals);
3221   return ret;
3222 }
3223
3224 /*!
3225  * Returns a string describing profiles and Gauss points held in \a this.
3226  *  \return std::string - the description string.
3227  */
3228 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3229 {
3230   const MEDFileFieldGlobs *glob=_globals;
3231   std::ostringstream oss2; oss2 << glob;
3232   std::string stars(oss2.str().length(),'*');
3233   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3234   if(glob)
3235     glob->simpleRepr(oss);
3236   else
3237     oss << "NO GLOBAL INFORMATION !\n";
3238 }
3239
3240 void MEDFileFieldGlobsReal::resetContent()
3241 {
3242   _globals=MEDFileFieldGlobs::New();
3243 }
3244
3245 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3246 {
3247 }
3248
3249 /*!
3250  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3251  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3252  */
3253 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3254 {
3255   _globals=other._globals;
3256 }
3257
3258 /*!
3259  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3260  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3261  */
3262 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3263 {
3264   const MEDFileFieldGlobs *otherg(other._globals);
3265   if(!otherg)
3266     return ;
3267   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3268 }
3269
3270 /*!
3271  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3272  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3273  */
3274 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3275 {
3276   const MEDFileFieldGlobs *otherg(other._globals);
3277   if(!otherg)
3278     return ;
3279   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3280 }
3281
3282 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3283 {
3284   _globals=other._globals;
3285   if((const MEDFileFieldGlobs *)_globals)
3286     _globals=other._globals->deepCopy();
3287 }
3288
3289 /*!
3290  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3291  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3292  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3293  *         \a this and \a other MEDFileFieldGlobsReal.
3294  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3295  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3296  */
3297 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3298 {
3299   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3300   if(thisGlobals==otherGlobals)
3301     return ;
3302   if(!thisGlobals)
3303     {
3304       _globals=other._globals;
3305       return ;
3306     }
3307   _globals->appendGlobs(*other._globals,eps);
3308 }
3309
3310 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3311 {
3312   checkGlobsPflsPartCoherency();
3313   checkGlobsLocsPartCoherency();
3314 }
3315
3316 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3317 {
3318   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3319 }
3320
3321 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3322 {
3323   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3324 }
3325
3326 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3327 {
3328   contentNotNull()->loadProfileInFile(fid,id,pflName);
3329 }
3330
3331 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3332 {
3333   contentNotNull()->loadProfileInFile(fid,id);
3334 }
3335
3336 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3337 {
3338   contentNotNull()->loadGlobals(fid,*this);
3339 }
3340
3341 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3342 {
3343   contentNotNull()->loadAllGlobals(fid);
3344 }
3345
3346 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3347 {
3348   contentNotNull()->writeGlobals(fid,opt);
3349 }
3350
3351 /*!
3352  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3353  * or getPflsReallyUsedMulti().
3354  *  \return std::vector<std::string> - a sequence of names of all profiles.
3355  */
3356 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3357 {
3358   return contentNotNull()->getPfls();
3359 }
3360
3361 /*!
3362  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3363  * or getLocsReallyUsedMulti().
3364  *  \return std::vector<std::string> - a sequence of names of all localizations.
3365  */
3366 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3367 {
3368   return contentNotNull()->getLocs();
3369 }
3370
3371 /*!
3372  * Checks if the profile with a given name exists.
3373  *  \param [in] pflName - the profile name of interest.
3374  *  \return bool - \c true if the profile named \a pflName exists.
3375  */
3376 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3377 {
3378   return contentNotNull()->existsPfl(pflName);
3379 }
3380
3381 /*!
3382  * Checks if the localization with a given name exists.
3383  *  \param [in] locName - the localization name of interest.
3384  *  \return bool - \c true if the localization named \a locName exists.
3385  */
3386 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3387 {
3388   return contentNotNull()->existsLoc(locName);
3389 }
3390
3391 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3392 {
3393   return contentNotNull()->createNewNameOfPfl();
3394 }
3395
3396 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3397 {
3398   return contentNotNull()->createNewNameOfLoc();
3399 }
3400
3401 /*!
3402  * Sets the name of a MED file.
3403  *  \param [inout] fileName - the file name.
3404  */
3405 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3406 {
3407   contentNotNull()->setFileName(fileName);
3408 }
3409
3410 /*!
3411  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3412  * in the same order.
3413  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3414  *          Each item of this sequence is a vector containing ids of equal profiles.
3415  */
3416 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3417 {
3418   return contentNotNull()->whichAreEqualProfiles();
3419 }
3420
3421 /*!
3422  * Finds equal localizations.
3423  *  \param [in] eps - a precision used to compare real values of the localizations.
3424  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3425  *          Each item of this sequence is a vector containing ids of equal localizations.
3426  */
3427 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3428 {
3429   return contentNotNull()->whichAreEqualLocs(eps);
3430 }
3431
3432 /*!
3433  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3434  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3435  *        this sequence is a pair whose 
3436  *        - the first item is a vector of profile names to replace by the second item,
3437  *        - the second item is a profile name to replace every profile name of the first item.
3438  */
3439 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3440 {
3441   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3442 }
3443
3444 /*!
3445  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3446  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3447  *        this sequence is a pair whose 
3448  *        - the first item is a vector of localization names to replace by the second item,
3449  *        - the second item is a localization name to replace every localization name of the first item.
3450  */
3451 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3452 {
3453   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3454 }
3455
3456 /*!
3457  * Replaces references to some profiles (a reference is a profile name) by references
3458  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3459  * them-selves accordingly. <br>
3460  * This method is a generalization of changePflName().
3461  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3462  *        this sequence is a pair whose 
3463  *        - the first item is a vector of profile names to replace by the second item,
3464  *        - the second item is a profile name to replace every profile of the first item.
3465  * \sa changePflsRefsNamesGen()
3466  * \sa changePflName()
3467  */
3468 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3469 {
3470   changePflsRefsNamesGen(mapOfModif);
3471   changePflsNamesInStruct(mapOfModif);
3472 }
3473
3474 /*!
3475  * Replaces references to some localizations (a reference is a localization name) by references
3476  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3477  * them-selves accordingly. <br>
3478  * This method is a generalization of changeLocName().
3479  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3480  *        this sequence is a pair whose 
3481  *        - the first item is a vector of localization names to replace by the second item,
3482  *        - the second item is a localization name to replace every localization of the first item.
3483  * \sa changeLocsRefsNamesGen()
3484  * \sa changeLocName()
3485  */
3486 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3487 {
3488   changeLocsRefsNamesGen(mapOfModif);
3489   changeLocsNamesInStruct(mapOfModif);
3490 }
3491
3492 /*!
3493  * Renames the profile having a given name and updates references to this profile.
3494  *  \param [in] oldName - the name of the profile to rename.
3495  *  \param [in] newName - a new name of the profile.
3496  * \sa changePflsNames().
3497  */
3498 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3499 {
3500   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3501   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3502   mapOfModif[0]=p;
3503   changePflsNames(mapOfModif);
3504 }
3505
3506 /*!
3507  * Renames the localization having a given name and updates references to this localization.
3508  *  \param [in] oldName - the name of the localization to rename.
3509  *  \param [in] newName - a new name of the localization.
3510  * \sa changeLocsNames().
3511  */
3512 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3513 {
3514   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3515   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3516   mapOfModif[0]=p;
3517   changeLocsNames(mapOfModif);
3518 }
3519
3520 /*!
3521  * Removes duplicated profiles. Returns a map used to update references to removed 
3522  * profiles via changePflsRefsNamesGen().
3523  * Equal profiles are found using whichAreEqualProfiles().
3524  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3525  *          a sequence describing the performed replacements of profiles. Each element of
3526  *          this sequence is a pair whose
3527  *          - the first item is a vector of profile names replaced by the second item,
3528  *          - the second item is a profile name replacing every profile of the first item.
3529  */
3530 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3531 {
3532   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3533   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3534   int i=0;
3535   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3536     {
3537       std::vector< std::string > tmp((*it).size());
3538       int j=0;
3539       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3540         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3541       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3542       ret[i]=p;
3543       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3544       killProfileIds(tmp2);
3545     }
3546   changePflsRefsNamesGen(ret);
3547   return ret;
3548 }
3549
3550 /*!
3551  * Removes duplicated localizations. Returns a map used to update references to removed 
3552  * localizations via changeLocsRefsNamesGen().
3553  * Equal localizations are found using whichAreEqualLocs().
3554  *  \param [in] eps - a precision used to compare real values of the localizations.
3555  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3556  *          a sequence describing the performed replacements of localizations. Each element of
3557  *          this sequence is a pair whose
3558  *          - the first item is a vector of localization names replaced by the second item,
3559  *          - the second item is a localization name replacing every localization of the first item.
3560  */
3561 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3562 {
3563   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3564   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3565   int i=0;
3566   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3567     {
3568       std::vector< std::string > tmp((*it).size());
3569       int j=0;
3570       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3571         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3572       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3573       ret[i]=p;
3574       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3575       killLocalizationIds(tmp2);
3576     }
3577   changeLocsRefsNamesGen(ret);
3578   return ret;
3579 }
3580
3581 /*!
3582  * Returns number of Gauss points per cell in a given localization.
3583  *  \param [in] locId - an id of the localization of interest.
3584  *  \return int - the number of the Gauss points per cell.
3585  */
3586 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3587 {
3588   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3589 }
3590
3591 /*!
3592  * Returns an id of a localization by its name.
3593  *  \param [in] loc - the localization name of interest.
3594  *  \return int - the id of the localization.
3595  *  \throw If there is no a localization named \a loc.
3596  */
3597 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3598 {
3599   return contentNotNull()->getLocalizationId(loc);
3600 }
3601
3602 /*!
3603  * Returns the name of the MED file.
3604  *  \return const std::string&  - the MED file name.
3605  */
3606 std::string MEDFileFieldGlobsReal::getFileName() const
3607 {
3608   return contentNotNull()->getFileName();
3609 }
3610
3611 /*!
3612  * Returns a localization object by its name.
3613  *  \param [in] locName - the name of the localization of interest.
3614  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3615  *  \throw If there is no a localization named \a locName.
3616  */
3617 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3618 {
3619   return contentNotNull()->getLocalization(locName);
3620 }
3621
3622 /*!
3623  * Returns a localization object by its id.
3624  *  \param [in] locId - the id of the localization of interest.
3625  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3626  *  \throw If there is no a localization with id \a locId.
3627  */
3628 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3629 {
3630   return contentNotNull()->getLocalizationFromId(locId);
3631 }
3632
3633 /*!
3634  * Returns a profile array by its name.
3635  *  \param [in] pflName - the name of the profile of interest.
3636  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3637  *  \throw If there is no a profile named \a pflName.
3638  */
3639 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3640 {
3641   return contentNotNull()->getProfile(pflName);
3642 }
3643
3644 /*!
3645  * Returns a profile array by its id.
3646  *  \param [in] pflId - the id of the profile of interest.
3647  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3648  *  \throw If there is no a profile with id \a pflId.
3649  */
3650 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3651 {
3652   return contentNotNull()->getProfileFromId(pflId);
3653 }
3654
3655 /*!
3656  * Returns a localization object, apt for modification, by its id.
3657  *  \param [in] locId - the id of the localization of interest.
3658  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3659  *          having the id \a locId.
3660  *  \throw If there is no a localization with id \a locId.
3661  */
3662 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3663 {
3664   return contentNotNull()->getLocalizationFromId(locId);
3665 }
3666
3667 /*!
3668  * Returns a localization object, apt for modification, by its name.
3669  *  \param [in] locName - the name of the localization of interest.
3670  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3671  *          having the name \a locName.
3672  *  \throw If there is no a localization named \a locName.
3673  */
3674 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3675 {
3676   return contentNotNull()->getLocalization(locName);
3677 }
3678
3679 /*!
3680  * Returns a profile array, apt for modification, by its name.
3681  *  \param [in] pflName - the name of the profile of interest.
3682  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3683  *  \throw If there is no a profile named \a pflName.
3684  */
3685 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3686 {
3687   return contentNotNull()->getProfile(pflName);
3688 }
3689
3690 /*!
3691  * Returns a profile array, apt for modification, by its id.
3692  *  \param [in] pflId - the id of the profile of interest.
3693  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3694  *  \throw If there is no a profile with id \a pflId.
3695  */
3696 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3697 {
3698   return contentNotNull()->getProfileFromId(pflId);
3699 }
3700
3701 /*!
3702  * Removes profiles given by their ids. No data is updated to track this removal.
3703  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3704  */
3705 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3706 {
3707   contentNotNull()->killProfileIds(pflIds);
3708 }
3709
3710 /*!
3711  * Removes localizations given by their ids. No data is updated to track this removal.
3712  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3713  */
3714 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3715 {
3716   contentNotNull()->killLocalizationIds(locIds);
3717 }
3718
3719 /*!
3720  * Stores a profile array.
3721  *  \param [in] pfl - the profile array to store.
3722  *  \throw If the name of \a pfl is empty.
3723  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3724  *         different ids.
3725  */
3726 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3727 {
3728   contentNotNull()->appendProfile(pfl);
3729 }
3730
3731 /*!
3732  * Adds a new localization of Gauss points.
3733  *  \param [in] locName - the name of the new localization.
3734  *  \param [in] geoType - a geometrical type of the reference cell.
3735  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3736  *         must be \c nbOfNodesPerCell * \c dimOfType.
3737  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3738  *         must be  _wg_.size() * \c dimOfType.
3739  *  \param [in] w - the weights of Gauss points.
3740  *  \throw If \a locName is empty.
3741  *  \throw If a localization with the name \a locName already exists but is
3742  *         different form the new one.
3743  */
3744 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)
3745 {
3746   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3747 }
3748
3749 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3750 {
3751   MEDFileFieldGlobs *g(_globals);
3752   if(!g)
3753     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3754   return g;
3755 }
3756
3757 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3758 {
3759   const MEDFileFieldGlobs *g(_globals);
3760   if(!g)
3761     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3762   return g;
3763 }
3764
3765 //= MEDFileFieldNameScope
3766
3767 MEDFileFieldNameScope::MEDFileFieldNameScope()
3768 {
3769 }
3770
3771 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3772 {
3773 }
3774
3775 /*!
3776  * Returns the name of \a this field.
3777  *  \return std::string - a string containing the field name.
3778  */
3779 std::string MEDFileFieldNameScope::getName() const
3780 {
3781   return _name;
3782 }
3783
3784 /*!
3785  * Sets name of \a this field
3786  *  \param [in] name - the new field name.
3787  */
3788 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3789 {
3790   _name=fieldName;
3791 }
3792
3793 std::string MEDFileFieldNameScope::getDtUnit() const
3794 {
3795   return _dt_unit;
3796 }
3797
3798 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3799 {
3800   _dt_unit=dtUnit;
3801 }
3802
3803 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3804 {
3805   _name=other._name;
3806   _dt_unit=other._dt_unit;
3807 }
3808
3809 //= MEDFileAnyTypeField1TSWithoutSDA
3810
3811 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3812 {
3813   _field_per_mesh.resize(other._field_per_mesh.size());
3814   std::size_t i=0;
3815   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3816     {
3817       if((const MEDFileFieldPerMesh *)*it)
3818         _field_per_mesh[i]=(*it)->deepCopy(this);
3819     }
3820 }
3821
3822 /*!
3823  * Prints a string describing \a this field into a stream. This string is outputted 
3824  * by \c print Python command.
3825  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3826  *  \param [in,out] oss - the out stream.
3827  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3828  *          info id printed, else, not.
3829  */
3830 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3831 {
3832   std::string startOfLine(bkOffset,' ');
3833   oss << startOfLine << "Field ";
3834   if(bkOffset==0)
3835     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3836   oss << "on one time Step ";
3837   if(f1tsId>=0)
3838     oss << "(" << f1tsId << ") ";
3839   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3840   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3841   const DataArray *arr=getUndergroundDataArray();
3842   if(arr)
3843     {
3844       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3845       if(f1tsId<0)
3846         {
3847           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3848           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3849             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3850         }
3851       if(arr->isAllocated())
3852         {
3853           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3854         }
3855       else
3856         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3857     }
3858   else
3859     {
3860       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3861     }
3862   oss << startOfLine << "----------------------" << std::endl;
3863   if(!_field_per_mesh.empty())
3864     {
3865       int i=0;
3866       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3867         {
3868           const MEDFileFieldPerMesh *cur=(*it2);
3869           if(cur)
3870             cur->simpleRepr(bkOffset,oss,i);
3871           else
3872             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3873         }
3874     }
3875   else
3876     {
3877       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3878     }
3879   oss << startOfLine << "----------------------" << std::endl;
3880 }
3881
3882 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3883 {
3884   const DataArray *arr(getUndergroundDataArray());
3885   if(!arr)
3886     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3887   int nbOfCompo=arr->getNumberOfComponents();
3888   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3889   for(int i=0;i<nbOfCompo;i++)
3890     {
3891       ret[i]=deepCopy();
3892       std::vector<int> v(1,i);
3893       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
3894       ret[i]->setArray(arr2);
3895     }
3896   return ret;
3897 }
3898
3899 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)
3900 {
3901 }
3902
3903 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3904 {
3905 }
3906
3907 /*!
3908  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3909  * empty. Returns -1 if this in on nodes.
3910  *  \return int - the dimension of \a this.
3911  */
3912 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3913 {
3914   int ret=-2;
3915   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3916     (*it)->getDimension(ret);
3917   return ret;
3918 }
3919
3920 /*!
3921  * Returns the mesh name.
3922  *  \return std::string - a string holding the mesh name.
3923  *  \throw If \c _field_per_mesh.empty()
3924  */
3925 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3926 {
3927   if(_field_per_mesh.empty())
3928     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3929   return _field_per_mesh[0]->getMeshName();
3930 }
3931
3932 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3933 {
3934   std::string oldName(getMeshName());
3935   std::vector< std::pair<std::string,std::string> > v(1);
3936   v[0].first=oldName; v[0].second=newMeshName;
3937   changeMeshNames(v);
3938 }
3939
3940 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3941 {
3942   bool ret=false;
3943   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3944     {
3945       MEDFileFieldPerMesh *cur(*it);
3946       if(cur)
3947         ret=cur->changeMeshNames(modifTab) || ret;
3948     }
3949   return ret;
3950 }
3951
3952 /*!
3953  * Returns the number of iteration of the state of underlying mesh.
3954  *  \return int - the iteration number.
3955  *  \throw If \c _field_per_mesh.empty()
3956  */
3957 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3958 {
3959   if(_field_per_mesh.empty())
3960     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3961   return _field_per_mesh[0]->getMeshIteration();
3962 }
3963
3964 /*!
3965  * Returns the order number of iteration of the state of underlying mesh.
3966  *  \return int - the order number.
3967  *  \throw If \c _field_per_mesh.empty()
3968  */
3969 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3970 {
3971   if(_field_per_mesh.empty())
3972     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3973   return _field_per_mesh[0]->getMeshOrder();
3974 }
3975
3976 /*!
3977  * Checks if \a this field is tagged by a given iteration number and a given
3978  * iteration order number.
3979  *  \param [in] iteration - the iteration number of interest.
3980  *  \param [in] order - the iteration order number of interest.
3981  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3982  *          \a this->getOrder() == \a order.
3983  */
3984 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3985 {
3986   return iteration==_iteration && order==_order;
3987 }
3988
3989 /*!
3990  * Returns number of iteration and order number of iteration when
3991  * \a this field has been calculated.
3992  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3993  *          order number.
3994  */
3995 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3996 {
3997   std::pair<int,int> p;
3998   fillIteration(p);
3999   return p;
4000 }
4001
4002 /*!
4003  * Returns number of iteration and order number of iteration when
4004  * \a this field has been calculated.
4005  *  \param [in,out] p - a pair returning the iteration number and the iteration
4006  *          order number.
4007  */
4008 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4009 {
4010   p.first=_iteration;
4011   p.second=_order;
4012 }
4013
4014 /*!
4015  * Returns all types of spatial discretization of \a this field.
4016  *  \param [in,out] types - a sequence of types of \a this field.
4017  */
4018 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4019 {
4020   std::set<TypeOfField> types2;
4021   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4022     {
4023       (*it)->fillTypesOfFieldAvailable(types2);
4024     }
4025   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4026   std::copy(types2.begin(),types2.end(),bi);
4027 }
4028
4029 /*!
4030  * Returns all types of spatial discretization of \a this field.
4031  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4032  *          of \a this field.
4033  */
4034 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4035 {
4036   std::vector<TypeOfField> ret;
4037   fillTypesOfFieldAvailable(ret);
4038   return ret;
4039 }
4040
4041 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4042 {
4043   std::vector<std::string> ret;
4044   std::set<std::string> ret2;
4045   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4046     {
4047       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4048       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4049         if(ret2.find(*it2)==ret2.end())
4050           {
4051             ret.push_back(*it2);
4052             ret2.insert(*it2);
4053           }
4054     }
4055   return ret;
4056 }
4057
4058 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4059 {
4060   std::vector<std::string> ret;
4061   std::set<std::string> ret2;
4062   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4063     {
4064       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4065       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4066         if(ret2.find(*it2)==ret2.end())
4067           {
4068             ret.push_back(*it2);
4069             ret2.insert(*it2);
4070           }
4071     }
4072   return ret;
4073 }
4074
4075 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4076 {
4077   std::vector<std::string> ret;
4078   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4079     {
4080       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4081       ret.insert(ret.end(),tmp.begin(),tmp.end());
4082     }
4083   return ret;
4084 }
4085
4086 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4087 {
4088   std::vector<std::string> ret;
4089   std::set<std::string> ret2;
4090   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4091     {
4092       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4093       ret.insert(ret.end(),tmp.begin(),tmp.end());
4094     }
4095   return ret;
4096 }
4097
4098 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4099 {
4100   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4101     (*it)->changePflsRefsNamesGen(mapOfModif);
4102 }
4103
4104 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4105 {
4106   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4107     (*it)->changeLocsRefsNamesGen(mapOfModif);
4108 }
4109
4110 /*!
4111  * Returns all attributes of parts of \a this field lying on a given mesh.
4112  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4113  * item of every of returned sequences refers to the _i_-th part of \a this field.
4114  * Thus all sequences returned by this method are of the same length equal to number
4115  * of different types of supporting entities.<br>
4116  * A field part can include sub-parts with several different spatial discretizations,
4117  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4118  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4119  * of a nested sequence corresponds to a type of spatial discretization.<br>
4120  * This method allows for iteration over MEDFile DataStructure without any overhead.
4121  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4122  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4123  *          not checked if \a mname == \c NULL).
4124  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4125  *          a field part is returned. 
4126  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4127  *          This sequence is of the same length as \a types. 
4128  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4129  *          discretization. A profile name can be empty.
4130  *          Length of this and of nested sequences is the same as that of \a typesF.
4131  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4132  *          discretization. A localization name can be empty.
4133  *          Length of this and of nested sequences is the same as that of \a typesF.
4134  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4135  *          of ids of tuples within the data array, per each type of spatial
4136  *          discretization within one mesh entity type. 
4137  *          Length of this and of nested sequences is the same as that of \a typesF.
4138  *  \throw If no field is lying on \a mname.
4139  */
4140 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
4141 {
4142   int meshId=0;
4143   if(!mname.empty())
4144     meshId=getMeshIdFromMeshName(mname);
4145   else
4146     if(_field_per_mesh.empty())
4147       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4148   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4149 }
4150
4151 /*!
4152  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4153  * maximal absolute dimension and values returned via the out parameter \a levs are 
4154  * dimensions relative to the maximal absolute dimension. <br>
4155  * This method is designed for MEDFileField1TS instances that have a discretization
4156  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4157  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4158  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4159  * Only these 3 discretizations will be taken into account here. If \a this is
4160  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4161  * This method is useful to make the link between the dimension of the underlying mesh
4162  * and the levels of \a this, because it is possible that the highest dimension of \a this
4163  * field is not equal to the dimension of the underlying mesh.
4164  * 
4165  * Let's consider the following case:
4166  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4167  * TETRA4, HEXA8, TRI3 and SEG2.
4168  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4169  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4170  *
4171  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4172  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4173  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4174  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4175  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4176  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4177  * For example<br>
4178  * to retrieve the highest level of
4179  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4180  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4181  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4182  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4183  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4184  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4185  *          not checked if \a mname == \c NULL).
4186  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4187  *          absolute one. They are in decreasing order. This sequence is cleared before
4188  *          filling it in.
4189  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4190  *  \throw If no field is lying on \a mname.
4191  */
4192 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4193 {
4194   levs.clear();
4195   int meshId=getMeshIdFromMeshName(mname);
4196   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4197   std::vector< std::vector<TypeOfField> > typesF;
4198   std::vector< std::vector<std::string> > pfls, locs;
4199   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4200   if(types.empty())
4201     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4202   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4203   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4204     return -1;
4205   st.erase(INTERP_KERNEL::NORM_ERROR);
4206   std::set<int> ret1;
4207   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4208     {
4209       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4210       ret1.insert((int)cm.getDimension());
4211     }
4212   int ret=*std::max_element(ret1.begin(),ret1.end());
4213   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4214   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4215   return ret;
4216 }
4217
4218 /*!
4219  * \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.
4220  * \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.
4221  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4222  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4223  */
4224 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4225 {
4226   int mid=getMeshIdFromMeshName(mName);
4227   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4228 }
4229
4230 /*!
4231  * \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.
4232  * \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.
4233  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4234  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4235  */
4236 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4237 {
4238   int mid=getMeshIdFromMeshName(mName);
4239   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4240 }
4241
4242 /*!
4243  * \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.
4244  */
4245 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4246 {
4247   if(_field_per_mesh.empty())
4248     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4249   if(mName.empty())
4250     return 0;
4251   std::string mName2(mName);
4252   int ret=0;
4253   std::vector<std::string> msg;
4254   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4255     if(mName2==(*it)->getMeshName())
4256       return ret;
4257     else
4258       msg.push_back((*it)->getMeshName());
4259   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4260   oss << "Possible meshes are : ";
4261   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4262     oss << "\"" << (*it2) << "\" ";
4263   throw INTERP_KERNEL::Exception(oss.str().c_str());
4264 }
4265
4266 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4267 {
4268   if(!mesh)
4269     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4270   std::string tmp(mesh->getName());
4271   if(tmp.empty())
4272     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4273   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4274   int i=0;
4275   for(;it!=_field_per_mesh.end();it++,i++)
4276     {
4277       if((*it)->getMeshName()==tmp)
4278         return i;
4279     }
4280   int sz=_field_per_mesh.size();
4281   _field_per_mesh.resize(sz+1);
4282   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4283   return sz;
4284 }
4285
4286 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4287                                                                    MEDFileFieldGlobsReal& glob)
4288 {
4289   bool ret=false;
4290   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4291     {
4292       MEDFileFieldPerMesh *fpm(*it);
4293       if(fpm)
4294         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4295     }
4296   return ret;
4297 }
4298
4299 /*!
4300  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4301  * splitting that leads to single spatial discretization of this.
4302  *
4303  * \sa splitMultiDiscrPerGeoTypes
4304  */
4305 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4306 {
4307   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4308   std::vector< std::vector<TypeOfField> > typesF;
4309   std::vector< std::vector<std::string> > pfls,locs;
4310   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4311   std::set<TypeOfField> allEnt;
4312   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4313     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4314       allEnt.insert(*it2);
4315   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4316   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4317   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4318     {
4319       std::vector< std::pair<int,int> > its;
4320       ret[i]=shallowCpy();
4321       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4322       ret[i]->updateData(newLgth,its);
4323     }
4324   return ret;
4325 }
4326
4327 /*!
4328  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4329  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4330  *
4331  * \sa splitDiscretizations
4332  */
4333 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4334 {
4335   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4336   std::vector< std::vector<TypeOfField> > typesF;
4337   std::vector< std::vector<std::string> > pfls,locs;
4338   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4339   std::set<TypeOfField> allEnt;
4340   std::size_t nbOfMDPGT(0),ii(0);
4341   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4342     {
4343       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4344       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4345         allEnt.insert(*it2);
4346     }
4347   if(allEnt.size()!=1)
4348     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4349   if(nbOfMDPGT==0)
4350     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4351   if(nbOfMDPGT==1)
4352     {
4353       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4354       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4355       return ret0;
4356     }
4357   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4358   for(std::size_t i=0;i<nbOfMDPGT;i++)
4359     {
4360       std::vector< std::pair<int,int> > its;
4361       ret[i]=shallowCpy();
4362       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4363       ret[i]->updateData(newLgth,its);
4364     }
4365   return ret;
4366 }
4367
4368 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4369 {
4370   int globalCounter(0);
4371   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4372     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4373   return globalCounter;
4374 }
4375
4376 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4377 {
4378   int globalCounter(0);
4379   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4380     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4381   return globalCounter;
4382 }
4383
4384 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4385 {
4386   if(_nb_of_tuples_to_be_allocated>=0)
4387     {
4388       _nb_of_tuples_to_be_allocated=newLgth;
4389       const DataArray *oldArr(getUndergroundDataArray());
4390       if(oldArr)
4391         {
4392           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4393           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4394           setArray(newArr);
4395           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4396         }
4397       return ;
4398     }
4399   if(_nb_of_tuples_to_be_allocated==-1)
4400     return ;
4401   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4402     {
4403       const DataArray *oldArr(getUndergroundDataArray());
4404       if(!oldArr || !oldArr->isAllocated())
4405         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4406       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4407       newArr->alloc(newLgth,getNumberOfComponents());
4408       if(oldArr)
4409         newArr->copyStringInfoFrom(*oldArr);
4410       int pos=0;
4411       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4412         {
4413           if((*it).second<(*it).first)
4414             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4415           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4416           pos+=(*it).second-(*it).first;
4417         }
4418       setArray(newArr);
4419       return ;
4420     }
4421   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4422 }
4423
4424 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4425 {
4426   if(_field_per_mesh.empty())
4427     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4428   if(_field_per_mesh.size()>1)
4429     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4430   _field_per_mesh[0]->copyOptionsFrom(opts);
4431   _field_per_mesh[0]->writeLL(fid,nasc);
4432 }
4433
4434 /*!
4435  * 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.
4436  * If false is returned the memory allocation is not required.
4437  */
4438 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4439 {
4440   if(_nb_of_tuples_to_be_allocated>=0)
4441     {
4442       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4443       _nb_of_tuples_to_be_allocated=-2;
4444       return true;
4445     }
4446   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4447     return false;
4448   if(_nb_of_tuples_to_be_allocated==-1)
4449     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4450   if(_nb_of_tuples_to_be_allocated<-3)
4451     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4452   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4453 }
4454
4455 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4456 {
4457   med_int numdt,numit;
4458   med_float dt;
4459   med_int nmesh;
4460   med_bool localMesh;
4461   med_int meshnumdt,meshnumit;
4462   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4463   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4464   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4465   if(_iteration!=numdt || _order!=numit)
4466     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4467   _field_per_mesh.resize(nmesh);
4468   //
4469   MEDFileMesh *mm(0);
4470   if(ms)
4471     {
4472       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4473       mm=ms->getMeshWithName(meshNameCpp);
4474     }
4475   //
4476   for(int i=0;i<nmesh;i++)
4477     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4478   _nb_of_tuples_to_be_allocated=0;
4479   for(int i=0;i<nmesh;i++)
4480     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4481 }
4482
4483 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4484 {
4485   allocIfNecessaryTheArrayToReceiveDataFromFile();
4486   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4487     (*it)->loadBigArraysRecursively(fid,nasc);
4488 }
4489
4490 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4491 {
4492   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4493     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4494       (*it)->loadBigArraysRecursively(fid,nasc);
4495 }
4496
4497 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4498 {
4499   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4500   loadBigArraysRecursively(fid,nasc);
4501 }
4502
4503 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4504 {
4505   DataArray *thisArr(getUndergroundDataArray());
4506   if(thisArr && thisArr->isAllocated())
4507     {
4508       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4509       thisArr->desallocate();
4510     }
4511 }
4512
4513 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4514 {
4515   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
4516 }
4517
4518 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4519 {
4520   std::vector<const BigMemoryObject *> ret;
4521   if(getUndergroundDataArray())
4522     ret.push_back(getUndergroundDataArray());
4523   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4524     ret.push_back((const MEDFileFieldPerMesh *)*it);
4525   return ret;
4526 }
4527
4528 /*!
4529  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4530  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4531  * "Sort By Type"), if not, an exception is thrown. 
4532  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4533  *  \param [in] arr - the array of values.
4534  *  \param [in,out] glob - the global data where profiles and localization present in
4535  *          \a field, if any, are added.
4536  *  \throw If the name of \a field is empty.
4537  *  \throw If the data array of \a field is not set.
4538  *  \throw If \a this->_arr is already allocated but has different number of components
4539  *         than \a field.
4540  *  \throw If the underlying mesh of \a field has no name.
4541  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4542  */
4543 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4544 {
4545   const MEDCouplingMesh *mesh=field->getMesh();
4546   //
4547   TypeOfField type=field->getTypeOfField();
4548   std::vector<DataArrayInt *> dummy;
4549   int start=copyTinyInfoFrom(field,arr);
4550   int pos=addNewEntryIfNecessary(mesh);
4551   if(type!=ON_NODES)
4552     {
4553       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4554       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4555     }
4556   else
4557     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4558 }
4559
4560 /*!
4561  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4562  * of a given mesh are used as the support of the given field (a real support is not used). 
4563  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4564  * Order of underlying mesh entities of the given field specified by \a profile parameter
4565  * is not prescribed; this method permutes field values to have them sorted by element
4566  * type as required for writing to MED file. A new profile is added only if no equal
4567  * profile is missing. 
4568  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4569  *  \param [in] arrOfVals - the values of the field \a field used.
4570  *  \param [in] mesh - the supporting mesh of \a field.
4571  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4572  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4573  *  \param [in,out] glob - the global data where profiles and localization present in
4574  *          \a field, if any, are added.
4575  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4576  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4577  *  \throw If the data array of \a field is not set.
4578  *  \throw If \a this->_arr is already allocated but has different number of components
4579  *         than \a field.
4580  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4581  *  \sa setFieldNoProfileSBT()
4582  */
4583 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4584 {
4585   if(!field)
4586     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4587   if(!arrOfVals || !arrOfVals->isAllocated())
4588     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4589   TypeOfField type=field->getTypeOfField();
4590   std::vector<DataArrayInt *> idsInPflPerType;
4591   std::vector<DataArrayInt *> idsPerType;
4592   std::vector<int> code,code2;
4593   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4594   if(type!=ON_NODES)
4595     {
4596       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4597       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4598       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4599       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4600       // start of check
4601       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
4602       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4603       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4604         {
4605           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4606           throw INTERP_KERNEL::Exception(oss.str().c_str());
4607         }
4608       // end of check
4609       int start=copyTinyInfoFrom(field,arrOfVals);
4610       code2=m->getDistributionOfTypes();
4611       //
4612       int pos=addNewEntryIfNecessary(m);
4613       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4614     }
4615   else
4616     {
4617       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4618         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4619       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4620       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4621       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4622       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4623         {
4624           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4625           throw INTERP_KERNEL::Exception(oss.str().c_str());
4626         }
4627       int start=copyTinyInfoFrom(field,arrOfVals);
4628       int pos=addNewEntryIfNecessary(m);
4629       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4630     }
4631 }
4632
4633 /*!
4634  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4635  */
4636 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4637 {
4638   if(_nb_of_tuples_to_be_allocated>=0)
4639     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 !");
4640   DataArray *arr(getOrCreateAndGetArray());
4641   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4642   _nb_of_tuples_to_be_allocated=-3;
4643 }
4644
4645 /*!
4646  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4647  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4648  * larger by the size of \a field. Returns an id of the first not filled
4649  * tuple of \a this->_arr.
4650  *  \param [in] field - the field to copy the info on components and the name from.
4651  *  \return int - the id of first not initialized tuple of \a this->_arr.
4652  *  \throw If the name of \a field is empty.
4653  *  \throw If the data array of \a field is not set.
4654  *  \throw If \a this->_arr is already allocated but has different number of components
4655  *         than \a field.
4656  */
4657 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4658 {
4659   if(!field)
4660     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4661   std::string name(field->getName());
4662   setName(name.c_str());
4663   setDtUnit(field->getTimeUnit());
4664   if(name.empty())
4665     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4666   if(!arr)
4667     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4668   if(!arr->isAllocated())
4669     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4670   _dt=field->getTime(_iteration,_order);
4671   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4672   if(!getOrCreateAndGetArray()->isAllocated())
4673     {
4674       allocNotFromFile(arr->getNumberOfTuples());
4675       return 0;
4676     }
4677   else
4678     {
4679       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4680       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4681       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4682       _nb_of_tuples_to_be_allocated=-3;
4683       return oldNbOfTuples;
4684     }
4685 }
4686
4687 /*!
4688  * Returns number of components in \a this field
4689  *  \return int - the number of components.
4690  */
4691 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4692 {
4693   return getOrCreateAndGetArray()->getNumberOfComponents();
4694 }
4695
4696 /*!
4697  * Change info on components in \a this.
4698  * \throw If size of \a infos is not equal to the number of components already in \a this.
4699  */
4700 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4701 {
4702   DataArray *arr=getOrCreateAndGetArray();
4703   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4704 }
4705
4706 /*!
4707  * Returns info on components of \a this field.
4708  *  \return const std::vector<std::string>& - a sequence of strings each being an
4709  *          information on _i_-th component.
4710  */
4711 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4712 {
4713   const DataArray *arr=getOrCreateAndGetArray();
4714   return arr->getInfoOnComponents();
4715 }
4716
4717 /*!
4718  * Returns a mutable info on components of \a this field.
4719  *  \return std::vector<std::string>& - a sequence of strings each being an
4720  *          information on _i_-th component.
4721  */
4722 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4723 {
4724   DataArray *arr=getOrCreateAndGetArray();
4725   return arr->getInfoOnComponents();
4726 }
4727
4728 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4729 {
4730   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4731     {
4732       const MEDFileFieldPerMesh *fpm(*it);
4733       if(!fpm)
4734         continue;
4735       if(fpm->presenceOfMultiDiscPerGeoType())
4736         return true;
4737     }
4738   return false;
4739 }
4740
4741 /*!
4742  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4743  *  \param [in] type - a spatial discretization of the new field.
4744  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4745  *  \param [in] mName - a name of the supporting mesh.
4746  *  \param [in] renumPol - specifies how to permute values of the result field according to
4747  *          the optional numbers of cells and nodes, if any. The valid values are
4748  *          - 0 - do not permute.
4749  *          - 1 - permute cells.
4750  *          - 2 - permute nodes.
4751  *          - 3 - permute cells and nodes.
4752  *
4753  *  \param [in] glob - the global data storing profiles and localization.
4754  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4755  *          caller is to delete this field using decrRef() as it is no more needed. 
4756  *  \throw If the MED file is not readable.
4757  *  \throw If there is no mesh named \a mName in the MED file.
4758  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4759  *  \throw If no field of \a this is lying on the mesh \a mName.
4760  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4761  */
4762 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4763 {
4764   MCAuto<MEDFileMesh> mm;
4765   if(mName.empty())
4766     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4767   else
4768     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4769   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4770 }
4771
4772 /*!
4773  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4774  *  \param [in] type - a spatial discretization of the new field.
4775  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4776  *  \param [in] renumPol - specifies how to permute values of the result field according to
4777  *          the optional numbers of cells and nodes, if any. The valid values are
4778  *          - 0 - do not permute.
4779  *          - 1 - permute cells.
4780  *          - 2 - permute nodes.
4781  *          - 3 - permute cells and nodes.
4782  *
4783  *  \param [in] glob - the global data storing profiles and localization.
4784  *  \param [in] mesh - the supporting mesh.
4785  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4786  *          caller is to delete this field using decrRef() as it is no more needed. 
4787  *  \throw If the MED file is not readable.
4788  *  \throw If no field of \a this is lying on \a mesh.
4789  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4790  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4791  */
4792 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4793 {
4794   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
4795   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4796   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4797   if(meshDimRelToMax==1)
4798     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4799   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4800 }
4801
4802 /*!
4803  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4804  * given mesh. 
4805  *  \param [in] type - a spatial discretization of the new field.
4806  *  \param [in] mName - a name of the supporting mesh.
4807  *  \param [in] renumPol - specifies how to permute values of the result field according to
4808  *          the optional numbers of cells and nodes, if any. The valid values are
4809  *          - 0 - do not permute.
4810  *          - 1 - permute cells.
4811  *          - 2 - permute nodes.
4812  *          - 3 - permute cells and nodes.
4813  *
4814  *  \param [in] glob - the global data storing profiles and localization.
4815  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4816  *          caller is to delete this field using decrRef() as it is no more needed. 
4817  *  \throw If the MED file is not readable.
4818  *  \throw If there is no mesh named \a mName in the MED file.
4819  *  \throw If there are no mesh entities in the mesh.
4820  *  \throw If no field values of the given \a type are available.
4821  */
4822 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4823 {
4824   MCAuto<MEDFileMesh> mm;
4825   if(mName.empty())
4826     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4827   else
4828     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4829   int absDim=getDimension();
4830   int meshDimRelToMax=absDim-mm->getMeshDimension();
4831   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4832 }
4833
4834 /*!
4835  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4836  *  \param [in] type - a spatial discretization of the new field.
4837  *  \param [in] renumPol - specifies how to permute values of the result field according to
4838  *          the optional numbers of cells and nodes, if any. The valid values are
4839  *          - 0 - do not permute.
4840  *          - 1 - permute cells.
4841  *          - 2 - permute nodes.
4842  *          - 3 - permute cells and nodes.
4843  *
4844  *  \param [in] glob - the global data storing profiles and localization.
4845  *  \param [in] mesh - the supporting mesh.
4846  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4847  *         field according to \a renumPol.
4848  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4849  *         field according to \a renumPol.
4850  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4851  *          caller is to delete this field using decrRef() as it is no more needed. 
4852  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4853  *  \throw If no field of \a this is lying on \a mesh.
4854  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4855  */
4856 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
4857 {
4858   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4859   int meshId=getMeshIdFromMeshName(mesh->getName());
4860   bool isPfl=false;
4861   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4862   switch(renumPol)
4863   {
4864     case 0:
4865       {
4866         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4867         return ret.retn();
4868       }
4869     case 3:
4870     case 1:
4871       {
4872         if(isPfl)
4873           throw INTERP_KERNEL::Exception(msg1);
4874         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4875         if(cellRenum)
4876           {
4877             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4878               {
4879                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4880                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4881                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4882               }
4883             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4884             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4885             std::vector<DataArray *> arrOut2(1,arrOut);
4886             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4887             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4888             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4889           }
4890         if(renumPol==1)
4891           return ret.retn();
4892       }
4893     case 2:
4894       {
4895         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4896         if(isPfl)
4897           throw INTERP_KERNEL::Exception(msg1);
4898         if(nodeRenum)
4899           {
4900             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4901               {
4902                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4903                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4904                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4905               }
4906             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4907             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4908               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4909             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4910           }
4911         return ret.retn();
4912       }
4913     default:
4914       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4915   }
4916 }
4917
4918 /*!
4919  * Returns values and a profile of the field of a given type lying on a given support.
4920  *  \param [in] type - a spatial discretization of the field.
4921  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4922  *  \param [in] mesh - the supporting mesh.
4923  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4924  *          field of interest lies on. If the field lies on all entities of the given
4925  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4926  *          using decrRef() as it is no more needed.  
4927  *  \param [in] glob - the global data storing profiles and localization.
4928  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4929  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4930  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4931  *  \throw If no field of \a this is lying on \a mesh.
4932  *  \throw If no field values of the given \a type are available.
4933  */
4934 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4935 {
4936   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4937   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4938   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4939   ret->setName(nasc.getName().c_str());
4940   return ret.retn();
4941 }
4942
4943 //= MEDFileField1TSWithoutSDA
4944
4945 /*!
4946  * Throws if a given value is not a valid (non-extended) relative dimension.
4947  *  \param [in] meshDimRelToMax - the relative dimension value.
4948  *  \throw If \a meshDimRelToMax > 0.
4949  */
4950 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4951 {
4952   if(meshDimRelToMax>0)
4953     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4954 }
4955
4956 /*!
4957  * Checks if elements of a given mesh are in the order suitable for writing 
4958  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4959  * vector describing types of elements and their number.
4960  *  \param [in] mesh - the mesh to check.
4961  *  \return std::vector<int> - a vector holding for each element type (1) item of
4962  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4963  *          These values are in full-interlace mode.
4964  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4965  */
4966 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4967 {
4968   if(!mesh)
4969     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4970   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4971   int nbOfTypes=geoTypes.size();
4972   std::vector<int> code(3*nbOfTypes);
4973   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
4974   arr1->alloc(nbOfTypes,1);
4975   int *arrPtr=arr1->getPointer();
4976   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4977   for(int i=0;i<nbOfTypes;i++,it++)
4978     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4979   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4980   const int *arrPtr2=arr2->getConstPointer();
4981   int i=0;
4982   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4983     {
4984       int pos=arrPtr2[i];
4985       int nbCells=mesh->getNumberOfCellsWithType(*it);
4986       code[3*pos]=(int)(*it);
4987       code[3*pos+1]=nbCells;
4988       code[3*pos+2]=-1;//no profiles
4989     }
4990   std::vector<const DataArrayInt *> idsPerType;//no profiles
4991   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4992   if(da)
4993     {
4994       da->decrRef();
4995       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4996     }
4997   return code;
4998 }
4999
5000 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5001 {
5002   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5003 }
5004
5005 /*!
5006  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5007  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5008  * item of every of returned sequences refers to the _i_-th part of \a this field.
5009  * Thus all sequences returned by this method are of the same length equal to number
5010  * of different types of supporting entities.<br>
5011  * A field part can include sub-parts with several different spatial discretizations,
5012  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5013  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5014  * of a nested sequence corresponds to a type of spatial discretization.<br>
5015  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5016  * The overhead is due to selecting values into new instances of DataArrayDouble.
5017  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5018  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5019  *          not checked if \a mname == \c NULL).
5020  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5021  *          a field part is returned. 
5022  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5023  *          A field part can include sub-parts with several different spatial discretizations,
5024  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5025  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5026  *          This sequence is of the same length as \a types. 
5027  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5028  *          discretization. A profile name can be empty.
5029  *          Length of this and of nested sequences is the same as that of \a typesF.
5030  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5031  *          discretization. A localization name can be empty.
5032  *          Length of this and of nested sequences is the same as that of \a typesF.
5033  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5034  *          per each type of spatial discretization within one mesh entity type.
5035  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5036  *          Length of this and of nested sequences is the same as that of \a typesF.
5037  *  \throw If no field is lying on \a mname.
5038  */
5039 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
5040 {
5041   int meshId=0;
5042   if(!mname.empty())
5043     meshId=getMeshIdFromMeshName(mname);
5044   else
5045     if(_field_per_mesh.empty())
5046       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5047   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5048   int nbOfRet=ret0.size();
5049   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5050   for(int i=0;i<nbOfRet;i++)
5051     {
5052       const std::vector< std::pair<int,int> >& p=ret0[i];
5053       int nbOfRet1=p.size();
5054       ret[i].resize(nbOfRet1);
5055       for(int j=0;j<nbOfRet1;j++)
5056         {
5057           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5058           ret[i][j]=tmp;
5059         }
5060     }
5061   return ret;
5062 }
5063
5064 /*!
5065  * Returns a pointer to the underground DataArrayDouble instance. So the
5066  * caller should not decrRef() it. This method allows for a direct access to the field
5067  * values. This method is quite unusable if there is more than a nodal field or a cell
5068  * field on single geometric cell type. 
5069  *  \return DataArrayDouble * - the pointer to the field values array.
5070  */
5071 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
5072 {
5073   const DataArrayDouble *ret=_arr;
5074   if(ret)
5075     return const_cast<DataArrayDouble *>(ret);
5076   else
5077     return 0;
5078 }
5079
5080 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5081 {
5082   return TYPE_STR;
5083 }
5084
5085 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5086 {
5087   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5088   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5089   ret->deepCpyLeavesFrom(*this);
5090   const DataArrayDouble *arr(_arr);
5091   if(arr)
5092     {
5093       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5094       ret->setArray(arr2);
5095     }
5096   return ret.retn();
5097 }
5098
5099 /*!
5100  * Returns a pointer to the underground DataArrayDouble instance. So the
5101  * caller should not decrRef() it. This method allows for a direct access to the field
5102  * values. This method is quite unusable if there is more than a nodal field or a cell
5103  * field on single geometric cell type. 
5104  *  \return DataArrayDouble * - the pointer to the field values array.
5105  */
5106 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
5107 {
5108   return getUndergroundDataArrayDouble();
5109 }
5110
5111 /*!
5112  * Returns a pointer to the underground DataArrayDouble instance and a
5113  * sequence describing parameters of a support of each part of \a this field. The
5114  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5115  * direct access to the field values. This method is intended for the field lying on one
5116  * mesh only.
5117  *  \param [in,out] entries - the sequence describing parameters of a support of each
5118  *         part of \a this field. Each item of this sequence consists of two parts. The
5119  *         first part describes a type of mesh entity and an id of discretization of a
5120  *         current field part. The second part describes a range of values [begin,end)
5121  *         within the returned array relating to the current field part.
5122  *  \return DataArrayDouble * - the pointer to the field values array.
5123  *  \throw If the number of underlying meshes is not equal to 1.
5124  *  \throw If no field values are available.
5125  *  \sa getUndergroundDataArray()
5126  */
5127 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5128 {
5129   if(_field_per_mesh.size()!=1)
5130     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5131   if(_field_per_mesh[0]==0)
5132     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5133   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5134   return getUndergroundDataArrayDouble();
5135 }
5136
5137 /*!
5138  * Returns a pointer to the underground DataArrayDouble instance and a
5139  * sequence describing parameters of a support of each part of \a this field. The
5140  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5141  * direct access to the field values. This method is intended for the field lying on one
5142  * mesh only.
5143  *  \param [in,out] entries - the sequence describing parameters of a support of each
5144  *         part of \a this field. Each item of this sequence consists of two parts. The
5145  *         first part describes a type of mesh entity and an id of discretization of a
5146  *         current field part. The second part describes a range of values [begin,end)
5147  *         within the returned array relating to the current field part.
5148  *  \return DataArrayDouble * - the pointer to the field values array.
5149  *  \throw If the number of underlying meshes is not equal to 1.
5150  *  \throw If no field values are available.
5151  *  \sa getUndergroundDataArray()
5152  */
5153 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5154 {
5155   return getUndergroundDataArrayDoubleExt(entries);
5156 }
5157
5158 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5159 {
5160   DataArrayDouble *arr(getOrCreateAndGetArrayDouble());
5161   arr->setInfoAndChangeNbOfCompo(infos);
5162 }
5163
5164 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5165 {
5166 }
5167
5168 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5169 {
5170   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5171   ret->deepCpyLeavesFrom(*this);
5172   return ret.retn();
5173 }
5174
5175 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5176 {
5177   MCAuto<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5178   if((const DataArrayDouble *)_arr)
5179     ret->_arr=_arr->deepCopy();
5180   return ret.retn();
5181 }
5182
5183 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
5184 {
5185   if(!arr)
5186     {
5187       _nb_of_tuples_to_be_allocated=-1;
5188       _arr=0;
5189       return ;
5190     }
5191   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
5192   if(!arrC)
5193     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
5194   else
5195     _nb_of_tuples_to_be_allocated=-3;
5196   arrC->incrRef();
5197   _arr=arrC;
5198 }
5199
5200 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5201 {
5202   return DataArrayDouble::New();
5203 }
5204
5205 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
5206 {
5207   DataArrayDouble *ret=_arr;
5208   if(ret)
5209     return ret;
5210   _arr=DataArrayDouble::New();
5211   return _arr;
5212 }
5213
5214 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
5215 {
5216   return getOrCreateAndGetArrayDouble();
5217 }
5218
5219 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
5220 {
5221   const DataArrayDouble *ret=_arr;
5222   if(ret)
5223     return ret;
5224   DataArrayDouble *ret2=DataArrayDouble::New();
5225   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
5226   return ret2;
5227 }
5228
5229 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
5230 {
5231   return getOrCreateAndGetArrayDouble();
5232 }
5233
5234 //= MEDFileIntField1TSWithoutSDA
5235
5236 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5237 {
5238   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5239 }
5240
5241 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5242 {
5243 }
5244
5245 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5246                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5247 {
5248   DataArrayInt *arr(getOrCreateAndGetArrayInt());
5249   arr->setInfoAndChangeNbOfCompo(infos);
5250 }
5251
5252 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5253 {
5254   return TYPE_STR;
5255 }
5256
5257 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5258 {
5259   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5260   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5261   ret->deepCpyLeavesFrom(*this);
5262   const DataArrayInt *arr(_arr);
5263   if(arr)
5264     {
5265       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5266       ret->setArray(arr2);
5267     }
5268   return ret.retn();
5269 }
5270
5271 /*!
5272  * Returns a pointer to the underground DataArrayInt instance. So the
5273  * caller should not decrRef() it. This method allows for a direct access to the field
5274  * values. This method is quite unusable if there is more than a nodal field or a cell
5275  * field on single geometric cell type. 
5276  *  \return DataArrayInt * - the pointer to the field values array.
5277  */
5278 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
5279 {
5280   return getUndergroundDataArrayInt();
5281 }
5282
5283 /*!
5284  * Returns a pointer to the underground DataArrayInt instance. So the
5285  * caller should not decrRef() it. This method allows for a direct access to the field
5286  * values. This method is quite unusable if there is more than a nodal field or a cell
5287  * field on single geometric cell type. 
5288  *  \return DataArrayInt * - the pointer to the field values array.
5289  */
5290 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5291 {
5292   const DataArrayInt *ret=_arr;
5293   if(ret)
5294     return const_cast<DataArrayInt *>(ret);
5295   else
5296     return 0;
5297 }
5298
5299 /*!
5300  * Returns a pointer to the underground DataArrayInt instance and a
5301  * sequence describing parameters of a support of each part of \a this field. The
5302  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5303  * direct access to the field values. This method is intended for the field lying on one
5304  * mesh only.
5305  *  \param [in,out] entries - the sequence describing parameters of a support of each
5306  *         part of \a this field. Each item of this sequence consists of two parts. The
5307  *         first part describes a type of mesh entity and an id of discretization of a
5308  *         current field part. The second part describes a range of values [begin,end)
5309  *         within the returned array relating to the current field part.
5310  *  \return DataArrayInt * - the pointer to the field values array.
5311  *  \throw If the number of underlying meshes is not equal to 1.
5312  *  \throw If no field values are available.
5313  *  \sa getUndergroundDataArray()
5314  */
5315 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5316 {
5317   return getUndergroundDataArrayIntExt(entries);
5318 }
5319
5320 /*!
5321  * Returns a pointer to the underground DataArrayInt instance and a
5322  * sequence describing parameters of a support of each part of \a this field. The
5323  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5324  * direct access to the field values. This method is intended for the field lying on one
5325  * mesh only.
5326  *  \param [in,out] entries - the sequence describing parameters of a support of each
5327  *         part of \a this field. Each item of this sequence consists of two parts. The
5328  *         first part describes a type of mesh entity and an id of discretization of a
5329  *         current field part. The second part describes a range of values [begin,end)
5330  *         within the returned array relating to the current field part.
5331  *  \return DataArrayInt * - the pointer to the field values array.
5332  *  \throw If the number of underlying meshes is not equal to 1.
5333  *  \throw If no field values are available.
5334  *  \sa getUndergroundDataArray()
5335  */
5336 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5337 {
5338   if(_field_per_mesh.size()!=1)
5339     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5340   if(_field_per_mesh[0]==0)
5341     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5342   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5343   return getUndergroundDataArrayInt();
5344 }
5345
5346 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5347 {
5348   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5349   ret->deepCpyLeavesFrom(*this);
5350   return ret.retn();
5351 }
5352
5353 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5354 {
5355   MCAuto<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5356   if((const DataArrayInt *)_arr)
5357     ret->_arr=_arr->deepCopy();
5358   return ret.retn();
5359 }
5360
5361 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5362 {
5363   if(!arr)
5364     {
5365       _nb_of_tuples_to_be_allocated=-1;
5366       _arr=0;
5367       return ;
5368     }
5369   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5370   if(!arrC)
5371     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5372   else
5373     _nb_of_tuples_to_be_allocated=-3;
5374   arrC->incrRef();
5375   _arr=arrC;
5376 }
5377
5378 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5379 {
5380   return DataArrayInt::New();
5381 }
5382
5383 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5384 {
5385   DataArrayInt *ret=_arr;
5386   if(ret)
5387     return ret;
5388   _arr=DataArrayInt::New();
5389   return _arr;
5390 }
5391
5392 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5393 {
5394   return getOrCreateAndGetArrayInt();
5395 }
5396
5397 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5398 {
5399   const DataArrayInt *ret=_arr;
5400   if(ret)
5401     return ret;
5402   DataArrayInt *ret2=DataArrayInt::New();
5403   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5404   return ret2;
5405 }
5406
5407 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5408 {
5409   return getOrCreateAndGetArrayInt();
5410 }
5411
5412 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5413 {
5414 }
5415
5416 //= MEDFileAnyTypeField1TS
5417
5418 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5419 {
5420   med_field_type typcha;
5421   //
5422   std::vector<std::string> infos;
5423   std::string dtunit,fieldName;
5424   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5425   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5426   switch(typcha)
5427   {
5428     case MED_FLOAT64:
5429       {
5430         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5431         break;
5432       }
5433     case MED_INT32:
5434       {
5435         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5436         break;
5437       }
5438     default:
5439       {
5440         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] !";
5441         throw INTERP_KERNEL::Exception(oss.str().c_str());
5442       }
5443   }
5444   ret->setDtUnit(dtunit.c_str());
5445   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5446   //
5447   med_int numdt,numit;
5448   med_float dt;
5449   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5450   ret->setTime(numdt,numit,dt);
5451   ret->_csit=1;
5452   if(loadAll)
5453     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5454   else
5455     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5456   return ret.retn();
5457 }
5458
5459 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5460 try:MEDFileFieldGlobsReal(fileName)
5461 {
5462   MEDFileUtilities::CheckFileForRead(fileName);
5463   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5464   _content=BuildContentFrom(fid,fileName,loadAll,ms);
5465   loadGlobals(fid);
5466 }
5467 catch(INTERP_KERNEL::Exception& e)
5468 {
5469     throw e;
5470 }
5471
5472 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5473 {
5474   med_field_type typcha;
5475   std::vector<std::string> infos;
5476   std::string dtunit;
5477   int iii=-1;
5478   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5479   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5480   switch(typcha)
5481   {
5482     case MED_FLOAT64:
5483       {
5484         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5485         break;
5486       }
5487     case MED_INT32:
5488       {
5489         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5490         break;
5491       }
5492     default:
5493       {
5494         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] !";
5495         throw INTERP_KERNEL::Exception(oss.str().c_str());
5496       }
5497   }
5498   ret->setDtUnit(dtunit.c_str());
5499   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5500   //
5501   if(nbSteps<1)
5502     {
5503       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5504       throw INTERP_KERNEL::Exception(oss.str().c_str());
5505     }
5506   //
5507   med_int numdt,numit;
5508   med_float dt;
5509   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5510   ret->setTime(numdt,numit,dt);
5511   ret->_csit=1;
5512   if(loadAll)
5513     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5514   else
5515     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5516   return ret.retn();
5517 }
5518
5519 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5520 try:MEDFileFieldGlobsReal(fileName)
5521 {
5522   MEDFileUtilities::CheckFileForRead(fileName);
5523   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5524   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
5525   loadGlobals(fid);
5526 }
5527 catch(INTERP_KERNEL::Exception& e)
5528 {
5529     throw e;
5530 }
5531
5532 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5533 {
5534   if(!c)
5535     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5536   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5537     {
5538       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New();
5539       ret->setFileName(fileName);
5540       ret->_content=c; c->incrRef();
5541       return ret.retn();
5542     }
5543   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5544     {
5545       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5546       ret->setFileName(fileName);
5547       ret->_content=c; c->incrRef();
5548       return ret.retn();
5549     }
5550   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5551 }
5552
5553 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5554 {
5555   MEDFileUtilities::CheckFileForRead(fileName);
5556   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5557   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
5558   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5559   ret->loadGlobals(fid);
5560   return ret.retn();
5561 }
5562
5563 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5564 {
5565   MEDFileUtilities::CheckFileForRead(fileName);
5566   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5567   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
5568   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5569   ret->loadGlobals(fid);
5570   return ret.retn();
5571 }
5572
5573 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5574 {
5575   MEDFileUtilities::CheckFileForRead(fileName);
5576   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5577   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll,0);
5578   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5579   ret->loadGlobals(fid);
5580   return ret.retn();
5581 }
5582
5583 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5584 {
5585   med_field_type typcha;
5586   std::vector<std::string> infos;
5587   std::string dtunit;
5588   int iii=-1;
5589   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5590   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5591   switch(typcha)
5592   {
5593     case MED_FLOAT64:
5594       {
5595         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5596         break;
5597       }
5598     case MED_INT32:
5599       {
5600         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5601         break;
5602       }
5603     default:
5604       {
5605         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] !";
5606         throw INTERP_KERNEL::Exception(oss.str().c_str());
5607       }
5608   }
5609   ret->setDtUnit(dtunit.c_str());
5610   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5611   //
5612   bool found=false;
5613   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5614   for(int i=0;i<nbOfStep2 && !found;i++)
5615     {
5616       med_int numdt,numit;
5617       med_float dt;
5618       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5619       if(numdt==iteration && numit==order)
5620         {
5621           found=true;
5622           ret->_csit=i+1;
5623         }
5624       else
5625         dtits[i]=std::pair<int,int>(numdt,numit);
5626     }
5627   if(!found)
5628     {
5629       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5630       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5631         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5632       throw INTERP_KERNEL::Exception(oss.str().c_str());
5633     }
5634   if(loadAll)
5635     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5636   else
5637     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5638   return ret.retn();
5639 }
5640
5641 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5642 try:MEDFileFieldGlobsReal(fileName)
5643 {
5644   MEDFileUtilities::CheckFileForRead(fileName);
5645   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5646   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll,ms);
5647   loadGlobals(fid);
5648 }
5649 catch(INTERP_KERNEL::Exception& e)
5650 {
5651     throw e;
5652 }
5653
5654 /*!
5655  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5656  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5657  *
5658  * \warning this is a shallow copy constructor
5659  */
5660 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5661 {
5662   if(!shallowCopyOfContent)
5663     {
5664       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5665       otherPtr->incrRef();
5666       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5667     }
5668   else
5669     {
5670       _content=other.shallowCpy();
5671     }
5672 }
5673
5674 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)
5675 {
5676   if(checkFieldId)
5677     {
5678       int nbFields=MEDnField(fid);
5679       if(fieldIdCFormat>=nbFields)
5680         {
5681           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5682           throw INTERP_KERNEL::Exception(oss.str().c_str());
5683         }
5684     }
5685   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5686   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5687   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5688   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5689   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5690   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5691   med_bool localMesh;
5692   int nbOfStep;
5693   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5694   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5695   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5696   infos.clear(); infos.resize(ncomp);
5697   for(int j=0;j<ncomp;j++)
5698     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5699   return nbOfStep;
5700 }
5701
5702 /*!
5703  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5704  * 
5705  * \param [out]
5706  * \return in case of success the number of time steps available for the field with name \a fieldName.
5707  */
5708 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)
5709 {
5710   int nbFields=MEDnField(fid);
5711   bool found=false;
5712   std::vector<std::string> fns(nbFields);
5713   int nbOfStep2=-1;
5714   for(int i=0;i<nbFields && !found;i++)
5715     {
5716       std::string tmp;
5717       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5718       fns[i]=tmp;
5719       found=(tmp==fieldName);
5720       if(found)
5721         posCFormat=i;
5722     }
5723   if(!found)
5724     {
5725       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5726       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5727         oss << "\"" << *it << "\" ";
5728       throw INTERP_KERNEL::Exception(oss.str().c_str());
5729     }
5730   return nbOfStep2;
5731 }
5732
5733 /*!
5734  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5735  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5736  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5737  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5738  * to keep a valid instance.
5739  * 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.
5740  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5741  * 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.
5742  *
5743  * \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.
5744  * \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.
5745  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5746  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5747  * \param [in] newLocName is the new localization name.
5748  * \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.
5749  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5750  */
5751 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5752 {
5753   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5754   std::string oldPflName=disc->getProfile();
5755   std::vector<std::string> vv=getPflsReallyUsedMulti();
5756   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5757   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5758     {
5759       disc->setProfile(newPflName);
5760       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5761       pfl->setName(newPflName);
5762     }
5763   else
5764     {
5765       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5766       throw INTERP_KERNEL::Exception(oss.str().c_str());
5767     }
5768 }
5769
5770 /*!
5771  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5772  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5773  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5774  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5775  * to keep a valid instance.
5776  * 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.
5777  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5778  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5779  * 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.
5780  *
5781  * \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.
5782  * \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.
5783  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5784  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5785  * \param [in] newLocName is the new localization name.
5786  * \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.
5787  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5788  */
5789 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5790 {
5791   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5792   std::string oldLocName=disc->getLocalization();
5793   std::vector<std::string> vv=getLocsReallyUsedMulti();
5794   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5795   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5796     {
5797       disc->setLocalization(newLocName);
5798       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5799       loc.setName(newLocName);
5800     }
5801   else
5802     {
5803       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5804       throw INTERP_KERNEL::Exception(oss.str().c_str());
5805     }
5806 }
5807
5808 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5809 {
5810   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5811   if(!ret)
5812     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5813   return ret;
5814 }
5815
5816 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5817 {
5818   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5819   if(!ret)
5820     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5821   return ret;
5822 }
5823
5824 /*!
5825  * Writes \a this field into a MED file specified by its name.
5826  *  \param [in] fileName - the MED file name.
5827  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5828  * - 2 - erase; an existing file is removed.
5829  * - 1 - append; same data should not be present in an existing file.
5830  * - 0 - overwrite; same data present in an existing file is overwritten.
5831  *  \throw If the field name is not set.
5832  *  \throw If no field data is set.
5833  *  \throw If \a mode == 1 and the same data is present in an existing file.
5834  */
5835 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5836 {
5837   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5838   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5839   writeLL(fid);
5840 }
5841
5842 /*!
5843  * This method alloc the arrays and load potentially huge arrays contained in this field.
5844  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5845  * This method can be also called to refresh or reinit values from a file.
5846  * 
5847  * \throw If the fileName is not set or points to a non readable MED file.
5848  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5849  */
5850 void MEDFileAnyTypeField1TS::loadArrays()
5851 {
5852   if(getFileName().empty())
5853     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5854   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5855   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5856 }
5857
5858 /*!
5859  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5860  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5861  * this method does not throw if \a this does not come from file read.
5862  * 
5863  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5864  */
5865 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5866 {
5867   if(!getFileName().empty())
5868     {
5869       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5870       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5871     }
5872 }
5873
5874 /*!
5875  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5876  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5877  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5878  * 
5879  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5880  */
5881 void MEDFileAnyTypeField1TS::unloadArrays()
5882 {
5883   contentNotNullBase()->unloadArrays();
5884 }
5885
5886 /*!
5887  * 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.
5888  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5889  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5890  * 
5891  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5892  */
5893 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5894 {
5895   if(!getFileName().empty())
5896     contentNotNullBase()->unloadArrays();
5897 }
5898
5899 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5900 {
5901   int nbComp=getNumberOfComponents();
5902   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5903   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5904   for(int i=0;i<nbComp;i++)
5905     {
5906       std::string info=getInfo()[i];
5907       std::string c,u;
5908       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5909       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5910       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5911     }
5912   if(getName().empty())
5913     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5914   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
5915   writeGlobals(fid,*this);
5916   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5917 }
5918
5919 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5920 {
5921   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5922 }
5923
5924 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5925 {
5926   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5927   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5928   return ret;
5929 }
5930
5931 /*!
5932  * Returns a string describing \a this field. This string is outputted 
5933  * by \c print Python command.
5934  */
5935 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5936 {
5937   std::ostringstream oss;
5938   contentNotNullBase()->simpleRepr(0,oss,-1);
5939   simpleReprGlobs(oss);
5940   return oss.str();
5941 }
5942
5943 /*!
5944  * This method returns all profiles whose name is non empty used.
5945  * \b WARNING If profile is used several times it will be reported \b only \b once.
5946  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5947  */
5948 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5949 {
5950   return contentNotNullBase()->getPflsReallyUsed2();
5951 }
5952
5953 /*!
5954  * This method returns all localizations whose name is non empty used.
5955  * \b WARNING If localization is used several times it will be reported \b only \b once.
5956  */
5957 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5958 {
5959   return contentNotNullBase()->getLocsReallyUsed2();
5960 }
5961
5962 /*!
5963  * This method returns all profiles whose name is non empty used.
5964  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5965  */
5966 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5967 {
5968   return contentNotNullBase()->getPflsReallyUsedMulti2();
5969 }
5970
5971 /*!
5972  * This method returns all localizations whose name is non empty used.
5973  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5974  */
5975 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5976 {
5977   return contentNotNullBase()->getLocsReallyUsedMulti2();
5978 }
5979
5980 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5981 {
5982   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5983 }
5984
5985 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5986 {
5987   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5988 }
5989
5990 int MEDFileAnyTypeField1TS::getDimension() const
5991 {
5992   return contentNotNullBase()->getDimension();
5993 }
5994
5995 int MEDFileAnyTypeField1TS::getIteration() const
5996 {
5997   return contentNotNullBase()->getIteration();
5998 }
5999
6000 int MEDFileAnyTypeField1TS::getOrder() const
6001 {
6002   return contentNotNullBase()->getOrder();
6003 }
6004
6005 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6006 {
6007   return contentNotNullBase()->getTime(iteration,order);
6008 }
6009
6010 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6011 {
6012   contentNotNullBase()->setTime(iteration,order,val);
6013 }
6014
6015 std::string MEDFileAnyTypeField1TS::getName() const
6016 {
6017   return contentNotNullBase()->getName();
6018 }
6019
6020 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6021 {
6022   contentNotNullBase()->setName(name);
6023 }
6024
6025 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6026 {
6027   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6028 }
6029
6030 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6031 {
6032   return contentNotNullBase()->getDtUnit();
6033 }
6034
6035 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6036 {
6037   contentNotNullBase()->setDtUnit(dtUnit);
6038 }
6039
6040 std::string MEDFileAnyTypeField1TS::getMeshName() const
6041 {
6042   return contentNotNullBase()->getMeshName();
6043 }
6044
6045 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6046 {
6047   contentNotNullBase()->setMeshName(newMeshName);
6048 }
6049
6050 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6051 {
6052   return contentNotNullBase()->changeMeshNames(modifTab);
6053 }
6054
6055 int MEDFileAnyTypeField1TS::getMeshIteration() const
6056 {
6057   return contentNotNullBase()->getMeshIteration();
6058 }
6059
6060 int MEDFileAnyTypeField1TS::getMeshOrder() const
6061 {
6062   return contentNotNullBase()->getMeshOrder();
6063 }
6064
6065 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6066 {
6067   return contentNotNullBase()->getNumberOfComponents();
6068 }
6069
6070 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6071 {
6072   return contentNotNullBase()->isDealingTS(iteration,order);
6073 }
6074
6075 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6076 {
6077   return contentNotNullBase()->getDtIt();
6078 }
6079
6080 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6081 {
6082   contentNotNullBase()->fillIteration(p);
6083 }
6084
6085 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6086 {
6087   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6088 }
6089
6090 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6091 {
6092   contentNotNullBase()->setInfo(infos);
6093 }
6094
6095 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6096 {
6097   return contentNotNullBase()->getInfo();
6098 }
6099 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6100 {
6101   return contentNotNullBase()->getInfo();
6102 }
6103
6104 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6105 {
6106   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6107 }
6108
6109 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6110 {
6111   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6112 }
6113
6114 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6115 {
6116   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6117 }
6118
6119 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6120 {
6121   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6122 }
6123
6124 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6125 {
6126   return contentNotNullBase()->getTypesOfFieldAvailable();
6127 }
6128
6129 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,
6130                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6131 {
6132   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6133 }
6134
6135 /*!
6136  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6137  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6138  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6139  */
6140 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6141 {
6142   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6143   if(!content)
6144     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6145   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6146   std::size_t sz(contentsSplit.size());
6147   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6148   for(std::size_t i=0;i<sz;i++)
6149     {
6150       ret[i]=shallowCpy();
6151       ret[i]->_content=contentsSplit[i];
6152     }
6153   return ret;
6154 }
6155
6156 /*!
6157  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6158  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6159  */
6160 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6161 {
6162   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6163   if(!content)
6164     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6165   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6166   std::size_t sz(contentsSplit.size());
6167   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6168   for(std::size_t i=0;i<sz;i++)
6169     {
6170       ret[i]=shallowCpy();
6171       ret[i]->_content=contentsSplit[i];
6172     }
6173   return ret;
6174 }
6175
6176 /*!
6177  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6178  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6179  */
6180 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6181 {
6182   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6183   if(!content)
6184     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6185   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6186   std::size_t sz(contentsSplit.size());
6187   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6188   for(std::size_t i=0;i<sz;i++)
6189     {
6190       ret[i]=shallowCpy();
6191       ret[i]->_content=contentsSplit[i];
6192     }
6193   return ret;
6194 }
6195
6196 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6197 {
6198   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6199   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6200     ret->_content=_content->deepCopy();
6201   ret->deepCpyGlobs(*this);
6202   return ret.retn();
6203 }
6204
6205 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6206 {
6207   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6208 }
6209
6210 //= MEDFileField1TS
6211
6212 /*!
6213  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6214  * the first field that has been read from a specified MED file.
6215  *  \param [in] fileName - the name of the MED file to read.
6216  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6217  *          is to delete this field using decrRef() as it is no more needed.
6218  *  \throw If reading the file fails.
6219  */
6220 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6221 {
6222   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,loadAll,0));
6223   ret->contentNotNull();
6224   return ret.retn();
6225 }
6226
6227 /*!
6228  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6229  * a given field that has been read from a specified MED file.
6230  *  \param [in] fileName - the name of the MED file to read.
6231  *  \param [in] fieldName - the name of the field to read.
6232  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6233  *          is to delete this field using decrRef() as it is no more needed.
6234  *  \throw If reading the file fails.
6235  *  \throw If there is no field named \a fieldName in the file.
6236  */
6237 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6238 {
6239   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,loadAll,0));
6240   ret->contentNotNull();
6241   return ret.retn();
6242 }
6243
6244 /*!
6245  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6246  * a given field that has been read from a specified MED file.
6247  *  \param [in] fileName - the name of the MED file to read.
6248  *  \param [in] fieldName - the name of the field to read.
6249  *  \param [in] iteration - the iteration number of a required time step.
6250  *  \param [in] order - the iteration order number of required time step.
6251  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6252  *          is to delete this field using decrRef() as it is no more needed.
6253  *  \throw If reading the file fails.
6254  *  \throw If there is no field named \a fieldName in the file.
6255  *  \throw If the required time step is missing from the file.
6256  */
6257 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6258 {
6259   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll,0));
6260   ret->contentNotNull();
6261   return ret.retn();
6262 }
6263
6264 /*!
6265  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6266  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6267  *
6268  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6269  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6270  * \warning this is a shallow copy constructor
6271  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6272  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6273  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6274  *          is to delete this field using decrRef() as it is no more needed.
6275  */
6276 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6277 {
6278   MCAuto<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
6279   ret->contentNotNull();
6280   return ret.retn();
6281 }
6282
6283 /*!
6284  * Returns a new empty instance of MEDFileField1TS.
6285  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6286  *          is to delete this field using decrRef() as it is no more needed.
6287  */
6288 MEDFileField1TS *MEDFileField1TS::New()
6289 {
6290   MCAuto<MEDFileField1TS> ret=new MEDFileField1TS;
6291   ret->contentNotNull();
6292   return ret.retn();
6293 }
6294
6295 /*!
6296  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6297  * following the given input policy.
6298  *
6299  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6300  *                            By default (true) the globals are deeply copied.
6301  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6302  */
6303 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6304 {
6305   MCAuto<MEDFileIntField1TS> ret;
6306   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6307   if(content)
6308     {
6309       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6310       if(!contc)
6311         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6312       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6313       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6314     }
6315   else
6316     ret=MEDFileIntField1TS::New();
6317   if(isDeepCpyGlobs)
6318     ret->deepCpyGlobs(*this);
6319   else
6320     ret->shallowCpyGlobs(*this);
6321   return ret.retn();
6322 }
6323
6324 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6325 {
6326   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6327   if(!pt)
6328     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6329   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6330   if(!ret)
6331     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 !");
6332   return ret;
6333 }
6334
6335 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6336 {
6337   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6338   if(!pt)
6339     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6340   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6341   if(!ret)
6342     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 !");
6343   return ret;
6344 }
6345
6346 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6347 {
6348   if(!f)
6349     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6350   if(!((DataArray*)arr))
6351     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6352   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6353   if(!arrOutC)
6354     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6355   f->setArray(arrOutC);
6356 }
6357
6358 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6359 {
6360   if(!((DataArray*)arr))
6361     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6362   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6363   if(!arrOutC)
6364     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6365   arrOutC->incrRef();
6366   return arrOutC;
6367 }
6368
6369 /*!
6370  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6371  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6372  *
6373  * \return A new object that the caller is responsible to deallocate.
6374  */
6375 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6376 {
6377   if(!mm)
6378     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6379   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6380   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6381   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6382     {
6383       if((*it0)!=ON_NODES)
6384         {
6385           std::vector<int> levs;
6386           getNonEmptyLevels(mm->getName(),levs);
6387           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6388             {
6389               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6390               if(it2!=extractDef.end())
6391                 {
6392                   MCAuto<DataArrayInt> t((*it2).second);
6393                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6394                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6395                   ret->setFieldNoProfileSBT(fOut);
6396                 }
6397             }
6398         }
6399       else
6400         {
6401           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6402           if(it2==extractDef.end())
6403             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6404           MCAuto<DataArrayInt> t((*it2).second);
6405           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6406           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6407           DataArrayDouble *arr(f->getArray());
6408           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6409           fOut->setArray(newArr);
6410           ret->setFieldNoProfileSBT(fOut);
6411         }
6412     }
6413   return ret.retn();
6414 }
6415
6416 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6417 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6418 {
6419 }
6420 catch(INTERP_KERNEL::Exception& e)
6421 { throw e; }
6422
6423 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6424 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6425 {
6426 }
6427 catch(INTERP_KERNEL::Exception& e)
6428 { throw e; }
6429
6430 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6431 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6432 {
6433 }
6434 catch(INTERP_KERNEL::Exception& e)
6435 { throw e; }
6436
6437 /*!
6438  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6439  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6440  *
6441  * \warning this is a shallow copy constructor
6442  */
6443 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6444 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6445 {
6446 }
6447 catch(INTERP_KERNEL::Exception& e)
6448 { throw e; }
6449
6450 MEDFileField1TS::MEDFileField1TS()
6451 {
6452   _content=new MEDFileField1TSWithoutSDA;
6453 }
6454
6455 /*!
6456  * Returns a new MEDCouplingFieldDouble of a given type lying on
6457  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6458  * has not been constructed via file reading, an exception is thrown.
6459  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6460  *  \param [in] type - a spatial discretization of interest.
6461  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6462  *  \param [in] renumPol - specifies how to permute values of the result field according to
6463  *          the optional numbers of cells and nodes, if any. The valid values are
6464  *          - 0 - do not permute.
6465  *          - 1 - permute cells.
6466  *          - 2 - permute nodes.
6467  *          - 3 - permute cells and nodes.
6468  *
6469  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6470  *          caller is to delete this field using decrRef() as it is no more needed. 
6471  *  \throw If \a this field has not been constructed via file reading.
6472  *  \throw If the MED file is not readable.
6473  *  \throw If there is no mesh in the MED file.
6474  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6475  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6476  *  \sa getFieldOnMeshAtLevel()
6477  */
6478 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6479 {
6480   if(getFileName().empty())
6481     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6482   MCAuto<DataArray> arrOut;
6483   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6484   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6485   return ret.retn();
6486 }
6487
6488 /*!
6489  * Returns a new MEDCouplingFieldDouble of a given type lying on
6490  * the top level cells of the first mesh in MED file. If \a this field 
6491  * has not been constructed via file reading, an exception is thrown.
6492  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6493  *  \param [in] type - a spatial discretization of interest.
6494  *  \param [in] renumPol - specifies how to permute values of the result field according to
6495  *          the optional numbers of cells and nodes, if any. The valid values are
6496  *          - 0 - do not permute.
6497  *          - 1 - permute cells.
6498  *          - 2 - permute nodes.
6499  *          - 3 - permute cells and nodes.
6500  *
6501  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6502  *          caller is to delete this field using decrRef() as it is no more needed. 
6503  *  \throw If \a this field has not been constructed via file reading.
6504  *  \throw If the MED file is not readable.
6505  *  \throw If there is no mesh in the MED file.
6506  *  \throw If no field values of the given \a type.
6507  *  \throw If no field values lying on the top level support.
6508  *  \sa getFieldAtLevel()
6509  */
6510 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6511 {
6512   if(getFileName().empty())
6513     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6514   MCAuto<DataArray> arrOut;
6515   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6516   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6517   return ret.retn();
6518 }
6519
6520 /*!
6521  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6522  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6523  *  \param [in] type - a spatial discretization of the new field.
6524  *  \param [in] mesh - the supporting mesh.
6525  *  \param [in] renumPol - specifies how to permute values of the result field according to
6526  *          the optional numbers of cells and nodes, if any. The valid values are
6527  *          - 0 - do not permute.
6528  *          - 1 - permute cells.
6529  *          - 2 - permute nodes.
6530  *          - 3 - permute cells and nodes.
6531  *
6532  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6533  *          caller is to delete this field using decrRef() as it is no more needed. 
6534  *  \throw If no field of \a this is lying on \a mesh.
6535  *  \throw If the mesh is empty.
6536  *  \throw If no field values of the given \a type are available.
6537  *  \sa getFieldAtLevel()
6538  *  \sa getFieldOnMeshAtLevel() 
6539  */
6540 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6541 {
6542   MCAuto<DataArray> arrOut;
6543   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6544   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6545   return ret.retn();
6546 }
6547
6548 /*!
6549  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6550  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6551  *  \param [in] type - a spatial discretization of interest.
6552  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6553  *  \param [in] mesh - the supporting mesh.
6554  *  \param [in] renumPol - specifies how to permute values of the result field according to
6555  *          the optional numbers of cells and nodes, if any. The valid values are
6556  *          - 0 - do not permute.
6557  *          - 1 - permute cells.
6558  *          - 2 - permute nodes.
6559  *          - 3 - permute cells and nodes.
6560  *
6561  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6562  *          caller is to delete this field using decrRef() as it is no more needed. 
6563  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6564  *  \throw If no field of \a this is lying on \a mesh.
6565  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6566  *  \sa getFieldAtLevel()
6567  *  \sa getFieldOnMeshAtLevel() 
6568  */
6569 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6570 {
6571   MCAuto<DataArray> arrOut;
6572   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6573   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6574   return ret.retn();
6575 }
6576
6577 /*!
6578  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6579  * This method is called "Old" because in MED3 norm a field has only one meshName
6580  * attached, so this method is for readers of MED2 files. If \a this field 
6581  * has not been constructed via file reading, an exception is thrown.
6582  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6583  *  \param [in] type - a spatial discretization of interest.
6584  *  \param [in] mName - a name of the supporting mesh.
6585  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6586  *  \param [in] renumPol - specifies how to permute values of the result field according to
6587  *          the optional numbers of cells and nodes, if any. The valid values are
6588  *          - 0 - do not permute.
6589  *          - 1 - permute cells.
6590  *          - 2 - permute nodes.
6591  *          - 3 - permute cells and nodes.
6592  *
6593  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6594  *          caller is to delete this field using decrRef() as it is no more needed. 
6595  *  \throw If the MED file is not readable.
6596  *  \throw If there is no mesh named \a mName in the MED file.
6597  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6598  *  \throw If \a this field has not been constructed via file reading.
6599  *  \throw If no field of \a this is lying on the mesh named \a mName.
6600  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6601  *  \sa getFieldAtLevel()
6602  */
6603 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6604 {
6605   if(getFileName().empty())
6606     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6607   MCAuto<DataArray> arrOut;
6608   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6609   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6610   return ret.retn();
6611 }
6612
6613 /*!
6614  * Returns values and a profile of the field of a given type lying on a given support.
6615  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6616  *  \param [in] type - a spatial discretization of the field.
6617  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6618  *  \param [in] mesh - the supporting mesh.
6619  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6620  *          field of interest lies on. If the field lies on all entities of the given
6621  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6622  *          using decrRef() as it is no more needed.  
6623  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6624  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6625  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6626  *  \throw If no field of \a this is lying on \a mesh.
6627  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6628  */
6629 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6630 {
6631   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6632   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6633 }
6634
6635 /*!
6636  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6637  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6638  * "Sort By Type"), if not, an exception is thrown. 
6639  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6640  *  \param [in] field - the field to add to \a this.
6641  *  \throw If the name of \a field is empty.
6642  *  \throw If the data array of \a field is not set.
6643  *  \throw If the data array is already allocated but has different number of components
6644  *         than \a field.
6645  *  \throw If the underlying mesh of \a field has no name.
6646  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6647  */
6648 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6649 {
6650   setFileName("");
6651   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6652 }
6653
6654 /*!
6655  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6656  * can be an aggregation of several MEDCouplingFieldDouble instances.
6657  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6658  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6659  * and \a profile.
6660  *
6661  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6662  * A new profile is added only if no equal profile is missing.
6663  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6664  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6665  *  \param [in] mesh - the supporting mesh of \a field.
6666  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6667  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6668  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6669  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6670  *  \throw If the data array of \a field is not set.
6671  *  \throw If the data array of \a this is already allocated but has different number of
6672  *         components than \a field.
6673  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6674  *  \sa setFieldNoProfileSBT()
6675  */
6676 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6677 {
6678   setFileName("");
6679   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6680 }
6681
6682 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6683 {
6684   return new MEDFileField1TS(*this);
6685 }
6686
6687 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6688 {
6689   return contentNotNull()->getUndergroundDataArrayDouble();
6690 }
6691
6692 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6693 {
6694   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6695 }
6696
6697 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6698                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6699 {
6700   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6701 }
6702
6703 //= MEDFileIntField1TS
6704
6705 MEDFileIntField1TS *MEDFileIntField1TS::New()
6706 {
6707   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6708   ret->contentNotNull();
6709   return ret.retn();
6710 }
6711
6712 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6713 {
6714   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6715   ret->contentNotNull();
6716   return ret.retn();
6717 }
6718
6719 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6720 {
6721   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6722   ret->contentNotNull();
6723   return ret.retn();
6724 }
6725
6726 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6727 {
6728   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6729   ret->contentNotNull();
6730   return ret.retn();
6731 }
6732
6733 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6734 {
6735   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6736   ret->contentNotNull();
6737   return ret.retn();
6738 }
6739
6740 MEDFileIntField1TS::MEDFileIntField1TS()
6741 {
6742   _content=new MEDFileIntField1TSWithoutSDA;
6743 }
6744
6745 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6746 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6747 {
6748 }
6749 catch(INTERP_KERNEL::Exception& e)
6750 { throw e; }
6751
6752 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6753 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6754 {
6755 }
6756 catch(INTERP_KERNEL::Exception& e)
6757 { throw e; }
6758
6759 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6760 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6761 {
6762 }
6763 catch(INTERP_KERNEL::Exception& e)
6764 { throw e; }
6765
6766 /*!
6767  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6768  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6769  *
6770  * \warning this is a shallow copy constructor
6771  */
6772 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6773 {
6774 }
6775
6776 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6777 {
6778   return new MEDFileIntField1TS(*this);
6779 }
6780
6781 /*!
6782  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6783  * following the given input policy.
6784  *
6785  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6786  *                            By default (true) the globals are deeply copied.
6787  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6788  */
6789 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6790 {
6791   MCAuto<MEDFileField1TS> ret;
6792   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6793   if(content)
6794     {
6795       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6796       if(!contc)
6797         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6798       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6799       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6800     }
6801   else
6802     ret=MEDFileField1TS::New();
6803   if(isDeepCpyGlobs)
6804     ret->deepCpyGlobs(*this);
6805   else
6806     ret->shallowCpyGlobs(*this);
6807   return ret.retn();
6808 }
6809
6810 /*!
6811  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6812  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6813  * "Sort By Type"), if not, an exception is thrown. 
6814  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6815  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6816  *  \param [in] arrOfVals - the values of the field \a field used.
6817  *  \throw If the name of \a field is empty.
6818  *  \throw If the data array of \a field is not set.
6819  *  \throw If the data array is already allocated but has different number of components
6820  *         than \a field.
6821  *  \throw If the underlying mesh of \a field has no name.
6822  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6823  */
6824 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6825 {
6826   setFileName("");
6827   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6828 }
6829
6830 /*!
6831  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6832  * can be an aggregation of several MEDCouplingFieldDouble instances.
6833  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6834  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6835  * and \a profile.
6836  *
6837  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6838  * A new profile is added only if no equal profile is missing.
6839  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6840  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6841  *  \param [in] arrOfVals - the values of the field \a field used.
6842  *  \param [in] mesh - the supporting mesh of \a field.
6843  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6844  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6845  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6846  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6847  *  \throw If the data array of \a field is not set.
6848  *  \throw If the data array of \a this is already allocated but has different number of
6849  *         components than \a field.
6850  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6851  *  \sa setFieldNoProfileSBT()
6852  */
6853 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6854 {
6855   setFileName("");
6856   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6857 }
6858
6859 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6860 {
6861   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6862   if(!pt)
6863     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6864   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6865   if(!ret)
6866     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 !");
6867   return ret;
6868 }
6869
6870 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6871 {
6872   if(getFileName().empty())
6873     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6874   MCAuto<DataArray> arrOut2;
6875   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6876   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6877   if(!arrOutC)
6878     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6879   arrOut=arrOutC;
6880   arrOut->incrRef();  // arrOut2 dies at the end of the func
6881   return ret.retn();
6882 }
6883
6884 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
6885 {
6886   if(!((DataArray *)arr))
6887     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6888   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6889   if(!arrC)
6890     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6891   arrC->incrRef();
6892   return arrC;
6893 }
6894
6895 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6896 {
6897   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
6898 }
6899
6900 /*!
6901  * Returns a new MEDCouplingFieldDouble of a given type lying on
6902  * the top level cells of the first mesh in MED file. If \a this field 
6903  * has not been constructed via file reading, an exception is thrown.
6904  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6905  *  \param [in] type - a spatial discretization of interest.
6906  *  \param [out] arrOut - the DataArrayInt containing values of field.
6907  *  \param [in] renumPol - specifies how to permute values of the result field according to
6908  *          the optional numbers of cells and nodes, if any. The valid values are
6909  *          - 0 - do not permute.
6910  *          - 1 - permute cells.
6911  *          - 2 - permute nodes.
6912  *          - 3 - permute cells and nodes.
6913  *
6914  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6915  *          caller is to delete this field using decrRef() as it is no more needed. 
6916  *  \throw If \a this field has not been constructed via file reading.
6917  *  \throw If the MED file is not readable.
6918  *  \throw If there is no mesh in the MED file.
6919  *  \throw If no field values of the given \a type.
6920  *  \throw If no field values lying on the top level support.
6921  *  \sa getFieldAtLevel()
6922  */
6923 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6924 {
6925   if(getFileName().empty())
6926     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6927   MCAuto<DataArray> arr;
6928   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6929   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6930   return ret.retn();
6931 }
6932
6933 /*!
6934  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6935  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6936  *  \param [in] type - a spatial discretization of the new field.
6937  *  \param [in] mesh - the supporting mesh.
6938  *  \param [out] arrOut - the DataArrayInt containing values of field.
6939  *  \param [in] renumPol - specifies how to permute values of the result field according to
6940  *          the optional numbers of cells and nodes, if any. The valid values are
6941  *          - 0 - do not permute.
6942  *          - 1 - permute cells.
6943  *          - 2 - permute nodes.
6944  *          - 3 - permute cells and nodes.
6945  *
6946  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6947  *          caller is to delete this field using decrRef() as it is no more needed. 
6948  *  \throw If no field of \a this is lying on \a mesh.
6949  *  \throw If the mesh is empty.
6950  *  \throw If no field values of the given \a type are available.
6951  *  \sa getFieldAtLevel()
6952  *  \sa getFieldOnMeshAtLevel() 
6953  */
6954 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6955 {
6956   MCAuto<DataArray> arr;
6957   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6958   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6959   return ret.retn();
6960 }
6961
6962 /*!
6963  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6964  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6965  *  \param [in] type - a spatial discretization of interest.
6966  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6967  *  \param [out] arrOut - the DataArrayInt containing values of field.
6968  *  \param [in] mesh - the supporting mesh.
6969  *  \param [in] renumPol - specifies how to permute values of the result field according to
6970  *          the optional numbers of cells and nodes, if any. The valid values are
6971  *          - 0 - do not permute.
6972  *          - 1 - permute cells.
6973  *          - 2 - permute nodes.
6974  *          - 3 - permute cells and nodes.
6975  *
6976  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6977  *          caller is to delete this field using decrRef() as it is no more needed. 
6978  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6979  *  \throw If no field of \a this is lying on \a mesh.
6980  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6981  *  \sa getFieldAtLevel()
6982  *  \sa getFieldOnMeshAtLevel() 
6983  */
6984 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6985 {
6986   MCAuto<DataArray> arr;
6987   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6988   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6989   return ret.retn();
6990 }
6991
6992 /*!
6993  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6994  * This method is called "Old" because in MED3 norm a field has only one meshName
6995  * attached, so this method is for readers of MED2 files. If \a this field 
6996  * has not been constructed via file reading, an exception is thrown.
6997  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6998  *  \param [in] type - a spatial discretization of interest.
6999  *  \param [in] mName - a name of the supporting mesh.
7000  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7001  *  \param [out] arrOut - the DataArrayInt containing values of field.
7002  *  \param [in] renumPol - specifies how to permute values of the result field according to
7003  *          the optional numbers of cells and nodes, if any. The valid values are
7004  *          - 0 - do not permute.
7005  *          - 1 - permute cells.
7006  *          - 2 - permute nodes.
7007  *          - 3 - permute cells and nodes.
7008  *
7009  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7010  *          caller is to delete this field using decrRef() as it is no more needed. 
7011  *  \throw If the MED file is not readable.
7012  *  \throw If there is no mesh named \a mName in the MED file.
7013  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7014  *  \throw If \a this field has not been constructed via file reading.
7015  *  \throw If no field of \a this is lying on the mesh named \a mName.
7016  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7017  *  \sa getFieldAtLevel()
7018  */
7019 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
7020 {
7021   if(getFileName().empty())
7022     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7023   MCAuto<DataArray> arr;
7024   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
7025   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7026   return ret.retn();
7027 }
7028
7029 /*!
7030  * Returns values and a profile of the field of a given type lying on a given support.
7031  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7032  *  \param [in] type - a spatial discretization of the field.
7033  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7034  *  \param [in] mesh - the supporting mesh.
7035  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7036  *          field of interest lies on. If the field lies on all entities of the given
7037  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7038  *          using decrRef() as it is no more needed.  
7039  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7040  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7041  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7042  *  \throw If no field of \a this is lying on \a mesh.
7043  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7044  */
7045 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7046 {
7047   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7048   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7049 }
7050
7051 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7052 {
7053   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7054   if(!pt)
7055     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7056   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7057   if(!ret)
7058     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 !");
7059   return ret;
7060 }
7061
7062 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7063 {
7064   return contentNotNull()->getUndergroundDataArrayInt();
7065 }
7066
7067 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7068
7069 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7070 {
7071 }
7072
7073 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7074 {
7075 }
7076
7077 /*!
7078  * \param [in] fieldId field id in C mode
7079  */
7080 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7081 {
7082   med_field_type typcha;
7083   std::string dtunitOut;
7084   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
7085   setDtUnit(dtunitOut.c_str());
7086   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7087 }
7088
7089 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)
7090 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7091 {
7092   setDtUnit(dtunit.c_str());
7093   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7094 }
7095 catch(INTERP_KERNEL::Exception& e)
7096 {
7097     throw e;
7098 }
7099
7100 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7101 {
7102   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7103   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7104     ret+=(*it).capacity();
7105   return ret;
7106 }
7107
7108 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7109 {
7110   std::vector<const BigMemoryObject *> ret;
7111   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7112     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7113   return ret;
7114 }
7115
7116 /*!
7117  * 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
7118  * NULL.
7119  */
7120 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7121 {
7122   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7123   ret->setInfo(_infos);
7124   int sz=(int)_time_steps.size();
7125   for(const int *id=startIds;id!=endIds;id++)
7126     {
7127       if(*id>=0 && *id<sz)
7128         {
7129           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7130           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7131           if(tse)
7132             {
7133               tse->incrRef();
7134               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7135             }
7136           ret->pushBackTimeStep(tse2);
7137         }
7138       else
7139         {
7140           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7141           oss << " ! Should be in [0," << sz << ") !";
7142           throw INTERP_KERNEL::Exception(oss.str().c_str());
7143         }
7144     }
7145   if(ret->getNumberOfTS()>0)
7146     ret->synchronizeNameScope();
7147   ret->copyNameScope(*this);
7148   return ret.retn();
7149 }
7150
7151 /*!
7152  * 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
7153  * NULL.
7154  */
7155 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7156 {
7157   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7158   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7159   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7160   ret->setInfo(_infos);
7161   int sz=(int)_time_steps.size();
7162   int j=bg;
7163   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7164     {
7165       if(j>=0 && j<sz)
7166         {
7167           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7168           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7169           if(tse)
7170             {
7171               tse->incrRef();
7172               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7173             }
7174           ret->pushBackTimeStep(tse2);
7175         }
7176       else
7177         {
7178           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7179           oss << " ! Should be in [0," << sz << ") !";
7180           throw INTERP_KERNEL::Exception(oss.str().c_str());
7181         }
7182     }
7183   if(ret->getNumberOfTS()>0)
7184     ret->synchronizeNameScope();
7185   ret->copyNameScope(*this);
7186   return ret.retn();
7187 }
7188
7189 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7190 {
7191   int id=0;
7192   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7193   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7194     {
7195       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7196       if(!cur)
7197         continue;
7198       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7199       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7200         ids->pushBackSilent(id);
7201     }
7202   return buildFromTimeStepIds(ids->begin(),ids->end());
7203 }
7204
7205 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7206 {
7207   int id=0;
7208   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7209   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7210     {
7211       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7212       if(!cur)
7213         continue;
7214       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7215       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7216         ids->pushBackSilent(id);
7217     }
7218   return buildFromTimeStepIds(ids->begin(),ids->end());
7219 }
7220
7221 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7222 {
7223   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7224     {
7225       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7226       if(!cur)
7227         continue;
7228       if(cur->presenceOfMultiDiscPerGeoType())
7229         return true;
7230     }
7231   return false;
7232 }
7233
7234 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7235 {
7236   return _infos;
7237 }
7238
7239 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7240 {
7241   _infos=info;
7242 }
7243
7244 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7245 {
7246   int ret=0;
7247   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7248     {
7249       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7250       if(pt->isDealingTS(iteration,order))
7251         return ret;
7252     }
7253   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7254   std::vector< std::pair<int,int> > vp=getIterations();
7255   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7256     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7257   throw INTERP_KERNEL::Exception(oss.str().c_str());
7258 }
7259
7260 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7261 {
7262   return *_time_steps[getTimeStepPos(iteration,order)];
7263 }
7264
7265 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7266 {
7267   return *_time_steps[getTimeStepPos(iteration,order)];
7268 }
7269
7270 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7271 {
7272   if(_time_steps.empty())
7273     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7274   return _time_steps[0]->getMeshName();
7275 }
7276
7277 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7278 {
7279   std::string oldName(getMeshName());
7280   std::vector< std::pair<std::string,std::string> > v(1);
7281   v[0].first=oldName; v[0].second=newMeshName;
7282   changeMeshNames(v);
7283 }
7284
7285 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7286 {
7287   bool ret=false;
7288   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7289     {
7290       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7291       if(cur)
7292         ret=cur->changeMeshNames(modifTab) || ret;
7293     }
7294   return ret;
7295 }
7296
7297 /*!
7298  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7299  */
7300 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7301 {
7302   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7303 }
7304
7305 /*!
7306  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7307  */
7308 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7309 {
7310   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7311 }
7312
7313 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7314                                                                        MEDFileFieldGlobsReal& glob)
7315 {
7316   bool ret=false;
7317   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7318     {
7319       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7320       if(f1ts)
7321         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7322     }
7323   return ret;
7324 }
7325
7326 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7327 {
7328   std::string startLine(bkOffset,' ');
7329   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7330   if(fmtsId>=0)
7331     oss << " (" << fmtsId << ")";
7332   oss << " has the following name: \"" << _name << "\"." << std::endl;
7333   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7334   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7335     {
7336       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7337     }
7338   int i=0;
7339   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7340     {
7341       std::string chapter(17,'0'+i);
7342       oss << startLine << chapter << std::endl;
7343       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7344       if(cur)
7345         cur->simpleRepr(bkOffset+2,oss,i);
7346       else
7347         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7348       oss << startLine << chapter << std::endl;
7349     }
7350 }
7351
7352 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7353 {
7354   std::size_t sz=_time_steps.size();
7355   std::vector< std::pair<int,int> > ret(sz);
7356   ret1.resize(sz);
7357   for(std::size_t i=0;i<sz;i++)
7358     {
7359       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7360       if(f1ts)
7361         {
7362           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7363         }
7364       else
7365         {
7366           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7367           throw INTERP_KERNEL::Exception(oss.str().c_str());
7368         }
7369     }
7370   return ret;
7371 }
7372
7373 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7374 {
7375   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7376   if(!tse2)
7377     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7378   checkCoherencyOfType(tse2);
7379   if(_time_steps.empty())
7380     {
7381       setName(tse2->getName().c_str());
7382       setInfo(tse2->getInfo());
7383     }
7384   checkThatComponentsMatch(tse2->getInfo());
7385   _time_steps.push_back(tse);
7386 }
7387
7388 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7389 {
7390   std::size_t nbOfCompo=_infos.size();
7391   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7392     {
7393       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7394       if(cur)
7395         {
7396           if((cur->getInfo()).size()!=nbOfCompo)
7397             {
7398               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7399               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7400               throw INTERP_KERNEL::Exception(oss.str().c_str());
7401             }
7402           cur->copyNameScope(*this);
7403         }
7404     }
7405 }
7406
7407 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)
7408 {
7409   _time_steps.resize(nbPdt);
7410   for(int i=0;i<nbPdt;i++)
7411     {
7412       std::vector< std::pair<int,int> > ts;
7413       med_int numdt=0,numo=0;
7414       med_int meshIt=0,meshOrder=0;
7415       med_float dt=0.0;
7416       MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder));
7417       switch(fieldTyp)
7418       {
7419         case MED_FLOAT64:
7420           {
7421             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7422             break;
7423           }
7424         case MED_INT32:
7425           {
7426             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7427             break;
7428           }
7429         default:
7430           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7431       }
7432       if(loadAll)
7433         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7434       else
7435         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7436     }
7437 }
7438
7439 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7440 {
7441   if(_time_steps.empty())
7442     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7443   checkThatNbOfCompoOfTSMatchThis();
7444   std::vector<std::string> infos(getInfo());
7445   int nbComp=infos.size();
7446   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7447   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7448   for(int i=0;i<nbComp;i++)
7449     {
7450       std::string info=infos[i];
7451       std::string c,u;
7452       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7453       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7454       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7455     }
7456   if(_name.empty())
7457     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7458   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7459   int nbOfTS=_time_steps.size();
7460   for(int i=0;i<nbOfTS;i++)
7461     _time_steps[i]->writeLL(fid,opts,*this);
7462 }
7463
7464 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7465 {
7466   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7467     {
7468       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7469       if(elt)
7470         elt->loadBigArraysRecursively(fid,nasc);
7471     }
7472 }
7473
7474 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7475 {
7476   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7477     {
7478       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7479       if(elt)
7480         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7481     }
7482 }
7483
7484 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7485 {
7486   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7487     {
7488       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7489       if(elt)
7490         elt->unloadArrays();
7491     }
7492 }
7493
7494 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7495 {
7496   return _time_steps.size();
7497 }
7498
7499 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7500 {
7501   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7502   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7503     {
7504       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7505       if(tmp)
7506         newTS.push_back(*it);
7507     }
7508   _time_steps=newTS;
7509 }
7510
7511 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7512 {
7513   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7514   int maxId=(int)_time_steps.size();
7515   int ii=0;
7516   std::set<int> idsToDel;
7517   for(const int *id=startIds;id!=endIds;id++,ii++)
7518     {
7519       if(*id>=0 && *id<maxId)
7520         {
7521           idsToDel.insert(*id);
7522         }
7523       else
7524         {
7525           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7526           throw INTERP_KERNEL::Exception(oss.str().c_str());
7527         }
7528     }
7529   for(int iii=0;iii<maxId;iii++)
7530     if(idsToDel.find(iii)==idsToDel.end())
7531       newTS.push_back(_time_steps[iii]);
7532   _time_steps=newTS;
7533 }
7534
7535 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7536 {
7537   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7538   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7539   if(nbOfEntriesToKill==0)
7540     return ;
7541   std::size_t sz=_time_steps.size();
7542   std::vector<bool> b(sz,true);
7543   int j=bg;
7544   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7545     b[j]=false;
7546   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7547   for(std::size_t i=0;i<sz;i++)
7548     if(b[i])
7549       newTS.push_back(_time_steps[i]);
7550   _time_steps=newTS;
7551 }
7552
7553 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7554 {
7555   int ret=0;
7556   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7557   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7558     {
7559       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7560       if(tmp)
7561         {
7562           int it2,ord;
7563           tmp->getTime(it2,ord);
7564           if(it2==iteration && order==ord)
7565             return ret;
7566           else
7567             oss << "(" << it2 << ","  << ord << "), ";
7568         }
7569     }
7570   throw INTERP_KERNEL::Exception(oss.str().c_str());
7571 }
7572
7573 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7574 {
7575   int ret=0;
7576   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7577   oss.precision(15);
7578   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7579     {
7580       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7581       if(tmp)
7582         {
7583           int it2,ord;
7584           double ti=tmp->getTime(it2,ord);
7585           if(fabs(time-ti)<eps)
7586             return ret;
7587           else
7588             oss << ti << ", ";
7589         }
7590     }
7591   throw INTERP_KERNEL::Exception(oss.str().c_str());
7592 }
7593
7594 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7595 {
7596   int lgth=_time_steps.size();
7597   std::vector< std::pair<int,int> > ret(lgth);
7598   for(int i=0;i<lgth;i++)
7599     _time_steps[i]->fillIteration(ret[i]);
7600   return ret;
7601 }
7602
7603 /*!
7604  * 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'
7605  * This method returns two things.
7606  * - The absolute dimension of 'this' in first parameter. 
7607  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7608  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7609  *
7610  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7611  * Only these 3 discretizations will be taken into account here.
7612  *
7613  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7614  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7615  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7616  *
7617  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7618  * 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'.
7619  * 
7620  * Let's consider the typical following case :
7621  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7622  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7623  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7624  *   TETRA4 and SEG2
7625  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7626  *
7627  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7628  * 
7629  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7630  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7631  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7632  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7633  */
7634 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7635 {
7636   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7637 }
7638
7639 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7640 {
7641   if(pos<0 || pos>=(int)_time_steps.size())
7642     {
7643       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7644       throw INTERP_KERNEL::Exception(oss.str().c_str());
7645     }
7646   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7647   if(item==0)
7648     {
7649       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7650       oss << "\nTry to use following method eraseEmptyTS !";
7651       throw INTERP_KERNEL::Exception(oss.str().c_str());
7652     }
7653   return item;
7654 }
7655
7656 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7657 {
7658   if(pos<0 || pos>=(int)_time_steps.size())
7659     {
7660       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7661       throw INTERP_KERNEL::Exception(oss.str().c_str());
7662     }
7663   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7664   if(item==0)
7665     {
7666       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7667       oss << "\nTry to use following method eraseEmptyTS !";
7668       throw INTERP_KERNEL::Exception(oss.str().c_str());
7669     }
7670   return item;
7671 }
7672
7673 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7674 {
7675   std::vector<std::string> ret;
7676   std::set<std::string> ret2;
7677   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7678     {
7679       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7680       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7681         if(ret2.find(*it2)==ret2.end())
7682           {
7683             ret.push_back(*it2);
7684             ret2.insert(*it2);
7685           }
7686     }
7687   return ret;
7688 }
7689
7690 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7691 {
7692   std::vector<std::string> ret;
7693   std::set<std::string> ret2;
7694   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7695     {
7696       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7697       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7698         if(ret2.find(*it2)==ret2.end())
7699           {
7700             ret.push_back(*it2);
7701             ret2.insert(*it2);
7702           }
7703     }
7704   return ret;
7705 }
7706
7707 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7708 {
7709   std::vector<std::string> ret;
7710   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7711     {
7712       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7713       ret.insert(ret.end(),tmp.begin(),tmp.end());
7714     }
7715   return ret;
7716 }
7717
7718 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7719 {
7720   std::vector<std::string> ret;
7721   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7722     {
7723       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7724       ret.insert(ret.end(),tmp.begin(),tmp.end());
7725     }
7726   return ret;
7727 }
7728
7729 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7730 {
7731   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7732     (*it)->changePflsRefsNamesGen2(mapOfModif);
7733 }
7734
7735 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7736 {
7737   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7738     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7739 }
7740
7741 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7742 {
7743   int lgth=_time_steps.size();
7744   std::vector< std::vector<TypeOfField> > ret(lgth);
7745   for(int i=0;i<lgth;i++)
7746     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7747   return ret;
7748 }
7749
7750 /*!
7751  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7752  */
7753 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
7754 {
7755   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7756 }
7757
7758 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7759 {
7760   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7761   std::size_t i=0;
7762   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7763     {
7764       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7765         ret->_time_steps[i]=(*it)->deepCopy();
7766     }
7767   return ret.retn();
7768 }
7769
7770 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7771 {
7772   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7773   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7774   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7775   for(std::size_t i=0;i<sz;i++)
7776     {
7777       ret[i]=shallowCpy();
7778       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7779     }
7780   for(std::size_t i=0;i<sz2;i++)
7781     {
7782       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7783       if(ret1.size()!=sz)
7784         {
7785           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7786           throw INTERP_KERNEL::Exception(oss.str().c_str());
7787         }
7788       ts[i]=ret1;
7789     }
7790   for(std::size_t i=0;i<sz;i++)
7791     for(std::size_t j=0;j<sz2;j++)
7792       ret[i]->_time_steps[j]=ts[j][i];
7793   return ret;
7794 }
7795
7796 /*!
7797  * This method splits into discretization each time steps in \a this.
7798  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7799  */
7800 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7801 {
7802   std::size_t sz(_time_steps.size());
7803   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7804   for(std::size_t i=0;i<sz;i++)
7805     {
7806       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7807       if(!timeStep)
7808         {
7809           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7810           throw INTERP_KERNEL::Exception(oss.str().c_str());
7811         }
7812       items[i]=timeStep->splitDiscretizations();  
7813     }
7814   //
7815   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7816   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7817   std::vector< TypeOfField > types;
7818   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7819     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7820       {
7821         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7822         if(ts.size()!=1)
7823           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7824         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7825         if(it2==types.end())
7826           types.push_back(ts[0]);
7827       }
7828   ret.resize(types.size()); ret2.resize(types.size());
7829   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7830     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7831       {
7832         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7833         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7834         ret2[pos].push_back(*it1);
7835       }
7836   for(std::size_t i=0;i<types.size();i++)
7837     {
7838       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7839       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7840         elt->pushBackTimeStep(*it1);//also updates infos in elt
7841       ret[i]=elt;
7842       elt->MEDFileFieldNameScope::operator=(*this);
7843     }
7844   return ret;
7845 }
7846
7847 /*!
7848  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7849  */
7850 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7851 {
7852   std::size_t sz(_time_steps.size());
7853   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7854   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7855   for(std::size_t i=0;i<sz;i++)
7856     {
7857       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7858       if(!timeStep)
7859         {
7860           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7861           throw INTERP_KERNEL::Exception(oss.str().c_str());
7862         }
7863       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7864       if(szOut==std::numeric_limits<std::size_t>::max())
7865         szOut=items[i].size();
7866       else
7867         if(items[i].size()!=szOut)
7868           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7869     }
7870   if(szOut==std::numeric_limits<std::size_t>::max())
7871     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7872   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7873   for(std::size_t i=0;i<szOut;i++)
7874     {
7875       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7876       for(std::size_t j=0;j<sz;j++)
7877         elt->pushBackTimeStep(items[j][i]);
7878       ret[i]=elt;
7879       elt->MEDFileFieldNameScope::operator=(*this);
7880     }
7881   return ret;
7882 }
7883
7884 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7885 {
7886   _name=field->getName();
7887   if(_name.empty())
7888     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7889   if(!arr)
7890     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7891   _infos=arr->getInfoOnComponents();
7892 }
7893
7894 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7895 {
7896   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7897   if(_name!=field->getName())
7898     {
7899       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7900       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7901       throw INTERP_KERNEL::Exception(oss.str().c_str());
7902     }
7903   if(!arr)
7904     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7905   checkThatComponentsMatch(arr->getInfoOnComponents());
7906 }
7907
7908 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7909 {
7910   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7911   if(getInfo().size()!=compos.size())
7912     {
7913       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7914       oss << " number of components of element to append (" << compos.size() << ") !";
7915       throw INTERP_KERNEL::Exception(oss.str().c_str());
7916     }
7917   if(_infos!=compos)
7918     {
7919       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7920       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7921       oss << " But compo in input fields are : ";
7922       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7923       oss << " !";
7924       throw INTERP_KERNEL::Exception(oss.str().c_str());
7925     }
7926 }
7927
7928 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7929 {
7930   std::size_t sz=_infos.size();
7931   int j=0;
7932   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7933     {
7934       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7935       if(elt)
7936         if(elt->getInfo().size()!=sz)
7937           {
7938             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7939             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7940             throw INTERP_KERNEL::Exception(oss.str().c_str());
7941           }
7942     }
7943 }
7944
7945 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7946 {
7947   if(!field)
7948     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7949   if(!_time_steps.empty())
7950     checkCoherencyOfTinyInfo(field,arr);
7951   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7952   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7953   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7954   copyTinyInfoFrom(field,arr);
7955   _time_steps.push_back(obj);
7956 }
7957
7958 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7959 {
7960   if(!field)
7961     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7962   if(!_time_steps.empty())
7963     checkCoherencyOfTinyInfo(field,arr);
7964   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7965   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7966   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7967   copyTinyInfoFrom(field,arr);
7968   _time_steps.push_back(obj);
7969 }
7970
7971 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
7972 {
7973   int sz=(int)_time_steps.size();
7974   if(i<0 || i>=sz)
7975     {
7976       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7977       throw INTERP_KERNEL::Exception(oss.str().c_str());
7978     }
7979   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7980   if(tsPtr)
7981     {
7982       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7983         {
7984           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7985           throw INTERP_KERNEL::Exception(oss.str().c_str());
7986         }
7987     }
7988   _time_steps[i]=ts;
7989 }
7990
7991 //= MEDFileFieldMultiTSWithoutSDA
7992
7993 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)
7994 {
7995   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
7996 }
7997
7998 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7999 {
8000 }
8001
8002 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8003 {
8004 }
8005
8006 /*!
8007  * \param [in] fieldId field id in C mode
8008  */
8009 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8010 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8011 {
8012 }
8013 catch(INTERP_KERNEL::Exception& e)
8014 { throw e; }
8015
8016 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)
8017 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8018 {
8019 }
8020 catch(INTERP_KERNEL::Exception& e)
8021 { throw e; }
8022
8023 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8024 {
8025   return new MEDFileField1TSWithoutSDA;
8026 }
8027
8028 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8029 {
8030   if(!f1ts)
8031     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8032   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8033   if(!f1tsC)
8034     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8035 }
8036
8037 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8038 {
8039   return MEDFileField1TSWithoutSDA::TYPE_STR;
8040 }
8041
8042 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8043 {
8044   return new MEDFileFieldMultiTSWithoutSDA(*this);
8045 }
8046
8047 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8048 {
8049   return new MEDFileFieldMultiTSWithoutSDA;
8050 }
8051
8052 /*!
8053  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8054  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8055  */
8056 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
8057 {
8058   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8059   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8060   if(!myF1TSC)
8061     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8062   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8063 }
8064
8065 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8066 {
8067   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8068   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8069   int i=0;
8070   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8071     {
8072       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8073       if(eltToConv)
8074         {
8075           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8076           if(!eltToConvC)
8077             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8078           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8079           ret->setIteration(i,elt);
8080         }
8081     }
8082   return ret.retn();
8083 }
8084
8085 //= MEDFileAnyTypeFieldMultiTS
8086
8087 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8088 {
8089 }
8090
8091 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8092 try:MEDFileFieldGlobsReal(fileName)
8093 {
8094   MEDFileUtilities::CheckFileForRead(fileName);
8095   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8096   _content=BuildContentFrom(fid,fileName,loadAll,ms);
8097   loadGlobals(fid);
8098 }
8099 catch(INTERP_KERNEL::Exception& e)
8100 {
8101     throw e;
8102 }
8103
8104 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)
8105 {
8106   med_field_type typcha;
8107   std::vector<std::string> infos;
8108   std::string dtunit;
8109   int i=-1;
8110   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
8111   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8112   switch(typcha)
8113   {
8114     case MED_FLOAT64:
8115       {
8116         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8117         break;
8118       }
8119     case MED_INT32:
8120       {
8121         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8122         break;
8123       }
8124     default:
8125       {
8126         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] !";
8127         throw INTERP_KERNEL::Exception(oss.str().c_str());
8128       }
8129   }
8130   ret->setDtUnit(dtunit.c_str());
8131   return ret.retn();
8132 }
8133
8134 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8135 {
8136   med_field_type typcha;
8137   //
8138   std::vector<std::string> infos;
8139   std::string dtunit,fieldName;
8140   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
8141   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8142   switch(typcha)
8143   {
8144     case MED_FLOAT64:
8145       {
8146         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8147         break;
8148       }
8149     case MED_INT32:
8150       {
8151         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8152         break;
8153       }
8154     default:
8155       {
8156         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] !";
8157         throw INTERP_KERNEL::Exception(oss.str().c_str());
8158       }
8159   }
8160   ret->setDtUnit(dtunit.c_str());
8161   return ret.retn();
8162 }
8163
8164 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
8165 {
8166   if(!c)
8167     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8168   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8169     {
8170       MCAuto<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
8171       ret->setFileName(fileName);
8172       ret->_content=c;  c->incrRef();
8173       return ret.retn();
8174     }
8175   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8176     {
8177       MCAuto<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
8178       ret->setFileName(fileName);
8179       ret->_content=c;  c->incrRef();
8180       return ret.retn();
8181     }
8182   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8183 }
8184
8185 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)
8186 try:MEDFileFieldGlobsReal(fileName)
8187 {
8188   MEDFileUtilities::CheckFileForRead(fileName);
8189   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8190   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms,entities);
8191   loadGlobals(fid);
8192 }
8193 catch(INTERP_KERNEL::Exception& e)
8194 {
8195     throw e;
8196 }
8197
8198 //= MEDFileIntFieldMultiTSWithoutSDA
8199
8200 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)
8201 {
8202   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8203 }
8204
8205 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8206 {
8207 }
8208
8209 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8210 {
8211 }
8212
8213 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)
8214 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8215 {
8216 }
8217 catch(INTERP_KERNEL::Exception& e)
8218 { throw e; }
8219
8220 /*!
8221  * \param [in] fieldId field id in C mode
8222  */
8223 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8224 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8225 {
8226 }
8227 catch(INTERP_KERNEL::Exception& e)
8228 { throw e; }
8229
8230 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8231 {
8232   return new MEDFileIntField1TSWithoutSDA;
8233 }
8234
8235 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8236 {
8237   if(!f1ts)
8238     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8239   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8240   if(!f1tsC)
8241     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8242 }
8243
8244 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8245 {
8246   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8247 }
8248
8249 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8250 {
8251   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8252 }
8253
8254 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8255 {
8256   return new MEDFileIntFieldMultiTSWithoutSDA;
8257 }
8258
8259 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8260 {
8261   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8262   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8263   int i=0;
8264   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8265     {
8266       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8267       if(eltToConv)
8268         {
8269           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8270           if(!eltToConvC)
8271             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8272           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8273           ret->setIteration(i,elt);
8274         }
8275     }
8276   return ret.retn();
8277 }
8278
8279 //= MEDFileAnyTypeFieldMultiTS
8280
8281 /*!
8282  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8283  * that has been read from a specified MED file.
8284  *  \param [in] fileName - the name of the MED file to read.
8285  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8286  *          is to delete this field using decrRef() as it is no more needed.
8287  *  \throw If reading the file fails.
8288  */
8289 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8290 {
8291   MEDFileUtilities::CheckFileForRead(fileName);
8292   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8293   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
8294   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8295   ret->loadGlobals(fid);
8296   return ret.retn();
8297 }
8298
8299 /*!
8300  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8301  * that has been read from a specified MED file.
8302  *  \param [in] fileName - the name of the MED file to read.
8303  *  \param [in] fieldName - the name of the field to read.
8304  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8305  *          is to delete this field using decrRef() as it is no more needed.
8306  *  \throw If reading the file fails.
8307  *  \throw If there is no field named \a fieldName in the file.
8308  */
8309 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8310 {
8311   MEDFileUtilities::CheckFileForRead(fileName);
8312   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8313   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fileName,fieldName,loadAll,0,0));
8314   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8315   ret->loadGlobals(fid);
8316   return ret.retn();
8317 }
8318
8319 /*!
8320  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8321  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8322  *
8323  * \warning this is a shallow copy constructor
8324  */
8325 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8326 {
8327   if(!shallowCopyOfContent)
8328     {
8329       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8330       otherPtr->incrRef();
8331       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8332     }
8333   else
8334     {
8335       _content=other.shallowCpy();
8336     }
8337 }
8338
8339 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8340 {
8341   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8342   if(!ret)
8343     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8344   return ret;
8345 }
8346
8347 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8348 {
8349   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8350   if(!ret)
8351     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8352   return ret;
8353 }
8354
8355 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8356 {
8357   return contentNotNullBase()->getPflsReallyUsed2();
8358 }
8359
8360 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8361 {
8362   return contentNotNullBase()->getLocsReallyUsed2();
8363 }
8364
8365 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8366 {
8367   return contentNotNullBase()->getPflsReallyUsedMulti2();
8368 }
8369
8370 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8371 {
8372   return contentNotNullBase()->getLocsReallyUsedMulti2();
8373 }
8374
8375 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8376 {
8377   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8378 }
8379
8380 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8381 {
8382   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8383 }
8384
8385 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8386 {
8387   return contentNotNullBase()->getNumberOfTS();
8388 }
8389
8390 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8391 {
8392   contentNotNullBase()->eraseEmptyTS();
8393 }
8394
8395 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8396 {
8397   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8398 }
8399
8400 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8401 {
8402   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8403 }
8404
8405 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8406 {
8407   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8408   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8409   ret->_content=c;
8410   return ret.retn();
8411 }
8412
8413 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8414 {
8415   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8416   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8417   ret->_content=c;
8418   return ret.retn();
8419 }
8420
8421 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8422 {
8423   return contentNotNullBase()->getIterations();
8424 }
8425
8426 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8427 {
8428   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8429     pushBackTimeStep(*it);
8430 }
8431
8432 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8433 {
8434   if(!fmts)
8435     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8436   int nbOfTS(fmts->getNumberOfTS());
8437   for(int i=0;i<nbOfTS;i++)
8438     {
8439       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8440       pushBackTimeStep(elt);
8441     }
8442 }
8443
8444 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8445 {
8446   if(!f1ts)
8447     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8448   checkCoherencyOfType(f1ts);
8449   f1ts->incrRef();
8450   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8451   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8452   c->incrRef();
8453   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8454   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8455     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8456   _content->pushBackTimeStep(cSafe);
8457   appendGlobs(*f1ts,1e-12);
8458 }
8459
8460 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8461 {
8462   contentNotNullBase()->synchronizeNameScope();
8463 }
8464
8465 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8466 {
8467   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8468 }
8469
8470 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8471 {
8472   return contentNotNullBase()->getPosGivenTime(time,eps);
8473 }
8474
8475 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8476 {
8477   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8478 }
8479
8480 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8481 {
8482   return contentNotNullBase()->getTypesOfFieldAvailable();
8483 }
8484
8485 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
8486 {
8487   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8488 }
8489
8490 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8491 {
8492   return contentNotNullBase()->getName();
8493 }
8494
8495 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8496 {
8497   contentNotNullBase()->setName(name);
8498 }
8499
8500 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8501 {
8502   return contentNotNullBase()->getDtUnit();
8503 }
8504
8505 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8506 {
8507   contentNotNullBase()->setDtUnit(dtUnit);
8508 }
8509
8510 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8511 {
8512   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8513 }
8514
8515 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8516 {
8517   return contentNotNullBase()->getTimeSteps(ret1);
8518 }
8519
8520 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8521 {
8522   return contentNotNullBase()->getMeshName();
8523 }
8524
8525 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8526 {
8527   contentNotNullBase()->setMeshName(newMeshName);
8528 }
8529
8530 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8531 {
8532   return contentNotNullBase()->changeMeshNames(modifTab);
8533 }
8534
8535 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8536 {
8537   return contentNotNullBase()->getInfo();
8538 }
8539
8540 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8541 {
8542   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8543 }
8544
8545 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8546 {
8547   return contentNotNullBase()->setInfo(info);
8548 }
8549
8550 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8551 {
8552   const std::vector<std::string> ret=getInfo();
8553   return (int)ret.size();
8554 }
8555
8556 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8557 {
8558   writeGlobals(fid,*this);
8559   contentNotNullBase()->writeLL(fid,*this);
8560 }
8561
8562 /*!
8563  * Writes \a this field into a MED file specified by its name.
8564  *  \param [in] fileName - the MED file name.
8565  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8566  * - 2 - erase; an existing file is removed.
8567  * - 1 - append; same data should not be present in an existing file.
8568  * - 0 - overwrite; same data present in an existing file is overwritten.
8569  *  \throw If the field name is not set.
8570  *  \throw If no field data is set.
8571  *  \throw If \a mode == 1 and the same data is present in an existing file.
8572  */
8573 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8574 {
8575   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8576   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8577   writeLL(fid);
8578 }
8579
8580 /*!
8581  * This method alloc the arrays and load potentially huge arrays contained in this field.
8582  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8583  * This method can be also called to refresh or reinit values from a file.
8584  * 
8585  * \throw If the fileName is not set or points to a non readable MED file.
8586  */
8587 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8588 {
8589   if(getFileName().empty())
8590     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8591   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8592   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8593 }
8594
8595 /*!
8596  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8597  * But once data loaded once, this method does nothing.
8598  * 
8599  * \throw If the fileName is not set or points to a non readable MED file.
8600  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8601  */
8602 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8603 {
8604   if(!getFileName().empty())
8605     {
8606       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8607       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8608     }
8609 }
8610
8611 /*!
8612  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8613  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8614  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8615  * 
8616  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8617  */
8618 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8619 {
8620   contentNotNullBase()->unloadArrays();
8621 }
8622
8623 /*!
8624  * 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.
8625  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8626  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8627  * 
8628  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8629  */
8630 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8631 {
8632   if(!getFileName().empty())
8633     contentNotNullBase()->unloadArrays();
8634 }
8635
8636 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8637 {
8638   std::ostringstream oss;
8639   contentNotNullBase()->simpleRepr(0,oss,-1);
8640   simpleReprGlobs(oss);
8641   return oss.str();
8642 }
8643
8644 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8645 {
8646   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8647 }
8648
8649 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8650 {
8651   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8652   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8653   return ret;
8654 }
8655
8656 /*!
8657  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8658  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8659  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8660  */
8661 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8662 {
8663   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8664   if(!content)
8665     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8666   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8667   std::size_t sz(contentsSplit.size());
8668   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8669   for(std::size_t i=0;i<sz;i++)
8670     {
8671       ret[i]=shallowCpy();
8672       ret[i]->_content=contentsSplit[i];
8673     }
8674   return ret;
8675 }
8676
8677 /*!
8678  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8679  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8680  */
8681 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8682 {
8683   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8684   if(!content)
8685     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8686   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8687   std::size_t sz(contentsSplit.size());
8688   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8689   for(std::size_t i=0;i<sz;i++)
8690     {
8691       ret[i]=shallowCpy();
8692       ret[i]->_content=contentsSplit[i];
8693     }
8694   return ret;
8695 }
8696
8697 /*!
8698  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8699  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8700  */
8701 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8702 {
8703   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8704   if(!content)
8705     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8706   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8707   std::size_t sz(contentsSplit.size());
8708   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8709   for(std::size_t i=0;i<sz;i++)
8710     {
8711       ret[i]=shallowCpy();
8712       ret[i]->_content=contentsSplit[i];
8713     }
8714   return ret;
8715 }
8716
8717 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8718 {
8719   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8720   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8721     ret->_content=_content->deepCopy();
8722   ret->deepCpyGlobs(*this);
8723   return ret.retn();
8724 }
8725
8726 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8727 {
8728   return _content;
8729 }
8730
8731 /*!
8732  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8733  *  \param [in] iteration - the iteration number of a required time step.
8734  *  \param [in] order - the iteration order number of required time step.
8735  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8736  *          delete this field using decrRef() as it is no more needed.
8737  *  \throw If there is no required time step in \a this field.
8738  */
8739 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8740 {
8741   int pos=getPosOfTimeStep(iteration,order);
8742   return getTimeStepAtPos(pos);
8743 }
8744
8745 /*!
8746  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8747  *  \param [in] time - the time of the time step of interest.
8748  *  \param [in] eps - a precision used to compare time values.
8749  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8750  *          delete this field using decrRef() as it is no more needed.
8751  *  \throw If there is no required time step in \a this field.
8752  */
8753 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8754 {
8755   int pos=getPosGivenTime(time,eps);
8756   return getTimeStepAtPos(pos);
8757 }
8758
8759 /*!
8760  * 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.
8761  * The float64 value of time attached to the pair of integers are not considered here.
8762  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8763  *
8764  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8765  * \throw If there is a null pointer in \a vectFMTS.
8766  */
8767 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8768 {
8769   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8770   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8771   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8772   while(!lstFMTS.empty())
8773     {
8774       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8775       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8776       if(!curIt)
8777         throw INTERP_KERNEL::Exception(msg);
8778       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8779       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8780       elt.push_back(curIt); it=lstFMTS.erase(it);
8781       while(it!=lstFMTS.end())
8782         {
8783           curIt=*it;
8784           if(!curIt)
8785             throw INTERP_KERNEL::Exception(msg);
8786           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8787           if(refIts==curIts)
8788             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8789           else
8790             it++;
8791         }
8792       ret.push_back(elt);
8793     }
8794   return ret;
8795 }
8796
8797 /*!
8798  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8799  * All returned instances in a subvector can be safely loaded, rendered along time
8800  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8801  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8802  * 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).
8803  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8804  * 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.
8805  *
8806  * \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().
8807  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8808  * \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.
8809  * \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.
8810  *
8811  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8812  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8813  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8814  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8815  * \throw If mesh is null.
8816  * \throw If an element in \a vectFMTS is null.
8817  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8818  */
8819 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
8820 {
8821   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8822   if(!mesh)
8823     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8824   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8825   if(vectFMTS.empty())
8826     return ret;
8827   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8828   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8829   if(!frstElt)
8830     throw INTERP_KERNEL::Exception(msg);
8831   std::size_t i=0;
8832   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8833   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8834   for(;it!=vectFMTS.end();it++,i++)
8835     {
8836       if(!(*it))
8837         throw INTERP_KERNEL::Exception(msg);
8838       TypeOfField tof0,tof1;
8839       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8840         {
8841           if(tof1!=ON_NODES)
8842             vectFMTSNotNodes.push_back(*it);
8843           else
8844             vectFMTSNodes.push_back(*it);
8845         }
8846       else
8847         vectFMTSNotNodes.push_back(*it);
8848     }
8849   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
8850   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8851   ret=retCell;
8852   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8853     {
8854       i=0;
8855       bool isFetched(false);
8856       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8857         {
8858           if((*it0).empty())
8859             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8860           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8861             { ret[i].push_back(*it2); isFetched=true; }
8862         }
8863       if(!isFetched)
8864         {
8865           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8866           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8867           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8868         }
8869     }
8870   fsc=cmps;
8871   return ret;
8872 }
8873
8874 /*!
8875  * 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.
8876  * \param [out] cmps - same size than the returned vector.
8877  */
8878 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
8879 {
8880   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8881   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8882   while(!lstFMTS.empty())
8883     {
8884       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8885       MEDFileAnyTypeFieldMultiTS *ref(*it);
8886       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8887       elt.push_back(ref); it=lstFMTS.erase(it);
8888       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8889       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8890       while(it!=lstFMTS.end())
8891         {
8892           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8893           if(cmp->isEqual(curIt))
8894             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8895           else
8896             it++;
8897         }
8898       ret.push_back(elt); cmps.push_back(cmp);
8899     }
8900   return ret;
8901 }
8902
8903 /*!
8904  * 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.
8905  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8906  *
8907  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8908  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8909  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8910  * \thorw If \a f0 and \a f1 do not have the same times steps.
8911  * \throw If mesh is null.
8912  * \throw If \a f0 or \a f1 is null.
8913  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8914  */
8915 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8916 {
8917   if(!mesh)
8918     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8919   if(!f0 || !f1)
8920     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8921   if(f0->getMeshName()!=mesh->getName())
8922     {
8923       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8924       throw INTERP_KERNEL::Exception(oss.str().c_str());
8925     }
8926   if(f1->getMeshName()!=mesh->getName())
8927     {
8928       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8929       throw INTERP_KERNEL::Exception(oss.str().c_str());
8930     }
8931   int nts=f0->getNumberOfTS();
8932   if(nts!=f1->getNumberOfTS())
8933     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8934   if(nts==0)
8935     return nts;
8936   for(int i=0;i<nts;i++)
8937     {
8938       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8939       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8940       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8941       if(tofs0.size()!=1 || tofs1.size()!=1)
8942         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8943       if(i!=0)
8944         {
8945           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8946             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8947         }
8948       else
8949         { tof0=tofs0[0]; tof1=tofs1[0]; }
8950       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8951         {
8952           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() << ") !";
8953           throw INTERP_KERNEL::Exception(oss.str().c_str());
8954         }
8955       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8956         {
8957           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() << ") !";
8958           throw INTERP_KERNEL::Exception(oss.str().c_str());
8959         }
8960       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8961         {
8962           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() << ") !";
8963           throw INTERP_KERNEL::Exception(oss.str().c_str());
8964         }
8965     }
8966   return nts;
8967 }
8968
8969 /*!
8970  * Return an extraction of \a this using \a extractDef map to specify the extraction.
8971  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
8972  *
8973  * \return A new object that the caller is responsible to deallocate.
8974  */
8975 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
8976 {
8977   if(!mm)
8978     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
8979   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
8980   int nbTS(getNumberOfTS());
8981   for(int i=0;i<nbTS;i++)
8982     {
8983       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
8984       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
8985       fmtsOut->pushBackTimeStep(f1tsOut);
8986     }
8987   return fmtsOut.retn();
8988 }
8989
8990 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8991 {
8992   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8993 }
8994
8995 //= MEDFileFieldMultiTS
8996
8997 /*!
8998  * Returns a new empty instance of MEDFileFieldMultiTS.
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  */
9002 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9003 {
9004   return new MEDFileFieldMultiTS;
9005 }
9006
9007 /*!
9008  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9009  * that has been read from a specified MED file.
9010  *  \param [in] fileName - the name of the MED file to read.
9011  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9012  *          is to delete this field using decrRef() as it is no more needed.
9013  *  \throw If reading the file fails.
9014  */
9015 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9016 {
9017   MCAuto<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
9018   ret->contentNotNull();//to check that content type matches with \a this type.
9019   return ret.retn();
9020 }
9021
9022 /*!
9023  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9024  * that has been read from a specified MED file.
9025  *  \param [in] fileName - the name of the MED file to read.
9026  *  \param [in] fieldName - the name of the field to read.
9027  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9028  *          is to delete this field using decrRef() as it is no more needed.
9029  *  \throw If reading the file fails.
9030  *  \throw If there is no field named \a fieldName in the file.
9031  */
9032 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9033 {
9034   MCAuto<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
9035   ret->contentNotNull();//to check that content type matches with \a this type.
9036   return ret.retn();
9037 }
9038
9039 /*!
9040  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9041  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9042  *
9043  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9044  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9045  * \warning this is a shallow copy constructor
9046  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9047  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9048  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9049  *          is to delete this field using decrRef() as it is no more needed.
9050  */
9051 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9052 {
9053   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9054 }
9055
9056 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9057 {
9058   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0,&entities));
9059   ret->contentNotNull();//to check that content type matches with \a this type.
9060   return ret.retn();
9061 }
9062
9063 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9064 {
9065   return new MEDFileFieldMultiTS(*this);
9066 }
9067
9068 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9069 {
9070   if(!f1ts)
9071     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9072   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9073   if(!f1tsC)
9074     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9075 }
9076
9077 /*!
9078  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9079  * following the given input policy.
9080  *
9081  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9082  *                            By default (true) the globals are deeply copied.
9083  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9084  */
9085 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9086 {
9087   MCAuto<MEDFileIntFieldMultiTS> ret;
9088   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9089   if(content)
9090     {
9091       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9092       if(!contc)
9093         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9094       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9095       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
9096     }
9097   else
9098     ret=MEDFileIntFieldMultiTS::New();
9099   if(isDeepCpyGlobs)
9100     ret->deepCpyGlobs(*this);
9101   else
9102     ret->shallowCpyGlobs(*this);
9103   return ret.retn();
9104 }
9105
9106 /*!
9107  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9108  *  \param [in] pos - a time step id.
9109  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9110  *          delete this field using decrRef() as it is no more needed.
9111  *  \throw If \a pos is not a valid time step id.
9112  */
9113 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9114 {
9115   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9116   if(!item)
9117     {
9118       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9119       throw INTERP_KERNEL::Exception(oss.str().c_str());
9120     }
9121   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9122   if(itemC)
9123     {
9124       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9125       ret->shallowCpyGlobs(*this);
9126       return ret.retn();
9127     }
9128   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9129   throw INTERP_KERNEL::Exception(oss.str().c_str());
9130 }
9131
9132 /*!
9133  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9134  * mesh entities of a given dimension of the first mesh in MED file.
9135  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9136  *  \param [in] type - a spatial discretization of interest.
9137  *  \param [in] iteration - the iteration number of a required time step.
9138  *  \param [in] order - the iteration order number of required time step.
9139  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9140  *  \param [in] renumPol - specifies how to permute values of the result field according to
9141  *          the optional numbers of cells and nodes, if any. The valid values are
9142  *          - 0 - do not permute.
9143  *          - 1 - permute cells.
9144  *          - 2 - permute nodes.
9145  *          - 3 - permute cells and nodes.
9146  *
9147  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9148  *          caller is to delete this field using decrRef() as it is no more needed. 
9149  *  \throw If the MED file is not readable.
9150  *  \throw If there is no mesh in the MED file.
9151  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9152  *  \throw If no field values of the required parameters are available.
9153  */
9154 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9155 {
9156   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9157   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9158   if(!myF1TSC)
9159     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9160   MCAuto<DataArray> arrOut;
9161   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9162   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9163   return ret.retn();
9164 }
9165
9166 /*!
9167  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9168  * the top level cells of the first mesh in MED file.
9169  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9170  *  \param [in] type - a spatial discretization of interest.
9171  *  \param [in] iteration - the iteration number of a required time step.
9172  *  \param [in] order - the iteration order number of required time step.
9173  *  \param [in] renumPol - specifies how to permute values of the result field according to
9174  *          the optional numbers of cells and nodes, if any. The valid values are
9175  *          - 0 - do not permute.
9176  *          - 1 - permute cells.
9177  *          - 2 - permute nodes.
9178  *          - 3 - permute cells and nodes.
9179  *
9180  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9181  *          caller is to delete this field using decrRef() as it is no more needed. 
9182  *  \throw If the MED file is not readable.
9183  *  \throw If there is no mesh in the MED file.
9184  *  \throw If no field values of the required parameters are available.
9185  */
9186 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9187 {
9188   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9189   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9190   if(!myF1TSC)
9191     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9192   MCAuto<DataArray> arrOut;
9193   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9194   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9195   return ret.retn();
9196 }
9197
9198 /*!
9199  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9200  * a given support.
9201  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9202  *  \param [in] type - a spatial discretization of interest.
9203  *  \param [in] iteration - the iteration number of a required time step.
9204  *  \param [in] order - the iteration order number of required time step.
9205  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9206  *  \param [in] mesh - the supporting mesh.
9207  *  \param [in] renumPol - specifies how to permute values of the result field according to
9208  *          the optional numbers of cells and nodes, if any. The valid values are
9209  *          - 0 - do not permute.
9210  *          - 1 - permute cells.
9211  *          - 2 - permute nodes.
9212  *          - 3 - permute cells and nodes.
9213  *
9214  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9215  *          caller is to delete this field using decrRef() as it is no more needed. 
9216  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9217  *  \throw If no field of \a this is lying on \a mesh.
9218  *  \throw If no field values of the required parameters are available.
9219  */
9220 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9221 {
9222   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9223   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9224   if(!myF1TSC)
9225     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9226   MCAuto<DataArray> arrOut;
9227   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9228   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9229   return ret.retn();
9230 }
9231
9232 /*!
9233  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9234  * given support. 
9235  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9236  *  \param [in] type - a spatial discretization of the new field.
9237  *  \param [in] iteration - the iteration number of a required time step.
9238  *  \param [in] order - the iteration order number of required time step.
9239  *  \param [in] mesh - the supporting mesh.
9240  *  \param [in] renumPol - specifies how to permute values of the result field according to
9241  *          the optional numbers of cells and nodes, if any. The valid values are
9242  *          - 0 - do not permute.
9243  *          - 1 - permute cells.
9244  *          - 2 - permute nodes.
9245  *          - 3 - permute cells and nodes.
9246  *
9247  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9248  *          caller is to delete this field using decrRef() as it is no more needed. 
9249  *  \throw If no field of \a this is lying on \a mesh.
9250  *  \throw If no field values of the required parameters are available.
9251  */
9252 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9253 {
9254   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9255   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9256   if(!myF1TSC)
9257     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9258   MCAuto<DataArray> arrOut;
9259   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9260   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9261   return ret.retn();
9262 }
9263
9264 /*!
9265  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9266  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9267  * This method is useful for MED2 file format when field on different mesh was autorized.
9268  */
9269 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9270 {
9271   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9272   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9273   if(!myF1TSC)
9274     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9275   MCAuto<DataArray> arrOut;
9276   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9277   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9278   return ret.retn();
9279 }
9280
9281 /*!
9282  * Returns values and a profile of the field of a given type, of a given time step,
9283  * lying on a given support.
9284  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9285  *  \param [in] type - a spatial discretization of the field.
9286  *  \param [in] iteration - the iteration number of a required time step.
9287  *  \param [in] order - the iteration order number of required time step.
9288  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9289  *  \param [in] mesh - the supporting mesh.
9290  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9291  *          field of interest lies on. If the field lies on all entities of the given
9292  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9293  *          using decrRef() as it is no more needed.  
9294  *  \param [in] glob - the global data storing profiles and localization.
9295  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9296  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9297  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9298  *  \throw If no field of \a this is lying on \a mesh.
9299  *  \throw If no field values of the required parameters are available.
9300  */
9301 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9302 {
9303   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9304   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9305   if(!myF1TSC)
9306     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9307   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9308   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9309 }
9310
9311 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9312 {
9313   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9314   if(!pt)
9315     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9316   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9317   if(!ret)
9318     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 !");
9319   return ret;
9320 }
9321
9322 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9323 {
9324   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9325   if(!pt)
9326     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9327   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9328   if(!ret)
9329     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 !");
9330   return ret;
9331 }
9332
9333 /*!
9334  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9335  * the given field is checked if its elements are sorted suitable for writing to MED file
9336  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9337  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9338  *  \param [in] field - the field to add to \a this.
9339  *  \throw If the name of \a field is empty.
9340  *  \throw If the data array of \a field is not set.
9341  *  \throw If existing time steps have different name or number of components than \a field.
9342  *  \throw If the underlying mesh of \a field has no name.
9343  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9344  */
9345 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9346 {
9347   const DataArrayDouble *arr=0;
9348   if(field)
9349     arr=field->getArray();
9350   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9351 }
9352
9353 /*!
9354  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9355  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9356  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9357  * and \a profile.
9358  *
9359  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9360  * A new profile is added only if no equal profile is missing.
9361  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9362  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9363  *  \param [in] mesh - the supporting mesh of \a field.
9364  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9365  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9366  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9367  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9368  *  \throw If the data array of \a field is not set.
9369  *  \throw If the data array of \a this is already allocated but has different number of
9370  *         components than \a field.
9371  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9372  *  \sa setFieldNoProfileSBT()
9373  */
9374 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9375 {
9376   const DataArrayDouble *arr=0;
9377   if(field)
9378     arr=field->getArray();
9379   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9380 }
9381
9382 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9383 {
9384   _content=new MEDFileFieldMultiTSWithoutSDA;
9385 }
9386
9387 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9388 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9389 {
9390 }
9391 catch(INTERP_KERNEL::Exception& e)
9392 { throw e; }
9393
9394 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)
9395 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9396 {
9397 }
9398 catch(INTERP_KERNEL::Exception& e)
9399 { throw e; }
9400
9401 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9402 {
9403 }
9404
9405 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
9406 {
9407   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9408 }
9409
9410 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9411 {
9412   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9413 }
9414
9415 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9416 {
9417   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9418 }
9419
9420 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
9421 {
9422   return MEDFileFieldMultiTS::New();
9423 }
9424
9425 //= MEDFileAnyTypeFieldMultiTSIterator
9426
9427 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9428 {
9429   if(fmts)
9430     {
9431       fmts->incrRef();
9432       _nb_iter=fmts->getNumberOfTS();
9433     }
9434 }
9435
9436 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9437 {
9438 }
9439
9440 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9441 {
9442   if(_iter_id<_nb_iter)
9443     {
9444       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9445       if(fmts)
9446         return fmts->getTimeStepAtPos(_iter_id++);
9447       else
9448         return 0;
9449     }
9450   else
9451     return 0;
9452 }
9453
9454 //= MEDFileIntFieldMultiTS
9455
9456 /*!
9457  * Returns a new empty instance of MEDFileFieldMultiTS.
9458  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9459  *          is to delete this field using decrRef() as it is no more needed.
9460  */
9461 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9462 {
9463   return new MEDFileIntFieldMultiTS;
9464 }
9465
9466 /*!
9467  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9468  * that has been read from a specified MED file.
9469  *  \param [in] fileName - the name of the MED file to read.
9470  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9471  *          is to delete this field using decrRef() as it is no more needed.
9472  *  \throw If reading the file fails.
9473  */
9474 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9475 {
9476   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9477   ret->contentNotNull();//to check that content type matches with \a this type.
9478   return ret.retn();
9479 }
9480
9481 /*!
9482  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9483  * that has been read from a specified MED file.
9484  *  \param [in] fileName - the name of the MED file to read.
9485  *  \param [in] fieldName - the name of the field to read.
9486  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9487  *          is to delete this field using decrRef() as it is no more needed.
9488  *  \throw If reading the file fails.
9489  *  \throw If there is no field named \a fieldName in the file.
9490  */
9491 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9492 {
9493   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9494   ret->contentNotNull();//to check that content type matches with \a this type.
9495   return ret.retn();
9496 }
9497
9498 /*!
9499  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9500  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9501  *
9502  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9503  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9504  * \warning this is a shallow copy constructor
9505  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9506  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9507  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9508  *          is to delete this field using decrRef() as it is no more needed.
9509  */
9510 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9511 {
9512   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9513 }
9514
9515 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9516 {
9517   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0,&entities);
9518   ret->contentNotNull();//to check that content type matches with \a this type.
9519   return ret.retn();
9520 }
9521
9522 /*!
9523  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9524  * following the given input policy.
9525  *
9526  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9527  *                            By default (true) the globals are deeply copied.
9528  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9529  */
9530 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9531 {
9532   MCAuto<MEDFileFieldMultiTS> ret;
9533   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9534   if(content)
9535     {
9536       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9537       if(!contc)
9538         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9539       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9540       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9541     }
9542   else
9543     ret=MEDFileFieldMultiTS::New();
9544   if(isDeepCpyGlobs)
9545     ret->deepCpyGlobs(*this);
9546   else
9547     ret->shallowCpyGlobs(*this);
9548   return ret.retn();
9549 }
9550
9551 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9552 {
9553   return new MEDFileIntFieldMultiTS(*this);
9554 }
9555
9556 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9557 {
9558   if(!f1ts)
9559     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9560   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9561   if(!f1tsC)
9562     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9563 }
9564
9565 /*!
9566  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9567  * mesh entities of a given dimension of the first mesh in MED file.
9568  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9569  *  \param [in] type - a spatial discretization of interest.
9570  *  \param [in] iteration - the iteration number of a required time step.
9571  *  \param [in] order - the iteration order number of required time step.
9572  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9573  *  \param [out] arrOut - the DataArrayInt containing values of field.
9574  *  \param [in] renumPol - specifies how to permute values of the result field according to
9575  *          the optional numbers of cells and nodes, if any. The valid values are
9576  *          - 0 - do not permute.
9577  *          - 1 - permute cells.
9578  *          - 2 - permute nodes.
9579  *          - 3 - permute cells and nodes.
9580  *
9581  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9582  *          caller is to delete this field using decrRef() as it is no more needed. 
9583  *  \throw If the MED file is not readable.
9584  *  \throw If there is no mesh in the MED file.
9585  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9586  *  \throw If no field values of the required parameters are available.
9587  */
9588 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9589 {
9590   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9591   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9592   if(!myF1TSC)
9593     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9594   MCAuto<DataArray> arr;
9595   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9596   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9597   return ret.retn();
9598 }
9599
9600 /*!
9601  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9602  * the top level cells of the first mesh in MED file.
9603  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9604  *  \param [in] type - a spatial discretization of interest.
9605  *  \param [in] iteration - the iteration number of a required time step.
9606  *  \param [in] order - the iteration order number of required time step.
9607  *  \param [out] arrOut - the DataArrayInt containing values of field.
9608  *  \param [in] renumPol - specifies how to permute values of the result field according to
9609  *          the optional numbers of cells and nodes, if any. The valid values are
9610  *          - 0 - do not permute.
9611  *          - 1 - permute cells.
9612  *          - 2 - permute nodes.
9613  *          - 3 - permute cells and nodes.
9614  *
9615  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9616  *          caller is to delete this field using decrRef() as it is no more needed. 
9617  *  \throw If the MED file is not readable.
9618  *  \throw If there is no mesh in the MED file.
9619  *  \throw If no field values of the required parameters are available.
9620  */
9621 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9622 {
9623   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9624   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9625   if(!myF1TSC)
9626     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9627   MCAuto<DataArray> arr;
9628   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9629   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9630   return ret.retn();
9631 }
9632
9633 /*!
9634  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9635  * a given support.
9636  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9637  *  \param [in] type - a spatial discretization of interest.
9638  *  \param [in] iteration - the iteration number of a required time step.
9639  *  \param [in] order - the iteration order number of required time step.
9640  *  \param [out] arrOut - the DataArrayInt containing values of field.
9641  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9642  *  \param [in] mesh - the supporting mesh.
9643  *  \param [in] renumPol - specifies how to permute values of the result field according to
9644  *          the optional numbers of cells and nodes, if any. The valid values are
9645  *          - 0 - do not permute.
9646  *          - 1 - permute cells.
9647  *          - 2 - permute nodes.
9648  *          - 3 - permute cells and nodes.
9649  *
9650  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9651  *          caller is to delete this field using decrRef() as it is no more needed. 
9652  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9653  *  \throw If no field of \a this is lying on \a mesh.
9654  *  \throw If no field values of the required parameters are available.
9655  */
9656 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9657 {
9658   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9659   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9660   if(!myF1TSC)
9661     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9662   MCAuto<DataArray> arr;
9663   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9664   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9665   return ret.retn();
9666 }
9667
9668 /*!
9669  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9670  * given support. 
9671  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9672  *  \param [in] type - a spatial discretization of the new field.
9673  *  \param [in] iteration - the iteration number of a required time step.
9674  *  \param [in] order - the iteration order number of required time step.
9675  *  \param [in] mesh - the supporting mesh.
9676  *  \param [out] arrOut - the DataArrayInt containing values of field.
9677  *  \param [in] renumPol - specifies how to permute values of the result field according to
9678  *          the optional numbers of cells and nodes, if any. The valid values are
9679  *          - 0 - do not permute.
9680  *          - 1 - permute cells.
9681  *          - 2 - permute nodes.
9682  *          - 3 - permute cells and nodes.
9683  *
9684  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9685  *          caller is to delete this field using decrRef() as it is no more needed. 
9686  *  \throw If no field of \a this is lying on \a mesh.
9687  *  \throw If no field values of the required parameters are available.
9688  */
9689 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9690 {
9691   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9692   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9693   if(!myF1TSC)
9694     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9695   MCAuto<DataArray> arr;
9696   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9697   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9698   return ret.retn();
9699 }
9700
9701 /*!
9702  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9703  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9704  * This method is useful for MED2 file format when field on different mesh was autorized.
9705  */
9706 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9707 {
9708   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9709   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9710   if(!myF1TSC)
9711     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9712   MCAuto<DataArray> arr;
9713   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9714   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9715   return ret.retn();
9716 }
9717
9718 /*!
9719  * Returns values and a profile of the field of a given type, of a given time step,
9720  * lying on a given support.
9721  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9722  *  \param [in] type - a spatial discretization of the field.
9723  *  \param [in] iteration - the iteration number of a required time step.
9724  *  \param [in] order - the iteration order number of required time step.
9725  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9726  *  \param [in] mesh - the supporting mesh.
9727  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9728  *          field of interest lies on. If the field lies on all entities of the given
9729  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9730  *          using decrRef() as it is no more needed.  
9731  *  \param [in] glob - the global data storing profiles and localization.
9732  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9733  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9734  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9735  *  \throw If no field of \a this is lying on \a mesh.
9736  *  \throw If no field values of the required parameters are available.
9737  */
9738 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9739 {
9740   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9741   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9742   if(!myF1TSC)
9743     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9744   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9745   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9746 }
9747
9748 /*!
9749  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9750  *  \param [in] pos - a time step id.
9751  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9752  *          delete this field using decrRef() as it is no more needed.
9753  *  \throw If \a pos is not a valid time step id.
9754  */
9755 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9756 {
9757   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9758   if(!item)
9759     {
9760       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9761       throw INTERP_KERNEL::Exception(oss.str().c_str());
9762     }
9763   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9764   if(itemC)
9765     {
9766       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9767       ret->shallowCpyGlobs(*this);
9768       return ret.retn();
9769     }
9770   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9771   throw INTERP_KERNEL::Exception(oss.str().c_str());
9772 }
9773
9774 /*!
9775  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9776  * the given field is checked if its elements are sorted suitable for writing to MED file
9777  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9778  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9779  *  \param [in] field - the field to add to \a this.
9780  *  \throw If the name of \a field is empty.
9781  *  \throw If the data array of \a field is not set.
9782  *  \throw If existing time steps have different name or number of components than \a field.
9783  *  \throw If the underlying mesh of \a field has no name.
9784  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9785  */
9786 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9787 {
9788   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9789 }
9790
9791 /*!
9792  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9793  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9794  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9795  * and \a profile.
9796  *
9797  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9798  * A new profile is added only if no equal profile is missing.
9799  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9800  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9801  *  \param [in] arrOfVals - the values of the field \a field used.
9802  *  \param [in] mesh - the supporting mesh of \a field.
9803  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9804  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9805  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9806  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9807  *  \throw If the data array of \a field is not set.
9808  *  \throw If the data array of \a this is already allocated but has different number of
9809  *         components than \a field.
9810  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9811  *  \sa setFieldNoProfileSBT()
9812  */
9813 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9814 {
9815   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9816 }
9817
9818 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9819 {
9820   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9821   if(!pt)
9822     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9823   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9824   if(!ret)
9825     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 !");
9826   return ret;
9827 }
9828
9829 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9830 {
9831   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9832   if(!pt)
9833     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9834   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9835   if(!ret)
9836     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 !");
9837   return ret;
9838 }
9839
9840 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9841 {
9842   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9843 }
9844
9845 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9846 {
9847 }
9848
9849 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9850 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9851 {
9852 }
9853 catch(INTERP_KERNEL::Exception& e)
9854 { throw e; }
9855
9856 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)
9857 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9858 {
9859 }
9860 catch(INTERP_KERNEL::Exception& e)
9861 { throw e; }
9862
9863 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9864 {
9865   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9866 }
9867
9868 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
9869 {
9870   return MEDFileIntFieldMultiTS::New();
9871 }
9872
9873 //= MEDFileFields
9874
9875 MEDFileFields *MEDFileFields::New()
9876 {
9877   return new MEDFileFields;
9878 }
9879
9880 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9881 {
9882   return new MEDFileFields(fileName,loadAll,0,0);
9883 }
9884
9885 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9886 {
9887   return new MEDFileFields(fileName,loadAll,ms,0);
9888 }
9889
9890 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9891 {
9892   return new MEDFileFields(fileName,loadAll,0,&entities);
9893 }
9894
9895 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9896 {
9897   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9898   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9899   return ret;
9900 }
9901
9902 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9903 {
9904   std::vector<const BigMemoryObject *> ret;
9905   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9906     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9907   return ret;
9908 }
9909
9910 MEDFileFields *MEDFileFields::deepCopy() const
9911 {
9912   MCAuto<MEDFileFields> ret=shallowCpy();
9913   std::size_t i=0;
9914   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9915     {
9916       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9917         ret->_fields[i]=(*it)->deepCopy();
9918     }
9919   ret->deepCpyGlobs(*this);
9920   return ret.retn();
9921 }
9922
9923 MEDFileFields *MEDFileFields::shallowCpy() const
9924 {
9925   return new MEDFileFields(*this);
9926 }
9927
9928 /*!
9929  * 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
9930  * 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.
9931  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9932  *
9933  * \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.
9934  * \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.
9935  * 
9936  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9937  */
9938 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9939 {
9940   std::set< std::pair<int,int> > s;
9941   bool firstShot=true;
9942   areThereSomeForgottenTS=false;
9943   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9944     {
9945       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9946         continue;
9947       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9948       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9949       if(firstShot)
9950         { s=s1; firstShot=false; }
9951       else
9952         {
9953           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9954           if(s!=s2)
9955             areThereSomeForgottenTS=true;
9956           s=s2;
9957         }
9958     }
9959   std::vector< std::pair<int,int> > ret;
9960   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9961   return ret;
9962 }
9963
9964 int MEDFileFields::getNumberOfFields() const
9965 {
9966   return _fields.size();
9967 }
9968
9969 std::vector<std::string> MEDFileFields::getFieldsNames() const
9970 {
9971   std::vector<std::string> ret(_fields.size());
9972   int i=0;
9973   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9974     {
9975       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9976       if(f)
9977         {
9978           ret[i]=f->getName();
9979         }
9980       else
9981         {
9982           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9983           throw INTERP_KERNEL::Exception(oss.str().c_str());
9984         }
9985     }
9986   return ret;
9987 }
9988
9989 std::vector<std::string> MEDFileFields::getMeshesNames() const
9990 {
9991   std::vector<std::string> ret;
9992   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9993     {
9994       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9995       if(cur)
9996         ret.push_back(cur->getMeshName());
9997     }
9998   return ret;
9999 }
10000
10001 std::string MEDFileFields::simpleRepr() const
10002 {
10003   std::ostringstream oss;
10004   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10005   simpleRepr(0,oss);
10006   return oss.str();
10007 }
10008
10009 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10010 {
10011   int nbOfFields=getNumberOfFields();
10012   std::string startLine(bkOffset,' ');
10013   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10014   int i=0;
10015   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10016     {
10017       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10018       if(cur)
10019         {
10020           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10021         }
10022       else
10023         {
10024           oss << startLine << "  - not defined !" << std::endl;
10025         }
10026     }
10027   i=0;
10028   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10029     {
10030       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10031       std::string chapter(17,'0'+i);
10032       oss << startLine << chapter << std::endl;
10033       if(cur)
10034         {
10035           cur->simpleRepr(bkOffset+2,oss,i);
10036         }
10037       else
10038         {
10039           oss << startLine << "  - not defined !" << std::endl;
10040         }
10041       oss << startLine << chapter << std::endl;
10042     }
10043   simpleReprGlobs(oss);
10044 }
10045
10046 MEDFileFields::MEDFileFields()
10047 {
10048 }
10049
10050 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
10051 try:MEDFileFieldGlobsReal(fileName)
10052 {
10053   MEDFileUtilities::CheckFileForRead(fileName);
10054   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
10055   int nbFields(MEDnField(fid));
10056   _fields.resize(nbFields);
10057   med_field_type typcha;
10058   for(int i=0;i<nbFields;i++)
10059     {
10060       std::vector<std::string> infos;
10061       std::string fieldName,dtunit;
10062       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
10063       switch(typcha)
10064       {
10065         case MED_FLOAT64:
10066           {
10067             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10068             break;
10069           }
10070         case MED_INT32:
10071           {
10072             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10073             break;
10074           }
10075         default:
10076           {
10077             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] !";
10078             throw INTERP_KERNEL::Exception(oss.str().c_str());
10079           }
10080       }
10081     }
10082   loadAllGlobals(fid);
10083 }
10084 catch(INTERP_KERNEL::Exception& e)
10085 {
10086     throw e;
10087 }
10088
10089 void MEDFileFields::writeLL(med_idt fid) const
10090 {
10091   int i=0;
10092   writeGlobals(fid,*this);
10093   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10094     {
10095       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10096       if(!elt)
10097         {
10098           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10099           throw INTERP_KERNEL::Exception(oss.str().c_str());
10100         }
10101       elt->writeLL(fid,*this);
10102     }
10103 }
10104
10105 void MEDFileFields::write(const std::string& fileName, int mode) const
10106 {
10107   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
10108   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
10109   writeLL(fid);
10110 }
10111
10112 /*!
10113  * This method alloc the arrays and load potentially huge arrays contained in this field.
10114  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10115  * This method can be also called to refresh or reinit values from a file.
10116  * 
10117  * \throw If the fileName is not set or points to a non readable MED file.
10118  */
10119 void MEDFileFields::loadArrays()
10120 {
10121   if(getFileName().empty())
10122     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10123   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10124   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10125     {
10126       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10127       if(elt)
10128         elt->loadBigArraysRecursively(fid,*elt);
10129     }
10130 }
10131
10132 /*!
10133  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10134  * But once data loaded once, this method does nothing.
10135  * 
10136  * \throw If the fileName is not set or points to a non readable MED file.
10137  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10138  */
10139 void MEDFileFields::loadArraysIfNecessary()
10140 {
10141   if(!getFileName().empty())
10142     {
10143       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10144       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10145         {
10146           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10147           if(elt)
10148             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10149         }
10150     }
10151 }
10152
10153 /*!
10154  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10155  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10156  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10157  * 
10158  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10159  */
10160 void MEDFileFields::unloadArrays()
10161 {
10162   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10163     {
10164       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10165       if(elt)
10166         elt->unloadArrays();
10167     }
10168 }
10169
10170 /*!
10171  * 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.
10172  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10173  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10174  * 
10175  * \sa MEDFileFields::loadArraysIfNecessary
10176  */
10177 void MEDFileFields::unloadArraysWithoutDataLoss()
10178 {
10179   if(!getFileName().empty())
10180     unloadArrays();
10181 }
10182
10183 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10184 {
10185   std::vector<std::string> ret;
10186   std::set<std::string> ret2;
10187   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10188     {
10189       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10190       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10191         if(ret2.find(*it2)==ret2.end())
10192           {
10193             ret.push_back(*it2);
10194             ret2.insert(*it2);
10195           }
10196     }
10197   return ret;
10198 }
10199
10200 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10201 {
10202   std::vector<std::string> ret;
10203   std::set<std::string> ret2;
10204   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10205     {
10206       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10207       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10208         if(ret2.find(*it2)==ret2.end())
10209           {
10210             ret.push_back(*it2);
10211             ret2.insert(*it2);
10212           }
10213     }
10214   return ret;
10215 }
10216
10217 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10218 {
10219   std::vector<std::string> ret;
10220   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10221     {
10222       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
10223       ret.insert(ret.end(),tmp.begin(),tmp.end());
10224     }
10225   return ret;
10226 }
10227
10228 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10229 {
10230   std::vector<std::string> ret;
10231   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10232     {
10233       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10234       ret.insert(ret.end(),tmp.begin(),tmp.end());
10235     }
10236   return ret;
10237 }
10238
10239 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10240 {
10241   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10242     (*it)->changePflsRefsNamesGen2(mapOfModif);
10243 }
10244
10245 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10246 {
10247   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10248     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10249 }
10250
10251 void MEDFileFields::resize(int newSize)
10252 {
10253   _fields.resize(newSize);
10254 }
10255
10256 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10257 {
10258   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10259     pushField(*it);
10260 }
10261
10262 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10263 {
10264   if(!field)
10265     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10266   _fields.push_back(field->getContent());
10267   appendGlobs(*field,1e-12);
10268 }
10269
10270 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10271 {
10272   if(!field)
10273     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10274   if(i>=(int)_fields.size())
10275     _fields.resize(i+1);
10276   _fields[i]=field->getContent();
10277   appendGlobs(*field,1e-12);
10278 }
10279
10280 void MEDFileFields::destroyFieldAtPos(int i)
10281 {
10282   destroyFieldsAtPos(&i,&i+1);
10283 }
10284
10285 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10286 {
10287   std::vector<bool> b(_fields.size(),true);
10288   for(const int *i=startIds;i!=endIds;i++)
10289     {
10290       if(*i<0 || *i>=(int)_fields.size())
10291         {
10292           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10293           throw INTERP_KERNEL::Exception(oss.str().c_str());
10294         }
10295       b[*i]=false;
10296     }
10297   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10298   std::size_t j=0;
10299   for(std::size_t i=0;i<_fields.size();i++)
10300     if(b[i])
10301       fields[j++]=_fields[i];
10302   _fields=fields;
10303 }
10304
10305 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10306 {
10307   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10308   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
10309   std::vector<bool> b(_fields.size(),true);
10310   int k=bg;
10311   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10312     {
10313       if(k<0 || k>=(int)_fields.size())
10314         {
10315           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10316           throw INTERP_KERNEL::Exception(oss.str().c_str());
10317         }
10318       b[k]=false;
10319     }
10320   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10321   std::size_t j=0;
10322   for(std::size_t i=0;i<_fields.size();i++)
10323     if(b[i])
10324       fields[j++]=_fields[i];
10325   _fields=fields;
10326 }
10327
10328 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10329 {
10330   bool ret=false;
10331   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10332     {
10333       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10334       if(cur)
10335         ret=cur->changeMeshNames(modifTab) || ret;
10336     }
10337   return ret;
10338 }
10339
10340 /*!
10341  * \param [in] meshName the name of the mesh that will be renumbered.
10342  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10343  *             This code corresponds to the distribution of types in the corresponding mesh.
10344  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10345  * \param [in] renumO2N the old to new renumber array.
10346  * \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 
10347  *         field in \a this.
10348  */
10349 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10350 {
10351   bool ret=false;
10352   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10353     {
10354       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10355       if(fmts)
10356         {
10357           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10358         }
10359     }
10360   return ret;
10361 }
10362
10363 /*!
10364  * Return an extraction of \a this using \a extractDef map to specify the extraction.
10365  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
10366  *
10367  * \return A new object that the caller is responsible to deallocate.
10368  */
10369 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
10370 {
10371   if(!mm)
10372     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
10373   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
10374   int nbFields(getNumberOfFields());
10375   for(int i=0;i<nbFields;i++)
10376     {
10377       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
10378       if(!fmts)
10379         {
10380           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
10381           throw INTERP_KERNEL::Exception(oss.str().c_str());
10382         }
10383       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
10384       fsOut->pushField(fmtsOut);
10385     }
10386   return fsOut.retn();
10387 }
10388
10389 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10390 {
10391   if(i<0 || i>=(int)_fields.size())
10392     {
10393       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10394       throw INTERP_KERNEL::Exception(oss.str().c_str());
10395     }
10396   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10397   if(!fmts)
10398     return 0;
10399   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
10400   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
10401   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
10402   if(fmtsC)
10403     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10404   else if(fmtsC2)
10405     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10406   else
10407     {
10408       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10409       throw INTERP_KERNEL::Exception(oss.str().c_str());
10410     }
10411   ret->shallowCpyGlobs(*this);
10412   return ret.retn();
10413 }
10414
10415 /*!
10416  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10417  * This method is accessible in python using __getitem__ with a list in input.
10418  * \return a new object that the caller should deal with.
10419  */
10420 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10421 {
10422   MCAuto<MEDFileFields> ret=shallowCpy();
10423   std::size_t sz=std::distance(startIds,endIds);
10424   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10425   int j=0;
10426   for(const int *i=startIds;i!=endIds;i++,j++)
10427     {
10428       if(*i<0 || *i>=(int)_fields.size())
10429         {
10430           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10431           throw INTERP_KERNEL::Exception(oss.str().c_str());
10432         }
10433       fields[j]=_fields[*i];
10434     }
10435   ret->_fields=fields;
10436   return ret.retn();
10437 }
10438
10439 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10440 {
10441   return getFieldAtPos(getPosFromFieldName(fieldName));
10442 }
10443
10444 /*!
10445  * This method removes, if any, fields in \a this having no time steps.
10446  * 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.
10447  * 
10448  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10449  */
10450 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10451 {
10452   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10453   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10454     {
10455       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10456       if(elt)
10457         {
10458           if(elt->getNumberOfTS()>0)
10459             newFields.push_back(*it);
10460         }
10461     }
10462   if(_fields.size()==newFields.size())
10463     return false;
10464   _fields=newFields;
10465   return true;
10466 }
10467
10468 /*!
10469  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10470  * This method can be seen as a filter applied on \a this, that returns an object containing
10471  * 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
10472  * shallow copied from \a this.
10473  * 
10474  * \param [in] meshName - the name of the mesh on w
10475  * \return a new object that the caller should deal with.
10476  */
10477 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10478 {
10479   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10480   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10481     {
10482       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10483       if(!cur)
10484         continue;
10485       if(cur->getMeshName()==meshName)
10486         {
10487           cur->incrRef();
10488           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10489           ret->_fields.push_back(cur2);
10490         }
10491     }
10492   ret->shallowCpyOnlyUsedGlobs(*this);
10493   return ret.retn();
10494 }
10495
10496 /*!
10497  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10498  * Input time steps are specified using a pair of integer (iteration, order).
10499  * 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,
10500  * but for each multitimestep only the time steps in \a timeSteps are kept.
10501  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10502  * 
10503  * The returned object points to shallow copy of elements in \a this.
10504  * 
10505  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10506  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10507  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10508  */
10509 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10510 {
10511   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10512   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10513     {
10514       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10515       if(!cur)
10516         continue;
10517       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10518       ret->_fields.push_back(elt);
10519     }
10520   ret->shallowCpyOnlyUsedGlobs(*this);
10521   return ret.retn();
10522 }
10523
10524 /*!
10525  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10526  */
10527 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10528 {
10529   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10530   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10531     {
10532       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10533       if(!cur)
10534         continue;
10535       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10536       if(elt->getNumberOfTS()!=0)
10537         ret->_fields.push_back(elt);
10538     }
10539   ret->shallowCpyOnlyUsedGlobs(*this);
10540   return ret.retn();
10541 }
10542
10543 MEDFileFieldsIterator *MEDFileFields::iterator()
10544 {
10545   return new MEDFileFieldsIterator(this);
10546 }
10547
10548 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10549 {
10550   std::string tmp(fieldName);
10551   std::vector<std::string> poss;
10552   for(std::size_t i=0;i<_fields.size();i++)
10553     {
10554       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10555       if(f)
10556         {
10557           std::string fname(f->getName());
10558           if(tmp==fname)
10559             return i;
10560           else
10561             poss.push_back(fname);
10562         }
10563     }
10564   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10565   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10566   oss << " !";
10567   throw INTERP_KERNEL::Exception(oss.str().c_str());
10568 }
10569
10570 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10571 {
10572   if(fs)
10573     {
10574       fs->incrRef();
10575       _nb_iter=fs->getNumberOfFields();
10576     }
10577 }
10578
10579 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10580 {
10581 }
10582
10583 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10584 {
10585   if(_iter_id<_nb_iter)
10586     {
10587       MEDFileFields *fs(_fs);
10588       if(fs)
10589         return fs->getFieldAtPos(_iter_id++);
10590       else
10591         return 0;
10592     }
10593   else
10594     return 0;
10595 }