Salome HOME
cc9e3fe602fafb922f1683ed5fbdb286b722b74a
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2013  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.
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
26 #include "MEDCouplingFieldDouble.hxx"
27 #include "MEDCouplingFieldDiscretization.hxx"
28
29 #include "InterpKernelAutoPtr.hxx"
30 #include "CellModel.hxx"
31
32 #include <algorithm>
33 #include <iterator>
34
35 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
36 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
37 extern med_geometry_type typmainoeud[1];
38 extern med_geometry_type typmai3[32];
39
40 using namespace ParaMEDMEM;
41
42 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const char *locName)
43 {
44   return new MEDFileFieldLoc(fid,locName);
45 }
46
47 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
48 {
49   return new MEDFileFieldLoc(fid,id);
50 }
51
52 MEDFileFieldLoc *MEDFileFieldLoc::New(const char *locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
53 {
54   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
55 }
56
57 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const char *locName):_name(locName)
58 {
59   med_geometry_type geotype;
60   med_geometry_type sectiongeotype;
61   int nsectionmeshcell;
62   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
63   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
64   MEDlocalizationInfoByName(fid,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
65   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+32,geotype)));
66   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
67   _nb_node_per_cell=cm.getNumberOfNodes();
68   _ref_coo.resize(_dim*_nb_node_per_cell);
69   _gs_coo.resize(_dim*_nb_gauss_pt);
70   _w.resize(_nb_gauss_pt);
71   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
72 }
73
74 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
75 {
76   med_geometry_type geotype;
77   med_geometry_type sectiongeotype;
78   int nsectionmeshcell;
79   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
80   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
81   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
82   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
83   _name=locName;
84   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+32,geotype)));
85   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
86   _nb_node_per_cell=cm.getNumberOfNodes();
87   _ref_coo.resize(_dim*_nb_node_per_cell);
88   _gs_coo.resize(_dim*_nb_gauss_pt);
89   _w.resize(_nb_gauss_pt);
90   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
91 }
92
93 MEDFileFieldLoc::MEDFileFieldLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType,
94                                  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),
95                                                                                                                                     _w(w)
96 {
97   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
98   _dim=cm.getDimension();
99   _nb_node_per_cell=cm.getNumberOfNodes();
100   _nb_gauss_pt=_w.size();
101 }
102
103 MEDFileFieldLoc *MEDFileFieldLoc::deepCpy() const
104 {
105   return new MEDFileFieldLoc(*this);
106 }
107
108 std::size_t MEDFileFieldLoc::getHeapMemorySize() const
109 {
110   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
111 }
112
113 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
114 {
115   static const char OFF7[]="\n    ";
116   oss << "\"" << _name << "\"" << OFF7;
117   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
118   oss << "Dimension=" << _dim << OFF7;
119   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
120   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
121   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
122   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
123   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
124 }
125
126 void MEDFileFieldLoc::setName(const char *name)
127 {
128   _name=name;
129 }
130
131 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
132 {
133   if(_name!=other._name)
134     return false;
135   if(_dim!=other._dim)
136     return false;
137   if(_nb_gauss_pt!=other._nb_gauss_pt)
138     return false;
139   if(_nb_node_per_cell!=other._nb_node_per_cell)
140     return false;
141   if(_geo_type!=other._geo_type)
142     return false;
143   if(MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
144     return false;
145   if(MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
146     return false;
147   if(MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
148     return false;
149   
150   return true;
151 }
152
153 void MEDFileFieldLoc::writeLL(med_idt fid) const
154 {
155   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);
156 }
157
158 std::string MEDFileFieldLoc::repr() const
159 {
160   std::ostringstream oss; oss.precision(15);
161   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
162   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
163   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
164   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
165   oss << "\n  - Ref coords are : ";
166   int sz=_ref_coo.size();
167   if(sz%_dim==0)
168     {
169       int nbOfTuples=sz/_dim;
170       for(int i=0;i<nbOfTuples;i++)
171         {
172           oss << "(";
173           for(int j=0;j<_dim;j++)
174             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
175           oss << ") ";
176         }
177     }
178   else
179     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
180   oss << "\n  - Gauss coords in reference element : ";
181   sz=_gs_coo.size();
182   if(sz%_dim==0)
183     {
184       int nbOfTuples=sz/_dim;
185       for(int i=0;i<nbOfTuples;i++)
186         {
187           oss << "(";
188           for(int j=0;j<_dim;j++)
189             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
190           oss << ") ";
191         }
192     }
193   else
194     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
195   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
196   return oss.str();
197 }
198
199 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
200 {
201   _type=field->getTypeOfField();
202   const DataArrayDouble *da=field->getArray();
203   _start=start;
204   switch(_type)
205     {
206     case ON_CELLS:
207       {
208         getArray()->setContigPartOfSelectedValues2(_start,da,offset,offset+nbOfCells,1);
209         _end=_start+nbOfCells;
210         _nval=nbOfCells;
211         break;
212       }
213     case ON_GAUSS_NE:
214       {
215         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
216         const int *arrPtr=arr->getConstPointer();
217         getArray()->setContigPartOfSelectedValues2(_start,da,arrPtr[offset],arrPtr[offset+nbOfCells],1);
218         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
219         _nval=nbOfCells;
220         break;
221       }
222     case ON_GAUSS_PT:
223       {
224         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
225         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
226         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
227         if(!disc2)
228           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
229         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
230         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
231         const int *dai2Ptr=dai2->getConstPointer();
232         int nbi=gsLoc.getWeights().size();
233         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=dai->selectByTupleId2(offset,offset+nbOfCells,1);
234         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
235         const int *da3Ptr=da3->getConstPointer();
236         if(da3->getNumberOfTuples()!=nbOfCells)
237           {//profile : for gauss even in NoProfile !!!
238             std::ostringstream oss; oss << "Pfl_" << getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
239             _profile=oss.str();
240             da3->setName(_profile.c_str());
241             glob.appendProfile(da3);
242           }
243         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=DataArrayInt::New();
244         _nval=da3->getNbOfElems();
245         da4->alloc(_nval*nbi,1);
246         int *da4Ptr=da4->getPointer();
247         for(int i=0;i<_nval;i++)
248           {
249             int ref=dai2Ptr[offset+da3Ptr[i]];
250             for(int j=0;j<nbi;j++)
251               *da4Ptr++=ref+j;
252           }
253         std::ostringstream oss2; oss2 << "Loc_" << getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
254         _localization=oss2.str();
255         getArray()->setContigPartOfSelectedValues(_start,da,da4);
256         _end=_start+_nval*nbi;
257         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
258         break;
259       }
260     default:
261       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
262     }
263   start=_end;
264 }
265
266 /*!
267  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
268  * \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).
269  * \param [in] multiTypePfl is the end user profile specified in high level API
270  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
271  * \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.
272  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
273  * \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.
274  */
275 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
276 {
277   _profile.clear();
278   _type=field->getTypeOfField();
279   std::string pflName(multiTypePfl->getName());
280   std::ostringstream oss; oss << pflName;
281   if(_type!=ON_NODES) { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); } else { oss << "_NODE"; }
282   if(locIds)
283     {
284       if(pflName.empty())
285         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
286       if(_type!=ON_GAUSS_PT)
287         {
288           locIds->setName(oss.str().c_str());
289           glob.appendProfile(locIds);
290           _profile=oss.str();
291         }
292     }
293   const DataArrayDouble *da=field->getArray();
294   _start=start;
295   switch(_type)
296     {
297     case ON_NODES:
298       {
299          _nval=idsInPfl->getNumberOfTuples();
300          getArray()->setContigPartOfSelectedValues2(_start,da,0,da->getNumberOfTuples(),1);
301          _end=_start+_nval;
302          break;
303       }
304     case ON_CELLS:
305       {
306         _nval=idsInPfl->getNumberOfTuples();
307         getArray()->setContigPartOfSelectedValues(_start,da,idsInPfl);
308         _end=_start+_nval;
309         break;
310       }
311     case ON_GAUSS_NE:
312       {
313         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
314         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr->deltaShiftIndex();
315         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
316         arr3->computeOffsets2();
317         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
318         int trueNval=tmp->getNumberOfTuples();
319         _nval=idsInPfl->getNumberOfTuples();
320         getArray()->setContigPartOfSelectedValues(_start,da,tmp);
321         _end=_start+trueNval;
322         break;
323       }
324     case ON_GAUSS_PT:
325       {
326         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
327         if(!disc2)
328           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
329         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
330         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
331         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
332         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
333         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
334         //
335         MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
336         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
337         //
338         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New();
339         int trueNval=0;
340         for(const int *pt=da4->begin();pt!=da4->end();pt++)
341           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
342         tmp->alloc(trueNval,1);
343         int *tmpPtr=tmp->getPointer();
344         for(const int *pt=da4->begin();pt!=da4->end();pt++)
345           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
346             *tmpPtr++=j;
347         //
348         _nval=da4->getNumberOfTuples();
349         getArray()->setContigPartOfSelectedValues(_start,da,tmp);
350         _end=_start+trueNval;
351         oss << "_loc_" << _loc_id;
352         if(locIds)
353           {
354             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
355             da5->setName(oss.str().c_str());
356             glob.appendProfile(da5);
357             _profile=oss.str();
358           }
359         else
360           {
361             if(da3->getNumberOfTuples()!=nbOfEltsInWholeMesh || !da3->isIdentity())
362               {
363                 da3->setName(oss.str().c_str());
364                 glob.appendProfile(da3);
365                 _profile=oss.str();
366               }
367           }
368         std::ostringstream oss2; oss2 << "Loc_" << getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
369         _localization=oss2.str();
370         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
371         break;
372       }
373     default:
374       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
375     }
376   start=_end;
377 }
378
379 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
380 {
381   _start=start;
382   _nval=field->getArray()->getNumberOfTuples();
383   getArray()->setContigPartOfSelectedValues2(_start,field->getArray(),0,_nval,1);
384   _end=_start+_nval;
385   start=_end;
386 }
387
388 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt) throw(INTERP_KERNEL::Exception)
389 {
390   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt);
391 }
392
393 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
394 {
395   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
396 }
397
398 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
399 {
400   return new MEDFileFieldPerMeshPerTypePerDisc(other);
401 }
402
403 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySize() const
404 {
405   return _profile.capacity()+_localization.capacity()+5*sizeof(int);
406 }
407
408 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const throw(INTERP_KERNEL::Exception)
409 {
410   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
411   ret->_father=father;
412   return ret.retn();
413 }
414
415 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt) throw(INTERP_KERNEL::Exception)
416 try:_type(atype),_father(fath)
417   {
418   }
419 catch(INTERP_KERNEL::Exception& e)
420 {
421   throw e;
422 }
423
424 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
425 {
426 }
427
428 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& 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),_tmp_work1(other._tmp_work1)
429 {
430 }
431
432 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
433                                                                        _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
434 {
435 }
436
437 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
438 {
439   return _father;
440 }
441
442 void MEDFileFieldPerMeshPerTypePerDisc::prepareLoading(med_idt fid, int profileIt, int& start) throw(INTERP_KERNEL::Exception)
443 {
444   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
445   INTERP_KERNEL::AutoPtr<char> pflname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
446   std::string fieldName=getName();
447   std::string meshName=getMeshName();
448   int iteration=getIteration();
449   int order=getOrder();
450   TypeOfField type=getType();
451   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
452   int profilesize,nbi;
453   med_geometry_type mgeoti;
454   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
455   _nval=MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,profileIt,MED_COMPACT_PFLMODE,
456                                   pflname,&profilesize,locname,&nbi);
457   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
458   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
459   _start=start;
460   _end=start+_nval*nbi;
461   start=_end;
462   if(type==ON_CELLS && !_localization.empty())
463     {
464       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
465         setType(ON_GAUSS_PT);
466       else
467         {
468           setType(ON_GAUSS_NE);
469           _localization.clear();
470         }
471     }
472 }
473
474 void MEDFileFieldPerMeshPerTypePerDisc::finishLoading(med_idt fid, int profileIt, int ft) throw(INTERP_KERNEL::Exception)
475 {
476   std::string fieldName=getName();
477   std::string meshName=getMeshName();
478   int iteration=getIteration();
479   int order=getOrder();
480   TypeOfField type=getType();
481   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
482   med_geometry_type mgeoti;
483   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
484   DataArrayDouble *arr=getArray();
485   double *startFeeding=arr->getPointer()+_start*arr->getNumberOfComponents();
486   switch(ft)
487     {
488     case 0:
489       {
490         MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
491                                    _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
492         break;
493       }
494     case 1:
495       {
496         INTERP_KERNEL::AutoPtr<int> tmpp=new int[(_end-_start)*arr->getNumberOfComponents()];
497         MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
498                                    _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>((int *)tmpp));
499         std::copy((const int *)tmpp,(const int *)tmpp+(_end-_start)*arr->getNumberOfComponents(),startFeeding);
500         break;
501       }
502     default:
503       throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
504     }
505 }
506
507 /*!
508  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
509  */
510 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart) throw(INTERP_KERNEL::Exception)
511 {
512   int delta=_end-_start;
513   _start=newValueOfStart;
514   _end=_start+delta;
515 }
516
517 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
518 {
519   return _father->getIteration();
520 }
521
522 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
523 {
524   return _father->getOrder();
525 }
526
527 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
528 {
529   return _father->getTime();
530 }
531
532 std::string MEDFileFieldPerMeshPerTypePerDisc::getName() const
533 {
534   return _father->getName();
535 }
536
537 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
538 {
539   return _father->getMeshName();
540 }
541
542 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
543 {
544   const char startLine[]="    ## ";
545   std::string startLine2(bkOffset,' ');
546   startLine2+=startLine;
547   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
548   oss << startLine2 << "Localization #" << id << "." << std::endl;
549   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
550   delete tmp;
551   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
552   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
553   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
554 }
555
556 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
557 {
558   return _type;
559 }
560
561 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
562 {
563   types.insert(_type);
564 }
565
566 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
567 {
568   _type=newType;
569 }
570
571 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
572 {
573   return _father->getGeoType();
574 }
575
576 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
577 {
578   return _father->getNumberOfComponents();
579 }
580
581 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
582 {
583   return _end-_start;
584 }
585
586 DataArrayDouble *MEDFileFieldPerMeshPerTypePerDisc::getArray()
587 {
588   return _father->getArray();
589 }
590
591 const DataArrayDouble *MEDFileFieldPerMeshPerTypePerDisc::getArray() const
592 {
593   const MEDFileFieldPerMeshPerType *fath=_father;
594   return fath->getArray();
595 }
596
597 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
598 {
599   return _father->getInfo();
600 }
601
602 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
603 {
604   return _profile;
605 }
606
607 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const char *newPflName)
608 {
609   _profile=newPflName;
610 }
611
612 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
613 {
614   return _localization;
615 }
616
617 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const char *newLocName)
618 {
619   _localization=newLocName;
620 }
621
622 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
623 {
624   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
625     {
626       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
627         {
628           _profile=(*it2).second;
629           return;
630         }
631     }
632 }
633
634 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
635 {
636   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
637     {
638       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
639         {
640           _localization=(*it2).second;
641           return;
642         }
643     }
644 }
645
646 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
647 {
648   if(type!=_type)
649     return ;
650   dads.push_back(std::pair<int,int>(_start,_end));
651   geoTypes.push_back(getGeoType());
652   if(_profile.empty())
653     pfls.push_back(0);
654   else
655     {
656       pfls.push_back(glob->getProfile(_profile.c_str()));
657     }
658   if(_localization.empty())
659     locs.push_back(-1);
660   else
661     {
662       locs.push_back(glob->getLocalizationId(_localization.c_str()));
663     }
664 }
665
666 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
667 {
668   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));
669   startEntryId++;
670 }
671
672 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
673 {
674   TypeOfField type=getType();
675   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
676   med_geometry_type mgeoti;
677   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
678   const DataArrayDouble *arr=getArray();
679   const double *locToWrite=arr->getConstPointer()+_start*arr->getNumberOfComponents();
680   MEDfieldValueWithProfileWr(fid,getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
681                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
682                              reinterpret_cast<const unsigned char*>(locToWrite));
683 }
684
685 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const throw(INTERP_KERNEL::Exception)
686 {
687   type=_type;
688   pfl=_profile;
689   loc=_localization;
690   dad.first=_start; dad.second=_end;
691 }
692
693 /*!
694  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
695  *             This code corresponds to the distribution of types in the corresponding mesh.
696  * \param [out] ptToFill memory zone where the output will be stored.
697  * \return the size of data pushed into output param \a ptToFill
698  */
699 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const throw(INTERP_KERNEL::Exception)
700 {
701   _loc_id=offset;
702   std::ostringstream oss;
703   std::size_t nbOfType=codeOfMesh.size()/3;
704   int found=-1;
705   for(std::size_t i=0;i<nbOfType && found==-1;i++)
706     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
707       found=(int)i;
708   if(found==-1)
709     {
710       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
711       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
712       throw INTERP_KERNEL::Exception(oss.str().c_str());
713     }
714   int *work=ptToFill;
715   if(_profile.empty())
716     {
717       if(_nval!=codeOfMesh[3*found+1])
718         {
719           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
720           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
721           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
722           throw INTERP_KERNEL::Exception(oss.str().c_str());
723         }
724       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
725         *work++=ii;
726     }
727   else
728     {
729       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
730       if(pfl->getNumberOfTuples()!=_nval)
731         {
732           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
733           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
734           oss << _nval;
735           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
736           throw INTERP_KERNEL::Exception(oss.str().c_str());
737         }
738       int offset2=codeOfMesh[3*found+2];
739       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
740         {
741           if(*pflId<codeOfMesh[3*found+1])
742             *work++=offset2+*pflId;
743         }
744     }
745   return _nval;
746 }
747
748 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const throw(INTERP_KERNEL::Exception)
749 {
750   for(int i=_start;i<_end;i++)
751     *ptToFill++=i;
752   return _end-_start;
753 }
754
755 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId) throw(INTERP_KERNEL::Exception)
756 {
757   switch(type)
758     {
759     case ON_CELLS:
760       return -2;
761     case ON_GAUSS_NE:
762       return -1;
763     case ON_GAUSS_PT:
764       return locId;
765     default:
766       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
767     }
768 }
769
770 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
771 {
772   int id=0;
773   std::map<std::pair<std::string,TypeOfField>,int> m;
774   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
775   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
776     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
777       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
778   ret.resize(id);
779   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
780     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
781   return ret;
782 }
783
784 /*!
785  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
786  * 
787  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
788  * \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.
789  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
790  * \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)
791  * \param [in,out] glob if necessary by the method, new profiles can be added to it
792  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
793  * \param [out] result All new entries will be appended on it.
794  * \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 !)
795  */
796 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
797                                                        const DataArrayInt *explicitIdsInMesh,
798                                                        const std::vector<int>& newCode,
799                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
800                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
801 {
802   if(entriesOnSameDisc.empty())
803     return false;
804   TypeOfField type=entriesOnSameDisc[0]->getType();
805   int szEntities=0,szTuples=0;
806   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
807     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
808   int nbi=szTuples/szEntities;
809   if(szTuples%szEntities!=0)
810     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
811   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
812   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
813   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
814   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
815   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
816   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
817   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
818   int id=0;
819   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
820     {
821       int startOfEltIdOfChunk=(*it)->_start;
822       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
823       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
824       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
825       //
826       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
827       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
828       //
829       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
830       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
831     }
832   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
833   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
834   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
835   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
836   //
837   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
838   //
839   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
840   arrPart->renumberInPlace(renumTupleIds->begin());
841   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
842   bool ret=false;
843   const int *idIt=diffVals->begin();
844   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
845   int offset2=0;
846   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
847     {
848       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
849       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
850       int nbEntityElts=subIds->getNumberOfTuples();
851       bool ret2;
852       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
853         NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
854                                     offset+offset2,
855                                     li,glob,ret2);
856       ret=ret || ret2;
857       result.push_back(eltToAdd);
858       offset2+=nbEntityElts*nbi;
859     }
860   ret=ret || li.empty();
861   return ret;
862 }
863
864 /*!
865  * \param [in] typeF type of field of new chunk
866  * \param [in] geoType the geometric type of the chunk
867  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
868  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
869  * \param [in] nbi number of integration points
870  * \param [in] offset The offset in the **global array of data**.
871  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
872  *                 to the new chunk to create.
873  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
874  * \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
875  *              and corresponding entry erased from \a entriesOnSameDisc.
876  * \return a newly allocated chunk
877  */
878 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
879                                                                                                   bool isPfl, int nbi, int offset,
880                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
881                                                                                                   MEDFileFieldGlobsReal& glob,
882                                                                                                   bool &notInExisting) throw(INTERP_KERNEL::Exception)
883 {
884   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
885   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
886   for(;it!=entriesOnSameDisc.end();it++)
887     {
888       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
889         {
890           if(!isPfl)
891             {
892               if((*it)->_profile.empty())
893                 break;
894               else
895                 if(!(*it)->_profile.empty())
896                   {
897                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
898                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
899                       break;
900                   }
901             }
902         }
903     }
904   if(it==entriesOnSameDisc.end())
905     {
906       notInExisting=true;
907       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
908       ret->_type=typeF;
909       ret->_loc_id=(int)geoType;
910       ret->_nval=nbMeshEntities;
911       ret->_start=offset;
912       ret->_end=ret->_start+ret->_nval*nbi;
913       if(isPfl)
914         {
915           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
916           glob.appendProfile(idsOfMeshElt);
917           ret->_profile=idsOfMeshElt->getName();
918         }
919       //tony treatment of localization
920       return ret;
921     }
922   else
923     {
924       notInExisting=false;
925       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
926       ret->_loc_id=(int)geoType;
927       ret->setNewStart(offset);
928       entriesOnSameDisc.erase(it);
929       return ret;
930     }
931   
932 }
933
934 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
935 {
936   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType);
937 }
938
939 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
940 {
941   return new MEDFileFieldPerMeshPerType(fath,geoType);
942 }
943
944 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySize() const
945 {
946   std::size_t ret=_field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
947   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
948     ret+=(*it)->getHeapMemorySize();
949   return ret;
950 }
951
952 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const throw(INTERP_KERNEL::Exception)
953 {
954   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
955   ret->_father=father;
956   std::size_t i=0;
957   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
958     {
959       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
960         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
961     }
962   return ret.retn();
963 }
964
965 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
966 {
967   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
968   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
969     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,glob);
970 }
971
972 /*!
973  * This method is the most general one. No optimization is done here.
974  * \param [in] multiTypePfl is the end user profile specified in high level API
975  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
976  * \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.
977  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
978  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
979  * \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.
980  */
981 void MEDFileFieldPerMeshPerType::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
982 {
983   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
984   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
985     _field_pm_pt_pd[*it]->assignFieldProfile(start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,mesh,glob);
986 }
987
988 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
989 {
990   _field_pm_pt_pd.resize(1);
991   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
992   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,glob);
993 }
994
995 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
996 {
997   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
998   //
999   _field_pm_pt_pd.resize(1);
1000   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1001   _field_pm_pt_pd[0]->assignFieldProfile(start,pfl,pfl2,pfl2,-1,field,0,glob);//mesh is not requested so 0 is send.
1002 }
1003
1004 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
1005 {
1006   TypeOfField type=field->getTypeOfField();
1007   if(type!=ON_GAUSS_PT)
1008     {
1009       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1010       int sz=_field_pm_pt_pd.size();
1011       bool found=false;
1012       for(int j=0;j<sz && !found;j++)
1013         {
1014           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1015             {
1016               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1017               found=true;
1018             }
1019         }
1020       if(!found)
1021         {
1022           _field_pm_pt_pd.resize(sz+1);
1023           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1024         }
1025       std::vector<int> ret(1,0);
1026       return ret;
1027     }
1028   else
1029     {
1030       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1031       int sz2=ret2.size();
1032       std::vector<int> ret3(sz2);
1033       int k=0;
1034       for(int i=0;i<sz2;i++)
1035         {
1036           int sz=_field_pm_pt_pd.size();
1037           int locIdToFind=ret2[i];
1038           bool found=false;
1039           for(int j=0;j<sz && !found;j++)
1040             {
1041               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1042                 {
1043                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1044                   ret3[k++]=j;
1045                   found=true;
1046                 }
1047             }
1048           if(!found)
1049             {
1050               _field_pm_pt_pd.resize(sz+1);
1051               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1052               ret3[k++]=sz;
1053             }
1054         }
1055       return ret3;
1056     }
1057 }
1058
1059 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
1060 {
1061   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1062   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1063   if(!disc2)
1064     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1065   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1066   if(!da)
1067     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1068   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1069   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1070   if(retTmp->presenceOfValue(-1))
1071     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1072   std::vector<int> ret(retTmp->begin(),retTmp->end());
1073   return ret;
1074 }
1075
1076 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1077 {
1078   TypeOfField type=field->getTypeOfField();
1079   if(type!=ON_GAUSS_PT)
1080     {
1081       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1082       int sz=_field_pm_pt_pd.size();
1083       bool found=false;
1084       for(int j=0;j<sz && !found;j++)
1085         {
1086           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1087             {
1088               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1089               found=true;
1090             }
1091         }
1092       if(!found)
1093         {
1094           _field_pm_pt_pd.resize(sz+1);
1095           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1096         }
1097       std::vector<int> ret(1,0);
1098       return ret;
1099     }
1100   else
1101     {
1102       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1103       int sz2=ret2.size();
1104       std::vector<int> ret3(sz2);
1105       int k=0;
1106       for(int i=0;i<sz2;i++)
1107         {
1108           int sz=_field_pm_pt_pd.size();
1109           int locIdToFind=ret2[i];
1110           bool found=false;
1111           for(int j=0;j<sz && !found;j++)
1112             {
1113               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1114                 {
1115                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1116                   ret3[k++]=j;
1117                   found=true;
1118                 }
1119             }
1120           if(!found)
1121             {
1122               _field_pm_pt_pd.resize(sz+1);
1123               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1124               ret3[k++]=sz;
1125             }
1126         }
1127       return ret3;
1128     }
1129 }
1130
1131 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1132 {
1133   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1134   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1135   if(!disc2)
1136     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1137   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1138   if(!da)
1139     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1140   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1141   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1142   if(retTmp->presenceOfValue(-1))
1143     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1144   std::vector<int> ret(retTmp->begin(),retTmp->end());
1145   return ret;
1146 }
1147
1148 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1149 {
1150   return _father;
1151 }
1152
1153 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1154 {
1155   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1156   int curDim=(int)cm.getDimension();
1157   dim=std::max(dim,curDim);
1158 }
1159
1160 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1161 {
1162   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1163     {
1164       (*it)->fillTypesOfFieldAvailable(types);
1165     }
1166 }
1167
1168 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 throw(INTERP_KERNEL::Exception)
1169 {
1170   int sz=_field_pm_pt_pd.size();
1171   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1172   for(int i=0;i<sz;i++)
1173     {
1174       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1175     }
1176 }
1177
1178 int MEDFileFieldPerMeshPerType::getIteration() const
1179 {
1180   return _father->getIteration();
1181 }
1182
1183 int MEDFileFieldPerMeshPerType::getOrder() const
1184 {
1185   return _father->getOrder();
1186 }
1187
1188 double MEDFileFieldPerMeshPerType::getTime() const
1189 {
1190   return _father->getTime();
1191 }
1192
1193 std::string MEDFileFieldPerMeshPerType::getName() const
1194 {
1195   return _father->getName();
1196 }
1197
1198 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1199 {
1200   return _father->getMeshName();
1201 }
1202
1203 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1204 {
1205   const char startLine[]="  ## ";
1206   std::string startLine2(bkOffset,' ');
1207   std::string startLine3(startLine2);
1208   startLine3+=startLine;
1209   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1210     {
1211       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1212       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1213     }
1214   else
1215     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1216   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1217   int i=0;
1218   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1219     {
1220       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1221       if(cur)
1222         cur->simpleRepr(bkOffset,oss,i);
1223       else
1224         {
1225           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1226         }
1227     }
1228 }
1229
1230 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1231 {
1232   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1233     {
1234       globalSz+=(*it)->getNumberOfTuples();
1235     }
1236   nbOfEntries+=(int)_field_pm_pt_pd.size();
1237 }
1238
1239 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1240 {
1241   return _geo_type;
1242 }
1243
1244
1245 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1246 {
1247   return _father->getNumberOfComponents();
1248 }
1249
1250 DataArrayDouble *MEDFileFieldPerMeshPerType::getArray()
1251 {
1252   return _father->getArray();
1253 }
1254
1255 const DataArrayDouble *MEDFileFieldPerMeshPerType::getArray() const
1256 {
1257   const MEDFileFieldPerMesh *fath=_father;
1258   return fath->getArray();
1259 }
1260
1261 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1262 {
1263   return _father->getInfo();
1264 }
1265
1266 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1267 {
1268   std::vector<std::string> ret;
1269   std::set<std::string> ret2;
1270   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1271     {
1272       std::string tmp=(*it1)->getProfile();
1273       if(!tmp.empty())
1274         if(ret2.find(tmp)==ret2.end())
1275           {
1276             ret.push_back(tmp);
1277             ret2.insert(tmp);
1278           }
1279     }
1280   return ret;
1281 }
1282
1283 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1284 {
1285   std::vector<std::string> ret;
1286   std::set<std::string> ret2;
1287   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1288     {
1289       std::string tmp=(*it1)->getLocalization();
1290       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1291         if(ret2.find(tmp)==ret2.end())
1292           {
1293             ret.push_back(tmp);
1294             ret2.insert(tmp);
1295           }
1296     }
1297   return ret;
1298 }
1299
1300 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1301 {
1302   std::vector<std::string> ret;
1303   std::set<std::string> ret2;
1304   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1305     {
1306       std::string tmp=(*it1)->getProfile();
1307       if(!tmp.empty())
1308         ret.push_back(tmp);
1309     }
1310   return ret;
1311 }
1312
1313 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1314 {
1315   std::vector<std::string> ret;
1316   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1317     {
1318       std::string tmp=(*it1)->getLocalization();
1319       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1320         ret.push_back(tmp);
1321     }
1322   return ret;
1323 }
1324
1325 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1326 {
1327   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1328     (*it1)->changePflsRefsNamesGen(mapOfModif);
1329 }
1330
1331 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1332 {
1333   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1334     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1335 }
1336
1337 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) throw(INTERP_KERNEL::Exception)
1338 {
1339   if(_field_pm_pt_pd.empty())
1340     {
1341       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1342       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1343       throw INTERP_KERNEL::Exception(oss.str().c_str());
1344     }
1345   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1346     return _field_pm_pt_pd[locId];
1347   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1348   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1349   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1350   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1351   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1352 }
1353
1354 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const throw(INTERP_KERNEL::Exception)
1355 {
1356   if(_field_pm_pt_pd.empty())
1357     {
1358       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1359       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1360       throw INTERP_KERNEL::Exception(oss.str().c_str());
1361     }
1362   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1363     return _field_pm_pt_pd[locId];
1364   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1365   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1366   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1367   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1368   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1369 }
1370
1371 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
1372 {
1373   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1374     {
1375       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1376       if(meshDim!=(int)cm.getDimension())
1377         return ;
1378     }
1379   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1380     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1381 }
1382
1383 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1384 {
1385   int i=0;
1386   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1387     {
1388       (*it)->fillValues(i,startEntryId,entries);
1389     }
1390 }
1391
1392 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1393 {
1394   _field_pm_pt_pd=leaves;
1395   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1396     (*it)->setFather(this);
1397 }
1398
1399 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType)
1400 {
1401 }
1402
1403 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType)
1404 {
1405   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1406   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1407   med_geometry_type mgeoti;
1408   med_entity_type menti=ConvertIntoMEDFileType(type,geoType,mgeoti);
1409   int nbProfiles=MEDfieldnProfile(fid,getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName);
1410   _field_pm_pt_pd.resize(nbProfiles);
1411   for(int i=0;i<nbProfiles;i++)
1412     {
1413       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i+1);
1414     }
1415 }
1416
1417 void MEDFileFieldPerMeshPerType::prepareLoading(med_idt fid, int &start) throw(INTERP_KERNEL::Exception)
1418 {
1419   int pflId=0;
1420   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1421     {
1422       (*it)->prepareLoading(fid,pflId+1,start);
1423     }
1424 }
1425
1426 void MEDFileFieldPerMeshPerType::finishLoading(med_idt fid, int ft) throw(INTERP_KERNEL::Exception)
1427 {
1428   int pflId=0;
1429   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1430     {
1431       (*it)->finishLoading(fid,pflId+1,ft);
1432     }
1433 }
1434
1435 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
1436 {
1437   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1438     {
1439       (*it)->copyOptionsFrom(*this);
1440       (*it)->writeLL(fid);
1441     }
1442 }
1443
1444 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1445 {
1446   switch(ikType)
1447     {
1448     case ON_CELLS:
1449       medfGeoType=typmai3[(int)ikGeoType];
1450       return MED_CELL;
1451     case ON_NODES:
1452       medfGeoType=MED_NONE;
1453       return MED_NODE;
1454     case ON_GAUSS_NE:
1455       medfGeoType=typmai3[(int)ikGeoType];
1456       return MED_NODE_ELEMENT;
1457     case ON_GAUSS_PT:
1458       medfGeoType=typmai3[(int)ikGeoType];
1459       return MED_CELL;
1460     default:
1461       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1462     }
1463   return MED_UNDEF_ENTITY_TYPE;
1464 }
1465
1466 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder) throw(INTERP_KERNEL::Exception)
1467 {
1468   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder);
1469 }
1470
1471 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1472 {
1473   return new MEDFileFieldPerMesh(fath,mesh);
1474 }
1475
1476 std::size_t MEDFileFieldPerMesh::getHeapMemorySize() const
1477 {
1478   std::size_t ret=_mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1479   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1480     if((const MEDFileFieldPerMeshPerType *)*it)
1481       ret+=(*it)->getHeapMemorySize();
1482   return ret;
1483 }
1484
1485 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileField1TSWithoutSDA *father) const throw(INTERP_KERNEL::Exception)
1486 {
1487   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1488   ret->_father=father;
1489   std::size_t i=0;
1490   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1491     {
1492       if((const MEDFileFieldPerMeshPerType *)*it)
1493         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1494     }
1495   return ret.retn();
1496 }
1497
1498 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1499 {
1500   std::string startLine(bkOffset,' ');
1501   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1502   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1503   int i=0;
1504   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1505     {
1506       const MEDFileFieldPerMeshPerType *cur=*it;
1507       if(cur)
1508         cur->simpleRepr(bkOffset,oss,i);
1509       else
1510         {
1511           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1512         }
1513     }
1514 }
1515
1516 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
1517 {
1518   _mesh_name=mesh->getName();
1519   mesh->getTime(_mesh_iteration,_mesh_order);
1520 }
1521
1522 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1523 {
1524   int nbOfTypes=code.size()/3;
1525   int offset=0;
1526   for(int i=0;i<nbOfTypes;i++)
1527     {
1528       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1529       int nbOfCells=code[3*i+1];
1530       int pos=addNewEntryIfNecessary(type);
1531       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,glob);
1532       offset+=nbOfCells;
1533     }
1534 }
1535
1536 /*!
1537  * This method is the most general one. No optimization is done here.
1538  * \param [in] multiTypePfl is the end user profile specified in high level API
1539  * \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].
1540  * \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.
1541  * \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.
1542  * \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.
1543  * \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.
1544  */
1545 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 MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1546 {
1547   int nbOfTypes=code.size()/3;
1548   for(int i=0;i<nbOfTypes;i++)
1549     {
1550       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1551       int pos=addNewEntryIfNecessary(type);
1552       DataArrayInt *pfl=0;
1553       if(code[3*i+2]!=-1)
1554         pfl=idsPerType[code[3*i+2]];
1555       int nbOfTupes2=code2.size()/3;
1556       int found=0;
1557       for(;found<nbOfTupes2;found++)
1558         if(code[3*i]==code2[3*found])
1559           break;
1560       if(found==nbOfTupes2)
1561         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1562       _field_pm_pt[pos]->assignFieldProfile(start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,mesh,glob);
1563     }
1564 }
1565
1566 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1567 {
1568   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1569   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,glob);
1570 }
1571
1572 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1573 {
1574   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1575   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,glob);
1576 }
1577
1578 void MEDFileFieldPerMesh::prepareLoading(med_idt fid, int& start) throw(INTERP_KERNEL::Exception)
1579 {
1580   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1581     (*it)->prepareLoading(fid,start);
1582 }
1583
1584 void MEDFileFieldPerMesh::finishLoading(med_idt fid, int ft) throw(INTERP_KERNEL::Exception)
1585 {
1586   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1587     (*it)->finishLoading(fid,ft);
1588 }
1589
1590 void MEDFileFieldPerMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
1591 {
1592   int nbOfTypes=_field_pm_pt.size();
1593   for(int i=0;i<nbOfTypes;i++)
1594     {
1595       _field_pm_pt[i]->copyOptionsFrom(*this);
1596       _field_pm_pt[i]->writeLL(fid);
1597     }
1598 }
1599
1600 void MEDFileFieldPerMesh::getDimension(int& dim) const
1601 {
1602   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1603     (*it)->getDimension(dim);
1604 }
1605
1606 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1607 {
1608   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1609     (*it)->fillTypesOfFieldAvailable(types);
1610 }
1611
1612 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 throw(INTERP_KERNEL::Exception)
1613 {
1614   int sz=_field_pm_pt.size();
1615   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1616   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1617   for(int i=0;i<sz;i++)
1618     {
1619       types[i]=_field_pm_pt[i]->getGeoType();
1620       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1621     }
1622   return ret;
1623 }
1624
1625 double MEDFileFieldPerMesh::getTime() const
1626 {
1627   int tmp1,tmp2;
1628   return _father->getTime(tmp1,tmp2);
1629 }
1630
1631 int MEDFileFieldPerMesh::getIteration() const
1632 {
1633   return _father->getIteration();
1634 }
1635
1636 const std::string& MEDFileFieldPerMesh::getDtUnit() const
1637 {
1638   return _father->getDtUnit();
1639 }
1640
1641 int MEDFileFieldPerMesh::getOrder() const
1642 {
1643   return _father->getOrder();
1644 }
1645
1646 std::string MEDFileFieldPerMesh::getName() const
1647 {
1648   return _father->getName();
1649 }
1650
1651 int MEDFileFieldPerMesh::getNumberOfComponents() const
1652 {
1653   return _father->getNumberOfComponents();
1654 }
1655
1656 DataArrayDouble *MEDFileFieldPerMesh::getArray()
1657 {
1658   return _father->getOrCreateAndGetArray();
1659 }
1660
1661 const DataArrayDouble *MEDFileFieldPerMesh::getArray() const
1662 {
1663   const MEDFileField1TSWithoutSDA *fath=_father;
1664   return fath->getOrCreateAndGetArray();
1665 }
1666
1667 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1668 {
1669   return _father->getInfo();
1670 }
1671
1672 /*!
1673  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1674  * 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.
1675  * It returns 2 output vectors :
1676  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1677  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1678  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1679  */
1680 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)
1681 {
1682   int notNullPflsSz=0;
1683   int nbOfArrs=geoTypes.size();
1684   for(int i=0;i<nbOfArrs;i++)
1685     if(pfls[i])
1686       notNullPflsSz++;
1687   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1688   int nbOfDiffGeoTypes=geoTypes3.size();
1689   code.resize(3*nbOfDiffGeoTypes);
1690   notNullPfls.resize(notNullPflsSz);
1691   notNullPflsSz=0;
1692   int j=0;
1693   for(int i=0;i<nbOfDiffGeoTypes;i++)
1694     {
1695       int startZone=j;
1696       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1697       std::vector<const DataArrayInt *> notNullTmp;
1698       if(pfls[j])
1699         notNullTmp.push_back(pfls[j]);
1700       j++;
1701       for(;j<nbOfArrs;j++)
1702         if(geoTypes[j]==refType)
1703           {
1704             if(pfls[j])
1705               notNullTmp.push_back(pfls[j]);
1706           }
1707         else
1708           break;
1709       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1710       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1711       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1712       code[3*i]=(int)refType;
1713       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1714       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1715       if(notNullTmp.empty())
1716         code[3*i+2]=-1;
1717       else
1718         {
1719           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1720           code[3*i+2]=notNullPflsSz++;
1721         }
1722     }
1723 }
1724
1725 /*!
1726  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1727  */
1728 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) throw(INTERP_KERNEL::Exception)
1729 {
1730   int sz=dads.size();
1731   int ret=0;
1732   for(int i=0;i<sz;i++)
1733     {
1734       if(locs[i]==-1)
1735         {
1736           if(type!=ON_GAUSS_NE)
1737             ret+=dads[i].second-dads[i].first;
1738           else
1739             {
1740               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1741               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1742             }
1743         }
1744       else
1745         {
1746           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1747           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1748         }
1749     }
1750   return ret;
1751 }
1752
1753 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1754 {
1755   std::vector<std::string> ret;
1756   std::set<std::string> ret2;
1757   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1758     {
1759       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1760       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1761         if(ret2.find(*it2)==ret2.end())
1762           {
1763             ret.push_back(*it2);
1764             ret2.insert(*it2);
1765           }
1766     }
1767   return ret;
1768 }
1769
1770 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1771 {
1772   std::vector<std::string> ret;
1773   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1774     {
1775       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1776       ret.insert(ret.end(),tmp.begin(),tmp.end());
1777     }
1778   return ret;
1779 }
1780
1781 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1782 {
1783   std::vector<std::string> ret;
1784   std::set<std::string> ret2;
1785   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1786     {
1787       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1788       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1789         if(ret2.find(*it2)==ret2.end())
1790           {
1791             ret.push_back(*it2);
1792             ret2.insert(*it2);
1793           }
1794     }
1795   return ret;
1796 }
1797
1798 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1799 {
1800   std::vector<std::string> ret;
1801   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1802     {
1803       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1804       ret.insert(ret.end(),tmp.begin(),tmp.end());
1805     }
1806   return ret;
1807 }
1808
1809 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
1810 {
1811   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1812     {
1813       if((*it).first==_mesh_name)
1814         {
1815           _mesh_name=(*it).second;
1816           return true;
1817         }
1818     }
1819   return false;
1820 }
1821
1822 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1823                                                       MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1824 {
1825   if(_mesh_name!=meshName)
1826     return false;
1827   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1828   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1829   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1830   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1831   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1832   DataArrayDouble *arr=getUndergroundDataArrayExt(entries);
1833   int sz=0;
1834   if(!arr)
1835     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1836   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1837     {
1838       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1839         {
1840           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1841           sz+=(*it).second.second-(*it).second.first;
1842         }
1843       else
1844         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1845     }
1846   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1847   ////////////////////
1848   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1849   int *workI2=explicitIdsOldInMesh->getPointer();
1850   int sz1=0,sz2=0,sid=1;
1851   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1852   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1853   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1854     {
1855       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1856       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1857       int *workI=explicitIdsOldInArr->getPointer();
1858       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1859         {
1860           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1861           (*itL2)->setLocId(sz2);
1862           (*itL2)->_tmp_work1=(*itL2)->getStart();
1863           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1864         }
1865       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1866     }
1867   explicitIdsOldInMesh->reAlloc(sz2);
1868   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1869   ////////////////////
1870   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1871   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1872   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1873   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1874     {
1875       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1876       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1877       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1878     }
1879   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1880   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1881   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
1882     {
1883       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1884       int newStart=elt->getLocId();
1885       elt->setLocId((*it)->getGeoType());
1886       elt->setNewStart(newStart);
1887       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
1888       entriesKeptNew.push_back(elt);
1889       entriesKeptNew2.push_back(elt);
1890     }
1891   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
1892   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
1893   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
1894   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
1895   bool ret=false;
1896   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
1897     {
1898       sid=0;
1899       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
1900         {
1901           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
1902           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
1903           }*/
1904       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
1905                                                             glob,arr2,otherEntriesNew) || ret;
1906     }
1907   if(!ret)
1908     return false;
1909   // Assign new dispatching
1910   assignNewLeaves(otherEntriesNew);
1911   arr->cpyFrom(*arr2);
1912   return true;
1913 }
1914
1915 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1916 {
1917   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
1918   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
1919     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
1920   //
1921   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
1922   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
1923   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
1924   for(;it1!=types.end();it1++,it2++)
1925     {
1926       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
1927       elt->setLeaves((*it1).second);
1928       *it2=elt;
1929     }
1930   _field_pm_pt=fieldPmPt;
1931 }
1932
1933 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1934 {
1935   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1936     (*it)->changePflsRefsNamesGen(mapOfModif);
1937 }
1938
1939 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1940 {
1941   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1942     (*it)->changeLocsRefsNamesGen(mapOfModif);
1943 }
1944
1945 /*!
1946  * \param [in] mesh is the whole mesh
1947  */
1948 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception)
1949 {
1950   if(_field_pm_pt.empty())
1951     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
1952   //
1953   std::vector< std::pair<int,int> > dads;
1954   std::vector<const DataArrayInt *> pfls;
1955   std::vector<DataArrayInt *> notNullPflsPerGeoType;
1956   std::vector<int> locs,code;
1957   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
1958   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1959     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
1960   // Sort by types
1961   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
1962   if(code.empty())
1963     {
1964       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << getName() << "\" exists but not with such spatial discretization or such dimension specified !";
1965       throw INTERP_KERNEL::Exception(oss.str().c_str());
1966     }
1967   //
1968   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
1969   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
1970   if(type!=ON_NODES)
1971     {
1972       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
1973       if(!arr)
1974         return finishField(type,glob,dads,locs,mesh,isPfl);
1975       else
1976         {
1977           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
1978           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl);
1979         }
1980     }
1981   else
1982     {
1983       if(code.size()!=3)
1984         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
1985       int nb=code[1];
1986       if(code[2]==-1)
1987         {
1988           if(nb!=mesh->getNumberOfNodes())
1989             {
1990               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
1991               oss << " nodes in mesh !";
1992               throw INTERP_KERNEL::Exception(oss.str().c_str());
1993             }
1994           return finishField(type,glob,dads,locs,mesh,isPfl);
1995         }
1996       else
1997         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl);
1998     }
1999 }
2000
2001 DataArrayDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
2002 {
2003   if(_field_pm_pt.empty())
2004     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2005   //
2006   std::vector<std::pair<int,int> > dads;
2007   std::vector<const DataArrayInt *> pfls;
2008   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2009   std::vector<int> locs,code;
2010   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2011   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2012     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2013   // Sort by types
2014   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2015   if(code.empty())
2016     {
2017       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2018       throw INTERP_KERNEL::Exception(oss.str().c_str());
2019     }
2020   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2021   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2022   if(type!=ON_NODES)
2023     {
2024       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2025       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2026     }
2027   else
2028     {
2029       if(code.size()!=3)
2030         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2031       int nb=code[1];
2032       if(code[2]==-1)
2033         {
2034           if(nb!=mesh->getNumberOfNodes())
2035             {
2036               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2037               oss << " nodes in mesh !";
2038               throw INTERP_KERNEL::Exception(oss.str().c_str());
2039             }
2040         }
2041       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2042     }
2043   //
2044   return 0;
2045 }
2046
2047 DataArrayDouble *MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
2048 {
2049   int globalSz=0;
2050   int nbOfEntries=0;
2051   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2052     {
2053       (*it)->getSizes(globalSz,nbOfEntries);
2054     }
2055   entries.resize(nbOfEntries);
2056   nbOfEntries=0;
2057   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2058     {
2059       (*it)->fillValues(nbOfEntries,entries);
2060     }
2061   return _father->getUndergroundDataArray();
2062 }
2063
2064 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
2065 {
2066   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2067     {
2068       if((*it)->getGeoType()==typ)
2069         return (*it)->getLeafGivenLocId(locId);
2070     }
2071   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2072   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2073   oss << "Possiblities are : ";
2074   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2075     {
2076       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2077       oss << "\"" << cm2.getRepr() << "\", ";
2078     }
2079   throw INTERP_KERNEL::Exception(oss.str().c_str());
2080 }
2081
2082 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
2083 {
2084   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2085     {
2086       if((*it)->getGeoType()==typ)
2087         return (*it)->getLeafGivenLocId(locId);
2088     }
2089   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2090   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2091   oss << "Possiblities are : ";
2092   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2093     {
2094       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2095       oss << "\"" << cm2.getRepr() << "\", ";
2096     }
2097   throw INTERP_KERNEL::Exception(oss.str().c_str());
2098 }
2099
2100 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2101 {
2102   int i=0;
2103   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2104   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2105   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2106     {
2107       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2108       if(type==curType)
2109         return i;
2110       else
2111         {
2112           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2113           if(pos>pos2)
2114             it2=it+1;
2115         }
2116     }
2117   int ret=std::distance(_field_pm_pt.begin(),it2);
2118   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2119   return ret;
2120 }
2121
2122 /*!
2123  * 'dads' and 'locs' input parameters have the same number of elements
2124  * \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
2125  */
2126 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2127                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2128                                                          const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception)
2129 {
2130   isPfl=false;
2131   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2132   ret->setMesh(mesh); ret->setName(getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(getDtUnit().c_str());
2133   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=getArray()->selectByTupleRanges(dads);
2134   const std::vector<std::string>& infos=getInfo();
2135   da->setInfoOnComponents(infos);
2136   da->setName("");
2137   ret->setArray(da);
2138   if(type==ON_GAUSS_PT)
2139     {
2140       int offset=0;
2141       int nbOfArrs=dads.size();
2142       for(int i=0;i<nbOfArrs;i++)
2143         {
2144           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2145           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2146           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2147           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2148           di->alloc(nbOfElems,1);
2149           di->iota(offset);
2150           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2151           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2152           offset+=nbOfElems;
2153         }
2154     }
2155   //
2156   return ret.retn();
2157 }
2158
2159 /*!
2160  * 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.
2161  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2162  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2163  * The order of cells in the returned field is those imposed by the profile.
2164  * \param [in] mesh is the global mesh.
2165  */
2166 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2167                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2168                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2169                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception)
2170 {
2171   if(da->isIdentity())
2172     {
2173       int nbOfTuples=da->getNumberOfTuples();
2174       if(nbOfTuples==mesh->getNumberOfCells())
2175         return finishField(type,glob,dads,locs,mesh,isPfl);
2176     }
2177   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2178   m2->setName(mesh->getName());
2179   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl);
2180   isPfl=true;
2181   return ret.retn();
2182 }
2183
2184 /*!
2185  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2186  */
2187 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2188                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2189                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception)
2190 {
2191   if(da->isIdentity())
2192     {
2193       int nbOfTuples=da->getNumberOfTuples();
2194       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2195         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl);
2196     }
2197   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2198   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2199   if(meshu)
2200     {
2201       if(meshu->getNodalConnectivity()==0)
2202         {
2203           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl);
2204           int nb=da->getNbOfElems();
2205           const int *ptr=da->getConstPointer();
2206           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2207           meshuc->allocateCells(nb);
2208           for(int i=0;i<nb;i++)
2209             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2210           meshuc->finishInsertingCells();
2211           ret->setMesh(meshuc);
2212           ret->checkCoherency();
2213           return ret.retn();
2214         }
2215     }
2216   //
2217   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl);
2218   isPfl=true;
2219   DataArrayInt *arr2=0;
2220   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2221   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2222   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2223   int nnodes=mesh2->getNumberOfNodes();
2224   if(nnodes==(int)da->getNbOfElems())
2225     {
2226       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2227       ret->getArray()->renumberInPlace(da3->getConstPointer());
2228       mesh2->setName(mesh->getName());
2229       ret->setMesh(mesh2);
2230       return ret.retn();
2231     }
2232   else
2233     {
2234       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 !!!";
2235       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2236       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2237       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2238       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2239       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2240       throw INTERP_KERNEL::Exception(oss.str().c_str());
2241     }
2242   return 0;
2243 }
2244
2245 /*!
2246  * This method is the most light method of field retrieving.
2247  */
2248 DataArrayDouble *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const throw(INTERP_KERNEL::Exception)
2249 {
2250   if(!pflIn)
2251     {
2252       pflOut=DataArrayInt::New();
2253       pflOut->alloc(nbOfElems,1);
2254       pflOut->iota(0);
2255     }
2256   else
2257     {
2258       pflOut=const_cast<DataArrayInt*>(pflIn);
2259       pflOut->incrRef();
2260     }
2261   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2262   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=getArray()->selectByTupleRanges(dads);
2263   const std::vector<std::string>& infos=getInfo();
2264   int nbOfComp=infos.size();
2265   for(int i=0;i<nbOfComp;i++)
2266     da->setInfoOnComponent(i,infos[i].c_str());
2267   safePfl->incrRef();
2268   return da.retn();
2269 }
2270
2271 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder) throw(INTERP_KERNEL::Exception):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2272                                                                                                                                                                        _mesh_csit(meshCsit),_father(fath)
2273 {
2274   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2275   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2276   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2277   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2278     {
2279       int nbProfile=MEDfield23nProfile(fid,getName().c_str(),getIteration(),getOrder(),MED_CELL,typmai[i],_mesh_csit,meshName,pflName,locName);
2280       if(nbProfile>0)
2281         {
2282           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i]));
2283           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2284         }
2285       nbProfile=MEDfield23nProfile(fid,getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],_mesh_csit,meshName,pflName,locName);
2286       if(nbProfile>0)
2287         {
2288           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_GAUSS_NE,typmai2[i]));
2289           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2290         }
2291     }
2292   int nbProfile=MEDfield23nProfile(fid,getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,_mesh_csit,meshName,pflName,locName);
2293   if(nbProfile>0)
2294     {
2295       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR));
2296       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2297     }
2298 }
2299
2300 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2301 {
2302   copyTinyInfoFrom(mesh);
2303 }
2304
2305 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
2306 {
2307   if(id>=(int)_pfls.size())
2308     _pfls.resize(id+1);
2309   _pfls[id]=DataArrayInt::New();
2310   int lgth=MEDprofileSizeByName(fid,pflName);
2311   _pfls[id]->setName(pflName);
2312   _pfls[id]->alloc(lgth,1);
2313   MEDprofileRd(fid,pflName,_pfls[id]->getPointer());
2314   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2315 }
2316
2317 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2318 {
2319   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2320   int sz;
2321   MEDprofileInfo(fid,i+1,pflName,&sz);
2322   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2323   if(i>=(int)_pfls.size())
2324     _pfls.resize(i+1);
2325   _pfls[i]=DataArrayInt::New();
2326   _pfls[i]->alloc(sz,1);
2327   _pfls[i]->setName(pflCpp.c_str());
2328   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2329   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2330 }
2331
2332 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
2333 {
2334   int nbOfPfls=_pfls.size();
2335   for(int i=0;i<nbOfPfls;i++)
2336     {
2337       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2338       cpy->applyLin(1,1,0);
2339       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2340       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2341       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2342     }
2343   //
2344   int nbOfLocs=_locs.size();
2345   for(int i=0;i<nbOfLocs;i++)
2346     _locs[i]->writeLL(fid);
2347 }
2348
2349 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps) throw(INTERP_KERNEL::Exception)
2350 {
2351   std::vector<std::string> pfls=getPfls();
2352   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2353     {
2354       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2355       if(it2==pfls.end())
2356         {
2357           _pfls.push_back(*it);
2358         }
2359       else
2360         {
2361           int id=std::distance(pfls.begin(),it2);
2362           if(!(*it)->isEqual(*_pfls[id]))
2363             {
2364               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2365               throw INTERP_KERNEL::Exception(oss.str().c_str());
2366             }
2367         }
2368     }
2369   std::vector<std::string> locs=getLocs();
2370   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2371     {
2372       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2373       if(it2==locs.end())
2374         {
2375           _locs.push_back(*it);
2376         }
2377       else
2378         {
2379           int id=std::distance(locs.begin(),it2);
2380           if(!(*it)->isEqual(*_locs[id],eps))
2381             {
2382               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2383               throw INTERP_KERNEL::Exception(oss.str().c_str());
2384             }
2385         }
2386     }
2387 }
2388
2389 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real) throw(INTERP_KERNEL::Exception)
2390 {
2391   std::vector<std::string> profiles=real.getPflsReallyUsed();
2392   int sz=profiles.size();
2393   _pfls.resize(sz);
2394   for(int i=0;i<sz;i++)
2395     loadProfileInFile(fid,i,profiles[i].c_str());
2396   //
2397   std::vector<std::string> locs=real.getLocsReallyUsed();
2398   sz=locs.size();
2399   _locs.resize(sz);
2400   for(int i=0;i<sz;i++)
2401     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2402 }
2403
2404 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2405 {
2406   int nProfil=MEDnProfile(fid);
2407   for(int i=0;i<nProfil;i++)
2408     loadProfileInFile(fid,i);
2409   int sz=MEDnLocalization(fid);
2410   _locs.resize(sz);
2411   for(int i=0;i<sz;i++)
2412     {
2413       _locs[i]=MEDFileFieldLoc::New(fid,i);
2414     }
2415 }
2416
2417 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const char *fname)
2418 {
2419   return new MEDFileFieldGlobs(fname);
2420 }
2421
2422 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2423 {
2424   return new MEDFileFieldGlobs;
2425 }
2426
2427 std::size_t MEDFileFieldGlobs::getHeapMemorySize() const
2428 {
2429   std::size_t ret=_file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2430   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2431     ret+=(*it)->getHeapMemorySize();
2432   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2433     ret+=(*it)->getHeapMemorySize();
2434   return ret;
2435 }
2436
2437 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const throw(INTERP_KERNEL::Exception)
2438 {
2439   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2440   std::size_t i=0;
2441   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2442     {
2443       if((const DataArrayInt *)*it)
2444         ret->_pfls[i]=(*it)->deepCpy();
2445     }
2446   i=0;
2447   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2448     {
2449       if((const MEDFileFieldLoc*)*it)
2450         ret->_locs[i]=(*it)->deepCpy();
2451     }
2452   return ret.retn();
2453 }
2454
2455 MEDFileFieldGlobs::MEDFileFieldGlobs(const char *fname):_file_name(fname)
2456 {
2457 }
2458
2459 MEDFileFieldGlobs::MEDFileFieldGlobs()
2460 {
2461 }
2462
2463 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2464 {
2465 }
2466
2467 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2468 {
2469   oss << "Profiles :\n";
2470   std::size_t n=_pfls.size();
2471   for(std::size_t i=0;i<n;i++)
2472     {
2473       oss << "  - #" << i << " ";
2474       const DataArrayInt *pfl=_pfls[i];
2475       if(pfl)
2476         oss << "\"" << pfl->getName() << "\"\n";
2477       else
2478         oss << "EMPTY !\n";
2479     }
2480   n=_locs.size();
2481   oss << "Localizations :\n";
2482   for(std::size_t i=0;i<n;i++)
2483     {
2484       oss << "  - #" << i << " ";
2485       const MEDFileFieldLoc *loc=_locs[i];
2486       if(loc)
2487         loc->simpleRepr(oss);
2488       else
2489         oss<< "EMPTY !\n";
2490     }
2491 }
2492
2493 void MEDFileFieldGlobs::setFileName(const char *fileName)
2494 {
2495   _file_name=fileName;
2496 }
2497
2498 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2499 {
2500   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2501     {
2502       DataArrayInt *elt(*it);
2503       if(elt)
2504         {
2505           std::string name(elt->getName());
2506           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2507             {
2508               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2509                 {
2510                   elt->setName((*it2).second.c_str());
2511                   return;
2512                 }
2513             }
2514         }
2515     }
2516 }
2517
2518 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2519 {
2520   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2521     {
2522       MEDFileFieldLoc *elt(*it);
2523       if(elt)
2524         {
2525           std::string name(elt->getName());
2526           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2527             {
2528               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2529                 {
2530                   elt->setName((*it2).second.c_str());
2531                   return;
2532                 }
2533             }
2534         }
2535     }
2536 }
2537
2538 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
2539 {
2540   if(locId<0 || locId>=(int)_locs.size())
2541     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2542   return _locs[locId]->getNbOfGaussPtPerCell();
2543 }
2544
2545 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
2546 {
2547   return getLocalizationFromId(getLocalizationId(locName));
2548 }
2549
2550 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
2551 {
2552   if(locId<0 || locId>=(int)_locs.size())
2553     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2554   return *_locs[locId];
2555 }
2556
2557 namespace ParaMEDMEMImpl
2558 {
2559   class LocFinder
2560   {
2561   public:
2562     LocFinder(const char *loc):_loc(loc) { }
2563     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2564   private:
2565     const char *_loc;
2566   };
2567
2568   class PflFinder
2569   {
2570   public:
2571     PflFinder(const std::string& pfl):_pfl(pfl) { }
2572     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2573   private:
2574     const std::string& _pfl;
2575   };
2576 }
2577
2578 int MEDFileFieldGlobs::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
2579 {
2580   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2581   if(it==_locs.end())
2582     {
2583       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2584       for(it=_locs.begin();it!=_locs.end();it++)
2585         oss << "\"" << (*it)->getName() << "\", ";
2586       throw INTERP_KERNEL::Exception(oss.str().c_str());
2587     }
2588   return std::distance(_locs.begin(),it);
2589 }
2590
2591 const DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
2592 {
2593   std::string pflNameCpp(pflName);
2594   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2595   if(it==_pfls.end())
2596     {
2597       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2598       for(it=_pfls.begin();it!=_pfls.end();it++)
2599         oss << "\"" << (*it)->getName() << "\", ";
2600       throw INTERP_KERNEL::Exception(oss.str().c_str());
2601     }
2602   return *it;
2603 }
2604
2605 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
2606 {
2607   if(pflId<0 || pflId>=(int)_pfls.size())
2608     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2609   return _pfls[pflId];
2610 }
2611
2612 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
2613 {
2614   if(locId<0 || locId>=(int)_locs.size())
2615     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2616   return *_locs[locId];
2617 }
2618
2619 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
2620 {
2621   return getLocalizationFromId(getLocalizationId(locName));
2622 }
2623
2624 DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
2625 {
2626   std::string pflNameCpp(pflName);
2627   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2628   if(it==_pfls.end())
2629     {
2630       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2631       for(it=_pfls.begin();it!=_pfls.end();it++)
2632         oss << "\"" << (*it)->getName() << "\", ";
2633       throw INTERP_KERNEL::Exception(oss.str().c_str());
2634     }
2635   return *it;
2636 }
2637
2638 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
2639 {
2640   if(pflId<0 || pflId>=(int)_pfls.size())
2641     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2642   return _pfls[pflId];
2643 }
2644
2645 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
2646 {
2647   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2648   int i=0;
2649   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2650     {
2651       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2652         newPfls.push_back(*it);
2653     }
2654   _pfls=newPfls;
2655 }
2656
2657 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
2658 {
2659   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2660   int i=0;
2661   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2662     {
2663       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2664         newLocs.push_back(*it);
2665     }
2666   _locs=newLocs;
2667 }
2668
2669 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2670 {
2671   int sz=_pfls.size();
2672   std::vector<std::string> ret(sz);
2673   for(int i=0;i<sz;i++)
2674     ret[i]=_pfls[i]->getName();
2675   return ret;
2676 }
2677
2678 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2679 {
2680   int sz=_locs.size();
2681   std::vector<std::string> ret(sz);
2682   for(int i=0;i<sz;i++)
2683     ret[i]=_locs[i]->getName();
2684   return ret;
2685 }
2686
2687 bool MEDFileFieldGlobs::existsPfl(const char *pflName) const
2688 {
2689   std::vector<std::string> v=getPfls();
2690   std::string s(pflName);
2691   return std::find(v.begin(),v.end(),s)!=v.end();
2692 }
2693
2694 bool MEDFileFieldGlobs::existsLoc(const char *locName) const
2695 {
2696   std::vector<std::string> v=getLocs();
2697   std::string s(locName);
2698   return std::find(v.begin(),v.end(),s)!=v.end();
2699 }
2700
2701 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2702 {
2703   std::map<int,std::vector<int> > m;
2704   int i=0;
2705   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2706     {
2707       const DataArrayInt *tmp=(*it);
2708       if(tmp)
2709         {
2710           m[tmp->getHashCode()].push_back(i);
2711         }
2712     }
2713   std::vector< std::vector<int> > ret;
2714   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2715     {
2716       if((*it2).second.size()>1)
2717         {
2718           std::vector<int> ret0;
2719           bool equalityOrNot=false;
2720           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2721             {
2722               std::vector<int>::const_iterator it4=it3; it4++;
2723               for(;it4!=(*it2).second.end();it4++)
2724                 {
2725                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2726                     {
2727                       if(!equalityOrNot)
2728                         ret0.push_back(*it3);
2729                       ret0.push_back(*it4);
2730                       equalityOrNot=true;
2731                     }
2732                 }
2733             }
2734           if(!ret0.empty())
2735             ret.push_back(ret0);
2736         }
2737     }
2738   return ret;
2739 }
2740
2741 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2742 {
2743   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2744 }
2745
2746 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
2747 {
2748   std::string name(pfl->getName());
2749   if(name.empty())
2750     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2751   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2752     if(name==(*it)->getName())
2753       {
2754         if(!pfl->isEqual(*(*it)))
2755           {
2756             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2757             throw INTERP_KERNEL::Exception(oss.str().c_str());
2758           }
2759       }
2760   pfl->incrRef();
2761   _pfls.push_back(pfl);
2762 }
2763
2764 void MEDFileFieldGlobs::appendLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w) throw(INTERP_KERNEL::Exception)
2765 {
2766   std::string name(locName);
2767   if(name.empty())
2768     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2769   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2770   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2771     if((*it)->isName(locName))
2772       {
2773         if(!(*it)->isEqual(*obj,1e-12))
2774           {
2775             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
2776             throw INTERP_KERNEL::Exception(oss.str().c_str());
2777           }
2778       }
2779   _locs.push_back(obj);
2780 }
2781
2782 std::string MEDFileFieldGlobs::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
2783 {
2784   std::vector<std::string> names=getPfls();
2785   return CreateNewNameNotIn("NewPfl_",names);
2786 }
2787
2788 std::string MEDFileFieldGlobs::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
2789 {
2790   std::vector<std::string> names=getLocs();
2791   return CreateNewNameNotIn("NewLoc_",names);
2792 }
2793
2794 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const char *prefix, const std::vector<std::string>& namesToAvoid) throw(INTERP_KERNEL::Exception)
2795 {
2796   for(std::size_t sz=0;sz<100000;sz++)
2797     {
2798       std::ostringstream tryName;
2799       tryName << prefix << sz;
2800       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
2801         return tryName.str();
2802     }
2803   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
2804 }
2805
2806 /*!
2807  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
2808  *  \param [in] fname - the file name.
2809  */
2810 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const char *fname):_globals(MEDFileFieldGlobs::New(fname))
2811 {
2812 }
2813
2814 /*!
2815  * Creates an empty MEDFileFieldGlobsReal.
2816  */
2817 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
2818 {
2819 }
2820
2821 std::size_t MEDFileFieldGlobsReal::getHeapMemorySize() const
2822 {
2823   std::size_t ret=0;
2824   if((const MEDFileFieldGlobs *)_globals)
2825     ret+=_globals->getHeapMemorySize();
2826   return ret;
2827 }
2828
2829 /*!
2830  * Returns a string describing profiles and Gauss points held in \a this.
2831  *  \return std::string - the description string.
2832  */
2833 void MEDFileFieldGlobsReal::simpleRepr(std::ostream& oss) const
2834 {
2835   oss << "Globals information on fields :" << "\n*******************************\n\n";
2836   const MEDFileFieldGlobs *glob=_globals;
2837   if(glob)
2838     glob->simpleRepr(oss);
2839   else
2840     oss << "NO GLOBAL INFORMATION !\n";
2841 }
2842
2843 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
2844 {
2845 }
2846
2847 /*!
2848  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
2849  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
2850  */
2851 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
2852 {
2853   _globals=other._globals;
2854 }
2855
2856 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
2857 {
2858   _globals=other._globals;
2859   if((const MEDFileFieldGlobs *)_globals)
2860     _globals=other._globals->deepCpy();
2861 }
2862
2863 /*!
2864  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
2865  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
2866  *  \param [in] eps - a precision used to compare Gauss points with same name held by
2867  *         \a this and \a other MEDFileFieldGlobsReal.
2868  *  \throw If \a this and \a other hold profiles with equal names but different ids.
2869  *  \throw If  \a this and \a other hold different Gauss points with equal names.
2870  */
2871 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps) throw(INTERP_KERNEL::Exception)
2872 {
2873   _globals->appendGlobs(*other._globals,eps);
2874 }
2875
2876 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
2877 {
2878   _globals->loadProfileInFile(fid,id,pflName);
2879 }
2880
2881 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
2882 {
2883   _globals->loadProfileInFile(fid,id);
2884 }
2885
2886 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2887 {
2888   _globals->loadGlobals(fid,*this);
2889 }
2890
2891 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2892 {
2893   _globals->loadAllGlobals(fid);
2894 }
2895
2896 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
2897 {
2898   _globals->writeGlobals(fid,opt);
2899 }
2900
2901 /*!
2902  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
2903  * or getPflsReallyUsedMulti().
2904  *  \return std::vector<std::string> - a sequence of names of all profiles.
2905  */
2906 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
2907 {
2908   return _globals->getPfls();
2909 }
2910
2911 /*!
2912  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
2913  * or getLocsReallyUsedMulti().
2914  *  \return std::vector<std::string> - a sequence of names of all localizations.
2915  */
2916 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
2917 {
2918   return _globals->getLocs();
2919 }
2920
2921 /*!
2922  * Checks if the profile with a given name exists.
2923  *  \param [in] pflName - the profile name of interest.
2924  *  \return bool - \c true if the profile named \a pflName exists.
2925  */
2926 bool MEDFileFieldGlobsReal::existsPfl(const char *pflName) const
2927 {
2928   return _globals->existsPfl(pflName);
2929 }
2930
2931 /*!
2932  * Checks if the localization with a given name exists.
2933  *  \param [in] locName - the localization name of interest.
2934  *  \return bool - \c true if the localization named \a locName exists.
2935  */
2936 bool MEDFileFieldGlobsReal::existsLoc(const char *locName) const
2937 {
2938   return _globals->existsLoc(locName);
2939 }
2940
2941 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
2942 {
2943   return _globals->createNewNameOfPfl();
2944 }
2945
2946 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
2947 {
2948   return _globals->createNewNameOfLoc();
2949 }
2950
2951 /*!
2952  * Sets the name of a MED file.
2953  *  \param [inout] fileName - the file name.
2954  */
2955 void MEDFileFieldGlobsReal::setFileName(const char *fileName)
2956 {
2957   _globals->setFileName(fileName);
2958 }
2959
2960 /*!
2961  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
2962  * in the same order.
2963  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
2964  *          Each item of this sequence is a vector containing ids of equal profiles.
2965  */
2966 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
2967 {
2968   return _globals->whichAreEqualProfiles();
2969 }
2970
2971 /*!
2972  * Finds equal localizations.
2973  *  \param [in] eps - a precision used to compare real values of the localizations.
2974  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
2975  *          Each item of this sequence is a vector containing ids of equal localizations.
2976  */
2977 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
2978 {
2979   return _globals->whichAreEqualLocs(eps);
2980 }
2981
2982 /*!
2983  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
2984  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
2985  *        this sequence is a pair whose 
2986  *        - the first item is a vector of profile names to replace by the second item,
2987  *        - the second item is a profile name to replace every profile name of the first item.
2988  */
2989 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2990 {
2991   _globals->changePflsNamesInStruct(mapOfModif);
2992 }
2993
2994 /*!
2995  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
2996  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
2997  *        this sequence is a pair whose 
2998  *        - the first item is a vector of localization names to replace by the second item,
2999  *        - the second item is a localization name to replace every localization name of the first item.
3000  */
3001 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3002 {
3003   _globals->changeLocsNamesInStruct(mapOfModif);
3004 }
3005
3006 /*!
3007  * Replaces references to some profiles (a reference is a profile name) by references
3008  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3009  * them-selves accordingly. <br>
3010  * This method is a generalization of changePflName().
3011  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3012  *        this sequence is a pair whose 
3013  *        - the first item is a vector of profile names to replace by the second item,
3014  *        - the second item is a profile name to replace every profile of the first item.
3015  * \sa changePflsRefsNamesGen()
3016  * \sa changePflName()
3017  */
3018 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3019 {
3020   changePflsRefsNamesGen(mapOfModif);
3021   changePflsNamesInStruct(mapOfModif);
3022 }
3023
3024 /*!
3025  * Replaces references to some localizations (a reference is a localization name) by references
3026  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3027  * them-selves accordingly. <br>
3028  * This method is a generalization of changeLocName().
3029  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3030  *        this sequence is a pair whose 
3031  *        - the first item is a vector of localization names to replace by the second item,
3032  *        - the second item is a localization name to replace every localization of the first item.
3033  * \sa changeLocsRefsNamesGen()
3034  * \sa changeLocName()
3035  */
3036 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3037 {
3038   changeLocsRefsNamesGen(mapOfModif);
3039   changeLocsNamesInStruct(mapOfModif);
3040 }
3041
3042 /*!
3043  * Renames the profile having a given name and updates references to this profile.
3044  *  \param [in] oldName - the name of the profile to rename.
3045  *  \param [in] newName - a new name of the profile.
3046  * \sa changePflsNames().
3047  */
3048 void MEDFileFieldGlobsReal::changePflName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
3049 {
3050   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3051   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3052   mapOfModif[0]=p;
3053   changePflsNames(mapOfModif);
3054 }
3055
3056 /*!
3057  * Renames the localization having a given name and updates references to this localization.
3058  *  \param [in] oldName - the name of the localization to rename.
3059  *  \param [in] newName - a new name of the localization.
3060  * \sa changeLocsNames().
3061  */
3062 void MEDFileFieldGlobsReal::changeLocName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
3063 {
3064   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3065   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3066   mapOfModif[0]=p;
3067   changeLocsNames(mapOfModif);
3068 }
3069
3070 /*!
3071  * Removes duplicated profiles. Returns a map used to update references to removed 
3072  * profiles via changePflsRefsNamesGen().
3073  * Equal profiles are found using whichAreEqualProfiles().
3074  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3075  *          a sequence describing the performed replacements of profiles. Each element of
3076  *          this sequence is a pair whose
3077  *          - the first item is a vector of profile names replaced by the second item,
3078  *          - the second item is a profile name replacing every profile of the first item.
3079  */
3080 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames() throw(INTERP_KERNEL::Exception)
3081 {
3082   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3083   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3084   int i=0;
3085   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3086     {
3087       std::vector< std::string > tmp((*it).size());
3088       int j=0;
3089       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3090         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3091       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3092       ret[i]=p;
3093       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3094       killProfileIds(tmp2);
3095     }
3096   changePflsRefsNamesGen(ret);
3097   return ret;
3098 }
3099
3100 /*!
3101  * Removes duplicated localizations. Returns a map used to update references to removed 
3102  * localizations via changeLocsRefsNamesGen().
3103  * Equal localizations are found using whichAreEqualLocs().
3104  *  \param [in] eps - a precision used to compare real values of the localizations.
3105  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3106  *          a sequence describing the performed replacements of localizations. Each element of
3107  *          this sequence is a pair whose
3108  *          - the first item is a vector of localization names replaced by the second item,
3109  *          - the second item is a localization name replacing every localization of the first item.
3110  */
3111 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps) throw(INTERP_KERNEL::Exception)
3112 {
3113   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3114   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3115   int i=0;
3116   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3117     {
3118       std::vector< std::string > tmp((*it).size());
3119       int j=0;
3120       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3121         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3122       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3123       ret[i]=p;
3124       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3125       killLocalizationIds(tmp2);
3126     }
3127   changeLocsRefsNamesGen(ret);
3128   return ret;
3129 }
3130
3131 /*!
3132  * Returns number of Gauss points per cell in a given localization.
3133  *  \param [in] locId - an id of the localization of interest.
3134  *  \return int - the number of the Gauss points per cell.
3135  */
3136 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
3137 {
3138   return _globals->getNbOfGaussPtPerCell(locId);
3139 }
3140
3141 /*!
3142  * Returns an id of a localization by its name.
3143  *  \param [in] loc - the localization name of interest.
3144  *  \return int - the id of the localization.
3145  *  \throw If there is no a localization named \a loc.
3146  */
3147 int MEDFileFieldGlobsReal::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
3148 {
3149   return _globals->getLocalizationId(loc);
3150 }
3151
3152 /*!
3153  * Returns the name of the MED file.
3154  *  \return const char * - the MED file name.
3155  */
3156 const char *MEDFileFieldGlobsReal::getFileName() const
3157 {
3158   return _globals->getFileName();
3159 }
3160
3161 std::string MEDFileFieldGlobsReal::getFileName2() const
3162 {
3163   return _globals->getFileName2();
3164 }
3165
3166 /*!
3167  * Returns a localization object by its name.
3168  *  \param [in] locName - the name of the localization of interest.
3169  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3170  *  \throw If there is no a localization named \a locName.
3171  */
3172 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
3173 {
3174   return _globals->getLocalization(locName);
3175 }
3176
3177 /*!
3178  * Returns a localization object by its id.
3179  *  \param [in] locId - the id of the localization of interest.
3180  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3181  *  \throw If there is no a localization with id \a locId.
3182  */
3183 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
3184 {
3185   return _globals->getLocalizationFromId(locId);
3186 }
3187
3188 /*!
3189  * Returns a profile array by its name.
3190  *  \param [in] pflName - the name of the profile of interest.
3191  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3192  *  \throw If there is no a profile named \a pflName.
3193  */
3194 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
3195 {
3196   return _globals->getProfile(pflName);
3197 }
3198
3199 /*!
3200  * Returns a profile array by its id.
3201  *  \param [in] pflId - the id of the profile of interest.
3202  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3203  *  \throw If there is no a profile with id \a pflId.
3204  */
3205 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
3206 {
3207   return _globals->getProfileFromId(pflId);
3208 }
3209
3210 /*!
3211  * Returns a localization object, apt for modification, by its id.
3212  *  \param [in] locId - the id of the localization of interest.
3213  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3214  *          having the id \a locId.
3215  *  \throw If there is no a localization with id \a locId.
3216  */
3217 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
3218 {
3219   return _globals->getLocalizationFromId(locId);
3220 }
3221
3222 /*!
3223  * Returns a localization object, apt for modification, by its name.
3224  *  \param [in] locName - the name of the localization of interest.
3225  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3226  *          having the name \a locName.
3227  *  \throw If there is no a localization named \a locName.
3228  */
3229 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
3230 {
3231   return _globals->getLocalization(locName);
3232 }
3233
3234 /*!
3235  * Returns a profile array, apt for modification, by its name.
3236  *  \param [in] pflName - the name of the profile of interest.
3237  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3238  *  \throw If there is no a profile named \a pflName.
3239  */
3240 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
3241 {
3242   return _globals->getProfile(pflName);
3243 }
3244
3245 /*!
3246  * Returns a profile array, apt for modification, by its id.
3247  *  \param [in] pflId - the id of the profile of interest.
3248  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3249  *  \throw If there is no a profile with id \a pflId.
3250  */
3251 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
3252 {
3253   return _globals->getProfileFromId(pflId);
3254 }
3255
3256 /*!
3257  * Removes profiles given by their ids. No data is updated to track this removal.
3258  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3259  */
3260 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
3261 {
3262   _globals->killProfileIds(pflIds);
3263 }
3264
3265 /*!
3266  * Removes localizations given by their ids. No data is updated to track this removal.
3267  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3268  */
3269 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
3270 {
3271   _globals->killLocalizationIds(locIds);
3272 }
3273
3274 /*!
3275  * Stores a profile array.
3276  *  \param [in] pfl - the profile array to store.
3277  *  \throw If the name of \a pfl is empty.
3278  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3279  *         different ids.
3280  */
3281 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
3282 {
3283   _globals->appendProfile(pfl);
3284 }
3285
3286 /*!
3287  * Adds a new localization of Gauss points.
3288  *  \param [in] locName - the name of the new localization.
3289  *  \param [in] geoType - a geometrical type of the reference cell.
3290  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3291  *         must be \c nbOfNodesPerCell * \c dimOfType.
3292  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3293  *         must be  _wg_.size() * \c dimOfType.
3294  *  \param [in] w - the weights of Gauss points.
3295  *  \throw If \a locName is empty.
3296  *  \throw If a localization with the name \a locName already exists but is
3297  *         different form the new one.
3298  */
3299 void MEDFileFieldGlobsReal::appendLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w) throw(INTERP_KERNEL::Exception)
3300 {
3301   _globals->appendLoc(locName,geoType,refCoo,gsCoo,w);
3302 }
3303
3304 /*!
3305  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3306  * empty. Returns -1 if this in on nodes.
3307  *  \return int - the dimension of \a this.
3308  */
3309 int MEDFileField1TSWithoutSDA::getDimension() const
3310 {
3311   int ret=-2;
3312   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3313     (*it)->getDimension(ret);
3314   return ret;
3315 }
3316
3317 /*!
3318  * Throws if a given value is not a valid (non-extended) relative dimension.
3319  *  \param [in] meshDimRelToMax - the relative dimension value.
3320  *  \throw If \a meshDimRelToMax > 0.
3321  */
3322 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
3323 {
3324   if(meshDimRelToMax>0)
3325     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
3326 }
3327
3328 /*!
3329  * Checks if elements of a given mesh are in the order suitable for writing 
3330  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
3331  * vector describing types of elements and their number.
3332  *  \param [in] mesh - the mesh to check.
3333  *  \return std::vector<int> - a vector holding for each element type (1) item of
3334  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
3335  *          These values are in full-interlace mode.
3336  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
3337  */
3338 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
3339 {
3340   //
3341   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
3342   int nbOfTypes=geoTypes.size();
3343   std::vector<int> code(3*nbOfTypes);
3344   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
3345   arr1->alloc(nbOfTypes,1);
3346   int *arrPtr=arr1->getPointer();
3347   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
3348   for(int i=0;i<nbOfTypes;i++,it++)
3349     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
3350   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
3351   const int *arrPtr2=arr2->getConstPointer();
3352   int i=0;
3353   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
3354     {
3355       int pos=arrPtr2[i];
3356       int nbCells=mesh->getNumberOfCellsWithType(*it);
3357       code[3*pos]=(int)(*it);
3358       code[3*pos+1]=nbCells;
3359       code[3*pos+2]=-1;//no profiles
3360     }
3361   std::vector<const DataArrayInt *> idsPerType;//no profiles
3362   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
3363   if(da)
3364     {
3365       da->decrRef();
3366       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
3367     }
3368   return code;
3369 }
3370
3371 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const char *fieldName, int csit, int fieldtype, int iteration, int order, const std::vector<std::string>& infos)
3372 {
3373   return new MEDFileField1TSWithoutSDA(fieldName,csit,fieldtype,iteration,order,infos);
3374 }
3375
3376 /*!
3377  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
3378  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
3379  * larger by the size of \a field. Returns an id of the first not filled
3380  * tuple of \a this->_arr.
3381  *  \param [in] field - the field to copy the info on components and the name from.
3382  *  \return int - the id of first not initialized tuple of \a this->_arr.
3383  *  \throw If the name of \a field is empty.
3384  *  \throw If the data array of \a field is not set.
3385  *  \throw If \a this->_arr is already allocated but has different number of components
3386  *         than \a field.
3387  */
3388 int MEDFileField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
3389 {
3390   std::string name(field->getName());
3391   getOrCreateAndGetArray()->setName(name.c_str());
3392   if(name.empty())
3393     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
3394   const DataArrayDouble *arr=field->getArray();
3395   if(!arr)
3396     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
3397   _dt=field->getTime(_iteration,_order);
3398   int nbOfComponents=arr->getNumberOfComponents();
3399   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
3400   if(!getOrCreateAndGetArray()->isAllocated())
3401     {
3402       _arr->alloc(arr->getNumberOfTuples(),arr->getNumberOfComponents());
3403       return 0;
3404     }
3405   else
3406     {
3407       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
3408       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
3409       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp=DataArrayDouble::New();
3410       tmp->alloc(newNbOfTuples,nbOfComponents);
3411       tmp->copyStringInfoFrom(*_arr);
3412       std::copy(_arr->begin(),_arr->end(),tmp->getPointer());
3413       _arr=tmp;
3414       return oldNbOfTuples;
3415     }
3416 }
3417
3418 /*!
3419  * Returns the name of \a this field.
3420  *  \return std::string - a string containing the field name.
3421  */
3422 std::string MEDFileField1TSWithoutSDA::getName() const
3423 {
3424   const DataArrayDouble *arr=getOrCreateAndGetArray();
3425   return arr->getName();
3426 }
3427
3428 /*!
3429  * Sets name of \a this field
3430  *  \param [in] name - the new field name.
3431  */
3432 void MEDFileField1TSWithoutSDA::setName(const char *name)
3433 {
3434   DataArrayDouble *arr=getOrCreateAndGetArray();
3435   arr->setName(name);
3436 }
3437
3438 /*!
3439  * Prints a string describing \a this field into a stream. This string is outputted 
3440  * by \c print Python command.
3441  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3442  *  \param [in,out] oss - the out stream.
3443  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3444  *          info id printed, else, not.
3445  */
3446 void MEDFileField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3447 {
3448   std::string startOfLine(bkOffset,' ');
3449   oss << startOfLine << "Field on One time Step ";
3450   if(f1tsId>=0)
3451     oss << "(" << f1tsId << ") ";
3452   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3453   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3454   const DataArrayDouble *arr=_arr;
3455   if(arr)
3456     {
3457       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3458       if(f1tsId<0)
3459         {
3460           oss << startOfLine << "Field Name : \"" << arr->getName() << "\"." << std::endl;
3461           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3462           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3463             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3464         }
3465       if(arr->isAllocated())
3466         {
3467           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3468         }
3469       else
3470         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3471     }
3472   else
3473     {
3474       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3475     }
3476   oss << startOfLine << "----------------------" << std::endl;
3477   if(!_field_per_mesh.empty())
3478     {
3479       int i=0;
3480       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3481         {
3482           const MEDFileFieldPerMesh *cur=(*it2);
3483           if(cur)
3484             cur->simpleRepr(bkOffset,oss,i);
3485           else
3486             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3487         }
3488     }
3489   else
3490     {
3491       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3492     }
3493   oss << startOfLine << "----------------------" << std::endl;
3494 }
3495
3496 /*!
3497  * Returns the mesh name.
3498  *  \return std::string - a string holding the mesh name.
3499  *  \throw If \c _field_per_mesh.empty()
3500  */
3501 std::string MEDFileField1TSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
3502 {
3503   if(_field_per_mesh.empty())
3504     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3505   return _field_per_mesh[0]->getMeshName();
3506 }
3507
3508 void MEDFileField1TSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
3509 {
3510   std::string oldName(getMeshName());
3511   std::vector< std::pair<std::string,std::string> > v(1);
3512   v[0].first=oldName; v[0].second=newMeshName;
3513   changeMeshNames(v);
3514 }
3515
3516 bool MEDFileField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
3517 {
3518   bool ret=false;
3519   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3520     {
3521       MEDFileFieldPerMesh *cur(*it);
3522       if(cur)
3523         ret=cur->changeMeshNames(modifTab) || ret;
3524     }
3525   return ret;
3526 }
3527
3528 bool MEDFileField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
3529                                                             MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
3530 {
3531   bool ret=false;
3532   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3533     {
3534       MEDFileFieldPerMesh *fpm(*it);
3535       if(fpm)
3536         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
3537     }
3538   return ret;
3539 }
3540
3541 /*!
3542  * Returns the number of iteration of the state of underlying mesh.
3543  *  \return int - the iteration number.
3544  *  \throw If \c _field_per_mesh.empty()
3545  */
3546 int MEDFileField1TSWithoutSDA::getMeshIteration() const throw(INTERP_KERNEL::Exception)
3547 {
3548   if(_field_per_mesh.empty())
3549     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3550   return _field_per_mesh[0]->getMeshIteration();
3551 }
3552
3553 /*!
3554  * Returns the order number of iteration of the state of underlying mesh.
3555  *  \return int - the order number.
3556  *  \throw If \c _field_per_mesh.empty()
3557  */
3558 int MEDFileField1TSWithoutSDA::getMeshOrder() const throw(INTERP_KERNEL::Exception)
3559 {
3560   if(_field_per_mesh.empty())
3561     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3562   return _field_per_mesh[0]->getMeshOrder();
3563 }
3564
3565 /*!
3566  * Returns number of components in \a this field
3567  *  \return int - the number of components.
3568  */
3569 int MEDFileField1TSWithoutSDA::getNumberOfComponents() const
3570 {
3571   return getOrCreateAndGetArray()->getNumberOfComponents();
3572 }
3573
3574 /*!
3575  * Checks if \a this field is tagged by a given iteration number and a given
3576  * iteration order number.
3577  *  \param [in] iteration - the iteration number of interest.
3578  *  \param [in] order - the iteration order number of interest.
3579  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3580  *          \a this->getOrder() == \a order.
3581  */
3582 bool MEDFileField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3583 {
3584   return iteration==_iteration && order==_order;
3585 }
3586
3587 /*!
3588  * Returns number of iteration and order number of iteration when
3589  * \a this field has been calculated.
3590  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3591  *          order number.
3592  */
3593 std::pair<int,int> MEDFileField1TSWithoutSDA::getDtIt() const
3594 {
3595   std::pair<int,int> p;
3596   fillIteration(p);
3597   return p;
3598 }
3599
3600 /*!
3601  * Returns number of iteration and order number of iteration when
3602  * \a this field has been calculated.
3603  *  \param [in,out] p - a pair returning the iteration number and the iteration
3604  *          order number.
3605  */
3606 void MEDFileField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3607 {
3608   p.first=_iteration;
3609   p.second=_order;
3610 }
3611
3612 /*!
3613  * Returns all types of spatial discretization of \a this field.
3614  *  \param [in,out] types - a sequence of types of \a this field.
3615  */
3616 void MEDFileField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
3617 {
3618   std::set<TypeOfField> types2;
3619   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3620     {
3621       (*it)->fillTypesOfFieldAvailable(types2);
3622     }
3623   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3624   std::copy(types2.begin(),types2.end(),bi);
3625 }
3626
3627 /*!
3628  * Returns info on components of \a this field.
3629  *  \return const std::vector<std::string>& - a sequence of strings each being an
3630  *          information on _i_-th component.
3631  */
3632 const std::vector<std::string>& MEDFileField1TSWithoutSDA::getInfo() const
3633 {
3634   const DataArrayDouble *arr=getOrCreateAndGetArray();
3635   return arr->getInfoOnComponents();
3636 }
3637
3638 /*!
3639  * Returns a mutable info on components of \a this field.
3640  *  \return std::vector<std::string>& - a sequence of strings each being an
3641  *          information on _i_-th component.
3642  */
3643 std::vector<std::string>& MEDFileField1TSWithoutSDA::getInfo()
3644 {
3645   DataArrayDouble *arr=getOrCreateAndGetArray();
3646   return arr->getInfoOnComponents();
3647 }
3648
3649 /*!
3650  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
3651  * maximal absolute dimension and values returned via the out parameter \a levs are 
3652  * dimensions relative to the maximal absolute dimension. <br>
3653  * This method is designed for MEDFileField1TS instances that have a discretization
3654  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
3655  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
3656  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
3657  * Only these 3 discretizations will be taken into account here. If \a this is
3658  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
3659  * This method is useful to make the link between the dimension of the underlying mesh
3660  * and the levels of \a this, because it is possible that the highest dimension of \a this
3661  * field is not equal to the dimension of the underlying mesh.
3662  * 
3663  * Let's consider the following case:
3664  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
3665  * TETRA4, HEXA8, TRI3 and SEG2.
3666  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
3667  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
3668  *
3669  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
3670  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
3671  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
3672  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
3673  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
3674  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
3675  * For example<br>
3676  * to retrieve the highest level of
3677  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
3678  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
3679  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
3680  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
3681  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3682  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3683  *          not checked if \a mname == \c NULL).
3684  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
3685  *          absolute one. They are in decreasing order. This sequence is cleared before
3686  *          filling it in.
3687  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
3688  *  \throw If no field is lying on \a mname.
3689  */
3690 int MEDFileField1TSWithoutSDA::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
3691 {
3692   levs.clear();
3693   int meshId=getMeshIdFromMeshName(mname);
3694   std::vector<INTERP_KERNEL::NormalizedCellType> types;
3695   std::vector< std::vector<TypeOfField> > typesF;
3696   std::vector< std::vector<std::string> > pfls, locs;
3697   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3698   if(types.empty())
3699     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
3700   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
3701   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
3702     return -1;
3703   st.erase(INTERP_KERNEL::NORM_ERROR);
3704   std::set<int> ret1;
3705   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
3706     {
3707       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
3708       ret1.insert((int)cm.getDimension());
3709     }
3710   int ret=*std::max_element(ret1.begin(),ret1.end());
3711   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
3712   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
3713   return ret;
3714 }
3715
3716 /*!
3717  * Returns all types of spatial discretization of \a this field.
3718  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3719  *          of \a this field.
3720  */
3721 std::vector<TypeOfField> MEDFileField1TSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
3722 {
3723   std::vector<TypeOfField> ret;
3724   fillTypesOfFieldAvailable(ret);
3725   return ret;
3726 }
3727
3728 /*!
3729  * Returns all attributes of parts of \a this field lying on a given mesh.
3730  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3731  * item of every of returned sequences refers to the _i_-th part of \a this field.
3732  * Thus all sequences returned by this method are of the same length equal to number
3733  * of different types of supporting entities.<br>
3734  * A field part can include sub-parts with several different spatial discretizations,
3735  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3736  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3737  * of a nested sequence corresponds to a type of spatial discretization.<br>
3738  * This method allows for iteration over MEDFile DataStructure without any overhead.
3739  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3740  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3741  *          not checked if \a mname == \c NULL).
3742  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3743  *          a field part is returned. 
3744  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3745  *          This sequence is of the same length as \a types. 
3746  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3747  *          discretization. A profile name can be empty.
3748  *          Length of this and of nested sequences is the same as that of \a typesF.
3749  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3750  *          discretization. A localization name can be empty.
3751  *          Length of this and of nested sequences is the same as that of \a typesF.
3752  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3753  *          of ids of tuples within the data array, per each type of spatial
3754  *          discretization within one mesh entity type. 
3755  *          Length of this and of nested sequences is the same as that of \a typesF.
3756  *  \throw If no field is lying on \a mname.
3757  */
3758 std::vector< std::vector< std::pair<int,int> > > MEDFileField1TSWithoutSDA::getFieldSplitedByType(const char *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 throw(INTERP_KERNEL::Exception)
3759 {
3760   int meshId=0;
3761   if(mname)
3762     meshId=getMeshIdFromMeshName(mname);
3763   else
3764     if(_field_per_mesh.empty())
3765       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3766   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3767 }
3768
3769 /*!
3770  * Returns all attributes and values of parts of \a this field lying on a given mesh.
3771  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3772  * item of every of returned sequences refers to the _i_-th part of \a this field.
3773  * Thus all sequences returned by this method are of the same length equal to number
3774  * of different types of supporting entities.<br>
3775  * A field part can include sub-parts with several different spatial discretizations,
3776  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3777  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3778  * of a nested sequence corresponds to a type of spatial discretization.<br>
3779  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
3780  * The overhead is due to selecting values into new instances of DataArrayDouble.
3781  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3782  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3783  *          not checked if \a mname == \c NULL).
3784  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3785  *          a field part is returned. 
3786  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3787  *          A field part can include sub-parts with several different spatial discretizations,
3788  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
3789  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
3790  *          This sequence is of the same length as \a types. 
3791  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3792  *          discretization. A profile name can be empty.
3793  *          Length of this and of nested sequences is the same as that of \a typesF.
3794  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3795  *          discretization. A localization name can be empty.
3796  *          Length of this and of nested sequences is the same as that of \a typesF.
3797  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
3798  *          per each type of spatial discretization within one mesh entity type.
3799  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
3800  *          Length of this and of nested sequences is the same as that of \a typesF.
3801  *  \throw If no field is lying on \a mname.
3802  */
3803 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TSWithoutSDA::getFieldSplitedByType2(const char *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 throw(INTERP_KERNEL::Exception)
3804 {
3805   int meshId=0;
3806   if(mname)
3807     meshId=getMeshIdFromMeshName(mname);
3808   else
3809     if(_field_per_mesh.empty())
3810       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3811   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3812   int nbOfRet=ret0.size();
3813   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
3814   for(int i=0;i<nbOfRet;i++)
3815     {
3816       const std::vector< std::pair<int,int> >& p=ret0[i];
3817       int nbOfRet1=p.size();
3818       ret[i].resize(nbOfRet1);
3819       for(int j=0;j<nbOfRet1;j++)
3820         {
3821           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
3822           ret[i][j]=tmp;
3823         }
3824     }
3825   return ret;
3826 }
3827
3828 void MEDFileField1TSWithoutSDA::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception)
3829 {
3830   med_int numdt,numit;
3831   med_float dt;
3832   med_int nmesh;
3833   med_bool localMesh;
3834   med_int meshnumdt,meshnumit;
3835   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3836   MEDfieldComputingStepInfo(fid,getName().c_str(),_csit,&numdt,&numit,&_dt);
3837   MEDfield23ComputingStepMeshInfo(fid,getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
3838   if(_iteration!=numdt || _order!=numit)
3839     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::finishLoading : unexpected exception internal error !");
3840   _field_per_mesh.resize(nmesh);
3841   for(int i=0;i<nmesh;i++)
3842     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i+1,meshnumdt,meshnumit);
3843   int start=0;
3844   for(int i=0;i<nmesh;i++)
3845     {
3846       _field_per_mesh[i]->prepareLoading(fid,start);
3847     }
3848   getOrCreateAndGetArray()->alloc(start,getNumberOfComponents());
3849   for(int i=0;i<nmesh;i++)
3850     {
3851       _field_per_mesh[i]->finishLoading(fid,_field_type);
3852     }
3853 }
3854
3855 std::vector<std::string> MEDFileField1TSWithoutSDA::getPflsReallyUsed2() const
3856 {
3857   std::vector<std::string> ret;
3858   std::set<std::string> ret2;
3859   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3860     {
3861       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3862       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3863         if(ret2.find(*it2)==ret2.end())
3864           {
3865             ret.push_back(*it2);
3866             ret2.insert(*it2);
3867           }
3868     }
3869   return ret;
3870 }
3871
3872 std::vector<std::string> MEDFileField1TSWithoutSDA::getLocsReallyUsed2() const
3873 {
3874   std::vector<std::string> ret;
3875   std::set<std::string> ret2;
3876   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3877     {
3878       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3879       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3880         if(ret2.find(*it2)==ret2.end())
3881           {
3882             ret.push_back(*it2);
3883             ret2.insert(*it2);
3884           }
3885     }
3886   return ret;
3887 }
3888
3889 std::vector<std::string> MEDFileField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3890 {
3891   std::vector<std::string> ret;
3892   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3893     {
3894       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3895       ret.insert(ret.end(),tmp.begin(),tmp.end());
3896     }
3897   return ret;
3898 }
3899
3900 std::vector<std::string> MEDFileField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3901 {
3902   std::vector<std::string> ret;
3903   std::set<std::string> ret2;
3904   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3905     {
3906       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3907       ret.insert(ret.end(),tmp.begin(),tmp.end());
3908     }
3909   return ret;
3910 }
3911
3912 void MEDFileField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3913 {
3914   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3915     (*it)->changePflsRefsNamesGen(mapOfModif);
3916 }
3917
3918 void MEDFileField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3919 {
3920   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3921     (*it)->changeLocsRefsNamesGen(mapOfModif);
3922 }
3923
3924 void MEDFileField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception)
3925 {
3926   if(_field_per_mesh.empty())
3927     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
3928   if(_field_per_mesh.size()>1)
3929     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
3930   _field_per_mesh[0]->copyOptionsFrom(opts);
3931   _field_per_mesh[0]->writeLL(fid);
3932 }
3933
3934 /*!
3935  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
3936  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
3937  * "Sort By Type"), if not, an exception is thrown. 
3938  *  \param [in] field - the field to add to \a this.
3939  *  \param [in,out] glob - the global data where profiles and localization present in
3940  *          \a field, if any, are added.
3941  *  \throw If the name of \a field is empty.
3942  *  \throw If the data array of \a field is not set.
3943  *  \throw If \a this->_arr is already allocated but has different number of components
3944  *         than \a field.
3945  *  \throw If the underlying mesh of \a field has no name.
3946  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
3947  */
3948 void MEDFileField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
3949 {
3950   const MEDCouplingMesh *mesh=field->getMesh();
3951   //
3952   TypeOfField type=field->getTypeOfField();
3953   std::vector<DataArrayInt *> dummy;
3954   int start=copyTinyInfoFrom(field);
3955   int pos=addNewEntryIfNecessary(mesh);
3956   if(type!=ON_NODES)
3957     {
3958       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
3959       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,glob);
3960     }
3961   else
3962     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,glob);
3963 }
3964
3965 /*!
3966  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
3967  * of a given mesh are used as the support of the given field (a real support is not used). 
3968  * Elements of the given mesh must be sorted suitable for writing to MED file. 
3969  * Order of underlying mesh entities of the given field specified by \a profile parameter
3970  * is not prescribed; this method permutes field values to have them sorted by element
3971  * type as required for writing to MED file. A new profile is added only if no equal
3972  * profile is missing. 
3973  *  \param [in] field - the field to add to \a this.
3974  *  \param [in] mesh - the supporting mesh of \a field.
3975  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
3976  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
3977  *  \param [in,out] glob - the global data where profiles and localization present in
3978  *          \a field, if any, are added.
3979  *  \throw If either \a field or \a mesh or \a profile has an empty name.
3980  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
3981  *  \throw If the data array of \a field is not set.
3982  *  \throw If \a this->_arr is already allocated but has different number of components
3983  *         than \a field.
3984  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
3985  *  \sa setFieldNoProfileSBT()
3986  */
3987 void MEDFileField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
3988 {
3989   TypeOfField type=field->getTypeOfField();
3990   int start=copyTinyInfoFrom(field);
3991   std::vector<DataArrayInt *> idsInPflPerType;
3992   std::vector<DataArrayInt *> idsPerType;
3993   std::vector<int> code,code2;
3994   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
3995   if(type!=ON_NODES)
3996     {
3997       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
3998       code2=m->getDistributionOfTypes();
3999       //
4000       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size());
4001       for(std::size_t i=0;i<idsInPflPerType.size();i++)
4002         idsInPflPerType2[i]=idsInPflPerType[i];
4003       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size());
4004       for(std::size_t i=0;i<idsPerType.size();i++)
4005         idsPerType2[i]=idsPerType[i];
4006       //
4007       int pos=addNewEntryIfNecessary(m);
4008       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,m,glob);
4009     }
4010   else
4011     {
4012       int pos=addNewEntryIfNecessary(m);
4013       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,glob);
4014     }
4015 }
4016
4017 /*!
4018  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4019  *  \param [in] type - a spatial discretization of the new field.
4020  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4021  *  \param [in] mName - a name of the supporting mesh.
4022  *  \param [in] renumPol - specifies how to permute values of the result field according to
4023  *          the optional numbers of cells and nodes, if any. The valid values are
4024  *          - 0 - do not permute.
4025  *          - 1 - permute cells.
4026  *          - 2 - permute nodes.
4027  *          - 3 - permute cells and nodes.
4028  *
4029  *  \param [in] glob - the global data storing profiles and localization.
4030  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4031  *          caller is to delete this field using decrRef() as it is no more needed. 
4032  *  \throw If the MED file is not readable.
4033  *  \throw If there is no mesh named \a mName in the MED file.
4034  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4035  *  \throw If no field of \a this is lying on the mesh \a mName.
4036  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4037  */
4038 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
4039 {
4040   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4041   if(mName==0)
4042     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4043   else
4044     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4045   return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm);
4046 }
4047
4048 /*!
4049  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4050  *  \param [in] type - a spatial discretization of the new field.
4051  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4052  *  \param [in] renumPol - specifies how to permute values of the result field according to
4053  *          the optional numbers of cells and nodes, if any. The valid values are
4054  *          - 0 - do not permute.
4055  *          - 1 - permute cells.
4056  *          - 2 - permute nodes.
4057  *          - 3 - permute cells and nodes.
4058  *
4059  *  \param [in] glob - the global data storing profiles and localization.
4060  *  \param [in] mesh - the supporting mesh.
4061  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4062  *          caller is to delete this field using decrRef() as it is no more needed. 
4063  *  \throw If the MED file is not readable.
4064  *  \throw If no field of \a this is lying on \a mesh.
4065  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4066  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4067  */
4068 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception)
4069 {
4070   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4071   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4072   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4073   if(meshDimRelToMax==1)
4074     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4075   return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e);
4076 }
4077
4078 /*!
4079  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4080  * given mesh. 
4081  *  \param [in] type - a spatial discretization of the new field.
4082  *  \param [in] mName - a name of the supporting mesh.
4083  *  \param [in] renumPol - specifies how to permute values of the result field according to
4084  *          the optional numbers of cells and nodes, if any. The valid values are
4085  *          - 0 - do not permute.
4086  *          - 1 - permute cells.
4087  *          - 2 - permute nodes.
4088  *          - 3 - permute cells and nodes.
4089  *
4090  *  \param [in] glob - the global data storing profiles and localization.
4091  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4092  *          caller is to delete this field using decrRef() as it is no more needed. 
4093  *  \throw If the MED file is not readable.
4094  *  \throw If there is no mesh named \a mName in the MED file.
4095  *  \throw If there are no mesh entities in the mesh.
4096  *  \throw If no field values of the given \a type are available.
4097  */
4098 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
4099 {
4100    MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4101   if(mName==0)
4102     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4103   else
4104     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4105   int absDim=getDimension();
4106   int meshDimRelToMax=absDim-mm->getMeshDimension();
4107   return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm);
4108 }
4109
4110 /*!
4111  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4112  *  \param [in] type - a spatial discretization of the new field.
4113  *  \param [in] renumPol - specifies how to permute values of the result field according to
4114  *          the optional numbers of cells and nodes, if any. The valid values are
4115  *          - 0 - do not permute.
4116  *          - 1 - permute cells.
4117  *          - 2 - permute nodes.
4118  *          - 3 - permute cells and nodes.
4119  *
4120  *  \param [in] glob - the global data storing profiles and localization.
4121  *  \param [in] mesh - the supporting mesh.
4122  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4123  *         field according to \a renumPol.
4124  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4125  *         field according to \a renumPol.
4126  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4127  *          caller is to delete this field using decrRef() as it is no more needed. 
4128  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4129  *  \throw If no field of \a this is lying on \a mesh.
4130  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4131  */
4132 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum) const throw(INTERP_KERNEL::Exception)
4133 {
4134   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4135   int meshId=getMeshIdFromMeshName(mesh->getName());
4136   bool isPfl=false;
4137   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl);
4138   switch(renumPol)
4139     {
4140     case 0:
4141       {
4142         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4143         return ret.retn();
4144       }
4145     case 3:
4146     case 1:
4147       {
4148         if(isPfl)
4149           throw INTERP_KERNEL::Exception(msg1);
4150         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4151         if(cellRenum)
4152           {
4153             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4154               {
4155                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4156                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4157                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4158               }
4159             ret->renumberCells(cellRenum->getConstPointer(),true);
4160           }
4161         if(renumPol==1)
4162           return ret.retn();
4163       }
4164     case 2:
4165       {
4166         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4167         if(isPfl)
4168           throw INTERP_KERNEL::Exception(msg1);
4169         if(nodeRenum)
4170           {
4171             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4172               {
4173                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4174                 oss << "\"" << getName() << "\" not defined on all nodes !";
4175                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4176               }
4177             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4178             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4179           }
4180         return ret.retn();
4181       }
4182     default:
4183       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4184     }
4185 }
4186
4187 /*!
4188  * Returns values and a profile of the field of a given type lying on a given support.
4189  *  \param [in] type - a spatial discretization of the field.
4190  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4191  *  \param [in] mesh - the supporting mesh.
4192  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4193  *          field of interest lies on. If the field lies on all entities of the given
4194  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4195  *          using decrRef() as it is no more needed.  
4196  *  \param [in] glob - the global data storing profiles and localization.
4197  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4198  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4199  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4200  *  \throw If no field of \a this is lying on \a mesh.
4201  *  \throw If no field values of the given \a type are available.
4202  */
4203 DataArrayDouble *MEDFileField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
4204 {
4205   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4206   int meshId=getMeshIdFromMeshName(mesh->getName());
4207   return _field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob);
4208 }
4209
4210 /*!
4211  * Returns a pointer to the underground DataArrayDouble instance. So the
4212  * caller should not decrRef() it. This method allows for a direct access to the field
4213  * values. This method is quite unusable if there is more than a nodal field or a cell
4214  * field on single geometric cell type. 
4215  *  \return DataArrayDouble * - the pointer to the field values array.
4216  */
4217 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4218 {
4219   const DataArrayDouble *ret=_arr;
4220   if(ret)
4221     return const_cast<DataArrayDouble *>(ret);
4222   else
4223     return 0;
4224 }
4225
4226 /*!
4227  * Returns a pointer to the underground DataArrayDouble instance and a
4228  * sequence describing parameters of a support of each part of \a this field. The
4229  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4230  * direct access to the field values. This method is intended for the field lying on one
4231  * mesh only.
4232  *  \param [in,out] entries - the sequence describing parameters of a support of each
4233  *         part of \a this field. Each item of this sequence consists of two parts. The
4234  *         first part describes a type of mesh entity and an id of discretization of a
4235  *         current field part. The second part describes a range of values [begin,end)
4236  *         within the returned array relating to the current field part.
4237  *  \return DataArrayDouble * - the pointer to the field values array.
4238  *  \throw If the number of underlying meshes is not equal to 1.
4239  *  \throw If no field values are available.
4240  *  \sa getUndergroundDataArray()
4241  */
4242 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4243 {
4244   if(_field_per_mesh.size()!=1)
4245     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4246   if(_field_per_mesh[0]==0)
4247     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4248   return _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4249 }
4250
4251 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const char *fieldName, int csit, int fieldtype, int iteration, int order,
4252                                                      const std::vector<std::string>& infos):_iteration(iteration),_order(order),_csit(csit),_field_type(fieldtype)
4253 {
4254   DataArrayDouble *arr=getOrCreateAndGetArray();
4255   arr->setName(fieldName);
4256   arr->setInfoAndChangeNbOfCompo(infos);
4257 }
4258
4259 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():_csit(-1),_field_type(-1)
4260 {
4261 }
4262
4263 int MEDFileField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
4264 {
4265   std::string tmp(mesh->getName());
4266   if(tmp.empty())
4267     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4268   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4269   int i=0;
4270   for(;it!=_field_per_mesh.end();it++,i++)
4271     {
4272       if((*it)->getMeshName()==tmp)
4273         return i;
4274     }
4275   int sz=_field_per_mesh.size();
4276   _field_per_mesh.resize(sz+1);
4277   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4278   return sz;
4279 }
4280
4281 /*!
4282  * \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.
4283  */
4284 int MEDFileField1TSWithoutSDA::getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception)
4285 {
4286   if(_field_per_mesh.empty())
4287     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4288   if(mName==0)
4289     return 0;
4290   std::string mName2(mName);
4291   int ret=0;
4292   std::vector<std::string> msg;
4293   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4294     if(mName2==(*it)->getMeshName())
4295       return ret;
4296     else
4297       msg.push_back((*it)->getMeshName());
4298   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4299   oss << "Possible meshes are : ";
4300   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4301     oss << "\"" << (*it2) << "\" ";
4302   throw INTERP_KERNEL::Exception(oss.str().c_str());
4303 }
4304
4305 /*!
4306  * \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.
4307  * \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.
4308  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4309  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4310  */
4311 MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
4312 {
4313   int mid=getMeshIdFromMeshName(mName);
4314   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4315 }
4316
4317 /*!
4318  * \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.
4319  * \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.
4320  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4321  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4322  */
4323 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
4324 {
4325   int mid=getMeshIdFromMeshName(mName);
4326   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4327 }
4328
4329 std::size_t MEDFileField1TSWithoutSDA::getHeapMemorySize() const
4330 {
4331   std::size_t ret=_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4332   if((const DataArrayDouble *)_arr)
4333     ret+=_arr->getHeapMemorySize();
4334   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4335     ret+=(*it)->getHeapMemorySize();
4336   return ret;
4337 }
4338
4339 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
4340 {
4341   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=new MEDFileField1TSWithoutSDA(*this);
4342   if((const DataArrayDouble *)_arr)
4343     ret->_arr=_arr->deepCpy();
4344   std::size_t i=0;
4345   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,i++)
4346     {
4347       if((const MEDFileFieldPerMesh *)*it)
4348         ret->_field_per_mesh[i]=(*it)->deepCpy((MEDFileField1TSWithoutSDA *)ret);
4349     }
4350   return ret.retn();
4351 }
4352
4353 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
4354 {
4355   DataArrayDouble *ret=_arr;
4356   if(ret)
4357     return ret;
4358   _arr=DataArrayDouble::New();
4359   return _arr;
4360 }
4361
4362 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
4363 {
4364   const DataArrayDouble *ret=_arr;
4365   if(ret)
4366     return ret;
4367   DataArrayDouble *ret2=DataArrayDouble::New();
4368   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
4369   return ret2;
4370 }
4371
4372 /*!
4373  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
4374  * the first field that has been read from a specified MED file.
4375  *  \param [in] fileName - the name of the MED file to read.
4376  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
4377  *          is to delete this field using decrRef() as it is no more needed.
4378  *  \throw If reading the file fails.
4379  */
4380 MEDFileField1TS *MEDFileField1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
4381 {
4382   return new MEDFileField1TS(fileName);
4383 }
4384
4385 /*!
4386  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
4387  * a given field that has been read from a specified MED file.
4388  *  \param [in] fileName - the name of the MED file to read.
4389  *  \param [in] fieldName - the name of the field to read.
4390  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
4391  *          is to delete this field using decrRef() as it is no more needed.
4392  *  \throw If reading the file fails.
4393  *  \throw If there is no field named \a fieldName in the file.
4394  */
4395 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
4396 {
4397   return new MEDFileField1TS(fileName,fieldName);
4398 }
4399
4400 /*!
4401  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
4402  * a given field that has been read from a specified MED file.
4403  *  \param [in] fileName - the name of the MED file to read.
4404  *  \param [in] fieldName - the name of the field to read.
4405  *  \param [in] iteration - the iteration number of a required time step.
4406  *  \param [in] order - the iteration order number of required time step.
4407  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
4408  *          is to delete this field using decrRef() as it is no more needed.
4409  *  \throw If reading the file fails.
4410  *  \throw If there is no field named \a fieldName in the file.
4411  *  \throw If the required time step is missing from the file.
4412  */
4413 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
4414 {
4415   return new MEDFileField1TS(fileName,fieldName,iteration,order);
4416 }
4417
4418 /*!
4419  * Returns a new instance of MEDFileField1TS holding either deep or shallow copy
4420  * of a given MEDFileField1TSWithoutSDA.
4421  * \warning this is a shallow copy constructor
4422  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
4423  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
4424  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
4425  *          is to delete this field using decrRef() as it is no more needed.
4426  */
4427 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
4428 {
4429   return new MEDFileField1TS(other,shallowCopyOfContent);
4430 }
4431
4432 /*!
4433  * Returns a new empty instance of MEDFileField1TS.
4434  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
4435  *          is to delete this field using decrRef() as it is no more needed.
4436  */
4437 MEDFileField1TS *MEDFileField1TS::New()
4438 {
4439   return new MEDFileField1TS;
4440 }
4441
4442 /*!
4443  * Returns a string describing \a this field. This string is outputted 
4444  * by \c print Python command.
4445  */
4446 std::string MEDFileField1TS::simpleRepr() const
4447 {
4448   std::ostringstream oss;
4449   _content->simpleRepr(0,oss,-1);
4450   MEDFileFieldGlobsReal::simpleRepr(oss);
4451   return oss.str();
4452 }
4453
4454 void MEDFileField1TS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
4455 {
4456   int nbComp=getNumberOfComponents();
4457   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
4458   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
4459   for(int i=0;i<nbComp;i++)
4460     {
4461       std::string info=getInfo()[i];
4462       std::string c,u;
4463       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
4464       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
4465       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
4466     }
4467   if(getName().empty())
4468     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
4469   MEDfieldCr(fid,getName().c_str(),MED_FLOAT64,nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
4470   writeGlobals(fid,*this);
4471   _content->writeLL(fid,*this);
4472 }
4473
4474 /*!
4475  * Writes \a this field into a MED file specified by its name.
4476  *  \param [in] fileName - the MED file name.
4477  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
4478  * - 2 - erase; an existing file is removed.
4479  * - 1 - append; same data should not be present in an existing file.
4480  * - 0 - overwrite; same data present in an existing file is overwritten.
4481  *  \throw If the field name is not set.
4482  *  \throw If no field data is set.
4483  *  \throw If \a mode == 1 and the same data is present in an existing file.
4484  */
4485 void MEDFileField1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
4486 {
4487   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
4488   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
4489   writeLL(fid);
4490 }
4491
4492 MEDFileField1TS::MEDFileField1TS(const char *fileName) throw(INTERP_KERNEL::Exception)
4493 try:MEDFileFieldGlobsReal(fileName)
4494 {
4495   MEDFileUtilities::CheckFileForRead(fileName);
4496   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
4497   med_field_type typcha;
4498   //
4499   int nbFields=MEDnField(fid);
4500   if(nbFields<1)
4501     {
4502       std::ostringstream oss; oss << "MEDFileField1TS(fileName) : no field present in file \'" << fileName << "\' !";
4503       throw INTERP_KERNEL::Exception(oss.str().c_str());
4504     }
4505   int ncomp=MEDfieldnComponent(fid,1);
4506   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4507   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4508   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
4509   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4510   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4511   med_bool localMesh;
4512   int nbOfStep;
4513   MEDfieldInfo(fid,1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
4514   std::string fieldName(nomcha);
4515   if(nbOfStep<1)
4516     {
4517       std::ostringstream oss; oss << "MEDFileField1TS(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
4518       throw INTERP_KERNEL::Exception(oss.str().c_str());
4519     }
4520   std::vector<std::string> infos(ncomp);
4521   for(int j=0;j<ncomp;j++)
4522     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
4523   _content=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4524   _content->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
4525   //
4526   med_int numdt,numit;
4527   med_float dt;
4528   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
4529   _content->setTime(numdt,numit,dt);
4530   _content->_csit=1;
4531   _content->_field_type=MEDFileUtilities::TraduceFieldType(typcha);
4532   _content->finishLoading(fid);
4533   //
4534   loadGlobals(fid);
4535 }
4536 catch(INTERP_KERNEL::Exception& e)
4537   {
4538     throw e;
4539   }
4540
4541 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
4542 try:MEDFileFieldGlobsReal(fileName),_content(MEDFileField1TSWithoutSDA::New(fieldName,-1,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>()))
4543 {
4544   MEDFileUtilities::CheckFileForRead(fileName);
4545   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
4546   med_field_type typcha;
4547   int nbSteps=locateField(fid,fileName,fieldName,typcha);
4548   if(nbSteps<1)
4549     {
4550       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
4551       throw INTERP_KERNEL::Exception(oss.str().c_str());
4552     }
4553   //
4554   med_int numdt,numit;
4555   med_float dt;
4556   MEDfieldComputingStepInfo(fid,fieldName,1,&numdt,&numit,&dt);
4557   _content->setTime(numdt,numit,dt);
4558   _content->_csit=1;
4559   _content->_field_type=MEDFileUtilities::TraduceFieldType(typcha);
4560   _content->finishLoading(fid);
4561   //
4562   loadGlobals(fid);
4563 }
4564 catch(INTERP_KERNEL::Exception& e)
4565   {
4566     throw e;
4567   }
4568
4569 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
4570 try:MEDFileFieldGlobsReal(fileName),_content(MEDFileField1TSWithoutSDA::New(fieldName,-1,-1,iteration,order,std::vector<std::string>()))
4571 {
4572   MEDFileUtilities::CheckFileForRead(fileName);
4573   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
4574   med_field_type typcha;
4575   int nbOfStep2=locateField(fid,fileName,fieldName,typcha);
4576   bool found=false;
4577   std::vector< std::pair<int,int> > dtits(nbOfStep2);
4578   for(int i=0;i<nbOfStep2 && !found;i++)
4579     {
4580       med_int numdt,numit;
4581       med_float dt;
4582       MEDfieldComputingStepInfo(fid,fieldName,i+1,&numdt,&numit,&dt);
4583       if(numdt==iteration && numit==order)
4584         {
4585           found=true;
4586           _content->_csit=i+1;
4587           _content->_field_type=MEDFileUtilities::TraduceFieldType(typcha);
4588         }
4589       else
4590         dtits[i]=std::pair<int,int>(numdt,numit);
4591     }
4592   if(!found)
4593     {
4594       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
4595       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
4596         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
4597       throw INTERP_KERNEL::Exception(oss.str().c_str());
4598     }
4599   _content->finishLoading(fid);
4600   //
4601   loadGlobals(fid);
4602 }
4603 catch(INTERP_KERNEL::Exception& e)
4604   {
4605     throw e;
4606   }
4607
4608 /*!
4609  * \warning this is a shallow copy constructor
4610  */
4611 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
4612 {
4613   if(!shallowCopyOfContent)
4614     {
4615       const MEDFileField1TSWithoutSDA *otherPtr(&other);
4616       otherPtr->incrRef();
4617       _content=const_cast<MEDFileField1TSWithoutSDA *>(otherPtr);
4618     }
4619   else
4620     {
4621       _content=new MEDFileField1TSWithoutSDA(other);
4622     }
4623 }
4624
4625 MEDFileField1TS::MEDFileField1TS():_content(new MEDFileField1TSWithoutSDA)
4626 {
4627 }
4628
4629 /*!
4630  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
4631  * 
4632  * \param [out]
4633  * \return in case of success the number of time steps available for the field with name \a fieldName.
4634  */
4635 int MEDFileField1TS::locateField(med_idt fid, const char *fileName, const char *fieldName, med_field_type& typcha) throw(INTERP_KERNEL::Exception)
4636 {
4637   int nbFields=MEDnField(fid);
4638   bool found=false;
4639   std::vector<std::string> fns(nbFields);
4640   int nbOfStep2=-1;
4641   for(int i=0;i<nbFields && !found;i++)
4642     {
4643       int ncomp=MEDfieldnComponent(fid,i+1);
4644       INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4645       INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4646       INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
4647       INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4648       INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4649       med_bool localMesh;
4650       int nbOfStep;
4651       MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
4652       std::string tmp(nomcha);
4653       fns[i]=tmp;
4654       found=(tmp==fieldName);
4655       if(found)
4656         {
4657           nbOfStep2=nbOfStep;
4658           std::string mname=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
4659           std::vector<std::string> infos(ncomp);
4660           for(int j=0;j<ncomp;j++)
4661             infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
4662           _content->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
4663         }
4664     }
4665   if(!found)
4666     {
4667       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
4668       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
4669         oss << "\"" << *it << "\" ";
4670       throw INTERP_KERNEL::Exception(oss.str().c_str());
4671     }
4672   return nbOfStep2;
4673 }
4674
4675 /*!
4676  * This method returns all profiles whose name is non empty used.
4677  * \b WARNING If profile is used several times it will be reported \b only \b once.
4678  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
4679  */
4680 std::vector<std::string> MEDFileField1TS::getPflsReallyUsed() const
4681 {
4682   return _content->getPflsReallyUsed2();
4683 }
4684
4685 /*!
4686  * This method returns all localizations whose name is non empty used.
4687  * \b WARNING If localization is used several times it will be reported \b only \b once.
4688  */
4689 std::vector<std::string> MEDFileField1TS::getLocsReallyUsed() const
4690 {
4691   return _content->getLocsReallyUsed2();
4692 }
4693
4694 /*!
4695  * This method returns all profiles whose name is non empty used.
4696  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
4697  */
4698 std::vector<std::string> MEDFileField1TS::getPflsReallyUsedMulti() const
4699 {
4700   return _content->getPflsReallyUsedMulti2();
4701 }
4702
4703 /*!
4704  * This method returns all localizations whose name is non empty used.
4705  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
4706  */
4707 std::vector<std::string> MEDFileField1TS::getLocsReallyUsedMulti() const
4708 {
4709   return _content->getLocsReallyUsedMulti2();
4710 }
4711
4712 void MEDFileField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
4713 {
4714   _content->changePflsRefsNamesGen2(mapOfModif);
4715 }
4716
4717 void MEDFileField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
4718 {
4719   _content->changeLocsRefsNamesGen2(mapOfModif);
4720 }
4721
4722 /*!
4723  * Returns a new MEDCouplingFieldDouble of a given type lying on
4724  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
4725  * has not been constructed via file reading, an exception is thrown.
4726  * For more info, see \ref AdvMEDLoaderAPIFieldRW
4727  *  \param [in] type - a spatial discretization of interest.
4728  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4729  *  \param [in] renumPol - specifies how to permute values of the result field according to
4730  *          the optional numbers of cells and nodes, if any. The valid values are
4731  *          - 0 - do not permute.
4732  *          - 1 - permute cells.
4733  *          - 2 - permute nodes.
4734  *          - 3 - permute cells and nodes.
4735  *
4736  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4737  *          caller is to delete this field using decrRef() as it is no more needed. 
4738  *  \throw If \a this field has not been constructed via file reading.
4739  *  \throw If the MED file is not readable.
4740  *  \throw If there is no mesh in the MED file.
4741  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4742  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4743  *  \sa getFieldOnMeshAtLevel()
4744  */
4745 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
4746 {
4747   if(getFileName2().empty())
4748     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
4749   return _content->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this);
4750 }
4751 /*!
4752  * Returns a new MEDCouplingFieldDouble of a given type lying on
4753  * the top level cells of the first mesh in MED file. If \a this field 
4754  * has not been constructed via file reading, an exception is thrown.
4755  * For more info, see \ref AdvMEDLoaderAPIFieldRW
4756  *  \param [in] type - a spatial discretization of interest.
4757  *  \param [in] renumPol - specifies how to permute values of the result field according to
4758  *          the optional numbers of cells and nodes, if any. The valid values are
4759  *          - 0 - do not permute.
4760  *          - 1 - permute cells.
4761  *          - 2 - permute nodes.
4762  *          - 3 - permute cells and nodes.
4763  *
4764  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4765  *          caller is to delete this field using decrRef() as it is no more needed. 
4766  *  \throw If \a this field has not been constructed via file reading.
4767  *  \throw If the MED file is not readable.
4768  *  \throw If there is no mesh in the MED file.
4769  *  \throw If no field values of the given \a type.
4770  *  \throw If no field values lying on the top level support.
4771  *  \sa getFieldAtLevel()
4772  */
4773 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const throw(INTERP_KERNEL::Exception)
4774 {
4775   if(getFileName2().empty())
4776     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
4777   return _content->getFieldAtTopLevel(type,0,renumPol,this);
4778 }
4779
4780
4781 /*!
4782  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
4783  * For more info, see \ref AdvMEDLoaderAPIFieldRW
4784  *  \param [in] type - a spatial discretization of the new field.
4785  *  \param [in] mesh - the supporting mesh.
4786  *  \param [in] renumPol - specifies how to permute values of the result field according to
4787  *          the optional numbers of cells and nodes, if any. The valid values are
4788  *          - 0 - do not permute.
4789  *          - 1 - permute cells.
4790  *          - 2 - permute nodes.
4791  *          - 3 - permute cells and nodes.
4792  *
4793  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4794  *          caller is to delete this field using decrRef() as it is no more needed. 
4795  *  \throw If no field of \a this is lying on \a mesh.
4796  *  \throw If the mesh is empty.
4797  *  \throw If no field values of the given \a type are available.
4798  *  \sa getFieldAtLevel()
4799  *  \sa getFieldOnMeshAtLevel() 
4800  */
4801 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
4802 {
4803   return _content->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0);
4804 }
4805
4806 /*!
4807  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
4808  * For more info, see \ref AdvMEDLoaderAPIFieldRW
4809  *  \param [in] type - a spatial discretization of interest.
4810  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4811  *  \param [in] mesh - the supporting mesh.
4812  *  \param [in] renumPol - specifies how to permute values of the result field according to
4813  *          the optional numbers of cells and nodes, if any. The valid values are
4814  *          - 0 - do not permute.
4815  *          - 1 - permute cells.
4816  *          - 2 - permute nodes.
4817  *          - 3 - permute cells and nodes.
4818  *
4819  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4820  *          caller is to delete this field using decrRef() as it is no more needed. 
4821  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4822  *  \throw If no field of \a this is lying on \a mesh.
4823  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4824  *  \sa getFieldAtLevel()
4825  *  \sa getFieldOnMeshAtLevel() 
4826  */
4827 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
4828 {
4829   return _content->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh);
4830 }
4831
4832 /*!
4833  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
4834  * This method is called "Old" because in MED3 norm a field has only one meshName
4835  * attached, so this method is for readers of MED2 files. If \a this field 
4836  * has not been constructed via file reading, an exception is thrown.
4837  * For more info, see \ref AdvMEDLoaderAPIFieldRW
4838  *  \param [in] type - a spatial discretization of interest.
4839  *  \param [in] mName - a name of the supporting mesh.
4840  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4841  *  \param [in] renumPol - specifies how to permute values of the result field according to
4842  *          the optional numbers of cells and nodes, if any. The valid values are
4843  *          - 0 - do not permute.
4844  *          - 1 - permute cells.
4845  *          - 2 - permute nodes.
4846  *          - 3 - permute cells and nodes.
4847  *
4848  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4849  *          caller is to delete this field using decrRef() as it is no more needed. 
4850  *  \throw If the MED file is not readable.
4851  *  \throw If there is no mesh named \a mName in the MED file.
4852  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4853  *  \throw If \a this field has not been constructed via file reading.
4854  *  \throw If no field of \a this is lying on the mesh named \a mName.
4855  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4856  *  \sa getFieldAtLevel()
4857  */
4858 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
4859 {
4860   if(getFileName2().empty())
4861     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
4862   return _content->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this);
4863 }
4864
4865
4866 /*!
4867  * Returns values and a profile of the field of a given type lying on a given support.
4868  * For more info, see \ref AdvMEDLoaderAPIFieldRW
4869  *  \param [in] type - a spatial discretization of the field.
4870  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4871  *  \param [in] mesh - the supporting mesh.
4872  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4873  *          field of interest lies on. If the field lies on all entities of the given
4874  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4875  *          using decrRef() as it is no more needed.  
4876  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4877  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4878  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4879  *  \throw If no field of \a this is lying on \a mesh.
4880  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4881  */
4882 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
4883 {
4884   return _content->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this);
4885 }
4886
4887 /*!
4888  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4889  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4890  * "Sort By Type"), if not, an exception is thrown. 
4891  * For more info, see \ref AdvMEDLoaderAPIFieldRW
4892  *  \param [in] field - the field to add to \a this.
4893  *  \throw If the name of \a field is empty.
4894  *  \throw If the data array of \a field is not set.
4895  *  \throw If the data array is already allocated but has different number of components
4896  *         than \a field.
4897  *  \throw If the underlying mesh of \a field has no name.
4898  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4899  */
4900 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
4901 {
4902   setFileName("");
4903   _content->setFieldNoProfileSBT(field,*this);
4904 }
4905
4906 /*!
4907  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4908  * of a given mesh are used as the support of the given field (a real support is not used). 
4909  * Elements of the given mesh must be sorted suitable for writing to MED file.
4910  * Order of underlying mesh entities of the given field specified by \a profile parameter
4911  * is not prescribed; this method permutes field values to have them sorted by element
4912  * type as required for writing to MED file. A new profile is added only if no equal
4913  * profile is missing.
4914  * For more info, see \ref AdvMEDLoaderAPIFieldRW
4915  *  \param [in] field - the field to add to \a this.
4916  *  \param [in] mesh - the supporting mesh of \a field.
4917  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4918  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4919  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4920  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4921  *  \throw If the data array of \a field is not set.
4922  *  \throw If the data array of \a this is already allocated but has different number of
4923  *         components than \a field.
4924  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4925  *  \sa setFieldNoProfileSBT()
4926  */
4927 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
4928 {
4929   setFileName("");
4930   _content->setFieldProfile(field,mesh,meshDimRelToMax,profile,*this);
4931 }
4932
4933 /*!
4934  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
4935  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
4936  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
4937  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
4938  * to keep a valid instance.
4939  * 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.
4940  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
4941  * 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.
4942  *
4943  * \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.
4944  * \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.
4945  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4946  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4947  * \param [in] newLocName is the new localization name.
4948  * \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.
4949  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
4950  */
4951 void MEDFileField1TS::setProfileNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newPflName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
4952 {
4953   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
4954   std::string oldPflName=disc->getProfile();
4955   std::vector<std::string> vv=getPflsReallyUsedMulti();
4956   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
4957   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
4958     {
4959       disc->setProfile(newPflName);
4960       DataArrayInt *pfl=getProfile(oldPflName.c_str());
4961       pfl->setName(newPflName);
4962     }
4963   else
4964     {
4965       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
4966       throw INTERP_KERNEL::Exception(oss.str().c_str());
4967     }
4968 }
4969
4970 /*!
4971  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
4972  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
4973  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
4974  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
4975  * to keep a valid instance.
4976  * 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.
4977  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
4978  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
4979  * 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.
4980  *
4981  * \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.
4982  * \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.
4983  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4984  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4985  * \param [in] newLocName is the new localization name.
4986  * \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.
4987  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
4988  */
4989 void MEDFileField1TS::setLocNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newLocName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
4990 {
4991   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
4992   std::string oldLocName=disc->getLocalization();
4993   std::vector<std::string> vv=getLocsReallyUsedMulti();
4994   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
4995   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
4996     {
4997       disc->setLocalization(newLocName);
4998       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
4999       loc.setName(newLocName);
5000     }
5001   else
5002     {
5003       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5004       throw INTERP_KERNEL::Exception(oss.str().c_str());
5005     }
5006 }
5007
5008 std::size_t MEDFileField1TS::getHeapMemorySize() const
5009 {
5010   std::size_t ret=0;
5011   if((const MEDFileField1TSWithoutSDA *)_content)
5012     ret+=_content->getHeapMemorySize();
5013   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
5014 }
5015
5016 MEDFileField1TS *MEDFileField1TS::deepCpy() const throw(INTERP_KERNEL::Exception)
5017 {
5018   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(*this);
5019   if((const MEDFileField1TSWithoutSDA *)_content)
5020     ret->_content=_content->deepCpy();
5021   ret->deepCpyGlobs(*this);
5022   return ret.retn();
5023 }
5024
5025 int MEDFileField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
5026 {
5027   return _content->copyTinyInfoFrom(field);
5028 }
5029
5030 int MEDFileField1TS::getDimension() const
5031 {
5032   return _content->getDimension();
5033 }
5034
5035 int MEDFileField1TS::getIteration() const
5036 {
5037   return _content->getIteration();
5038 }
5039
5040 int MEDFileField1TS::getOrder() const
5041 {
5042   return _content->getOrder();
5043 }
5044
5045 double MEDFileField1TS::getTime(int& iteration, int& order) const
5046 {
5047   return _content->getTime(iteration,order);
5048 }
5049
5050 void MEDFileField1TS::setTime(int iteration, int order, double val)
5051 {
5052   _content->setTime(iteration,order,val);
5053 }
5054
5055 std::string MEDFileField1TS::getName() const
5056 {
5057   return _content->getName();
5058 }
5059
5060 void MEDFileField1TS::setName(const char *name)
5061 {
5062   _content->setName(name);
5063 }
5064
5065 void MEDFileField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5066 {
5067   _content->simpleRepr(bkOffset,oss,f1tsId);
5068 }
5069
5070 const std::string& MEDFileField1TS::getDtUnit() const
5071 {
5072   return _content->getDtUnit();
5073 }
5074
5075 std::string MEDFileField1TS::getMeshName() const throw(INTERP_KERNEL::Exception)
5076 {
5077   return _content->getMeshName();
5078 }
5079
5080 void MEDFileField1TS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
5081 {
5082   _content->setMeshName(newMeshName);
5083 }
5084
5085 bool MEDFileField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
5086 {
5087   return _content->changeMeshNames(modifTab);
5088 }
5089
5090 int MEDFileField1TS::getMeshIteration() const throw(INTERP_KERNEL::Exception)
5091 {
5092   return _content->getMeshIteration();
5093 }
5094
5095 int MEDFileField1TS::getMeshOrder() const throw(INTERP_KERNEL::Exception)
5096 {
5097   return _content->getMeshOrder();
5098 }
5099
5100 int MEDFileField1TS::getNumberOfComponents() const
5101 {
5102   return _content->getNumberOfComponents();
5103 }
5104
5105 bool MEDFileField1TS::isDealingTS(int iteration, int order) const
5106 {
5107   return _content->isDealingTS(iteration,order);
5108 }
5109
5110 std::pair<int,int> MEDFileField1TS::getDtIt() const
5111 {
5112   return _content->getDtIt();
5113 }
5114
5115 void MEDFileField1TS::fillIteration(std::pair<int,int>& p) const
5116 {
5117   _content->fillIteration(p);
5118 }
5119 void MEDFileField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
5120 {
5121   _content->fillTypesOfFieldAvailable(types);
5122 }
5123
5124 const std::vector<std::string>& MEDFileField1TS::getInfo() const
5125 {
5126   return _content->getInfo();
5127 }
5128 std::vector<std::string>& MEDFileField1TS::getInfo()
5129 {
5130   return _content->getInfo();
5131 }
5132
5133 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
5134 {
5135   return _content->getUndergroundDataArray();
5136 }
5137
5138 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
5139 {
5140   return _content->getUndergroundDataArrayExt(entries);
5141 }
5142
5143 MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
5144 {
5145   return _content->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5146 }
5147
5148 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
5149 {
5150   return _content->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5151 }
5152
5153 int MEDFileField1TS::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
5154 {
5155   return _content->getNonEmptyLevels(mname,levs);
5156 }
5157
5158 std::vector<TypeOfField> MEDFileField1TS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
5159 {
5160   return _content->getTypesOfFieldAvailable();
5161 }
5162
5163 std::vector< std::vector<std::pair<int,int> > > MEDFileField1TS::getFieldSplitedByType(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
5164                                                                                        std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
5165 {
5166   return _content->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5167 }
5168 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
5169                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
5170 {
5171   return _content->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
5172 }
5173
5174 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const char *fieldName, int id, int ft, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception)
5175 {
5176   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,id,ft,infos,nbOfStep);
5177 }
5178
5179 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA():_field_type(-1)
5180 {
5181 }
5182
5183 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const char *fieldName):_name(fieldName),_field_type(-1)
5184 {
5185 }
5186
5187 /*!
5188  * \param [in] fieldId field id in C mode
5189  */
5190 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId) throw(INTERP_KERNEL::Exception)
5191 try:_name("")
5192 {
5193   med_field_type typcha;
5194   //
5195   int ncomp=MEDfieldnComponent(fid,fieldId+1);
5196   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5197   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5198   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5199   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5200   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5201   med_bool localMesh;
5202   int nbOfStep;
5203   MEDfieldInfo(fid,fieldId+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5204   _name=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5205   _field_type=MEDFileUtilities::TraduceFieldType(typcha);
5206   _infos.resize(ncomp);
5207   for(int j=0;j<ncomp;j++)
5208     _infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5209   //
5210   finishLoading(fid,nbOfStep);
5211 }
5212 catch(INTERP_KERNEL::Exception& e)
5213   {
5214     throw e;
5215   }
5216
5217 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, int id, int ft, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception)
5218 try:_name(fieldName),_infos(infos),_field_type(ft)
5219 {
5220   finishLoading(fid,nbOfStep);
5221 }
5222 catch(INTERP_KERNEL::Exception& e)
5223 {
5224   throw e;
5225 }
5226
5227 std::size_t MEDFileFieldMultiTSWithoutSDA::getHeapMemorySize() const
5228 {
5229   std::size_t ret=_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>);
5230   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
5231     ret+=(*it).capacity();
5232   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5233     if((const MEDFileField1TSWithoutSDA *)(*it))
5234       ret+=(*it)->getHeapMemorySize();
5235   return ret;
5236 }
5237
5238 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
5239 {
5240   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret=new MEDFileFieldMultiTSWithoutSDA(*this);
5241   std::size_t i=0;
5242   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
5243     {
5244       if((const MEDFileField1TSWithoutSDA *)*it)
5245         ret->_time_steps[i]=(*it)->deepCpy();
5246     }
5247   return ret.retn();
5248 }
5249
5250 const std::vector<std::string>& MEDFileFieldMultiTSWithoutSDA::getInfo() const throw(INTERP_KERNEL::Exception)
5251 {
5252   if(_time_steps.empty())
5253     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getInfos : not time steps !");
5254   return _time_steps[0]->getInfo();
5255 }
5256
5257 /*!
5258  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
5259  */
5260 DataArrayDouble *MEDFileFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
5261 {
5262   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
5263 }
5264
5265 /*!
5266  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
5267  */
5268 DataArrayDouble *MEDFileFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
5269 {
5270   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
5271 }
5272
5273 std::string MEDFileFieldMultiTSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
5274 {
5275   if(_time_steps.empty())
5276     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
5277   return _time_steps[0]->getMeshName();
5278 }
5279
5280 void MEDFileFieldMultiTSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
5281 {
5282   std::string oldName(getMeshName());
5283   std::vector< std::pair<std::string,std::string> > v(1);
5284   v[0].first=oldName; v[0].second=newMeshName;
5285   changeMeshNames(v);
5286 }
5287
5288 bool MEDFileFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
5289 {
5290   bool ret=false;
5291   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5292     {
5293       MEDFileField1TSWithoutSDA *cur(*it);
5294       if(cur)
5295         ret=cur->changeMeshNames(modifTab) || ret;
5296     }
5297   return ret;
5298 }
5299
5300 bool MEDFileFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
5301                                                                 MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
5302 {
5303   bool ret=false;
5304   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5305     {
5306       MEDFileField1TSWithoutSDA *f1ts(*it);
5307       if(f1ts)
5308         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
5309     }
5310   return ret;
5311 }
5312
5313 void MEDFileFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
5314 {
5315   if(_time_steps.empty())
5316     {
5317       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
5318       obj->setFieldNoProfileSBT(field,glob);
5319       copyTinyInfoFrom(field);
5320       _time_steps.push_back(obj);
5321     }
5322   else
5323     {
5324       checkCoherencyOfTinyInfo(field);
5325       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
5326       obj->setFieldNoProfileSBT(field,glob);
5327       _time_steps.push_back(obj);
5328     }
5329 }
5330
5331 void MEDFileFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
5332 {
5333   if(_time_steps.empty())
5334     {
5335       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
5336       obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,glob);
5337       copyTinyInfoFrom(field);
5338       _time_steps.push_back(obj);
5339     }
5340   else
5341     {
5342       checkCoherencyOfTinyInfo(field);
5343       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
5344       obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,glob);
5345       _time_steps.push_back(obj);
5346     }
5347 }
5348
5349 std::string MEDFileFieldMultiTSWithoutSDA::getDtUnit() const throw(INTERP_KERNEL::Exception)
5350 {
5351   if(_time_steps.empty())
5352     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
5353   return _time_steps[0]->getDtUnit();
5354 }
5355
5356 std::string MEDFileFieldMultiTSWithoutSDA::getName() const
5357 {
5358   return _name;
5359 }
5360
5361 void MEDFileFieldMultiTSWithoutSDA::setName(const char *name)
5362 {
5363   _name=name;
5364 }
5365
5366 void MEDFileFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
5367 {
5368   std::string startLine(bkOffset,' ');
5369   oss << startLine << "Field multi time steps";
5370   if(fmtsId>=0)
5371     oss << " (" << fmtsId << ")";
5372   oss << " has the following name: \"" << _name << "\"." << std::endl;
5373   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
5374   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
5375     {
5376       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
5377     }
5378   int i=0;
5379   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
5380     {
5381       std::string chapter(17,'0'+i);
5382       oss << startLine << chapter << std::endl;
5383       const MEDFileField1TSWithoutSDA *cur=(*it);
5384       if(cur)
5385         cur->simpleRepr(bkOffset+2,oss,i);
5386       else
5387         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
5388       oss << startLine << chapter << std::endl;
5389     }
5390 }
5391
5392 std::vector< std::pair<int,int> > MEDFileFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
5393 {
5394   std::size_t sz=_time_steps.size();
5395   std::vector< std::pair<int,int> > ret(sz);
5396   ret1.resize(sz);
5397   for(std::size_t i=0;i<sz;i++)
5398     {
5399       const MEDFileField1TSWithoutSDA *f1ts=_time_steps[i];
5400       if(f1ts)
5401         {
5402           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
5403         }
5404       else
5405         {
5406           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
5407           throw INTERP_KERNEL::Exception(oss.str().c_str());
5408         }
5409     }
5410   return ret;
5411 }
5412
5413 void MEDFileFieldMultiTSWithoutSDA::finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception)
5414 {
5415   _time_steps.resize(nbPdt);
5416   for(int i=0;i<nbPdt;i++)
5417     {
5418       std::vector< std::pair<int,int> > ts;
5419       med_int numdt=0,numo=0;
5420       med_int meshIt=0,meshOrder=0;
5421       med_float dt=0.0;
5422       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
5423       _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,_field_type,numdt,numo,_infos);
5424       _time_steps[i]->finishLoading(fid);
5425     }
5426 }
5427
5428 void MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
5429 {
5430   _name=field->getName();
5431   if(_name.empty())
5432     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
5433   const DataArrayDouble *arr=field->getArray();
5434   if(!arr)
5435     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
5436   _infos=arr->getInfoOnComponents();
5437 }
5438
5439 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field) const throw(INTERP_KERNEL::Exception)
5440 {
5441   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
5442   if(_name!=field->getName())
5443     {
5444       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
5445       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
5446       throw INTERP_KERNEL::Exception(oss.str().c_str());
5447     }
5448   const DataArrayDouble *arr=field->getArray();
5449   if(!arr)
5450     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
5451   if(_infos!=arr->getInfoOnComponents())
5452     {
5453       std::ostringstream oss; oss << MSG << "components ! should be \"";
5454       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
5455       oss << " But compo in input fields are : ";
5456       std::vector<std::string> tmp=arr->getInfoOnComponents();
5457       std::copy(tmp.begin(),tmp.end(),std::ostream_iterator<std::string>(oss,", "));
5458       oss << " !";
5459       throw INTERP_KERNEL::Exception(oss.str().c_str());
5460     }
5461 }
5462
5463 void MEDFileFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception)
5464 {
5465   if(_time_steps.empty())
5466     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
5467   std::vector<std::string> infos(getInfo());
5468   int nbComp=infos.size();
5469   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5470   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5471   for(int i=0;i<nbComp;i++)
5472     {
5473       std::string info=infos[i];
5474       std::string c,u;
5475       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5476       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
5477       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
5478     }
5479   if(_name.empty())
5480     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
5481   MEDfieldCr(fid,_name.c_str(),MED_FLOAT64,nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5482   int nbOfTS=_time_steps.size();
5483   for(int i=0;i<nbOfTS;i++)
5484     _time_steps[i]->writeLL(fid,opts);
5485 }
5486
5487 int MEDFileFieldMultiTSWithoutSDA::getNumberOfTS() const
5488 {
5489   return _time_steps.size();
5490 }
5491
5492 void MEDFileFieldMultiTSWithoutSDA::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
5493 {
5494   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  > newTS;
5495   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5496     {
5497       const MEDFileField1TSWithoutSDA *tmp=(*it);
5498       if(tmp)
5499         newTS.push_back(*it);
5500     }
5501   _time_steps=newTS;
5502 }
5503
5504 void MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
5505 {
5506   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  > newTS;
5507   int maxId=(int)_time_steps.size();
5508   int ii=0;
5509   std::set<int> idsToDel;
5510   for(const int *id=startIds;id!=endIds;id++,ii++)
5511     {
5512       if(*id>=0 && *id<maxId)
5513         {
5514           idsToDel.insert(*id);
5515         }
5516       else
5517         {
5518           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
5519           throw INTERP_KERNEL::Exception(oss.str().c_str());
5520         }
5521     }
5522   for(int iii=0;iii<maxId;iii++)
5523     if(idsToDel.find(iii)==idsToDel.end())
5524       newTS.push_back(_time_steps[iii]);
5525   _time_steps=newTS;
5526 }
5527
5528 int MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
5529 {
5530   int ret=0;
5531   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
5532   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
5533     {
5534       const MEDFileField1TSWithoutSDA *tmp(*it);
5535       if(tmp)
5536         {
5537           int it2,ord;
5538           tmp->getTime(it2,ord);
5539           if(it2==iteration && order==ord)
5540             return ret;
5541           else
5542             oss << "(" << it2 << ","  << ord << "), ";
5543         }
5544     }
5545   throw INTERP_KERNEL::Exception(oss.str().c_str());
5546 }
5547
5548 int MEDFileFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
5549 {
5550   int ret=0;
5551   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
5552   oss.precision(15);
5553   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
5554     {
5555       const MEDFileField1TSWithoutSDA *tmp(*it);
5556       if(tmp)
5557         {
5558           int it2,ord;
5559           double ti=tmp->getTime(it2,ord);
5560           if(fabs(time-ti)<eps)
5561             return ret;
5562           else
5563             oss << ti << ", ";
5564         }
5565     }
5566   throw INTERP_KERNEL::Exception(oss.str().c_str());
5567 }
5568
5569 std::vector< std::pair<int,int> > MEDFileFieldMultiTSWithoutSDA::getIterations() const
5570 {
5571   int lgth=_time_steps.size();
5572   std::vector< std::pair<int,int> > ret(lgth);
5573   for(int i=0;i<lgth;i++)
5574     _time_steps[i]->fillIteration(ret[i]);
5575   return ret;
5576 }
5577
5578 /*!
5579  * 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'
5580  * This method returns two things.
5581  * - The absolute dimension of 'this' in first parameter. 
5582  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
5583  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
5584  *
5585  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
5586  * Only these 3 discretizations will be taken into account here.
5587  *
5588  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
5589  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
5590  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
5591  *
5592  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
5593  * 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'.
5594  * 
5595  * Let's consider the typical following case :
5596  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
5597  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
5598  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
5599  *   TETRA4 and SEG2
5600  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
5601  *
5602  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
5603  * 
5604  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
5605  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
5606  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
5607  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
5608  */
5609 int MEDFileFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
5610 {
5611   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
5612 }
5613
5614 std::vector< std::vector<TypeOfField> > MEDFileFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
5615 {
5616   int lgth=_time_steps.size();
5617   std::vector< std::vector<TypeOfField> > ret(lgth);
5618   for(int i=0;i<lgth;i++)
5619     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
5620   return ret;
5621 }
5622
5623 /*!
5624  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
5625  */
5626 std::vector< std::vector< std::pair<int,int> > > MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType(int iteration, int order, const char *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 throw(INTERP_KERNEL::Exception)
5627 {
5628   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
5629 }
5630
5631 /*!
5632  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
5633  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
5634  */
5635 std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2(int iteration, int order, const char *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 throw(INTERP_KERNEL::Exception)
5636 {
5637   return getTimeStepEntry(iteration,order).getFieldSplitedByType2(mname,types,typesF,pfls,locs);
5638 }
5639
5640 const MEDFileField1TSWithoutSDA& MEDFileFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const throw(INTERP_KERNEL::Exception)
5641 {
5642   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5643     if((*it)->isDealingTS(iteration,order))
5644       return *(*it);
5645   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepEntry : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
5646   std::vector< std::pair<int,int> > vp=getIterations();
5647   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
5648     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
5649   throw INTERP_KERNEL::Exception(oss.str().c_str());
5650 }
5651
5652 MEDFileField1TSWithoutSDA& MEDFileFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) throw(INTERP_KERNEL::Exception)
5653 {
5654   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5655     if((*it)->isDealingTS(iteration,order))
5656       return *(*it);
5657   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepEntry : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
5658   std::vector< std::pair<int,int> > vp=getIterations();
5659   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
5660     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
5661   throw INTERP_KERNEL::Exception(oss.str().c_str());
5662 }
5663
5664 const MEDFileField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const throw(INTERP_KERNEL::Exception)
5665 {
5666   if(pos<0 || pos>=(int)_time_steps.size())
5667     {
5668       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
5669       throw INTERP_KERNEL::Exception(oss.str().c_str());
5670     }
5671   const MEDFileField1TSWithoutSDA *item=_time_steps[pos];
5672   if(item==0)
5673     {
5674       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
5675       oss << "\nTry to use following method eraseEmptyTS !";
5676       throw INTERP_KERNEL::Exception(oss.str().c_str());
5677     }
5678   return item;
5679 }
5680
5681 MEDFileField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) throw(INTERP_KERNEL::Exception)
5682 {
5683   if(pos<0 || pos>=(int)_time_steps.size())
5684     {
5685       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
5686       throw INTERP_KERNEL::Exception(oss.str().c_str());
5687     }
5688   MEDFileField1TSWithoutSDA *item=_time_steps[pos];
5689   if(item==0)
5690     {
5691       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
5692       oss << "\nTry to use following method eraseEmptyTS !";
5693       throw INTERP_KERNEL::Exception(oss.str().c_str());
5694     }
5695   return item;
5696 }
5697
5698 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
5699 {
5700   std::vector<std::string> ret;
5701   std::set<std::string> ret2;
5702   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5703     {
5704       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
5705       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
5706         if(ret2.find(*it2)==ret2.end())
5707           {
5708             ret.push_back(*it2);
5709             ret2.insert(*it2);
5710           }
5711     }
5712   return ret;
5713 }
5714
5715 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
5716 {
5717   std::vector<std::string> ret;
5718   std::set<std::string> ret2;
5719   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5720     {
5721       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
5722       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
5723         if(ret2.find(*it2)==ret2.end())
5724           {
5725             ret.push_back(*it2);
5726             ret2.insert(*it2);
5727           }
5728     }
5729   return ret;
5730 }
5731
5732 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
5733 {
5734   std::vector<std::string> ret;
5735   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5736     {
5737       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
5738       ret.insert(ret.end(),tmp.begin(),tmp.end());
5739     }
5740   return ret;
5741 }
5742
5743 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
5744 {
5745   std::vector<std::string> ret;
5746   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5747     {
5748       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
5749       ret.insert(ret.end(),tmp.begin(),tmp.end());
5750     }
5751   return ret;
5752 }
5753
5754 void MEDFileFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5755 {
5756   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5757     (*it)->changePflsRefsNamesGen2(mapOfModif);
5758 }
5759
5760 void MEDFileFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5761 {
5762   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5763     (*it)->changeLocsRefsNamesGen2(mapOfModif);
5764 }
5765
5766 /*!
5767  * Returns a new empty instance of MEDFileFieldMultiTS.
5768  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
5769  *          is to delete this field using decrRef() as it is no more needed.
5770  */
5771 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
5772 {
5773   return new MEDFileFieldMultiTS;
5774 }
5775
5776 /*!
5777  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
5778  * that has been read from a specified MED file.
5779  *  \param [in] fileName - the name of the MED file to read.
5780  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
5781  *          is to delete this field using decrRef() as it is no more needed.
5782  *  \throw If reading the file fails.
5783  */
5784 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
5785 {
5786   return new MEDFileFieldMultiTS(fileName);
5787 }
5788
5789 /*!
5790  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
5791  * that has been read from a specified MED file.
5792  *  \param [in] fileName - the name of the MED file to read.
5793  *  \param [in] fieldName - the name of the field to read.
5794  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
5795  *          is to delete this field using decrRef() as it is no more needed.
5796  *  \throw If reading the file fails.
5797  *  \throw If there is no field named \a fieldName in the file.
5798  */
5799 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
5800 {
5801   return new MEDFileFieldMultiTS(fileName,fieldName);
5802 }
5803
5804 /*!
5805  * Returns a new instance of MEDFileFieldMultiTS holding either deep or shallow copy
5806  * of a given MEDFileFieldMultiTSWithoutSDA.
5807  *  \param [in] other - a MEDFileFieldMultiTSWithoutSDA to copy.
5808  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
5809  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
5810  *          is to delete this field using decrRef() as it is no more needed.
5811  */
5812 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
5813 {
5814   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
5815 }
5816
5817 std::size_t MEDFileFieldMultiTS::getHeapMemorySize() const
5818 {
5819   std::size_t ret=0;
5820   if((const MEDFileFieldMultiTSWithoutSDA*)_content)
5821     ret+=_content->getHeapMemorySize();
5822   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
5823 }
5824
5825 MEDFileFieldMultiTS *MEDFileFieldMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception)
5826 {
5827   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(*this);
5828   if((const MEDFileFieldMultiTSWithoutSDA *)_content)
5829     ret->_content=_content->deepCpy();
5830   ret->deepCpyGlobs(*this);
5831   return ret.retn();
5832 }
5833
5834 /*!
5835  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
5836  *  \param [in] pos - a time step id.
5837  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
5838  *          delete this field using decrRef() as it is no more needed.
5839  *  \throw If \a pos is not a valid time step id.
5840  */
5841 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
5842 {
5843   const MEDFileField1TSWithoutSDA *item=_content->getTimeStepAtPos2(pos);
5844   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*item,false);
5845   ret->shallowCpyGlobs(*this);
5846   return ret.retn();
5847 }
5848
5849 /*!
5850  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
5851  *  \param [in] iteration - the iteration number of a required time step.
5852  *  \param [in] order - the iteration order number of required time step.
5853  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
5854  *          delete this field using decrRef() as it is no more needed.
5855  *  \throw If there is no required time step in \a this field.
5856  */
5857 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
5858 {
5859   int pos=getPosOfTimeStep(iteration,order);
5860   return getTimeStepAtPos(pos);
5861 }
5862
5863 /*!
5864  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
5865  *  \param [in] time - the time of the time step of interest.
5866  *  \param [in] eps - a precision used to compare time values.
5867  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
5868  *          delete this field using decrRef() as it is no more needed.
5869  *  \throw If there is no required time step in \a this field.
5870  */
5871 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
5872 {
5873   int pos=getPosGivenTime(time,eps);
5874   return getTimeStepAtPos(pos);
5875 }
5876
5877 MEDFileFieldMultiTSIterator *MEDFileFieldMultiTS::iterator() throw(INTERP_KERNEL::Exception)
5878 {
5879   return new MEDFileFieldMultiTSIterator(this);
5880 }
5881
5882 std::string MEDFileFieldMultiTS::simpleRepr() const
5883 {
5884   std::ostringstream oss;
5885   _content->simpleRepr(0,oss,-1);
5886   MEDFileFieldGlobsReal::simpleRepr(oss);
5887   return oss.str();
5888 }
5889
5890 void MEDFileFieldMultiTS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
5891 {
5892   writeGlobals(fid,*this);
5893   _content->writeLL(fid,*this);
5894 }
5895
5896 /*!
5897  * Writes \a this field into a MED file specified by its name.
5898  *  \param [in] fileName - the MED file name.
5899  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5900  * - 2 - erase; an existing file is removed.
5901  * - 1 - append; same data should not be present in an existing file.
5902  * - 0 - overwrite; same data present in an existing file is overwritten.
5903  *  \throw If the field name is not set.
5904  *  \throw If no field data is set.
5905  *  \throw If \a mode == 1 and the same data is present in an existing file.
5906  */
5907 void MEDFileFieldMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
5908 {
5909   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5910   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
5911   writeLL(fid);
5912 }
5913
5914 /*!
5915  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
5916  * mesh entities of a given dimension of the first mesh in MED file.
5917  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5918  *  \param [in] type - a spatial discretization of interest.
5919  *  \param [in] iteration - the iteration number of a required time step.
5920  *  \param [in] order - the iteration order number of required time step.
5921  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5922  *  \param [in] renumPol - specifies how to permute values of the result field according to
5923  *          the optional numbers of cells and nodes, if any. The valid values are
5924  *          - 0 - do not permute.
5925  *          - 1 - permute cells.
5926  *          - 2 - permute nodes.
5927  *          - 3 - permute cells and nodes.
5928  *
5929  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5930  *          caller is to delete this field using decrRef() as it is no more needed. 
5931  *  \throw If the MED file is not readable.
5932  *  \throw If there is no mesh in the MED file.
5933  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5934  *  \throw If no field values of the required parameters are available.
5935  */
5936 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
5937 {
5938   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
5939   return myF1TS.getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this);
5940 }
5941
5942 /*!
5943  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
5944  * the top level cells of the first mesh in MED file.
5945  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5946  *  \param [in] type - a spatial discretization of interest.
5947  *  \param [in] iteration - the iteration number of a required time step.
5948  *  \param [in] order - the iteration order number of required time step.
5949  *  \param [in] renumPol - specifies how to permute values of the result field according to
5950  *          the optional numbers of cells and nodes, if any. The valid values are
5951  *          - 0 - do not permute.
5952  *          - 1 - permute cells.
5953  *          - 2 - permute nodes.
5954  *          - 3 - permute cells and nodes.
5955  *
5956  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5957  *          caller is to delete this field using decrRef() as it is no more needed. 
5958  *  \throw If the MED file is not readable.
5959  *  \throw If there is no mesh in the MED file.
5960  *  \throw If no field values of the required parameters are available.
5961  */
5962 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const throw(INTERP_KERNEL::Exception)
5963 {
5964   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
5965   return myF1TS.getFieldAtTopLevel(type,0,renumPol,this);
5966 }
5967
5968 /*!
5969  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
5970  * a given support.
5971  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5972  *  \param [in] type - a spatial discretization of interest.
5973  *  \param [in] iteration - the iteration number of a required time step.
5974  *  \param [in] order - the iteration order number of required time step.
5975  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5976  *  \param [in] mesh - the supporting mesh.
5977  *  \param [in] renumPol - specifies how to permute values of the result field according to
5978  *          the optional numbers of cells and nodes, if any. The valid values are
5979  *          - 0 - do not permute.
5980  *          - 1 - permute cells.
5981  *          - 2 - permute nodes.
5982  *          - 3 - permute cells and nodes.
5983  *
5984  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5985  *          caller is to delete this field using decrRef() as it is no more needed. 
5986  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5987  *  \throw If no field of \a this is lying on \a mesh.
5988  *  \throw If no field values of the required parameters are available.
5989  */
5990 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
5991 {
5992   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
5993   return myF1TS.getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh);
5994 }
5995
5996 /*!
5997  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
5998  * given support. 
5999  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6000  *  \param [in] type - a spatial discretization of the new field.
6001  *  \param [in] iteration - the iteration number of a required time step.
6002  *  \param [in] order - the iteration order number of required time step.
6003  *  \param [in] mesh - the supporting mesh.
6004  *  \param [in] renumPol - specifies how to permute values of the result field according to
6005  *          the optional numbers of cells and nodes, if any. The valid values are
6006  *          - 0 - do not permute.
6007  *          - 1 - permute cells.
6008  *          - 2 - permute nodes.
6009  *          - 3 - permute cells and nodes.
6010  *
6011  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6012  *          caller is to delete this field using decrRef() as it is no more needed. 
6013  *  \throw If no field of \a this is lying on \a mesh.
6014  *  \throw If no field values of the required parameters are available.
6015  */
6016 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
6017 {
6018   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
6019   return myF1TS.getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0);
6020 }
6021
6022 /*!
6023  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
6024  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
6025  * This method is useful for MED2 file format when field on different mesh was autorized.
6026  */
6027 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
6028 {
6029   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
6030   return myF1TS.getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this);
6031 }
6032
6033 /*!
6034  * Returns values and a profile of the field of a given type, of a given time step,
6035  * lying on a given support.
6036  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6037  *  \param [in] type - a spatial discretization of the field.
6038  *  \param [in] iteration - the iteration number of a required time step.
6039  *  \param [in] order - the iteration order number of required time step.
6040  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6041  *  \param [in] mesh - the supporting mesh.
6042  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6043  *          field of interest lies on. If the field lies on all entities of the given
6044  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6045  *          using decrRef() as it is no more needed.  
6046  *  \param [in] glob - the global data storing profiles and localization.
6047  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6048  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6049  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6050  *  \throw If no field of \a this is lying on \a mesh.
6051  *  \throw If no field values of the required parameters are available.
6052  */
6053 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
6054 {
6055   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
6056   return myF1TS.getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this);
6057 }
6058
6059 /*!
6060  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
6061  * the given field is checked if its elements are sorted suitable for writing to MED file
6062  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
6063  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6064  *  \param [in] field - the field to add to \a this.
6065  *  \throw If the name of \a field is empty.
6066  *  \throw If the data array of \a field is not set.
6067  *  \throw If existing time steps have different name or number of components than \a field.
6068  *  \throw If the underlying mesh of \a field has no name.
6069  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6070  */
6071 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
6072 {
6073   _content->appendFieldNoProfileSBT(field,*this);
6074 }
6075
6076 /*!
6077  * Adds a MEDCouplingFieldDouble to \a this as another time step. Specified entities of
6078  * a given dimension of a given mesh are used as the support of the given field.
6079  * Elements of the given mesh must be sorted suitable for writing to MED file. 
6080  * Order of underlying mesh entities of the given field specified by \a profile parameter
6081  * is not prescribed; this method permutes field values to have them sorted by element
6082  * type as required for writing to MED file.  
6083  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6084  *  \param [in] field - the field to add to \a this.
6085  *  \param [in] mesh - the supporting mesh of \a field.
6086  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
6087  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6088  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6089  *  \throw If existing time steps have different name or number of components than \a field.
6090  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6091  *  \throw If the data array of \a field is not set.
6092  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6093  */
6094 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
6095 {
6096   _content->appendFieldProfile(field,mesh,meshDimRelToMax,profile,*this);
6097 }
6098
6099 MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> MEDFileFieldMultiTS::getContent()
6100 {
6101   return _content;
6102 }
6103
6104 MEDFileFieldMultiTS::MEDFileFieldMultiTS():_content(new MEDFileFieldMultiTSWithoutSDA)
6105 {
6106 }
6107
6108
6109
6110 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
6111 try:MEDFileFieldGlobsReal(fileName)
6112 {
6113   MEDFileUtilities::CheckFileForRead(fileName);
6114   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
6115   int nbFields=MEDnField(fid);
6116   if(nbFields<1)
6117     {
6118       std::ostringstream oss; oss << "MEDFileFieldMultiTS(const char *fileName) constructor : no fields in file \"" << fileName << "\" !";
6119       throw INTERP_KERNEL::Exception(oss.str().c_str());
6120     }
6121   _content=new MEDFileFieldMultiTSWithoutSDA(fid,0);
6122   //
6123   loadGlobals(fid);
6124 }
6125 catch(INTERP_KERNEL::Exception& e)
6126   {
6127     throw e;
6128   }
6129
6130 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
6131 try:MEDFileFieldGlobsReal(fileName)
6132 {
6133   MEDFileUtilities::CheckFileForRead(fileName);
6134   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
6135   int nbFields=MEDnField(fid);
6136   med_field_type typcha;
6137   bool found=false;
6138   std::vector<std::string> fns(nbFields);
6139   for(int i=0;i<nbFields && !found;i++)
6140     {
6141       int ncomp=MEDfieldnComponent(fid,i+1);
6142       INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
6143       INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
6144       INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
6145       INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
6146       INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
6147       med_bool localMesh;
6148       int nbOfStep;
6149       MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
6150       std::string tmp(nomcha);
6151       fns[i]=tmp;
6152       found=(tmp==fieldName);
6153       if(found)
6154         _content=new MEDFileFieldMultiTSWithoutSDA(fid,i);
6155     }
6156   if(!found)
6157     {
6158       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
6159       std::copy(fns.begin(),fns.end(),std::ostream_iterator<std::string>(oss," "));
6160       throw INTERP_KERNEL::Exception(oss.str().c_str());
6161     }
6162   //
6163   loadGlobals(fid);
6164 }
6165 catch(INTERP_KERNEL::Exception& e)
6166   {
6167     throw e;
6168   }
6169
6170 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
6171 {
6172   if(!shallowCopyOfContent)
6173     {
6174       const MEDFileFieldMultiTSWithoutSDA *otherPtr(&other);
6175       otherPtr->incrRef();
6176       _content=const_cast<MEDFileFieldMultiTSWithoutSDA *>(otherPtr);
6177     }
6178   else
6179     {
6180       _content=new MEDFileFieldMultiTSWithoutSDA(other);
6181     }
6182 }
6183
6184 std::vector<std::string> MEDFileFieldMultiTS::getPflsReallyUsed() const
6185 {
6186   return _content->getPflsReallyUsed2();
6187 }
6188
6189 std::vector<std::string> MEDFileFieldMultiTS::getLocsReallyUsed() const
6190 {
6191   return _content->getLocsReallyUsed2();
6192 }
6193
6194 std::vector<std::string> MEDFileFieldMultiTS::getPflsReallyUsedMulti() const
6195 {
6196   return _content->getPflsReallyUsedMulti2();
6197 }
6198
6199 std::vector<std::string> MEDFileFieldMultiTS::getLocsReallyUsedMulti() const
6200 {
6201   return _content->getLocsReallyUsedMulti2();
6202 }
6203
6204 void MEDFileFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
6205 {
6206   _content->changePflsRefsNamesGen2(mapOfModif);
6207 }
6208
6209 void MEDFileFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
6210 {
6211   _content->changeLocsRefsNamesGen2(mapOfModif);
6212 }
6213
6214 int MEDFileFieldMultiTS::getNumberOfTS() const
6215 {
6216   return _content->getNumberOfTS();
6217 }
6218
6219 void MEDFileFieldMultiTS::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
6220 {
6221   _content->eraseEmptyTS();
6222 }
6223
6224 void MEDFileFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
6225 {
6226   _content->eraseTimeStepIds(startIds,endIds);
6227 }
6228
6229 std::vector< std::pair<int,int> > MEDFileFieldMultiTS::getIterations() const
6230 {
6231   return _content->getIterations();
6232 }
6233
6234 int MEDFileFieldMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6235 {
6236   return _content->getPosOfTimeStep(iteration,order);
6237 }
6238
6239 int MEDFileFieldMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
6240 {
6241   return _content->getPosGivenTime(time,eps);
6242 }
6243
6244 int MEDFileFieldMultiTS::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
6245 {
6246   return _content->getNonEmptyLevels(iteration,order,mname,levs);
6247 }
6248
6249 std::vector< std::vector<TypeOfField> > MEDFileFieldMultiTS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
6250 {
6251   return _content->getTypesOfFieldAvailable();
6252 }
6253
6254 std::vector< std::vector< std::pair<int,int> > > MEDFileFieldMultiTS::getFieldSplitedByType(int iteration, int order, const char *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 throw(INTERP_KERNEL::Exception)
6255 {
6256   return _content->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
6257 }
6258
6259 std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTS::getFieldSplitedByType2(int iteration, int order, const char *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 throw(INTERP_KERNEL::Exception)
6260 {
6261   return _content->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
6262 }
6263
6264 std::string MEDFileFieldMultiTS::getName() const
6265 {
6266   return _content->getName();
6267 }
6268
6269 void MEDFileFieldMultiTS::setName(const char *name)
6270 {
6271   _content->setName(name);
6272 }
6273
6274 void MEDFileFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
6275 {
6276   _content->simpleRepr(bkOffset,oss,fmtsId);
6277 }
6278
6279 std::vector< std::pair<int,int> > MEDFileFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
6280 {
6281   return _content->getTimeSteps(ret1);
6282 }
6283
6284 std::string MEDFileFieldMultiTS::getMeshName() const throw(INTERP_KERNEL::Exception)
6285 {
6286   return _content->getMeshName();
6287 }
6288
6289 void MEDFileFieldMultiTS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
6290 {
6291   _content->setMeshName(newMeshName);
6292 }
6293
6294 bool MEDFileFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
6295 {
6296   return _content->changeMeshNames(modifTab);
6297 }
6298
6299 const std::vector<std::string>& MEDFileFieldMultiTS::getInfo() const throw(INTERP_KERNEL::Exception)
6300 {
6301   return _content->getInfo();
6302 }
6303
6304 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6305 {
6306   return _content->getUndergroundDataArray(iteration,order);
6307 }
6308
6309 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
6310 {
6311   return _content->getUndergroundDataArrayExt(iteration,order,entries);
6312 }
6313
6314 MEDFileFieldMultiTSIterator::MEDFileFieldMultiTSIterator(MEDFileFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
6315 {
6316   if(fmts)
6317     {
6318       fmts->incrRef();
6319       _nb_iter=fmts->getNumberOfTS();
6320     }
6321 }
6322
6323 MEDFileFieldMultiTSIterator::~MEDFileFieldMultiTSIterator() 
6324 {
6325 }
6326
6327 MEDFileField1TS *MEDFileFieldMultiTSIterator::nextt()
6328 {
6329   if(_iter_id<_nb_iter)
6330     {
6331       MEDFileFieldMultiTS *fmts(_fmts);
6332       if(fmts)
6333         return fmts->getTimeStepAtPos(_iter_id++);
6334       else
6335         return 0;
6336     }
6337   else
6338     return 0;
6339 }
6340
6341 MEDFileFields *MEDFileFields::New()
6342 {
6343   return new MEDFileFields;
6344 }
6345
6346 MEDFileFields *MEDFileFields::New(const char *fileName) throw(INTERP_KERNEL::Exception)
6347 {
6348   return new MEDFileFields(fileName);
6349 }
6350
6351 std::size_t MEDFileFields::getHeapMemorySize() const
6352 {
6353   std::size_t ret=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA>);
6354   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
6355     if((const MEDFileFieldMultiTSWithoutSDA *)*it)
6356       ret+=(*it)->getHeapMemorySize();
6357   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
6358 }
6359
6360 MEDFileFields *MEDFileFields::deepCpy() const throw(INTERP_KERNEL::Exception)
6361 {
6362   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=new MEDFileFields(*this);
6363   std::size_t i=0;
6364   for( std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
6365     {
6366       if((const MEDFileFieldMultiTSWithoutSDA*)*it)
6367         ret->_fields[i]=(*it)->deepCpy();
6368     }
6369   ret->deepCpyGlobs(*this);
6370   return ret.retn();
6371 }
6372
6373 int MEDFileFields::getNumberOfFields() const
6374 {
6375   return _fields.size();
6376 }
6377
6378 std::vector<std::string> MEDFileFields::getFieldsNames() const throw(INTERP_KERNEL::Exception)
6379 {
6380   std::vector<std::string> ret(_fields.size());
6381   int i=0;
6382   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
6383     {
6384       const MEDFileFieldMultiTSWithoutSDA *f=(*it);
6385       if(f)
6386         {
6387           ret[i]=f->getName();
6388         }
6389       else
6390         {
6391           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
6392           throw INTERP_KERNEL::Exception(oss.str().c_str());
6393         }
6394     }
6395   return ret;
6396 }
6397
6398 std::vector<std::string> MEDFileFields::getMeshesNames() const throw(INTERP_KERNEL::Exception)
6399 {
6400   std::vector<std::string> ret;
6401   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
6402     {
6403       const MEDFileFieldMultiTSWithoutSDA *cur(*it);
6404       if(cur)
6405         ret.push_back(cur->getMeshName());
6406     }
6407   return ret;
6408 }
6409
6410 std::string MEDFileFields::simpleRepr() const
6411 {
6412   std::ostringstream oss;
6413   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
6414   simpleRepr(0,oss);
6415   return oss.str();
6416 }
6417
6418 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
6419 {
6420   int nbOfFields=getNumberOfFields();
6421   std::string startLine(bkOffset,' ');
6422   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
6423   int i=0;
6424   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
6425     {
6426       const MEDFileFieldMultiTSWithoutSDA *cur=(*it);
6427       if(cur)
6428         {
6429           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
6430         }
6431       else
6432         {
6433           oss << startLine << "  - not defined !" << std::endl;
6434         }
6435     }
6436   i=0;
6437   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
6438     {
6439       const MEDFileFieldMultiTSWithoutSDA *cur=(*it);
6440       std::string chapter(17,'0'+i);
6441       oss << startLine << chapter << std::endl;
6442       if(cur)
6443         {
6444           cur->simpleRepr(bkOffset+2,oss,i);
6445         }
6446       else
6447         {
6448           oss << startLine << "  - not defined !" << std::endl;
6449         }
6450       oss << startLine << chapter << std::endl;
6451     }
6452   MEDFileFieldGlobsReal::simpleRepr(oss);
6453 }
6454
6455 MEDFileFields::MEDFileFields()
6456 {
6457 }
6458
6459 MEDFileFields::MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception)
6460 try:MEDFileFieldGlobsReal(fileName)
6461   {
6462     MEDFileUtilities::CheckFileForRead(fileName);
6463     MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
6464     int nbFields=MEDnField(fid);
6465     _fields.resize(nbFields);
6466     med_field_type typcha;
6467     for(int i=0;i<nbFields;i++)
6468       {
6469         int ncomp=MEDfieldnComponent(fid,i+1);
6470         INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
6471         INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
6472         INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
6473         INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
6474         INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
6475         med_bool localMesh;
6476         int nbOfStep;
6477         MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
6478         int ft=MEDFileUtilities::TraduceFieldType(typcha);
6479         std::vector<std::string> infos(ncomp);
6480         for(int j=0;j<ncomp;j++)
6481           infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
6482         _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,nomcha,i+1,ft,infos,nbOfStep);
6483       }
6484     loadAllGlobals(fid);
6485   }
6486 catch(INTERP_KERNEL::Exception& e)
6487   {
6488     throw e;
6489   }
6490
6491 void MEDFileFields::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
6492 {
6493   int i=0;
6494   writeGlobals(fid,*this);
6495   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
6496     {
6497       const MEDFileFieldMultiTSWithoutSDA *elt=*it;
6498       if(!elt)
6499         {
6500           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
6501           throw INTERP_KERNEL::Exception(oss.str().c_str());
6502         }
6503       elt->writeLL(fid,*this);
6504     }
6505 }
6506
6507 void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
6508 {
6509   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
6510   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
6511   writeLL(fid);
6512 }
6513
6514 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
6515 {
6516   std::vector<std::string> ret;
6517   std::set<std::string> ret2;
6518   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
6519     {
6520       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
6521       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
6522         if(ret2.find(*it2)==ret2.end())
6523           {
6524             ret.push_back(*it2);
6525             ret2.insert(*it2);
6526           }
6527     }
6528   return ret;
6529 }
6530
6531 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
6532 {
6533   std::vector<std::string> ret;
6534   std::set<std::string> ret2;
6535   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
6536     {
6537       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
6538       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
6539         if(ret2.find(*it2)==ret2.end())
6540           {
6541             ret.push_back(*it2);
6542             ret2.insert(*it2);
6543           }
6544     }
6545   return ret;
6546 }
6547
6548 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
6549 {
6550   std::vector<std::string> ret;
6551   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
6552     {
6553       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
6554       ret.insert(ret.end(),tmp.begin(),tmp.end());
6555     }
6556   return ret;
6557 }
6558
6559 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
6560 {
6561   std::vector<std::string> ret;
6562   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
6563     {
6564       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
6565       ret.insert(ret.end(),tmp.begin(),tmp.end());
6566     }
6567   return ret;
6568 }
6569
6570 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
6571 {
6572   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
6573     (*it)->changePflsRefsNamesGen2(mapOfModif);
6574 }
6575
6576 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
6577 {
6578   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
6579     (*it)->changeLocsRefsNamesGen2(mapOfModif);
6580 }
6581
6582 void MEDFileFields::resize(int newSize) throw(INTERP_KERNEL::Exception)
6583 {
6584   _fields.resize(newSize);
6585 }
6586
6587 void MEDFileFields::pushField(MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
6588 {
6589   if(!field)
6590     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
6591   _fields.push_back(field->getContent());
6592   appendGlobs(*field,1e-12);
6593 }
6594
6595 void MEDFileFields::setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
6596 {
6597   if(!field)
6598     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
6599   if(i>=(int)_fields.size())
6600     _fields.resize(i+1);
6601   _fields[i]=field->getContent();
6602   appendGlobs(*field,1e-12);
6603 }
6604
6605 void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception)
6606 {
6607   if(i<0 || i>=(int)_fields.size())
6608     {
6609       std::ostringstream oss; oss << "MEDFileFields::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
6610       throw INTERP_KERNEL::Exception(oss.str().c_str());
6611     }
6612   _fields.erase(_fields.begin()+i);
6613 }
6614
6615 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
6616 {
6617   bool ret=false;
6618   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
6619     {
6620       MEDFileFieldMultiTSWithoutSDA *cur(*it);
6621       if(cur)
6622         ret=cur->changeMeshNames(modifTab) || ret;
6623     }
6624   return ret;
6625 }
6626
6627 /*!
6628  * \param [in] meshName the name of the mesh that will be renumbered.
6629  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
6630  *             This code corresponds to the distribution of types in the corresponding mesh.
6631  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
6632  * \param [in] renumO2N the old to new renumber array.
6633  * \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 
6634  *         field in \a this.
6635  */
6636 bool MEDFileFields::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N) throw(INTERP_KERNEL::Exception)
6637 {
6638   bool ret=false;
6639   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
6640     {
6641       MEDFileFieldMultiTSWithoutSDA *fmts(*it);
6642       if(fmts)
6643         {
6644           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
6645         }
6646     }
6647   return ret;
6648 }
6649
6650 MEDFileFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception)
6651 {
6652   if(i<0 || i>=(int)_fields.size())
6653     {
6654       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
6655       throw INTERP_KERNEL::Exception(oss.str().c_str());
6656     }
6657   const MEDFileFieldMultiTSWithoutSDA *fmts=_fields[i];
6658   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New(*fmts,false);
6659   ret->shallowCpyGlobs(*this);
6660   return ret.retn();
6661 }
6662
6663 MEDFileFieldMultiTS *MEDFileFields::getFieldWithName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
6664 {
6665   return getFieldAtPos(getPosFromFieldName(fieldName));
6666 }
6667
6668 MEDFileFieldsIterator *MEDFileFields::iterator() throw(INTERP_KERNEL::Exception)
6669 {
6670   return new MEDFileFieldsIterator(this);
6671 }
6672
6673 int MEDFileFields::getPosFromFieldName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
6674 {
6675   std::string tmp(fieldName);
6676   std::vector<std::string> poss;
6677   for(std::size_t i=0;i<_fields.size();i++)
6678     {
6679       const MEDFileFieldMultiTSWithoutSDA *f=_fields[i];
6680       if(f)
6681         {
6682           std::string fname(f->getName());
6683           if(tmp==fname)
6684             return i;
6685           else
6686             poss.push_back(fname);
6687         }
6688     }
6689   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
6690   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
6691   oss << " !";
6692   throw INTERP_KERNEL::Exception(oss.str().c_str());
6693 }
6694
6695 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
6696 {
6697   if(fs)
6698     {
6699       fs->incrRef();
6700       _nb_iter=fs->getNumberOfFields();
6701     }
6702 }
6703
6704 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
6705 {
6706 }
6707
6708 MEDFileFieldMultiTS *MEDFileFieldsIterator::nextt()
6709 {
6710   if(_iter_id<_nb_iter)
6711     {
6712       MEDFileFields *fs(_fs);
6713       if(fs)
6714         return fs->getFieldAtPos(_iter_id++);
6715       else
6716         return 0;
6717     }
6718   else
6719     return 0;
6720 }