Salome HOME
Merge from V6_main 01/04/2013
[modules/med.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   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1067   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1068   if(retTmp->presenceOfValue(-1))
1069     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1070   std::vector<int> ret(retTmp->begin(),retTmp->end());
1071   return ret;
1072 }
1073
1074 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1075 {
1076   TypeOfField type=field->getTypeOfField();
1077   if(type!=ON_GAUSS_PT)
1078     {
1079       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1080       int sz=_field_pm_pt_pd.size();
1081       bool found=false;
1082       for(int j=0;j<sz && !found;j++)
1083         {
1084           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1085             {
1086               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1087               found=true;
1088             }
1089         }
1090       if(!found)
1091         {
1092           _field_pm_pt_pd.resize(sz+1);
1093           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1094         }
1095       std::vector<int> ret(1,0);
1096       return ret;
1097     }
1098   else
1099     {
1100       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1101       int sz2=ret2.size();
1102       std::vector<int> ret3(sz2);
1103       int k=0;
1104       for(int i=0;i<sz2;i++)
1105         {
1106           int sz=_field_pm_pt_pd.size();
1107           int locIdToFind=ret2[i];
1108           bool found=false;
1109           for(int j=0;j<sz && !found;j++)
1110             {
1111               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1112                 {
1113                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1114                   ret3[k++]=j;
1115                   found=true;
1116                 }
1117             }
1118           if(!found)
1119             {
1120               _field_pm_pt_pd.resize(sz+1);
1121               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1122               ret3[k++]=sz;
1123             }
1124         }
1125       return ret3;
1126     }
1127 }
1128
1129 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1130 {
1131   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1132   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1133   if(!disc2)
1134     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1135   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1136   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1137   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1138   if(retTmp->presenceOfValue(-1))
1139     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1140   std::vector<int> ret(retTmp->begin(),retTmp->end());
1141   return ret;
1142 }
1143
1144 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1145 {
1146   return _father;
1147 }
1148
1149 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1150 {
1151   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1152   int curDim=(int)cm.getDimension();
1153   dim=std::max(dim,curDim);
1154 }
1155
1156 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1157 {
1158   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1159     {
1160       (*it)->fillTypesOfFieldAvailable(types);
1161     }
1162 }
1163
1164 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)
1165 {
1166   int sz=_field_pm_pt_pd.size();
1167   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1168   for(int i=0;i<sz;i++)
1169     {
1170       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1171     }
1172 }
1173
1174 int MEDFileFieldPerMeshPerType::getIteration() const
1175 {
1176   return _father->getIteration();
1177 }
1178
1179 int MEDFileFieldPerMeshPerType::getOrder() const
1180 {
1181   return _father->getOrder();
1182 }
1183
1184 double MEDFileFieldPerMeshPerType::getTime() const
1185 {
1186   return _father->getTime();
1187 }
1188
1189 std::string MEDFileFieldPerMeshPerType::getName() const
1190 {
1191   return _father->getName();
1192 }
1193
1194 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1195 {
1196   return _father->getMeshName();
1197 }
1198
1199 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1200 {
1201   const char startLine[]="  ## ";
1202   std::string startLine2(bkOffset,' ');
1203   std::string startLine3(startLine2);
1204   startLine3+=startLine;
1205   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1206     {
1207       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1208       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1209     }
1210   else
1211     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1212   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1213   int i=0;
1214   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1215     {
1216       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1217       if(cur)
1218         cur->simpleRepr(bkOffset,oss,i);
1219       else
1220         {
1221           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1222         }
1223     }
1224 }
1225
1226 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1227 {
1228   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1229     {
1230       globalSz+=(*it)->getNumberOfTuples();
1231     }
1232   nbOfEntries+=(int)_field_pm_pt_pd.size();
1233 }
1234
1235 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1236 {
1237   return _geo_type;
1238 }
1239
1240
1241 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1242 {
1243   return _father->getNumberOfComponents();
1244 }
1245
1246 DataArrayDouble *MEDFileFieldPerMeshPerType::getArray()
1247 {
1248   return _father->getArray();
1249 }
1250
1251 const DataArrayDouble *MEDFileFieldPerMeshPerType::getArray() const
1252 {
1253   const MEDFileFieldPerMesh *fath=_father;
1254   return fath->getArray();
1255 }
1256
1257 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1258 {
1259   return _father->getInfo();
1260 }
1261
1262 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1263 {
1264   std::vector<std::string> ret;
1265   std::set<std::string> ret2;
1266   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1267     {
1268       std::string tmp=(*it1)->getProfile();
1269       if(!tmp.empty())
1270         if(ret2.find(tmp)==ret2.end())
1271           {
1272             ret.push_back(tmp);
1273             ret2.insert(tmp);
1274           }
1275     }
1276   return ret;
1277 }
1278
1279 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1280 {
1281   std::vector<std::string> ret;
1282   std::set<std::string> ret2;
1283   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1284     {
1285       std::string tmp=(*it1)->getLocalization();
1286       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1287         if(ret2.find(tmp)==ret2.end())
1288           {
1289             ret.push_back(tmp);
1290             ret2.insert(tmp);
1291           }
1292     }
1293   return ret;
1294 }
1295
1296 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1297 {
1298   std::vector<std::string> ret;
1299   std::set<std::string> ret2;
1300   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1301     {
1302       std::string tmp=(*it1)->getProfile();
1303       if(!tmp.empty())
1304         ret.push_back(tmp);
1305     }
1306   return ret;
1307 }
1308
1309 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1310 {
1311   std::vector<std::string> ret;
1312   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1313     {
1314       std::string tmp=(*it1)->getLocalization();
1315       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1316         ret.push_back(tmp);
1317     }
1318   return ret;
1319 }
1320
1321 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1322 {
1323   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1324     (*it1)->changePflsRefsNamesGen(mapOfModif);
1325 }
1326
1327 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1328 {
1329   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1330     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1331 }
1332
1333 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) throw(INTERP_KERNEL::Exception)
1334 {
1335   if(_field_pm_pt_pd.empty())
1336     {
1337       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1338       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1339       throw INTERP_KERNEL::Exception(oss.str().c_str());
1340     }
1341   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1342     return _field_pm_pt_pd[locId];
1343   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1344   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1345   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1346   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1347   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1348 }
1349
1350 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const throw(INTERP_KERNEL::Exception)
1351 {
1352   if(_field_pm_pt_pd.empty())
1353     {
1354       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1355       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1356       throw INTERP_KERNEL::Exception(oss.str().c_str());
1357     }
1358   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1359     return _field_pm_pt_pd[locId];
1360   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1361   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1362   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1363   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1364   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1365 }
1366
1367 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
1368 {
1369   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1370     {
1371       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1372       if(meshDim!=(int)cm.getDimension())
1373         return ;
1374     }
1375   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1376     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1377 }
1378
1379 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1380 {
1381   int i=0;
1382   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1383     {
1384       (*it)->fillValues(i,startEntryId,entries);
1385     }
1386 }
1387
1388 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1389 {
1390   _field_pm_pt_pd=leaves;
1391   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1392     (*it)->setFather(this);
1393 }
1394
1395 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType)
1396 {
1397 }
1398
1399 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType)
1400 {
1401   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1402   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1403   med_geometry_type mgeoti;
1404   med_entity_type menti=ConvertIntoMEDFileType(type,geoType,mgeoti);
1405   int nbProfiles=MEDfieldnProfile(fid,getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName);
1406   _field_pm_pt_pd.resize(nbProfiles);
1407   for(int i=0;i<nbProfiles;i++)
1408     {
1409       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i+1);
1410     }
1411 }
1412
1413 void MEDFileFieldPerMeshPerType::prepareLoading(med_idt fid, int &start) throw(INTERP_KERNEL::Exception)
1414 {
1415   int pflId=0;
1416   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1417     {
1418       (*it)->prepareLoading(fid,pflId+1,start);
1419     }
1420 }
1421
1422 void MEDFileFieldPerMeshPerType::finishLoading(med_idt fid, int ft) throw(INTERP_KERNEL::Exception)
1423 {
1424   int pflId=0;
1425   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1426     {
1427       (*it)->finishLoading(fid,pflId+1,ft);
1428     }
1429 }
1430
1431 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
1432 {
1433   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1434     {
1435       (*it)->copyOptionsFrom(*this);
1436       (*it)->writeLL(fid);
1437     }
1438 }
1439
1440 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1441 {
1442   switch(ikType)
1443     {
1444     case ON_CELLS:
1445       medfGeoType=typmai3[(int)ikGeoType];
1446       return MED_CELL;
1447     case ON_NODES:
1448       medfGeoType=MED_NONE;
1449       return MED_NODE;
1450     case ON_GAUSS_NE:
1451       medfGeoType=typmai3[(int)ikGeoType];
1452       return MED_NODE_ELEMENT;
1453     case ON_GAUSS_PT:
1454       medfGeoType=typmai3[(int)ikGeoType];
1455       return MED_CELL;
1456     default:
1457       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1458     }
1459   return MED_UNDEF_ENTITY_TYPE;
1460 }
1461
1462 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder) throw(INTERP_KERNEL::Exception)
1463 {
1464   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder);
1465 }
1466
1467 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1468 {
1469   return new MEDFileFieldPerMesh(fath,mesh);
1470 }
1471
1472 std::size_t MEDFileFieldPerMesh::getHeapMemorySize() const
1473 {
1474   std::size_t ret=_mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1475   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1476     if((const MEDFileFieldPerMeshPerType *)*it)
1477       ret+=(*it)->getHeapMemorySize();
1478   return ret;
1479 }
1480
1481 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileField1TSWithoutSDA *father) const throw(INTERP_KERNEL::Exception)
1482 {
1483   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1484   ret->_father=father;
1485   std::size_t i=0;
1486   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1487     {
1488       if((const MEDFileFieldPerMeshPerType *)*it)
1489         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1490     }
1491   return ret.retn();
1492 }
1493
1494 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1495 {
1496   std::string startLine(bkOffset,' ');
1497   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1498   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1499   int i=0;
1500   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1501     {
1502       const MEDFileFieldPerMeshPerType *cur=*it;
1503       if(cur)
1504         cur->simpleRepr(bkOffset,oss,i);
1505       else
1506         {
1507           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1508         }
1509     }
1510 }
1511
1512 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
1513 {
1514   _mesh_name=mesh->getName();
1515   mesh->getTime(_mesh_iteration,_mesh_order);
1516 }
1517
1518 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1519 {
1520   int nbOfTypes=code.size()/3;
1521   int offset=0;
1522   for(int i=0;i<nbOfTypes;i++)
1523     {
1524       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1525       int nbOfCells=code[3*i+1];
1526       int pos=addNewEntryIfNecessary(type);
1527       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,glob);
1528       offset+=nbOfCells;
1529     }
1530 }
1531
1532 /*!
1533  * This method is the most general one. No optimization is done here.
1534  * \param [in] multiTypePfl is the end user profile specified in high level API
1535  * \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].
1536  * \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.
1537  * \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.
1538  * \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.
1539  * \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.
1540  */
1541 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)
1542 {
1543   int nbOfTypes=code.size()/3;
1544   for(int i=0;i<nbOfTypes;i++)
1545     {
1546       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1547       int pos=addNewEntryIfNecessary(type);
1548       DataArrayInt *pfl=0;
1549       if(code[3*i+2]!=-1)
1550         pfl=idsPerType[code[3*i+2]];
1551       int nbOfTupes2=code2.size()/3;
1552       int found=0;
1553       for(;found<nbOfTupes2;found++)
1554         if(code[3*i]==code2[3*found])
1555           break;
1556       if(found==nbOfTupes2)
1557         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1558       _field_pm_pt[pos]->assignFieldProfile(start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,mesh,glob);
1559     }
1560 }
1561
1562 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1563 {
1564   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1565   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,glob);
1566 }
1567
1568 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1569 {
1570   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1571   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,glob);
1572 }
1573
1574 void MEDFileFieldPerMesh::prepareLoading(med_idt fid, int& start) throw(INTERP_KERNEL::Exception)
1575 {
1576   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1577     (*it)->prepareLoading(fid,start);
1578 }
1579
1580 void MEDFileFieldPerMesh::finishLoading(med_idt fid, int ft) throw(INTERP_KERNEL::Exception)
1581 {
1582   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1583     (*it)->finishLoading(fid,ft);
1584 }
1585
1586 void MEDFileFieldPerMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
1587 {
1588   int nbOfTypes=_field_pm_pt.size();
1589   for(int i=0;i<nbOfTypes;i++)
1590     {
1591       _field_pm_pt[i]->copyOptionsFrom(*this);
1592       _field_pm_pt[i]->writeLL(fid);
1593     }
1594 }
1595
1596 void MEDFileFieldPerMesh::getDimension(int& dim) const
1597 {
1598   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1599     (*it)->getDimension(dim);
1600 }
1601
1602 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1603 {
1604   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1605     (*it)->fillTypesOfFieldAvailable(types);
1606 }
1607
1608 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)
1609 {
1610   int sz=_field_pm_pt.size();
1611   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1612   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1613   for(int i=0;i<sz;i++)
1614     {
1615       types[i]=_field_pm_pt[i]->getGeoType();
1616       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1617     }
1618   return ret;
1619 }
1620
1621 double MEDFileFieldPerMesh::getTime() const
1622 {
1623   int tmp1,tmp2;
1624   return _father->getTime(tmp1,tmp2);
1625 }
1626
1627 int MEDFileFieldPerMesh::getIteration() const
1628 {
1629   return _father->getIteration();
1630 }
1631
1632 const std::string& MEDFileFieldPerMesh::getDtUnit() const
1633 {
1634   return _father->getDtUnit();
1635 }
1636
1637 int MEDFileFieldPerMesh::getOrder() const
1638 {
1639   return _father->getOrder();
1640 }
1641
1642 std::string MEDFileFieldPerMesh::getName() const
1643 {
1644   return _father->getName();
1645 }
1646
1647 int MEDFileFieldPerMesh::getNumberOfComponents() const
1648 {
1649   return _father->getNumberOfComponents();
1650 }
1651
1652 DataArrayDouble *MEDFileFieldPerMesh::getArray()
1653 {
1654   return _father->getOrCreateAndGetArray();
1655 }
1656
1657 const DataArrayDouble *MEDFileFieldPerMesh::getArray() const
1658 {
1659   const MEDFileField1TSWithoutSDA *fath=_father;
1660   return fath->getOrCreateAndGetArray();
1661 }
1662
1663 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1664 {
1665   return _father->getInfo();
1666 }
1667
1668 /*!
1669  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1670  * 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.
1671  * It returns 2 output vectors :
1672  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1673  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1674  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1675  */
1676 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)
1677 {
1678   int notNullPflsSz=0;
1679   int nbOfArrs=geoTypes.size();
1680   for(int i=0;i<nbOfArrs;i++)
1681     if(pfls[i])
1682       notNullPflsSz++;
1683   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1684   int nbOfDiffGeoTypes=geoTypes3.size();
1685   code.resize(3*nbOfDiffGeoTypes);
1686   notNullPfls.resize(notNullPflsSz);
1687   notNullPflsSz=0;
1688   int j=0;
1689   for(int i=0;i<nbOfDiffGeoTypes;i++)
1690     {
1691       int startZone=j;
1692       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1693       std::vector<const DataArrayInt *> notNullTmp;
1694       if(pfls[j])
1695         notNullTmp.push_back(pfls[j]);
1696       j++;
1697       for(;j<nbOfArrs;j++)
1698         if(geoTypes[j]==refType)
1699           {
1700             if(pfls[j])
1701               notNullTmp.push_back(pfls[j]);
1702           }
1703         else
1704           break;
1705       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1706       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1707       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1708       code[3*i]=(int)refType;
1709       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1710       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1711       if(notNullTmp.empty())
1712         code[3*i+2]=-1;
1713       else
1714         {
1715           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1716           code[3*i+2]=notNullPflsSz++;
1717         }
1718     }
1719 }
1720
1721 /*!
1722  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1723  */
1724 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)
1725 {
1726   int sz=dads.size();
1727   int ret=0;
1728   for(int i=0;i<sz;i++)
1729     {
1730       if(locs[i]==-1)
1731         {
1732           if(type!=ON_GAUSS_NE)
1733             ret+=dads[i].second-dads[i].first;
1734           else
1735             {
1736               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1737               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1738             }
1739         }
1740       else
1741         {
1742           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1743           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1744         }
1745     }
1746   return ret;
1747 }
1748
1749 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1750 {
1751   std::vector<std::string> ret;
1752   std::set<std::string> ret2;
1753   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1754     {
1755       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1756       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1757         if(ret2.find(*it2)==ret2.end())
1758           {
1759             ret.push_back(*it2);
1760             ret2.insert(*it2);
1761           }
1762     }
1763   return ret;
1764 }
1765
1766 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1767 {
1768   std::vector<std::string> ret;
1769   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1770     {
1771       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1772       ret.insert(ret.end(),tmp.begin(),tmp.end());
1773     }
1774   return ret;
1775 }
1776
1777 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1778 {
1779   std::vector<std::string> ret;
1780   std::set<std::string> ret2;
1781   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1782     {
1783       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1784       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1785         if(ret2.find(*it2)==ret2.end())
1786           {
1787             ret.push_back(*it2);
1788             ret2.insert(*it2);
1789           }
1790     }
1791   return ret;
1792 }
1793
1794 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1795 {
1796   std::vector<std::string> ret;
1797   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1798     {
1799       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1800       ret.insert(ret.end(),tmp.begin(),tmp.end());
1801     }
1802   return ret;
1803 }
1804
1805 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
1806 {
1807   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1808     {
1809       if((*it).first==_mesh_name)
1810         {
1811           _mesh_name=(*it).second;
1812           return true;
1813         }
1814     }
1815   return false;
1816 }
1817
1818 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1819                                                       MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1820 {
1821   if(_mesh_name!=meshName)
1822     return false;
1823   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1824   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1825   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1826   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1827   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1828   DataArrayDouble *arr=getUndergroundDataArrayExt(entries);
1829   int sz=0;
1830   if(!arr)
1831     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1832   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1833     {
1834       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1835         {
1836           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1837           sz+=(*it).second.second-(*it).second.first;
1838         }
1839       else
1840         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1841     }
1842   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1843   ////////////////////
1844   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1845   int *workI2=explicitIdsOldInMesh->getPointer();
1846   int sz1=0,sz2=0,sid=1;
1847   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1848   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1849   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1850     {
1851       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1852       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1853       int *workI=explicitIdsOldInArr->getPointer();
1854       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1855         {
1856           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1857           (*itL2)->setLocId(sz2);
1858           (*itL2)->_tmp_work1=(*itL2)->getStart();
1859           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1860         }
1861       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1862     }
1863   explicitIdsOldInMesh->reAlloc(sz2);
1864   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1865   ////////////////////
1866   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1867   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1868   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1869   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1870     {
1871       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1872       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1873       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1874     }
1875   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1876   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1877   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
1878     {
1879       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1880       int newStart=elt->getLocId();
1881       elt->setLocId((*it)->getGeoType());
1882       elt->setNewStart(newStart);
1883       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
1884       entriesKeptNew.push_back(elt);
1885       entriesKeptNew2.push_back(elt);
1886     }
1887   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
1888   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
1889   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
1890   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
1891   bool ret=false;
1892   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
1893     {
1894       sid=0;
1895       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
1896         {
1897           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
1898           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
1899           }*/
1900       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
1901                                                             glob,arr2,otherEntriesNew) || ret;
1902     }
1903   if(!ret)
1904     return false;
1905   // Assign new dispatching
1906   assignNewLeaves(otherEntriesNew);
1907   arr->cpyFrom(*arr2);
1908   return true;
1909 }
1910
1911 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1912 {
1913   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
1914   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
1915     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
1916   //
1917   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
1918   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
1919   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
1920   for(;it1!=types.end();it1++,it2++)
1921     {
1922       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
1923       elt->setLeaves((*it1).second);
1924       *it2=elt;
1925     }
1926   _field_pm_pt=fieldPmPt;
1927 }
1928
1929 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1930 {
1931   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1932     (*it)->changePflsRefsNamesGen(mapOfModif);
1933 }
1934
1935 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1936 {
1937   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1938     (*it)->changeLocsRefsNamesGen(mapOfModif);
1939 }
1940
1941 /*!
1942  * \param [in] mesh is the whole mesh
1943  */
1944 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception)
1945 {
1946   if(_field_pm_pt.empty())
1947     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
1948   //
1949   std::vector< std::pair<int,int> > dads;
1950   std::vector<const DataArrayInt *> pfls;
1951   std::vector<DataArrayInt *> notNullPflsPerGeoType;
1952   std::vector<int> locs,code;
1953   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
1954   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1955     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
1956   // Sort by types
1957   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
1958   if(code.empty())
1959     {
1960       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << getName() << "\" exists but not with such spatial discretization or such dimension specified !";
1961       throw INTERP_KERNEL::Exception(oss.str().c_str());
1962     }
1963   //
1964   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
1965   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
1966   if(type!=ON_NODES)
1967     {
1968       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
1969       if(!arr)
1970         return finishField(type,glob,dads,locs,mesh,isPfl);
1971       else
1972         {
1973           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
1974           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl);
1975         }
1976     }
1977   else
1978     {
1979       if(code.size()!=3)
1980         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
1981       int nb=code[1];
1982       if(code[2]==-1)
1983         {
1984           if(nb!=mesh->getNumberOfNodes())
1985             {
1986               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
1987               oss << " nodes in mesh !";
1988               throw INTERP_KERNEL::Exception(oss.str().c_str());
1989             }
1990           return finishField(type,glob,dads,locs,mesh,isPfl);
1991         }
1992       else
1993         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl);
1994     }
1995 }
1996
1997 DataArrayDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
1998 {
1999   if(_field_pm_pt.empty())
2000     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2001   //
2002   std::vector<std::pair<int,int> > dads;
2003   std::vector<const DataArrayInt *> pfls;
2004   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2005   std::vector<int> locs,code;
2006   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2007   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2008     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2009   // Sort by types
2010   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2011   if(code.empty())
2012     {
2013       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2014       throw INTERP_KERNEL::Exception(oss.str().c_str());
2015     }
2016   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2017   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2018   if(type!=ON_NODES)
2019     {
2020       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2021       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2022     }
2023   else
2024     {
2025       if(code.size()!=3)
2026         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2027       int nb=code[1];
2028       if(code[2]==-1)
2029         {
2030           if(nb!=mesh->getNumberOfNodes())
2031             {
2032               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2033               oss << " nodes in mesh !";
2034               throw INTERP_KERNEL::Exception(oss.str().c_str());
2035             }
2036         }
2037       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2038     }
2039   //
2040   return 0;
2041 }
2042
2043 DataArrayDouble *MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
2044 {
2045   int globalSz=0;
2046   int nbOfEntries=0;
2047   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2048     {
2049       (*it)->getSizes(globalSz,nbOfEntries);
2050     }
2051   entries.resize(nbOfEntries);
2052   nbOfEntries=0;
2053   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2054     {
2055       (*it)->fillValues(nbOfEntries,entries);
2056     }
2057   return _father->getUndergroundDataArray();
2058 }
2059
2060 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
2061 {
2062   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2063     {
2064       if((*it)->getGeoType()==typ)
2065         return (*it)->getLeafGivenLocId(locId);
2066     }
2067   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2068   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2069   oss << "Possiblities are : ";
2070   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2071     {
2072       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2073       oss << "\"" << cm2.getRepr() << "\", ";
2074     }
2075   throw INTERP_KERNEL::Exception(oss.str().c_str());
2076 }
2077
2078 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
2079 {
2080   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2081     {
2082       if((*it)->getGeoType()==typ)
2083         return (*it)->getLeafGivenLocId(locId);
2084     }
2085   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2086   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2087   oss << "Possiblities are : ";
2088   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2089     {
2090       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2091       oss << "\"" << cm2.getRepr() << "\", ";
2092     }
2093   throw INTERP_KERNEL::Exception(oss.str().c_str());
2094 }
2095
2096 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2097 {
2098   int i=0;
2099   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2100   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2101   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2102     {
2103       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2104       if(type==curType)
2105         return i;
2106       else
2107         {
2108           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2109           if(pos>pos2)
2110             it2=it+1;
2111         }
2112     }
2113   int ret=std::distance(_field_pm_pt.begin(),it2);
2114   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2115   return ret;
2116 }
2117
2118 /*!
2119  * 'dads' and 'locs' input parameters have the same number of elements
2120  * \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
2121  */
2122 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2123                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2124                                                          const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception)
2125 {
2126   isPfl=false;
2127   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2128   ret->setMesh(mesh); ret->setName(getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(getDtUnit().c_str());
2129   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=getArray()->selectByTupleRanges(dads);
2130   const std::vector<std::string>& infos=getInfo();
2131   da->setInfoOnComponents(infos);
2132   da->setName("");
2133   ret->setArray(da);
2134   if(type==ON_GAUSS_PT)
2135     {
2136       int offset=0;
2137       int nbOfArrs=dads.size();
2138       for(int i=0;i<nbOfArrs;i++)
2139         {
2140           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2141           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2142           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2143           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2144           di->alloc(nbOfElems,1);
2145           di->iota(offset);
2146           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2147           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2148           offset+=nbOfElems;
2149         }
2150     }
2151   //
2152   return ret.retn();
2153 }
2154
2155 /*!
2156  * 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.
2157  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2158  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2159  * The order of cells in the returned field is those imposed by the profile.
2160  * \param [in] mesh is the global mesh.
2161  */
2162 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2163                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2164                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2165                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception)
2166 {
2167   if(da->isIdentity())
2168     {
2169       int nbOfTuples=da->getNumberOfTuples();
2170       if(nbOfTuples==mesh->getNumberOfCells())
2171         return finishField(type,glob,dads,locs,mesh,isPfl);
2172     }
2173   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2174   m2->setName(mesh->getName());
2175   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl);
2176   isPfl=true;
2177   return ret.retn();
2178 }
2179
2180 /*!
2181  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2182  */
2183 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2184                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2185                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception)
2186 {
2187   if(da->isIdentity())
2188     {
2189       int nbOfTuples=da->getNumberOfTuples();
2190       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2191         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl);
2192     }
2193   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2194   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2195   if(meshu)
2196     {
2197       if(meshu->getNodalConnectivity()==0)
2198         {
2199           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl);
2200           int nb=da->getNbOfElems();
2201           const int *ptr=da->getConstPointer();
2202           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2203           meshuc->allocateCells(nb);
2204           for(int i=0;i<nb;i++)
2205             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2206           meshuc->finishInsertingCells();
2207           ret->setMesh(meshuc);
2208           ret->checkCoherency();
2209           return ret.retn();
2210         }
2211     }
2212   //
2213   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl);
2214   isPfl=true;
2215   DataArrayInt *arr2=0;
2216   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2217   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2218   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2219   int nnodes=mesh2->getNumberOfNodes();
2220   if(nnodes==(int)da->getNbOfElems())
2221     {
2222       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2223       ret->getArray()->renumberInPlace(da3->getConstPointer());
2224       mesh2->setName(mesh->getName());
2225       ret->setMesh(mesh2);
2226       return ret.retn();
2227     }
2228   else
2229     {
2230       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 !!!";
2231       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2232       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2233       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2234       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2235       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2236       throw INTERP_KERNEL::Exception(oss.str().c_str());
2237     }
2238   return 0;
2239 }
2240
2241 /*!
2242  * This method is the most light method of field retrieving.
2243  */
2244 DataArrayDouble *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const throw(INTERP_KERNEL::Exception)
2245 {
2246   if(!pflIn)
2247     {
2248       pflOut=DataArrayInt::New();
2249       pflOut->alloc(nbOfElems,1);
2250       pflOut->iota(0);
2251     }
2252   else
2253     {
2254       pflOut=const_cast<DataArrayInt*>(pflIn);
2255       pflOut->incrRef();
2256     }
2257   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2258   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=getArray()->selectByTupleRanges(dads);
2259   const std::vector<std::string>& infos=getInfo();
2260   int nbOfComp=infos.size();
2261   for(int i=0;i<nbOfComp;i++)
2262     da->setInfoOnComponent(i,infos[i].c_str());
2263   safePfl->incrRef();
2264   return da.retn();
2265 }
2266
2267 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder) throw(INTERP_KERNEL::Exception):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2268                                                                                                                                                                        _mesh_csit(meshCsit),_father(fath)
2269 {
2270   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2271   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2272   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2273   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2274     {
2275       int nbProfile=MEDfield23nProfile(fid,getName().c_str(),getIteration(),getOrder(),MED_CELL,typmai[i],_mesh_csit,meshName,pflName,locName);
2276       if(nbProfile>0)
2277         {
2278           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i]));
2279           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2280         }
2281       nbProfile=MEDfield23nProfile(fid,getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],_mesh_csit,meshName,pflName,locName);
2282       if(nbProfile>0)
2283         {
2284           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_GAUSS_NE,typmai2[i]));
2285           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2286         }
2287     }
2288   int nbProfile=MEDfield23nProfile(fid,getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,_mesh_csit,meshName,pflName,locName);
2289   if(nbProfile>0)
2290     {
2291       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR));
2292       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2293     }
2294 }
2295
2296 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2297 {
2298   copyTinyInfoFrom(mesh);
2299 }
2300
2301 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
2302 {
2303   if(id>=(int)_pfls.size())
2304     _pfls.resize(id+1);
2305   _pfls[id]=DataArrayInt::New();
2306   int lgth=MEDprofileSizeByName(fid,pflName);
2307   _pfls[id]->setName(pflName);
2308   _pfls[id]->alloc(lgth,1);
2309   MEDprofileRd(fid,pflName,_pfls[id]->getPointer());
2310   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2311 }
2312
2313 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2314 {
2315   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2316   int sz;
2317   MEDprofileInfo(fid,i+1,pflName,&sz);
2318   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2319   if(i>=(int)_pfls.size())
2320     _pfls.resize(i+1);
2321   _pfls[i]=DataArrayInt::New();
2322   _pfls[i]->alloc(sz,1);
2323   _pfls[i]->setName(pflCpp.c_str());
2324   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2325   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2326 }
2327
2328 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
2329 {
2330   int nbOfPfls=_pfls.size();
2331   for(int i=0;i<nbOfPfls;i++)
2332     {
2333       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2334       cpy->applyLin(1,1,0);
2335       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2336       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2337       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2338     }
2339   //
2340   int nbOfLocs=_locs.size();
2341   for(int i=0;i<nbOfLocs;i++)
2342     _locs[i]->writeLL(fid);
2343 }
2344
2345 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps) throw(INTERP_KERNEL::Exception)
2346 {
2347   std::vector<std::string> pfls=getPfls();
2348   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2349     {
2350       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2351       if(it2==pfls.end())
2352         {
2353           _pfls.push_back(*it);
2354         }
2355       else
2356         {
2357           int id=std::distance(pfls.begin(),it2);
2358           if(!(*it)->isEqual(*_pfls[id]))
2359             {
2360               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2361               throw INTERP_KERNEL::Exception(oss.str().c_str());
2362             }
2363         }
2364     }
2365   std::vector<std::string> locs=getLocs();
2366   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2367     {
2368       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2369       if(it2==locs.end())
2370         {
2371           _locs.push_back(*it);
2372         }
2373       else
2374         {
2375           int id=std::distance(locs.begin(),it2);
2376           if(!(*it)->isEqual(*_locs[id],eps))
2377             {
2378               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2379               throw INTERP_KERNEL::Exception(oss.str().c_str());
2380             }
2381         }
2382     }
2383 }
2384
2385 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real) throw(INTERP_KERNEL::Exception)
2386 {
2387   std::vector<std::string> profiles=real.getPflsReallyUsed();
2388   int sz=profiles.size();
2389   _pfls.resize(sz);
2390   for(int i=0;i<sz;i++)
2391     loadProfileInFile(fid,i,profiles[i].c_str());
2392   //
2393   std::vector<std::string> locs=real.getLocsReallyUsed();
2394   sz=locs.size();
2395   _locs.resize(sz);
2396   for(int i=0;i<sz;i++)
2397     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2398 }
2399
2400 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2401 {
2402   int nProfil=MEDnProfile(fid);
2403   for(int i=0;i<nProfil;i++)
2404     loadProfileInFile(fid,i);
2405   int sz=MEDnLocalization(fid);
2406   _locs.resize(sz);
2407   for(int i=0;i<sz;i++)
2408     {
2409       _locs[i]=MEDFileFieldLoc::New(fid,i);
2410     }
2411 }
2412
2413 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const char *fname)
2414 {
2415   return new MEDFileFieldGlobs(fname);
2416 }
2417
2418 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2419 {
2420   return new MEDFileFieldGlobs;
2421 }
2422
2423 std::size_t MEDFileFieldGlobs::getHeapMemorySize() const
2424 {
2425   std::size_t ret=_file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2426   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2427     ret+=(*it)->getHeapMemorySize();
2428   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2429     ret+=(*it)->getHeapMemorySize();
2430   return ret;
2431 }
2432
2433 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const throw(INTERP_KERNEL::Exception)
2434 {
2435   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2436   std::size_t i=0;
2437   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2438     {
2439       if((const DataArrayInt *)*it)
2440         ret->_pfls[i]=(*it)->deepCpy();
2441     }
2442   i=0;
2443   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2444     {
2445       if((const MEDFileFieldLoc*)*it)
2446         ret->_locs[i]=(*it)->deepCpy();
2447     }
2448   return ret.retn();
2449 }
2450
2451 MEDFileFieldGlobs::MEDFileFieldGlobs(const char *fname):_file_name(fname)
2452 {
2453 }
2454
2455 MEDFileFieldGlobs::MEDFileFieldGlobs()
2456 {
2457 }
2458
2459 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2460 {
2461 }
2462
2463 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2464 {
2465   oss << "Profiles :\n";
2466   std::size_t n=_pfls.size();
2467   for(std::size_t i=0;i<n;i++)
2468     {
2469       oss << "  - #" << i << " ";
2470       const DataArrayInt *pfl=_pfls[i];
2471       if(pfl)
2472         oss << "\"" << pfl->getName() << "\"\n";
2473       else
2474         oss << "EMPTY !\n";
2475     }
2476   n=_locs.size();
2477   oss << "Localizations :\n";
2478   for(std::size_t i=0;i<n;i++)
2479     {
2480       oss << "  - #" << i << " ";
2481       const MEDFileFieldLoc *loc=_locs[i];
2482       if(loc)
2483         loc->simpleRepr(oss);
2484       else
2485         oss<< "EMPTY !\n";
2486     }
2487 }
2488
2489 void MEDFileFieldGlobs::setFileName(const char *fileName)
2490 {
2491   _file_name=fileName;
2492 }
2493
2494 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2495 {
2496   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2497     {
2498       DataArrayInt *elt(*it);
2499       if(elt)
2500         {
2501           std::string name(elt->getName());
2502           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2503             {
2504               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2505                 {
2506                   elt->setName((*it2).second.c_str());
2507                   return;
2508                 }
2509             }
2510         }
2511     }
2512 }
2513
2514 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2515 {
2516   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2517     {
2518       MEDFileFieldLoc *elt(*it);
2519       if(elt)
2520         {
2521           std::string name(elt->getName());
2522           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2523             {
2524               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2525                 {
2526                   elt->setName((*it2).second.c_str());
2527                   return;
2528                 }
2529             }
2530         }
2531     }
2532 }
2533
2534 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
2535 {
2536   if(locId<0 || locId>=(int)_locs.size())
2537     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2538   return _locs[locId]->getNbOfGaussPtPerCell();
2539 }
2540
2541 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
2542 {
2543   return getLocalizationFromId(getLocalizationId(locName));
2544 }
2545
2546 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
2547 {
2548   if(locId<0 || locId>=(int)_locs.size())
2549     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2550   return *_locs[locId];
2551 }
2552
2553 namespace ParaMEDMEMImpl
2554 {
2555   class LocFinder
2556   {
2557   public:
2558     LocFinder(const char *loc):_loc(loc) { }
2559     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2560   private:
2561     const char *_loc;
2562   };
2563
2564   class PflFinder
2565   {
2566   public:
2567     PflFinder(const std::string& pfl):_pfl(pfl) { }
2568     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2569   private:
2570     const std::string& _pfl;
2571   };
2572 }
2573
2574 int MEDFileFieldGlobs::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
2575 {
2576   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2577   if(it==_locs.end())
2578     {
2579       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2580       for(it=_locs.begin();it!=_locs.end();it++)
2581         oss << "\"" << (*it)->getName() << "\", ";
2582       throw INTERP_KERNEL::Exception(oss.str().c_str());
2583     }
2584   return std::distance(_locs.begin(),it);
2585 }
2586
2587 const DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
2588 {
2589   std::string pflNameCpp(pflName);
2590   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2591   if(it==_pfls.end())
2592     {
2593       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2594       for(it=_pfls.begin();it!=_pfls.end();it++)
2595         oss << "\"" << (*it)->getName() << "\", ";
2596       throw INTERP_KERNEL::Exception(oss.str().c_str());
2597     }
2598   return *it;
2599 }
2600
2601 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
2602 {
2603   if(pflId<0 || pflId>=(int)_pfls.size())
2604     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2605   return _pfls[pflId];
2606 }
2607
2608 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
2609 {
2610   if(locId<0 || locId>=(int)_locs.size())
2611     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2612   return *_locs[locId];
2613 }
2614
2615 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
2616 {
2617   return getLocalizationFromId(getLocalizationId(locName));
2618 }
2619
2620 DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
2621 {
2622   std::string pflNameCpp(pflName);
2623   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2624   if(it==_pfls.end())
2625     {
2626       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2627       for(it=_pfls.begin();it!=_pfls.end();it++)
2628         oss << "\"" << (*it)->getName() << "\", ";
2629       throw INTERP_KERNEL::Exception(oss.str().c_str());
2630     }
2631   return *it;
2632 }
2633
2634 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
2635 {
2636   if(pflId<0 || pflId>=(int)_pfls.size())
2637     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2638   return _pfls[pflId];
2639 }
2640
2641 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
2642 {
2643   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2644   int i=0;
2645   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2646     {
2647       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2648         newPfls.push_back(*it);
2649     }
2650   _pfls=newPfls;
2651 }
2652
2653 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
2654 {
2655   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2656   int i=0;
2657   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2658     {
2659       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2660         newLocs.push_back(*it);
2661     }
2662   _locs=newLocs;
2663 }
2664
2665 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2666 {
2667   int sz=_pfls.size();
2668   std::vector<std::string> ret(sz);
2669   for(int i=0;i<sz;i++)
2670     ret[i]=_pfls[i]->getName();
2671   return ret;
2672 }
2673
2674 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2675 {
2676   int sz=_locs.size();
2677   std::vector<std::string> ret(sz);
2678   for(int i=0;i<sz;i++)
2679     ret[i]=_locs[i]->getName();
2680   return ret;
2681 }
2682
2683 bool MEDFileFieldGlobs::existsPfl(const char *pflName) const
2684 {
2685   std::vector<std::string> v=getPfls();
2686   std::string s(pflName);
2687   return std::find(v.begin(),v.end(),s)!=v.end();
2688 }
2689
2690 bool MEDFileFieldGlobs::existsLoc(const char *locName) const
2691 {
2692   std::vector<std::string> v=getLocs();
2693   std::string s(locName);
2694   return std::find(v.begin(),v.end(),s)!=v.end();
2695 }
2696
2697 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2698 {
2699   std::map<int,std::vector<int> > m;
2700   int i=0;
2701   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2702     {
2703       const DataArrayInt *tmp=(*it);
2704       if(tmp)
2705         {
2706           m[tmp->getHashCode()].push_back(i);
2707         }
2708     }
2709   std::vector< std::vector<int> > ret;
2710   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2711     {
2712       if((*it2).second.size()>1)
2713         {
2714           std::vector<int> ret0;
2715           bool equalityOrNot=false;
2716           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2717             {
2718               std::vector<int>::const_iterator it4=it3; it4++;
2719               for(;it4!=(*it2).second.end();it4++)
2720                 {
2721                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2722                     {
2723                       if(!equalityOrNot)
2724                         ret0.push_back(*it3);
2725                       ret0.push_back(*it4);
2726                       equalityOrNot=true;
2727                     }
2728                 }
2729             }
2730           if(!ret0.empty())
2731             ret.push_back(ret0);
2732         }
2733     }
2734   return ret;
2735 }
2736
2737 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2738 {
2739   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2740 }
2741
2742 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
2743 {
2744   std::string name(pfl->getName());
2745   if(name.empty())
2746     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2747   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2748     if(name==(*it)->getName())
2749       {
2750         if(!pfl->isEqual(*(*it)))
2751           {
2752             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2753             throw INTERP_KERNEL::Exception(oss.str().c_str());
2754           }
2755       }
2756   pfl->incrRef();
2757   _pfls.push_back(pfl);
2758 }
2759
2760 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)
2761 {
2762   std::string name(locName);
2763   if(name.empty())
2764     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2765   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2766   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2767     if((*it)->isName(locName))
2768       {
2769         if(!(*it)->isEqual(*obj,1e-12))
2770           {
2771             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
2772             throw INTERP_KERNEL::Exception(oss.str().c_str());
2773           }
2774       }
2775   _locs.push_back(obj);
2776 }
2777
2778 std::string MEDFileFieldGlobs::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
2779 {
2780   std::vector<std::string> names=getPfls();
2781   return CreateNewNameNotIn("NewPfl_",names);
2782 }
2783
2784 std::string MEDFileFieldGlobs::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
2785 {
2786   std::vector<std::string> names=getLocs();
2787   return CreateNewNameNotIn("NewLoc_",names);
2788 }
2789
2790 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const char *prefix, const std::vector<std::string>& namesToAvoid) throw(INTERP_KERNEL::Exception)
2791 {
2792   for(std::size_t sz=0;sz<100000;sz++)
2793     {
2794       std::ostringstream tryName;
2795       tryName << prefix << sz;
2796       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
2797         return tryName.str();
2798     }
2799   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
2800 }
2801
2802 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const char *fname):_globals(MEDFileFieldGlobs::New(fname))
2803 {
2804 }
2805
2806 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
2807 {
2808 }
2809
2810 std::size_t MEDFileFieldGlobsReal::getHeapMemorySize() const
2811 {
2812   std::size_t ret=0;
2813   if((const MEDFileFieldGlobs *)_globals)
2814     ret+=_globals->getHeapMemorySize();
2815   return ret;
2816 }
2817
2818 void MEDFileFieldGlobsReal::simpleRepr(std::ostream& oss) const
2819 {
2820   oss << "Globals information on fields :" << "\n*******************************\n\n";
2821   const MEDFileFieldGlobs *glob=_globals;
2822   if(glob)
2823     glob->simpleRepr(oss);
2824   else
2825     oss << "NO GLOBAL INFORMATION !\n";
2826 }
2827
2828 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
2829 {
2830 }
2831
2832 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
2833 {
2834   _globals=other._globals;
2835 }
2836
2837 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
2838 {
2839   _globals=other._globals;
2840   if((const MEDFileFieldGlobs *)_globals)
2841     _globals=other._globals->deepCpy();
2842 }
2843
2844 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps) throw(INTERP_KERNEL::Exception)
2845 {
2846   _globals->appendGlobs(*other._globals,eps);
2847 }
2848
2849 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
2850 {
2851   _globals->loadProfileInFile(fid,id,pflName);
2852 }
2853
2854 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
2855 {
2856   _globals->loadProfileInFile(fid,id);
2857 }
2858
2859 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2860 {
2861   _globals->loadGlobals(fid,*this);
2862 }
2863
2864 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2865 {
2866   _globals->loadAllGlobals(fid);
2867 }
2868
2869 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
2870 {
2871   _globals->writeGlobals(fid,opt);
2872 }
2873
2874 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
2875 {
2876   return _globals->getPfls();
2877 }
2878
2879 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
2880 {
2881   return _globals->getLocs();
2882 }
2883
2884 bool MEDFileFieldGlobsReal::existsPfl(const char *pflName) const
2885 {
2886   return _globals->existsPfl(pflName);
2887 }
2888
2889 bool MEDFileFieldGlobsReal::existsLoc(const char *locName) const
2890 {
2891   return _globals->existsLoc(locName);
2892 }
2893
2894 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
2895 {
2896   return _globals->createNewNameOfPfl();
2897 }
2898
2899 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
2900 {
2901   return _globals->createNewNameOfLoc();
2902 }
2903
2904 void MEDFileFieldGlobsReal::setFileName(const char *fileName)
2905 {
2906   _globals->setFileName(fileName);
2907 }
2908
2909 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
2910 {
2911   return _globals->whichAreEqualProfiles();
2912 }
2913
2914 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
2915 {
2916   return _globals->whichAreEqualLocs(eps);
2917 }
2918
2919 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2920 {
2921   _globals->changePflsNamesInStruct(mapOfModif);
2922 }
2923
2924 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2925 {
2926   _globals->changeLocsNamesInStruct(mapOfModif);
2927 }
2928
2929 /*!
2930  * This method is a generalization of MEDFileFieldGlobsReal::changePflName.
2931  * This method contrary to abstract method MEDFileFieldGlobsReal::changePflsRefsNamesGen updates in addition of MEDFileFieldGlobsReal::changePflsRefsNamesGen,
2932  * the profiles themselves and not only leaves of field.
2933  */
2934 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2935 {
2936   changePflsRefsNamesGen(mapOfModif);
2937   changePflsNamesInStruct(mapOfModif);
2938 }
2939
2940 /*!
2941  * This method is a generalization of MEDFileFieldGlobsReal::changePflName.
2942  * This method contrary to abstract method MEDFileFieldGlobsReal::changeLocsRefsNamesGen updates in addition of MEDFileFieldGlobsReal::changeLocsRefsNamesGen,
2943  * the localizations themselves and not only leaves of field.
2944  */
2945 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2946 {
2947   changeLocsRefsNamesGen(mapOfModif);
2948   changeLocsNamesInStruct(mapOfModif);
2949 }
2950
2951 /*!
2952  * This method is a more friendly API but less general method than MEDFileFieldGlobsReal::changePflsNames.
2953  */
2954 void MEDFileFieldGlobsReal::changePflName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
2955 {
2956   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
2957   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
2958   mapOfModif[0]=p;
2959   changePflsNames(mapOfModif);
2960 }
2961
2962 /*!
2963  * This method is a more friendly API but less general method than MEDFileFieldGlobsReal::changeLocsNames.
2964  */
2965 void MEDFileFieldGlobsReal::changeLocName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
2966 {
2967   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
2968   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
2969   mapOfModif[0]=p;
2970   changeLocsNames(mapOfModif);
2971 }
2972
2973 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames() throw(INTERP_KERNEL::Exception)
2974 {
2975   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
2976   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
2977   int i=0;
2978   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
2979     {
2980       std::vector< std::string > tmp((*it).size());
2981       int j=0;
2982       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
2983         tmp[j]=std::string(getProfileFromId(*it2)->getName());
2984       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
2985       ret[i]=p;
2986       std::vector<int> tmp2((*it).begin()+1,(*it).end());
2987       killProfileIds(tmp2);
2988     }
2989   changePflsRefsNamesGen(ret);
2990   return ret;
2991 }
2992
2993 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps) throw(INTERP_KERNEL::Exception)
2994 {
2995   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
2996   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
2997   int i=0;
2998   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
2999     {
3000       std::vector< std::string > tmp((*it).size());
3001       int j=0;
3002       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3003         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3004       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3005       ret[i]=p;
3006       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3007       killLocalizationIds(tmp2);
3008     }
3009   changeLocsRefsNamesGen(ret);
3010   return ret;
3011 }
3012
3013 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
3014 {
3015   return _globals->getNbOfGaussPtPerCell(locId);
3016 }
3017
3018 int MEDFileFieldGlobsReal::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
3019 {
3020   return _globals->getLocalizationId(loc);
3021 }
3022
3023 const char *MEDFileFieldGlobsReal::getFileName() const
3024 {
3025   return _globals->getFileName();
3026 }
3027
3028 std::string MEDFileFieldGlobsReal::getFileName2() const
3029 {
3030   return _globals->getFileName2();
3031 }
3032
3033 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
3034 {
3035   return _globals->getLocalization(locName);
3036 }
3037
3038 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
3039 {
3040   return _globals->getLocalizationFromId(locId);
3041 }
3042
3043 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
3044 {
3045   return _globals->getProfile(pflName);
3046 }
3047
3048 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
3049 {
3050   return _globals->getProfileFromId(pflId);
3051 }
3052
3053 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
3054 {
3055   return _globals->getLocalizationFromId(locId);
3056 }
3057
3058 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
3059 {
3060   return _globals->getLocalization(locName);
3061 }
3062
3063 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
3064 {
3065   return _globals->getProfile(pflName);
3066 }
3067
3068 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
3069 {
3070   return _globals->getProfileFromId(pflId);
3071 }
3072
3073 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
3074 {
3075   _globals->killProfileIds(pflIds);
3076 }
3077
3078 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
3079 {
3080   _globals->killLocalizationIds(locIds);
3081 }
3082
3083 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
3084 {
3085   _globals->appendProfile(pfl);
3086 }
3087
3088 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)
3089 {
3090   _globals->appendLoc(locName,geoType,refCoo,gsCoo,w);
3091 }
3092
3093 /*!
3094  * This method returns the max dimension of 'this'.
3095  * This method returns -2 if 'this' is empty, -1 if only nodes are defined.
3096  */
3097 int MEDFileField1TSWithoutSDA::getDimension() const
3098 {
3099   int ret=-2;
3100   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3101     (*it)->getDimension(ret);
3102   return ret;
3103 }
3104
3105 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
3106 {
3107   if(meshDimRelToMax>0)
3108     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
3109 }
3110
3111 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
3112 {
3113   //
3114   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
3115   int nbOfTypes=geoTypes.size();
3116   std::vector<int> code(3*nbOfTypes);
3117   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
3118   arr1->alloc(nbOfTypes,1);
3119   int *arrPtr=arr1->getPointer();
3120   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
3121   for(int i=0;i<nbOfTypes;i++,it++)
3122     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
3123   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
3124   const int *arrPtr2=arr2->getConstPointer();
3125   int i=0;
3126   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
3127     {
3128       int pos=arrPtr2[i];
3129       int nbCells=mesh->getNumberOfCellsWithType(*it);
3130       code[3*pos]=(int)(*it);
3131       code[3*pos+1]=nbCells;
3132       code[3*pos+2]=-1;//no profiles
3133     }
3134   std::vector<const DataArrayInt *> idsPerType;//no profiles
3135   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
3136   if(da)
3137     {
3138       da->decrRef();
3139       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
3140     }
3141   return code;
3142 }
3143
3144 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const char *fieldName, int csit, int fieldtype, int iteration, int order, const std::vector<std::string>& infos)
3145 {
3146   return new MEDFileField1TSWithoutSDA(fieldName,csit,fieldtype,iteration,order,infos);
3147 }
3148
3149 /*!
3150  * This method copyies tiny info but also preallocated the DataArrayDouble instance in this->_arr.
3151  * This not allocated it allocates to the size of 'field' array. If already allocated it grows the array to
3152  * the previous size + the size of the array of the input 'field'.
3153  * This method returns the position (in tuple id) where to start to feed 'this->_arr'
3154  */
3155 int MEDFileField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
3156 {
3157   std::string name(field->getName());
3158   getOrCreateAndGetArray()->setName(name.c_str());
3159   if(name.empty())
3160     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
3161   const DataArrayDouble *arr=field->getArray();
3162   if(!arr)
3163     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
3164   _dt=field->getTime(_iteration,_order);
3165   int nbOfComponents=arr->getNumberOfComponents();
3166   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
3167   if(!getOrCreateAndGetArray()->isAllocated())
3168     {
3169       _arr->alloc(arr->getNumberOfTuples(),arr->getNumberOfComponents());
3170       return 0;
3171     }
3172   else
3173     {
3174       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
3175       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
3176       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp=DataArrayDouble::New();
3177       tmp->alloc(newNbOfTuples,nbOfComponents);
3178       tmp->copyStringInfoFrom(*_arr);
3179       std::copy(_arr->begin(),_arr->end(),tmp->getPointer());
3180       _arr=tmp;
3181       return oldNbOfTuples;
3182     }
3183 }
3184
3185 std::string MEDFileField1TSWithoutSDA::getName() const
3186 {
3187   const DataArrayDouble *arr=getOrCreateAndGetArray();
3188   return arr->getName();
3189 }
3190
3191 void MEDFileField1TSWithoutSDA::setName(const char *name)
3192 {
3193   DataArrayDouble *arr=getOrCreateAndGetArray();
3194   arr->setName(name);
3195 }
3196
3197 void MEDFileField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3198 {
3199   std::string startOfLine(bkOffset,' ');
3200   oss << startOfLine << "Field on One time Step ";
3201   if(f1tsId>=0)
3202     oss << "(" << f1tsId << ") ";
3203   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3204   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3205   const DataArrayDouble *arr=_arr;
3206   if(arr)
3207     {
3208       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3209       if(f1tsId<0)
3210         {
3211           oss << startOfLine << "Field Name : \"" << arr->getName() << "\"." << std::endl;
3212           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3213           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3214             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3215         }
3216       if(arr->isAllocated())
3217         {
3218           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3219         }
3220       else
3221         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3222     }
3223   else
3224     {
3225       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3226     }
3227   oss << startOfLine << "----------------------" << std::endl;
3228   if(!_field_per_mesh.empty())
3229     {
3230       int i=0;
3231       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3232         {
3233           const MEDFileFieldPerMesh *cur=(*it2);
3234           if(cur)
3235             cur->simpleRepr(bkOffset,oss,i);
3236           else
3237             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3238         }
3239     }
3240   else
3241     {
3242       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3243     }
3244   oss << startOfLine << "----------------------" << std::endl;
3245 }
3246
3247 std::string MEDFileField1TSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
3248 {
3249   if(_field_per_mesh.empty())
3250     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3251   return _field_per_mesh[0]->getMeshName();
3252 }
3253
3254 void MEDFileField1TSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
3255 {
3256   std::string oldName(getMeshName());
3257   std::vector< std::pair<std::string,std::string> > v(1);
3258   v[0].first=oldName; v[0].second=newMeshName;
3259   changeMeshNames(v);
3260 }
3261
3262 bool MEDFileField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
3263 {
3264   bool ret=false;
3265   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3266     {
3267       MEDFileFieldPerMesh *cur(*it);
3268       if(cur)
3269         ret=cur->changeMeshNames(modifTab) || ret;
3270     }
3271   return ret;
3272 }
3273
3274 bool MEDFileField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
3275                                                             MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
3276 {
3277   bool ret=false;
3278   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3279     {
3280       MEDFileFieldPerMesh *fpm(*it);
3281       if(fpm)
3282         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
3283     }
3284   return ret;
3285 }
3286
3287 int MEDFileField1TSWithoutSDA::getMeshIteration() const throw(INTERP_KERNEL::Exception)
3288 {
3289   if(_field_per_mesh.empty())
3290     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3291   return _field_per_mesh[0]->getMeshIteration();
3292 }
3293
3294 int MEDFileField1TSWithoutSDA::getMeshOrder() const throw(INTERP_KERNEL::Exception)
3295 {
3296   if(_field_per_mesh.empty())
3297     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3298   return _field_per_mesh[0]->getMeshOrder();
3299 }
3300
3301 int MEDFileField1TSWithoutSDA::getNumberOfComponents() const
3302 {
3303   return getOrCreateAndGetArray()->getNumberOfComponents();
3304 }
3305
3306 bool MEDFileField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3307 {
3308   return iteration==_iteration && order==_order;
3309 }
3310
3311 std::pair<int,int> MEDFileField1TSWithoutSDA::getDtIt() const
3312 {
3313   std::pair<int,int> p;
3314   fillIteration(p);
3315   return p;
3316 }
3317
3318 void MEDFileField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3319 {
3320   p.first=_iteration;
3321   p.second=_order;
3322 }
3323
3324 void MEDFileField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
3325 {
3326   std::set<TypeOfField> types2;
3327   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3328     {
3329       (*it)->fillTypesOfFieldAvailable(types2);
3330     }
3331   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3332   std::copy(types2.begin(),types2.end(),bi);
3333 }
3334
3335 const std::vector<std::string>& MEDFileField1TSWithoutSDA::getInfo() const
3336 {
3337   const DataArrayDouble *arr=getOrCreateAndGetArray();
3338   return arr->getInfoOnComponents();
3339 }
3340
3341 std::vector<std::string>& MEDFileField1TSWithoutSDA::getInfo()
3342 {
3343   DataArrayDouble *arr=getOrCreateAndGetArray();
3344   return arr->getInfoOnComponents();
3345 }
3346
3347 /*!
3348  * This method has one input 'mname'. It can be null if the user is the general case where there is only one meshName lying on 'this'
3349  * This method returns two things.
3350  * - The absolute dimension of 'this' in first parameter. 
3351  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
3352  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
3353  *
3354  * This method is designed for MEDFileField1TS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
3355  * Only these 3 discretizations will be taken into account here.
3356  *
3357  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
3358  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
3359  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
3360  *
3361  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
3362  * 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'.
3363  * 
3364  * Let's consider the typical following case :
3365  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
3366  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
3367  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
3368  *   TETRA4 and SEG2
3369  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
3370  *
3371  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
3372  * 
3373  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
3374  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
3375  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
3376  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
3377  */
3378 int MEDFileField1TSWithoutSDA::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
3379 {
3380   levs.clear();
3381   int meshId=getMeshIdFromMeshName(mname);
3382   std::vector<INTERP_KERNEL::NormalizedCellType> types;
3383   std::vector< std::vector<TypeOfField> > typesF;
3384   std::vector< std::vector<std::string> > pfls, locs;
3385   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3386   if(types.empty())
3387     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
3388   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
3389   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
3390     return -1;
3391   st.erase(INTERP_KERNEL::NORM_ERROR);
3392   std::set<int> ret1;
3393   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
3394     {
3395       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
3396       ret1.insert((int)cm.getDimension());
3397     }
3398   int ret=*std::max_element(ret1.begin(),ret1.end());
3399   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
3400   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
3401   return ret;
3402 }
3403
3404 std::vector<TypeOfField> MEDFileField1TSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
3405 {
3406   std::vector<TypeOfField> ret;
3407   fillTypesOfFieldAvailable(ret);
3408   return ret;
3409 }
3410
3411 /*!
3412  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
3413  */
3414 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)
3415 {
3416   int meshId=0;
3417   if(mname)
3418     meshId=getMeshIdFromMeshName(mname);
3419   else
3420     if(_field_per_mesh.empty())
3421       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3422   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3423 }
3424
3425 /*!
3426  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
3427  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
3428  */
3429 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)
3430 {
3431   int meshId=0;
3432   if(mname)
3433     meshId=getMeshIdFromMeshName(mname);
3434   else
3435     if(_field_per_mesh.empty())
3436       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3437   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3438   int nbOfRet=ret0.size();
3439   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
3440   for(int i=0;i<nbOfRet;i++)
3441     {
3442       const std::vector< std::pair<int,int> >& p=ret0[i];
3443       int nbOfRet1=p.size();
3444       ret[i].resize(nbOfRet1);
3445       for(int j=0;j<nbOfRet1;j++)
3446         {
3447           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
3448           ret[i][j]=tmp;
3449         }
3450     }
3451   return ret;
3452 }
3453
3454 void MEDFileField1TSWithoutSDA::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception)
3455 {
3456   med_int numdt,numit;
3457   med_float dt;
3458   med_int nmesh;
3459   med_bool localMesh;
3460   med_int meshnumdt,meshnumit;
3461   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3462   MEDfieldComputingStepInfo(fid,getName().c_str(),_csit,&numdt,&numit,&_dt);
3463   MEDfield23ComputingStepMeshInfo(fid,getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
3464   if(_iteration!=numdt || _order!=numit)
3465     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::finishLoading : unexpected exception internal error !");
3466   _field_per_mesh.resize(nmesh);
3467   for(int i=0;i<nmesh;i++)
3468     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i+1,meshnumdt,meshnumit);
3469   int start=0;
3470   for(int i=0;i<nmesh;i++)
3471     {
3472       _field_per_mesh[i]->prepareLoading(fid,start);
3473     }
3474   getOrCreateAndGetArray()->alloc(start,getNumberOfComponents());
3475   for(int i=0;i<nmesh;i++)
3476     {
3477       _field_per_mesh[i]->finishLoading(fid,_field_type);
3478     }
3479 }
3480
3481 std::vector<std::string> MEDFileField1TSWithoutSDA::getPflsReallyUsed2() const
3482 {
3483   std::vector<std::string> ret;
3484   std::set<std::string> ret2;
3485   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3486     {
3487       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3488       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3489         if(ret2.find(*it2)==ret2.end())
3490           {
3491             ret.push_back(*it2);
3492             ret2.insert(*it2);
3493           }
3494     }
3495   return ret;
3496 }
3497
3498 std::vector<std::string> MEDFileField1TSWithoutSDA::getLocsReallyUsed2() const
3499 {
3500   std::vector<std::string> ret;
3501   std::set<std::string> ret2;
3502   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3503     {
3504       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3505       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3506         if(ret2.find(*it2)==ret2.end())
3507           {
3508             ret.push_back(*it2);
3509             ret2.insert(*it2);
3510           }
3511     }
3512   return ret;
3513 }
3514
3515 std::vector<std::string> MEDFileField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3516 {
3517   std::vector<std::string> ret;
3518   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3519     {
3520       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3521       ret.insert(ret.end(),tmp.begin(),tmp.end());
3522     }
3523   return ret;
3524 }
3525
3526 std::vector<std::string> MEDFileField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3527 {
3528   std::vector<std::string> ret;
3529   std::set<std::string> ret2;
3530   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3531     {
3532       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3533       ret.insert(ret.end(),tmp.begin(),tmp.end());
3534     }
3535   return ret;
3536 }
3537
3538 void MEDFileField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3539 {
3540   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3541     (*it)->changePflsRefsNamesGen(mapOfModif);
3542 }
3543
3544 void MEDFileField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3545 {
3546   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3547     (*it)->changeLocsRefsNamesGen(mapOfModif);
3548 }
3549
3550 void MEDFileField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception)
3551 {
3552   if(_field_per_mesh.empty())
3553     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
3554   if(_field_per_mesh.size()>1)
3555     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
3556   _field_per_mesh[0]->copyOptionsFrom(opts);
3557   _field_per_mesh[0]->writeLL(fid);
3558 }
3559
3560 /*!
3561  * SBT means Sort By Type.
3562  * This method is the most basic method to assign field in this. Basic in sense that no renumbering is done. Underlying mesh in 'field' is globaly ignored except for type contiguous check.
3563  */
3564 void MEDFileField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
3565 {
3566   const MEDCouplingMesh *mesh=field->getMesh();
3567   //
3568   TypeOfField type=field->getTypeOfField();
3569   std::vector<DataArrayInt *> dummy;
3570   int start=copyTinyInfoFrom(field);
3571   int pos=addNewEntryIfNecessary(mesh);
3572   if(type!=ON_NODES)
3573     {
3574       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
3575       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,glob);
3576     }
3577   else
3578     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,glob);
3579 }
3580
3581 /*!
3582  * Generalization of MEDFileField1TSWithoutSDA::setFieldNoProfileSBT method.
3583  */
3584 void MEDFileField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
3585 {
3586   TypeOfField type=field->getTypeOfField();
3587   int start=copyTinyInfoFrom(field);
3588   std::vector<DataArrayInt *> idsInPflPerType;
3589   std::vector<DataArrayInt *> idsPerType;
3590   std::vector<int> code,code2;
3591   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
3592   if(type!=ON_NODES)
3593     {
3594       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
3595       code2=m->getDistributionOfTypes();
3596       //
3597       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size());
3598       for(std::size_t i=0;i<idsInPflPerType.size();i++)
3599         idsInPflPerType2[i]=idsInPflPerType[i];
3600       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size());
3601       for(std::size_t i=0;i<idsPerType.size();i++)
3602         idsPerType2[i]=idsPerType[i];
3603       //
3604       int pos=addNewEntryIfNecessary(m);
3605       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,m,glob);
3606     }
3607   else
3608     {
3609       int pos=addNewEntryIfNecessary(m);
3610       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,glob);
3611     }
3612 }
3613
3614 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
3615 {
3616   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
3617   if(mName==0)
3618     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
3619   else
3620     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
3621   return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm);
3622 }
3623
3624 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception)
3625 {
3626   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
3627   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
3628   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
3629   if(meshDimRelToMax==1)
3630     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
3631   return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e);
3632 }
3633
3634 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
3635 {
3636    MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
3637   if(mName==0)
3638     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
3639   else
3640     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
3641   int absDim=getDimension();
3642   int meshDimRelToMax=absDim-mm->getMeshDimension();
3643   return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm);
3644 }
3645
3646 /*!
3647  * \param [in] mesh is the whole mesh.
3648  */
3649 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum) const throw(INTERP_KERNEL::Exception)
3650 {
3651   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
3652   int meshId=getMeshIdFromMeshName(mesh->getName());
3653   bool isPfl=false;
3654   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl);
3655   switch(renumPol)
3656     {
3657     case 0:
3658       {
3659         //no need to test _field_per_mesh.empty() because geMeshName has already done it
3660         return ret.retn();
3661       }
3662     case 3:
3663     case 1:
3664       {
3665         if(isPfl)
3666           throw INTERP_KERNEL::Exception(msg1);
3667         //no need to test _field_per_mesh.empty() because geMeshName has already done it
3668         if(cellRenum)
3669           {
3670             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
3671               {
3672                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
3673                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
3674                 throw INTERP_KERNEL::Exception(oss.str().c_str());
3675               }
3676             ret->renumberCells(cellRenum->getConstPointer(),true);
3677           }
3678         if(renumPol==1)
3679           return ret.retn();
3680       }
3681     case 2:
3682       {
3683         //no need to test _field_per_mesh.empty() because geMeshName has already done it
3684         if(isPfl)
3685           throw INTERP_KERNEL::Exception(msg1);
3686         if(nodeRenum)
3687           {
3688             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
3689               {
3690                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
3691                 oss << "\"" << getName() << "\" not defined on all nodes !";
3692                 throw INTERP_KERNEL::Exception(oss.str().c_str());
3693               }
3694             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
3695             ret->renumberNodes(nodeRenumSafe->getConstPointer());
3696           }
3697         return ret.retn();
3698       }
3699     default:
3700       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
3701     }
3702 }
3703
3704 DataArrayDouble *MEDFileField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
3705 {
3706   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
3707   int meshId=getMeshIdFromMeshName(mesh->getName());
3708   return _field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob);
3709 }
3710
3711 /*!
3712  * This method retrieves direct access to the underground ParaMEDMEM::DataArrayDouble instance. The returned array is not a newly
3713  * created array so it should \b not be dealed by the caller.
3714  * This method allows to the user a direct access to the values.
3715  * This method is quite unusable if there is more than a nodal field or a cell field on single geometric cell type.
3716  */
3717 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
3718 {
3719   const DataArrayDouble *ret=_arr;
3720   if(ret)
3721     return const_cast<DataArrayDouble *>(ret);
3722   else
3723     return 0;
3724 }
3725
3726 /*!
3727  * This method returns an array that the caller must deal with (contrary to those returned by MEDFileField1TSWithoutSDA::getUndergroundDataArray method).
3728  * The returned array is the result of the aggregation of all sub arrays stored in the MED file. So to allow the caller to select the output param
3729  * 'entries' is returned. This output param is a vector of a pair of 2 pairs. The first pair of pair informs of the geometric type it refers to and the discretization
3730  * id attached to it. The second pair of pair precise the range [begin,end) into the returned array.
3731  * This method makes the hypothesis that the field lies only on one mesh. If it is not the case an exception will be thrown.
3732  */
3733 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
3734 {
3735   if(_field_per_mesh.size()!=1)
3736     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
3737   if(_field_per_mesh[0]==0)
3738     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
3739   return _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
3740 }
3741
3742 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const char *fieldName, int csit, int fieldtype, int iteration, int order,
3743                                                      const std::vector<std::string>& infos):_iteration(iteration),_order(order),_csit(csit),_field_type(fieldtype)
3744 {
3745   DataArrayDouble *arr=getOrCreateAndGetArray();
3746   arr->setName(fieldName);
3747   arr->setInfoAndChangeNbOfCompo(infos);
3748 }
3749
3750 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():_csit(-1),_field_type(-1)
3751 {
3752 }
3753
3754 int MEDFileField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
3755 {
3756   std::string tmp(mesh->getName());
3757   if(tmp.empty())
3758     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
3759   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
3760   int i=0;
3761   for(;it!=_field_per_mesh.end();it++,i++)
3762     {
3763       if((*it)->getMeshName()==tmp)
3764         return i;
3765     }
3766   int sz=_field_per_mesh.size();
3767   _field_per_mesh.resize(sz+1);
3768   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
3769   return sz;
3770 }
3771
3772 /*!
3773  * \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.
3774  */
3775 int MEDFileField1TSWithoutSDA::getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception)
3776 {
3777   if(_field_per_mesh.empty())
3778     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
3779   if(mName==0)
3780     return 0;
3781   std::string mName2(mName);
3782   int ret=0;
3783   std::vector<std::string> msg;
3784   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
3785     if(mName2==(*it)->getMeshName())
3786       return ret;
3787     else
3788       msg.push_back((*it)->getMeshName());
3789   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
3790   oss << "Possible meshes are : ";
3791   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
3792     oss << "\"" << (*it2) << "\" ";
3793   throw INTERP_KERNEL::Exception(oss.str().c_str());
3794 }
3795
3796 /*!
3797  * \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.
3798  * \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.
3799  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3800  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3801  */
3802 MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
3803 {
3804   int mid=getMeshIdFromMeshName(mName);
3805   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3806 }
3807
3808 /*!
3809  * \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.
3810  * \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.
3811  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3812  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3813  */
3814 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
3815 {
3816   int mid=getMeshIdFromMeshName(mName);
3817   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3818 }
3819
3820 std::size_t MEDFileField1TSWithoutSDA::getHeapMemorySize() const
3821 {
3822   std::size_t ret=_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
3823   if((const DataArrayDouble *)_arr)
3824     ret+=_arr->getHeapMemorySize();
3825   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3826     ret+=(*it)->getHeapMemorySize();
3827   return ret;
3828 }
3829
3830 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
3831 {
3832   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=new MEDFileField1TSWithoutSDA(*this);
3833   if((const DataArrayDouble *)_arr)
3834     ret->_arr=_arr->deepCpy();
3835   std::size_t i=0;
3836   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,i++)
3837     {
3838       if((const MEDFileFieldPerMesh *)*it)
3839         ret->_field_per_mesh[i]=(*it)->deepCpy((MEDFileField1TSWithoutSDA *)ret);
3840     }
3841   return ret.retn();
3842 }
3843
3844 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
3845 {
3846   DataArrayDouble *ret=_arr;
3847   if(ret)
3848     return ret;
3849   _arr=DataArrayDouble::New();
3850   return _arr;
3851 }
3852
3853 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
3854 {
3855   const DataArrayDouble *ret=_arr;
3856   if(ret)
3857     return ret;
3858   DataArrayDouble *ret2=DataArrayDouble::New();
3859   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
3860   return ret2;
3861 }
3862
3863 /*!
3864  * This methods returns a new instance (to be dealt by the caller).
3865  * This method returns for the first field in the file \a fileName the first time step of this first field, if
3866  * such field exists and time step exists. If not, an INTERP_KERNEL::Exception will be thrown.
3867  */
3868 MEDFileField1TS *MEDFileField1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
3869 {
3870   return new MEDFileField1TS(fileName);
3871 }
3872
3873 /*!
3874  * This methods returns a new instance (to be dealt by the caller).
3875  * This method returns the first time step of the field \a fieldName in file \a fieldName, if
3876  * such field exists. If not, an INTERP_KERNEL::Exception will be thrown.
3877  */
3878 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
3879 {
3880   return new MEDFileField1TS(fileName,fieldName);
3881 }
3882
3883 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
3884 {
3885   return new MEDFileField1TS(fileName,fieldName,iteration,order);
3886 }
3887
3888 /*!
3889  * \warning this is a shallow copy constructor
3890  */
3891 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
3892 {
3893   return new MEDFileField1TS(other,shallowCopyOfContent);
3894 }
3895
3896 MEDFileField1TS *MEDFileField1TS::New()
3897 {
3898   return new MEDFileField1TS;
3899 }
3900
3901 std::string MEDFileField1TS::simpleRepr() const
3902 {
3903   std::ostringstream oss;
3904   _content->simpleRepr(0,oss,-1);
3905   MEDFileFieldGlobsReal::simpleRepr(oss);
3906   return oss.str();
3907 }
3908
3909 void MEDFileField1TS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
3910 {
3911   int nbComp=getNumberOfComponents();
3912   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
3913   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
3914   for(int i=0;i<nbComp;i++)
3915     {
3916       std::string info=getInfo()[i];
3917       std::string c,u;
3918       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
3919       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
3920       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
3921     }
3922   if(getName().empty())
3923     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
3924   MEDfieldCr(fid,getName().c_str(),MED_FLOAT64,nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
3925   writeGlobals(fid,*this);
3926   _content->writeLL(fid,*this);
3927 }
3928
3929 void MEDFileField1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
3930 {
3931   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
3932   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
3933   writeLL(fid);
3934 }
3935
3936 MEDFileField1TS::MEDFileField1TS(const char *fileName) throw(INTERP_KERNEL::Exception)
3937 try:MEDFileFieldGlobsReal(fileName)
3938 {
3939   MEDFileUtilities::CheckFileForRead(fileName);
3940   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
3941   med_field_type typcha;
3942   //
3943   int nbFields=MEDnField(fid);
3944   if(nbFields<1)
3945     {
3946       std::ostringstream oss; oss << "MEDFileField1TS(fileName) : no field present in file \'" << fileName << "\' !";
3947       throw INTERP_KERNEL::Exception(oss.str().c_str());
3948     }
3949   int ncomp=MEDfieldnComponent(fid,1);
3950   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
3951   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
3952   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
3953   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3954   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3955   med_bool localMesh;
3956   int nbOfStep;
3957   MEDfieldInfo(fid,1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
3958   std::string fieldName(nomcha);
3959   if(nbOfStep<1)
3960     {
3961       std::ostringstream oss; oss << "MEDFileField1TS(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
3962       throw INTERP_KERNEL::Exception(oss.str().c_str());
3963     }
3964   std::vector<std::string> infos(ncomp);
3965   for(int j=0;j<ncomp;j++)
3966     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
3967   _content=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
3968   _content->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
3969   //
3970   med_int numdt,numit;
3971   med_float dt;
3972   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
3973   _content->setTime(numdt,numit,dt);
3974   _content->_csit=1;
3975   _content->_field_type=MEDFileUtilities::TraduceFieldType(typcha);
3976   _content->finishLoading(fid);
3977   //
3978   loadGlobals(fid);
3979 }
3980 catch(INTERP_KERNEL::Exception& e)
3981   {
3982     throw e;
3983   }
3984
3985 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
3986 try:MEDFileFieldGlobsReal(fileName),_content(MEDFileField1TSWithoutSDA::New(fieldName,-1,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>()))
3987 {
3988   MEDFileUtilities::CheckFileForRead(fileName);
3989   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
3990   med_field_type typcha;
3991   int nbSteps=locateField(fid,fileName,fieldName,typcha);
3992   if(nbSteps<1)
3993     {
3994       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
3995       throw INTERP_KERNEL::Exception(oss.str().c_str());
3996     }
3997   //
3998   med_int numdt,numit;
3999   med_float dt;
4000   MEDfieldComputingStepInfo(fid,fieldName,1,&numdt,&numit,&dt);
4001   _content->setTime(numdt,numit,dt);
4002   _content->_csit=1;
4003   _content->_field_type=MEDFileUtilities::TraduceFieldType(typcha);
4004   _content->finishLoading(fid);
4005   //
4006   loadGlobals(fid);
4007 }
4008 catch(INTERP_KERNEL::Exception& e)
4009   {
4010     throw e;
4011   }
4012
4013 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
4014 try:MEDFileFieldGlobsReal(fileName),_content(MEDFileField1TSWithoutSDA::New(fieldName,-1,-1,iteration,order,std::vector<std::string>()))
4015 {
4016   MEDFileUtilities::CheckFileForRead(fileName);
4017   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
4018   med_field_type typcha;
4019   int nbOfStep2=locateField(fid,fileName,fieldName,typcha);
4020   bool found=false;
4021   std::vector< std::pair<int,int> > dtits(nbOfStep2);
4022   for(int i=0;i<nbOfStep2 && !found;i++)
4023     {
4024       med_int numdt,numit;
4025       med_float dt;
4026       MEDfieldComputingStepInfo(fid,fieldName,i+1,&numdt,&numit,&dt);
4027       if(numdt==iteration && numit==order)
4028         {
4029           found=true;
4030           _content->_csit=i+1;
4031           _content->_field_type=MEDFileUtilities::TraduceFieldType(typcha);
4032         }
4033       else
4034         dtits[i]=std::pair<int,int>(numdt,numit);
4035     }
4036   if(!found)
4037     {
4038       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
4039       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
4040         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
4041       throw INTERP_KERNEL::Exception(oss.str().c_str());
4042     }
4043   _content->finishLoading(fid);
4044   //
4045   loadGlobals(fid);
4046 }
4047 catch(INTERP_KERNEL::Exception& e)
4048   {
4049     throw e;
4050   }
4051
4052 /*!
4053  * \warning this is a shallow copy constructor
4054  */
4055 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
4056 {
4057   if(!shallowCopyOfContent)
4058     {
4059       const MEDFileField1TSWithoutSDA *otherPtr(&other);
4060       otherPtr->incrRef();
4061       _content=const_cast<MEDFileField1TSWithoutSDA *>(otherPtr);
4062     }
4063   else
4064     {
4065       _content=new MEDFileField1TSWithoutSDA(other);
4066     }
4067 }
4068
4069 MEDFileField1TS::MEDFileField1TS():_content(new MEDFileField1TSWithoutSDA)
4070 {
4071 }
4072
4073 /*!
4074  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
4075  * 
4076  * \param [out]
4077  * \return in case of success the number of time steps available for the field with name \a fieldName.
4078  */
4079 int MEDFileField1TS::locateField(med_idt fid, const char *fileName, const char *fieldName, med_field_type& typcha) throw(INTERP_KERNEL::Exception)
4080 {
4081   int nbFields=MEDnField(fid);
4082   bool found=false;
4083   std::vector<std::string> fns(nbFields);
4084   int nbOfStep2=-1;
4085   for(int i=0;i<nbFields && !found;i++)
4086     {
4087       int ncomp=MEDfieldnComponent(fid,i+1);
4088       INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4089       INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4090       INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
4091       INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4092       INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4093       med_bool localMesh;
4094       int nbOfStep;
4095       MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
4096       std::string tmp(nomcha);
4097       fns[i]=tmp;
4098       found=(tmp==fieldName);
4099       if(found)
4100         {
4101           nbOfStep2=nbOfStep;
4102           std::string mname=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
4103           std::vector<std::string> infos(ncomp);
4104           for(int j=0;j<ncomp;j++)
4105             infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
4106           _content->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
4107         }
4108     }
4109   if(!found)
4110     {
4111       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
4112       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
4113         oss << "\"" << *it << "\" ";
4114       throw INTERP_KERNEL::Exception(oss.str().c_str());
4115     }
4116   return nbOfStep2;
4117 }
4118
4119 /*!
4120  * This method returns all profiles whose name is non empty used.
4121  * \b WARNING If profile is used several times it will be reported \b only \b once.
4122  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
4123  */
4124 std::vector<std::string> MEDFileField1TS::getPflsReallyUsed() const
4125 {
4126   return _content->getPflsReallyUsed2();
4127 }
4128
4129 /*!
4130  * This method returns all localizations whose name is non empty used.
4131  * \b WARNING If localization is used several times it will be reported \b only \b once.
4132  */
4133 std::vector<std::string> MEDFileField1TS::getLocsReallyUsed() const
4134 {
4135   return _content->getLocsReallyUsed2();
4136 }
4137
4138 /*!
4139  * This method returns all profiles whose name is non empty used.
4140  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
4141  */
4142 std::vector<std::string> MEDFileField1TS::getPflsReallyUsedMulti() const
4143 {
4144   return _content->getPflsReallyUsedMulti2();
4145 }
4146
4147 /*!
4148  * This method returns all localizations whose name is non empty used.
4149  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
4150  */
4151 std::vector<std::string> MEDFileField1TS::getLocsReallyUsedMulti() const
4152 {
4153   return _content->getLocsReallyUsedMulti2();
4154 }
4155
4156 void MEDFileField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
4157 {
4158   _content->changePflsRefsNamesGen2(mapOfModif);
4159 }
4160
4161 void MEDFileField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
4162 {
4163   _content->changeLocsRefsNamesGen2(mapOfModif);
4164 }
4165
4166 /*!
4167  * This method requests underlying file to perform the job, for mesh reading. If the current instance is not coming from a file and has been constructed from scratch
4168  * an exception will be thrown. In this case you should use MEDFileField1TS::getFieldOnMeshAtLevel method instead.
4169  * \b WARNING ! Parameter 'meshDimRelToMax' is relative from read mesh in file that can be different from the field in MED file !
4170  * It leads that the returned field of this method is always coherent.
4171  */
4172 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
4173 {
4174   if(getFileName2().empty())
4175     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
4176   return _content->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this);
4177 }
4178
4179 /*!
4180  * This method is close to MEDFileField1TS::getFieldAtLevel except that here the 'meshDimRelToMax' param is ignored and the maximal dimension is taken
4181  * automatically. If the field lies on different level and that an another level than the maximal is requested MEDFileField1TS::getFieldAtLevel
4182  * should be called instead.
4183  */
4184 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const throw(INTERP_KERNEL::Exception)
4185 {
4186   if(getFileName2().empty())
4187     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
4188   return _content->getFieldAtTopLevel(type,0,renumPol,this);
4189 }
4190
4191 /*!
4192  * \b WARNING, there is a main difference with the two close methods (MEDFileField1TS::getFieldAtLevel and MEDFileField1TS::getFieldOnMeshAtLevel method) !
4193  * Here the mesh-dimension of 'mesh' is used by this to automatically request the right geoTypes regarding 'type'.
4194  * If no such element fufilled the deduced dimension and 'type' an exception will be thrown.
4195  * It leads that the returned field of this method is always coherent.
4196  */
4197 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
4198 {
4199   return _content->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0);
4200 }
4201
4202 /*!
4203  * This method can be called whatever the mode of instance feeding of this (MED file or from scratch).
4204  * But the parameter ''meshDimRelToMax' is applyied on 'mesh' (like MEDFileField1TS::getFieldAtLevel does). \b WARNING the dim of 'this' can be different from those in 'mesh' !
4205  * It leads that the returned field of this method is always coherent.
4206  */
4207 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
4208 {
4209   return _content->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh);
4210 }
4211
4212 /*!
4213  * This method is identical to MEDFileField1TS::getFieldAtLevel method except that meshName 'mname' should be specified.
4214  * This method is called "Old" because in MED3 norm a field has only one meshName attached. This method is only here for reader of MED2 files.
4215  * See MEDFileField1TS::getFieldAtLevel for more information.
4216  */
4217 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
4218 {
4219   if(getFileName2().empty())
4220     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
4221   return _content->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this);
4222 }
4223
4224 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
4225 {
4226   return _content->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this);
4227 }
4228
4229 /*!
4230  * SBT means Sort By Type.
4231  * This method is the most basic method to assign field in this. Basic in sense that no renumbering is done. Underlying mesh in 'field' is globaly ignored except for type contiguous check.
4232  * 
4233  */
4234 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
4235 {
4236   setFileName("");
4237   _content->setFieldNoProfileSBT(field,*this);
4238 }
4239
4240 /*!
4241  * This method is a generalization of MEDFileField1TS::setFieldNoProfileSBT method. Here a profile array is given in input.
4242  * The support of field 'field' is \b not used by this method, so it can be null or incoherent with field.
4243  * This method uses input parameters 'mesh', 'meshDimRelToMax' and 'profile' to determine what is really the support of field 'field'. If field is incoherent regarding this deduced support,
4244  * an exception will be thrown.
4245  * This method is trying to reduce the size of MEDfile file so profile is created only if it is absolutely necessary. If it is necessary the name of 'profile' will be used to create it in 'this'.
4246  * In this case, if this profile name is empty an exception will be thrown.
4247  */
4248 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
4249 {
4250   setFileName("");
4251   _content->setFieldProfile(field,mesh,meshDimRelToMax,profile,*this);
4252 }
4253
4254 /*!
4255  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
4256  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
4257  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
4258  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
4259  * to keep a valid instance.
4260  * 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.
4261  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
4262  * 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.
4263  *
4264  * \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.
4265  * \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.
4266  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4267  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4268  * \param [in] newLocName is the new localization name.
4269  * \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.
4270  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
4271  */
4272 void MEDFileField1TS::setProfileNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newPflName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
4273 {
4274   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
4275   std::string oldPflName=disc->getProfile();
4276   std::vector<std::string> vv=getPflsReallyUsedMulti();
4277   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
4278   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
4279     {
4280       disc->setProfile(newPflName);
4281       DataArrayInt *pfl=getProfile(oldPflName.c_str());
4282       pfl->setName(newPflName);
4283     }
4284   else
4285     {
4286       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
4287       throw INTERP_KERNEL::Exception(oss.str().c_str());
4288     }
4289 }
4290
4291 /*!
4292  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
4293  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
4294  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
4295  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
4296  * to keep a valid instance.
4297  * 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.
4298  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
4299  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
4300  * 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.
4301  *
4302  * \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.
4303  * \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.
4304  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4305  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4306  * \param [in] newLocName is the new localization name.
4307  * \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.
4308  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
4309  */
4310 void MEDFileField1TS::setLocNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newLocName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
4311 {
4312   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
4313   std::string oldLocName=disc->getLocalization();
4314   std::vector<std::string> vv=getLocsReallyUsedMulti();
4315   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
4316   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
4317     {
4318       disc->setLocalization(newLocName);
4319       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
4320       loc.setName(newLocName);
4321     }
4322   else
4323     {
4324       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
4325       throw INTERP_KERNEL::Exception(oss.str().c_str());
4326     }
4327 }
4328
4329 std::size_t MEDFileField1TS::getHeapMemorySize() const
4330 {
4331   std::size_t ret=0;
4332   if((const MEDFileField1TSWithoutSDA *)_content)
4333     ret+=_content->getHeapMemorySize();
4334   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
4335 }
4336
4337 MEDFileField1TS *MEDFileField1TS::deepCpy() const throw(INTERP_KERNEL::Exception)
4338 {
4339   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(*this);
4340   if((const MEDFileField1TSWithoutSDA *)_content)
4341     ret->_content=_content->deepCpy();
4342   ret->deepCpyGlobs(*this);
4343   return ret.retn();
4344 }
4345
4346 int MEDFileField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
4347 {
4348   return _content->copyTinyInfoFrom(field);
4349 }
4350
4351 int MEDFileField1TS::getDimension() const
4352 {
4353   return _content->getDimension();
4354 }
4355
4356 int MEDFileField1TS::getIteration() const
4357 {
4358   return _content->getIteration();
4359 }
4360
4361 int MEDFileField1TS::getOrder() const
4362 {
4363   return _content->getOrder();
4364 }
4365
4366 double MEDFileField1TS::getTime(int& iteration, int& order) const
4367 {
4368   return _content->getTime(iteration,order);
4369 }
4370
4371 void MEDFileField1TS::setTime(int iteration, int order, double val)
4372 {
4373   _content->setTime(iteration,order,val);
4374 }
4375
4376 std::string MEDFileField1TS::getName() const
4377 {
4378   return _content->getName();
4379 }
4380
4381 void MEDFileField1TS::setName(const char *name)
4382 {
4383   _content->setName(name);
4384 }
4385
4386 void MEDFileField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4387 {
4388   _content->simpleRepr(bkOffset,oss,f1tsId);
4389 }
4390
4391 const std::string& MEDFileField1TS::getDtUnit() const
4392 {
4393   return _content->getDtUnit();
4394 }
4395
4396 std::string MEDFileField1TS::getMeshName() const throw(INTERP_KERNEL::Exception)
4397 {
4398   return _content->getMeshName();
4399 }
4400
4401 void MEDFileField1TS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
4402 {
4403   _content->setMeshName(newMeshName);
4404 }
4405
4406 bool MEDFileField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
4407 {
4408   return _content->changeMeshNames(modifTab);
4409 }
4410
4411 int MEDFileField1TS::getMeshIteration() const throw(INTERP_KERNEL::Exception)
4412 {
4413   return _content->getMeshIteration();
4414 }
4415
4416 int MEDFileField1TS::getMeshOrder() const throw(INTERP_KERNEL::Exception)
4417 {
4418   return _content->getMeshOrder();
4419 }
4420
4421 int MEDFileField1TS::getNumberOfComponents() const
4422 {
4423   return _content->getNumberOfComponents();
4424 }
4425
4426 bool MEDFileField1TS::isDealingTS(int iteration, int order) const
4427 {
4428   return _content->isDealingTS(iteration,order);
4429 }
4430
4431 std::pair<int,int> MEDFileField1TS::getDtIt() const
4432 {
4433   return _content->getDtIt();
4434 }
4435
4436 void MEDFileField1TS::fillIteration(std::pair<int,int>& p) const
4437 {
4438   _content->fillIteration(p);
4439 }
4440 void MEDFileField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
4441 {
4442   _content->fillTypesOfFieldAvailable(types);
4443 }
4444
4445 const std::vector<std::string>& MEDFileField1TS::getInfo() const
4446 {
4447   return _content->getInfo();
4448 }
4449 std::vector<std::string>& MEDFileField1TS::getInfo()
4450 {
4451   return _content->getInfo();
4452 }
4453
4454 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4455 {
4456   return _content->getUndergroundDataArray();
4457 }
4458
4459 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4460 {
4461   return _content->getUndergroundDataArrayExt(entries);
4462 }
4463
4464 MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
4465 {
4466   return _content->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
4467 }
4468
4469 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
4470 {
4471   return _content->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
4472 }
4473
4474 int MEDFileField1TS::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
4475 {
4476   return _content->getNonEmptyLevels(mname,levs);
4477 }
4478
4479 std::vector<TypeOfField> MEDFileField1TS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
4480 {
4481   return _content->getTypesOfFieldAvailable();
4482 }
4483
4484 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,
4485                                                                                        std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
4486 {
4487   return _content->getFieldSplitedByType(mname,types,typesF,pfls,locs);
4488 }
4489 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
4490                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
4491 {
4492   return _content->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
4493 }
4494
4495 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)
4496 {
4497   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,id,ft,infos,nbOfStep);
4498 }
4499
4500 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA():_field_type(-1)
4501 {
4502 }
4503
4504 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const char *fieldName):_name(fieldName),_field_type(-1)
4505 {
4506 }
4507
4508 /*!
4509  * \param [in] fieldId field id in C mode
4510  */
4511 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId) throw(INTERP_KERNEL::Exception)
4512 try:_name("")
4513 {
4514   med_field_type typcha;
4515   //
4516   int ncomp=MEDfieldnComponent(fid,fieldId+1);
4517   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4518   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4519   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
4520   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4521   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4522   med_bool localMesh;
4523   int nbOfStep;
4524   MEDfieldInfo(fid,fieldId+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
4525   _name=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
4526   _field_type=MEDFileUtilities::TraduceFieldType(typcha);
4527   _infos.resize(ncomp);
4528   for(int j=0;j<ncomp;j++)
4529     _infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
4530   //
4531   finishLoading(fid,nbOfStep);
4532 }
4533 catch(INTERP_KERNEL::Exception& e)
4534   {
4535     throw e;
4536   }
4537
4538 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, int id, int ft, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception)
4539 try:_name(fieldName),_infos(infos),_field_type(ft)
4540 {
4541   finishLoading(fid,nbOfStep);
4542 }
4543 catch(INTERP_KERNEL::Exception& e)
4544 {
4545   throw e;
4546 }
4547
4548 std::size_t MEDFileFieldMultiTSWithoutSDA::getHeapMemorySize() const
4549 {
4550   std::size_t ret=_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>);
4551   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
4552     ret+=(*it).capacity();
4553   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4554     if((const MEDFileField1TSWithoutSDA *)(*it))
4555       ret+=(*it)->getHeapMemorySize();
4556   return ret;
4557 }
4558
4559 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
4560 {
4561   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret=new MEDFileFieldMultiTSWithoutSDA(*this);
4562   std::size_t i=0;
4563   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
4564     {
4565       if((const MEDFileField1TSWithoutSDA *)*it)
4566         ret->_time_steps[i]=(*it)->deepCpy();
4567     }
4568   return ret.retn();
4569 }
4570
4571 const std::vector<std::string>& MEDFileFieldMultiTSWithoutSDA::getInfo() const throw(INTERP_KERNEL::Exception)
4572 {
4573   if(_time_steps.empty())
4574     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getInfos : not time steps !");
4575   return _time_steps[0]->getInfo();
4576 }
4577
4578 /*!
4579  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
4580  */
4581 DataArrayDouble *MEDFileFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
4582 {
4583   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
4584 }
4585
4586 /*!
4587  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
4588  */
4589 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)
4590 {
4591   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
4592 }
4593
4594 std::string MEDFileFieldMultiTSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
4595 {
4596   if(_time_steps.empty())
4597     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
4598   return _time_steps[0]->getMeshName();
4599 }
4600
4601 void MEDFileFieldMultiTSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
4602 {
4603   std::string oldName(getMeshName());
4604   std::vector< std::pair<std::string,std::string> > v(1);
4605   v[0].first=oldName; v[0].second=newMeshName;
4606   changeMeshNames(v);
4607 }
4608
4609 bool MEDFileFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
4610 {
4611   bool ret=false;
4612   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4613     {
4614       MEDFileField1TSWithoutSDA *cur(*it);
4615       if(cur)
4616         ret=cur->changeMeshNames(modifTab) || ret;
4617     }
4618   return ret;
4619 }
4620
4621 bool MEDFileFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4622                                                                 MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
4623 {
4624   bool ret=false;
4625   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4626     {
4627       MEDFileField1TSWithoutSDA *f1ts(*it);
4628       if(f1ts)
4629         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4630     }
4631   return ret;
4632 }
4633
4634 void MEDFileFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
4635 {
4636   if(_time_steps.empty())
4637     {
4638       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
4639       obj->setFieldNoProfileSBT(field,glob);
4640       copyTinyInfoFrom(field);
4641       _time_steps.push_back(obj);
4642     }
4643   else
4644     {
4645       checkCoherencyOfTinyInfo(field);
4646       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
4647       obj->setFieldNoProfileSBT(field,glob);
4648       _time_steps.push_back(obj);
4649     }
4650 }
4651
4652 void MEDFileFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
4653 {
4654   if(_time_steps.empty())
4655     {
4656       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
4657       obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,glob);
4658       copyTinyInfoFrom(field);
4659       _time_steps.push_back(obj);
4660     }
4661   else
4662     {
4663       checkCoherencyOfTinyInfo(field);
4664       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
4665       obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,glob);
4666       _time_steps.push_back(obj);
4667     }
4668 }
4669
4670 std::string MEDFileFieldMultiTSWithoutSDA::getDtUnit() const throw(INTERP_KERNEL::Exception)
4671 {
4672   if(_time_steps.empty())
4673     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
4674   return _time_steps[0]->getDtUnit();
4675 }
4676
4677 std::string MEDFileFieldMultiTSWithoutSDA::getName() const
4678 {
4679   return _name;
4680 }
4681
4682 void MEDFileFieldMultiTSWithoutSDA::setName(const char *name)
4683 {
4684   _name=name;
4685 }
4686
4687 void MEDFileFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
4688 {
4689   std::string startLine(bkOffset,' ');
4690   oss << startLine << "Field multi time steps";
4691   if(fmtsId>=0)
4692     oss << " (" << fmtsId << ")";
4693   oss << " has the following name: \"" << _name << "\"." << std::endl;
4694   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
4695   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
4696     {
4697       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
4698     }
4699   int i=0;
4700   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
4701     {
4702       std::string chapter(17,'0'+i);
4703       oss << startLine << chapter << std::endl;
4704       const MEDFileField1TSWithoutSDA *cur=(*it);
4705       if(cur)
4706         cur->simpleRepr(bkOffset+2,oss,i);
4707       else
4708         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
4709       oss << startLine << chapter << std::endl;
4710     }
4711 }
4712
4713 std::vector< std::pair<int,int> > MEDFileFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
4714 {
4715   std::size_t sz=_time_steps.size();
4716   std::vector< std::pair<int,int> > ret(sz);
4717   ret1.resize(sz);
4718   for(std::size_t i=0;i<sz;i++)
4719     {
4720       const MEDFileField1TSWithoutSDA *f1ts=_time_steps[i];
4721       if(f1ts)
4722         {
4723           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
4724         }
4725       else
4726         {
4727           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
4728           throw INTERP_KERNEL::Exception(oss.str().c_str());
4729         }
4730     }
4731   return ret;
4732 }
4733
4734 void MEDFileFieldMultiTSWithoutSDA::finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception)
4735 {
4736   _time_steps.resize(nbPdt);
4737   for(int i=0;i<nbPdt;i++)
4738     {
4739       std::vector< std::pair<int,int> > ts;
4740       med_int numdt=0,numo=0;
4741       med_int meshIt=0,meshOrder=0;
4742       med_float dt=0.0;
4743       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
4744       _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,_field_type,numdt,numo,_infos);
4745       _time_steps[i]->finishLoading(fid);
4746     }
4747 }
4748
4749 void MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
4750 {
4751   _name=field->getName();
4752   if(_name.empty())
4753     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4754   const DataArrayDouble *arr=field->getArray();
4755   if(!arr)
4756     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
4757   _infos=arr->getInfoOnComponents();
4758 }
4759
4760 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field) const throw(INTERP_KERNEL::Exception)
4761 {
4762   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
4763   if(_name!=field->getName())
4764     {
4765       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
4766       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
4767       throw INTERP_KERNEL::Exception(oss.str().c_str());
4768     }
4769   const DataArrayDouble *arr=field->getArray();
4770   if(!arr)
4771     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
4772   if(_infos!=arr->getInfoOnComponents())
4773     {
4774       std::ostringstream oss; oss << MSG << "components ! should be \"";
4775       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
4776       oss << " But compo in input fields are : ";
4777       std::vector<std::string> tmp=arr->getInfoOnComponents();
4778       std::copy(tmp.begin(),tmp.end(),std::ostream_iterator<std::string>(oss,", "));
4779       oss << " !";
4780       throw INTERP_KERNEL::Exception(oss.str().c_str());
4781     }
4782 }
4783
4784 void MEDFileFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception)
4785 {
4786   if(_time_steps.empty())
4787     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
4788   std::vector<std::string> infos(getInfo());
4789   int nbComp=infos.size();
4790   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
4791   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
4792   for(int i=0;i<nbComp;i++)
4793     {
4794       std::string info=infos[i];
4795       std::string c,u;
4796       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
4797       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
4798       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
4799     }
4800   if(_name.empty())
4801     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
4802   MEDfieldCr(fid,_name.c_str(),MED_FLOAT64,nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
4803   int nbOfTS=_time_steps.size();
4804   for(int i=0;i<nbOfTS;i++)
4805     _time_steps[i]->writeLL(fid,opts);
4806 }
4807
4808 int MEDFileFieldMultiTSWithoutSDA::getNumberOfTS() const
4809 {
4810   return _time_steps.size();
4811 }
4812
4813 void MEDFileFieldMultiTSWithoutSDA::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
4814 {
4815   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  > newTS;
4816   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4817     {
4818       const MEDFileField1TSWithoutSDA *tmp=(*it);
4819       if(tmp)
4820         newTS.push_back(*it);
4821     }
4822   _time_steps=newTS;
4823 }
4824
4825 void MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
4826 {
4827   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  > newTS;
4828   int maxId=(int)_time_steps.size();
4829   int ii=0;
4830   std::set<int> idsToDel;
4831   for(const int *id=startIds;id!=endIds;id++,ii++)
4832     {
4833       if(*id>=0 && *id<maxId)
4834         {
4835           idsToDel.insert(*id);
4836         }
4837       else
4838         {
4839           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
4840           throw INTERP_KERNEL::Exception(oss.str().c_str());
4841         }
4842     }
4843   for(int iii=0;iii<maxId;iii++)
4844     if(idsToDel.find(iii)==idsToDel.end())
4845       newTS.push_back(_time_steps[iii]);
4846   _time_steps=newTS;
4847 }
4848
4849 int MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
4850 {
4851   int ret=0;
4852   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
4853   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
4854     {
4855       const MEDFileField1TSWithoutSDA *tmp(*it);
4856       if(tmp)
4857         {
4858           int it2,ord;
4859           tmp->getTime(it2,ord);
4860           if(it2==iteration && order==ord)
4861             return ret;
4862           else
4863             oss << "(" << it2 << ","  << ord << "), ";
4864         }
4865     }
4866   throw INTERP_KERNEL::Exception(oss.str().c_str());
4867 }
4868
4869 int MEDFileFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
4870 {
4871   int ret=0;
4872   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
4873   oss.precision(15);
4874   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
4875     {
4876       const MEDFileField1TSWithoutSDA *tmp(*it);
4877       if(tmp)
4878         {
4879           int it2,ord;
4880           double ti=tmp->getTime(it2,ord);
4881           if(fabs(time-ti)<eps)
4882             return ret;
4883           else
4884             oss << ti << ", ";
4885         }
4886     }
4887   throw INTERP_KERNEL::Exception(oss.str().c_str());
4888 }
4889
4890 std::vector< std::pair<int,int> > MEDFileFieldMultiTSWithoutSDA::getIterations() const
4891 {
4892   int lgth=_time_steps.size();
4893   std::vector< std::pair<int,int> > ret(lgth);
4894   for(int i=0;i<lgth;i++)
4895     _time_steps[i]->fillIteration(ret[i]);
4896   return ret;
4897 }
4898
4899 /*!
4900  * 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'
4901  * This method returns two things.
4902  * - The absolute dimension of 'this' in first parameter. 
4903  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
4904  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
4905  *
4906  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
4907  * Only these 3 discretizations will be taken into account here.
4908  *
4909  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
4910  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
4911  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
4912  *
4913  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
4914  * 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'.
4915  * 
4916  * Let's consider the typical following case :
4917  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
4918  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
4919  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
4920  *   TETRA4 and SEG2
4921  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
4922  *
4923  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
4924  * 
4925  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
4926  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
4927  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
4928  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
4929  */
4930 int MEDFileFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
4931 {
4932   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
4933 }
4934
4935 std::vector< std::vector<TypeOfField> > MEDFileFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
4936 {
4937   int lgth=_time_steps.size();
4938   std::vector< std::vector<TypeOfField> > ret(lgth);
4939   for(int i=0;i<lgth;i++)
4940     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
4941   return ret;
4942 }
4943
4944 /*!
4945  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
4946  */
4947 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)
4948 {
4949   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
4950 }
4951
4952 /*!
4953  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
4954  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
4955  */
4956 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)
4957 {
4958   return getTimeStepEntry(iteration,order).getFieldSplitedByType2(mname,types,typesF,pfls,locs);
4959 }
4960
4961 const MEDFileField1TSWithoutSDA& MEDFileFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const throw(INTERP_KERNEL::Exception)
4962 {
4963   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4964     if((*it)->isDealingTS(iteration,order))
4965       return *(*it);
4966   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepEntry : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
4967   std::vector< std::pair<int,int> > vp=getIterations();
4968   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
4969     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
4970   throw INTERP_KERNEL::Exception(oss.str().c_str());
4971 }
4972
4973 MEDFileField1TSWithoutSDA& MEDFileFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) throw(INTERP_KERNEL::Exception)
4974 {
4975   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4976     if((*it)->isDealingTS(iteration,order))
4977       return *(*it);
4978   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepEntry : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
4979   std::vector< std::pair<int,int> > vp=getIterations();
4980   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
4981     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
4982   throw INTERP_KERNEL::Exception(oss.str().c_str());
4983 }
4984
4985 const MEDFileField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const throw(INTERP_KERNEL::Exception)
4986 {
4987   if(pos<0 || pos>=(int)_time_steps.size())
4988     {
4989       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
4990       throw INTERP_KERNEL::Exception(oss.str().c_str());
4991     }
4992   const MEDFileField1TSWithoutSDA *item=_time_steps[pos];
4993   if(item==0)
4994     {
4995       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
4996       oss << "\nTry to use following method eraseEmptyTS !";
4997       throw INTERP_KERNEL::Exception(oss.str().c_str());
4998     }
4999   return item;
5000 }
5001
5002 MEDFileField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) throw(INTERP_KERNEL::Exception)
5003 {
5004   if(pos<0 || pos>=(int)_time_steps.size())
5005     {
5006       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
5007       throw INTERP_KERNEL::Exception(oss.str().c_str());
5008     }
5009   MEDFileField1TSWithoutSDA *item=_time_steps[pos];
5010   if(item==0)
5011     {
5012       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
5013       oss << "\nTry to use following method eraseEmptyTS !";
5014       throw INTERP_KERNEL::Exception(oss.str().c_str());
5015     }
5016   return item;
5017 }
5018
5019 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
5020 {
5021   std::vector<std::string> ret;
5022   std::set<std::string> ret2;
5023   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5024     {
5025       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
5026       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
5027         if(ret2.find(*it2)==ret2.end())
5028           {
5029             ret.push_back(*it2);
5030             ret2.insert(*it2);
5031           }
5032     }
5033   return ret;
5034 }
5035
5036 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
5037 {
5038   std::vector<std::string> ret;
5039   std::set<std::string> ret2;
5040   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5041     {
5042       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
5043       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
5044         if(ret2.find(*it2)==ret2.end())
5045           {
5046             ret.push_back(*it2);
5047             ret2.insert(*it2);
5048           }
5049     }
5050   return ret;
5051 }
5052
5053 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
5054 {
5055   std::vector<std::string> ret;
5056   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5057     {
5058       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
5059       ret.insert(ret.end(),tmp.begin(),tmp.end());
5060     }
5061   return ret;
5062 }
5063
5064 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
5065 {
5066   std::vector<std::string> ret;
5067   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5068     {
5069       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
5070       ret.insert(ret.end(),tmp.begin(),tmp.end());
5071     }
5072   return ret;
5073 }
5074
5075 void MEDFileFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5076 {
5077   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5078     (*it)->changePflsRefsNamesGen2(mapOfModif);
5079 }
5080
5081 void MEDFileFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5082 {
5083   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
5084     (*it)->changeLocsRefsNamesGen2(mapOfModif);
5085 }
5086
5087 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
5088 {
5089   return new MEDFileFieldMultiTS;
5090 }
5091
5092 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
5093 {
5094   return new MEDFileFieldMultiTS(fileName);
5095 }
5096
5097 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
5098 {
5099   return new MEDFileFieldMultiTS(fileName,fieldName);
5100 }
5101
5102 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
5103 {
5104   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
5105 }
5106
5107 std::size_t MEDFileFieldMultiTS::getHeapMemorySize() const
5108 {
5109   std::size_t ret=0;
5110   if((const MEDFileFieldMultiTSWithoutSDA*)_content)
5111     ret+=_content->getHeapMemorySize();
5112   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
5113 }
5114
5115 MEDFileFieldMultiTS *MEDFileFieldMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception)
5116 {
5117   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(*this);
5118   if((const MEDFileFieldMultiTSWithoutSDA *)_content)
5119     ret->_content=_content->deepCpy();
5120   ret->deepCpyGlobs(*this);
5121   return ret.retn();
5122 }
5123
5124 /*!
5125  * \return a new allocated object that the caller should deal with.
5126  */
5127 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
5128 {
5129   const MEDFileField1TSWithoutSDA *item=_content->getTimeStepAtPos2(pos);
5130   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*item,false);
5131   ret->shallowCpyGlobs(*this);
5132   return ret.retn();
5133 }
5134
5135 /*!
5136  * \return a new allocated object that the caller should deal with.
5137  */
5138 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
5139 {
5140   int pos=getPosOfTimeStep(iteration,order);
5141   return getTimeStepAtPos(pos);
5142 }
5143
5144 /*!
5145  * \return a new allocated object that the caller should deal with.
5146  */
5147 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
5148 {
5149   int pos=getPosGivenTime(time,eps);
5150   return getTimeStepAtPos(pos);
5151 }
5152
5153 MEDFileFieldMultiTSIterator *MEDFileFieldMultiTS::iterator() throw(INTERP_KERNEL::Exception)
5154 {
5155   return new MEDFileFieldMultiTSIterator(this);
5156 }
5157
5158 std::string MEDFileFieldMultiTS::simpleRepr() const
5159 {
5160   std::ostringstream oss;
5161   _content->simpleRepr(0,oss,-1);
5162   MEDFileFieldGlobsReal::simpleRepr(oss);
5163   return oss.str();
5164 }
5165
5166 void MEDFileFieldMultiTS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
5167 {
5168   writeGlobals(fid,*this);
5169   _content->writeLL(fid,*this);
5170 }
5171
5172 void MEDFileFieldMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
5173 {
5174   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5175   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
5176   writeLL(fid);
5177 }
5178
5179 /*!
5180  * Performs the job than MEDFileField1TS::getFieldAtLevel except that (iteration,order) couple should be specified !
5181  * If such couple does not exist an exception is thrown.
5182  */
5183 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
5184 {
5185   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
5186   return myF1TS.getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this);
5187 }
5188
5189 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const throw(INTERP_KERNEL::Exception)
5190 {
5191   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
5192   return myF1TS.getFieldAtTopLevel(type,0,renumPol,this);
5193 }
5194
5195 /*!
5196  * Performs the job than MEDFileField1TS::getFieldOnMeshAtLevel except that (iteration,order) couple should be specified !
5197  * If such couple does not exist an exception is thrown.
5198  */
5199 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
5200 {
5201   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
5202   return myF1TS.getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh);
5203 }
5204
5205 /*!
5206  * Performs the job than MEDFileField1TS::getFieldOnMeshAtLevel except that (iteration,order) couple should be specified !
5207  * If such couple does not exist an exception is thrown.
5208  */
5209 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
5210 {
5211   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
5212   return myF1TS.getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0);
5213 }
5214
5215 /*!
5216  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
5217  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
5218  * This method is useful for MED2 file format when field on different mesh was autorized.
5219  */
5220 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
5221 {
5222   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
5223   return myF1TS.getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this);
5224 }
5225
5226 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
5227 {
5228   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
5229   return myF1TS.getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this);
5230 }
5231
5232 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
5233 {
5234   _content->appendFieldNoProfileSBT(field,*this);
5235 }
5236
5237 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
5238 {
5239   _content->appendFieldProfile(field,mesh,meshDimRelToMax,profile,*this);
5240 }
5241
5242 MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> MEDFileFieldMultiTS::getContent()
5243 {
5244   return _content;
5245 }
5246
5247 MEDFileFieldMultiTS::MEDFileFieldMultiTS():_content(new MEDFileFieldMultiTSWithoutSDA)
5248 {
5249 }
5250
5251
5252
5253 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
5254 try:MEDFileFieldGlobsReal(fileName)
5255 {
5256   MEDFileUtilities::CheckFileForRead(fileName);
5257   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5258   int nbFields=MEDnField(fid);
5259   if(nbFields<1)
5260     {
5261       std::ostringstream oss; oss << "MEDFileFieldMultiTS(const char *fileName) constructor : no fields in file \"" << fileName << "\" !";
5262       throw INTERP_KERNEL::Exception(oss.str().c_str());
5263     }
5264   _content=new MEDFileFieldMultiTSWithoutSDA(fid,0);
5265   //
5266   loadGlobals(fid);
5267 }
5268 catch(INTERP_KERNEL::Exception& e)
5269   {
5270     throw e;
5271   }
5272
5273 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
5274 try:MEDFileFieldGlobsReal(fileName)
5275 {
5276   MEDFileUtilities::CheckFileForRead(fileName);
5277   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5278   int nbFields=MEDnField(fid);
5279   med_field_type typcha;
5280   bool found=false;
5281   std::vector<std::string> fns(nbFields);
5282   for(int i=0;i<nbFields && !found;i++)
5283     {
5284       int ncomp=MEDfieldnComponent(fid,i+1);
5285       INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5286       INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5287       INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5288       INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5289       INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5290       med_bool localMesh;
5291       int nbOfStep;
5292       MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5293       std::string tmp(nomcha);
5294       fns[i]=tmp;
5295       found=(tmp==fieldName);
5296       if(found)
5297         _content=new MEDFileFieldMultiTSWithoutSDA(fid,i);
5298     }
5299   if(!found)
5300     {
5301       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5302       std::copy(fns.begin(),fns.end(),std::ostream_iterator<std::string>(oss," "));
5303       throw INTERP_KERNEL::Exception(oss.str().c_str());
5304     }
5305   //
5306   loadGlobals(fid);
5307 }
5308 catch(INTERP_KERNEL::Exception& e)
5309   {
5310     throw e;
5311   }
5312
5313 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
5314 {
5315   if(!shallowCopyOfContent)
5316     {
5317       const MEDFileFieldMultiTSWithoutSDA *otherPtr(&other);
5318       otherPtr->incrRef();
5319       _content=const_cast<MEDFileFieldMultiTSWithoutSDA *>(otherPtr);
5320     }
5321   else
5322     {
5323       _content=new MEDFileFieldMultiTSWithoutSDA(other);
5324     }
5325 }
5326
5327 std::vector<std::string> MEDFileFieldMultiTS::getPflsReallyUsed() const
5328 {
5329   return _content->getPflsReallyUsed2();
5330 }
5331
5332 std::vector<std::string> MEDFileFieldMultiTS::getLocsReallyUsed() const
5333 {
5334   return _content->getLocsReallyUsed2();
5335 }
5336
5337 std::vector<std::string> MEDFileFieldMultiTS::getPflsReallyUsedMulti() const
5338 {
5339   return _content->getPflsReallyUsedMulti2();
5340 }
5341
5342 std::vector<std::string> MEDFileFieldMultiTS::getLocsReallyUsedMulti() const
5343 {
5344   return _content->getLocsReallyUsedMulti2();
5345 }
5346
5347 void MEDFileFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5348 {
5349   _content->changePflsRefsNamesGen2(mapOfModif);
5350 }
5351
5352 void MEDFileFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5353 {
5354   _content->changeLocsRefsNamesGen2(mapOfModif);
5355 }
5356
5357 int MEDFileFieldMultiTS::getNumberOfTS() const
5358 {
5359   return _content->getNumberOfTS();
5360 }
5361
5362 void MEDFileFieldMultiTS::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
5363 {
5364   _content->eraseEmptyTS();
5365 }
5366
5367 void MEDFileFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
5368 {
5369   _content->eraseTimeStepIds(startIds,endIds);
5370 }
5371
5372 std::vector< std::pair<int,int> > MEDFileFieldMultiTS::getIterations() const
5373 {
5374   return _content->getIterations();
5375 }
5376
5377 int MEDFileFieldMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
5378 {
5379   return _content->getPosOfTimeStep(iteration,order);
5380 }
5381
5382 int MEDFileFieldMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
5383 {
5384   return _content->getPosGivenTime(time,eps);
5385 }
5386
5387 int MEDFileFieldMultiTS::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
5388 {
5389   return _content->getNonEmptyLevels(iteration,order,mname,levs);
5390 }
5391
5392 std::vector< std::vector<TypeOfField> > MEDFileFieldMultiTS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
5393 {
5394   return _content->getTypesOfFieldAvailable();
5395 }
5396
5397 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)
5398 {
5399   return _content->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
5400 }
5401
5402 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)
5403 {
5404   return _content->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
5405 }
5406
5407 std::string MEDFileFieldMultiTS::getName() const
5408 {
5409   return _content->getName();
5410 }
5411
5412 void MEDFileFieldMultiTS::setName(const char *name)
5413 {
5414   _content->setName(name);
5415 }
5416
5417 void MEDFileFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
5418 {
5419   _content->simpleRepr(bkOffset,oss,fmtsId);
5420 }
5421
5422 std::vector< std::pair<int,int> > MEDFileFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
5423 {
5424   return _content->getTimeSteps(ret1);
5425 }
5426
5427 std::string MEDFileFieldMultiTS::getMeshName() const throw(INTERP_KERNEL::Exception)
5428 {
5429   return _content->getMeshName();
5430 }
5431
5432 void MEDFileFieldMultiTS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
5433 {
5434   _content->setMeshName(newMeshName);
5435 }
5436
5437 bool MEDFileFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
5438 {
5439   return _content->changeMeshNames(modifTab);
5440 }
5441
5442 const std::vector<std::string>& MEDFileFieldMultiTS::getInfo() const throw(INTERP_KERNEL::Exception)
5443 {
5444   return _content->getInfo();
5445 }
5446
5447 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
5448 {
5449   return _content->getUndergroundDataArray(iteration,order);
5450 }
5451
5452 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)
5453 {
5454   return _content->getUndergroundDataArrayExt(iteration,order,entries);
5455 }
5456
5457 MEDFileFieldMultiTSIterator::MEDFileFieldMultiTSIterator(MEDFileFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
5458 {
5459   if(fmts)
5460     {
5461       fmts->incrRef();
5462       _nb_iter=fmts->getNumberOfTS();
5463     }
5464 }
5465
5466 MEDFileFieldMultiTSIterator::~MEDFileFieldMultiTSIterator() 
5467 {
5468 }
5469
5470 MEDFileField1TS *MEDFileFieldMultiTSIterator::nextt()
5471 {
5472   if(_iter_id<_nb_iter)
5473     {
5474       MEDFileFieldMultiTS *fmts(_fmts);
5475       if(fmts)
5476         return fmts->getTimeStepAtPos(_iter_id++);
5477       else
5478         return 0;
5479     }
5480   else
5481     return 0;
5482 }
5483
5484 MEDFileFields *MEDFileFields::New()
5485 {
5486   return new MEDFileFields;
5487 }
5488
5489 MEDFileFields *MEDFileFields::New(const char *fileName) throw(INTERP_KERNEL::Exception)
5490 {
5491   return new MEDFileFields(fileName);
5492 }
5493
5494 std::size_t MEDFileFields::getHeapMemorySize() const
5495 {
5496   std::size_t ret=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA>);
5497   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
5498     if((const MEDFileFieldMultiTSWithoutSDA *)*it)
5499       ret+=(*it)->getHeapMemorySize();
5500   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
5501 }
5502
5503 MEDFileFields *MEDFileFields::deepCpy() const throw(INTERP_KERNEL::Exception)
5504 {
5505   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=new MEDFileFields(*this);
5506   std::size_t i=0;
5507   for( std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
5508     {
5509       if((const MEDFileFieldMultiTSWithoutSDA*)*it)
5510         ret->_fields[i]=(*it)->deepCpy();
5511     }
5512   ret->deepCpyGlobs(*this);
5513   return ret.retn();
5514 }
5515
5516 int MEDFileFields::getNumberOfFields() const
5517 {
5518   return _fields.size();
5519 }
5520
5521 std::vector<std::string> MEDFileFields::getFieldsNames() const throw(INTERP_KERNEL::Exception)
5522 {
5523   std::vector<std::string> ret(_fields.size());
5524   int i=0;
5525   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
5526     {
5527       const MEDFileFieldMultiTSWithoutSDA *f=(*it);
5528       if(f)
5529         {
5530           ret[i]=f->getName();
5531         }
5532       else
5533         {
5534           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
5535           throw INTERP_KERNEL::Exception(oss.str().c_str());
5536         }
5537     }
5538   return ret;
5539 }
5540
5541 std::vector<std::string> MEDFileFields::getMeshesNames() const throw(INTERP_KERNEL::Exception)
5542 {
5543   std::vector<std::string> ret;
5544   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
5545     {
5546       const MEDFileFieldMultiTSWithoutSDA *cur(*it);
5547       if(cur)
5548         ret.push_back(cur->getMeshName());
5549     }
5550   return ret;
5551 }
5552
5553 std::string MEDFileFields::simpleRepr() const
5554 {
5555   std::ostringstream oss;
5556   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
5557   simpleRepr(0,oss);
5558   return oss.str();
5559 }
5560
5561 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
5562 {
5563   int nbOfFields=getNumberOfFields();
5564   std::string startLine(bkOffset,' ');
5565   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
5566   int i=0;
5567   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
5568     {
5569       const MEDFileFieldMultiTSWithoutSDA *cur=(*it);
5570       if(cur)
5571         {
5572           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
5573         }
5574       else
5575         {
5576           oss << startLine << "  - not defined !" << std::endl;
5577         }
5578     }
5579   i=0;
5580   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
5581     {
5582       const MEDFileFieldMultiTSWithoutSDA *cur=(*it);
5583       std::string chapter(17,'0'+i);
5584       oss << startLine << chapter << std::endl;
5585       if(cur)
5586         {
5587           cur->simpleRepr(bkOffset+2,oss,i);
5588         }
5589       else
5590         {
5591           oss << startLine << "  - not defined !" << std::endl;
5592         }
5593       oss << startLine << chapter << std::endl;
5594     }
5595   MEDFileFieldGlobsReal::simpleRepr(oss);
5596 }
5597
5598 MEDFileFields::MEDFileFields()
5599 {
5600 }
5601
5602 MEDFileFields::MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception)
5603 try:MEDFileFieldGlobsReal(fileName)
5604   {
5605     MEDFileUtilities::CheckFileForRead(fileName);
5606     MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5607     int nbFields=MEDnField(fid);
5608     _fields.resize(nbFields);
5609     med_field_type typcha;
5610     for(int i=0;i<nbFields;i++)
5611       {
5612         int ncomp=MEDfieldnComponent(fid,i+1);
5613         INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5614         INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5615         INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5616         INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5617         INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5618         med_bool localMesh;
5619         int nbOfStep;
5620         MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5621         int ft=MEDFileUtilities::TraduceFieldType(typcha);
5622         std::vector<std::string> infos(ncomp);
5623         for(int j=0;j<ncomp;j++)
5624           infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5625         _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,nomcha,i+1,ft,infos,nbOfStep);
5626       }
5627     loadAllGlobals(fid);
5628   }
5629 catch(INTERP_KERNEL::Exception& e)
5630   {
5631     throw e;
5632   }
5633
5634 void MEDFileFields::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
5635 {
5636   int i=0;
5637   writeGlobals(fid,*this);
5638   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
5639     {
5640       const MEDFileFieldMultiTSWithoutSDA *elt=*it;
5641       if(!elt)
5642         {
5643           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
5644           throw INTERP_KERNEL::Exception(oss.str().c_str());
5645         }
5646       elt->writeLL(fid,*this);
5647     }
5648 }
5649
5650 void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
5651 {
5652   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5653   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
5654   writeLL(fid);
5655 }
5656
5657 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
5658 {
5659   std::vector<std::string> ret;
5660   std::set<std::string> ret2;
5661   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
5662     {
5663       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
5664       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
5665         if(ret2.find(*it2)==ret2.end())
5666           {
5667             ret.push_back(*it2);
5668             ret2.insert(*it2);
5669           }
5670     }
5671   return ret;
5672 }
5673
5674 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
5675 {
5676   std::vector<std::string> ret;
5677   std::set<std::string> ret2;
5678   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
5679     {
5680       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
5681       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
5682         if(ret2.find(*it2)==ret2.end())
5683           {
5684             ret.push_back(*it2);
5685             ret2.insert(*it2);
5686           }
5687     }
5688   return ret;
5689 }
5690
5691 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
5692 {
5693   std::vector<std::string> ret;
5694   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
5695     {
5696       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
5697       ret.insert(ret.end(),tmp.begin(),tmp.end());
5698     }
5699   return ret;
5700 }
5701
5702 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
5703 {
5704   std::vector<std::string> ret;
5705   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
5706     {
5707       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
5708       ret.insert(ret.end(),tmp.begin(),tmp.end());
5709     }
5710   return ret;
5711 }
5712
5713 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5714 {
5715   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
5716     (*it)->changePflsRefsNamesGen2(mapOfModif);
5717 }
5718
5719 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5720 {
5721   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
5722     (*it)->changeLocsRefsNamesGen2(mapOfModif);
5723 }
5724
5725 void MEDFileFields::resize(int newSize) throw(INTERP_KERNEL::Exception)
5726 {
5727   _fields.resize(newSize);
5728 }
5729
5730 void MEDFileFields::pushField(MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
5731 {
5732   if(!field)
5733     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
5734   _fields.push_back(field->getContent());
5735   appendGlobs(*field,1e-12);
5736 }
5737
5738 void MEDFileFields::setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
5739 {
5740   if(!field)
5741     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
5742   if(i>=(int)_fields.size())
5743     _fields.resize(i+1);
5744   _fields[i]=field->getContent();
5745   appendGlobs(*field,1e-12);
5746 }
5747
5748 void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception)
5749 {
5750   if(i<0 || i>=(int)_fields.size())
5751     {
5752       std::ostringstream oss; oss << "MEDFileFields::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
5753       throw INTERP_KERNEL::Exception(oss.str().c_str());
5754     }
5755   _fields.erase(_fields.begin()+i);
5756 }
5757
5758 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
5759 {
5760   bool ret=false;
5761   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
5762     {
5763       MEDFileFieldMultiTSWithoutSDA *cur(*it);
5764       if(cur)
5765         ret=cur->changeMeshNames(modifTab) || ret;
5766     }
5767   return ret;
5768 }
5769
5770 /*!
5771  * \param [in] meshName the name of the mesh that will be renumbered.
5772  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
5773  *             This code corresponds to the distribution of types in the corresponding mesh.
5774  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
5775  * \param [in] renumO2N the old to new renumber array.
5776  * \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 
5777  *         field in \a this.
5778  */
5779 bool MEDFileFields::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N) throw(INTERP_KERNEL::Exception)
5780 {
5781   bool ret=false;
5782   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
5783     {
5784       MEDFileFieldMultiTSWithoutSDA *fmts(*it);
5785       if(fmts)
5786         {
5787           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
5788         }
5789     }
5790   return ret;
5791 }
5792
5793 MEDFileFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception)
5794 {
5795   if(i<0 || i>=(int)_fields.size())
5796     {
5797       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
5798       throw INTERP_KERNEL::Exception(oss.str().c_str());
5799     }
5800   const MEDFileFieldMultiTSWithoutSDA *fmts=_fields[i];
5801   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New(*fmts,false);
5802   ret->shallowCpyGlobs(*this);
5803   return ret.retn();
5804 }
5805
5806 MEDFileFieldMultiTS *MEDFileFields::getFieldWithName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
5807 {
5808   return getFieldAtPos(getPosFromFieldName(fieldName));
5809 }
5810
5811 MEDFileFieldsIterator *MEDFileFields::iterator() throw(INTERP_KERNEL::Exception)
5812 {
5813   return new MEDFileFieldsIterator(this);
5814 }
5815
5816 int MEDFileFields::getPosFromFieldName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
5817 {
5818   std::string tmp(fieldName);
5819   std::vector<std::string> poss;
5820   for(std::size_t i=0;i<_fields.size();i++)
5821     {
5822       const MEDFileFieldMultiTSWithoutSDA *f=_fields[i];
5823       if(f)
5824         {
5825           std::string fname(f->getName());
5826           if(tmp==fname)
5827             return i;
5828           else
5829             poss.push_back(fname);
5830         }
5831     }
5832   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
5833   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
5834   oss << " !";
5835   throw INTERP_KERNEL::Exception(oss.str().c_str());
5836 }
5837
5838 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
5839 {
5840   if(fs)
5841     {
5842       fs->incrRef();
5843       _nb_iter=fs->getNumberOfFields();
5844     }
5845 }
5846
5847 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
5848 {
5849 }
5850
5851 MEDFileFieldMultiTS *MEDFileFieldsIterator::nextt()
5852 {
5853   if(_iter_id<_nb_iter)
5854     {
5855       MEDFileFields *fs(_fs);
5856       if(fs)
5857         return fs->getFieldAtPos(_iter_id++);
5858       else
5859         return 0;
5860     }
5861   else
5862     return 0;
5863 }