]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDFileField.cxx
Salome HOME
Debug revealed with convertTo
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileUtilities.hxx"
25
26 #include "MEDCouplingFieldDouble.hxx"
27 #include "MEDCouplingFieldDiscretization.hxx"
28
29 #include "InterpKernelAutoPtr.hxx"
30 #include "CellModel.hxx"
31
32 #include <algorithm>
33 #include <iterator>
34
35 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
36 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
37 extern med_geometry_type typmainoeud[1];
38 extern med_geometry_type typmai3[32];
39
40 using namespace ParaMEDMEM;
41
42 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
43 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
44
45 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const char *locName)
46 {
47   return new MEDFileFieldLoc(fid,locName);
48 }
49
50 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
51 {
52   return new MEDFileFieldLoc(fid,id);
53 }
54
55 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)
56 {
57   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
58 }
59
60 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const char *locName):_name(locName)
61 {
62   med_geometry_type geotype;
63   med_geometry_type sectiongeotype;
64   int nsectionmeshcell;
65   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
66   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
67   MEDlocalizationInfoByName(fid,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
68   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+32,geotype)));
69   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
70   _nb_node_per_cell=cm.getNumberOfNodes();
71   _ref_coo.resize(_dim*_nb_node_per_cell);
72   _gs_coo.resize(_dim*_nb_gauss_pt);
73   _w.resize(_nb_gauss_pt);
74   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
75 }
76
77 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
78 {
79   med_geometry_type geotype;
80   med_geometry_type sectiongeotype;
81   int nsectionmeshcell;
82   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
83   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
84   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
85   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
86   _name=locName;
87   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+32,geotype)));
88   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
89   _nb_node_per_cell=cm.getNumberOfNodes();
90   _ref_coo.resize(_dim*_nb_node_per_cell);
91   _gs_coo.resize(_dim*_nb_gauss_pt);
92   _w.resize(_nb_gauss_pt);
93   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
94 }
95
96 MEDFileFieldLoc::MEDFileFieldLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType,
97                                  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),
98                                                                                                                                     _w(w)
99 {
100   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
101   _dim=cm.getDimension();
102   _nb_node_per_cell=cm.getNumberOfNodes();
103   _nb_gauss_pt=_w.size();
104 }
105
106 MEDFileFieldLoc *MEDFileFieldLoc::deepCpy() const
107 {
108   return new MEDFileFieldLoc(*this);
109 }
110
111 std::size_t MEDFileFieldLoc::getHeapMemorySize() const
112 {
113   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
114 }
115
116 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
117 {
118   static const char OFF7[]="\n    ";
119   oss << "\"" << _name << "\"" << OFF7;
120   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
121   oss << "Dimension=" << _dim << OFF7;
122   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
123   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
124   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
125   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
126   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
127 }
128
129 void MEDFileFieldLoc::setName(const char *name)
130 {
131   _name=name;
132 }
133
134 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
135 {
136   if(_name!=other._name)
137     return false;
138   if(_dim!=other._dim)
139     return false;
140   if(_nb_gauss_pt!=other._nb_gauss_pt)
141     return false;
142   if(_nb_node_per_cell!=other._nb_node_per_cell)
143     return false;
144   if(_geo_type!=other._geo_type)
145     return false;
146   if(MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
147     return false;
148   if(MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
149     return false;
150   if(MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
151     return false;
152   
153   return true;
154 }
155
156 void MEDFileFieldLoc::writeLL(med_idt fid) const
157 {
158   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);
159 }
160
161 std::string MEDFileFieldLoc::repr() const
162 {
163   std::ostringstream oss; oss.precision(15);
164   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
165   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
166   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
167   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
168   oss << "\n  - Ref coords are : ";
169   int sz=_ref_coo.size();
170   if(sz%_dim==0)
171     {
172       int nbOfTuples=sz/_dim;
173       for(int i=0;i<nbOfTuples;i++)
174         {
175           oss << "(";
176           for(int j=0;j<_dim;j++)
177             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
178           oss << ") ";
179         }
180     }
181   else
182     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
183   oss << "\n  - Gauss coords in reference element : ";
184   sz=_gs_coo.size();
185   if(sz%_dim==0)
186     {
187       int nbOfTuples=sz/_dim;
188       for(int i=0;i<nbOfTuples;i++)
189         {
190           oss << "(";
191           for(int j=0;j<_dim;j++)
192             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
193           oss << ") ";
194         }
195     }
196   else
197     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
198   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
199   return oss.str();
200 }
201
202 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
203 {
204   _type=field->getTypeOfField();
205   _start=start;
206   switch(_type)
207     {
208     case ON_CELLS:
209       {
210         getArray()->setContigPartOfSelectedValues2(_start,arrr,offset,offset+nbOfCells,1);
211         _end=_start+nbOfCells;
212         _nval=nbOfCells;
213         break;
214       }
215     case ON_GAUSS_NE:
216       {
217         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
218         const int *arrPtr=arr->getConstPointer();
219         getArray()->setContigPartOfSelectedValues2(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
220         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
221         _nval=nbOfCells;
222         break;
223       }
224     case ON_GAUSS_PT:
225       {
226         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
227         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
228         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
229         if(!disc2)
230           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
231         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
232         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
233         const int *dai2Ptr=dai2->getConstPointer();
234         int nbi=gsLoc.getWeights().size();
235         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=dai->selectByTupleId2(offset,offset+nbOfCells,1);
236         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
237         const int *da3Ptr=da3->getConstPointer();
238         if(da3->getNumberOfTuples()!=nbOfCells)
239           {//profile : for gauss even in NoProfile !!!
240             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
241             _profile=oss.str();
242             da3->setName(_profile.c_str());
243             glob.appendProfile(da3);
244           }
245         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=DataArrayInt::New();
246         _nval=da3->getNbOfElems();
247         da4->alloc(_nval*nbi,1);
248         int *da4Ptr=da4->getPointer();
249         for(int i=0;i<_nval;i++)
250           {
251             int ref=dai2Ptr[offset+da3Ptr[i]];
252             for(int j=0;j<nbi;j++)
253               *da4Ptr++=ref+j;
254           }
255         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
256         _localization=oss2.str();
257         getArray()->setContigPartOfSelectedValues(_start,arrr,da4);
258         _end=_start+_nval*nbi;
259         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
260         break;
261       }
262     default:
263       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
264     }
265   start=_end;
266 }
267
268 /*!
269  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
270  * \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).
271  * \param [in] multiTypePfl is the end user profile specified in high level API
272  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
273  * \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.
274  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
275  * \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.
276  */
277 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
278 {
279   _profile.clear();
280   _type=field->getTypeOfField();
281   std::string pflName(multiTypePfl->getName());
282   std::ostringstream oss; oss << pflName;
283   if(_type!=ON_NODES) { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); } else { oss << "_NODE"; }
284   if(locIds)
285     {
286       if(pflName.empty())
287         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
288       if(_type!=ON_GAUSS_PT)
289         {
290           locIds->setName(oss.str().c_str());
291           glob.appendProfile(locIds);
292           _profile=oss.str();
293         }
294     }
295   _start=start;
296   switch(_type)
297     {
298     case ON_NODES:
299       {
300          _nval=idsInPfl->getNumberOfTuples();
301          getArray()->setContigPartOfSelectedValues2(_start,arrr,0,arrr->getNumberOfTuples(),1);
302          _end=_start+_nval;
303          break;
304       }
305     case ON_CELLS:
306       {
307         _nval=idsInPfl->getNumberOfTuples();
308         getArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
309         _end=_start+_nval;
310         break;
311       }
312     case ON_GAUSS_NE:
313       {
314         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
315         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr->deltaShiftIndex();
316         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
317         arr3->computeOffsets2();
318         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
319         int trueNval=tmp->getNumberOfTuples();
320         _nval=idsInPfl->getNumberOfTuples();
321         getArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
322         _end=_start+trueNval;
323         break;
324       }
325     case ON_GAUSS_PT:
326       {
327         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
328         if(!disc2)
329           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
330         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
331         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
332         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
333         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
334         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
335         //
336         MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
337         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
338         //
339         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New();
340         int trueNval=0;
341         for(const int *pt=da4->begin();pt!=da4->end();pt++)
342           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
343         tmp->alloc(trueNval,1);
344         int *tmpPtr=tmp->getPointer();
345         for(const int *pt=da4->begin();pt!=da4->end();pt++)
346           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
347             *tmpPtr++=j;
348         //
349         _nval=da4->getNumberOfTuples();
350         getArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
351         _end=_start+trueNval;
352         oss << "_loc_" << _loc_id;
353         if(locIds)
354           {
355             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
356             da5->setName(oss.str().c_str());
357             glob.appendProfile(da5);
358             _profile=oss.str();
359           }
360         else
361           {
362             if(da3->getNumberOfTuples()!=nbOfEltsInWholeMesh || !da3->isIdentity())
363               {
364                 da3->setName(oss.str().c_str());
365                 glob.appendProfile(da3);
366                 _profile=oss.str();
367               }
368           }
369         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
370         _localization=oss2.str();
371         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
372         break;
373       }
374     default:
375       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
376     }
377   start=_end;
378 }
379
380 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
381 {
382   _start=start;
383   _nval=arrr->getNumberOfTuples();
384   getArray()->setContigPartOfSelectedValues2(_start,arrr,0,_nval,1);
385   _end=_start+_nval;
386   start=_end;
387 }
388
389 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt) throw(INTERP_KERNEL::Exception)
390 {
391   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt);
392 }
393
394 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
395 {
396   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
397 }
398
399 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
400 {
401   return new MEDFileFieldPerMeshPerTypePerDisc(other);
402 }
403
404 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySize() const
405 {
406   return _profile.capacity()+_localization.capacity()+5*sizeof(int);
407 }
408
409 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const throw(INTERP_KERNEL::Exception)
410 {
411   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
412   ret->_father=father;
413   return ret.retn();
414 }
415
416 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt) throw(INTERP_KERNEL::Exception)
417 try:_type(atype),_father(fath)
418   {
419   }
420 catch(INTERP_KERNEL::Exception& e)
421 {
422   throw e;
423 }
424
425 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
426 {
427 }
428
429 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)
430 {
431 }
432
433 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
434                                                                        _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
435 {
436 }
437
438 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
439 {
440   return _father;
441 }
442
443 void MEDFileFieldPerMeshPerTypePerDisc::prepareLoading(med_idt fid, int profileIt, int& start, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
444 {
445   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
446   INTERP_KERNEL::AutoPtr<char> pflname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
447   std::string fieldName=nasc.getName();
448   std::string meshName=getMeshName();
449   int iteration=getIteration();
450   int order=getOrder();
451   TypeOfField type=getType();
452   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
453   int profilesize,nbi;
454   med_geometry_type mgeoti;
455   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
456   _nval=MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,profileIt,MED_COMPACT_PFLMODE,
457                                   pflname,&profilesize,locname,&nbi);
458   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
459   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
460   _start=start;
461   _end=start+_nval*nbi;
462   start=_end;
463   if(type==ON_CELLS && !_localization.empty())
464     {
465       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
466         setType(ON_GAUSS_PT);
467       else
468         {
469           setType(ON_GAUSS_NE);
470           _localization.clear();
471         }
472     }
473 }
474
475 void MEDFileFieldPerMeshPerTypePerDisc::finishLoading(med_idt fid, int profileIt, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
476 {
477   std::string fieldName=nasc.getName();
478   std::string meshName=getMeshName();
479   int iteration=getIteration();
480   int order=getOrder();
481   TypeOfField type=getType();
482   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
483   med_geometry_type mgeoti;
484   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
485   DataArray *arr=getArray();
486   DataArrayDouble *arrD=dynamic_cast<DataArrayDouble *>(arr);
487   if(arrD)
488     {
489       double *startFeeding=arrD->getPointer()+_start*arrD->getNumberOfComponents();
490       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
491                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
492       return ;
493     }
494   DataArrayInt *arrI=dynamic_cast<DataArrayInt *>(arr);
495   if(arrI)
496     {
497       int *startFeeding=arrI->getPointer()+_start*arrI->getNumberOfComponents();
498       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
499                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
500       return ;
501     }
502   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
503 }
504
505 /*!
506  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
507  */
508 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart) throw(INTERP_KERNEL::Exception)
509 {
510   int delta=_end-_start;
511   _start=newValueOfStart;
512   _end=_start+delta;
513 }
514
515 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
516 {
517   return _father->getIteration();
518 }
519
520 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
521 {
522   return _father->getOrder();
523 }
524
525 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
526 {
527   return _father->getTime();
528 }
529
530 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
531 {
532   return _father->getMeshName();
533 }
534
535 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
536 {
537   const char startLine[]="    ## ";
538   std::string startLine2(bkOffset,' ');
539   startLine2+=startLine;
540   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
541   oss << startLine2 << "Localization #" << id << "." << std::endl;
542   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
543   delete tmp;
544   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
545   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
546   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
547 }
548
549 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
550 {
551   return _type;
552 }
553
554 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
555 {
556   types.insert(_type);
557 }
558
559 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
560 {
561   _type=newType;
562 }
563
564 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
565 {
566   return _father->getGeoType();
567 }
568
569 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
570 {
571   return _father->getNumberOfComponents();
572 }
573
574 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
575 {
576   return _end-_start;
577 }
578
579 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getArray()
580 {
581   return _father->getArray();
582 }
583
584 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getArray() const
585 {
586   const MEDFileFieldPerMeshPerType *fath=_father;
587   return fath->getArray();
588 }
589
590 DataArrayDouble *MEDFileFieldPerMeshPerTypePerDisc::getArrayDouble()
591 {
592   return _father->getArrayDouble();
593 }
594
595 const DataArrayDouble *MEDFileFieldPerMeshPerTypePerDisc::getArrayDouble() const
596 {
597   const MEDFileFieldPerMeshPerType *fath=_father;
598   return fath->getArrayDouble();
599 }
600
601 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
602 {
603   return _father->getInfo();
604 }
605
606 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
607 {
608   return _profile;
609 }
610
611 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const char *newPflName)
612 {
613   _profile=newPflName;
614 }
615
616 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
617 {
618   return _localization;
619 }
620
621 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const char *newLocName)
622 {
623   _localization=newLocName;
624 }
625
626 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
627 {
628   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
629     {
630       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
631         {
632           _profile=(*it2).second;
633           return;
634         }
635     }
636 }
637
638 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
639 {
640   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
641     {
642       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
643         {
644           _localization=(*it2).second;
645           return;
646         }
647     }
648 }
649
650 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
651 {
652   if(type!=_type)
653     return ;
654   dads.push_back(std::pair<int,int>(_start,_end));
655   geoTypes.push_back(getGeoType());
656   if(_profile.empty())
657     pfls.push_back(0);
658   else
659     {
660       pfls.push_back(glob->getProfile(_profile.c_str()));
661     }
662   if(_localization.empty())
663     locs.push_back(-1);
664   else
665     {
666       locs.push_back(glob->getLocalizationId(_localization.c_str()));
667     }
668 }
669
670 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
671 {
672   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));
673   startEntryId++;
674 }
675
676 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
677 {
678   TypeOfField type=getType();
679   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
680   med_geometry_type mgeoti;
681   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
682   const DataArray *arr=getArray();
683   if(!arr)
684     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
685   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
686   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
687   const unsigned char *locToWrite=0;
688   if(arrD)
689     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
690   else if(arrI)
691     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
692   else
693     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
694   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
695                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
696                              locToWrite);
697 }
698
699 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const throw(INTERP_KERNEL::Exception)
700 {
701   type=_type;
702   pfl=_profile;
703   loc=_localization;
704   dad.first=_start; dad.second=_end;
705 }
706
707 /*!
708  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
709  *             This code corresponds to the distribution of types in the corresponding mesh.
710  * \param [out] ptToFill memory zone where the output will be stored.
711  * \return the size of data pushed into output param \a ptToFill
712  */
713 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const throw(INTERP_KERNEL::Exception)
714 {
715   _loc_id=offset;
716   std::ostringstream oss;
717   std::size_t nbOfType=codeOfMesh.size()/3;
718   int found=-1;
719   for(std::size_t i=0;i<nbOfType && found==-1;i++)
720     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
721       found=(int)i;
722   if(found==-1)
723     {
724       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
725       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
726       throw INTERP_KERNEL::Exception(oss.str().c_str());
727     }
728   int *work=ptToFill;
729   if(_profile.empty())
730     {
731       if(_nval!=codeOfMesh[3*found+1])
732         {
733           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
734           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
735           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
736           throw INTERP_KERNEL::Exception(oss.str().c_str());
737         }
738       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
739         *work++=ii;
740     }
741   else
742     {
743       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
744       if(pfl->getNumberOfTuples()!=_nval)
745         {
746           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
747           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
748           oss << _nval;
749           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
750           throw INTERP_KERNEL::Exception(oss.str().c_str());
751         }
752       int offset2=codeOfMesh[3*found+2];
753       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
754         {
755           if(*pflId<codeOfMesh[3*found+1])
756             *work++=offset2+*pflId;
757         }
758     }
759   return _nval;
760 }
761
762 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const throw(INTERP_KERNEL::Exception)
763 {
764   for(int i=_start;i<_end;i++)
765     *ptToFill++=i;
766   return _end-_start;
767 }
768
769 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId) throw(INTERP_KERNEL::Exception)
770 {
771   switch(type)
772     {
773     case ON_CELLS:
774       return -2;
775     case ON_GAUSS_NE:
776       return -1;
777     case ON_GAUSS_PT:
778       return locId;
779     default:
780       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
781     }
782 }
783
784 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
785 {
786   int id=0;
787   std::map<std::pair<std::string,TypeOfField>,int> m;
788   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
789   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
790     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
791       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
792   ret.resize(id);
793   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
794     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
795   return ret;
796 }
797
798 /*!
799  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
800  * 
801  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
802  * \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.
803  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
804  * \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)
805  * \param [in,out] glob if necessary by the method, new profiles can be added to it
806  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
807  * \param [out] result All new entries will be appended on it.
808  * \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 !)
809  */
810 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
811                                                        const DataArrayInt *explicitIdsInMesh,
812                                                        const std::vector<int>& newCode,
813                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
814                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
815 {
816   if(entriesOnSameDisc.empty())
817     return false;
818   TypeOfField type=entriesOnSameDisc[0]->getType();
819   int szEntities=0,szTuples=0;
820   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
821     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
822   int nbi=szTuples/szEntities;
823   if(szTuples%szEntities!=0)
824     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
825   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
826   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
827   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
828   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
829   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
830   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
831   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
832   int id=0;
833   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
834     {
835       int startOfEltIdOfChunk=(*it)->_start;
836       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
837       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
838       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
839       //
840       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
841       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
842       //
843       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
844       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
845     }
846   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
847   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
848   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
849   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
850   //
851   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
852   //
853   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
854   arrPart->renumberInPlace(renumTupleIds->begin());
855   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
856   bool ret=false;
857   const int *idIt=diffVals->begin();
858   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
859   int offset2=0;
860   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
861     {
862       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
863       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
864       int nbEntityElts=subIds->getNumberOfTuples();
865       bool ret2;
866       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
867         NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
868                                     offset+offset2,
869                                     li,glob,ret2);
870       ret=ret || ret2;
871       result.push_back(eltToAdd);
872       offset2+=nbEntityElts*nbi;
873     }
874   ret=ret || li.empty();
875   return ret;
876 }
877
878 /*!
879  * \param [in] typeF type of field of new chunk
880  * \param [in] geoType the geometric type of the chunk
881  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
882  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
883  * \param [in] nbi number of integration points
884  * \param [in] offset The offset in the **global array of data**.
885  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
886  *                 to the new chunk to create.
887  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
888  * \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
889  *              and corresponding entry erased from \a entriesOnSameDisc.
890  * \return a newly allocated chunk
891  */
892 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
893                                                                                                   bool isPfl, int nbi, int offset,
894                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
895                                                                                                   MEDFileFieldGlobsReal& glob,
896                                                                                                   bool &notInExisting) throw(INTERP_KERNEL::Exception)
897 {
898   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
899   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
900   for(;it!=entriesOnSameDisc.end();it++)
901     {
902       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
903         {
904           if(!isPfl)
905             {
906               if((*it)->_profile.empty())
907                 break;
908               else
909                 if(!(*it)->_profile.empty())
910                   {
911                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
912                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
913                       break;
914                   }
915             }
916         }
917     }
918   if(it==entriesOnSameDisc.end())
919     {
920       notInExisting=true;
921       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
922       ret->_type=typeF;
923       ret->_loc_id=(int)geoType;
924       ret->_nval=nbMeshEntities;
925       ret->_start=offset;
926       ret->_end=ret->_start+ret->_nval*nbi;
927       if(isPfl)
928         {
929           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
930           glob.appendProfile(idsOfMeshElt);
931           ret->_profile=idsOfMeshElt->getName();
932         }
933       //tony treatment of localization
934       return ret;
935     }
936   else
937     {
938       notInExisting=false;
939       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
940       ret->_loc_id=(int)geoType;
941       ret->setNewStart(offset);
942       entriesOnSameDisc.erase(it);
943       return ret;
944     }
945   
946 }
947
948 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
949 {
950   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc);
951 }
952
953 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
954 {
955   return new MEDFileFieldPerMeshPerType(fath,geoType);
956 }
957
958 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySize() const
959 {
960   std::size_t ret=_field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
961   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
962     ret+=(*it)->getHeapMemorySize();
963   return ret;
964 }
965
966 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const throw(INTERP_KERNEL::Exception)
967 {
968   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
969   ret->_father=father;
970   std::size_t i=0;
971   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
972     {
973       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
974         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
975     }
976   return ret.retn();
977 }
978
979 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
980 {
981   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
982   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
983     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
984 }
985
986 /*!
987  * This method is the most general one. No optimization is done here.
988  * \param [in] multiTypePfl is the end user profile specified in high level API
989  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
990  * \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.
991  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
992  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
993  * \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.
994  */
995 void MEDFileFieldPerMeshPerType::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
996 {
997   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
998   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
999     _field_pm_pt_pd[*it]->assignFieldProfile(start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1000 }
1001
1002 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1003 {
1004   _field_pm_pt_pd.resize(1);
1005   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1006   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1007 }
1008
1009 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1010 {
1011   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1012   //
1013   _field_pm_pt_pd.resize(1);
1014   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1015   _field_pm_pt_pd[0]->assignFieldProfile(start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1016 }
1017
1018 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
1019 {
1020   TypeOfField type=field->getTypeOfField();
1021   if(type!=ON_GAUSS_PT)
1022     {
1023       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1024       int sz=_field_pm_pt_pd.size();
1025       bool found=false;
1026       for(int j=0;j<sz && !found;j++)
1027         {
1028           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1029             {
1030               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1031               found=true;
1032             }
1033         }
1034       if(!found)
1035         {
1036           _field_pm_pt_pd.resize(sz+1);
1037           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1038         }
1039       std::vector<int> ret(1,0);
1040       return ret;
1041     }
1042   else
1043     {
1044       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1045       int sz2=ret2.size();
1046       std::vector<int> ret3(sz2);
1047       int k=0;
1048       for(int i=0;i<sz2;i++)
1049         {
1050           int sz=_field_pm_pt_pd.size();
1051           int locIdToFind=ret2[i];
1052           bool found=false;
1053           for(int j=0;j<sz && !found;j++)
1054             {
1055               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1056                 {
1057                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1058                   ret3[k++]=j;
1059                   found=true;
1060                 }
1061             }
1062           if(!found)
1063             {
1064               _field_pm_pt_pd.resize(sz+1);
1065               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1066               ret3[k++]=sz;
1067             }
1068         }
1069       return ret3;
1070     }
1071 }
1072
1073 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
1074 {
1075   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1076   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1077   if(!disc2)
1078     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1079   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1080   if(!da)
1081     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1082   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1083   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1084   if(retTmp->presenceOfValue(-1))
1085     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1086   std::vector<int> ret(retTmp->begin(),retTmp->end());
1087   return ret;
1088 }
1089
1090 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1091 {
1092   TypeOfField type=field->getTypeOfField();
1093   if(type!=ON_GAUSS_PT)
1094     {
1095       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1096       int sz=_field_pm_pt_pd.size();
1097       bool found=false;
1098       for(int j=0;j<sz && !found;j++)
1099         {
1100           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1101             {
1102               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1103               found=true;
1104             }
1105         }
1106       if(!found)
1107         {
1108           _field_pm_pt_pd.resize(sz+1);
1109           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1110         }
1111       std::vector<int> ret(1,0);
1112       return ret;
1113     }
1114   else
1115     {
1116       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1117       int sz2=ret2.size();
1118       std::vector<int> ret3(sz2);
1119       int k=0;
1120       for(int i=0;i<sz2;i++)
1121         {
1122           int sz=_field_pm_pt_pd.size();
1123           int locIdToFind=ret2[i];
1124           bool found=false;
1125           for(int j=0;j<sz && !found;j++)
1126             {
1127               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1128                 {
1129                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1130                   ret3[k++]=j;
1131                   found=true;
1132                 }
1133             }
1134           if(!found)
1135             {
1136               _field_pm_pt_pd.resize(sz+1);
1137               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1138               ret3[k++]=sz;
1139             }
1140         }
1141       return ret3;
1142     }
1143 }
1144
1145 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1146 {
1147   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1148   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1149   if(!disc2)
1150     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1151   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1152   if(!da)
1153     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1154   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1155   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1156   if(retTmp->presenceOfValue(-1))
1157     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1158   std::vector<int> ret(retTmp->begin(),retTmp->end());
1159   return ret;
1160 }
1161
1162 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1163 {
1164   return _father;
1165 }
1166
1167 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1168 {
1169   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1170   int curDim=(int)cm.getDimension();
1171   dim=std::max(dim,curDim);
1172 }
1173
1174 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1175 {
1176   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1177     {
1178       (*it)->fillTypesOfFieldAvailable(types);
1179     }
1180 }
1181
1182 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)
1183 {
1184   int sz=_field_pm_pt_pd.size();
1185   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1186   for(int i=0;i<sz;i++)
1187     {
1188       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1189     }
1190 }
1191
1192 int MEDFileFieldPerMeshPerType::getIteration() const
1193 {
1194   return _father->getIteration();
1195 }
1196
1197 int MEDFileFieldPerMeshPerType::getOrder() const
1198 {
1199   return _father->getOrder();
1200 }
1201
1202 double MEDFileFieldPerMeshPerType::getTime() const
1203 {
1204   return _father->getTime();
1205 }
1206
1207 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1208 {
1209   return _father->getMeshName();
1210 }
1211
1212 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1213 {
1214   const char startLine[]="  ## ";
1215   std::string startLine2(bkOffset,' ');
1216   std::string startLine3(startLine2);
1217   startLine3+=startLine;
1218   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1219     {
1220       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1221       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1222     }
1223   else
1224     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1225   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1226   int i=0;
1227   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1228     {
1229       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1230       if(cur)
1231         cur->simpleRepr(bkOffset,oss,i);
1232       else
1233         {
1234           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1235         }
1236     }
1237 }
1238
1239 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1240 {
1241   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1242     {
1243       globalSz+=(*it)->getNumberOfTuples();
1244     }
1245   nbOfEntries+=(int)_field_pm_pt_pd.size();
1246 }
1247
1248 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1249 {
1250   return _geo_type;
1251 }
1252
1253
1254 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1255 {
1256   return _father->getNumberOfComponents();
1257 }
1258
1259 DataArray *MEDFileFieldPerMeshPerType::getArray()
1260 {
1261   return _father->getArray();
1262 }
1263
1264 const DataArray *MEDFileFieldPerMeshPerType::getArray() const
1265 {
1266   const MEDFileFieldPerMesh *fath=_father;
1267   return fath->getArray();
1268 }
1269
1270 DataArrayDouble *MEDFileFieldPerMeshPerType::getArrayDouble()
1271 {
1272   return _father->getArrayDouble();
1273 }
1274
1275 const DataArrayDouble *MEDFileFieldPerMeshPerType::getArrayDouble() const
1276 {
1277   const MEDFileFieldPerMesh *fath=_father;
1278   return fath->getArrayDouble();
1279 }
1280
1281 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1282 {
1283   return _father->getInfo();
1284 }
1285
1286 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1287 {
1288   std::vector<std::string> ret;
1289   std::set<std::string> ret2;
1290   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1291     {
1292       std::string tmp=(*it1)->getProfile();
1293       if(!tmp.empty())
1294         if(ret2.find(tmp)==ret2.end())
1295           {
1296             ret.push_back(tmp);
1297             ret2.insert(tmp);
1298           }
1299     }
1300   return ret;
1301 }
1302
1303 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1304 {
1305   std::vector<std::string> ret;
1306   std::set<std::string> ret2;
1307   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1308     {
1309       std::string tmp=(*it1)->getLocalization();
1310       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1311         if(ret2.find(tmp)==ret2.end())
1312           {
1313             ret.push_back(tmp);
1314             ret2.insert(tmp);
1315           }
1316     }
1317   return ret;
1318 }
1319
1320 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1321 {
1322   std::vector<std::string> ret;
1323   std::set<std::string> ret2;
1324   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1325     {
1326       std::string tmp=(*it1)->getProfile();
1327       if(!tmp.empty())
1328         ret.push_back(tmp);
1329     }
1330   return ret;
1331 }
1332
1333 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1334 {
1335   std::vector<std::string> ret;
1336   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1337     {
1338       std::string tmp=(*it1)->getLocalization();
1339       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1340         ret.push_back(tmp);
1341     }
1342   return ret;
1343 }
1344
1345 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1346 {
1347   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1348     (*it1)->changePflsRefsNamesGen(mapOfModif);
1349 }
1350
1351 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1352 {
1353   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1354     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1355 }
1356
1357 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) throw(INTERP_KERNEL::Exception)
1358 {
1359   if(_field_pm_pt_pd.empty())
1360     {
1361       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1362       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1363       throw INTERP_KERNEL::Exception(oss.str().c_str());
1364     }
1365   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1366     return _field_pm_pt_pd[locId];
1367   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1368   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1369   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1370   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1371   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1372 }
1373
1374 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const throw(INTERP_KERNEL::Exception)
1375 {
1376   if(_field_pm_pt_pd.empty())
1377     {
1378       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1379       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1380       throw INTERP_KERNEL::Exception(oss.str().c_str());
1381     }
1382   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1383     return _field_pm_pt_pd[locId];
1384   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1385   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1386   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1387   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1388   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1389 }
1390
1391 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
1392 {
1393   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1394     {
1395       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1396       if(meshDim!=(int)cm.getDimension())
1397         return ;
1398     }
1399   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1400     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1401 }
1402
1403 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1404 {
1405   int i=0;
1406   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1407     {
1408       (*it)->fillValues(i,startEntryId,entries);
1409     }
1410 }
1411
1412 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1413 {
1414   _field_pm_pt_pd=leaves;
1415   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1416     (*it)->setFather(this);
1417 }
1418
1419 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType)
1420 {
1421 }
1422
1423 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType)
1424 {
1425   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1426   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1427   med_geometry_type mgeoti;
1428   med_entity_type menti=ConvertIntoMEDFileType(type,geoType,mgeoti);
1429   int nbProfiles=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName);
1430   _field_pm_pt_pd.resize(nbProfiles);
1431   for(int i=0;i<nbProfiles;i++)
1432     {
1433       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i+1);
1434     }
1435 }
1436
1437 void MEDFileFieldPerMeshPerType::prepareLoading(med_idt fid, int &start, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1438 {
1439   int pflId=0;
1440   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1441     {
1442       (*it)->prepareLoading(fid,pflId+1,start,nasc);//tony
1443     }
1444 }
1445
1446 void MEDFileFieldPerMeshPerType::finishLoading(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1447 {
1448   int pflId=0;
1449   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1450     {
1451       (*it)->finishLoading(fid,pflId+1,nasc);//tony
1452     }
1453 }
1454
1455 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
1456 {
1457   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1458     {
1459       (*it)->copyOptionsFrom(*this);
1460       (*it)->writeLL(fid,nasc);
1461     }
1462 }
1463
1464 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1465 {
1466   switch(ikType)
1467     {
1468     case ON_CELLS:
1469       medfGeoType=typmai3[(int)ikGeoType];
1470       return MED_CELL;
1471     case ON_NODES:
1472       medfGeoType=MED_NONE;
1473       return MED_NODE;
1474     case ON_GAUSS_NE:
1475       medfGeoType=typmai3[(int)ikGeoType];
1476       return MED_NODE_ELEMENT;
1477     case ON_GAUSS_PT:
1478       medfGeoType=typmai3[(int)ikGeoType];
1479       return MED_CELL;
1480     default:
1481       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1482     }
1483   return MED_UNDEF_ENTITY_TYPE;
1484 }
1485
1486 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1487 {
1488   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc);
1489 }
1490
1491 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1492 {
1493   return new MEDFileFieldPerMesh(fath,mesh);
1494 }
1495
1496 std::size_t MEDFileFieldPerMesh::getHeapMemorySize() const
1497 {
1498   std::size_t ret=_mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1499   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1500     if((const MEDFileFieldPerMeshPerType *)*it)
1501       ret+=(*it)->getHeapMemorySize();
1502   return ret;
1503 }
1504
1505 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const throw(INTERP_KERNEL::Exception)
1506 {
1507   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1508   ret->_father=father;
1509   std::size_t i=0;
1510   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1511     {
1512       if((const MEDFileFieldPerMeshPerType *)*it)
1513         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1514     }
1515   return ret.retn();
1516 }
1517
1518 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1519 {
1520   std::string startLine(bkOffset,' ');
1521   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1522   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1523   int i=0;
1524   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1525     {
1526       const MEDFileFieldPerMeshPerType *cur=*it;
1527       if(cur)
1528         cur->simpleRepr(bkOffset,oss,i);
1529       else
1530         {
1531           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1532         }
1533     }
1534 }
1535
1536 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
1537 {
1538   _mesh_name=mesh->getName();
1539   mesh->getTime(_mesh_iteration,_mesh_order);
1540 }
1541
1542 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1543 {
1544   int nbOfTypes=code.size()/3;
1545   int offset=0;
1546   for(int i=0;i<nbOfTypes;i++)
1547     {
1548       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1549       int nbOfCells=code[3*i+1];
1550       int pos=addNewEntryIfNecessary(type);
1551       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1552       offset+=nbOfCells;
1553     }
1554 }
1555
1556 /*!
1557  * This method is the most general one. No optimization is done here.
1558  * \param [in] multiTypePfl is the end user profile specified in high level API
1559  * \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].
1560  * \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.
1561  * \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.
1562  * \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.
1563  * \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.
1564  */
1565 void MEDFileFieldPerMesh::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector<int>& code, const std::vector<int>& code2, const std::vector<DataArrayInt *>& idsInPflPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1566 {
1567   int nbOfTypes=code.size()/3;
1568   for(int i=0;i<nbOfTypes;i++)
1569     {
1570       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1571       int pos=addNewEntryIfNecessary(type);
1572       DataArrayInt *pfl=0;
1573       if(code[3*i+2]!=-1)
1574         pfl=idsPerType[code[3*i+2]];
1575       int nbOfTupes2=code2.size()/3;
1576       int found=0;
1577       for(;found<nbOfTupes2;found++)
1578         if(code[3*i]==code2[3*found])
1579           break;
1580       if(found==nbOfTupes2)
1581         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1582       _field_pm_pt[pos]->assignFieldProfile(start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1583     }
1584 }
1585
1586 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1587 {
1588   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1589   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1590 }
1591
1592 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1593 {
1594   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1595   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1596 }
1597
1598 void MEDFileFieldPerMesh::prepareLoading(med_idt fid, int& start, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1599 {
1600   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1601     (*it)->prepareLoading(fid,start,nasc);
1602 }
1603
1604 void MEDFileFieldPerMesh::finishLoading(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1605 {
1606   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1607     (*it)->finishLoading(fid,nasc);
1608 }
1609
1610 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
1611 {
1612   int nbOfTypes=_field_pm_pt.size();
1613   for(int i=0;i<nbOfTypes;i++)
1614     {
1615       _field_pm_pt[i]->copyOptionsFrom(*this);
1616       _field_pm_pt[i]->writeLL(fid,nasc);
1617     }
1618 }
1619
1620 void MEDFileFieldPerMesh::getDimension(int& dim) const
1621 {
1622   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1623     (*it)->getDimension(dim);
1624 }
1625
1626 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1627 {
1628   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1629     (*it)->fillTypesOfFieldAvailable(types);
1630 }
1631
1632 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)
1633 {
1634   int sz=_field_pm_pt.size();
1635   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1636   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1637   for(int i=0;i<sz;i++)
1638     {
1639       types[i]=_field_pm_pt[i]->getGeoType();
1640       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1641     }
1642   return ret;
1643 }
1644
1645 double MEDFileFieldPerMesh::getTime() const
1646 {
1647   int tmp1,tmp2;
1648   return _father->getTime(tmp1,tmp2);
1649 }
1650
1651 int MEDFileFieldPerMesh::getIteration() const
1652 {
1653   return _father->getIteration();
1654 }
1655
1656 int MEDFileFieldPerMesh::getOrder() const
1657 {
1658   return _father->getOrder();
1659 }
1660
1661 int MEDFileFieldPerMesh::getNumberOfComponents() const
1662 {
1663   return _father->getNumberOfComponents();
1664 }
1665
1666 DataArray *MEDFileFieldPerMesh::getArray()
1667 {
1668   if(!_father)
1669     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getArray : no father ! internal error !");
1670   return _father->getOrCreateAndGetArray();
1671 }
1672
1673 const DataArray *MEDFileFieldPerMesh::getArray() const
1674 {
1675   if(!_father)
1676     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getArray : no father ! internal error !");
1677   return _father->getOrCreateAndGetArray();
1678 }
1679
1680 DataArrayDouble *MEDFileFieldPerMesh::getArrayDouble()
1681 {
1682   MEDFileField1TSWithoutSDA *fatherC=dynamic_cast<MEDFileField1TSWithoutSDA *>(_father);
1683   if(!fatherC)
1684     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getArrayDouble : Expected to be called on double array !");
1685   return fatherC->getOrCreateAndGetArrayDouble();
1686 }
1687
1688 const DataArrayDouble *MEDFileFieldPerMesh::getArrayDouble() const
1689 {
1690   const MEDFileField1TSWithoutSDA *fatherC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(_father);
1691   if(!fatherC)
1692     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getArrayDouble : Expected to be called on double array !");
1693   return fatherC->getOrCreateAndGetArrayDouble();
1694 }
1695
1696 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1697 {
1698   return _father->getInfo();
1699 }
1700
1701 /*!
1702  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1703  * 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.
1704  * It returns 2 output vectors :
1705  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1706  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1707  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1708  */
1709 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)
1710 {
1711   int notNullPflsSz=0;
1712   int nbOfArrs=geoTypes.size();
1713   for(int i=0;i<nbOfArrs;i++)
1714     if(pfls[i])
1715       notNullPflsSz++;
1716   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1717   int nbOfDiffGeoTypes=geoTypes3.size();
1718   code.resize(3*nbOfDiffGeoTypes);
1719   notNullPfls.resize(notNullPflsSz);
1720   notNullPflsSz=0;
1721   int j=0;
1722   for(int i=0;i<nbOfDiffGeoTypes;i++)
1723     {
1724       int startZone=j;
1725       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1726       std::vector<const DataArrayInt *> notNullTmp;
1727       if(pfls[j])
1728         notNullTmp.push_back(pfls[j]);
1729       j++;
1730       for(;j<nbOfArrs;j++)
1731         if(geoTypes[j]==refType)
1732           {
1733             if(pfls[j])
1734               notNullTmp.push_back(pfls[j]);
1735           }
1736         else
1737           break;
1738       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1739       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1740       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1741       code[3*i]=(int)refType;
1742       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1743       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1744       if(notNullTmp.empty())
1745         code[3*i+2]=-1;
1746       else
1747         {
1748           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1749           code[3*i+2]=notNullPflsSz++;
1750         }
1751     }
1752 }
1753
1754 /*!
1755  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1756  */
1757 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)
1758 {
1759   int sz=dads.size();
1760   int ret=0;
1761   for(int i=0;i<sz;i++)
1762     {
1763       if(locs[i]==-1)
1764         {
1765           if(type!=ON_GAUSS_NE)
1766             ret+=dads[i].second-dads[i].first;
1767           else
1768             {
1769               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1770               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1771             }
1772         }
1773       else
1774         {
1775           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1776           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1777         }
1778     }
1779   return ret;
1780 }
1781
1782 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1783 {
1784   std::vector<std::string> ret;
1785   std::set<std::string> ret2;
1786   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1787     {
1788       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1789       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1790         if(ret2.find(*it2)==ret2.end())
1791           {
1792             ret.push_back(*it2);
1793             ret2.insert(*it2);
1794           }
1795     }
1796   return ret;
1797 }
1798
1799 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1800 {
1801   std::vector<std::string> ret;
1802   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1803     {
1804       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1805       ret.insert(ret.end(),tmp.begin(),tmp.end());
1806     }
1807   return ret;
1808 }
1809
1810 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1811 {
1812   std::vector<std::string> ret;
1813   std::set<std::string> ret2;
1814   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1815     {
1816       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1817       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1818         if(ret2.find(*it2)==ret2.end())
1819           {
1820             ret.push_back(*it2);
1821             ret2.insert(*it2);
1822           }
1823     }
1824   return ret;
1825 }
1826
1827 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1828 {
1829   std::vector<std::string> ret;
1830   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1831     {
1832       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1833       ret.insert(ret.end(),tmp.begin(),tmp.end());
1834     }
1835   return ret;
1836 }
1837
1838 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
1839 {
1840   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1841     {
1842       if((*it).first==_mesh_name)
1843         {
1844           _mesh_name=(*it).second;
1845           return true;
1846         }
1847     }
1848   return false;
1849 }
1850
1851 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1852                                                       MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1853 {
1854   if(_mesh_name!=meshName)
1855     return false;
1856   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1857   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1858   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1859   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1860   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1861   getUndergroundDataArrayExt(entries);
1862   DataArrayDouble *arr=getArrayDouble();
1863   int sz=0;
1864   if(!arr)
1865     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1866   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1867     {
1868       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1869         {
1870           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1871           sz+=(*it).second.second-(*it).second.first;
1872         }
1873       else
1874         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1875     }
1876   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1877   ////////////////////
1878   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1879   int *workI2=explicitIdsOldInMesh->getPointer();
1880   int sz1=0,sz2=0,sid=1;
1881   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1882   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1883   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1884     {
1885       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1886       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1887       int *workI=explicitIdsOldInArr->getPointer();
1888       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1889         {
1890           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1891           (*itL2)->setLocId(sz2);
1892           (*itL2)->_tmp_work1=(*itL2)->getStart();
1893           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1894         }
1895       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1896     }
1897   explicitIdsOldInMesh->reAlloc(sz2);
1898   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1899   ////////////////////
1900   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1901   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1902   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1903   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1904     {
1905       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1906       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1907       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1908     }
1909   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1910   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1911   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
1912     {
1913       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1914       int newStart=elt->getLocId();
1915       elt->setLocId((*it)->getGeoType());
1916       elt->setNewStart(newStart);
1917       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
1918       entriesKeptNew.push_back(elt);
1919       entriesKeptNew2.push_back(elt);
1920     }
1921   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
1922   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
1923   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
1924   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
1925   bool ret=false;
1926   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
1927     {
1928       sid=0;
1929       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
1930         {
1931           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
1932           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
1933           }*/
1934       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
1935                                                             glob,arr2,otherEntriesNew) || ret;
1936     }
1937   if(!ret)
1938     return false;
1939   // Assign new dispatching
1940   assignNewLeaves(otherEntriesNew);
1941   arr->cpyFrom(*arr2);
1942   return true;
1943 }
1944
1945 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1946 {
1947   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
1948   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
1949     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
1950   //
1951   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
1952   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
1953   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
1954   for(;it1!=types.end();it1++,it2++)
1955     {
1956       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
1957       elt->setLeaves((*it1).second);
1958       *it2=elt;
1959     }
1960   _field_pm_pt=fieldPmPt;
1961 }
1962
1963 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1964 {
1965   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1966     (*it)->changePflsRefsNamesGen(mapOfModif);
1967 }
1968
1969 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1970 {
1971   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1972     (*it)->changeLocsRefsNamesGen(mapOfModif);
1973 }
1974
1975 /*!
1976  * \param [in] mesh is the whole mesh
1977  */
1978 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
1979 {
1980   if(_field_pm_pt.empty())
1981     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
1982   //
1983   std::vector< std::pair<int,int> > dads;
1984   std::vector<const DataArrayInt *> pfls;
1985   std::vector<DataArrayInt *> notNullPflsPerGeoType;
1986   std::vector<int> locs,code;
1987   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
1988   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1989     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
1990   // Sort by types
1991   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
1992   if(code.empty())
1993     {
1994       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
1995       throw INTERP_KERNEL::Exception(oss.str().c_str());
1996     }
1997   //
1998   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
1999   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2000   if(type!=ON_NODES)
2001     {
2002       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2003       if(!arr)
2004         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2005       else
2006         {
2007           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2008           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2009         }
2010     }
2011   else
2012     {
2013       if(code.size()!=3)
2014         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2015       int nb=code[1];
2016       if(code[2]==-1)
2017         {
2018           if(nb!=mesh->getNumberOfNodes())
2019             {
2020               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2021               oss << " nodes in mesh !";
2022               throw INTERP_KERNEL::Exception(oss.str().c_str());
2023             }
2024           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2025         }
2026       else
2027         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2028     }
2029 }
2030
2031 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2032 {
2033   if(_field_pm_pt.empty())
2034     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2035   //
2036   std::vector<std::pair<int,int> > dads;
2037   std::vector<const DataArrayInt *> pfls;
2038   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2039   std::vector<int> locs,code;
2040   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2041   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2042     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2043   // Sort by types
2044   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2045   if(code.empty())
2046     {
2047       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2048       throw INTERP_KERNEL::Exception(oss.str().c_str());
2049     }
2050   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2051   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2052   if(type!=ON_NODES)
2053     {
2054       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2055       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2056     }
2057   else
2058     {
2059       if(code.size()!=3)
2060         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2061       int nb=code[1];
2062       if(code[2]==-1)
2063         {
2064           if(nb!=mesh->getNumberOfNodes())
2065             {
2066               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2067               oss << " nodes in mesh !";
2068               throw INTERP_KERNEL::Exception(oss.str().c_str());
2069             }
2070         }
2071       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2072     }
2073   //
2074   return 0;
2075 }
2076
2077 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
2078 {
2079   int globalSz=0;
2080   int nbOfEntries=0;
2081   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2082     {
2083       (*it)->getSizes(globalSz,nbOfEntries);
2084     }
2085   entries.resize(nbOfEntries);
2086   nbOfEntries=0;
2087   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2088     {
2089       (*it)->fillValues(nbOfEntries,entries);
2090     }
2091 }
2092
2093 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
2094 {
2095   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2096     {
2097       if((*it)->getGeoType()==typ)
2098         return (*it)->getLeafGivenLocId(locId);
2099     }
2100   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2101   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2102   oss << "Possiblities are : ";
2103   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2104     {
2105       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2106       oss << "\"" << cm2.getRepr() << "\", ";
2107     }
2108   throw INTERP_KERNEL::Exception(oss.str().c_str());
2109 }
2110
2111 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
2112 {
2113   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2114     {
2115       if((*it)->getGeoType()==typ)
2116         return (*it)->getLeafGivenLocId(locId);
2117     }
2118   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2119   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2120   oss << "Possiblities are : ";
2121   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2122     {
2123       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2124       oss << "\"" << cm2.getRepr() << "\", ";
2125     }
2126   throw INTERP_KERNEL::Exception(oss.str().c_str());
2127 }
2128
2129 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2130 {
2131   int i=0;
2132   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2133   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2134   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2135     {
2136       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2137       if(type==curType)
2138         return i;
2139       else
2140         {
2141           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2142           if(pos>pos2)
2143             it2=it+1;
2144         }
2145     }
2146   int ret=std::distance(_field_pm_pt.begin(),it2);
2147   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2148   return ret;
2149 }
2150
2151 /*!
2152  * 'dads' and 'locs' input parameters have the same number of elements
2153  * \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
2154  */
2155 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2156                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2157                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2158 {
2159   isPfl=false;
2160   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2161   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2162   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getArray()->selectByTupleRanges(dads);
2163   const std::vector<std::string>& infos=getInfo();
2164   da->setInfoOnComponents(infos);
2165   da->setName("");
2166   if(type==ON_GAUSS_PT)
2167     {
2168       int offset=0;
2169       int nbOfArrs=dads.size();
2170       for(int i=0;i<nbOfArrs;i++)
2171         {
2172           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2173           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2174           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2175           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2176           di->alloc(nbOfElems,1);
2177           di->iota(offset);
2178           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2179           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2180           offset+=nbOfElems;
2181         }
2182     }
2183   arrOut=da;
2184   return ret.retn();
2185 }
2186
2187 /*!
2188  * 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.
2189  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2190  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2191  * The order of cells in the returned field is those imposed by the profile.
2192  * \param [in] mesh is the global mesh.
2193  */
2194 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2195                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2196                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2197                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2198 {
2199   if(da->isIdentity())
2200     {
2201       int nbOfTuples=da->getNumberOfTuples();
2202       if(nbOfTuples==mesh->getNumberOfCells())
2203         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2204     }
2205   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2206   m2->setName(mesh->getName());
2207   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2208   isPfl=true;
2209   return ret.retn();
2210 }
2211
2212 /*!
2213  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2214  */
2215 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2216                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2217                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2218 {
2219   if(da->isIdentity())
2220     {
2221       int nbOfTuples=da->getNumberOfTuples();
2222       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2223         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2224     }
2225   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2226   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2227   if(meshu)
2228     {
2229       if(meshu->getNodalConnectivity()==0)
2230         {
2231           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2232           int nb=da->getNbOfElems();
2233           const int *ptr=da->getConstPointer();
2234           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2235           meshuc->allocateCells(nb);
2236           for(int i=0;i<nb;i++)
2237             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2238           meshuc->finishInsertingCells();
2239           ret->setMesh(meshuc);
2240           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2241           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2242           disc->checkCoherencyBetween(meshuc,arrOut);
2243           return ret.retn();
2244         }
2245     }
2246   //
2247   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2248   isPfl=true;
2249   DataArrayInt *arr2=0;
2250   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2251   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2252   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2253   int nnodes=mesh2->getNumberOfNodes();
2254   if(nnodes==(int)da->getNbOfElems())
2255     {
2256       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2257       arrOut->renumberInPlace(da3->getConstPointer());
2258       mesh2->setName(mesh->getName());
2259       ret->setMesh(mesh2);
2260       return ret.retn();
2261     }
2262   else
2263     {
2264       std::ostringstream oss; oss << "MEDFileFieldPerMesh::finishFieldNode2 : The field on nodes lies on a node profile so that it is impossible to find a submesh having exactly the same nodes of that profile !!!";
2265       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2266       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2267       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2268       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2269       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2270       throw INTERP_KERNEL::Exception(oss.str().c_str());
2271     }
2272   return 0;
2273 }
2274
2275 /*!
2276  * This method is the most light method of field retrieving.
2277  */
2278 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const throw(INTERP_KERNEL::Exception)
2279 {
2280   if(!pflIn)
2281     {
2282       pflOut=DataArrayInt::New();
2283       pflOut->alloc(nbOfElems,1);
2284       pflOut->iota(0);
2285     }
2286   else
2287     {
2288       pflOut=const_cast<DataArrayInt*>(pflIn);
2289       pflOut->incrRef();
2290     }
2291   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2292   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getArray()->selectByTupleRanges(dads);
2293   const std::vector<std::string>& infos=getInfo();
2294   int nbOfComp=infos.size();
2295   for(int i=0;i<nbOfComp;i++)
2296     da->setInfoOnComponent(i,infos[i].c_str());
2297   safePfl->incrRef();
2298   return da.retn();
2299 }
2300
2301 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2302                                                                                                                                                                                                                  _mesh_csit(meshCsit),_father(fath)
2303 {
2304   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2305   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2306   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2307   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2308     {
2309       int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL,typmai[i],_mesh_csit,meshName,pflName,locName);
2310       if(nbProfile>0)
2311         {
2312           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i],nasc));
2313           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2314         }
2315       nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],_mesh_csit,meshName,pflName,locName);
2316       if(nbProfile>0)
2317         {
2318           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_GAUSS_NE,typmai2[i],nasc));
2319           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2320         }
2321     }
2322   int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,_mesh_csit,meshName,pflName,locName);
2323   if(nbProfile>0)
2324     {
2325       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc));
2326       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2327     }
2328 }
2329
2330 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2331 {
2332   copyTinyInfoFrom(mesh);
2333 }
2334
2335 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
2336 {
2337   if(id>=(int)_pfls.size())
2338     _pfls.resize(id+1);
2339   _pfls[id]=DataArrayInt::New();
2340   int lgth=MEDprofileSizeByName(fid,pflName);
2341   _pfls[id]->setName(pflName);
2342   _pfls[id]->alloc(lgth,1);
2343   MEDprofileRd(fid,pflName,_pfls[id]->getPointer());
2344   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2345 }
2346
2347 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2348 {
2349   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2350   int sz;
2351   MEDprofileInfo(fid,i+1,pflName,&sz);
2352   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2353   if(i>=(int)_pfls.size())
2354     _pfls.resize(i+1);
2355   _pfls[i]=DataArrayInt::New();
2356   _pfls[i]->alloc(sz,1);
2357   _pfls[i]->setName(pflCpp.c_str());
2358   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2359   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2360 }
2361
2362 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
2363 {
2364   int nbOfPfls=_pfls.size();
2365   for(int i=0;i<nbOfPfls;i++)
2366     {
2367       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2368       cpy->applyLin(1,1,0);
2369       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2370       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2371       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2372     }
2373   //
2374   int nbOfLocs=_locs.size();
2375   for(int i=0;i<nbOfLocs;i++)
2376     _locs[i]->writeLL(fid);
2377 }
2378
2379 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps) throw(INTERP_KERNEL::Exception)
2380 {
2381   std::vector<std::string> pfls=getPfls();
2382   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2383     {
2384       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2385       if(it2==pfls.end())
2386         {
2387           _pfls.push_back(*it);
2388         }
2389       else
2390         {
2391           int id=std::distance(pfls.begin(),it2);
2392           if(!(*it)->isEqual(*_pfls[id]))
2393             {
2394               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2395               throw INTERP_KERNEL::Exception(oss.str().c_str());
2396             }
2397         }
2398     }
2399   std::vector<std::string> locs=getLocs();
2400   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2401     {
2402       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2403       if(it2==locs.end())
2404         {
2405           _locs.push_back(*it);
2406         }
2407       else
2408         {
2409           int id=std::distance(locs.begin(),it2);
2410           if(!(*it)->isEqual(*_locs[id],eps))
2411             {
2412               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2413               throw INTERP_KERNEL::Exception(oss.str().c_str());
2414             }
2415         }
2416     }
2417 }
2418
2419 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const throw(INTERP_KERNEL::Exception)
2420 {
2421   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2422     getProfile((*it).c_str());
2423 }
2424
2425 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const throw(INTERP_KERNEL::Exception)
2426 {
2427   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2428     getLocalization((*it).c_str());
2429 }
2430
2431 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real) throw(INTERP_KERNEL::Exception)
2432 {
2433   std::vector<std::string> profiles=real.getPflsReallyUsed();
2434   int sz=profiles.size();
2435   _pfls.resize(sz);
2436   for(int i=0;i<sz;i++)
2437     loadProfileInFile(fid,i,profiles[i].c_str());
2438   //
2439   std::vector<std::string> locs=real.getLocsReallyUsed();
2440   sz=locs.size();
2441   _locs.resize(sz);
2442   for(int i=0;i<sz;i++)
2443     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2444 }
2445
2446 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2447 {
2448   int nProfil=MEDnProfile(fid);
2449   for(int i=0;i<nProfil;i++)
2450     loadProfileInFile(fid,i);
2451   int sz=MEDnLocalization(fid);
2452   _locs.resize(sz);
2453   for(int i=0;i<sz;i++)
2454     {
2455       _locs[i]=MEDFileFieldLoc::New(fid,i);
2456     }
2457 }
2458
2459 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const char *fname)
2460 {
2461   return new MEDFileFieldGlobs(fname);
2462 }
2463
2464 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2465 {
2466   return new MEDFileFieldGlobs;
2467 }
2468
2469 std::size_t MEDFileFieldGlobs::getHeapMemorySize() const
2470 {
2471   std::size_t ret=_file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2472   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2473     ret+=(*it)->getHeapMemorySize();
2474   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2475     ret+=(*it)->getHeapMemorySize();
2476   return ret;
2477 }
2478
2479 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const throw(INTERP_KERNEL::Exception)
2480 {
2481   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2482   std::size_t i=0;
2483   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2484     {
2485       if((const DataArrayInt *)*it)
2486         ret->_pfls[i]=(*it)->deepCpy();
2487     }
2488   i=0;
2489   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2490     {
2491       if((const MEDFileFieldLoc*)*it)
2492         ret->_locs[i]=(*it)->deepCpy();
2493     }
2494   return ret.retn();
2495 }
2496
2497 /*!
2498  * \throw if a profile in \a pfls in not in \a this.
2499  * \throw if a localization in \a locs in not in \a this.
2500  * \sa MEDFileFieldGlobs::deepCpyPart
2501  */
2502 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const throw(INTERP_KERNEL::Exception)
2503 {
2504   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2505   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2506     {
2507       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2508       if(!pfl)
2509         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2510       pfl->incrRef();
2511       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2512       ret->_pfls.push_back(pfl2);
2513     }
2514   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2515     {
2516       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2517       if(!loc)
2518         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2519       loc->incrRef();
2520       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2521       ret->_locs.push_back(loc2);
2522     }
2523   ret->setFileName(getFileName());
2524   return ret.retn();
2525 }
2526
2527 /*!
2528  * \throw if a profile in \a pfls in not in \a this.
2529  * \throw if a localization in \a locs in not in \a this.
2530  * \sa MEDFileFieldGlobs::shallowCpyPart
2531  */
2532 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const throw(INTERP_KERNEL::Exception)
2533 {
2534   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2535   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2536     {
2537       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2538       if(!pfl)
2539         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2540       ret->_pfls.push_back(pfl->deepCpy());
2541     }
2542   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2543     {
2544       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2545       if(!loc)
2546         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2547       ret->_locs.push_back(loc->deepCpy());
2548     }
2549   ret->setFileName(getFileName());
2550   return ret.retn();
2551 }
2552
2553 MEDFileFieldGlobs::MEDFileFieldGlobs(const char *fname):_file_name(fname)
2554 {
2555 }
2556
2557 MEDFileFieldGlobs::MEDFileFieldGlobs()
2558 {
2559 }
2560
2561 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2562 {
2563 }
2564
2565 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2566 {
2567   oss << "Profiles :\n";
2568   std::size_t n=_pfls.size();
2569   for(std::size_t i=0;i<n;i++)
2570     {
2571       oss << "  - #" << i << " ";
2572       const DataArrayInt *pfl=_pfls[i];
2573       if(pfl)
2574         oss << "\"" << pfl->getName() << "\"\n";
2575       else
2576         oss << "EMPTY !\n";
2577     }
2578   n=_locs.size();
2579   oss << "Localizations :\n";
2580   for(std::size_t i=0;i<n;i++)
2581     {
2582       oss << "  - #" << i << " ";
2583       const MEDFileFieldLoc *loc=_locs[i];
2584       if(loc)
2585         loc->simpleRepr(oss);
2586       else
2587         oss<< "EMPTY !\n";
2588     }
2589 }
2590
2591 void MEDFileFieldGlobs::setFileName(const char *fileName)
2592 {
2593   _file_name=fileName;
2594 }
2595
2596 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2597 {
2598   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2599     {
2600       DataArrayInt *elt(*it);
2601       if(elt)
2602         {
2603           std::string name(elt->getName());
2604           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2605             {
2606               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2607                 {
2608                   elt->setName((*it2).second.c_str());
2609                   return;
2610                 }
2611             }
2612         }
2613     }
2614 }
2615
2616 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2617 {
2618   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2619     {
2620       MEDFileFieldLoc *elt(*it);
2621       if(elt)
2622         {
2623           std::string name(elt->getName());
2624           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2625             {
2626               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2627                 {
2628                   elt->setName((*it2).second.c_str());
2629                   return;
2630                 }
2631             }
2632         }
2633     }
2634 }
2635
2636 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
2637 {
2638   if(locId<0 || locId>=(int)_locs.size())
2639     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2640   return _locs[locId]->getNbOfGaussPtPerCell();
2641 }
2642
2643 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
2644 {
2645   return getLocalizationFromId(getLocalizationId(locName));
2646 }
2647
2648 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
2649 {
2650   if(locId<0 || locId>=(int)_locs.size())
2651     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2652   return *_locs[locId];
2653 }
2654
2655 namespace ParaMEDMEMImpl
2656 {
2657   class LocFinder
2658   {
2659   public:
2660     LocFinder(const char *loc):_loc(loc) { }
2661     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2662   private:
2663     const char *_loc;
2664   };
2665
2666   class PflFinder
2667   {
2668   public:
2669     PflFinder(const std::string& pfl):_pfl(pfl) { }
2670     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2671   private:
2672     const std::string& _pfl;
2673   };
2674 }
2675
2676 int MEDFileFieldGlobs::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
2677 {
2678   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2679   if(it==_locs.end())
2680     {
2681       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2682       for(it=_locs.begin();it!=_locs.end();it++)
2683         oss << "\"" << (*it)->getName() << "\", ";
2684       throw INTERP_KERNEL::Exception(oss.str().c_str());
2685     }
2686   return std::distance(_locs.begin(),it);
2687 }
2688
2689 /*!
2690  * The returned value is never null.
2691  */
2692 const DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
2693 {
2694   std::string pflNameCpp(pflName);
2695   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2696   if(it==_pfls.end())
2697     {
2698       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2699       for(it=_pfls.begin();it!=_pfls.end();it++)
2700         oss << "\"" << (*it)->getName() << "\", ";
2701       throw INTERP_KERNEL::Exception(oss.str().c_str());
2702     }
2703   return *it;
2704 }
2705
2706 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
2707 {
2708   if(pflId<0 || pflId>=(int)_pfls.size())
2709     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2710   return _pfls[pflId];
2711 }
2712
2713 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
2714 {
2715   if(locId<0 || locId>=(int)_locs.size())
2716     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2717   return *_locs[locId];
2718 }
2719
2720 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
2721 {
2722   return getLocalizationFromId(getLocalizationId(locName));
2723 }
2724
2725 /*!
2726  * The returned value is never null.
2727  */
2728 DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
2729 {
2730   std::string pflNameCpp(pflName);
2731   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2732   if(it==_pfls.end())
2733     {
2734       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2735       for(it=_pfls.begin();it!=_pfls.end();it++)
2736         oss << "\"" << (*it)->getName() << "\", ";
2737       throw INTERP_KERNEL::Exception(oss.str().c_str());
2738     }
2739   return *it;
2740 }
2741
2742 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
2743 {
2744   if(pflId<0 || pflId>=(int)_pfls.size())
2745     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2746   return _pfls[pflId];
2747 }
2748
2749 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
2750 {
2751   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2752   int i=0;
2753   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2754     {
2755       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2756         newPfls.push_back(*it);
2757     }
2758   _pfls=newPfls;
2759 }
2760
2761 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
2762 {
2763   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2764   int i=0;
2765   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2766     {
2767       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2768         newLocs.push_back(*it);
2769     }
2770   _locs=newLocs;
2771 }
2772
2773 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2774 {
2775   int sz=_pfls.size();
2776   std::vector<std::string> ret(sz);
2777   for(int i=0;i<sz;i++)
2778     ret[i]=_pfls[i]->getName();
2779   return ret;
2780 }
2781
2782 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2783 {
2784   int sz=_locs.size();
2785   std::vector<std::string> ret(sz);
2786   for(int i=0;i<sz;i++)
2787     ret[i]=_locs[i]->getName();
2788   return ret;
2789 }
2790
2791 bool MEDFileFieldGlobs::existsPfl(const char *pflName) const
2792 {
2793   std::vector<std::string> v=getPfls();
2794   std::string s(pflName);
2795   return std::find(v.begin(),v.end(),s)!=v.end();
2796 }
2797
2798 bool MEDFileFieldGlobs::existsLoc(const char *locName) const
2799 {
2800   std::vector<std::string> v=getLocs();
2801   std::string s(locName);
2802   return std::find(v.begin(),v.end(),s)!=v.end();
2803 }
2804
2805 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2806 {
2807   std::map<int,std::vector<int> > m;
2808   int i=0;
2809   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2810     {
2811       const DataArrayInt *tmp=(*it);
2812       if(tmp)
2813         {
2814           m[tmp->getHashCode()].push_back(i);
2815         }
2816     }
2817   std::vector< std::vector<int> > ret;
2818   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2819     {
2820       if((*it2).second.size()>1)
2821         {
2822           std::vector<int> ret0;
2823           bool equalityOrNot=false;
2824           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2825             {
2826               std::vector<int>::const_iterator it4=it3; it4++;
2827               for(;it4!=(*it2).second.end();it4++)
2828                 {
2829                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2830                     {
2831                       if(!equalityOrNot)
2832                         ret0.push_back(*it3);
2833                       ret0.push_back(*it4);
2834                       equalityOrNot=true;
2835                     }
2836                 }
2837             }
2838           if(!ret0.empty())
2839             ret.push_back(ret0);
2840         }
2841     }
2842   return ret;
2843 }
2844
2845 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2846 {
2847   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2848 }
2849
2850 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
2851 {
2852   std::string name(pfl->getName());
2853   if(name.empty())
2854     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2855   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2856     if(name==(*it)->getName())
2857       {
2858         if(!pfl->isEqual(*(*it)))
2859           {
2860             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2861             throw INTERP_KERNEL::Exception(oss.str().c_str());
2862           }
2863       }
2864   pfl->incrRef();
2865   _pfls.push_back(pfl);
2866 }
2867
2868 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)
2869 {
2870   std::string name(locName);
2871   if(name.empty())
2872     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2873   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2874   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2875     if((*it)->isName(locName))
2876       {
2877         if(!(*it)->isEqual(*obj,1e-12))
2878           {
2879             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
2880             throw INTERP_KERNEL::Exception(oss.str().c_str());
2881           }
2882       }
2883   _locs.push_back(obj);
2884 }
2885
2886 std::string MEDFileFieldGlobs::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
2887 {
2888   std::vector<std::string> names=getPfls();
2889   return CreateNewNameNotIn("NewPfl_",names);
2890 }
2891
2892 std::string MEDFileFieldGlobs::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
2893 {
2894   std::vector<std::string> names=getLocs();
2895   return CreateNewNameNotIn("NewLoc_",names);
2896 }
2897
2898 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const char *prefix, const std::vector<std::string>& namesToAvoid) throw(INTERP_KERNEL::Exception)
2899 {
2900   for(std::size_t sz=0;sz<100000;sz++)
2901     {
2902       std::ostringstream tryName;
2903       tryName << prefix << sz;
2904       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
2905         return tryName.str();
2906     }
2907   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
2908 }
2909
2910 /*!
2911  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
2912  *  \param [in] fname - the file name.
2913  */
2914 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const char *fname):_globals(MEDFileFieldGlobs::New(fname))
2915 {
2916 }
2917
2918 /*!
2919  * Creates an empty MEDFileFieldGlobsReal.
2920  */
2921 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
2922 {
2923 }
2924
2925 std::size_t MEDFileFieldGlobsReal::getHeapMemorySize() const
2926 {
2927   std::size_t ret=0;
2928   if((const MEDFileFieldGlobs *)_globals)
2929     ret+=_globals->getHeapMemorySize();
2930   return ret;
2931 }
2932
2933 /*!
2934  * Returns a string describing profiles and Gauss points held in \a this.
2935  *  \return std::string - the description string.
2936  */
2937 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
2938 {
2939   const MEDFileFieldGlobs *glob=_globals;
2940   std::ostringstream oss2; oss2 << glob;
2941   std::string stars(oss2.str().length(),'*');
2942   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
2943   if(glob)
2944     glob->simpleRepr(oss);
2945   else
2946     oss << "NO GLOBAL INFORMATION !\n";
2947 }
2948
2949 void MEDFileFieldGlobsReal::resetContent()
2950 {
2951   _globals=MEDFileFieldGlobs::New();
2952 }
2953
2954 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
2955 {
2956 }
2957
2958 /*!
2959  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
2960  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
2961  */
2962 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
2963 {
2964   _globals=other._globals;
2965 }
2966
2967 /*!
2968  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
2969  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
2970  */
2971 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other) throw(INTERP_KERNEL::Exception)
2972 {
2973   const MEDFileFieldGlobs *otherg(other._globals);
2974   if(!otherg)
2975     return ;
2976   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
2977 }
2978
2979 /*!
2980  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
2981  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
2982  */
2983 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other) throw(INTERP_KERNEL::Exception)
2984 {
2985   const MEDFileFieldGlobs *otherg(other._globals);
2986   if(!otherg)
2987     return ;
2988   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
2989 }
2990
2991 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
2992 {
2993   _globals=other._globals;
2994   if((const MEDFileFieldGlobs *)_globals)
2995     _globals=other._globals->deepCpy();
2996 }
2997
2998 /*!
2999  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3000  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3001  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3002  *         \a this and \a other MEDFileFieldGlobsReal.
3003  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3004  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3005  */
3006 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps) throw(INTERP_KERNEL::Exception)
3007 {
3008   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3009   if(thisGlobals==otherGlobals)
3010     return ;
3011   if(!thisGlobals)
3012     {
3013       _globals=other._globals;
3014       return ;
3015     }
3016   _globals->appendGlobs(*other._globals,eps);
3017 }
3018
3019 void MEDFileFieldGlobsReal::checkGlobsCoherency() const throw(INTERP_KERNEL::Exception)
3020 {
3021   checkGlobsPflsPartCoherency();
3022   checkGlobsLocsPartCoherency();
3023 }
3024
3025 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const throw(INTERP_KERNEL::Exception)
3026 {
3027   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3028 }
3029
3030 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const throw(INTERP_KERNEL::Exception)
3031 {
3032   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3033 }
3034
3035 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
3036 {
3037   contentNotNull()->loadProfileInFile(fid,id,pflName);
3038 }
3039
3040 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3041 {
3042   contentNotNull()->loadProfileInFile(fid,id);
3043 }
3044
3045 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
3046 {
3047   contentNotNull()->loadGlobals(fid,*this);
3048 }
3049
3050 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
3051 {
3052   contentNotNull()->loadAllGlobals(fid);
3053 }
3054
3055 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
3056 {
3057   contentNotNull()->writeGlobals(fid,opt);
3058 }
3059
3060 /*!
3061  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3062  * or getPflsReallyUsedMulti().
3063  *  \return std::vector<std::string> - a sequence of names of all profiles.
3064  */
3065 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3066 {
3067   return contentNotNull()->getPfls();
3068 }
3069
3070 /*!
3071  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3072  * or getLocsReallyUsedMulti().
3073  *  \return std::vector<std::string> - a sequence of names of all localizations.
3074  */
3075 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3076 {
3077   return contentNotNull()->getLocs();
3078 }
3079
3080 /*!
3081  * Checks if the profile with a given name exists.
3082  *  \param [in] pflName - the profile name of interest.
3083  *  \return bool - \c true if the profile named \a pflName exists.
3084  */
3085 bool MEDFileFieldGlobsReal::existsPfl(const char *pflName) const
3086 {
3087   return contentNotNull()->existsPfl(pflName);
3088 }
3089
3090 /*!
3091  * Checks if the localization with a given name exists.
3092  *  \param [in] locName - the localization name of interest.
3093  *  \return bool - \c true if the localization named \a locName exists.
3094  */
3095 bool MEDFileFieldGlobsReal::existsLoc(const char *locName) const
3096 {
3097   return contentNotNull()->existsLoc(locName);
3098 }
3099
3100 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
3101 {
3102   return contentNotNull()->createNewNameOfPfl();
3103 }
3104
3105 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
3106 {
3107   return contentNotNull()->createNewNameOfLoc();
3108 }
3109
3110 /*!
3111  * Sets the name of a MED file.
3112  *  \param [inout] fileName - the file name.
3113  */
3114 void MEDFileFieldGlobsReal::setFileName(const char *fileName)
3115 {
3116   contentNotNull()->setFileName(fileName);
3117 }
3118
3119 /*!
3120  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3121  * in the same order.
3122  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3123  *          Each item of this sequence is a vector containing ids of equal profiles.
3124  */
3125 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3126 {
3127   return contentNotNull()->whichAreEqualProfiles();
3128 }
3129
3130 /*!
3131  * Finds equal localizations.
3132  *  \param [in] eps - a precision used to compare real values of the localizations.
3133  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3134  *          Each item of this sequence is a vector containing ids of equal localizations.
3135  */
3136 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3137 {
3138   return contentNotNull()->whichAreEqualLocs(eps);
3139 }
3140
3141 /*!
3142  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3143  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3144  *        this sequence is a pair whose 
3145  *        - the first item is a vector of profile names to replace by the second item,
3146  *        - the second item is a profile name to replace every profile name of the first item.
3147  */
3148 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3149 {
3150   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3151 }
3152
3153 /*!
3154  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3155  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3156  *        this sequence is a pair whose 
3157  *        - the first item is a vector of localization names to replace by the second item,
3158  *        - the second item is a localization name to replace every localization name of the first item.
3159  */
3160 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3161 {
3162   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3163 }
3164
3165 /*!
3166  * Replaces references to some profiles (a reference is a profile name) by references
3167  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3168  * them-selves accordingly. <br>
3169  * This method is a generalization of changePflName().
3170  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3171  *        this sequence is a pair whose 
3172  *        - the first item is a vector of profile names to replace by the second item,
3173  *        - the second item is a profile name to replace every profile of the first item.
3174  * \sa changePflsRefsNamesGen()
3175  * \sa changePflName()
3176  */
3177 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3178 {
3179   changePflsRefsNamesGen(mapOfModif);
3180   changePflsNamesInStruct(mapOfModif);
3181 }
3182
3183 /*!
3184  * Replaces references to some localizations (a reference is a localization name) by references
3185  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3186  * them-selves accordingly. <br>
3187  * This method is a generalization of changeLocName().
3188  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3189  *        this sequence is a pair whose 
3190  *        - the first item is a vector of localization names to replace by the second item,
3191  *        - the second item is a localization name to replace every localization of the first item.
3192  * \sa changeLocsRefsNamesGen()
3193  * \sa changeLocName()
3194  */
3195 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3196 {
3197   changeLocsRefsNamesGen(mapOfModif);
3198   changeLocsNamesInStruct(mapOfModif);
3199 }
3200
3201 /*!
3202  * Renames the profile having a given name and updates references to this profile.
3203  *  \param [in] oldName - the name of the profile to rename.
3204  *  \param [in] newName - a new name of the profile.
3205  * \sa changePflsNames().
3206  */
3207 void MEDFileFieldGlobsReal::changePflName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
3208 {
3209   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3210   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3211   mapOfModif[0]=p;
3212   changePflsNames(mapOfModif);
3213 }
3214
3215 /*!
3216  * Renames the localization having a given name and updates references to this localization.
3217  *  \param [in] oldName - the name of the localization to rename.
3218  *  \param [in] newName - a new name of the localization.
3219  * \sa changeLocsNames().
3220  */
3221 void MEDFileFieldGlobsReal::changeLocName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
3222 {
3223   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3224   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3225   mapOfModif[0]=p;
3226   changeLocsNames(mapOfModif);
3227 }
3228
3229 /*!
3230  * Removes duplicated profiles. Returns a map used to update references to removed 
3231  * profiles via changePflsRefsNamesGen().
3232  * Equal profiles are found using whichAreEqualProfiles().
3233  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3234  *          a sequence describing the performed replacements of profiles. Each element of
3235  *          this sequence is a pair whose
3236  *          - the first item is a vector of profile names replaced by the second item,
3237  *          - the second item is a profile name replacing every profile of the first item.
3238  */
3239 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames() throw(INTERP_KERNEL::Exception)
3240 {
3241   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3242   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3243   int i=0;
3244   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3245     {
3246       std::vector< std::string > tmp((*it).size());
3247       int j=0;
3248       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3249         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3250       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3251       ret[i]=p;
3252       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3253       killProfileIds(tmp2);
3254     }
3255   changePflsRefsNamesGen(ret);
3256   return ret;
3257 }
3258
3259 /*!
3260  * Removes duplicated localizations. Returns a map used to update references to removed 
3261  * localizations via changeLocsRefsNamesGen().
3262  * Equal localizations are found using whichAreEqualLocs().
3263  *  \param [in] eps - a precision used to compare real values of the localizations.
3264  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3265  *          a sequence describing the performed replacements of localizations. Each element of
3266  *          this sequence is a pair whose
3267  *          - the first item is a vector of localization names replaced by the second item,
3268  *          - the second item is a localization name replacing every localization of the first item.
3269  */
3270 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps) throw(INTERP_KERNEL::Exception)
3271 {
3272   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3273   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3274   int i=0;
3275   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3276     {
3277       std::vector< std::string > tmp((*it).size());
3278       int j=0;
3279       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3280         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3281       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3282       ret[i]=p;
3283       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3284       killLocalizationIds(tmp2);
3285     }
3286   changeLocsRefsNamesGen(ret);
3287   return ret;
3288 }
3289
3290 /*!
3291  * Returns number of Gauss points per cell in a given localization.
3292  *  \param [in] locId - an id of the localization of interest.
3293  *  \return int - the number of the Gauss points per cell.
3294  */
3295 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
3296 {
3297   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3298 }
3299
3300 /*!
3301  * Returns an id of a localization by its name.
3302  *  \param [in] loc - the localization name of interest.
3303  *  \return int - the id of the localization.
3304  *  \throw If there is no a localization named \a loc.
3305  */
3306 int MEDFileFieldGlobsReal::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
3307 {
3308   return contentNotNull()->getLocalizationId(loc);
3309 }
3310
3311 /*!
3312  * Returns the name of the MED file.
3313  *  \return const char * - the MED file name.
3314  */
3315 const char *MEDFileFieldGlobsReal::getFileName() const
3316 {
3317   return contentNotNull()->getFileName();
3318 }
3319
3320 std::string MEDFileFieldGlobsReal::getFileName2() const
3321 {
3322   return contentNotNull()->getFileName2();
3323 }
3324
3325 /*!
3326  * Returns a localization object by its name.
3327  *  \param [in] locName - the name of the localization of interest.
3328  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3329  *  \throw If there is no a localization named \a locName.
3330  */
3331 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
3332 {
3333   return contentNotNull()->getLocalization(locName);
3334 }
3335
3336 /*!
3337  * Returns a localization object by its id.
3338  *  \param [in] locId - the id of the localization of interest.
3339  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3340  *  \throw If there is no a localization with id \a locId.
3341  */
3342 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
3343 {
3344   return contentNotNull()->getLocalizationFromId(locId);
3345 }
3346
3347 /*!
3348  * Returns a profile array by its name.
3349  *  \param [in] pflName - the name of the profile of interest.
3350  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3351  *  \throw If there is no a profile named \a pflName.
3352  */
3353 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
3354 {
3355   return contentNotNull()->getProfile(pflName);
3356 }
3357
3358 /*!
3359  * Returns a profile array by its id.
3360  *  \param [in] pflId - the id of the profile of interest.
3361  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3362  *  \throw If there is no a profile with id \a pflId.
3363  */
3364 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
3365 {
3366   return contentNotNull()->getProfileFromId(pflId);
3367 }
3368
3369 /*!
3370  * Returns a localization object, apt for modification, by its id.
3371  *  \param [in] locId - the id of the localization of interest.
3372  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3373  *          having the id \a locId.
3374  *  \throw If there is no a localization with id \a locId.
3375  */
3376 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
3377 {
3378   return contentNotNull()->getLocalizationFromId(locId);
3379 }
3380
3381 /*!
3382  * Returns a localization object, apt for modification, by its name.
3383  *  \param [in] locName - the name of the localization of interest.
3384  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3385  *          having the name \a locName.
3386  *  \throw If there is no a localization named \a locName.
3387  */
3388 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
3389 {
3390   return contentNotNull()->getLocalization(locName);
3391 }
3392
3393 /*!
3394  * Returns a profile array, apt for modification, by its name.
3395  *  \param [in] pflName - the name of the profile of interest.
3396  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3397  *  \throw If there is no a profile named \a pflName.
3398  */
3399 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
3400 {
3401   return contentNotNull()->getProfile(pflName);
3402 }
3403
3404 /*!
3405  * Returns a profile array, apt for modification, by its id.
3406  *  \param [in] pflId - the id of the profile of interest.
3407  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3408  *  \throw If there is no a profile with id \a pflId.
3409  */
3410 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
3411 {
3412   return contentNotNull()->getProfileFromId(pflId);
3413 }
3414
3415 /*!
3416  * Removes profiles given by their ids. No data is updated to track this removal.
3417  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3418  */
3419 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
3420 {
3421   contentNotNull()->killProfileIds(pflIds);
3422 }
3423
3424 /*!
3425  * Removes localizations given by their ids. No data is updated to track this removal.
3426  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3427  */
3428 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
3429 {
3430   contentNotNull()->killLocalizationIds(locIds);
3431 }
3432
3433 /*!
3434  * Stores a profile array.
3435  *  \param [in] pfl - the profile array to store.
3436  *  \throw If the name of \a pfl is empty.
3437  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3438  *         different ids.
3439  */
3440 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
3441 {
3442   contentNotNull()->appendProfile(pfl);
3443 }
3444
3445 /*!
3446  * Adds a new localization of Gauss points.
3447  *  \param [in] locName - the name of the new localization.
3448  *  \param [in] geoType - a geometrical type of the reference cell.
3449  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3450  *         must be \c nbOfNodesPerCell * \c dimOfType.
3451  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3452  *         must be  _wg_.size() * \c dimOfType.
3453  *  \param [in] w - the weights of Gauss points.
3454  *  \throw If \a locName is empty.
3455  *  \throw If a localization with the name \a locName already exists but is
3456  *         different form the new one.
3457  */
3458 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)
3459 {
3460   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3461 }
3462
3463 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() throw(INTERP_KERNEL::Exception)
3464 {
3465   MEDFileFieldGlobs *g(_globals);
3466   if(!g)
3467     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3468   return g;
3469 }
3470
3471 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const throw(INTERP_KERNEL::Exception)
3472 {
3473   const MEDFileFieldGlobs *g(_globals);
3474   if(!g)
3475     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3476   return g;
3477 }
3478
3479 //= MEDFileFieldNameScope
3480
3481 MEDFileFieldNameScope::MEDFileFieldNameScope()
3482 {
3483 }
3484
3485 MEDFileFieldNameScope::MEDFileFieldNameScope(const char *fieldName):_name(fieldName)
3486 {
3487 }
3488
3489 /*!
3490  * Returns the name of \a this field.
3491  *  \return std::string - a string containing the field name.
3492  */
3493 std::string MEDFileFieldNameScope::getName() const throw(INTERP_KERNEL::Exception)
3494 {
3495   return _name;
3496 }
3497
3498 /*!
3499  * Sets name of \a this field
3500  *  \param [in] name - the new field name.
3501  */
3502 void MEDFileFieldNameScope::setName(const char *fieldName) throw(INTERP_KERNEL::Exception)
3503 {
3504   _name=fieldName;
3505 }
3506
3507 std::string MEDFileFieldNameScope::getDtUnit() const throw(INTERP_KERNEL::Exception)
3508 {
3509   return _dt_unit;
3510 }
3511
3512 void MEDFileFieldNameScope::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
3513 {
3514   _dt_unit=dtUnit;
3515 }
3516
3517 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3518 {
3519   _name=other._name;
3520   _dt_unit=other._dt_unit;
3521 }
3522
3523 //= MEDFileAnyTypeField1TSWithoutSDA
3524
3525 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other) throw(INTERP_KERNEL::Exception)
3526 {
3527   _field_per_mesh.resize(other._field_per_mesh.size());
3528   std::size_t i=0;
3529   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3530     {
3531       if((const MEDFileFieldPerMesh *)*it)
3532         _field_per_mesh[i]=(*it)->deepCpy(this);
3533     }
3534 }
3535
3536 /*!
3537  * Prints a string describing \a this field into a stream. This string is outputted 
3538  * by \c print Python command.
3539  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3540  *  \param [in,out] oss - the out stream.
3541  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3542  *          info id printed, else, not.
3543  */
3544 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3545 {
3546   std::string startOfLine(bkOffset,' ');
3547   oss << startOfLine << "Field ";
3548   if(bkOffset==0)
3549     oss << "[Type=" << getTypeStr() << "] ";
3550   oss << "on One time Step ";
3551   if(f1tsId>=0)
3552     oss << "(" << f1tsId << ") ";
3553   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3554   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3555   const DataArray *arr=getUndergroundDataArray();
3556   if(arr)
3557     {
3558       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3559       if(f1tsId<0)
3560         {
3561           oss << startOfLine << "Field Name : \"" << arr->getName() << "\"." << std::endl;
3562           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3563           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3564             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3565         }
3566       if(arr->isAllocated())
3567         {
3568           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3569         }
3570       else
3571         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3572     }
3573   else
3574     {
3575       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3576     }
3577   oss << startOfLine << "----------------------" << std::endl;
3578   if(!_field_per_mesh.empty())
3579     {
3580       int i=0;
3581       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3582         {
3583           const MEDFileFieldPerMesh *cur=(*it2);
3584           if(cur)
3585             cur->simpleRepr(bkOffset,oss,i);
3586           else
3587             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3588         }
3589     }
3590   else
3591     {
3592       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3593     }
3594   oss << startOfLine << "----------------------" << std::endl;
3595 }
3596
3597 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const throw(INTERP_KERNEL::Exception)
3598 {
3599   const DataArray *arr(getUndergroundDataArray());
3600   if(!arr)
3601     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3602   int nbOfCompo=arr->getNumberOfComponents();
3603   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3604   for(int i=0;i<nbOfCompo;i++)
3605     {
3606       ret[i]=deepCpy();
3607       std::vector<int> v(1,i);
3608       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3609       ret[i]->setArray(arr2);
3610     }
3611   return ret;
3612 }
3613
3614 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order):MEDFileFieldNameScope(fieldName),_iteration(iteration),_order(order),_csit(csit)
3615 {
3616 }
3617
3618 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1)
3619 {
3620 }
3621
3622 /*!
3623  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3624  * empty. Returns -1 if this in on nodes.
3625  *  \return int - the dimension of \a this.
3626  */
3627 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3628 {
3629   int ret=-2;
3630   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3631     (*it)->getDimension(ret);
3632   return ret;
3633 }
3634
3635 /*!
3636  * Returns the mesh name.
3637  *  \return std::string - a string holding the mesh name.
3638  *  \throw If \c _field_per_mesh.empty()
3639  */
3640 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
3641 {
3642   if(_field_per_mesh.empty())
3643     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3644   return _field_per_mesh[0]->getMeshName();
3645 }
3646
3647 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
3648 {
3649   std::string oldName(getMeshName());
3650   std::vector< std::pair<std::string,std::string> > v(1);
3651   v[0].first=oldName; v[0].second=newMeshName;
3652   changeMeshNames(v);
3653 }
3654
3655 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
3656 {
3657   bool ret=false;
3658   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3659     {
3660       MEDFileFieldPerMesh *cur(*it);
3661       if(cur)
3662         ret=cur->changeMeshNames(modifTab) || ret;
3663     }
3664   return ret;
3665 }
3666
3667 /*!
3668  * Returns the number of iteration of the state of underlying mesh.
3669  *  \return int - the iteration number.
3670  *  \throw If \c _field_per_mesh.empty()
3671  */
3672 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const throw(INTERP_KERNEL::Exception)
3673 {
3674   if(_field_per_mesh.empty())
3675     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3676   return _field_per_mesh[0]->getMeshIteration();
3677 }
3678
3679 /*!
3680  * Returns the order number of iteration of the state of underlying mesh.
3681  *  \return int - the order number.
3682  *  \throw If \c _field_per_mesh.empty()
3683  */
3684 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const throw(INTERP_KERNEL::Exception)
3685 {
3686   if(_field_per_mesh.empty())
3687     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3688   return _field_per_mesh[0]->getMeshOrder();
3689 }
3690
3691 /*!
3692  * Checks if \a this field is tagged by a given iteration number and a given
3693  * iteration order number.
3694  *  \param [in] iteration - the iteration number of interest.
3695  *  \param [in] order - the iteration order number of interest.
3696  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3697  *          \a this->getOrder() == \a order.
3698  */
3699 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3700 {
3701   return iteration==_iteration && order==_order;
3702 }
3703
3704 /*!
3705  * Returns number of iteration and order number of iteration when
3706  * \a this field has been calculated.
3707  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3708  *          order number.
3709  */
3710 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3711 {
3712   std::pair<int,int> p;
3713   fillIteration(p);
3714   return p;
3715 }
3716
3717 /*!
3718  * Returns number of iteration and order number of iteration when
3719  * \a this field has been calculated.
3720  *  \param [in,out] p - a pair returning the iteration number and the iteration
3721  *          order number.
3722  */
3723 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3724 {
3725   p.first=_iteration;
3726   p.second=_order;
3727 }
3728
3729 /*!
3730  * Returns all types of spatial discretization of \a this field.
3731  *  \param [in,out] types - a sequence of types of \a this field.
3732  */
3733 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
3734 {
3735   std::set<TypeOfField> types2;
3736   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3737     {
3738       (*it)->fillTypesOfFieldAvailable(types2);
3739     }
3740   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3741   std::copy(types2.begin(),types2.end(),bi);
3742 }
3743
3744 /*!
3745  * Returns all types of spatial discretization of \a this field.
3746  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3747  *          of \a this field.
3748  */
3749 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
3750 {
3751   std::vector<TypeOfField> ret;
3752   fillTypesOfFieldAvailable(ret);
3753   return ret;
3754 }
3755
3756 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3757 {
3758   std::vector<std::string> ret;
3759   std::set<std::string> ret2;
3760   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3761     {
3762       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3763       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3764         if(ret2.find(*it2)==ret2.end())
3765           {
3766             ret.push_back(*it2);
3767             ret2.insert(*it2);
3768           }
3769     }
3770   return ret;
3771 }
3772
3773 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3774 {
3775   std::vector<std::string> ret;
3776   std::set<std::string> ret2;
3777   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3778     {
3779       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3780       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3781         if(ret2.find(*it2)==ret2.end())
3782           {
3783             ret.push_back(*it2);
3784             ret2.insert(*it2);
3785           }
3786     }
3787   return ret;
3788 }
3789
3790 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3791 {
3792   std::vector<std::string> ret;
3793   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3794     {
3795       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3796       ret.insert(ret.end(),tmp.begin(),tmp.end());
3797     }
3798   return ret;
3799 }
3800
3801 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3802 {
3803   std::vector<std::string> ret;
3804   std::set<std::string> ret2;
3805   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3806     {
3807       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3808       ret.insert(ret.end(),tmp.begin(),tmp.end());
3809     }
3810   return ret;
3811 }
3812
3813 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3814 {
3815   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3816     (*it)->changePflsRefsNamesGen(mapOfModif);
3817 }
3818
3819 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3820 {
3821   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3822     (*it)->changeLocsRefsNamesGen(mapOfModif);
3823 }
3824
3825 /*!
3826  * Returns all attributes of parts of \a this field lying on a given mesh.
3827  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3828  * item of every of returned sequences refers to the _i_-th part of \a this field.
3829  * Thus all sequences returned by this method are of the same length equal to number
3830  * of different types of supporting entities.<br>
3831  * A field part can include sub-parts with several different spatial discretizations,
3832  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3833  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3834  * of a nested sequence corresponds to a type of spatial discretization.<br>
3835  * This method allows for iteration over MEDFile DataStructure without any overhead.
3836  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3837  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3838  *          not checked if \a mname == \c NULL).
3839  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3840  *          a field part is returned. 
3841  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3842  *          This sequence is of the same length as \a types. 
3843  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3844  *          discretization. A profile name can be empty.
3845  *          Length of this and of nested sequences is the same as that of \a typesF.
3846  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3847  *          discretization. A localization name can be empty.
3848  *          Length of this and of nested sequences is the same as that of \a typesF.
3849  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3850  *          of ids of tuples within the data array, per each type of spatial
3851  *          discretization within one mesh entity type. 
3852  *          Length of this and of nested sequences is the same as that of \a typesF.
3853  *  \throw If no field is lying on \a mname.
3854  */
3855 std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeField1TSWithoutSDA::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)
3856 {
3857   int meshId=0;
3858   if(mname)
3859     meshId=getMeshIdFromMeshName(mname);
3860   else
3861     if(_field_per_mesh.empty())
3862       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3863   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3864 }
3865
3866 /*!
3867  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
3868  * maximal absolute dimension and values returned via the out parameter \a levs are 
3869  * dimensions relative to the maximal absolute dimension. <br>
3870  * This method is designed for MEDFileField1TS instances that have a discretization
3871  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
3872  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
3873  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
3874  * Only these 3 discretizations will be taken into account here. If \a this is
3875  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
3876  * This method is useful to make the link between the dimension of the underlying mesh
3877  * and the levels of \a this, because it is possible that the highest dimension of \a this
3878  * field is not equal to the dimension of the underlying mesh.
3879  * 
3880  * Let's consider the following case:
3881  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
3882  * TETRA4, HEXA8, TRI3 and SEG2.
3883  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
3884  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
3885  *
3886  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
3887  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
3888  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
3889  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
3890  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
3891  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
3892  * For example<br>
3893  * to retrieve the highest level of
3894  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
3895  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
3896  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
3897  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
3898  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3899  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3900  *          not checked if \a mname == \c NULL).
3901  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
3902  *          absolute one. They are in decreasing order. This sequence is cleared before
3903  *          filling it in.
3904  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
3905  *  \throw If no field is lying on \a mname.
3906  */
3907 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
3908 {
3909   levs.clear();
3910   int meshId=getMeshIdFromMeshName(mname);
3911   std::vector<INTERP_KERNEL::NormalizedCellType> types;
3912   std::vector< std::vector<TypeOfField> > typesF;
3913   std::vector< std::vector<std::string> > pfls, locs;
3914   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3915   if(types.empty())
3916     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
3917   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
3918   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
3919     return -1;
3920   st.erase(INTERP_KERNEL::NORM_ERROR);
3921   std::set<int> ret1;
3922   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
3923     {
3924       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
3925       ret1.insert((int)cm.getDimension());
3926     }
3927   int ret=*std::max_element(ret1.begin(),ret1.end());
3928   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
3929   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
3930   return ret;
3931 }
3932
3933 /*!
3934  * \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.
3935  * \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.
3936  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3937  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3938  */
3939 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
3940 {
3941   int mid=getMeshIdFromMeshName(mName);
3942   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3943 }
3944
3945 /*!
3946  * \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.
3947  * \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.
3948  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3949  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3950  */
3951 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
3952 {
3953   int mid=getMeshIdFromMeshName(mName);
3954   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3955 }
3956
3957 /*!
3958  * \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.
3959  */
3960 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception)
3961 {
3962   if(_field_per_mesh.empty())
3963     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
3964   if(mName==0)
3965     return 0;
3966   std::string mName2(mName);
3967   int ret=0;
3968   std::vector<std::string> msg;
3969   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
3970     if(mName2==(*it)->getMeshName())
3971       return ret;
3972     else
3973       msg.push_back((*it)->getMeshName());
3974   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
3975   oss << "Possible meshes are : ";
3976   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
3977     oss << "\"" << (*it2) << "\" ";
3978   throw INTERP_KERNEL::Exception(oss.str().c_str());
3979 }
3980
3981 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
3982 {
3983   if(!mesh)
3984     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
3985   std::string tmp(mesh->getName());
3986   if(tmp.empty())
3987     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
3988   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
3989   int i=0;
3990   for(;it!=_field_per_mesh.end();it++,i++)
3991     {
3992       if((*it)->getMeshName()==tmp)
3993         return i;
3994     }
3995   int sz=_field_per_mesh.size();
3996   _field_per_mesh.resize(sz+1);
3997   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
3998   return sz;
3999 }
4000
4001 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4002                                                             MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
4003 {
4004   bool ret=false;
4005   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4006     {
4007       MEDFileFieldPerMesh *fpm(*it);
4008       if(fpm)
4009         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4010     }
4011   return ret;
4012 }
4013
4014 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4015 {
4016   if(_field_per_mesh.empty())
4017     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4018   if(_field_per_mesh.size()>1)
4019     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4020   _field_per_mesh[0]->copyOptionsFrom(opts);
4021   _field_per_mesh[0]->writeLL(fid,nasc);
4022 }
4023
4024 void MEDFileAnyTypeField1TSWithoutSDA::finishLoading(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4025 {
4026   med_int numdt,numit;
4027   med_float dt;
4028   med_int nmesh;
4029   med_bool localMesh;
4030   med_int meshnumdt,meshnumit;
4031   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4032   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4033   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4034   if(_iteration!=numdt || _order!=numit)
4035     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::finishLoading : unexpected exception internal error !");
4036   _field_per_mesh.resize(nmesh);
4037   for(int i=0;i<nmesh;i++)
4038     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i+1,meshnumdt,meshnumit,nasc);//tony
4039   int start=0;
4040   for(int i=0;i<nmesh;i++)
4041     {
4042       _field_per_mesh[i]->prepareLoading(fid,start,nasc);
4043     }
4044   getOrCreateAndGetArray()->alloc(start,getNumberOfComponents());
4045   for(int i=0;i<nmesh;i++)
4046     {
4047       _field_per_mesh[i]->finishLoading(fid,nasc);
4048     }
4049 }
4050
4051 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySize() const
4052 {
4053   std::size_t ret=_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4054   if(getUndergroundDataArray())
4055     ret+=getUndergroundDataArray()->getHeapMemorySize();
4056   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4057     ret+=(*it)->getHeapMemorySize();
4058   return ret;
4059 }
4060
4061 /*!
4062  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4063  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4064  * "Sort By Type"), if not, an exception is thrown. 
4065  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4066  *  \param [in] arr - the array of values.
4067  *  \param [in,out] glob - the global data where profiles and localization present in
4068  *          \a field, if any, are added.
4069  *  \throw If the name of \a field is empty.
4070  *  \throw If the data array of \a field is not set.
4071  *  \throw If \a this->_arr is already allocated but has different number of components
4072  *         than \a field.
4073  *  \throw If the underlying mesh of \a field has no name.
4074  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4075  */
4076 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4077 {
4078   const MEDCouplingMesh *mesh=field->getMesh();
4079   //
4080   TypeOfField type=field->getTypeOfField();
4081   std::vector<DataArrayInt *> dummy;
4082   int start=copyTinyInfoFrom(field,arr);
4083   int pos=addNewEntryIfNecessary(mesh);
4084   if(type!=ON_NODES)
4085     {
4086       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4087       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4088     }
4089   else
4090     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4091 }
4092
4093 /*!
4094  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4095  * of a given mesh are used as the support of the given field (a real support is not used). 
4096  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4097  * Order of underlying mesh entities of the given field specified by \a profile parameter
4098  * is not prescribed; this method permutes field values to have them sorted by element
4099  * type as required for writing to MED file. A new profile is added only if no equal
4100  * profile is missing. 
4101  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4102  *  \param [in] arrOfVals - the values of the field \a field used.
4103  *  \param [in] mesh - the supporting mesh of \a field.
4104  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4105  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4106  *  \param [in,out] glob - the global data where profiles and localization present in
4107  *          \a field, if any, are added.
4108  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4109  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4110  *  \throw If the data array of \a field is not set.
4111  *  \throw If \a this->_arr is already allocated but has different number of components
4112  *         than \a field.
4113  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4114  *  \sa setFieldNoProfileSBT()
4115  */
4116 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4117 {
4118   TypeOfField type=field->getTypeOfField();
4119   int start=copyTinyInfoFrom(field,arrOfVals);
4120   std::vector<DataArrayInt *> idsInPflPerType;
4121   std::vector<DataArrayInt *> idsPerType;
4122   std::vector<int> code,code2;
4123   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4124   if(type!=ON_NODES)
4125     {
4126       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4127       code2=m->getDistributionOfTypes();
4128       //
4129       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size());
4130       for(std::size_t i=0;i<idsInPflPerType.size();i++)
4131         idsInPflPerType2[i]=idsInPflPerType[i];
4132       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size());
4133       for(std::size_t i=0;i<idsPerType.size();i++)
4134         idsPerType2[i]=idsPerType[i];
4135       //
4136       int pos=addNewEntryIfNecessary(m);
4137       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4138     }
4139   else
4140     {
4141       int pos=addNewEntryIfNecessary(m);
4142       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4143     }
4144 }
4145
4146 /*!
4147  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4148  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4149  * larger by the size of \a field. Returns an id of the first not filled
4150  * tuple of \a this->_arr.
4151  *  \param [in] field - the field to copy the info on components and the name from.
4152  *  \return int - the id of first not initialized tuple of \a this->_arr.
4153  *  \throw If the name of \a field is empty.
4154  *  \throw If the data array of \a field is not set.
4155  *  \throw If \a this->_arr is already allocated but has different number of components
4156  *         than \a field.
4157  */
4158 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
4159 {
4160   if(!field)
4161     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4162   std::string name(field->getName());
4163   setName(name.c_str());
4164   setDtUnit(field->getTimeUnit());
4165   if(name.empty())
4166     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4167   if(!arr)
4168     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4169   _dt=field->getTime(_iteration,_order);
4170   int nbOfComponents=arr->getNumberOfComponents();
4171   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4172   if(!getOrCreateAndGetArray()->isAllocated())
4173     {
4174       getOrCreateAndGetArray()->alloc(arr->getNumberOfTuples(),arr->getNumberOfComponents());
4175       return 0;
4176     }
4177   else
4178     {
4179       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4180       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4181       MEDCouplingAutoRefCountObjectPtr<DataArray> tmp=createNewEmptyDataArrayInstance();
4182       tmp->alloc(newNbOfTuples,nbOfComponents);
4183       tmp->copyStringInfoFrom(*getOrCreateAndGetArray());
4184       DataArray *arrr=getOrCreateAndGetArray();      
4185       tmp->setContigPartOfSelectedValues2(0,arrr,0,oldNbOfTuples,1);
4186       setArray(tmp);
4187       return oldNbOfTuples;
4188     }
4189 }
4190
4191 /*!
4192  * Returns number of components in \a this field
4193  *  \return int - the number of components.
4194  */
4195 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4196 {
4197   return getOrCreateAndGetArray()->getNumberOfComponents();
4198 }
4199
4200 /*!
4201  * Change info on components in \a this.
4202  * \throw If size of \a infos is not equal to the number of components already in \a this.
4203  */
4204 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
4205 {
4206   DataArray *arr=getOrCreateAndGetArray();
4207   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4208 }
4209
4210 /*!
4211  * Returns info on components of \a this field.
4212  *  \return const std::vector<std::string>& - a sequence of strings each being an
4213  *          information on _i_-th component.
4214  */
4215 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4216 {
4217   const DataArray *arr=getOrCreateAndGetArray();
4218   return arr->getInfoOnComponents();
4219 }
4220
4221 /*!
4222  * Returns a mutable info on components of \a this field.
4223  *  \return std::vector<std::string>& - a sequence of strings each being an
4224  *          information on _i_-th component.
4225  */
4226 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4227 {
4228   DataArray *arr=getOrCreateAndGetArray();
4229   return arr->getInfoOnComponents();
4230 }
4231
4232 /*!
4233  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4234  *  \param [in] type - a spatial discretization of the new field.
4235  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4236  *  \param [in] mName - a name of the supporting mesh.
4237  *  \param [in] renumPol - specifies how to permute values of the result field according to
4238  *          the optional numbers of cells and nodes, if any. The valid values are
4239  *          - 0 - do not permute.
4240  *          - 1 - permute cells.
4241  *          - 2 - permute nodes.
4242  *          - 3 - permute cells and nodes.
4243  *
4244  *  \param [in] glob - the global data storing profiles and localization.
4245  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4246  *          caller is to delete this field using decrRef() as it is no more needed. 
4247  *  \throw If the MED file is not readable.
4248  *  \throw If there is no mesh named \a mName in the MED file.
4249  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4250  *  \throw If no field of \a this is lying on the mesh \a mName.
4251  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4252  */
4253 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4254 {
4255   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4256   if(mName==0)
4257     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4258   else
4259     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4260   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4261 }
4262
4263 /*!
4264  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4265  *  \param [in] type - a spatial discretization of the new field.
4266  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4267  *  \param [in] renumPol - specifies how to permute values of the result field according to
4268  *          the optional numbers of cells and nodes, if any. The valid values are
4269  *          - 0 - do not permute.
4270  *          - 1 - permute cells.
4271  *          - 2 - permute nodes.
4272  *          - 3 - permute cells and nodes.
4273  *
4274  *  \param [in] glob - the global data storing profiles and localization.
4275  *  \param [in] mesh - the supporting mesh.
4276  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4277  *          caller is to delete this field using decrRef() as it is no more needed. 
4278  *  \throw If the MED file is not readable.
4279  *  \throw If no field of \a this is lying on \a mesh.
4280  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4281  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4282  */
4283 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4284 {
4285   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4286   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4287   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4288   if(meshDimRelToMax==1)
4289     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4290   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4291 }
4292
4293 /*!
4294  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4295  * given mesh. 
4296  *  \param [in] type - a spatial discretization of the new field.
4297  *  \param [in] mName - a name of the supporting mesh.
4298  *  \param [in] renumPol - specifies how to permute values of the result field according to
4299  *          the optional numbers of cells and nodes, if any. The valid values are
4300  *          - 0 - do not permute.
4301  *          - 1 - permute cells.
4302  *          - 2 - permute nodes.
4303  *          - 3 - permute cells and nodes.
4304  *
4305  *  \param [in] glob - the global data storing profiles and localization.
4306  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4307  *          caller is to delete this field using decrRef() as it is no more needed. 
4308  *  \throw If the MED file is not readable.
4309  *  \throw If there is no mesh named \a mName in the MED file.
4310  *  \throw If there are no mesh entities in the mesh.
4311  *  \throw If no field values of the given \a type are available.
4312  */
4313 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4314 {
4315    MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4316   if(mName==0)
4317     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4318   else
4319     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4320   int absDim=getDimension();
4321   int meshDimRelToMax=absDim-mm->getMeshDimension();
4322   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4323 }
4324
4325 /*!
4326  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4327  *  \param [in] type - a spatial discretization of the new field.
4328  *  \param [in] renumPol - specifies how to permute values of the result field according to
4329  *          the optional numbers of cells and nodes, if any. The valid values are
4330  *          - 0 - do not permute.
4331  *          - 1 - permute cells.
4332  *          - 2 - permute nodes.
4333  *          - 3 - permute cells and nodes.
4334  *
4335  *  \param [in] glob - the global data storing profiles and localization.
4336  *  \param [in] mesh - the supporting mesh.
4337  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4338  *         field according to \a renumPol.
4339  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4340  *         field according to \a renumPol.
4341  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4342  *          caller is to delete this field using decrRef() as it is no more needed. 
4343  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4344  *  \throw If no field of \a this is lying on \a mesh.
4345  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4346  */
4347 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4348 {
4349   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4350   int meshId=getMeshIdFromMeshName(mesh->getName());
4351   bool isPfl=false;
4352   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4353   switch(renumPol)
4354     {
4355     case 0:
4356       {
4357         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4358         return ret.retn();
4359       }
4360     case 3:
4361     case 1:
4362       {
4363         if(isPfl)
4364           throw INTERP_KERNEL::Exception(msg1);
4365         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4366         if(cellRenum)
4367           {
4368             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4369               {
4370                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4371                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4372                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4373               }
4374             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4375             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4376             std::vector<DataArray *> arrOut2(1,arrOut);
4377             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4378             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4379             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4380           }
4381         if(renumPol==1)
4382           return ret.retn();
4383       }
4384     case 2:
4385       {
4386         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4387         if(isPfl)
4388           throw INTERP_KERNEL::Exception(msg1);
4389         if(nodeRenum)
4390           {
4391             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4392               {
4393                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4394                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4395                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4396               }
4397             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4398             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4399               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4400             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4401           }
4402         return ret.retn();
4403       }
4404     default:
4405       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4406     }
4407 }
4408
4409 /*!
4410  * Returns values and a profile of the field of a given type lying on a given support.
4411  *  \param [in] type - a spatial discretization of the field.
4412  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4413  *  \param [in] mesh - the supporting mesh.
4414  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4415  *          field of interest lies on. If the field lies on all entities of the given
4416  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4417  *          using decrRef() as it is no more needed.  
4418  *  \param [in] glob - the global data storing profiles and localization.
4419  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4420  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4421  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4422  *  \throw If no field of \a this is lying on \a mesh.
4423  *  \throw If no field values of the given \a type are available.
4424  */
4425 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4426 {
4427   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4428   int meshId=getMeshIdFromMeshName(mesh->getName());
4429   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4430   ret->setName(nasc.getName().c_str());
4431   return ret.retn();
4432 }
4433
4434 //= MEDFileField1TSWithoutSDA
4435
4436 /*!
4437  * Throws if a given value is not a valid (non-extended) relative dimension.
4438  *  \param [in] meshDimRelToMax - the relative dimension value.
4439  *  \throw If \a meshDimRelToMax > 0.
4440  */
4441 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
4442 {
4443   if(meshDimRelToMax>0)
4444     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4445 }
4446
4447 /*!
4448  * Checks if elements of a given mesh are in the order suitable for writing 
4449  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4450  * vector describing types of elements and their number.
4451  *  \param [in] mesh - the mesh to check.
4452  *  \return std::vector<int> - a vector holding for each element type (1) item of
4453  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4454  *          These values are in full-interlace mode.
4455  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4456  */
4457 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
4458 {
4459   if(!mesh)
4460     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4461   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4462   int nbOfTypes=geoTypes.size();
4463   std::vector<int> code(3*nbOfTypes);
4464   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4465   arr1->alloc(nbOfTypes,1);
4466   int *arrPtr=arr1->getPointer();
4467   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4468   for(int i=0;i<nbOfTypes;i++,it++)
4469     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4470   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4471   const int *arrPtr2=arr2->getConstPointer();
4472   int i=0;
4473   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4474     {
4475       int pos=arrPtr2[i];
4476       int nbCells=mesh->getNumberOfCellsWithType(*it);
4477       code[3*pos]=(int)(*it);
4478       code[3*pos+1]=nbCells;
4479       code[3*pos+2]=-1;//no profiles
4480     }
4481   std::vector<const DataArrayInt *> idsPerType;//no profiles
4482   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4483   if(da)
4484     {
4485       da->decrRef();
4486       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4487     }
4488   return code;
4489 }
4490
4491 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const char *fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4492 {
4493   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4494 }
4495
4496 /*!
4497  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4498  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4499  * item of every of returned sequences refers to the _i_-th part of \a this field.
4500  * Thus all sequences returned by this method are of the same length equal to number
4501  * of different types of supporting entities.<br>
4502  * A field part can include sub-parts with several different spatial discretizations,
4503  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4504  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4505  * of a nested sequence corresponds to a type of spatial discretization.<br>
4506  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4507  * The overhead is due to selecting values into new instances of DataArrayDouble.
4508  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4509  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4510  *          not checked if \a mname == \c NULL).
4511  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4512  *          a field part is returned. 
4513  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4514  *          A field part can include sub-parts with several different spatial discretizations,
4515  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4516  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4517  *          This sequence is of the same length as \a types. 
4518  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4519  *          discretization. A profile name can be empty.
4520  *          Length of this and of nested sequences is the same as that of \a typesF.
4521  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4522  *          discretization. A localization name can be empty.
4523  *          Length of this and of nested sequences is the same as that of \a typesF.
4524  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4525  *          per each type of spatial discretization within one mesh entity type.
4526  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4527  *          Length of this and of nested sequences is the same as that of \a typesF.
4528  *  \throw If no field is lying on \a mname.
4529  */
4530 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)
4531 {
4532   int meshId=0;
4533   if(mname)
4534     meshId=getMeshIdFromMeshName(mname);
4535   else
4536     if(_field_per_mesh.empty())
4537       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4538   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4539   int nbOfRet=ret0.size();
4540   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4541   for(int i=0;i<nbOfRet;i++)
4542     {
4543       const std::vector< std::pair<int,int> >& p=ret0[i];
4544       int nbOfRet1=p.size();
4545       ret[i].resize(nbOfRet1);
4546       for(int j=0;j<nbOfRet1;j++)
4547         {
4548           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4549           ret[i][j]=tmp;
4550         }
4551     }
4552   return ret;
4553 }
4554
4555 /*!
4556  * Returns a pointer to the underground DataArrayDouble instance. So the
4557  * caller should not decrRef() it. This method allows for a direct access to the field
4558  * values. This method is quite unusable if there is more than a nodal field or a cell
4559  * field on single geometric cell type. 
4560  *  \return DataArrayDouble * - the pointer to the field values array.
4561  */
4562 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const throw(INTERP_KERNEL::Exception)
4563 {
4564   const DataArrayDouble *ret=_arr;
4565   if(ret)
4566     return const_cast<DataArrayDouble *>(ret);
4567   else
4568     return 0;
4569 }
4570
4571 const char *MEDFileField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
4572 {
4573   return TYPE_STR;
4574 }
4575
4576 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const throw(INTERP_KERNEL::Exception)
4577 {
4578   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
4579   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4580   ret->deepCpyLeavesFrom(*this);
4581   const DataArrayDouble *arr(_arr);
4582   if(arr)
4583     {
4584       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
4585       ret->setArray(arr2);
4586     }
4587   return ret.retn();
4588 }
4589
4590 /*!
4591  * Returns a pointer to the underground DataArrayDouble instance. So the
4592  * caller should not decrRef() it. This method allows for a direct access to the field
4593  * values. This method is quite unusable if there is more than a nodal field or a cell
4594  * field on single geometric cell type. 
4595  *  \return DataArrayDouble * - the pointer to the field values array.
4596  */
4597 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4598 {
4599   return getUndergroundDataArrayDouble();
4600 }
4601
4602 /*!
4603  * Returns a pointer to the underground DataArrayDouble instance and a
4604  * sequence describing parameters of a support of each part of \a this field. The
4605  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4606  * direct access to the field values. This method is intended for the field lying on one
4607  * mesh only.
4608  *  \param [in,out] entries - the sequence describing parameters of a support of each
4609  *         part of \a this field. Each item of this sequence consists of two parts. The
4610  *         first part describes a type of mesh entity and an id of discretization of a
4611  *         current field part. The second part describes a range of values [begin,end)
4612  *         within the returned array relating to the current field part.
4613  *  \return DataArrayDouble * - the pointer to the field values array.
4614  *  \throw If the number of underlying meshes is not equal to 1.
4615  *  \throw If no field values are available.
4616  *  \sa getUndergroundDataArray()
4617  */
4618 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4619 {
4620   if(_field_per_mesh.size()!=1)
4621     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4622   if(_field_per_mesh[0]==0)
4623     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4624   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4625   return getUndergroundDataArrayDouble();
4626 }
4627
4628 /*!
4629  * Returns a pointer to the underground DataArrayDouble instance and a
4630  * sequence describing parameters of a support of each part of \a this field. The
4631  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4632  * direct access to the field values. This method is intended for the field lying on one
4633  * mesh only.
4634  *  \param [in,out] entries - the sequence describing parameters of a support of each
4635  *         part of \a this field. Each item of this sequence consists of two parts. The
4636  *         first part describes a type of mesh entity and an id of discretization of a
4637  *         current field part. The second part describes a range of values [begin,end)
4638  *         within the returned array relating to the current field part.
4639  *  \return DataArrayDouble * - the pointer to the field values array.
4640  *  \throw If the number of underlying meshes is not equal to 1.
4641  *  \throw If no field values are available.
4642  *  \sa getUndergroundDataArray()
4643  */
4644 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4645 {
4646   return getUndergroundDataArrayDoubleExt(entries);
4647 }
4648
4649 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order,
4650                                                      const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4651 {
4652   DataArrayDouble *arr=getOrCreateAndGetArrayDouble();
4653   arr->setInfoAndChangeNbOfCompo(infos);
4654 }
4655
4656 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4657 {
4658 }
4659
4660 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
4661 {
4662   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
4663   ret->deepCpyLeavesFrom(*this);
4664   return ret.retn();
4665 }
4666
4667 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
4668 {
4669   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
4670   if((const DataArrayDouble *)_arr)
4671     ret->_arr=_arr->deepCpy();
4672   return ret.retn();
4673 }
4674
4675 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
4676 {
4677   if(!arr)
4678     _arr=0;
4679   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
4680   if(!arrC)
4681     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
4682   arrC->incrRef();
4683   _arr=arrC;
4684 }
4685
4686 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4687 {
4688   return DataArrayDouble::New();
4689 }
4690
4691 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
4692 {
4693   DataArrayDouble *ret=_arr;
4694   if(ret)
4695     return ret;
4696   _arr=DataArrayDouble::New();
4697   return _arr;
4698 }
4699
4700 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
4701 {
4702   return getOrCreateAndGetArrayDouble();
4703 }
4704
4705 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
4706 {
4707   const DataArrayDouble *ret=_arr;
4708   if(ret)
4709     return ret;
4710   DataArrayDouble *ret2=DataArrayDouble::New();
4711   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
4712   return ret2;
4713 }
4714
4715 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
4716 {
4717   return getOrCreateAndGetArrayDouble();
4718 }
4719
4720 //= MEDFileIntField1TSWithoutSDA
4721
4722 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const char *fieldName, int csit, int iteration, int order,
4723                                                                 const std::vector<std::string>& infos)
4724 {
4725   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4726 }
4727
4728 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4729 {
4730 }
4731
4732 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order,
4733                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4734 {
4735   DataArrayInt *arr=getOrCreateAndGetArrayInt();
4736   arr->setInfoAndChangeNbOfCompo(infos);
4737 }
4738
4739 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
4740 {
4741   return TYPE_STR;
4742 }
4743
4744 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const throw(INTERP_KERNEL::Exception)
4745 {
4746   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
4747   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4748   ret->deepCpyLeavesFrom(*this);
4749   const DataArrayInt *arr(_arr);
4750   if(arr)
4751     {
4752       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
4753       ret->setArray(arr2);
4754     }
4755   return ret.retn();
4756 }
4757
4758 /*!
4759  * Returns a pointer to the underground DataArrayInt instance. So the
4760  * caller should not decrRef() it. This method allows for a direct access to the field
4761  * values. This method is quite unusable if there is more than a nodal field or a cell
4762  * field on single geometric cell type. 
4763  *  \return DataArrayInt * - the pointer to the field values array.
4764  */
4765 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4766 {
4767   return getUndergroundDataArrayInt();
4768 }
4769
4770 /*!
4771  * Returns a pointer to the underground DataArrayInt instance. So the
4772  * caller should not decrRef() it. This method allows for a direct access to the field
4773  * values. This method is quite unusable if there is more than a nodal field or a cell
4774  * field on single geometric cell type. 
4775  *  \return DataArrayInt * - the pointer to the field values array.
4776  */
4777 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const throw(INTERP_KERNEL::Exception)
4778 {
4779   const DataArrayInt *ret=_arr;
4780   if(ret)
4781     return const_cast<DataArrayInt *>(ret);
4782   else
4783     return 0;
4784 }
4785
4786 /*!
4787  * Returns a pointer to the underground DataArrayInt instance and a
4788  * sequence describing parameters of a support of each part of \a this field. The
4789  * caller should not decrRef() the returned DataArrayInt. This method allows for a
4790  * direct access to the field values. This method is intended for the field lying on one
4791  * mesh only.
4792  *  \param [in,out] entries - the sequence describing parameters of a support of each
4793  *         part of \a this field. Each item of this sequence consists of two parts. The
4794  *         first part describes a type of mesh entity and an id of discretization of a
4795  *         current field part. The second part describes a range of values [begin,end)
4796  *         within the returned array relating to the current field part.
4797  *  \return DataArrayInt * - the pointer to the field values array.
4798  *  \throw If the number of underlying meshes is not equal to 1.
4799  *  \throw If no field values are available.
4800  *  \sa getUndergroundDataArray()
4801  */
4802 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4803 {
4804   return getUndergroundDataArrayIntExt(entries);
4805 }
4806
4807 /*!
4808  * Returns a pointer to the underground DataArrayInt instance and a
4809  * sequence describing parameters of a support of each part of \a this field. The
4810  * caller should not decrRef() the returned DataArrayInt. This method allows for a
4811  * direct access to the field values. This method is intended for the field lying on one
4812  * mesh only.
4813  *  \param [in,out] entries - the sequence describing parameters of a support of each
4814  *         part of \a this field. Each item of this sequence consists of two parts. The
4815  *         first part describes a type of mesh entity and an id of discretization of a
4816  *         current field part. The second part describes a range of values [begin,end)
4817  *         within the returned array relating to the current field part.
4818  *  \return DataArrayInt * - the pointer to the field values array.
4819  *  \throw If the number of underlying meshes is not equal to 1.
4820  *  \throw If no field values are available.
4821  *  \sa getUndergroundDataArray()
4822  */
4823 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4824 {
4825   if(_field_per_mesh.size()!=1)
4826     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4827   if(_field_per_mesh[0]==0)
4828     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4829   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4830   return getUndergroundDataArrayInt();
4831 }
4832
4833 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
4834 {
4835   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
4836   ret->deepCpyLeavesFrom(*this);
4837   return ret.retn();
4838 }
4839
4840 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
4841 {
4842   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
4843   if((const DataArrayInt *)_arr)
4844     ret->_arr=_arr->deepCpy();
4845   return ret.retn();
4846 }
4847
4848 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
4849 {
4850   if(!arr)
4851     _arr=0;
4852   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
4853   if(!arrC)
4854     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
4855   arrC->incrRef();
4856   _arr=arrC;
4857 }
4858
4859 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4860 {
4861   return DataArrayInt::New();
4862 }
4863
4864 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
4865 {
4866   DataArrayInt *ret=_arr;
4867   if(ret)
4868     return ret;
4869   _arr=DataArrayInt::New();
4870   return _arr;
4871 }
4872
4873 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
4874 {
4875   return getOrCreateAndGetArrayInt();
4876 }
4877
4878 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
4879 {
4880   const DataArrayInt *ret=_arr;
4881   if(ret)
4882     return ret;
4883   DataArrayInt *ret2=DataArrayInt::New();
4884   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
4885   return ret2;
4886 }
4887
4888 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
4889 {
4890   return getOrCreateAndGetArrayInt();
4891 }
4892
4893 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
4894 {
4895 }
4896
4897 //= MEDFileAnyTypeField1TS
4898
4899 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName) throw(INTERP_KERNEL::Exception)
4900 {
4901   med_field_type typcha;
4902   //
4903   std::vector<std::string> infos;
4904   std::string dtunit,fieldName;
4905   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
4906   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
4907   switch(typcha)
4908     {
4909     case MED_FLOAT64:
4910       {
4911         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4912         break;
4913       }
4914     case MED_INT32:
4915       {
4916         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4917         break;
4918       }
4919     default:
4920       {
4921         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
4922         throw INTERP_KERNEL::Exception(oss.str().c_str());
4923       }
4924     }
4925   ret->setDtUnit(dtunit.c_str());
4926   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
4927   //
4928   med_int numdt,numit;
4929   med_float dt;
4930   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
4931   ret->setTime(numdt,numit,dt);
4932   ret->_csit=1;
4933   ret->finishLoading(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
4934   return ret.retn();
4935 }
4936
4937 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName) throw(INTERP_KERNEL::Exception)
4938 try:MEDFileFieldGlobsReal(fileName)
4939 {
4940   MEDFileUtilities::CheckFileForRead(fileName);
4941   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
4942   _content=BuildContentFrom(fid,fileName);
4943   loadGlobals(fid);
4944 }
4945 catch(INTERP_KERNEL::Exception& e)
4946   {
4947     throw e;
4948   }
4949
4950 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
4951 {
4952   med_field_type typcha;
4953   std::vector<std::string> infos;
4954   std::string dtunit;
4955   int iii=-1;
4956   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
4957   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
4958   switch(typcha)
4959     {
4960     case MED_FLOAT64:
4961       {
4962         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4963         break;
4964       }
4965     case MED_INT32:
4966       {
4967         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4968         break;
4969       }
4970     default:
4971       {
4972         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
4973         throw INTERP_KERNEL::Exception(oss.str().c_str());
4974       }
4975     }
4976   ret->setDtUnit(dtunit.c_str());
4977   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
4978   //
4979   if(nbSteps<1)
4980     {
4981       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
4982       throw INTERP_KERNEL::Exception(oss.str().c_str());
4983     }
4984   //
4985   med_int numdt,numit;
4986   med_float dt;
4987   MEDfieldComputingStepInfo(fid,fieldName,1,&numdt,&numit,&dt);
4988   ret->setTime(numdt,numit,dt);
4989   ret->_csit=1;
4990   ret->finishLoading(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
4991   return ret.retn();
4992 }
4993
4994 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
4995 try:MEDFileFieldGlobsReal(fileName)
4996 {
4997   MEDFileUtilities::CheckFileForRead(fileName);
4998   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
4999   _content=BuildContentFrom(fid,fileName,fieldName);
5000   loadGlobals(fid);
5001 }
5002 catch(INTERP_KERNEL::Exception& e)
5003   {
5004     throw e;
5005   }
5006
5007 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const char *fileName) throw(INTERP_KERNEL::Exception)
5008 {
5009   if(!c)
5010     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5011   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5012     {
5013       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5014       ret->setFileName(fileName);
5015       ret->_content=c; c->incrRef();
5016       return ret.retn();
5017     }
5018   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5019     {
5020       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5021       ret->setFileName(fileName);
5022       ret->_content=c; c->incrRef();
5023       return ret.retn();
5024     }
5025   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5026 }
5027
5028 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
5029 {
5030   MEDFileUtilities::CheckFileForRead(fileName);
5031   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5032   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName);
5033   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5034   ret->loadGlobals(fid);
5035   return ret.retn();
5036 }
5037
5038 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
5039 {
5040   MEDFileUtilities::CheckFileForRead(fileName);
5041   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5042   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName);
5043   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5044   ret->loadGlobals(fid);
5045   return ret.retn();
5046 }
5047
5048 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
5049 {
5050   MEDFileUtilities::CheckFileForRead(fileName);
5051   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5052   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order);
5053   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5054   ret->loadGlobals(fid);
5055   return ret.retn();
5056 }
5057
5058 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
5059 {
5060   med_field_type typcha;
5061   std::vector<std::string> infos;
5062   std::string dtunit;
5063   int iii=-1;
5064   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5065   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5066   switch(typcha)
5067     {
5068     case MED_FLOAT64:
5069       {
5070         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5071         break;
5072       }
5073     case MED_INT32:
5074       {
5075         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5076         break;
5077       }
5078     default:
5079       {
5080         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName,iteration,order) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5081         throw INTERP_KERNEL::Exception(oss.str().c_str());
5082       }
5083     }
5084   ret->setDtUnit(dtunit.c_str());
5085   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5086   //
5087   bool found=false;
5088   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5089   for(int i=0;i<nbOfStep2 && !found;i++)
5090     {
5091       med_int numdt,numit;
5092       med_float dt;
5093       MEDfieldComputingStepInfo(fid,fieldName,i+1,&numdt,&numit,&dt);
5094       if(numdt==iteration && numit==order)
5095         {
5096           found=true;
5097           ret->_csit=i+1;
5098         }
5099       else
5100         dtits[i]=std::pair<int,int>(numdt,numit);
5101     }
5102   if(!found)
5103     {
5104       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5105       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5106         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5107       throw INTERP_KERNEL::Exception(oss.str().c_str());
5108     }
5109   ret->finishLoading(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5110   return ret.retn();
5111 }
5112
5113 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
5114 try:MEDFileFieldGlobsReal(fileName)
5115 {
5116   MEDFileUtilities::CheckFileForRead(fileName);
5117   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5118   _content=BuildContentFrom(fid,fileName,fieldName,iteration,order);
5119   loadGlobals(fid);
5120 }
5121 catch(INTERP_KERNEL::Exception& e)
5122   {
5123     throw e;
5124   }
5125
5126 /*!
5127  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5128  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5129  *
5130  * \warning this is a shallow copy constructor
5131  */
5132 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5133 {
5134   if(!shallowCopyOfContent)
5135     {
5136       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5137       otherPtr->incrRef();
5138       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5139     }
5140   else
5141     {
5142       _content=other.shallowCpy();
5143     }
5144 }
5145
5146 int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, const char *fileName, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut) throw(INTERP_KERNEL::Exception)
5147 {
5148   if(checkFieldId)
5149     {
5150       int nbFields=MEDnField(fid);
5151       if(fieldIdCFormat>=nbFields)
5152         {
5153           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5154           throw INTERP_KERNEL::Exception(oss.str().c_str());
5155         }
5156     }
5157   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5158   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5159   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5160   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5161   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5162   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5163   med_bool localMesh;
5164   int nbOfStep;
5165   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5166   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5167   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5168   infos.clear(); infos.resize(ncomp);
5169   for(int j=0;j<ncomp;j++)
5170     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5171   return nbOfStep;
5172 }
5173
5174 /*!
5175  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5176  * 
5177  * \param [out]
5178  * \return in case of success the number of time steps available for the field with name \a fieldName.
5179  */
5180 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const char *fileName, const char *fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut) throw(INTERP_KERNEL::Exception)
5181 {
5182   int nbFields=MEDnField(fid);
5183   bool found=false;
5184   std::vector<std::string> fns(nbFields);
5185   int nbOfStep2=-1;
5186   for(int i=0;i<nbFields && !found;i++)
5187     {
5188       std::string tmp;
5189       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5190       fns[i]=tmp;
5191       found=(tmp==fieldName);
5192       if(found)
5193         posCFormat=i;
5194     }
5195   if(!found)
5196     {
5197       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5198       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5199         oss << "\"" << *it << "\" ";
5200       throw INTERP_KERNEL::Exception(oss.str().c_str());
5201     }
5202   return nbOfStep2;
5203 }
5204
5205 /*!
5206  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5207  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5208  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5209  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5210  * to keep a valid instance.
5211  * 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.
5212  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5213  * 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.
5214  *
5215  * \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.
5216  * \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.
5217  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5218  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5219  * \param [in] newLocName is the new localization name.
5220  * \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.
5221  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5222  */
5223 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newPflName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
5224 {
5225   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5226   std::string oldPflName=disc->getProfile();
5227   std::vector<std::string> vv=getPflsReallyUsedMulti();
5228   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5229   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5230     {
5231       disc->setProfile(newPflName);
5232       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5233       pfl->setName(newPflName);
5234     }
5235   else
5236     {
5237       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5238       throw INTERP_KERNEL::Exception(oss.str().c_str());
5239     }
5240 }
5241
5242 /*!
5243  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5244  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5245  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5246  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5247  * to keep a valid instance.
5248  * 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.
5249  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5250  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5251  * 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.
5252  *
5253  * \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.
5254  * \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.
5255  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5256  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5257  * \param [in] newLocName is the new localization name.
5258  * \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.
5259  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5260  */
5261 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newLocName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
5262 {
5263   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5264   std::string oldLocName=disc->getLocalization();
5265   std::vector<std::string> vv=getLocsReallyUsedMulti();
5266   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5267   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5268     {
5269       disc->setLocalization(newLocName);
5270       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5271       loc.setName(newLocName);
5272     }
5273   else
5274     {
5275       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5276       throw INTERP_KERNEL::Exception(oss.str().c_str());
5277     }
5278 }
5279
5280 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() throw(INTERP_KERNEL::Exception)
5281 {
5282   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5283   if(!ret)
5284     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5285   return ret;
5286 }
5287
5288 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const throw(INTERP_KERNEL::Exception)
5289 {
5290   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5291   if(!ret)
5292     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5293   return ret;
5294 }
5295
5296 /*!
5297  * Writes \a this field into a MED file specified by its name.
5298  *  \param [in] fileName - the MED file name.
5299  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5300  * - 2 - erase; an existing file is removed.
5301  * - 1 - append; same data should not be present in an existing file.
5302  * - 0 - overwrite; same data present in an existing file is overwritten.
5303  *  \throw If the field name is not set.
5304  *  \throw If no field data is set.
5305  *  \throw If \a mode == 1 and the same data is present in an existing file.
5306  */
5307 void MEDFileAnyTypeField1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
5308 {
5309   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5310   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
5311   writeLL(fid);
5312 }
5313
5314 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
5315 {
5316   int nbComp=getNumberOfComponents();
5317   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5318   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5319   for(int i=0;i<nbComp;i++)
5320     {
5321       std::string info=getInfo()[i];
5322       std::string c,u;
5323       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5324       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5325       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5326     }
5327   if(getName().empty())
5328     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5329   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5330   writeGlobals(fid,*this);
5331   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5332 }
5333
5334 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySize() const
5335 {
5336   std::size_t ret=0;
5337   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5338     ret+=_content->getHeapMemorySize();
5339   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
5340 }
5341
5342 /*!
5343  * Returns a string describing \a this field. This string is outputted 
5344  * by \c print Python command.
5345  */
5346 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5347 {
5348   std::ostringstream oss;
5349   contentNotNullBase()->simpleRepr(0,oss,-1);
5350   simpleReprGlobs(oss);
5351   return oss.str();
5352 }
5353
5354 /*!
5355  * This method returns all profiles whose name is non empty used.
5356  * \b WARNING If profile is used several times it will be reported \b only \b once.
5357  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5358  */
5359 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5360 {
5361   return contentNotNullBase()->getPflsReallyUsed2();
5362 }
5363
5364 /*!
5365  * This method returns all localizations whose name is non empty used.
5366  * \b WARNING If localization is used several times it will be reported \b only \b once.
5367  */
5368 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5369 {
5370   return contentNotNullBase()->getLocsReallyUsed2();
5371 }
5372
5373 /*!
5374  * This method returns all profiles whose name is non empty used.
5375  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5376  */
5377 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5378 {
5379   return contentNotNullBase()->getPflsReallyUsedMulti2();
5380 }
5381
5382 /*!
5383  * This method returns all localizations whose name is non empty used.
5384  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5385  */
5386 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5387 {
5388   return contentNotNullBase()->getLocsReallyUsedMulti2();
5389 }
5390
5391 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5392 {
5393   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5394 }
5395
5396 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5397 {
5398   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5399 }
5400
5401 int MEDFileAnyTypeField1TS::getDimension() const
5402 {
5403   return contentNotNullBase()->getDimension();
5404 }
5405
5406 int MEDFileAnyTypeField1TS::getIteration() const
5407 {
5408   return contentNotNullBase()->getIteration();
5409 }
5410
5411 int MEDFileAnyTypeField1TS::getOrder() const
5412 {
5413   return contentNotNullBase()->getOrder();
5414 }
5415
5416 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5417 {
5418   return contentNotNullBase()->getTime(iteration,order);
5419 }
5420
5421 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5422 {
5423   contentNotNullBase()->setTime(iteration,order,val);
5424 }
5425
5426 std::string MEDFileAnyTypeField1TS::getName() const
5427 {
5428   return contentNotNullBase()->getName();
5429 }
5430
5431 void MEDFileAnyTypeField1TS::setName(const char *name)
5432 {
5433   contentNotNullBase()->setName(name);
5434 }
5435
5436 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5437 {
5438   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5439 }
5440
5441 std::string MEDFileAnyTypeField1TS::getDtUnit() const throw(INTERP_KERNEL::Exception)
5442 {
5443   return contentNotNullBase()->getDtUnit();
5444 }
5445
5446 void MEDFileAnyTypeField1TS::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
5447 {
5448   contentNotNullBase()->setDtUnit(dtUnit);
5449 }
5450
5451 std::string MEDFileAnyTypeField1TS::getMeshName() const throw(INTERP_KERNEL::Exception)
5452 {
5453   return contentNotNullBase()->getMeshName();
5454 }
5455
5456 void MEDFileAnyTypeField1TS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
5457 {
5458   contentNotNullBase()->setMeshName(newMeshName);
5459 }
5460
5461 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
5462 {
5463   return contentNotNullBase()->changeMeshNames(modifTab);
5464 }
5465
5466 int MEDFileAnyTypeField1TS::getMeshIteration() const throw(INTERP_KERNEL::Exception)
5467 {
5468   return contentNotNullBase()->getMeshIteration();
5469 }
5470
5471 int MEDFileAnyTypeField1TS::getMeshOrder() const throw(INTERP_KERNEL::Exception)
5472 {
5473   return contentNotNullBase()->getMeshOrder();
5474 }
5475
5476 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5477 {
5478   return contentNotNullBase()->getNumberOfComponents();
5479 }
5480
5481 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5482 {
5483   return contentNotNullBase()->isDealingTS(iteration,order);
5484 }
5485
5486 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5487 {
5488   return contentNotNullBase()->getDtIt();
5489 }
5490
5491 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5492 {
5493   contentNotNullBase()->fillIteration(p);
5494 }
5495
5496 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
5497 {
5498   contentNotNullBase()->fillTypesOfFieldAvailable(types);
5499 }
5500
5501 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
5502 {
5503   contentNotNullBase()->setInfo(infos);
5504 }
5505
5506 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
5507 {
5508   return contentNotNullBase()->getInfo();
5509 }
5510 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
5511 {
5512   return contentNotNullBase()->getInfo();
5513 }
5514
5515 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
5516 {
5517   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5518 }
5519
5520 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
5521 {
5522   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5523 }
5524
5525 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
5526 {
5527   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
5528 }
5529
5530 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
5531 {
5532   return contentNotNullBase()->getTypesOfFieldAvailable();
5533 }
5534
5535 std::vector< std::vector<std::pair<int,int> > > MEDFileAnyTypeField1TS::getFieldSplitedByType(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
5536                                                                                        std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
5537 {
5538   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5539 }
5540
5541 /*!
5542  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
5543  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5544  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
5545  */
5546 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const throw(INTERP_KERNEL::Exception)
5547 {
5548   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5549   if(!content)
5550     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
5551   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
5552   std::size_t sz(contentsSplit.size());
5553   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5554   for(std::size_t i=0;i<sz;i++)
5555     {
5556       ret[i]=shallowCpy();
5557       ret[i]->_content=contentsSplit[i];
5558     }
5559   return ret;
5560 }
5561
5562 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const throw(INTERP_KERNEL::Exception)
5563 {
5564   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
5565   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5566     ret->_content=_content->deepCpy();
5567   ret->deepCpyGlobs(*this);
5568   return ret.retn();
5569 }
5570
5571 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
5572 {
5573   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
5574 }
5575
5576 //= MEDFileField1TS
5577
5578 /*!
5579  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5580  * the first field that has been read from a specified MED file.
5581  *  \param [in] fileName - the name of the MED file to read.
5582  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5583  *          is to delete this field using decrRef() as it is no more needed.
5584  *  \throw If reading the file fails.
5585  */
5586 MEDFileField1TS *MEDFileField1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
5587 {
5588   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName);
5589   ret->contentNotNull();
5590   return ret.retn();
5591 }
5592
5593 /*!
5594  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5595  * a given field that has been read from a specified MED file.
5596  *  \param [in] fileName - the name of the MED file to read.
5597  *  \param [in] fieldName - the name of the field to read.
5598  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5599  *          is to delete this field using decrRef() as it is no more needed.
5600  *  \throw If reading the file fails.
5601  *  \throw If there is no field named \a fieldName in the file.
5602  */
5603 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
5604 {
5605   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName);
5606   ret->contentNotNull();
5607   return ret.retn();
5608 }
5609
5610 /*!
5611  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
5612  * a given field that has been read from a specified MED file.
5613  *  \param [in] fileName - the name of the MED file to read.
5614  *  \param [in] fieldName - the name of the field to read.
5615  *  \param [in] iteration - the iteration number of a required time step.
5616  *  \param [in] order - the iteration order number of required time step.
5617  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5618  *          is to delete this field using decrRef() as it is no more needed.
5619  *  \throw If reading the file fails.
5620  *  \throw If there is no field named \a fieldName in the file.
5621  *  \throw If the required time step is missing from the file.
5622  */
5623 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
5624 {
5625   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,iteration,order);
5626   ret->contentNotNull();
5627   return ret.retn();
5628 }
5629
5630 /*!
5631  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5632  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5633  *
5634  * Returns a new instance of MEDFileField1TS holding either a shallow copy
5635  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
5636  * \warning this is a shallow copy constructor
5637  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
5638  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
5639  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5640  *          is to delete this field using decrRef() as it is no more needed.
5641  */
5642 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
5643 {
5644   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
5645   ret->contentNotNull();
5646   return ret.retn();
5647 }
5648
5649 /*!
5650  * Returns a new empty instance of MEDFileField1TS.
5651  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5652  *          is to delete this field using decrRef() as it is no more needed.
5653  */
5654 MEDFileField1TS *MEDFileField1TS::New()
5655 {
5656   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
5657   ret->contentNotNull();
5658   return ret.retn();
5659 }
5660
5661 /*!
5662  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
5663  * following the given input policy.
5664  *
5665  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
5666  *                            By default (true) the globals are deeply copied.
5667  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
5668  */
5669 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
5670 {
5671   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
5672   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5673   if(content)
5674     {
5675       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
5676       if(!contc)
5677         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
5678       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
5679       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
5680     }
5681   else
5682     ret=MEDFileIntField1TS::New();
5683   if(deepCpyGlobs)
5684     ret->deepCpyGlobs(*this);
5685   else
5686     ret->shallowCpyGlobs(*this);
5687   return ret.retn();
5688 }
5689
5690 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const throw(INTERP_KERNEL::Exception)
5691 {
5692   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
5693   if(!pt)
5694     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
5695   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
5696   if(!ret)
5697     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
5698   return ret;
5699 }
5700
5701 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() throw(INTERP_KERNEL::Exception)
5702 {
5703   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
5704   if(!pt)
5705     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
5706   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
5707   if(!ret)
5708     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
5709   return ret;
5710 }
5711
5712 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
5713 {
5714   if(!f)
5715     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
5716   if(!((DataArray*)arr))
5717     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
5718   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
5719   if(!arrOutC)
5720     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
5721   f->setArray(arrOutC);
5722 }
5723
5724 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
5725 {
5726   if(!((DataArray*)arr))
5727     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
5728   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
5729   if(!arrOutC)
5730     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
5731   arrOutC->incrRef();
5732   return arrOutC;
5733 }
5734
5735 MEDFileField1TS::MEDFileField1TS(const char *fileName) throw(INTERP_KERNEL::Exception)
5736 try:MEDFileAnyTypeField1TS(fileName)
5737 {
5738 }
5739 catch(INTERP_KERNEL::Exception& e)
5740   { throw e; }
5741
5742 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
5743 try:MEDFileAnyTypeField1TS(fileName,fieldName)
5744 {
5745 }
5746 catch(INTERP_KERNEL::Exception& e)
5747   { throw e; }
5748
5749 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
5750 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order)
5751 {
5752 }
5753 catch(INTERP_KERNEL::Exception& e)
5754   { throw e; }
5755
5756 /*!
5757  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5758  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5759  *
5760  * \warning this is a shallow copy constructor
5761  */
5762 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
5763 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
5764 {
5765 }
5766 catch(INTERP_KERNEL::Exception& e)
5767   { throw e; }
5768
5769 MEDFileField1TS::MEDFileField1TS()
5770 {
5771   _content=new MEDFileField1TSWithoutSDA;
5772 }
5773
5774 /*!
5775  * Returns a new MEDCouplingFieldDouble of a given type lying on
5776  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
5777  * has not been constructed via file reading, an exception is thrown.
5778  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5779  *  \param [in] type - a spatial discretization of interest.
5780  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5781  *  \param [in] renumPol - specifies how to permute values of the result field according to
5782  *          the optional numbers of cells and nodes, if any. The valid values are
5783  *          - 0 - do not permute.
5784  *          - 1 - permute cells.
5785  *          - 2 - permute nodes.
5786  *          - 3 - permute cells and nodes.
5787  *
5788  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5789  *          caller is to delete this field using decrRef() as it is no more needed. 
5790  *  \throw If \a this field has not been constructed via file reading.
5791  *  \throw If the MED file is not readable.
5792  *  \throw If there is no mesh in the MED file.
5793  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5794  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5795  *  \sa getFieldOnMeshAtLevel()
5796  */
5797 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
5798 {
5799   if(getFileName2().empty())
5800     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
5801   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5802   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut,*contentNotNull());
5803   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5804   return ret.retn();
5805 }
5806
5807 /*!
5808  * Returns a new MEDCouplingFieldDouble of a given type lying on
5809  * the top level cells of the first mesh in MED file. If \a this field 
5810  * has not been constructed via file reading, an exception is thrown.
5811  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5812  *  \param [in] type - a spatial discretization of interest.
5813  *  \param [in] renumPol - specifies how to permute values of the result field according to
5814  *          the optional numbers of cells and nodes, if any. The valid values are
5815  *          - 0 - do not permute.
5816  *          - 1 - permute cells.
5817  *          - 2 - permute nodes.
5818  *          - 3 - permute cells and nodes.
5819  *
5820  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5821  *          caller is to delete this field using decrRef() as it is no more needed. 
5822  *  \throw If \a this field has not been constructed via file reading.
5823  *  \throw If the MED file is not readable.
5824  *  \throw If there is no mesh in the MED file.
5825  *  \throw If no field values of the given \a type.
5826  *  \throw If no field values lying on the top level support.
5827  *  \sa getFieldAtLevel()
5828  */
5829 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const throw(INTERP_KERNEL::Exception)
5830 {
5831   if(getFileName2().empty())
5832     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
5833   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5834   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,0,renumPol,this,arrOut,*contentNotNull());
5835   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5836   return ret.retn();
5837 }
5838
5839 /*!
5840  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
5841  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5842  *  \param [in] type - a spatial discretization of the new field.
5843  *  \param [in] mesh - the supporting mesh.
5844  *  \param [in] renumPol - specifies how to permute values of the result field according to
5845  *          the optional numbers of cells and nodes, if any. The valid values are
5846  *          - 0 - do not permute.
5847  *          - 1 - permute cells.
5848  *          - 2 - permute nodes.
5849  *          - 3 - permute cells and nodes.
5850  *
5851  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5852  *          caller is to delete this field using decrRef() as it is no more needed. 
5853  *  \throw If no field of \a this is lying on \a mesh.
5854  *  \throw If the mesh is empty.
5855  *  \throw If no field values of the given \a type are available.
5856  *  \sa getFieldAtLevel()
5857  *  \sa getFieldOnMeshAtLevel() 
5858  */
5859 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
5860 {
5861   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5862   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
5863   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5864   return ret.retn();
5865 }
5866
5867 /*!
5868  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
5869  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5870  *  \param [in] type - a spatial discretization of interest.
5871  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5872  *  \param [in] mesh - the supporting mesh.
5873  *  \param [in] renumPol - specifies how to permute values of the result field according to
5874  *          the optional numbers of cells and nodes, if any. The valid values are
5875  *          - 0 - do not permute.
5876  *          - 1 - permute cells.
5877  *          - 2 - permute nodes.
5878  *          - 3 - permute cells and nodes.
5879  *
5880  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5881  *          caller is to delete this field using decrRef() as it is no more needed. 
5882  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5883  *  \throw If no field of \a this is lying on \a mesh.
5884  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5885  *  \sa getFieldAtLevel()
5886  *  \sa getFieldOnMeshAtLevel() 
5887  */
5888 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
5889 {
5890   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5891   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
5892   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5893   return ret.retn();
5894 }
5895
5896 /*!
5897  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
5898  * This method is called "Old" because in MED3 norm a field has only one meshName
5899  * attached, so this method is for readers of MED2 files. If \a this field 
5900  * has not been constructed via file reading, an exception is thrown.
5901  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5902  *  \param [in] type - a spatial discretization of interest.
5903  *  \param [in] mName - a name of the supporting mesh.
5904  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5905  *  \param [in] renumPol - specifies how to permute values of the result field according to
5906  *          the optional numbers of cells and nodes, if any. The valid values are
5907  *          - 0 - do not permute.
5908  *          - 1 - permute cells.
5909  *          - 2 - permute nodes.
5910  *          - 3 - permute cells and nodes.
5911  *
5912  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5913  *          caller is to delete this field using decrRef() as it is no more needed. 
5914  *  \throw If the MED file is not readable.
5915  *  \throw If there is no mesh named \a mName in the MED file.
5916  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5917  *  \throw If \a this field has not been constructed via file reading.
5918  *  \throw If no field of \a this is lying on the mesh named \a mName.
5919  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5920  *  \sa getFieldAtLevel()
5921  */
5922 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
5923 {
5924   if(getFileName2().empty())
5925     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
5926   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5927   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
5928   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5929   return ret.retn();
5930 }
5931
5932 /*!
5933  * Returns values and a profile of the field of a given type lying on a given support.
5934  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5935  *  \param [in] type - a spatial discretization of the field.
5936  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5937  *  \param [in] mesh - the supporting mesh.
5938  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5939  *          field of interest lies on. If the field lies on all entities of the given
5940  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5941  *          using decrRef() as it is no more needed.  
5942  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5943  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5944  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5945  *  \throw If no field of \a this is lying on \a mesh.
5946  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5947  */
5948 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
5949 {
5950   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
5951   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
5952 }
5953
5954 /*!
5955  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
5956  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
5957  * "Sort By Type"), if not, an exception is thrown. 
5958  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5959  *  \param [in] field - the field to add to \a this.
5960  *  \throw If the name of \a field is empty.
5961  *  \throw If the data array of \a field is not set.
5962  *  \throw If the data array is already allocated but has different number of components
5963  *         than \a field.
5964  *  \throw If the underlying mesh of \a field has no name.
5965  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
5966  */
5967 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
5968 {
5969   setFileName("");
5970   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
5971 }
5972
5973 /*!
5974  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
5975  * of a given mesh are used as the support of the given field (a real support is not used). 
5976  * Elements of the given mesh must be sorted suitable for writing to MED file.
5977  * Order of underlying mesh entities of the given field specified by \a profile parameter
5978  * is not prescribed; this method permutes field values to have them sorted by element
5979  * type as required for writing to MED file. A new profile is added only if no equal
5980  * profile is missing.
5981  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5982  *  \param [in] field - the field to add to \a this.
5983  *  \param [in] mesh - the supporting mesh of \a field.
5984  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
5985  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
5986  *  \throw If either \a field or \a mesh or \a profile has an empty name.
5987  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5988  *  \throw If the data array of \a field is not set.
5989  *  \throw If the data array of \a this is already allocated but has different number of
5990  *         components than \a field.
5991  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5992  *  \sa setFieldNoProfileSBT()
5993  */
5994 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
5995 {
5996   setFileName("");
5997   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
5998 }
5999
6000 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const throw(INTERP_KERNEL::Exception)
6001 {
6002   return new MEDFileField1TS(*this);
6003 }
6004
6005 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
6006 {
6007   return contentNotNull()->getUndergroundDataArrayDouble();
6008 }
6009
6010 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
6011 {
6012   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6013 }
6014
6015 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6016                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
6017 {
6018   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6019 }
6020
6021 //= MEDFileIntField1TS
6022
6023 MEDFileIntField1TS *MEDFileIntField1TS::New()
6024 {
6025   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6026   ret->contentNotNull();
6027   return ret.retn();
6028 }
6029
6030 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
6031 {
6032   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName);
6033   ret->contentNotNull();
6034   return ret.retn();
6035 }
6036
6037 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
6038 {
6039   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName);
6040   ret->contentNotNull();
6041   return ret.retn();
6042 }
6043
6044 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
6045 {
6046   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,iteration,order);
6047   ret->contentNotNull();
6048   return ret.retn();
6049 }
6050
6051 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6052 {
6053   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6054   ret->contentNotNull();
6055   return ret.retn();
6056 }
6057
6058 MEDFileIntField1TS::MEDFileIntField1TS()
6059 {
6060   _content=new MEDFileIntField1TSWithoutSDA;
6061 }
6062
6063 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName) throw(INTERP_KERNEL::Exception)
6064 try:MEDFileAnyTypeField1TS(fileName)
6065 {
6066 }
6067 catch(INTERP_KERNEL::Exception& e)
6068   { throw e; }
6069
6070 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
6071 try:MEDFileAnyTypeField1TS(fileName,fieldName)
6072 {
6073 }
6074 catch(INTERP_KERNEL::Exception& e)
6075   { throw e; }
6076
6077 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
6078 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order)
6079 {
6080 }
6081 catch(INTERP_KERNEL::Exception& e)
6082   { throw e; }
6083
6084 /*!
6085  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6086  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6087  *
6088  * \warning this is a shallow copy constructor
6089  */
6090 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6091 {
6092 }
6093
6094 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const throw(INTERP_KERNEL::Exception)
6095 {
6096   return new MEDFileIntField1TS(*this);
6097 }
6098
6099 /*!
6100  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6101  * following the given input policy.
6102  *
6103  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6104  *                            By default (true) the globals are deeply copied.
6105  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6106  */
6107 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
6108 {
6109   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6110   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6111   if(content)
6112     {
6113       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6114       if(!contc)
6115         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6116       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6117       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6118     }
6119   else
6120     ret=MEDFileField1TS::New();
6121   if(deepCpyGlobs)
6122     ret->deepCpyGlobs(*this);
6123   else
6124     ret->shallowCpyGlobs(*this);
6125   return ret.retn();
6126 }
6127
6128 /*!
6129  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6130  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6131  * "Sort By Type"), if not, an exception is thrown. 
6132  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6133  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6134  *  \param [in] arrOfVals - the values of the field \a field used.
6135  *  \throw If the name of \a field is empty.
6136  *  \throw If the data array of \a field is not set.
6137  *  \throw If the data array is already allocated but has different number of components
6138  *         than \a field.
6139  *  \throw If the underlying mesh of \a field has no name.
6140  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6141  */
6142 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception)
6143 {
6144   setFileName("");
6145   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6146 }
6147
6148 /*!
6149  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
6150  * of a given mesh are used as the support of the given field (a real support is not used). 
6151  * Elements of the given mesh must be sorted suitable for writing to MED file.
6152  * Order of underlying mesh entities of the given field specified by \a profile parameter
6153  * is not prescribed; this method permutes field values to have them sorted by element
6154  * type as required for writing to MED file. A new profile is added only if no equal
6155  * profile is missing.
6156  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6157  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6158  *  \param [in] arrOfVals - the values of the field \a field used.
6159  *  \param [in] mesh - the supporting mesh of \a field.
6160  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
6161  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6162  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6163  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6164  *  \throw If the data array of \a field is not set.
6165  *  \throw If the data array of \a this is already allocated but has different number of
6166  *         components than \a field.
6167  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6168  *  \sa setFieldNoProfileSBT()
6169  */
6170 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
6171 {
6172   setFileName("");
6173   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6174 }
6175
6176 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const throw(INTERP_KERNEL::Exception)
6177 {
6178   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6179   if(!pt)
6180     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6181   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6182   if(!ret)
6183     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is not null but it is not of type int32 ! Reason is maybe that the read field has not the type INT32 !");
6184   return ret;
6185 }
6186
6187 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6188 {
6189   if(getFileName2().empty())
6190     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6191   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6192   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut2,*contentNotNull());
6193   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6194   if(!arrOutC)
6195     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6196   arrOut=arrOutC;
6197   return ret.retn();
6198 }
6199
6200 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
6201 {
6202   if(!((DataArray *)arr))
6203     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6204   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6205   if(!arrC)
6206     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6207   arrC->incrRef();
6208   return arrC;
6209 }
6210
6211 /*!
6212  * Returns a new MEDCouplingFieldDouble of a given type lying on
6213  * the top level cells of the first mesh in MED file. If \a this field 
6214  * has not been constructed via file reading, an exception is thrown.
6215  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6216  *  \param [in] type - a spatial discretization of interest.
6217  *  \param [out] arrOut - the DataArrayInt containing values of field.
6218  *  \param [in] renumPol - specifies how to permute values of the result field according to
6219  *          the optional numbers of cells and nodes, if any. The valid values are
6220  *          - 0 - do not permute.
6221  *          - 1 - permute cells.
6222  *          - 2 - permute nodes.
6223  *          - 3 - permute cells and nodes.
6224  *
6225  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6226  *          caller is to delete this field using decrRef() as it is no more needed. 
6227  *  \throw If \a this field has not been constructed via file reading.
6228  *  \throw If the MED file is not readable.
6229  *  \throw If there is no mesh in the MED file.
6230  *  \throw If no field values of the given \a type.
6231  *  \throw If no field values lying on the top level support.
6232  *  \sa getFieldAtLevel()
6233  */
6234 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6235 {
6236   if(getFileName2().empty())
6237     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6238   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6239   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,0,renumPol,this,arr,*contentNotNull());
6240   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6241   return ret.retn();
6242 }
6243
6244 /*!
6245  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6246  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6247  *  \param [in] type - a spatial discretization of the new field.
6248  *  \param [in] mesh - the supporting mesh.
6249  *  \param [out] arrOut - the DataArrayInt containing values of field.
6250  *  \param [in] renumPol - specifies how to permute values of the result field according to
6251  *          the optional numbers of cells and nodes, if any. The valid values are
6252  *          - 0 - do not permute.
6253  *          - 1 - permute cells.
6254  *          - 2 - permute nodes.
6255  *          - 3 - permute cells and nodes.
6256  *
6257  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6258  *          caller is to delete this field using decrRef() as it is no more needed. 
6259  *  \throw If no field of \a this is lying on \a mesh.
6260  *  \throw If the mesh is empty.
6261  *  \throw If no field values of the given \a type are available.
6262  *  \sa getFieldAtLevel()
6263  *  \sa getFieldOnMeshAtLevel() 
6264  */
6265 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6266 {
6267   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6268   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6269   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6270   return ret.retn();
6271 }
6272
6273 /*!
6274  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6275  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6276  *  \param [in] type - a spatial discretization of interest.
6277  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6278  *  \param [out] arrOut - the DataArrayInt containing values of field.
6279  *  \param [in] mesh - the supporting mesh.
6280  *  \param [in] renumPol - specifies how to permute values of the result field according to
6281  *          the optional numbers of cells and nodes, if any. The valid values are
6282  *          - 0 - do not permute.
6283  *          - 1 - permute cells.
6284  *          - 2 - permute nodes.
6285  *          - 3 - permute cells and nodes.
6286  *
6287  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6288  *          caller is to delete this field using decrRef() as it is no more needed. 
6289  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6290  *  \throw If no field of \a this is lying on \a mesh.
6291  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6292  *  \sa getFieldAtLevel()
6293  *  \sa getFieldOnMeshAtLevel() 
6294  */
6295 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6296 {
6297   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6298   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6299   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6300   return ret.retn();
6301 }
6302
6303 /*!
6304  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6305  * This method is called "Old" because in MED3 norm a field has only one meshName
6306  * attached, so this method is for readers of MED2 files. If \a this field 
6307  * has not been constructed via file reading, an exception is thrown.
6308  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6309  *  \param [in] type - a spatial discretization of interest.
6310  *  \param [in] mName - a name of the supporting mesh.
6311  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6312  *  \param [out] arrOut - the DataArrayInt containing values of field.
6313  *  \param [in] renumPol - specifies how to permute values of the result field according to
6314  *          the optional numbers of cells and nodes, if any. The valid values are
6315  *          - 0 - do not permute.
6316  *          - 1 - permute cells.
6317  *          - 2 - permute nodes.
6318  *          - 3 - permute cells and nodes.
6319  *
6320  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6321  *          caller is to delete this field using decrRef() as it is no more needed. 
6322  *  \throw If the MED file is not readable.
6323  *  \throw If there is no mesh named \a mName in the MED file.
6324  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6325  *  \throw If \a this field has not been constructed via file reading.
6326  *  \throw If no field of \a this is lying on the mesh named \a mName.
6327  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6328  *  \sa getFieldAtLevel()
6329  */
6330 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6331 {
6332   if(getFileName2().empty())
6333     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6334   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6335   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6336   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6337   return ret.retn();
6338 }
6339
6340 /*!
6341  * Returns values and a profile of the field of a given type lying on a given support.
6342  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6343  *  \param [in] type - a spatial discretization of the field.
6344  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6345  *  \param [in] mesh - the supporting mesh.
6346  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6347  *          field of interest lies on. If the field lies on all entities of the given
6348  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6349  *          using decrRef() as it is no more needed.  
6350  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6351  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6352  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6353  *  \throw If no field of \a this is lying on \a mesh.
6354  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6355  */
6356 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
6357 {
6358   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6359   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6360 }
6361
6362 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() throw(INTERP_KERNEL::Exception)
6363 {
6364   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6365   if(!pt)
6366     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6367   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6368   if(!ret)
6369     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is not null but it is not of type int32 ! Reason is maybe that the read field has not the type INT32 !");
6370   return ret;
6371 }
6372
6373 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
6374 {
6375   return contentNotNull()->getUndergroundDataArrayInt();
6376 }
6377
6378 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6379
6380 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6381 {
6382 }
6383
6384 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const char *fieldName):MEDFileFieldNameScope(fieldName)
6385 {
6386 }
6387
6388 /*!
6389  * \param [in] fieldId field id in C mode
6390  */
6391 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId) throw(INTERP_KERNEL::Exception)
6392 {
6393   med_field_type typcha;
6394   std::string dtunitOut;
6395   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6396   setDtUnit(dtunitOut.c_str());
6397   finishLoading(fid,nbOfStep,typcha);
6398 }
6399
6400 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit) throw(INTERP_KERNEL::Exception)
6401 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6402 {
6403   setDtUnit(dtunit.c_str());
6404   finishLoading(fid,nbOfStep,fieldTyp);
6405 }
6406 catch(INTERP_KERNEL::Exception& e)
6407 {
6408   throw e;
6409 }
6410
6411 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySize() const
6412 {
6413   std::size_t ret=_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>);
6414   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6415     ret+=(*it).capacity();
6416   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6417     if((const MEDFileAnyTypeField1TSWithoutSDA *)(*it))
6418       ret+=(*it)->getHeapMemorySize();
6419   return ret;
6420 }
6421
6422 /*!
6423  * If one of the id in [ \a startIds , \a endIds ) points to a null element, there is not throw. Simply, this empty element is added as if it were not
6424  * NULL.
6425  */
6426 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
6427 {
6428   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6429   ret->setInfo(_infos);
6430   int sz=(int)_time_steps.size();
6431   for(const int *id=startIds;id!=endIds;id++)
6432     {
6433       if(*id>=0 && *id<sz)
6434         {
6435           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6436           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6437           if(tse)
6438             {
6439               tse->incrRef();
6440               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6441             }
6442           ret->pushBackTimeStep(tse2);
6443         }
6444       else
6445         {
6446           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6447           oss << " ! Should be in [0," << sz << ") !";
6448           throw INTERP_KERNEL::Exception(oss.str().c_str());
6449         }
6450     }
6451   if(ret->getNumberOfTS()>0)
6452     ret->synchronizeNameScope();
6453   ret->copyNameScope(*this);
6454   return ret.retn();
6455 }
6456
6457 /*!
6458  * If one of the id in the input range points to a null element, there is not throw. Simply, this empty element is added as if it were not
6459  * NULL.
6460  */
6461 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
6462 {
6463   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6464   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6465   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6466   ret->setInfo(_infos);
6467   int sz=(int)_time_steps.size();
6468   int j=bg;
6469   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
6470     {
6471       if(j>=0 && j<sz)
6472         {
6473           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
6474           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6475           if(tse)
6476             {
6477               tse->incrRef();
6478               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6479             }
6480           ret->pushBackTimeStep(tse2);
6481         }
6482       else
6483         {
6484           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
6485           oss << " ! Should be in [0," << sz << ") !";
6486           throw INTERP_KERNEL::Exception(oss.str().c_str());
6487         }
6488     }
6489   if(ret->getNumberOfTS()>0)
6490     ret->synchronizeNameScope();
6491   ret->copyNameScope(*this);
6492   return ret.retn();
6493 }
6494
6495 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
6496 {
6497   int id=0;
6498   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6499   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6500     {
6501       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6502       if(!cur)
6503         continue;
6504       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6505       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
6506         ids->pushBackSilent(id);
6507     }
6508   return buildFromTimeStepIds(ids->begin(),ids->end());
6509 }
6510
6511 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
6512 {
6513   int id=0;
6514   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6515   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6516     {
6517       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6518       if(!cur)
6519         continue;
6520       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6521       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
6522         ids->pushBackSilent(id);
6523     }
6524   return buildFromTimeStepIds(ids->begin(),ids->end());
6525 }
6526
6527 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const throw(INTERP_KERNEL::Exception)
6528 {
6529   return _infos;
6530 }
6531
6532 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
6533 {
6534   _infos=info;
6535 }
6536
6537 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6538 {
6539   int ret=0;
6540   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6541     {
6542       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
6543       if(pt->isDealingTS(iteration,order))
6544         return ret;
6545     }
6546   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
6547   std::vector< std::pair<int,int> > vp=getIterations();
6548   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
6549     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
6550   throw INTERP_KERNEL::Exception(oss.str().c_str());
6551 }
6552
6553 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6554 {
6555   return *_time_steps[getTimeStepPos(iteration,order)];
6556 }
6557
6558 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) throw(INTERP_KERNEL::Exception)
6559 {
6560   return *_time_steps[getTimeStepPos(iteration,order)];
6561 }
6562
6563 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
6564 {
6565   if(_time_steps.empty())
6566     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
6567   return _time_steps[0]->getMeshName();
6568 }
6569
6570 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
6571 {
6572   std::string oldName(getMeshName());
6573   std::vector< std::pair<std::string,std::string> > v(1);
6574   v[0].first=oldName; v[0].second=newMeshName;
6575   changeMeshNames(v);
6576 }
6577
6578 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
6579 {
6580   bool ret=false;
6581   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6582     {
6583       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6584       if(cur)
6585         ret=cur->changeMeshNames(modifTab) || ret;
6586     }
6587   return ret;
6588 }
6589
6590 /*!
6591  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
6592  */
6593 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6594 {
6595   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
6596 }
6597
6598 /*!
6599  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
6600  */
6601 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::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)
6602 {
6603   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
6604 }
6605
6606 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
6607                                                                 MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
6608 {
6609   bool ret=false;
6610   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6611     {
6612       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
6613       if(f1ts)
6614         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
6615     }
6616   return ret;
6617 }
6618
6619 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
6620 {
6621   std::string startLine(bkOffset,' ');
6622   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
6623   if(fmtsId>=0)
6624     oss << " (" << fmtsId << ")";
6625   oss << " has the following name: \"" << _name << "\"." << std::endl;
6626   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
6627   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6628     {
6629       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
6630     }
6631   int i=0;
6632   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
6633     {
6634       std::string chapter(17,'0'+i);
6635       oss << startLine << chapter << std::endl;
6636       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6637       if(cur)
6638         cur->simpleRepr(bkOffset+2,oss,i);
6639       else
6640         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
6641       oss << startLine << chapter << std::endl;
6642     }
6643 }
6644
6645 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
6646 {
6647   std::size_t sz=_time_steps.size();
6648   std::vector< std::pair<int,int> > ret(sz);
6649   ret1.resize(sz);
6650   for(std::size_t i=0;i<sz;i++)
6651     {
6652       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
6653       if(f1ts)
6654         {
6655           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
6656         }
6657       else
6658         {
6659           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
6660           throw INTERP_KERNEL::Exception(oss.str().c_str());
6661         }
6662     }
6663   return ret;
6664 }
6665
6666 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse) throw(INTERP_KERNEL::Exception)
6667 {
6668   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
6669   if(!tse2)
6670     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
6671   checkCoherencyOfType(tse2);
6672   if(_time_steps.empty())
6673     {
6674       setName(tse2->getName().c_str());
6675       setInfo(tse2->getInfo());
6676     }
6677   checkThatComponentsMatch(tse2->getInfo());
6678   _time_steps.push_back(tse);
6679 }
6680
6681 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope() throw(INTERP_KERNEL::Exception)
6682 {
6683   std::size_t nbOfCompo=_infos.size();
6684   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6685     {
6686       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6687       if(cur)
6688         {
6689           if((cur->getInfo()).size()!=nbOfCompo)
6690             {
6691               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
6692               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
6693               throw INTERP_KERNEL::Exception(oss.str().c_str());
6694             }
6695           cur->copyNameScope(*this);
6696         }
6697     }
6698 }
6699
6700 void MEDFileAnyTypeFieldMultiTSWithoutSDA::finishLoading(med_idt fid, int nbPdt, med_field_type fieldTyp) throw(INTERP_KERNEL::Exception)
6701 {
6702   _time_steps.resize(nbPdt);
6703   for(int i=0;i<nbPdt;i++)
6704     {
6705       std::vector< std::pair<int,int> > ts;
6706       med_int numdt=0,numo=0;
6707       med_int meshIt=0,meshOrder=0;
6708       med_float dt=0.0;
6709       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
6710       switch(fieldTyp)
6711         {
6712         case MED_FLOAT64:
6713           {
6714             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
6715             break;
6716           }
6717         case MED_INT32:
6718           {
6719             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
6720             break;
6721           }
6722         default:
6723           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::finishLoading : managed field type are : FLOAT64, INT32 !");
6724         }
6725       _time_steps[i]->finishLoading(fid,*this);
6726     }
6727 }
6728
6729 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception)
6730 {
6731   if(_time_steps.empty())
6732     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
6733   checkThatNbOfCompoOfTSMatchThis();
6734   std::vector<std::string> infos(getInfo());
6735   int nbComp=infos.size();
6736   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
6737   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
6738   for(int i=0;i<nbComp;i++)
6739     {
6740       std::string info=infos[i];
6741       std::string c,u;
6742       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6743       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
6744       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
6745     }
6746   if(_name.empty())
6747     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
6748   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
6749   int nbOfTS=_time_steps.size();
6750   for(int i=0;i<nbOfTS;i++)
6751     _time_steps[i]->writeLL(fid,opts,*this);
6752 }
6753
6754 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
6755 {
6756   return _time_steps.size();
6757 }
6758
6759 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
6760 {
6761   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
6762   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6763     {
6764       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
6765       if(tmp)
6766         newTS.push_back(*it);
6767     }
6768   _time_steps=newTS;
6769 }
6770
6771 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
6772 {
6773   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
6774   int maxId=(int)_time_steps.size();
6775   int ii=0;
6776   std::set<int> idsToDel;
6777   for(const int *id=startIds;id!=endIds;id++,ii++)
6778     {
6779       if(*id>=0 && *id<maxId)
6780         {
6781           idsToDel.insert(*id);
6782         }
6783       else
6784         {
6785           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
6786           throw INTERP_KERNEL::Exception(oss.str().c_str());
6787         }
6788     }
6789   for(int iii=0;iii<maxId;iii++)
6790     if(idsToDel.find(iii)==idsToDel.end())
6791       newTS.push_back(_time_steps[iii]);
6792   _time_steps=newTS;
6793 }
6794
6795 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
6796 {
6797   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
6798   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6799   if(nbOfEntriesToKill==0)
6800     return ;
6801   std::size_t sz=_time_steps.size();
6802   std::vector<bool> b(sz,true);
6803   int j=bg;
6804   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
6805     b[j]=false;
6806   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
6807   for(std::size_t i=0;i<sz;i++)
6808     if(b[i])
6809       newTS.push_back(_time_steps[i]);
6810   _time_steps=newTS;
6811 }
6812
6813 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6814 {
6815   int ret=0;
6816   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
6817   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6818     {
6819       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
6820       if(tmp)
6821         {
6822           int it2,ord;
6823           tmp->getTime(it2,ord);
6824           if(it2==iteration && order==ord)
6825             return ret;
6826           else
6827             oss << "(" << it2 << ","  << ord << "), ";
6828         }
6829     }
6830   throw INTERP_KERNEL::Exception(oss.str().c_str());
6831 }
6832
6833 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
6834 {
6835   int ret=0;
6836   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
6837   oss.precision(15);
6838   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6839     {
6840       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
6841       if(tmp)
6842         {
6843           int it2,ord;
6844           double ti=tmp->getTime(it2,ord);
6845           if(fabs(time-ti)<eps)
6846             return ret;
6847           else
6848             oss << ti << ", ";
6849         }
6850     }
6851   throw INTERP_KERNEL::Exception(oss.str().c_str());
6852 }
6853
6854 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
6855 {
6856   int lgth=_time_steps.size();
6857   std::vector< std::pair<int,int> > ret(lgth);
6858   for(int i=0;i<lgth;i++)
6859     _time_steps[i]->fillIteration(ret[i]);
6860   return ret;
6861 }
6862
6863 /*!
6864  * 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'
6865  * This method returns two things.
6866  * - The absolute dimension of 'this' in first parameter. 
6867  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
6868  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
6869  *
6870  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
6871  * Only these 3 discretizations will be taken into account here.
6872  *
6873  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
6874  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
6875  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
6876  *
6877  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
6878  * 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'.
6879  * 
6880  * Let's consider the typical following case :
6881  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
6882  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
6883  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
6884  *   TETRA4 and SEG2
6885  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
6886  *
6887  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
6888  * 
6889  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
6890  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
6891  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
6892  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
6893  */
6894 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
6895 {
6896   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
6897 }
6898
6899 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const throw(INTERP_KERNEL::Exception)
6900 {
6901   if(pos<0 || pos>=(int)_time_steps.size())
6902     {
6903       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
6904       throw INTERP_KERNEL::Exception(oss.str().c_str());
6905     }
6906   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
6907   if(item==0)
6908     {
6909       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
6910       oss << "\nTry to use following method eraseEmptyTS !";
6911       throw INTERP_KERNEL::Exception(oss.str().c_str());
6912     }
6913   return item;
6914 }
6915
6916 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) throw(INTERP_KERNEL::Exception)
6917 {
6918   if(pos<0 || pos>=(int)_time_steps.size())
6919     {
6920       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
6921       throw INTERP_KERNEL::Exception(oss.str().c_str());
6922     }
6923   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
6924   if(item==0)
6925     {
6926       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
6927       oss << "\nTry to use following method eraseEmptyTS !";
6928       throw INTERP_KERNEL::Exception(oss.str().c_str());
6929     }
6930   return item;
6931 }
6932
6933 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
6934 {
6935   std::vector<std::string> ret;
6936   std::set<std::string> ret2;
6937   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6938     {
6939       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
6940       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
6941         if(ret2.find(*it2)==ret2.end())
6942           {
6943             ret.push_back(*it2);
6944             ret2.insert(*it2);
6945           }
6946     }
6947   return ret;
6948 }
6949
6950 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
6951 {
6952   std::vector<std::string> ret;
6953   std::set<std::string> ret2;
6954   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6955     {
6956       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
6957       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
6958         if(ret2.find(*it2)==ret2.end())
6959           {
6960             ret.push_back(*it2);
6961             ret2.insert(*it2);
6962           }
6963     }
6964   return ret;
6965 }
6966
6967 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
6968 {
6969   std::vector<std::string> ret;
6970   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6971     {
6972       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
6973       ret.insert(ret.end(),tmp.begin(),tmp.end());
6974     }
6975   return ret;
6976 }
6977
6978 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
6979 {
6980   std::vector<std::string> ret;
6981   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6982     {
6983       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
6984       ret.insert(ret.end(),tmp.begin(),tmp.end());
6985     }
6986   return ret;
6987 }
6988
6989 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
6990 {
6991   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6992     (*it)->changePflsRefsNamesGen2(mapOfModif);
6993 }
6994
6995 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
6996 {
6997   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6998     (*it)->changeLocsRefsNamesGen2(mapOfModif);
6999 }
7000
7001 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
7002 {
7003   int lgth=_time_steps.size();
7004   std::vector< std::vector<TypeOfField> > ret(lgth);
7005   for(int i=0;i<lgth;i++)
7006     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7007   return ret;
7008 }
7009
7010 /*!
7011  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7012  */
7013 std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeFieldMultiTSWithoutSDA::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)
7014 {
7015   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7016 }
7017
7018 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
7019 {
7020   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7021   std::size_t i=0;
7022   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7023     {
7024       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7025         ret->_time_steps[i]=(*it)->deepCpy();
7026     }
7027   return ret.retn();
7028 }
7029
7030 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const throw(INTERP_KERNEL::Exception)
7031 {
7032   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7033   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7034   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7035   for(std::size_t i=0;i<sz;i++)
7036     {
7037       ret[i]=shallowCpy();
7038       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7039     }
7040   for(std::size_t i=0;i<sz2;i++)
7041     {
7042       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7043       if(ret1.size()!=sz)
7044         {
7045           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7046           throw INTERP_KERNEL::Exception(oss.str().c_str());
7047         }
7048       ts[i]=ret1;
7049     }
7050   for(std::size_t i=0;i<sz;i++)
7051     for(std::size_t j=0;j<sz2;j++)
7052       ret[i]->_time_steps[j]=ts[j][i];
7053   return ret;
7054 }
7055
7056 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
7057 {
7058   _name=field->getName();
7059   if(_name.empty())
7060     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7061   if(!arr)
7062     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7063   _infos=arr->getInfoOnComponents();
7064 }
7065
7066 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const throw(INTERP_KERNEL::Exception)
7067 {
7068   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7069   if(_name!=field->getName())
7070     {
7071       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7072       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7073       throw INTERP_KERNEL::Exception(oss.str().c_str());
7074     }
7075   if(!arr)
7076     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7077   checkThatComponentsMatch(arr->getInfoOnComponents());
7078 }
7079
7080 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const throw(INTERP_KERNEL::Exception)
7081 {
7082   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7083   if(getInfo().size()!=compos.size())
7084     {
7085       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7086       oss << " number of components of element to append (" << compos.size() << ") !";
7087       throw INTERP_KERNEL::Exception(oss.str().c_str());
7088     }
7089   if(_infos!=compos)
7090     {
7091       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7092       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7093       oss << " But compo in input fields are : ";
7094       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7095       oss << " !";
7096       throw INTERP_KERNEL::Exception(oss.str().c_str());
7097     }
7098 }
7099
7100 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const throw(INTERP_KERNEL::Exception)
7101 {
7102   std::size_t sz=_infos.size();
7103   int j=0;
7104   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7105     {
7106       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7107       if(elt)
7108         if(elt->getInfo().size()!=sz)
7109           {
7110             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7111             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7112             throw INTERP_KERNEL::Exception(oss.str().c_str());
7113           }
7114     }
7115 }
7116
7117 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
7118 {
7119   if(!field)
7120     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7121   if(!_time_steps.empty())
7122     checkCoherencyOfTinyInfo(field,arr);
7123   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7124   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7125   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7126   copyTinyInfoFrom(field,arr);
7127   _time_steps.push_back(obj);
7128 }
7129
7130 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
7131 {
7132   if(!field)
7133     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7134   if(!_time_steps.empty())
7135     checkCoherencyOfTinyInfo(field,arr);
7136   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7137   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7138   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7139   copyTinyInfoFrom(field,arr);
7140   _time_steps.push_back(obj);
7141 }
7142
7143 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts) throw(INTERP_KERNEL::Exception)
7144 {
7145   int sz=(int)_time_steps.size();
7146   if(i<0 || i>=sz)
7147     {
7148       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7149       throw INTERP_KERNEL::Exception(oss.str().c_str());
7150     }
7151   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7152   if(tsPtr)
7153     {
7154       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7155         {
7156           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7157           throw INTERP_KERNEL::Exception(oss.str().c_str());
7158         }
7159     }
7160   _time_steps[i]=ts;
7161 }
7162
7163 //= MEDFileFieldMultiTSWithoutSDA
7164
7165 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit) throw(INTERP_KERNEL::Exception)
7166 {
7167   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit);
7168 }
7169
7170 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7171 {
7172 }
7173
7174 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const char *fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7175 {
7176 }
7177
7178 /*!
7179  * \param [in] fieldId field id in C mode
7180  */
7181 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId) throw(INTERP_KERNEL::Exception)
7182 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId)
7183 {
7184 }
7185 catch(INTERP_KERNEL::Exception& e)
7186   { throw e; }
7187
7188 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit) throw(INTERP_KERNEL::Exception)
7189 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit)
7190 {
7191 }
7192 catch(INTERP_KERNEL::Exception& e)
7193 { throw e; }
7194
7195 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const throw(INTERP_KERNEL::Exception)
7196 {
7197   return new MEDFileField1TSWithoutSDA;
7198 }
7199
7200 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const throw(INTERP_KERNEL::Exception)
7201 {
7202   if(!f1ts)
7203     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7204   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7205   if(!f1tsC)
7206     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7207 }
7208
7209 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
7210 {
7211   return MEDFileField1TSWithoutSDA::TYPE_STR;
7212 }
7213
7214 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
7215 {
7216   return new MEDFileFieldMultiTSWithoutSDA(*this);
7217 }
7218
7219 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const throw(INTERP_KERNEL::Exception)
7220 {
7221   return new MEDFileFieldMultiTSWithoutSDA;
7222 }
7223
7224 /*!
7225  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7226  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7227  */
7228 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)
7229 {
7230   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7231   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7232   if(!myF1TSC)
7233     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7234   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7235 }
7236
7237 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const throw(INTERP_KERNEL::Exception)
7238 {
7239   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7240   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7241   int i=0;
7242   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7243     {
7244       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7245       if(eltToConv)
7246         {
7247           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7248           if(!eltToConvC)
7249             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7250           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7251           ret->setIteration(i,elt);
7252         }
7253     }
7254   return ret.retn();
7255 }
7256
7257 //= MEDFileAnyTypeFieldMultiTS
7258
7259 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7260 {
7261 }
7262
7263 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
7264 try:MEDFileFieldGlobsReal(fileName)
7265 {
7266   MEDFileUtilities::CheckFileForRead(fileName);
7267   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7268   _content=BuildContentFrom(fid,fileName);
7269   loadGlobals(fid);
7270 }
7271 catch(INTERP_KERNEL::Exception& e)
7272   {
7273     throw e;
7274   }
7275
7276 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
7277 {
7278   med_field_type typcha;
7279   std::vector<std::string> infos;
7280   std::string dtunit;
7281   int i=-1;
7282   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7283   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7284   switch(typcha)
7285     {
7286     case MED_FLOAT64:
7287       {
7288         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i);
7289         break;
7290       }
7291     case MED_INT32:
7292       {
7293         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i);
7294         break;
7295       }
7296     default:
7297       {
7298         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
7299         throw INTERP_KERNEL::Exception(oss.str().c_str());
7300       }
7301     }
7302   ret->setDtUnit(dtunit.c_str());
7303   return ret.retn();
7304 }
7305
7306 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const char *fileName) throw(INTERP_KERNEL::Exception)
7307 {
7308   med_field_type typcha;
7309   //
7310   std::vector<std::string> infos;
7311   std::string dtunit,fieldName;
7312   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
7313   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7314   switch(typcha)
7315     {
7316     case MED_FLOAT64:
7317       {
7318         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0);
7319         break;
7320       }
7321     case MED_INT32:
7322       {
7323         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0);
7324         break;
7325       }
7326     default:
7327       {
7328         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
7329         throw INTERP_KERNEL::Exception(oss.str().c_str());
7330       }
7331     }
7332   ret->setDtUnit(dtunit.c_str());
7333   return ret.retn();
7334 }
7335
7336 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const char *fileName) throw(INTERP_KERNEL::Exception)
7337 {
7338   if(!c)
7339     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
7340   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
7341     {
7342       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
7343       ret->setFileName(fileName);
7344       ret->_content=c;  c->incrRef();
7345       return ret.retn();
7346     }
7347   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
7348     {
7349       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
7350       ret->setFileName(fileName);
7351       ret->_content=c;  c->incrRef();
7352       return ret.retn();
7353     }
7354   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
7355 }
7356
7357 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
7358 try:MEDFileFieldGlobsReal(fileName)
7359 {
7360   MEDFileUtilities::CheckFileForRead(fileName);
7361   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7362   _content=BuildContentFrom(fid,fileName,fieldName);
7363   loadGlobals(fid);
7364 }
7365 catch(INTERP_KERNEL::Exception& e)
7366   {
7367     throw e;
7368   }
7369
7370 //= MEDFileIntFieldMultiTSWithoutSDA
7371
7372 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit) throw(INTERP_KERNEL::Exception)
7373 {
7374   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit);
7375 }
7376
7377 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
7378 {
7379 }
7380
7381 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const char *fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7382 {
7383 }
7384
7385 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit) throw(INTERP_KERNEL::Exception)
7386 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit)
7387 {
7388 }
7389 catch(INTERP_KERNEL::Exception& e)
7390 { throw e; }
7391
7392 /*!
7393  * \param [in] fieldId field id in C mode
7394  */
7395 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId) throw(INTERP_KERNEL::Exception)
7396 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId)
7397 {
7398 }
7399 catch(INTERP_KERNEL::Exception& e)
7400   { throw e; }
7401
7402 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const throw(INTERP_KERNEL::Exception)
7403 {
7404   return new MEDFileIntField1TSWithoutSDA;
7405 }
7406
7407 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const throw(INTERP_KERNEL::Exception)
7408 {
7409   if(!f1ts)
7410     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7411   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
7412   if(!f1tsC)
7413     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
7414 }
7415
7416 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
7417 {
7418   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
7419 }
7420
7421 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
7422 {
7423   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
7424 }
7425
7426 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const throw(INTERP_KERNEL::Exception)
7427 {
7428   return new MEDFileIntFieldMultiTSWithoutSDA;
7429 }
7430
7431 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const throw(INTERP_KERNEL::Exception)
7432 {
7433   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
7434   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7435   int i=0;
7436   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7437     {
7438       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7439       if(eltToConv)
7440         {
7441           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
7442           if(!eltToConvC)
7443             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
7444           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
7445           ret->setIteration(i,elt);
7446         }
7447     }
7448   return ret.retn();
7449 }
7450
7451 //= MEDFileAnyTypeFieldMultiTS
7452
7453 /*!
7454  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
7455  * that has been read from a specified MED file.
7456  *  \param [in] fileName - the name of the MED file to read.
7457  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7458  *          is to delete this field using decrRef() as it is no more needed.
7459  *  \throw If reading the file fails.
7460  */
7461 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
7462 {
7463   MEDFileUtilities::CheckFileForRead(fileName);
7464   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7465   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName);
7466   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7467   ret->loadGlobals(fid);
7468   return ret.retn();
7469 }
7470
7471 /*!
7472  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
7473  * that has been read from a specified MED file.
7474  *  \param [in] fileName - the name of the MED file to read.
7475  *  \param [in] fieldName - the name of the field to read.
7476  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7477  *          is to delete this field using decrRef() as it is no more needed.
7478  *  \throw If reading the file fails.
7479  *  \throw If there is no field named \a fieldName in the file.
7480  */
7481 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
7482 {
7483   MEDFileUtilities::CheckFileForRead(fileName);
7484   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7485   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName);
7486   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7487   ret->loadGlobals(fid);
7488   return ret.retn();
7489 }
7490
7491 /*!
7492  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7493  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7494  *
7495  * \warning this is a shallow copy constructor
7496  */
7497 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7498 {
7499   if(!shallowCopyOfContent)
7500     {
7501       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
7502       otherPtr->incrRef();
7503       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
7504     }
7505   else
7506     {
7507       _content=other.shallowCpy();
7508     }
7509 }
7510
7511 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() throw(INTERP_KERNEL::Exception)
7512 {
7513   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7514   if(!ret)
7515     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
7516   return ret;
7517 }
7518
7519 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const throw(INTERP_KERNEL::Exception)
7520 {
7521   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7522   if(!ret)
7523     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
7524   return ret;
7525 }
7526
7527 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
7528 {
7529   return contentNotNullBase()->getPflsReallyUsed2();
7530 }
7531
7532 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
7533 {
7534   return contentNotNullBase()->getLocsReallyUsed2();
7535 }
7536
7537 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
7538 {
7539   return contentNotNullBase()->getPflsReallyUsedMulti2();
7540 }
7541
7542 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
7543 {
7544   return contentNotNullBase()->getLocsReallyUsedMulti2();
7545 }
7546
7547 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7548 {
7549   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
7550 }
7551
7552 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7553 {
7554   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
7555 }
7556
7557 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
7558 {
7559   return contentNotNullBase()->getNumberOfTS();
7560 }
7561
7562 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
7563 {
7564   contentNotNullBase()->eraseEmptyTS();
7565 }
7566
7567 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
7568 {
7569   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
7570 }
7571
7572 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
7573 {
7574   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
7575 }
7576
7577 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
7578 {
7579   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
7580   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7581   ret->_content=c;
7582   return ret.retn();
7583 }
7584
7585 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
7586 {
7587   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
7588   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7589   ret->_content=c;
7590   return ret.retn();
7591 }
7592
7593 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
7594 {
7595   return contentNotNullBase()->getIterations();
7596 }
7597
7598 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts) throw(INTERP_KERNEL::Exception)
7599 {
7600   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
7601     pushBackTimeStep(*it);
7602 }
7603
7604 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts) throw(INTERP_KERNEL::Exception)
7605 {
7606   if(!f1ts)
7607     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
7608   checkCoherencyOfType(f1ts);
7609   f1ts->incrRef();
7610   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
7611   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
7612   c->incrRef();
7613   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
7614   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
7615     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
7616   _content->pushBackTimeStep(cSafe);
7617   appendGlobs(*f1ts,1e-12);
7618 }
7619
7620 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope() throw(INTERP_KERNEL::Exception)
7621 {
7622   contentNotNullBase()->synchronizeNameScope();
7623 }
7624
7625 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
7626 {
7627   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
7628 }
7629
7630 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
7631 {
7632   return contentNotNullBase()->getPosGivenTime(time,eps);
7633 }
7634
7635 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
7636 {
7637   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
7638 }
7639
7640 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
7641 {
7642   return contentNotNullBase()->getTypesOfFieldAvailable();
7643 }
7644
7645 std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeFieldMultiTS::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)
7646 {
7647   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
7648 }
7649
7650 std::string MEDFileAnyTypeFieldMultiTS::getName() const
7651 {
7652   return contentNotNullBase()->getName();
7653 }
7654
7655 void MEDFileAnyTypeFieldMultiTS::setName(const char *name)
7656 {
7657   contentNotNullBase()->setName(name);
7658 }
7659
7660 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const throw(INTERP_KERNEL::Exception)
7661 {
7662   return contentNotNullBase()->getDtUnit();
7663 }
7664
7665 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
7666 {
7667   contentNotNullBase()->setDtUnit(dtUnit);
7668 }
7669
7670 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7671 {
7672   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
7673 }
7674
7675 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
7676 {
7677   return contentNotNullBase()->getTimeSteps(ret1);
7678 }
7679
7680 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const throw(INTERP_KERNEL::Exception)
7681 {
7682   return contentNotNullBase()->getMeshName();
7683 }
7684
7685 void MEDFileAnyTypeFieldMultiTS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
7686 {
7687   contentNotNullBase()->setMeshName(newMeshName);
7688 }
7689
7690 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
7691 {
7692   return contentNotNullBase()->changeMeshNames(modifTab);
7693 }
7694
7695 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const throw(INTERP_KERNEL::Exception)
7696 {
7697   return contentNotNullBase()->getInfo();
7698 }
7699
7700 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
7701 {
7702   return contentNotNullBase()->setInfo(info);
7703 }
7704
7705 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const throw(INTERP_KERNEL::Exception)
7706 {
7707   const std::vector<std::string> ret=getInfo();
7708   return (int)ret.size();
7709 }
7710
7711 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
7712 {
7713   writeGlobals(fid,*this);
7714   contentNotNullBase()->writeLL(fid,*this);
7715 }
7716
7717 /*!
7718  * Writes \a this field into a MED file specified by its name.
7719  *  \param [in] fileName - the MED file name.
7720  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
7721  * - 2 - erase; an existing file is removed.
7722  * - 1 - append; same data should not be present in an existing file.
7723  * - 0 - overwrite; same data present in an existing file is overwritten.
7724  *  \throw If the field name is not set.
7725  *  \throw If no field data is set.
7726  *  \throw If \a mode == 1 and the same data is present in an existing file.
7727  */
7728 void MEDFileAnyTypeFieldMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
7729 {
7730   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
7731   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
7732   writeLL(fid);
7733 }
7734
7735 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
7736 {
7737   std::ostringstream oss;
7738   contentNotNullBase()->simpleRepr(0,oss,-1);
7739   simpleReprGlobs(oss);
7740   return oss.str();
7741 }
7742
7743 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySize() const
7744 {
7745   std::size_t ret=0;
7746   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)_content)
7747     ret+=_content->getHeapMemorySize();
7748   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
7749 }
7750
7751 /*!
7752  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
7753  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
7754  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
7755  */
7756 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const throw(INTERP_KERNEL::Exception)
7757 {
7758   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
7759   if(!content)
7760     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
7761   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
7762   std::size_t sz(contentsSplit.size());
7763   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
7764   for(std::size_t i=0;i<sz;i++)
7765     {
7766       ret[i]=shallowCpy();
7767       ret[i]->_content=contentsSplit[i];
7768     }
7769   return ret;
7770 }
7771
7772 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception)
7773 {
7774   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7775   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
7776     ret->_content=_content->deepCpy();
7777   ret->deepCpyGlobs(*this);
7778   return ret.retn();
7779 }
7780
7781 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
7782 {
7783   return _content;
7784 }
7785
7786 /*!
7787  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
7788  *  \param [in] iteration - the iteration number of a required time step.
7789  *  \param [in] order - the iteration order number of required time step.
7790  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
7791  *          delete this field using decrRef() as it is no more needed.
7792  *  \throw If there is no required time step in \a this field.
7793  */
7794 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
7795 {
7796   int pos=getPosOfTimeStep(iteration,order);
7797   return getTimeStepAtPos(pos);
7798 }
7799
7800 /*!
7801  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
7802  *  \param [in] time - the time of the time step of interest.
7803  *  \param [in] eps - a precision used to compare time values.
7804  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
7805  *          delete this field using decrRef() as it is no more needed.
7806  *  \throw If there is no required time step in \a this field.
7807  */
7808 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
7809 {
7810   int pos=getPosGivenTime(time,eps);
7811   return getTimeStepAtPos(pos);
7812 }
7813
7814 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator() throw(INTERP_KERNEL::Exception)
7815 {
7816   return new MEDFileAnyTypeFieldMultiTSIterator(this);
7817 }
7818
7819 //= MEDFileFieldMultiTS
7820
7821 /*!
7822  * Returns a new empty instance of MEDFileFieldMultiTS.
7823  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
7824  *          is to delete this field using decrRef() as it is no more needed.
7825  */
7826 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
7827 {
7828   return new MEDFileFieldMultiTS;
7829 }
7830
7831 /*!
7832  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
7833  * that has been read from a specified MED file.
7834  *  \param [in] fileName - the name of the MED file to read.
7835  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
7836  *          is to delete this field using decrRef() as it is no more needed.
7837  *  \throw If reading the file fails.
7838  */
7839 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
7840 {
7841   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName);
7842   ret->contentNotNull();//to check that content type matches with \a this type.
7843   return ret.retn();
7844 }
7845
7846 /*!
7847  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
7848  * that has been read from a specified MED file.
7849  *  \param [in] fileName - the name of the MED file to read.
7850  *  \param [in] fieldName - the name of the field to read.
7851  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
7852  *          is to delete this field using decrRef() as it is no more needed.
7853  *  \throw If reading the file fails.
7854  *  \throw If there is no field named \a fieldName in the file.
7855  */
7856 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
7857 {
7858   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName);
7859   ret->contentNotNull();//to check that content type matches with \a this type.
7860   return ret.retn();
7861 }
7862
7863 /*!
7864  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7865  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7866  *
7867  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
7868  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
7869  * \warning this is a shallow copy constructor
7870  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
7871  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
7872  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
7873  *          is to delete this field using decrRef() as it is no more needed.
7874  */
7875 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7876 {
7877   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
7878 }
7879
7880 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const throw(INTERP_KERNEL::Exception)
7881 {
7882   return new MEDFileFieldMultiTS(*this);
7883 }
7884
7885 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception)
7886 {
7887   if(!f1ts)
7888     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7889   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
7890   if(!f1tsC)
7891     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7892 }
7893
7894 /*!
7895  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
7896  * following the given input policy.
7897  *
7898  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
7899  *                            By default (true) the globals are deeply copied.
7900  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
7901  */
7902 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
7903 {
7904   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
7905   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
7906   if(content)
7907     {
7908       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
7909       if(!contc)
7910         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
7911       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
7912       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
7913     }
7914   else
7915     ret=MEDFileIntFieldMultiTS::New();
7916   if(deepCpyGlobs)
7917     ret->deepCpyGlobs(*this);
7918   else
7919     ret->shallowCpyGlobs(*this);
7920   return ret.retn();
7921 }
7922
7923 /*!
7924  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
7925  *  \param [in] pos - a time step id.
7926  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
7927  *          delete this field using decrRef() as it is no more needed.
7928  *  \throw If \a pos is not a valid time step id.
7929  */
7930 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
7931 {
7932   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
7933   if(!item)
7934     {
7935       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
7936       throw INTERP_KERNEL::Exception(oss.str().c_str());
7937     }
7938   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
7939   if(itemC)
7940     {
7941       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
7942       ret->shallowCpyGlobs(*this);
7943       return ret.retn();
7944     }
7945   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
7946   throw INTERP_KERNEL::Exception(oss.str().c_str());
7947 }
7948
7949 /*!
7950  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
7951  * mesh entities of a given dimension of the first mesh in MED file.
7952  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7953  *  \param [in] type - a spatial discretization of interest.
7954  *  \param [in] iteration - the iteration number of a required time step.
7955  *  \param [in] order - the iteration order number of required time step.
7956  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7957  *  \param [in] renumPol - specifies how to permute values of the result field according to
7958  *          the optional numbers of cells and nodes, if any. The valid values are
7959  *          - 0 - do not permute.
7960  *          - 1 - permute cells.
7961  *          - 2 - permute nodes.
7962  *          - 3 - permute cells and nodes.
7963  *
7964  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7965  *          caller is to delete this field using decrRef() as it is no more needed. 
7966  *  \throw If the MED file is not readable.
7967  *  \throw If there is no mesh in the MED file.
7968  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7969  *  \throw If no field values of the required parameters are available.
7970  */
7971 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
7972 {
7973   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
7974   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7975   if(!myF1TSC)
7976     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
7977   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
7978   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut,*contentNotNullBase());
7979   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7980   return ret.retn();
7981 }
7982
7983 /*!
7984  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
7985  * the top level cells of the first mesh in MED file.
7986  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7987  *  \param [in] type - a spatial discretization of interest.
7988  *  \param [in] iteration - the iteration number of a required time step.
7989  *  \param [in] order - the iteration order number of required time step.
7990  *  \param [in] renumPol - specifies how to permute values of the result field according to
7991  *          the optional numbers of cells and nodes, if any. The valid values are
7992  *          - 0 - do not permute.
7993  *          - 1 - permute cells.
7994  *          - 2 - permute nodes.
7995  *          - 3 - permute cells and nodes.
7996  *
7997  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7998  *          caller is to delete this field using decrRef() as it is no more needed. 
7999  *  \throw If the MED file is not readable.
8000  *  \throw If there is no mesh in the MED file.
8001  *  \throw If no field values of the required parameters are available.
8002  */
8003 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const throw(INTERP_KERNEL::Exception)
8004 {
8005   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8006   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8007   if(!myF1TSC)
8008     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
8009   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8010   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,0,renumPol,this,arrOut,*contentNotNullBase());
8011   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8012   return ret.retn();
8013 }
8014
8015 /*!
8016  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8017  * a given support.
8018  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8019  *  \param [in] type - a spatial discretization of interest.
8020  *  \param [in] iteration - the iteration number of a required time step.
8021  *  \param [in] order - the iteration order number of required time step.
8022  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8023  *  \param [in] mesh - the supporting mesh.
8024  *  \param [in] renumPol - specifies how to permute values of the result field according to
8025  *          the optional numbers of cells and nodes, if any. The valid values are
8026  *          - 0 - do not permute.
8027  *          - 1 - permute cells.
8028  *          - 2 - permute nodes.
8029  *          - 3 - permute cells and nodes.
8030  *
8031  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8032  *          caller is to delete this field using decrRef() as it is no more needed. 
8033  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8034  *  \throw If no field of \a this is lying on \a mesh.
8035  *  \throw If no field values of the required parameters are available.
8036  */
8037 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
8038 {
8039   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8040   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8041   if(!myF1TSC)
8042     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8043   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8044   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
8045   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8046   return ret.retn();
8047 }
8048
8049 /*!
8050  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8051  * given support. 
8052  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8053  *  \param [in] type - a spatial discretization of the new field.
8054  *  \param [in] iteration - the iteration number of a required time step.
8055  *  \param [in] order - the iteration order number of required time step.
8056  *  \param [in] mesh - the supporting mesh.
8057  *  \param [in] renumPol - specifies how to permute values of the result field according to
8058  *          the optional numbers of cells and nodes, if any. The valid values are
8059  *          - 0 - do not permute.
8060  *          - 1 - permute cells.
8061  *          - 2 - permute nodes.
8062  *          - 3 - permute cells and nodes.
8063  *
8064  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8065  *          caller is to delete this field using decrRef() as it is no more needed. 
8066  *  \throw If no field of \a this is lying on \a mesh.
8067  *  \throw If no field values of the required parameters are available.
8068  */
8069 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
8070 {
8071   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8072   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8073   if(!myF1TSC)
8074     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8075   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8076   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
8077   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8078   return ret.retn();
8079 }
8080
8081 /*!
8082  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
8083  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8084  * This method is useful for MED2 file format when field on different mesh was autorized.
8085  */
8086 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
8087 {
8088   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8089   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8090   if(!myF1TSC)
8091     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
8092   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8093   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
8094   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8095   return ret.retn();
8096 }
8097
8098 /*!
8099  * Returns values and a profile of the field of a given type, of a given time step,
8100  * lying on a given support.
8101  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8102  *  \param [in] type - a spatial discretization of the field.
8103  *  \param [in] iteration - the iteration number of a required time step.
8104  *  \param [in] order - the iteration order number of required time step.
8105  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8106  *  \param [in] mesh - the supporting mesh.
8107  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8108  *          field of interest lies on. If the field lies on all entities of the given
8109  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8110  *          using decrRef() as it is no more needed.  
8111  *  \param [in] glob - the global data storing profiles and localization.
8112  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
8113  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8114  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8115  *  \throw If no field of \a this is lying on \a mesh.
8116  *  \throw If no field values of the required parameters are available.
8117  */
8118 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
8119 {
8120   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8121   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8122   if(!myF1TSC)
8123     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
8124   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8125   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
8126 }
8127
8128 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const throw(INTERP_KERNEL::Exception)
8129 {
8130   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8131   if(!pt)
8132     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
8133   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
8134   if(!ret)
8135     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
8136   return ret;
8137 }
8138
8139  MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() throw(INTERP_KERNEL::Exception)
8140 {
8141   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8142   if(!pt)
8143     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
8144   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
8145   if(!ret)
8146     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
8147   return ret;
8148 }
8149
8150 /*!
8151  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8152  * the given field is checked if its elements are sorted suitable for writing to MED file
8153  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8154  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8155  *  \param [in] field - the field to add to \a this.
8156  *  \throw If the name of \a field is empty.
8157  *  \throw If the data array of \a field is not set.
8158  *  \throw If existing time steps have different name or number of components than \a field.
8159  *  \throw If the underlying mesh of \a field has no name.
8160  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8161  */
8162 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
8163 {
8164   const DataArrayDouble *arr=0;
8165   if(field)
8166     arr=field->getArray();
8167   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
8168 }
8169
8170 /*!
8171  * Adds a MEDCouplingFieldDouble to \a this as another time step. Specified entities of
8172  * a given dimension of a given mesh are used as the support of the given field.
8173  * Elements of the given mesh must be sorted suitable for writing to MED file. 
8174  * Order of underlying mesh entities of the given field specified by \a profile parameter
8175  * is not prescribed; this method permutes field values to have them sorted by element
8176  * type as required for writing to MED file.  
8177  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8178  *  \param [in] field - the field to add to \a this.
8179  *  \param [in] mesh - the supporting mesh of \a field.
8180  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
8181  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8182  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8183  *  \throw If existing time steps have different name or number of components than \a field.
8184  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8185  *  \throw If the data array of \a field is not set.
8186  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8187  */
8188 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
8189 {
8190   const DataArrayDouble *arr=0;
8191   if(field)
8192     arr=field->getArray();
8193   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
8194 }
8195
8196 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
8197 {
8198   _content=new MEDFileFieldMultiTSWithoutSDA;
8199 }
8200
8201 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
8202 try:MEDFileAnyTypeFieldMultiTS(fileName)
8203 {
8204 }
8205 catch(INTERP_KERNEL::Exception& e)
8206   { throw e; }
8207
8208 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
8209 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName)
8210 {
8211 }
8212 catch(INTERP_KERNEL::Exception& e)
8213   { throw e; }
8214
8215 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8216 {
8217 }
8218
8219 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)
8220 {
8221   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
8222 }
8223
8224 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
8225 {
8226   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8227 }
8228
8229 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)
8230 {
8231   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
8232 }
8233
8234 //= MEDFileAnyTypeFieldMultiTSIterator
8235
8236 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
8237 {
8238   if(fmts)
8239     {
8240       fmts->incrRef();
8241       _nb_iter=fmts->getNumberOfTS();
8242     }
8243 }
8244
8245 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
8246 {
8247 }
8248
8249 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt() throw(INTERP_KERNEL::Exception)
8250 {
8251   if(_iter_id<_nb_iter)
8252     {
8253       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
8254       if(fmts)
8255         return fmts->getTimeStepAtPos(_iter_id++);
8256       else
8257         return 0;
8258     }
8259   else
8260     return 0;
8261 }
8262
8263 //= MEDFileIntFieldMultiTS
8264
8265 /*!
8266  * Returns a new empty instance of MEDFileFieldMultiTS.
8267  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8268  *          is to delete this field using decrRef() as it is no more needed.
8269  */
8270 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
8271 {
8272   return new MEDFileIntFieldMultiTS;
8273 }
8274
8275 /*!
8276  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
8277  * that has been read from a specified MED file.
8278  *  \param [in] fileName - the name of the MED file to read.
8279  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8280  *          is to delete this field using decrRef() as it is no more needed.
8281  *  \throw If reading the file fails.
8282  */
8283 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
8284 {
8285   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName);
8286   ret->contentNotNull();//to check that content type matches with \a this type.
8287   return ret.retn();
8288 }
8289
8290 /*!
8291  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
8292  * that has been read from a specified MED file.
8293  *  \param [in] fileName - the name of the MED file to read.
8294  *  \param [in] fieldName - the name of the field to read.
8295  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8296  *          is to delete this field using decrRef() as it is no more needed.
8297  *  \throw If reading the file fails.
8298  *  \throw If there is no field named \a fieldName in the file.
8299  */
8300 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
8301 {
8302   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName);
8303   ret->contentNotNull();//to check that content type matches with \a this type.
8304   return ret.retn();
8305 }
8306
8307 /*!
8308  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8309  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8310  *
8311  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
8312  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8313  * \warning this is a shallow copy constructor
8314  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
8315  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8316  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8317  *          is to delete this field using decrRef() as it is no more needed.
8318  */
8319 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8320 {
8321   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
8322 }
8323
8324 /*!
8325  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
8326  * following the given input policy.
8327  *
8328  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8329  *                            By default (true) the globals are deeply copied.
8330  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
8331  */
8332 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
8333 {
8334   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
8335   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8336   if(content)
8337     {
8338       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
8339       if(!contc)
8340         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
8341       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
8342       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
8343     }
8344   else
8345     ret=MEDFileFieldMultiTS::New();
8346   if(deepCpyGlobs)
8347     ret->deepCpyGlobs(*this);
8348   else
8349     ret->shallowCpyGlobs(*this);
8350   return ret.retn();
8351 }
8352
8353 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const throw(INTERP_KERNEL::Exception)
8354 {
8355   return new MEDFileIntFieldMultiTS(*this);
8356 }
8357
8358 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception)
8359 {
8360   if(!f1ts)
8361     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8362   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
8363   if(!f1tsC)
8364     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8365 }
8366
8367 /*!
8368  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8369  * mesh entities of a given dimension of the first mesh in MED file.
8370  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8371  *  \param [in] type - a spatial discretization of interest.
8372  *  \param [in] iteration - the iteration number of a required time step.
8373  *  \param [in] order - the iteration order number of required time step.
8374  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8375  *  \param [out] arrOut - the DataArrayInt containing values of field.
8376  *  \param [in] renumPol - specifies how to permute values of the result field according to
8377  *          the optional numbers of cells and nodes, if any. The valid values are
8378  *          - 0 - do not permute.
8379  *          - 1 - permute cells.
8380  *          - 2 - permute nodes.
8381  *          - 3 - permute cells and nodes.
8382  *
8383  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8384  *          caller is to delete this field using decrRef() as it is no more needed. 
8385  *  \throw If the MED file is not readable.
8386  *  \throw If there is no mesh in the MED file.
8387  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8388  *  \throw If no field values of the required parameters are available.
8389  */
8390 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8391 {
8392   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8393   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8394   if(!myF1TSC)
8395     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
8396   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8397   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arr,*contentNotNullBase());
8398   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8399   return ret.retn();
8400 }
8401
8402 /*!
8403  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8404  * the top level cells of the first mesh in MED file.
8405  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8406  *  \param [in] type - a spatial discretization of interest.
8407  *  \param [in] iteration - the iteration number of a required time step.
8408  *  \param [in] order - the iteration order number of required time step.
8409  *  \param [out] arrOut - the DataArrayInt containing values of field.
8410  *  \param [in] renumPol - specifies how to permute values of the result field according to
8411  *          the optional numbers of cells and nodes, if any. The valid values are
8412  *          - 0 - do not permute.
8413  *          - 1 - permute cells.
8414  *          - 2 - permute nodes.
8415  *          - 3 - permute cells and nodes.
8416  *
8417  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8418  *          caller is to delete this field using decrRef() as it is no more needed. 
8419  *  \throw If the MED file is not readable.
8420  *  \throw If there is no mesh in the MED file.
8421  *  \throw If no field values of the required parameters are available.
8422  */
8423 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8424 {
8425   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8426   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8427   if(!myF1TSC)
8428     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
8429   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8430   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,0,renumPol,this,arr,*contentNotNullBase());
8431   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8432   return ret.retn();
8433 }
8434
8435 /*!
8436  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8437  * a given support.
8438  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8439  *  \param [in] type - a spatial discretization of interest.
8440  *  \param [in] iteration - the iteration number of a required time step.
8441  *  \param [in] order - the iteration order number of required time step.
8442  *  \param [out] arrOut - the DataArrayInt containing values of field.
8443  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8444  *  \param [in] mesh - the supporting mesh.
8445  *  \param [in] renumPol - specifies how to permute values of the result field according to
8446  *          the optional numbers of cells and nodes, if any. The valid values are
8447  *          - 0 - do not permute.
8448  *          - 1 - permute cells.
8449  *          - 2 - permute nodes.
8450  *          - 3 - permute cells and nodes.
8451  *
8452  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8453  *          caller is to delete this field using decrRef() as it is no more needed. 
8454  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8455  *  \throw If no field of \a this is lying on \a mesh.
8456  *  \throw If no field values of the required parameters are available.
8457  */
8458 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8459 {
8460   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8461   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8462   if(!myF1TSC)
8463     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8464   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8465   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
8466   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8467   return ret.retn();
8468 }
8469
8470 /*!
8471  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8472  * given support. 
8473  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8474  *  \param [in] type - a spatial discretization of the new field.
8475  *  \param [in] iteration - the iteration number of a required time step.
8476  *  \param [in] order - the iteration order number of required time step.
8477  *  \param [in] mesh - the supporting mesh.
8478  *  \param [out] arrOut - the DataArrayInt containing values of field.
8479  *  \param [in] renumPol - specifies how to permute values of the result field according to
8480  *          the optional numbers of cells and nodes, if any. The valid values are
8481  *          - 0 - do not permute.
8482  *          - 1 - permute cells.
8483  *          - 2 - permute nodes.
8484  *          - 3 - permute cells and nodes.
8485  *
8486  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8487  *          caller is to delete this field using decrRef() as it is no more needed. 
8488  *  \throw If no field of \a this is lying on \a mesh.
8489  *  \throw If no field values of the required parameters are available.
8490  */
8491 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8492 {
8493   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8494   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8495   if(!myF1TSC)
8496     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8497   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8498   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
8499   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8500   return ret.retn();
8501 }
8502
8503 /*!
8504  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
8505  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8506  * This method is useful for MED2 file format when field on different mesh was autorized.
8507  */
8508 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const char *mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8509 {
8510   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8511   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8512   if(!myF1TSC)
8513     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8514   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8515   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
8516   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8517   return ret.retn();
8518 }
8519
8520 /*!
8521  * Returns values and a profile of the field of a given type, of a given time step,
8522  * lying on a given support.
8523  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8524  *  \param [in] type - a spatial discretization of the field.
8525  *  \param [in] iteration - the iteration number of a required time step.
8526  *  \param [in] order - the iteration order number of required time step.
8527  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8528  *  \param [in] mesh - the supporting mesh.
8529  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8530  *          field of interest lies on. If the field lies on all entities of the given
8531  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8532  *          using decrRef() as it is no more needed.  
8533  *  \param [in] glob - the global data storing profiles and localization.
8534  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
8535  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8536  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8537  *  \throw If no field of \a this is lying on \a mesh.
8538  *  \throw If no field values of the required parameters are available.
8539  */
8540 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
8541 {
8542   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8543   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8544   if(!myF1TSC)
8545     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
8546   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8547   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
8548 }
8549
8550 /*!
8551  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
8552  *  \param [in] pos - a time step id.
8553  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
8554  *          delete this field using decrRef() as it is no more needed.
8555  *  \throw If \a pos is not a valid time step id.
8556  */
8557 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
8558 {
8559   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8560   if(!item)
8561     {
8562       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8563       throw INTERP_KERNEL::Exception(oss.str().c_str());
8564     }
8565   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
8566   if(itemC)
8567     {
8568       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
8569       ret->shallowCpyGlobs(*this);
8570       return ret.retn();
8571     }
8572   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
8573   throw INTERP_KERNEL::Exception(oss.str().c_str());
8574 }
8575
8576 /*!
8577  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8578  * the given field is checked if its elements are sorted suitable for writing to MED file
8579  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8580  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8581  *  \param [in] field - the field to add to \a this.
8582  *  \throw If the name of \a field is empty.
8583  *  \throw If the data array of \a field is not set.
8584  *  \throw If existing time steps have different name or number of components than \a field.
8585  *  \throw If the underlying mesh of \a field has no name.
8586  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8587  */
8588 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception)
8589 {
8590   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
8591 }
8592
8593 /*!
8594  * Adds a MEDCouplingFieldDouble to \a this as another time step. Specified entities of
8595  * a given dimension of a given mesh are used as the support of the given field.
8596  * Elements of the given mesh must be sorted suitable for writing to MED file. 
8597  * Order of underlying mesh entities of the given field specified by \a profile parameter
8598  * is not prescribed; this method permutes field values to have them sorted by element
8599  * type as required for writing to MED file.  
8600  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8601  *  \param [in] field - the field to add to \a this.
8602  *  \param [in] mesh - the supporting mesh of \a field.
8603  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
8604  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8605  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8606  *  \throw If existing time steps have different name or number of components than \a field.
8607  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8608  *  \throw If the data array of \a field is not set.
8609  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8610  */
8611 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
8612 {
8613   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
8614 }
8615
8616 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const throw(INTERP_KERNEL::Exception)
8617 {
8618   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8619   if(!pt)
8620     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
8621   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
8622   if(!ret)
8623     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is not null but it is not of type int ! Reason is maybe that the read field has not the type INT32 !");
8624   return ret;
8625 }
8626
8627  MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() throw(INTERP_KERNEL::Exception)
8628 {
8629   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8630   if(!pt)
8631     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
8632   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
8633   if(!ret)
8634     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is not null but it is not of type int ! Reason is maybe that the read field has not the type INT32 !");
8635   return ret;
8636 }
8637
8638 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
8639 {
8640   _content=new MEDFileIntFieldMultiTSWithoutSDA;
8641 }
8642
8643 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8644 {
8645 }
8646
8647 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
8648 try:MEDFileAnyTypeFieldMultiTS(fileName)
8649 {
8650 }
8651 catch(INTERP_KERNEL::Exception& e)
8652   { throw e; }
8653
8654 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
8655 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName)
8656 {
8657 }
8658 catch(INTERP_KERNEL::Exception& e)
8659   { throw e; }
8660
8661 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
8662 {
8663   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8664 }
8665
8666 //= MEDFileFields
8667
8668 MEDFileFields *MEDFileFields::New()
8669 {
8670   return new MEDFileFields;
8671 }
8672
8673 MEDFileFields *MEDFileFields::New(const char *fileName) throw(INTERP_KERNEL::Exception)
8674 {
8675   return new MEDFileFields(fileName);
8676 }
8677
8678 std::size_t MEDFileFields::getHeapMemorySize() const
8679 {
8680   std::size_t ret=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
8681   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8682     if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it)
8683       ret+=(*it)->getHeapMemorySize();
8684   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
8685 }
8686
8687 MEDFileFields *MEDFileFields::deepCpy() const throw(INTERP_KERNEL::Exception)
8688 {
8689   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
8690   std::size_t i=0;
8691   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8692     {
8693       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
8694         ret->_fields[i]=(*it)->deepCpy();
8695     }
8696   ret->deepCpyGlobs(*this);
8697   return ret.retn();
8698 }
8699
8700 MEDFileFields *MEDFileFields::shallowCpy() const throw(INTERP_KERNEL::Exception)
8701 {
8702   return new MEDFileFields(*this);
8703 }
8704
8705 /*!
8706  * This method scans for all fields in \a this which time steps ids are common. Time step are discriminated by the pair of integer (iteration,order) whatever
8707  * the double time value. If all returned time steps are \b exactly those for all fields in \a this output parameter \a areThereSomeForgottenTS will be set to false.
8708  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
8709  *
8710  * \param [out] areThereSomeForgottenTS - indicates to the caller if there is some time steps in \a this that are not present for all fields in \a this.
8711  * \return the sorted list of time steps (specified with a pair of integer iteration first and order second) present for all fields in \a this.
8712  * 
8713  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
8714  */
8715 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const throw(INTERP_KERNEL::Exception)
8716 {
8717   std::set< std::pair<int,int> > s;
8718   bool firstShot=true;
8719   areThereSomeForgottenTS=false;
8720   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8721     {
8722       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
8723         continue;
8724       std::vector< std::pair<int,int> > v=(*it)->getIterations();
8725       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
8726       if(firstShot)
8727         { s=s1; firstShot=false; }
8728       else
8729         {
8730           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
8731           if(s!=s2)
8732             areThereSomeForgottenTS=true;
8733           s=s2;
8734         }
8735     }
8736   std::vector< std::pair<int,int> > ret;
8737   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
8738   return ret;
8739 }
8740
8741 int MEDFileFields::getNumberOfFields() const
8742 {
8743   return _fields.size();
8744 }
8745
8746 std::vector<std::string> MEDFileFields::getFieldsNames() const throw(INTERP_KERNEL::Exception)
8747 {
8748   std::vector<std::string> ret(_fields.size());
8749   int i=0;
8750   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8751     {
8752       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
8753       if(f)
8754         {
8755           ret[i]=f->getName();
8756         }
8757       else
8758         {
8759           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
8760           throw INTERP_KERNEL::Exception(oss.str().c_str());
8761         }
8762     }
8763   return ret;
8764 }
8765
8766 std::vector<std::string> MEDFileFields::getMeshesNames() const throw(INTERP_KERNEL::Exception)
8767 {
8768   std::vector<std::string> ret;
8769   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8770     {
8771       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
8772       if(cur)
8773         ret.push_back(cur->getMeshName());
8774     }
8775   return ret;
8776 }
8777
8778 std::string MEDFileFields::simpleRepr() const
8779 {
8780   std::ostringstream oss;
8781   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
8782   simpleRepr(0,oss);
8783   return oss.str();
8784 }
8785
8786 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
8787 {
8788   int nbOfFields=getNumberOfFields();
8789   std::string startLine(bkOffset,' ');
8790   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
8791   int i=0;
8792   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8793     {
8794       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
8795       if(cur)
8796         {
8797           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
8798         }
8799       else
8800         {
8801           oss << startLine << "  - not defined !" << std::endl;
8802         }
8803     }
8804   i=0;
8805   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8806     {
8807       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
8808       std::string chapter(17,'0'+i);
8809       oss << startLine << chapter << std::endl;
8810       if(cur)
8811         {
8812           cur->simpleRepr(bkOffset+2,oss,i);
8813         }
8814       else
8815         {
8816           oss << startLine << "  - not defined !" << std::endl;
8817         }
8818       oss << startLine << chapter << std::endl;
8819     }
8820   simpleReprGlobs(oss);
8821 }
8822
8823 MEDFileFields::MEDFileFields()
8824 {
8825 }
8826
8827 MEDFileFields::MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception)
8828 try:MEDFileFieldGlobsReal(fileName)
8829   {
8830     MEDFileUtilities::CheckFileForRead(fileName);
8831     MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
8832     int nbFields=MEDnField(fid);
8833     _fields.resize(nbFields);
8834     med_field_type typcha;
8835     for(int i=0;i<nbFields;i++)
8836       {
8837         std::vector<std::string> infos;
8838         std::string fieldName,dtunit;
8839         int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit);
8840         switch(typcha)
8841           {
8842           case MED_FLOAT64:
8843             {
8844               _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit);
8845               break;
8846             }
8847           case MED_INT32:
8848             {
8849               _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit);
8850               break;
8851             }
8852           default:
8853             {
8854               std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << fileName << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
8855               throw INTERP_KERNEL::Exception(oss.str().c_str());
8856             }
8857           }
8858       }
8859     loadAllGlobals(fid);
8860   }
8861 catch(INTERP_KERNEL::Exception& e)
8862   {
8863     throw e;
8864   }
8865
8866 void MEDFileFields::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
8867 {
8868   int i=0;
8869   writeGlobals(fid,*this);
8870   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8871     {
8872       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
8873       if(!elt)
8874         {
8875           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
8876           throw INTERP_KERNEL::Exception(oss.str().c_str());
8877         }
8878       elt->writeLL(fid,*this);
8879     }
8880 }
8881
8882 void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
8883 {
8884   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8885   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
8886   writeLL(fid);
8887 }
8888
8889 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
8890 {
8891   std::vector<std::string> ret;
8892   std::set<std::string> ret2;
8893   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8894     {
8895       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
8896       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8897         if(ret2.find(*it2)==ret2.end())
8898           {
8899             ret.push_back(*it2);
8900             ret2.insert(*it2);
8901           }
8902     }
8903   return ret;
8904 }
8905
8906 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
8907 {
8908   std::vector<std::string> ret;
8909   std::set<std::string> ret2;
8910   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8911     {
8912       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8913       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8914         if(ret2.find(*it2)==ret2.end())
8915           {
8916             ret.push_back(*it2);
8917             ret2.insert(*it2);
8918           }
8919     }
8920   return ret;
8921 }
8922
8923 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
8924 {
8925   std::vector<std::string> ret;
8926   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8927     {
8928       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
8929       ret.insert(ret.end(),tmp.begin(),tmp.end());
8930     }
8931   return ret;
8932 }
8933
8934 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
8935 {
8936   std::vector<std::string> ret;
8937   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8938     {
8939       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8940       ret.insert(ret.end(),tmp.begin(),tmp.end());
8941     }
8942   return ret;
8943 }
8944
8945 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
8946 {
8947   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
8948     (*it)->changePflsRefsNamesGen2(mapOfModif);
8949 }
8950
8951 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
8952 {
8953   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
8954     (*it)->changeLocsRefsNamesGen2(mapOfModif);
8955 }
8956
8957 void MEDFileFields::resize(int newSize) throw(INTERP_KERNEL::Exception)
8958 {
8959   _fields.resize(newSize);
8960 }
8961
8962 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields) throw(INTERP_KERNEL::Exception)
8963 {
8964   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
8965     pushField(*it);
8966 }
8967
8968 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
8969 {
8970   if(!field)
8971     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
8972   _fields.push_back(field->getContent());
8973   appendGlobs(*field,1e-12);
8974 }
8975
8976 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
8977 {
8978   if(!field)
8979     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
8980   if(i>=(int)_fields.size())
8981     _fields.resize(i+1);
8982   _fields[i]=field->getContent();
8983   appendGlobs(*field,1e-12);
8984 }
8985
8986 void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception)
8987 {
8988   destroyFieldsAtPos(&i,&i+1);
8989 }
8990
8991 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
8992 {
8993   std::vector<bool> b(_fields.size(),true);
8994   for(const int *i=startIds;i!=endIds;i++)
8995     {
8996       if(*i<0 || *i>=(int)_fields.size())
8997         {
8998           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
8999           throw INTERP_KERNEL::Exception(oss.str().c_str());
9000         }
9001       b[*i]=false;
9002     }
9003   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9004   std::size_t j=0;
9005   for(std::size_t i=0;i<_fields.size();i++)
9006     if(b[i])
9007       fields[j++]=_fields[i];
9008   _fields=fields;
9009 }
9010
9011 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
9012 {
9013   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9014   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
9015   std::vector<bool> b(_fields.size(),true);
9016   int k=bg;
9017   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9018     {
9019       if(k<0 || k>=(int)_fields.size())
9020         {
9021           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9022           throw INTERP_KERNEL::Exception(oss.str().c_str());
9023         }
9024       b[k]=false;
9025     }
9026   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9027   std::size_t j=0;
9028   for(std::size_t i=0;i<_fields.size();i++)
9029     if(b[i])
9030       fields[j++]=_fields[i];
9031   _fields=fields;
9032 }
9033
9034 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
9035 {
9036   bool ret=false;
9037   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9038     {
9039       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9040       if(cur)
9041         ret=cur->changeMeshNames(modifTab) || ret;
9042     }
9043   return ret;
9044 }
9045
9046 /*!
9047  * \param [in] meshName the name of the mesh that will be renumbered.
9048  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9049  *             This code corresponds to the distribution of types in the corresponding mesh.
9050  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9051  * \param [in] renumO2N the old to new renumber array.
9052  * \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 
9053  *         field in \a this.
9054  */
9055 bool MEDFileFields::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N) throw(INTERP_KERNEL::Exception)
9056 {
9057   bool ret=false;
9058   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9059     {
9060       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9061       if(fmts)
9062         {
9063           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9064         }
9065     }
9066   return ret;
9067 }
9068
9069 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception)
9070 {
9071   if(i<0 || i>=(int)_fields.size())
9072     {
9073       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9074       throw INTERP_KERNEL::Exception(oss.str().c_str());
9075     }
9076   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9077   if(!fmts)
9078     return 0;
9079   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
9080   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
9081   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
9082   if(fmtsC)
9083     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9084   else if(fmtsC2)
9085     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9086   else
9087     {
9088       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
9089       throw INTERP_KERNEL::Exception(oss.str().c_str());
9090     }
9091   ret->shallowCpyGlobs(*this);
9092   return ret.retn();
9093 }
9094
9095 /*!
9096  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9097  * This method is accessible in python using __getitem__ with a list in input.
9098  * \return a new object that the caller should deal with.
9099  */
9100 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
9101 {
9102   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9103   std::size_t sz=std::distance(startIds,endIds);
9104   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9105   int j=0;
9106   for(const int *i=startIds;i!=endIds;i++,j++)
9107     {
9108       if(*i<0 || *i>=(int)_fields.size())
9109         {
9110           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9111           throw INTERP_KERNEL::Exception(oss.str().c_str());
9112         }
9113       fields[j]=_fields[*i];
9114     }
9115   ret->_fields=fields;
9116   return ret.retn();
9117 }
9118
9119 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
9120 {
9121   return getFieldAtPos(getPosFromFieldName(fieldName));
9122 }
9123
9124 /*!
9125  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9126  * This method can be seen as a filter applied on \a this, that returns an object containing
9127  * reduced the list of fields compared to those in \a this. The returned object is a new object but the object on which it lies are only
9128  * shallow copied from \a this.
9129  * 
9130  * \param [in] meshName - the name of the mesh on w
9131  * \return a new object that the caller should deal with.
9132  */
9133 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const char *meshName) const throw(INTERP_KERNEL::Exception)
9134 {
9135   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9136   ret->shallowCpyOnlyUsedGlobs(*this);
9137   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9138     {
9139       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9140       if(!cur)
9141         continue;
9142       if(cur->getMeshName()==meshName)
9143         {
9144           cur->incrRef();
9145           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
9146           ret->_fields.push_back(cur2);
9147         }
9148     }
9149   return ret.retn();
9150 }
9151
9152 /*!
9153  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
9154  * Input time steps are specified using a pair of integer (iteration, order).
9155  * This method can be seen as a filter applied on \a this, that returns an object containing the same number of fields than those in \a this,
9156  * but for each multitimestep only the time steps in \a timeSteps are kept.
9157  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
9158  * 
9159  * The returned object points to shallow copy of elements in \a this.
9160  * 
9161  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
9162  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
9163  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9164  */
9165 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
9166 {
9167   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9168   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9169     {
9170       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9171       if(!cur)
9172         continue;
9173       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
9174       ret->_fields.push_back(elt);
9175     }
9176   ret->shallowCpyOnlyUsedGlobs(*this);
9177   return ret.retn();
9178 }
9179
9180 /*!
9181  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
9182  */
9183 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
9184 {
9185   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9186   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9187     {
9188       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9189       if(!cur)
9190         continue;
9191       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
9192       if(elt->getNumberOfTS()!=0)
9193         ret->_fields.push_back(elt);
9194     }
9195   ret->shallowCpyOnlyUsedGlobs(*this);
9196   return ret.retn();
9197 }
9198
9199 MEDFileFieldsIterator *MEDFileFields::iterator() throw(INTERP_KERNEL::Exception)
9200 {
9201   return new MEDFileFieldsIterator(this);
9202 }
9203
9204 int MEDFileFields::getPosFromFieldName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
9205 {
9206   std::string tmp(fieldName);
9207   std::vector<std::string> poss;
9208   for(std::size_t i=0;i<_fields.size();i++)
9209     {
9210       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
9211       if(f)
9212         {
9213           std::string fname(f->getName());
9214           if(tmp==fname)
9215             return i;
9216           else
9217             poss.push_back(fname);
9218         }
9219     }
9220   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
9221   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
9222   oss << " !";
9223   throw INTERP_KERNEL::Exception(oss.str().c_str());
9224 }
9225
9226 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
9227 {
9228   if(fs)
9229     {
9230       fs->incrRef();
9231       _nb_iter=fs->getNumberOfFields();
9232     }
9233 }
9234
9235 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
9236 {
9237 }
9238
9239 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
9240 {
9241   if(_iter_id<_nb_iter)
9242     {
9243       MEDFileFields *fs(_fs);
9244       if(fs)
9245         return fs->getFieldAtPos(_iter_id++);
9246       else
9247         return 0;
9248     }
9249   else
9250     return 0;
9251 }