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