Salome HOME
MED file loading on demand.
[modules/med.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileUtilities.hxx"
25
26 #include "MEDCouplingFieldDouble.hxx"
27 #include "MEDCouplingFieldDiscretization.hxx"
28
29 #include "InterpKernelAutoPtr.hxx"
30 #include "CellModel.hxx"
31
32 #include <algorithm>
33 #include <iterator>
34
35 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
36 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
37 extern med_geometry_type typmainoeud[1];
38 extern med_geometry_type typmai3[32];
39
40 using namespace ParaMEDMEM;
41
42 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         getOrCreateAndGetArray()->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         getOrCreateAndGetArray()->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         getOrCreateAndGetArray()->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          getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,arrr->getNumberOfTuples(),1);
302          _end=_start+_nval;
303          break;
304       }
305     case ON_CELLS:
306       {
307         _nval=idsInPfl->getNumberOfTuples();
308         getOrCreateAndGetArray()->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         getOrCreateAndGetArray()->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         getOrCreateAndGetArray()->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   getOrCreateAndGetArray()->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::loadOnlyStructureOfDataRecursively(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::loadBigArray(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=getOrCreateAndGetArray();
486   if(_start>_end)
487     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
488   if(_start<0 || _start>=arr->getNumberOfTuples())
489     {
490       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
491       throw INTERP_KERNEL::Exception(oss.str().c_str());
492     }
493   if(_end<0 || _end>arr->getNumberOfTuples())
494     {
495       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
496       throw INTERP_KERNEL::Exception(oss.str().c_str());
497     }
498   DataArrayDouble *arrD=dynamic_cast<DataArrayDouble *>(arr);
499   if(arrD)
500     {
501       double *startFeeding=arrD->getPointer()+_start*arrD->getNumberOfComponents();
502       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
503                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
504       return ;
505     }
506   DataArrayInt *arrI=dynamic_cast<DataArrayInt *>(arr);
507   if(arrI)
508     {
509       int *startFeeding=arrI->getPointer()+_start*arrI->getNumberOfComponents();
510       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
511                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
512       return ;
513     }
514   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
515 }
516
517 /*!
518  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
519  */
520 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart) throw(INTERP_KERNEL::Exception)
521 {
522   int delta=_end-_start;
523   _start=newValueOfStart;
524   _end=_start+delta;
525 }
526
527 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
528 {
529   return _father->getIteration();
530 }
531
532 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
533 {
534   return _father->getOrder();
535 }
536
537 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
538 {
539   return _father->getTime();
540 }
541
542 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
543 {
544   return _father->getMeshName();
545 }
546
547 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
548 {
549   const char startLine[]="    ## ";
550   std::string startLine2(bkOffset,' ');
551   startLine2+=startLine;
552   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
553   oss << startLine2 << "Localization #" << id << "." << std::endl;
554   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
555   delete tmp;
556   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
557   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
558   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
559 }
560
561 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
562 {
563   return _type;
564 }
565
566 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
567 {
568   types.insert(_type);
569 }
570
571 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
572 {
573   _type=newType;
574 }
575
576 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
577 {
578   return _father->getGeoType();
579 }
580
581 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
582 {
583   return _father->getNumberOfComponents();
584 }
585
586 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
587 {
588   return _end-_start;
589 }
590
591 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
592 {
593   return _father->getOrCreateAndGetArray();
594 }
595
596 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
597 {
598   const MEDFileFieldPerMeshPerType *fath=_father;
599   return fath->getOrCreateAndGetArray();
600 }
601
602 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
603 {
604   return _father->getInfo();
605 }
606
607 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
608 {
609   return _profile;
610 }
611
612 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const char *newPflName)
613 {
614   _profile=newPflName;
615 }
616
617 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
618 {
619   return _localization;
620 }
621
622 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const char *newLocName)
623 {
624   _localization=newLocName;
625 }
626
627 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
628 {
629   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
630     {
631       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
632         {
633           _profile=(*it2).second;
634           return;
635         }
636     }
637 }
638
639 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
640 {
641   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
642     {
643       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
644         {
645           _localization=(*it2).second;
646           return;
647         }
648     }
649 }
650
651 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
652 {
653   if(type!=_type)
654     return ;
655   dads.push_back(std::pair<int,int>(_start,_end));
656   geoTypes.push_back(getGeoType());
657   if(_profile.empty())
658     pfls.push_back(0);
659   else
660     {
661       pfls.push_back(glob->getProfile(_profile.c_str()));
662     }
663   if(_localization.empty())
664     locs.push_back(-1);
665   else
666     {
667       locs.push_back(glob->getLocalizationId(_localization.c_str()));
668     }
669 }
670
671 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
672 {
673   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));
674   startEntryId++;
675 }
676
677 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
678 {
679   TypeOfField type=getType();
680   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
681   med_geometry_type mgeoti;
682   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
683   const DataArray *arr=getOrCreateAndGetArray();
684   if(!arr)
685     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
686   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
687   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
688   const unsigned char *locToWrite=0;
689   if(arrD)
690     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
691   else if(arrI)
692     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
693   else
694     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
695   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
696                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
697                              locToWrite);
698 }
699
700 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const throw(INTERP_KERNEL::Exception)
701 {
702   type=_type;
703   pfl=_profile;
704   loc=_localization;
705   dad.first=_start; dad.second=_end;
706 }
707
708 /*!
709  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
710  *             This code corresponds to the distribution of types in the corresponding mesh.
711  * \param [out] ptToFill memory zone where the output will be stored.
712  * \return the size of data pushed into output param \a ptToFill
713  */
714 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const throw(INTERP_KERNEL::Exception)
715 {
716   _loc_id=offset;
717   std::ostringstream oss;
718   std::size_t nbOfType=codeOfMesh.size()/3;
719   int found=-1;
720   for(std::size_t i=0;i<nbOfType && found==-1;i++)
721     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
722       found=(int)i;
723   if(found==-1)
724     {
725       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
726       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
727       throw INTERP_KERNEL::Exception(oss.str().c_str());
728     }
729   int *work=ptToFill;
730   if(_profile.empty())
731     {
732       if(_nval!=codeOfMesh[3*found+1])
733         {
734           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
735           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
736           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
737           throw INTERP_KERNEL::Exception(oss.str().c_str());
738         }
739       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
740         *work++=ii;
741     }
742   else
743     {
744       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
745       if(pfl->getNumberOfTuples()!=_nval)
746         {
747           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
748           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
749           oss << _nval;
750           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
751           throw INTERP_KERNEL::Exception(oss.str().c_str());
752         }
753       int offset2=codeOfMesh[3*found+2];
754       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
755         {
756           if(*pflId<codeOfMesh[3*found+1])
757             *work++=offset2+*pflId;
758         }
759     }
760   return _nval;
761 }
762
763 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const throw(INTERP_KERNEL::Exception)
764 {
765   for(int i=_start;i<_end;i++)
766     *ptToFill++=i;
767   return _end-_start;
768 }
769
770 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId) throw(INTERP_KERNEL::Exception)
771 {
772   switch(type)
773     {
774     case ON_CELLS:
775       return -2;
776     case ON_GAUSS_NE:
777       return -1;
778     case ON_GAUSS_PT:
779       return locId;
780     default:
781       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
782     }
783 }
784
785 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
786 {
787   int id=0;
788   std::map<std::pair<std::string,TypeOfField>,int> m;
789   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
790   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
791     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
792       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
793   ret.resize(id);
794   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
795     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
796   return ret;
797 }
798
799 /*!
800  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
801  * 
802  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
803  * \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.
804  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
805  * \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)
806  * \param [in,out] glob if necessary by the method, new profiles can be added to it
807  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
808  * \param [out] result All new entries will be appended on it.
809  * \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 !)
810  */
811 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
812                                                        const DataArrayInt *explicitIdsInMesh,
813                                                        const std::vector<int>& newCode,
814                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
815                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
816 {
817   if(entriesOnSameDisc.empty())
818     return false;
819   TypeOfField type=entriesOnSameDisc[0]->getType();
820   int szEntities=0,szTuples=0;
821   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
822     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
823   int nbi=szTuples/szEntities;
824   if(szTuples%szEntities!=0)
825     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
826   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
827   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
828   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
829   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
830   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
831   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
832   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
833   int id=0;
834   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
835     {
836       int startOfEltIdOfChunk=(*it)->_start;
837       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
838       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
839       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
840       //
841       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
842       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
843       //
844       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
845       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
846     }
847   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
848   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
849   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
850   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
851   //
852   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
853   //
854   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
855   arrPart->renumberInPlace(renumTupleIds->begin());
856   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
857   bool ret=false;
858   const int *idIt=diffVals->begin();
859   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
860   int offset2=0;
861   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
862     {
863       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
864       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
865       int nbEntityElts=subIds->getNumberOfTuples();
866       bool ret2;
867       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
868         NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
869                                     offset+offset2,
870                                     li,glob,ret2);
871       ret=ret || ret2;
872       result.push_back(eltToAdd);
873       offset2+=nbEntityElts*nbi;
874     }
875   ret=ret || li.empty();
876   return ret;
877 }
878
879 /*!
880  * \param [in] typeF type of field of new chunk
881  * \param [in] geoType the geometric type of the chunk
882  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
883  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
884  * \param [in] nbi number of integration points
885  * \param [in] offset The offset in the **global array of data**.
886  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
887  *                 to the new chunk to create.
888  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
889  * \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
890  *              and corresponding entry erased from \a entriesOnSameDisc.
891  * \return a newly allocated chunk
892  */
893 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
894                                                                                                   bool isPfl, int nbi, int offset,
895                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
896                                                                                                   MEDFileFieldGlobsReal& glob,
897                                                                                                   bool &notInExisting) throw(INTERP_KERNEL::Exception)
898 {
899   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
900   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
901   for(;it!=entriesOnSameDisc.end();it++)
902     {
903       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
904         {
905           if(!isPfl)
906             {
907               if((*it)->_profile.empty())
908                 break;
909               else
910                 if(!(*it)->_profile.empty())
911                   {
912                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
913                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
914                       break;
915                   }
916             }
917         }
918     }
919   if(it==entriesOnSameDisc.end())
920     {
921       notInExisting=true;
922       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
923       ret->_type=typeF;
924       ret->_loc_id=(int)geoType;
925       ret->_nval=nbMeshEntities;
926       ret->_start=offset;
927       ret->_end=ret->_start+ret->_nval*nbi;
928       if(isPfl)
929         {
930           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
931           glob.appendProfile(idsOfMeshElt);
932           ret->_profile=idsOfMeshElt->getName();
933         }
934       //tony treatment of localization
935       return ret;
936     }
937   else
938     {
939       notInExisting=false;
940       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
941       ret->_loc_id=(int)geoType;
942       ret->setNewStart(offset);
943       entriesOnSameDisc.erase(it);
944       return ret;
945     }
946   
947 }
948
949 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
950 {
951   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc);
952 }
953
954 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
955 {
956   return new MEDFileFieldPerMeshPerType(fath,geoType);
957 }
958
959 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySize() const
960 {
961   std::size_t ret=_field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
962   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
963     ret+=(*it)->getHeapMemorySize();
964   return ret;
965 }
966
967 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const throw(INTERP_KERNEL::Exception)
968 {
969   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
970   ret->_father=father;
971   std::size_t i=0;
972   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
973     {
974       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
975         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
976     }
977   return ret.retn();
978 }
979
980 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
981 {
982   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
983   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
984     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
985 }
986
987 /*!
988  * This method is the most general one. No optimization is done here.
989  * \param [in] multiTypePfl is the end user profile specified in high level API
990  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
991  * \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.
992  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
993  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
994  * \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.
995  */
996 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)
997 {
998   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
999   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1000     _field_pm_pt_pd[*it]->assignFieldProfile(start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1001 }
1002
1003 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1004 {
1005   _field_pm_pt_pd.resize(1);
1006   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1007   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1008 }
1009
1010 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1011 {
1012   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1013   //
1014   _field_pm_pt_pd.resize(1);
1015   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1016   _field_pm_pt_pd[0]->assignFieldProfile(start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1017 }
1018
1019 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
1020 {
1021   TypeOfField type=field->getTypeOfField();
1022   if(type!=ON_GAUSS_PT)
1023     {
1024       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1025       int sz=_field_pm_pt_pd.size();
1026       bool found=false;
1027       for(int j=0;j<sz && !found;j++)
1028         {
1029           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1030             {
1031               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1032               found=true;
1033             }
1034         }
1035       if(!found)
1036         {
1037           _field_pm_pt_pd.resize(sz+1);
1038           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1039         }
1040       std::vector<int> ret(1,0);
1041       return ret;
1042     }
1043   else
1044     {
1045       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1046       int sz2=ret2.size();
1047       std::vector<int> ret3(sz2);
1048       int k=0;
1049       for(int i=0;i<sz2;i++)
1050         {
1051           int sz=_field_pm_pt_pd.size();
1052           int locIdToFind=ret2[i];
1053           bool found=false;
1054           for(int j=0;j<sz && !found;j++)
1055             {
1056               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1057                 {
1058                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1059                   ret3[k++]=j;
1060                   found=true;
1061                 }
1062             }
1063           if(!found)
1064             {
1065               _field_pm_pt_pd.resize(sz+1);
1066               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1067               ret3[k++]=sz;
1068             }
1069         }
1070       return ret3;
1071     }
1072 }
1073
1074 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
1075 {
1076   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1077   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1078   if(!disc2)
1079     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1080   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1081   if(!da)
1082     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1083   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1084   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1085   if(retTmp->presenceOfValue(-1))
1086     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1087   std::vector<int> ret(retTmp->begin(),retTmp->end());
1088   return ret;
1089 }
1090
1091 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1092 {
1093   TypeOfField type=field->getTypeOfField();
1094   if(type!=ON_GAUSS_PT)
1095     {
1096       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1097       int sz=_field_pm_pt_pd.size();
1098       bool found=false;
1099       for(int j=0;j<sz && !found;j++)
1100         {
1101           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1102             {
1103               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1104               found=true;
1105             }
1106         }
1107       if(!found)
1108         {
1109           _field_pm_pt_pd.resize(sz+1);
1110           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1111         }
1112       std::vector<int> ret(1,0);
1113       return ret;
1114     }
1115   else
1116     {
1117       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1118       int sz2=ret2.size();
1119       std::vector<int> ret3(sz2);
1120       int k=0;
1121       for(int i=0;i<sz2;i++)
1122         {
1123           int sz=_field_pm_pt_pd.size();
1124           int locIdToFind=ret2[i];
1125           bool found=false;
1126           for(int j=0;j<sz && !found;j++)
1127             {
1128               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1129                 {
1130                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1131                   ret3[k++]=j;
1132                   found=true;
1133                 }
1134             }
1135           if(!found)
1136             {
1137               _field_pm_pt_pd.resize(sz+1);
1138               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1139               ret3[k++]=sz;
1140             }
1141         }
1142       return ret3;
1143     }
1144 }
1145
1146 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1147 {
1148   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1149   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1150   if(!disc2)
1151     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1152   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1153   if(!da)
1154     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1155   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1156   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1157   if(retTmp->presenceOfValue(-1))
1158     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1159   std::vector<int> ret(retTmp->begin(),retTmp->end());
1160   return ret;
1161 }
1162
1163 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1164 {
1165   return _father;
1166 }
1167
1168 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1169 {
1170   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1171   int curDim=(int)cm.getDimension();
1172   dim=std::max(dim,curDim);
1173 }
1174
1175 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1176 {
1177   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1178     {
1179       (*it)->fillTypesOfFieldAvailable(types);
1180     }
1181 }
1182
1183 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)
1184 {
1185   int sz=_field_pm_pt_pd.size();
1186   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1187   for(int i=0;i<sz;i++)
1188     {
1189       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1190     }
1191 }
1192
1193 int MEDFileFieldPerMeshPerType::getIteration() const
1194 {
1195   return _father->getIteration();
1196 }
1197
1198 int MEDFileFieldPerMeshPerType::getOrder() const
1199 {
1200   return _father->getOrder();
1201 }
1202
1203 double MEDFileFieldPerMeshPerType::getTime() const
1204 {
1205   return _father->getTime();
1206 }
1207
1208 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1209 {
1210   return _father->getMeshName();
1211 }
1212
1213 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1214 {
1215   const char startLine[]="  ## ";
1216   std::string startLine2(bkOffset,' ');
1217   std::string startLine3(startLine2);
1218   startLine3+=startLine;
1219   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1220     {
1221       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1222       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1223     }
1224   else
1225     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1226   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1227   int i=0;
1228   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1229     {
1230       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1231       if(cur)
1232         cur->simpleRepr(bkOffset,oss,i);
1233       else
1234         {
1235           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1236         }
1237     }
1238 }
1239
1240 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1241 {
1242   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1243     {
1244       globalSz+=(*it)->getNumberOfTuples();
1245     }
1246   nbOfEntries+=(int)_field_pm_pt_pd.size();
1247 }
1248
1249 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1250 {
1251   return _geo_type;
1252 }
1253
1254
1255 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1256 {
1257   return _father->getNumberOfComponents();
1258 }
1259
1260 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1261 {
1262   return _father->getOrCreateAndGetArray();
1263 }
1264
1265 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1266 {
1267   const MEDFileFieldPerMesh *fath=_father;
1268   return fath->getOrCreateAndGetArray();
1269 }
1270
1271 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1272 {
1273   return _father->getInfo();
1274 }
1275
1276 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1277 {
1278   std::vector<std::string> ret;
1279   std::set<std::string> ret2;
1280   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1281     {
1282       std::string tmp=(*it1)->getProfile();
1283       if(!tmp.empty())
1284         if(ret2.find(tmp)==ret2.end())
1285           {
1286             ret.push_back(tmp);
1287             ret2.insert(tmp);
1288           }
1289     }
1290   return ret;
1291 }
1292
1293 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1294 {
1295   std::vector<std::string> ret;
1296   std::set<std::string> ret2;
1297   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1298     {
1299       std::string tmp=(*it1)->getLocalization();
1300       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1301         if(ret2.find(tmp)==ret2.end())
1302           {
1303             ret.push_back(tmp);
1304             ret2.insert(tmp);
1305           }
1306     }
1307   return ret;
1308 }
1309
1310 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1311 {
1312   std::vector<std::string> ret;
1313   std::set<std::string> ret2;
1314   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1315     {
1316       std::string tmp=(*it1)->getProfile();
1317       if(!tmp.empty())
1318         ret.push_back(tmp);
1319     }
1320   return ret;
1321 }
1322
1323 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1324 {
1325   std::vector<std::string> ret;
1326   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1327     {
1328       std::string tmp=(*it1)->getLocalization();
1329       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1330         ret.push_back(tmp);
1331     }
1332   return ret;
1333 }
1334
1335 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1336 {
1337   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1338     (*it1)->changePflsRefsNamesGen(mapOfModif);
1339 }
1340
1341 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1342 {
1343   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1344     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1345 }
1346
1347 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) throw(INTERP_KERNEL::Exception)
1348 {
1349   if(_field_pm_pt_pd.empty())
1350     {
1351       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1352       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1353       throw INTERP_KERNEL::Exception(oss.str().c_str());
1354     }
1355   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1356     return _field_pm_pt_pd[locId];
1357   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1358   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1359   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1360   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1361   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1362 }
1363
1364 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const throw(INTERP_KERNEL::Exception)
1365 {
1366   if(_field_pm_pt_pd.empty())
1367     {
1368       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1369       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1370       throw INTERP_KERNEL::Exception(oss.str().c_str());
1371     }
1372   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1373     return _field_pm_pt_pd[locId];
1374   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1375   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1376   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1377   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1378   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1379 }
1380
1381 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
1382 {
1383   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1384     {
1385       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1386       if(meshDim!=(int)cm.getDimension())
1387         return ;
1388     }
1389   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1390     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1391 }
1392
1393 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1394 {
1395   int i=0;
1396   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1397     {
1398       (*it)->fillValues(i,startEntryId,entries);
1399     }
1400 }
1401
1402 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1403 {
1404   _field_pm_pt_pd=leaves;
1405   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1406     (*it)->setFather(this);
1407 }
1408
1409 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType)
1410 {
1411 }
1412
1413 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)
1414 {
1415   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1416   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1417   med_geometry_type mgeoti;
1418   med_entity_type menti=ConvertIntoMEDFileType(type,geoType,mgeoti);
1419   int nbProfiles=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName);
1420   _field_pm_pt_pd.resize(nbProfiles);
1421   for(int i=0;i<nbProfiles;i++)
1422     {
1423       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i+1);
1424     }
1425 }
1426
1427 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1428 {
1429   int pflId=0;
1430   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1431     {
1432       (*it)->loadOnlyStructureOfDataRecursively(fid,pflId+1,start,nasc);//tony
1433     }
1434 }
1435
1436 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1437 {
1438   int pflId=0;
1439   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1440     {
1441       (*it)->loadBigArray(fid,pflId+1,nasc);//tony
1442     }
1443 }
1444
1445 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
1446 {
1447   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1448     {
1449       (*it)->copyOptionsFrom(*this);
1450       (*it)->writeLL(fid,nasc);
1451     }
1452 }
1453
1454 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1455 {
1456   switch(ikType)
1457     {
1458     case ON_CELLS:
1459       medfGeoType=typmai3[(int)ikGeoType];
1460       return MED_CELL;
1461     case ON_NODES:
1462       medfGeoType=MED_NONE;
1463       return MED_NODE;
1464     case ON_GAUSS_NE:
1465       medfGeoType=typmai3[(int)ikGeoType];
1466       return MED_NODE_ELEMENT;
1467     case ON_GAUSS_PT:
1468       medfGeoType=typmai3[(int)ikGeoType];
1469       return MED_CELL;
1470     default:
1471       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1472     }
1473   return MED_UNDEF_ENTITY_TYPE;
1474 }
1475
1476 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1477 {
1478   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc);
1479 }
1480
1481 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1482 {
1483   return new MEDFileFieldPerMesh(fath,mesh);
1484 }
1485
1486 std::size_t MEDFileFieldPerMesh::getHeapMemorySize() const
1487 {
1488   std::size_t ret=_mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1489   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1490     if((const MEDFileFieldPerMeshPerType *)*it)
1491       ret+=(*it)->getHeapMemorySize();
1492   return ret;
1493 }
1494
1495 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const throw(INTERP_KERNEL::Exception)
1496 {
1497   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1498   ret->_father=father;
1499   std::size_t i=0;
1500   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1501     {
1502       if((const MEDFileFieldPerMeshPerType *)*it)
1503         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1504     }
1505   return ret.retn();
1506 }
1507
1508 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1509 {
1510   std::string startLine(bkOffset,' ');
1511   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1512   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1513   int i=0;
1514   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1515     {
1516       const MEDFileFieldPerMeshPerType *cur=*it;
1517       if(cur)
1518         cur->simpleRepr(bkOffset,oss,i);
1519       else
1520         {
1521           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1522         }
1523     }
1524 }
1525
1526 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
1527 {
1528   _mesh_name=mesh->getName();
1529   mesh->getTime(_mesh_iteration,_mesh_order);
1530 }
1531
1532 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)
1533 {
1534   int nbOfTypes=code.size()/3;
1535   int offset=0;
1536   for(int i=0;i<nbOfTypes;i++)
1537     {
1538       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1539       int nbOfCells=code[3*i+1];
1540       int pos=addNewEntryIfNecessary(type);
1541       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1542       offset+=nbOfCells;
1543     }
1544 }
1545
1546 /*!
1547  * This method is the most general one. No optimization is done here.
1548  * \param [in] multiTypePfl is the end user profile specified in high level API
1549  * \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].
1550  * \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.
1551  * \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.
1552  * \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.
1553  * \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.
1554  */
1555 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)
1556 {
1557   int nbOfTypes=code.size()/3;
1558   for(int i=0;i<nbOfTypes;i++)
1559     {
1560       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1561       int pos=addNewEntryIfNecessary(type);
1562       DataArrayInt *pfl=0;
1563       if(code[3*i+2]!=-1)
1564         pfl=idsPerType[code[3*i+2]];
1565       int nbOfTupes2=code2.size()/3;
1566       int found=0;
1567       for(;found<nbOfTupes2;found++)
1568         if(code[3*i]==code2[3*found])
1569           break;
1570       if(found==nbOfTupes2)
1571         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1572       _field_pm_pt[pos]->assignFieldProfile(start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1573     }
1574 }
1575
1576 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1577 {
1578   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1579   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1580 }
1581
1582 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1583 {
1584   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1585   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1586 }
1587
1588 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1589 {
1590   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1591     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1592 }
1593
1594 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1595 {
1596   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1597     (*it)->loadBigArraysRecursively(fid,nasc);
1598 }
1599
1600 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
1601 {
1602   int nbOfTypes=_field_pm_pt.size();
1603   for(int i=0;i<nbOfTypes;i++)
1604     {
1605       _field_pm_pt[i]->copyOptionsFrom(*this);
1606       _field_pm_pt[i]->writeLL(fid,nasc);
1607     }
1608 }
1609
1610 void MEDFileFieldPerMesh::getDimension(int& dim) const
1611 {
1612   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1613     (*it)->getDimension(dim);
1614 }
1615
1616 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1617 {
1618   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1619     (*it)->fillTypesOfFieldAvailable(types);
1620 }
1621
1622 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)
1623 {
1624   int sz=_field_pm_pt.size();
1625   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1626   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1627   for(int i=0;i<sz;i++)
1628     {
1629       types[i]=_field_pm_pt[i]->getGeoType();
1630       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1631     }
1632   return ret;
1633 }
1634
1635 double MEDFileFieldPerMesh::getTime() const
1636 {
1637   int tmp1,tmp2;
1638   return _father->getTime(tmp1,tmp2);
1639 }
1640
1641 int MEDFileFieldPerMesh::getIteration() const
1642 {
1643   return _father->getIteration();
1644 }
1645
1646 int MEDFileFieldPerMesh::getOrder() const
1647 {
1648   return _father->getOrder();
1649 }
1650
1651 int MEDFileFieldPerMesh::getNumberOfComponents() const
1652 {
1653   return _father->getNumberOfComponents();
1654 }
1655
1656 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1657 {
1658   if(!_father)
1659     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1660   return _father->getOrCreateAndGetArray();
1661 }
1662
1663 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1664 {
1665   if(!_father)
1666     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1667   return _father->getOrCreateAndGetArray();
1668 }
1669
1670 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1671 {
1672   return _father->getInfo();
1673 }
1674
1675 /*!
1676  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1677  * 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.
1678  * It returns 2 output vectors :
1679  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1680  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1681  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1682  */
1683 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)
1684 {
1685   int notNullPflsSz=0;
1686   int nbOfArrs=geoTypes.size();
1687   for(int i=0;i<nbOfArrs;i++)
1688     if(pfls[i])
1689       notNullPflsSz++;
1690   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1691   int nbOfDiffGeoTypes=geoTypes3.size();
1692   code.resize(3*nbOfDiffGeoTypes);
1693   notNullPfls.resize(notNullPflsSz);
1694   notNullPflsSz=0;
1695   int j=0;
1696   for(int i=0;i<nbOfDiffGeoTypes;i++)
1697     {
1698       int startZone=j;
1699       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1700       std::vector<const DataArrayInt *> notNullTmp;
1701       if(pfls[j])
1702         notNullTmp.push_back(pfls[j]);
1703       j++;
1704       for(;j<nbOfArrs;j++)
1705         if(geoTypes[j]==refType)
1706           {
1707             if(pfls[j])
1708               notNullTmp.push_back(pfls[j]);
1709           }
1710         else
1711           break;
1712       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1713       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1714       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1715       code[3*i]=(int)refType;
1716       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1717       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1718       if(notNullTmp.empty())
1719         code[3*i+2]=-1;
1720       else
1721         {
1722           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1723           code[3*i+2]=notNullPflsSz++;
1724         }
1725     }
1726 }
1727
1728 /*!
1729  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1730  */
1731 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)
1732 {
1733   int sz=dads.size();
1734   int ret=0;
1735   for(int i=0;i<sz;i++)
1736     {
1737       if(locs[i]==-1)
1738         {
1739           if(type!=ON_GAUSS_NE)
1740             ret+=dads[i].second-dads[i].first;
1741           else
1742             {
1743               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1744               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1745             }
1746         }
1747       else
1748         {
1749           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1750           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1751         }
1752     }
1753   return ret;
1754 }
1755
1756 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1757 {
1758   std::vector<std::string> ret;
1759   std::set<std::string> ret2;
1760   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1761     {
1762       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1763       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1764         if(ret2.find(*it2)==ret2.end())
1765           {
1766             ret.push_back(*it2);
1767             ret2.insert(*it2);
1768           }
1769     }
1770   return ret;
1771 }
1772
1773 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1774 {
1775   std::vector<std::string> ret;
1776   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1777     {
1778       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1779       ret.insert(ret.end(),tmp.begin(),tmp.end());
1780     }
1781   return ret;
1782 }
1783
1784 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1785 {
1786   std::vector<std::string> ret;
1787   std::set<std::string> ret2;
1788   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1789     {
1790       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1791       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1792         if(ret2.find(*it2)==ret2.end())
1793           {
1794             ret.push_back(*it2);
1795             ret2.insert(*it2);
1796           }
1797     }
1798   return ret;
1799 }
1800
1801 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1802 {
1803   std::vector<std::string> ret;
1804   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1805     {
1806       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1807       ret.insert(ret.end(),tmp.begin(),tmp.end());
1808     }
1809   return ret;
1810 }
1811
1812 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
1813 {
1814   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1815     {
1816       if((*it).first==_mesh_name)
1817         {
1818           _mesh_name=(*it).second;
1819           return true;
1820         }
1821     }
1822   return false;
1823 }
1824
1825 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1826                                                       MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1827 {
1828   if(_mesh_name!=meshName)
1829     return false;
1830   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1831   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1832   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1833   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1834   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1835   getUndergroundDataArrayExt(entries);
1836   DataArray *arr0=getOrCreateAndGetArray();//tony
1837   if(!arr0)
1838     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
1839   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
1840   if(!arr0)
1841     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
1842   int sz=0;
1843   if(!arr)
1844     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1845   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1846     {
1847       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1848         {
1849           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1850           sz+=(*it).second.second-(*it).second.first;
1851         }
1852       else
1853         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1854     }
1855   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1856   ////////////////////
1857   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1858   int *workI2=explicitIdsOldInMesh->getPointer();
1859   int sz1=0,sz2=0,sid=1;
1860   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1861   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1862   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1863     {
1864       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1865       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1866       int *workI=explicitIdsOldInArr->getPointer();
1867       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1868         {
1869           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1870           (*itL2)->setLocId(sz2);
1871           (*itL2)->_tmp_work1=(*itL2)->getStart();
1872           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1873         }
1874       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1875     }
1876   explicitIdsOldInMesh->reAlloc(sz2);
1877   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1878   ////////////////////
1879   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1880   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1881   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1882   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1883     {
1884       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1885       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1886       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1887     }
1888   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1889   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1890   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
1891     {
1892       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1893       int newStart=elt->getLocId();
1894       elt->setLocId((*it)->getGeoType());
1895       elt->setNewStart(newStart);
1896       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
1897       entriesKeptNew.push_back(elt);
1898       entriesKeptNew2.push_back(elt);
1899     }
1900   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
1901   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
1902   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
1903   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
1904   bool ret=false;
1905   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
1906     {
1907       sid=0;
1908       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
1909         {
1910           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
1911           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
1912           }*/
1913       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
1914                                                             glob,arr2,otherEntriesNew) || ret;
1915     }
1916   if(!ret)
1917     return false;
1918   // Assign new dispatching
1919   assignNewLeaves(otherEntriesNew);
1920   arr->cpyFrom(*arr2);
1921   return true;
1922 }
1923
1924 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1925 {
1926   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
1927   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
1928     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
1929   //
1930   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
1931   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
1932   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
1933   for(;it1!=types.end();it1++,it2++)
1934     {
1935       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
1936       elt->setLeaves((*it1).second);
1937       *it2=elt;
1938     }
1939   _field_pm_pt=fieldPmPt;
1940 }
1941
1942 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1943 {
1944   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1945     (*it)->changePflsRefsNamesGen(mapOfModif);
1946 }
1947
1948 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1949 {
1950   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1951     (*it)->changeLocsRefsNamesGen(mapOfModif);
1952 }
1953
1954 /*!
1955  * \param [in] mesh is the whole mesh
1956  */
1957 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
1958 {
1959   if(_field_pm_pt.empty())
1960     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
1961   //
1962   std::vector< std::pair<int,int> > dads;
1963   std::vector<const DataArrayInt *> pfls;
1964   std::vector<DataArrayInt *> notNullPflsPerGeoType;
1965   std::vector<int> locs,code;
1966   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
1967   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1968     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
1969   // Sort by types
1970   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
1971   if(code.empty())
1972     {
1973       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
1974       throw INTERP_KERNEL::Exception(oss.str().c_str());
1975     }
1976   //
1977   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
1978   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
1979   if(type!=ON_NODES)
1980     {
1981       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
1982       if(!arr)
1983         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
1984       else
1985         {
1986           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
1987           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
1988         }
1989     }
1990   else
1991     {
1992       if(code.size()!=3)
1993         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
1994       int nb=code[1];
1995       if(code[2]==-1)
1996         {
1997           if(nb!=mesh->getNumberOfNodes())
1998             {
1999               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2000               oss << " nodes in mesh !";
2001               throw INTERP_KERNEL::Exception(oss.str().c_str());
2002             }
2003           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2004         }
2005       else
2006         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2007     }
2008 }
2009
2010 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2011 {
2012   if(_field_pm_pt.empty())
2013     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2014   //
2015   std::vector<std::pair<int,int> > dads;
2016   std::vector<const DataArrayInt *> pfls;
2017   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2018   std::vector<int> locs,code;
2019   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2020   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2021     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2022   // Sort by types
2023   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2024   if(code.empty())
2025     {
2026       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2027       throw INTERP_KERNEL::Exception(oss.str().c_str());
2028     }
2029   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2030   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2031   if(type!=ON_NODES)
2032     {
2033       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2034       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2035     }
2036   else
2037     {
2038       if(code.size()!=3)
2039         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2040       int nb=code[1];
2041       if(code[2]==-1)
2042         {
2043           if(nb!=mesh->getNumberOfNodes())
2044             {
2045               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2046               oss << " nodes in mesh !";
2047               throw INTERP_KERNEL::Exception(oss.str().c_str());
2048             }
2049         }
2050       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2051     }
2052   //
2053   return 0;
2054 }
2055
2056 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
2057 {
2058   int globalSz=0;
2059   int nbOfEntries=0;
2060   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2061     {
2062       (*it)->getSizes(globalSz,nbOfEntries);
2063     }
2064   entries.resize(nbOfEntries);
2065   nbOfEntries=0;
2066   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2067     {
2068       (*it)->fillValues(nbOfEntries,entries);
2069     }
2070 }
2071
2072 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
2073 {
2074   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2075     {
2076       if((*it)->getGeoType()==typ)
2077         return (*it)->getLeafGivenLocId(locId);
2078     }
2079   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2080   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2081   oss << "Possiblities are : ";
2082   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2083     {
2084       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2085       oss << "\"" << cm2.getRepr() << "\", ";
2086     }
2087   throw INTERP_KERNEL::Exception(oss.str().c_str());
2088 }
2089
2090 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
2091 {
2092   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2093     {
2094       if((*it)->getGeoType()==typ)
2095         return (*it)->getLeafGivenLocId(locId);
2096     }
2097   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2098   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2099   oss << "Possiblities are : ";
2100   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2101     {
2102       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2103       oss << "\"" << cm2.getRepr() << "\", ";
2104     }
2105   throw INTERP_KERNEL::Exception(oss.str().c_str());
2106 }
2107
2108 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2109 {
2110   int i=0;
2111   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2112   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2113   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2114     {
2115       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2116       if(type==curType)
2117         return i;
2118       else
2119         {
2120           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2121           if(pos>pos2)
2122             it2=it+1;
2123         }
2124     }
2125   int ret=std::distance(_field_pm_pt.begin(),it2);
2126   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2127   return ret;
2128 }
2129
2130 /*!
2131  * 'dads' and 'locs' input parameters have the same number of elements
2132  * \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
2133  */
2134 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2135                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2136                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2137 {
2138   isPfl=false;
2139   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2140   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2141   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2142   const std::vector<std::string>& infos=getInfo();
2143   da->setInfoOnComponents(infos);
2144   da->setName("");
2145   if(type==ON_GAUSS_PT)
2146     {
2147       int offset=0;
2148       int nbOfArrs=dads.size();
2149       for(int i=0;i<nbOfArrs;i++)
2150         {
2151           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2152           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2153           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2154           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2155           di->alloc(nbOfElems,1);
2156           di->iota(offset);
2157           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2158           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2159           offset+=nbOfElems;
2160         }
2161     }
2162   arrOut=da;
2163   return ret.retn();
2164 }
2165
2166 /*!
2167  * 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.
2168  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2169  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2170  * The order of cells in the returned field is those imposed by the profile.
2171  * \param [in] mesh is the global mesh.
2172  */
2173 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2174                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2175                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2176                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2177 {
2178   if(da->isIdentity())
2179     {
2180       int nbOfTuples=da->getNumberOfTuples();
2181       if(nbOfTuples==mesh->getNumberOfCells())
2182         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2183     }
2184   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2185   m2->setName(mesh->getName());
2186   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2187   isPfl=true;
2188   return ret.retn();
2189 }
2190
2191 /*!
2192  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2193  */
2194 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2195                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2196                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2197 {
2198   if(da->isIdentity())
2199     {
2200       int nbOfTuples=da->getNumberOfTuples();
2201       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2202         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2203     }
2204   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2205   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2206   if(meshu)
2207     {
2208       if(meshu->getNodalConnectivity()==0)
2209         {
2210           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2211           int nb=da->getNbOfElems();
2212           const int *ptr=da->getConstPointer();
2213           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2214           meshuc->allocateCells(nb);
2215           for(int i=0;i<nb;i++)
2216             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2217           meshuc->finishInsertingCells();
2218           ret->setMesh(meshuc);
2219           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2220           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2221           disc->checkCoherencyBetween(meshuc,arrOut);
2222           return ret.retn();
2223         }
2224     }
2225   //
2226   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2227   isPfl=true;
2228   DataArrayInt *arr2=0;
2229   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2230   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2231   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2232   int nnodes=mesh2->getNumberOfNodes();
2233   if(nnodes==(int)da->getNbOfElems())
2234     {
2235       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2236       arrOut->renumberInPlace(da3->getConstPointer());
2237       mesh2->setName(mesh->getName());
2238       ret->setMesh(mesh2);
2239       return ret.retn();
2240     }
2241   else
2242     {
2243       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 !!!";
2244       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2245       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2246       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2247       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2248       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2249       throw INTERP_KERNEL::Exception(oss.str().c_str());
2250     }
2251   return 0;
2252 }
2253
2254 /*!
2255  * This method is the most light method of field retrieving.
2256  */
2257 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const throw(INTERP_KERNEL::Exception)
2258 {
2259   if(!pflIn)
2260     {
2261       pflOut=DataArrayInt::New();
2262       pflOut->alloc(nbOfElems,1);
2263       pflOut->iota(0);
2264     }
2265   else
2266     {
2267       pflOut=const_cast<DataArrayInt*>(pflIn);
2268       pflOut->incrRef();
2269     }
2270   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2271   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2272   const std::vector<std::string>& infos=getInfo();
2273   int nbOfComp=infos.size();
2274   for(int i=0;i<nbOfComp;i++)
2275     da->setInfoOnComponent(i,infos[i].c_str());
2276   safePfl->incrRef();
2277   return da.retn();
2278 }
2279
2280 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),
2281                                                                                                                                                                                                                  _mesh_csit(meshCsit),_father(fath)
2282 {
2283   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2284   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2285   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2286   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2287     {
2288       int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL,typmai[i],_mesh_csit,meshName,pflName,locName);
2289       if(nbProfile>0)
2290         {
2291           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i],nasc));
2292           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2293         }
2294       nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],_mesh_csit,meshName,pflName,locName);
2295       if(nbProfile>0)
2296         {
2297           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_GAUSS_NE,typmai2[i],nasc));
2298           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2299         }
2300     }
2301   int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,_mesh_csit,meshName,pflName,locName);
2302   if(nbProfile>0)
2303     {
2304       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc));
2305       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2306     }
2307 }
2308
2309 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2310 {
2311   copyTinyInfoFrom(mesh);
2312 }
2313
2314 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
2315 {
2316   if(id>=(int)_pfls.size())
2317     _pfls.resize(id+1);
2318   _pfls[id]=DataArrayInt::New();
2319   int lgth=MEDprofileSizeByName(fid,pflName);
2320   _pfls[id]->setName(pflName);
2321   _pfls[id]->alloc(lgth,1);
2322   MEDprofileRd(fid,pflName,_pfls[id]->getPointer());
2323   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2324 }
2325
2326 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2327 {
2328   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2329   int sz;
2330   MEDprofileInfo(fid,i+1,pflName,&sz);
2331   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2332   if(i>=(int)_pfls.size())
2333     _pfls.resize(i+1);
2334   _pfls[i]=DataArrayInt::New();
2335   _pfls[i]->alloc(sz,1);
2336   _pfls[i]->setName(pflCpp.c_str());
2337   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2338   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2339 }
2340
2341 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
2342 {
2343   int nbOfPfls=_pfls.size();
2344   for(int i=0;i<nbOfPfls;i++)
2345     {
2346       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2347       cpy->applyLin(1,1,0);
2348       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2349       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2350       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2351     }
2352   //
2353   int nbOfLocs=_locs.size();
2354   for(int i=0;i<nbOfLocs;i++)
2355     _locs[i]->writeLL(fid);
2356 }
2357
2358 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps) throw(INTERP_KERNEL::Exception)
2359 {
2360   std::vector<std::string> pfls=getPfls();
2361   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2362     {
2363       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2364       if(it2==pfls.end())
2365         {
2366           _pfls.push_back(*it);
2367         }
2368       else
2369         {
2370           int id=std::distance(pfls.begin(),it2);
2371           if(!(*it)->isEqual(*_pfls[id]))
2372             {
2373               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2374               throw INTERP_KERNEL::Exception(oss.str().c_str());
2375             }
2376         }
2377     }
2378   std::vector<std::string> locs=getLocs();
2379   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2380     {
2381       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2382       if(it2==locs.end())
2383         {
2384           _locs.push_back(*it);
2385         }
2386       else
2387         {
2388           int id=std::distance(locs.begin(),it2);
2389           if(!(*it)->isEqual(*_locs[id],eps))
2390             {
2391               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2392               throw INTERP_KERNEL::Exception(oss.str().c_str());
2393             }
2394         }
2395     }
2396 }
2397
2398 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const throw(INTERP_KERNEL::Exception)
2399 {
2400   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2401     getProfile((*it).c_str());
2402 }
2403
2404 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const throw(INTERP_KERNEL::Exception)
2405 {
2406   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2407     getLocalization((*it).c_str());
2408 }
2409
2410 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real) throw(INTERP_KERNEL::Exception)
2411 {
2412   std::vector<std::string> profiles=real.getPflsReallyUsed();
2413   int sz=profiles.size();
2414   _pfls.resize(sz);
2415   for(int i=0;i<sz;i++)
2416     loadProfileInFile(fid,i,profiles[i].c_str());
2417   //
2418   std::vector<std::string> locs=real.getLocsReallyUsed();
2419   sz=locs.size();
2420   _locs.resize(sz);
2421   for(int i=0;i<sz;i++)
2422     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2423 }
2424
2425 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2426 {
2427   int nProfil=MEDnProfile(fid);
2428   for(int i=0;i<nProfil;i++)
2429     loadProfileInFile(fid,i);
2430   int sz=MEDnLocalization(fid);
2431   _locs.resize(sz);
2432   for(int i=0;i<sz;i++)
2433     {
2434       _locs[i]=MEDFileFieldLoc::New(fid,i);
2435     }
2436 }
2437
2438 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const char *fname)
2439 {
2440   return new MEDFileFieldGlobs(fname);
2441 }
2442
2443 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2444 {
2445   return new MEDFileFieldGlobs;
2446 }
2447
2448 std::size_t MEDFileFieldGlobs::getHeapMemorySize() const
2449 {
2450   std::size_t ret=_file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2451   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2452     ret+=(*it)->getHeapMemorySize();
2453   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2454     ret+=(*it)->getHeapMemorySize();
2455   return ret;
2456 }
2457
2458 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const throw(INTERP_KERNEL::Exception)
2459 {
2460   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2461   std::size_t i=0;
2462   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2463     {
2464       if((const DataArrayInt *)*it)
2465         ret->_pfls[i]=(*it)->deepCpy();
2466     }
2467   i=0;
2468   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2469     {
2470       if((const MEDFileFieldLoc*)*it)
2471         ret->_locs[i]=(*it)->deepCpy();
2472     }
2473   return ret.retn();
2474 }
2475
2476 /*!
2477  * \throw if a profile in \a pfls in not in \a this.
2478  * \throw if a localization in \a locs in not in \a this.
2479  * \sa MEDFileFieldGlobs::deepCpyPart
2480  */
2481 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const throw(INTERP_KERNEL::Exception)
2482 {
2483   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2484   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2485     {
2486       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2487       if(!pfl)
2488         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2489       pfl->incrRef();
2490       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2491       ret->_pfls.push_back(pfl2);
2492     }
2493   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2494     {
2495       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2496       if(!loc)
2497         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2498       loc->incrRef();
2499       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2500       ret->_locs.push_back(loc2);
2501     }
2502   ret->setFileName(getFileName());
2503   return ret.retn();
2504 }
2505
2506 /*!
2507  * \throw if a profile in \a pfls in not in \a this.
2508  * \throw if a localization in \a locs in not in \a this.
2509  * \sa MEDFileFieldGlobs::shallowCpyPart
2510  */
2511 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const throw(INTERP_KERNEL::Exception)
2512 {
2513   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2514   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2515     {
2516       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2517       if(!pfl)
2518         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2519       ret->_pfls.push_back(pfl->deepCpy());
2520     }
2521   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2522     {
2523       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2524       if(!loc)
2525         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2526       ret->_locs.push_back(loc->deepCpy());
2527     }
2528   ret->setFileName(getFileName());
2529   return ret.retn();
2530 }
2531
2532 MEDFileFieldGlobs::MEDFileFieldGlobs(const char *fname):_file_name(fname)
2533 {
2534 }
2535
2536 MEDFileFieldGlobs::MEDFileFieldGlobs()
2537 {
2538 }
2539
2540 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2541 {
2542 }
2543
2544 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2545 {
2546   oss << "Profiles :\n";
2547   std::size_t n=_pfls.size();
2548   for(std::size_t i=0;i<n;i++)
2549     {
2550       oss << "  - #" << i << " ";
2551       const DataArrayInt *pfl=_pfls[i];
2552       if(pfl)
2553         oss << "\"" << pfl->getName() << "\"\n";
2554       else
2555         oss << "EMPTY !\n";
2556     }
2557   n=_locs.size();
2558   oss << "Localizations :\n";
2559   for(std::size_t i=0;i<n;i++)
2560     {
2561       oss << "  - #" << i << " ";
2562       const MEDFileFieldLoc *loc=_locs[i];
2563       if(loc)
2564         loc->simpleRepr(oss);
2565       else
2566         oss<< "EMPTY !\n";
2567     }
2568 }
2569
2570 void MEDFileFieldGlobs::setFileName(const char *fileName)
2571 {
2572   _file_name=fileName;
2573 }
2574
2575 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2576 {
2577   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2578     {
2579       DataArrayInt *elt(*it);
2580       if(elt)
2581         {
2582           std::string name(elt->getName());
2583           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2584             {
2585               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2586                 {
2587                   elt->setName((*it2).second.c_str());
2588                   return;
2589                 }
2590             }
2591         }
2592     }
2593 }
2594
2595 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2596 {
2597   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2598     {
2599       MEDFileFieldLoc *elt(*it);
2600       if(elt)
2601         {
2602           std::string name(elt->getName());
2603           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2604             {
2605               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2606                 {
2607                   elt->setName((*it2).second.c_str());
2608                   return;
2609                 }
2610             }
2611         }
2612     }
2613 }
2614
2615 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
2616 {
2617   if(locId<0 || locId>=(int)_locs.size())
2618     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2619   return _locs[locId]->getNbOfGaussPtPerCell();
2620 }
2621
2622 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
2623 {
2624   return getLocalizationFromId(getLocalizationId(locName));
2625 }
2626
2627 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
2628 {
2629   if(locId<0 || locId>=(int)_locs.size())
2630     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2631   return *_locs[locId];
2632 }
2633
2634 namespace ParaMEDMEMImpl
2635 {
2636   class LocFinder
2637   {
2638   public:
2639     LocFinder(const char *loc):_loc(loc) { }
2640     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2641   private:
2642     const char *_loc;
2643   };
2644
2645   class PflFinder
2646   {
2647   public:
2648     PflFinder(const std::string& pfl):_pfl(pfl) { }
2649     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2650   private:
2651     const std::string& _pfl;
2652   };
2653 }
2654
2655 int MEDFileFieldGlobs::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
2656 {
2657   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2658   if(it==_locs.end())
2659     {
2660       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2661       for(it=_locs.begin();it!=_locs.end();it++)
2662         oss << "\"" << (*it)->getName() << "\", ";
2663       throw INTERP_KERNEL::Exception(oss.str().c_str());
2664     }
2665   return std::distance(_locs.begin(),it);
2666 }
2667
2668 /*!
2669  * The returned value is never null.
2670  */
2671 const DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
2672 {
2673   std::string pflNameCpp(pflName);
2674   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2675   if(it==_pfls.end())
2676     {
2677       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2678       for(it=_pfls.begin();it!=_pfls.end();it++)
2679         oss << "\"" << (*it)->getName() << "\", ";
2680       throw INTERP_KERNEL::Exception(oss.str().c_str());
2681     }
2682   return *it;
2683 }
2684
2685 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
2686 {
2687   if(pflId<0 || pflId>=(int)_pfls.size())
2688     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2689   return _pfls[pflId];
2690 }
2691
2692 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
2693 {
2694   if(locId<0 || locId>=(int)_locs.size())
2695     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2696   return *_locs[locId];
2697 }
2698
2699 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
2700 {
2701   return getLocalizationFromId(getLocalizationId(locName));
2702 }
2703
2704 /*!
2705  * The returned value is never null.
2706  */
2707 DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
2708 {
2709   std::string pflNameCpp(pflName);
2710   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2711   if(it==_pfls.end())
2712     {
2713       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2714       for(it=_pfls.begin();it!=_pfls.end();it++)
2715         oss << "\"" << (*it)->getName() << "\", ";
2716       throw INTERP_KERNEL::Exception(oss.str().c_str());
2717     }
2718   return *it;
2719 }
2720
2721 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
2722 {
2723   if(pflId<0 || pflId>=(int)_pfls.size())
2724     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2725   return _pfls[pflId];
2726 }
2727
2728 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
2729 {
2730   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2731   int i=0;
2732   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2733     {
2734       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2735         newPfls.push_back(*it);
2736     }
2737   _pfls=newPfls;
2738 }
2739
2740 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
2741 {
2742   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2743   int i=0;
2744   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2745     {
2746       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2747         newLocs.push_back(*it);
2748     }
2749   _locs=newLocs;
2750 }
2751
2752 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2753 {
2754   int sz=_pfls.size();
2755   std::vector<std::string> ret(sz);
2756   for(int i=0;i<sz;i++)
2757     ret[i]=_pfls[i]->getName();
2758   return ret;
2759 }
2760
2761 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2762 {
2763   int sz=_locs.size();
2764   std::vector<std::string> ret(sz);
2765   for(int i=0;i<sz;i++)
2766     ret[i]=_locs[i]->getName();
2767   return ret;
2768 }
2769
2770 bool MEDFileFieldGlobs::existsPfl(const char *pflName) const
2771 {
2772   std::vector<std::string> v=getPfls();
2773   std::string s(pflName);
2774   return std::find(v.begin(),v.end(),s)!=v.end();
2775 }
2776
2777 bool MEDFileFieldGlobs::existsLoc(const char *locName) const
2778 {
2779   std::vector<std::string> v=getLocs();
2780   std::string s(locName);
2781   return std::find(v.begin(),v.end(),s)!=v.end();
2782 }
2783
2784 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2785 {
2786   std::map<int,std::vector<int> > m;
2787   int i=0;
2788   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2789     {
2790       const DataArrayInt *tmp=(*it);
2791       if(tmp)
2792         {
2793           m[tmp->getHashCode()].push_back(i);
2794         }
2795     }
2796   std::vector< std::vector<int> > ret;
2797   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2798     {
2799       if((*it2).second.size()>1)
2800         {
2801           std::vector<int> ret0;
2802           bool equalityOrNot=false;
2803           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2804             {
2805               std::vector<int>::const_iterator it4=it3; it4++;
2806               for(;it4!=(*it2).second.end();it4++)
2807                 {
2808                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2809                     {
2810                       if(!equalityOrNot)
2811                         ret0.push_back(*it3);
2812                       ret0.push_back(*it4);
2813                       equalityOrNot=true;
2814                     }
2815                 }
2816             }
2817           if(!ret0.empty())
2818             ret.push_back(ret0);
2819         }
2820     }
2821   return ret;
2822 }
2823
2824 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2825 {
2826   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2827 }
2828
2829 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
2830 {
2831   std::string name(pfl->getName());
2832   if(name.empty())
2833     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2834   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2835     if(name==(*it)->getName())
2836       {
2837         if(!pfl->isEqual(*(*it)))
2838           {
2839             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2840             throw INTERP_KERNEL::Exception(oss.str().c_str());
2841           }
2842       }
2843   pfl->incrRef();
2844   _pfls.push_back(pfl);
2845 }
2846
2847 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)
2848 {
2849   std::string name(locName);
2850   if(name.empty())
2851     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2852   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2853   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2854     if((*it)->isName(locName))
2855       {
2856         if(!(*it)->isEqual(*obj,1e-12))
2857           {
2858             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
2859             throw INTERP_KERNEL::Exception(oss.str().c_str());
2860           }
2861       }
2862   _locs.push_back(obj);
2863 }
2864
2865 std::string MEDFileFieldGlobs::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
2866 {
2867   std::vector<std::string> names=getPfls();
2868   return CreateNewNameNotIn("NewPfl_",names);
2869 }
2870
2871 std::string MEDFileFieldGlobs::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
2872 {
2873   std::vector<std::string> names=getLocs();
2874   return CreateNewNameNotIn("NewLoc_",names);
2875 }
2876
2877 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const char *prefix, const std::vector<std::string>& namesToAvoid) throw(INTERP_KERNEL::Exception)
2878 {
2879   for(std::size_t sz=0;sz<100000;sz++)
2880     {
2881       std::ostringstream tryName;
2882       tryName << prefix << sz;
2883       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
2884         return tryName.str();
2885     }
2886   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
2887 }
2888
2889 /*!
2890  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
2891  *  \param [in] fname - the file name.
2892  */
2893 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const char *fname):_globals(MEDFileFieldGlobs::New(fname))
2894 {
2895 }
2896
2897 /*!
2898  * Creates an empty MEDFileFieldGlobsReal.
2899  */
2900 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
2901 {
2902 }
2903
2904 std::size_t MEDFileFieldGlobsReal::getHeapMemorySize() const
2905 {
2906   std::size_t ret=0;
2907   if((const MEDFileFieldGlobs *)_globals)
2908     ret+=_globals->getHeapMemorySize();
2909   return ret;
2910 }
2911
2912 /*!
2913  * Returns a string describing profiles and Gauss points held in \a this.
2914  *  \return std::string - the description string.
2915  */
2916 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
2917 {
2918   const MEDFileFieldGlobs *glob=_globals;
2919   std::ostringstream oss2; oss2 << glob;
2920   std::string stars(oss2.str().length(),'*');
2921   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
2922   if(glob)
2923     glob->simpleRepr(oss);
2924   else
2925     oss << "NO GLOBAL INFORMATION !\n";
2926 }
2927
2928 void MEDFileFieldGlobsReal::resetContent()
2929 {
2930   _globals=MEDFileFieldGlobs::New();
2931 }
2932
2933 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
2934 {
2935 }
2936
2937 /*!
2938  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
2939  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
2940  */
2941 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
2942 {
2943   _globals=other._globals;
2944 }
2945
2946 /*!
2947  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
2948  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
2949  */
2950 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other) throw(INTERP_KERNEL::Exception)
2951 {
2952   const MEDFileFieldGlobs *otherg(other._globals);
2953   if(!otherg)
2954     return ;
2955   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
2956 }
2957
2958 /*!
2959  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
2960  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
2961  */
2962 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other) throw(INTERP_KERNEL::Exception)
2963 {
2964   const MEDFileFieldGlobs *otherg(other._globals);
2965   if(!otherg)
2966     return ;
2967   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
2968 }
2969
2970 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
2971 {
2972   _globals=other._globals;
2973   if((const MEDFileFieldGlobs *)_globals)
2974     _globals=other._globals->deepCpy();
2975 }
2976
2977 /*!
2978  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
2979  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
2980  *  \param [in] eps - a precision used to compare Gauss points with same name held by
2981  *         \a this and \a other MEDFileFieldGlobsReal.
2982  *  \throw If \a this and \a other hold profiles with equal names but different ids.
2983  *  \throw If  \a this and \a other hold different Gauss points with equal names.
2984  */
2985 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps) throw(INTERP_KERNEL::Exception)
2986 {
2987   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
2988   if(thisGlobals==otherGlobals)
2989     return ;
2990   if(!thisGlobals)
2991     {
2992       _globals=other._globals;
2993       return ;
2994     }
2995   _globals->appendGlobs(*other._globals,eps);
2996 }
2997
2998 void MEDFileFieldGlobsReal::checkGlobsCoherency() const throw(INTERP_KERNEL::Exception)
2999 {
3000   checkGlobsPflsPartCoherency();
3001   checkGlobsLocsPartCoherency();
3002 }
3003
3004 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const throw(INTERP_KERNEL::Exception)
3005 {
3006   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3007 }
3008
3009 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const throw(INTERP_KERNEL::Exception)
3010 {
3011   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3012 }
3013
3014 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
3015 {
3016   contentNotNull()->loadProfileInFile(fid,id,pflName);
3017 }
3018
3019 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3020 {
3021   contentNotNull()->loadProfileInFile(fid,id);
3022 }
3023
3024 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
3025 {
3026   contentNotNull()->loadGlobals(fid,*this);
3027 }
3028
3029 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
3030 {
3031   contentNotNull()->loadAllGlobals(fid);
3032 }
3033
3034 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
3035 {
3036   contentNotNull()->writeGlobals(fid,opt);
3037 }
3038
3039 /*!
3040  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3041  * or getPflsReallyUsedMulti().
3042  *  \return std::vector<std::string> - a sequence of names of all profiles.
3043  */
3044 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3045 {
3046   return contentNotNull()->getPfls();
3047 }
3048
3049 /*!
3050  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3051  * or getLocsReallyUsedMulti().
3052  *  \return std::vector<std::string> - a sequence of names of all localizations.
3053  */
3054 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3055 {
3056   return contentNotNull()->getLocs();
3057 }
3058
3059 /*!
3060  * Checks if the profile with a given name exists.
3061  *  \param [in] pflName - the profile name of interest.
3062  *  \return bool - \c true if the profile named \a pflName exists.
3063  */
3064 bool MEDFileFieldGlobsReal::existsPfl(const char *pflName) const
3065 {
3066   return contentNotNull()->existsPfl(pflName);
3067 }
3068
3069 /*!
3070  * Checks if the localization with a given name exists.
3071  *  \param [in] locName - the localization name of interest.
3072  *  \return bool - \c true if the localization named \a locName exists.
3073  */
3074 bool MEDFileFieldGlobsReal::existsLoc(const char *locName) const
3075 {
3076   return contentNotNull()->existsLoc(locName);
3077 }
3078
3079 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
3080 {
3081   return contentNotNull()->createNewNameOfPfl();
3082 }
3083
3084 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
3085 {
3086   return contentNotNull()->createNewNameOfLoc();
3087 }
3088
3089 /*!
3090  * Sets the name of a MED file.
3091  *  \param [inout] fileName - the file name.
3092  */
3093 void MEDFileFieldGlobsReal::setFileName(const char *fileName)
3094 {
3095   contentNotNull()->setFileName(fileName);
3096 }
3097
3098 /*!
3099  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3100  * in the same order.
3101  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3102  *          Each item of this sequence is a vector containing ids of equal profiles.
3103  */
3104 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3105 {
3106   return contentNotNull()->whichAreEqualProfiles();
3107 }
3108
3109 /*!
3110  * Finds equal localizations.
3111  *  \param [in] eps - a precision used to compare real values of the localizations.
3112  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3113  *          Each item of this sequence is a vector containing ids of equal localizations.
3114  */
3115 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3116 {
3117   return contentNotNull()->whichAreEqualLocs(eps);
3118 }
3119
3120 /*!
3121  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3122  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3123  *        this sequence is a pair whose 
3124  *        - the first item is a vector of profile names to replace by the second item,
3125  *        - the second item is a profile name to replace every profile name of the first item.
3126  */
3127 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3128 {
3129   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3130 }
3131
3132 /*!
3133  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3134  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3135  *        this sequence is a pair whose 
3136  *        - the first item is a vector of localization names to replace by the second item,
3137  *        - the second item is a localization name to replace every localization name of the first item.
3138  */
3139 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3140 {
3141   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3142 }
3143
3144 /*!
3145  * Replaces references to some profiles (a reference is a profile name) by references
3146  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3147  * them-selves accordingly. <br>
3148  * This method is a generalization of changePflName().
3149  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3150  *        this sequence is a pair whose 
3151  *        - the first item is a vector of profile names to replace by the second item,
3152  *        - the second item is a profile name to replace every profile of the first item.
3153  * \sa changePflsRefsNamesGen()
3154  * \sa changePflName()
3155  */
3156 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3157 {
3158   changePflsRefsNamesGen(mapOfModif);
3159   changePflsNamesInStruct(mapOfModif);
3160 }
3161
3162 /*!
3163  * Replaces references to some localizations (a reference is a localization name) by references
3164  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3165  * them-selves accordingly. <br>
3166  * This method is a generalization of changeLocName().
3167  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3168  *        this sequence is a pair whose 
3169  *        - the first item is a vector of localization names to replace by the second item,
3170  *        - the second item is a localization name to replace every localization of the first item.
3171  * \sa changeLocsRefsNamesGen()
3172  * \sa changeLocName()
3173  */
3174 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3175 {
3176   changeLocsRefsNamesGen(mapOfModif);
3177   changeLocsNamesInStruct(mapOfModif);
3178 }
3179
3180 /*!
3181  * Renames the profile having a given name and updates references to this profile.
3182  *  \param [in] oldName - the name of the profile to rename.
3183  *  \param [in] newName - a new name of the profile.
3184  * \sa changePflsNames().
3185  */
3186 void MEDFileFieldGlobsReal::changePflName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
3187 {
3188   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3189   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3190   mapOfModif[0]=p;
3191   changePflsNames(mapOfModif);
3192 }
3193
3194 /*!
3195  * Renames the localization having a given name and updates references to this localization.
3196  *  \param [in] oldName - the name of the localization to rename.
3197  *  \param [in] newName - a new name of the localization.
3198  * \sa changeLocsNames().
3199  */
3200 void MEDFileFieldGlobsReal::changeLocName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
3201 {
3202   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3203   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3204   mapOfModif[0]=p;
3205   changeLocsNames(mapOfModif);
3206 }
3207
3208 /*!
3209  * Removes duplicated profiles. Returns a map used to update references to removed 
3210  * profiles via changePflsRefsNamesGen().
3211  * Equal profiles are found using whichAreEqualProfiles().
3212  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3213  *          a sequence describing the performed replacements of profiles. Each element of
3214  *          this sequence is a pair whose
3215  *          - the first item is a vector of profile names replaced by the second item,
3216  *          - the second item is a profile name replacing every profile of the first item.
3217  */
3218 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames() throw(INTERP_KERNEL::Exception)
3219 {
3220   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3221   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3222   int i=0;
3223   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3224     {
3225       std::vector< std::string > tmp((*it).size());
3226       int j=0;
3227       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3228         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3229       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3230       ret[i]=p;
3231       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3232       killProfileIds(tmp2);
3233     }
3234   changePflsRefsNamesGen(ret);
3235   return ret;
3236 }
3237
3238 /*!
3239  * Removes duplicated localizations. Returns a map used to update references to removed 
3240  * localizations via changeLocsRefsNamesGen().
3241  * Equal localizations are found using whichAreEqualLocs().
3242  *  \param [in] eps - a precision used to compare real values of the localizations.
3243  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3244  *          a sequence describing the performed replacements of localizations. Each element of
3245  *          this sequence is a pair whose
3246  *          - the first item is a vector of localization names replaced by the second item,
3247  *          - the second item is a localization name replacing every localization of the first item.
3248  */
3249 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps) throw(INTERP_KERNEL::Exception)
3250 {
3251   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3252   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3253   int i=0;
3254   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3255     {
3256       std::vector< std::string > tmp((*it).size());
3257       int j=0;
3258       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3259         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3260       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3261       ret[i]=p;
3262       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3263       killLocalizationIds(tmp2);
3264     }
3265   changeLocsRefsNamesGen(ret);
3266   return ret;
3267 }
3268
3269 /*!
3270  * Returns number of Gauss points per cell in a given localization.
3271  *  \param [in] locId - an id of the localization of interest.
3272  *  \return int - the number of the Gauss points per cell.
3273  */
3274 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
3275 {
3276   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3277 }
3278
3279 /*!
3280  * Returns an id of a localization by its name.
3281  *  \param [in] loc - the localization name of interest.
3282  *  \return int - the id of the localization.
3283  *  \throw If there is no a localization named \a loc.
3284  */
3285 int MEDFileFieldGlobsReal::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
3286 {
3287   return contentNotNull()->getLocalizationId(loc);
3288 }
3289
3290 /*!
3291  * Returns the name of the MED file.
3292  *  \return const char * - the MED file name.
3293  */
3294 const char *MEDFileFieldGlobsReal::getFileName() const
3295 {
3296   return contentNotNull()->getFileName();
3297 }
3298
3299 std::string MEDFileFieldGlobsReal::getFileName2() const
3300 {
3301   return contentNotNull()->getFileName2();
3302 }
3303
3304 /*!
3305  * Returns a localization object by its name.
3306  *  \param [in] locName - the name of the localization of interest.
3307  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3308  *  \throw If there is no a localization named \a locName.
3309  */
3310 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
3311 {
3312   return contentNotNull()->getLocalization(locName);
3313 }
3314
3315 /*!
3316  * Returns a localization object by its id.
3317  *  \param [in] locId - the id of the localization of interest.
3318  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3319  *  \throw If there is no a localization with id \a locId.
3320  */
3321 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
3322 {
3323   return contentNotNull()->getLocalizationFromId(locId);
3324 }
3325
3326 /*!
3327  * Returns a profile array by its name.
3328  *  \param [in] pflName - the name of the profile of interest.
3329  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3330  *  \throw If there is no a profile named \a pflName.
3331  */
3332 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
3333 {
3334   return contentNotNull()->getProfile(pflName);
3335 }
3336
3337 /*!
3338  * Returns a profile array by its id.
3339  *  \param [in] pflId - the id of the profile of interest.
3340  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3341  *  \throw If there is no a profile with id \a pflId.
3342  */
3343 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
3344 {
3345   return contentNotNull()->getProfileFromId(pflId);
3346 }
3347
3348 /*!
3349  * Returns a localization object, apt for modification, by its id.
3350  *  \param [in] locId - the id of the localization of interest.
3351  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3352  *          having the id \a locId.
3353  *  \throw If there is no a localization with id \a locId.
3354  */
3355 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
3356 {
3357   return contentNotNull()->getLocalizationFromId(locId);
3358 }
3359
3360 /*!
3361  * Returns a localization object, apt for modification, by its name.
3362  *  \param [in] locName - the name of the localization of interest.
3363  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3364  *          having the name \a locName.
3365  *  \throw If there is no a localization named \a locName.
3366  */
3367 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
3368 {
3369   return contentNotNull()->getLocalization(locName);
3370 }
3371
3372 /*!
3373  * Returns a profile array, apt for modification, by its name.
3374  *  \param [in] pflName - the name of the profile of interest.
3375  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3376  *  \throw If there is no a profile named \a pflName.
3377  */
3378 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
3379 {
3380   return contentNotNull()->getProfile(pflName);
3381 }
3382
3383 /*!
3384  * Returns a profile array, apt for modification, by its id.
3385  *  \param [in] pflId - the id of the profile of interest.
3386  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3387  *  \throw If there is no a profile with id \a pflId.
3388  */
3389 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
3390 {
3391   return contentNotNull()->getProfileFromId(pflId);
3392 }
3393
3394 /*!
3395  * Removes profiles given by their ids. No data is updated to track this removal.
3396  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3397  */
3398 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
3399 {
3400   contentNotNull()->killProfileIds(pflIds);
3401 }
3402
3403 /*!
3404  * Removes localizations given by their ids. No data is updated to track this removal.
3405  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3406  */
3407 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
3408 {
3409   contentNotNull()->killLocalizationIds(locIds);
3410 }
3411
3412 /*!
3413  * Stores a profile array.
3414  *  \param [in] pfl - the profile array to store.
3415  *  \throw If the name of \a pfl is empty.
3416  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3417  *         different ids.
3418  */
3419 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
3420 {
3421   contentNotNull()->appendProfile(pfl);
3422 }
3423
3424 /*!
3425  * Adds a new localization of Gauss points.
3426  *  \param [in] locName - the name of the new localization.
3427  *  \param [in] geoType - a geometrical type of the reference cell.
3428  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3429  *         must be \c nbOfNodesPerCell * \c dimOfType.
3430  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3431  *         must be  _wg_.size() * \c dimOfType.
3432  *  \param [in] w - the weights of Gauss points.
3433  *  \throw If \a locName is empty.
3434  *  \throw If a localization with the name \a locName already exists but is
3435  *         different form the new one.
3436  */
3437 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)
3438 {
3439   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3440 }
3441
3442 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() throw(INTERP_KERNEL::Exception)
3443 {
3444   MEDFileFieldGlobs *g(_globals);
3445   if(!g)
3446     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3447   return g;
3448 }
3449
3450 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const throw(INTERP_KERNEL::Exception)
3451 {
3452   const MEDFileFieldGlobs *g(_globals);
3453   if(!g)
3454     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3455   return g;
3456 }
3457
3458 //= MEDFileFieldNameScope
3459
3460 MEDFileFieldNameScope::MEDFileFieldNameScope()
3461 {
3462 }
3463
3464 MEDFileFieldNameScope::MEDFileFieldNameScope(const char *fieldName):_name(fieldName)
3465 {
3466 }
3467
3468 /*!
3469  * Returns the name of \a this field.
3470  *  \return std::string - a string containing the field name.
3471  */
3472 std::string MEDFileFieldNameScope::getName() const throw(INTERP_KERNEL::Exception)
3473 {
3474   return _name;
3475 }
3476
3477 /*!
3478  * Sets name of \a this field
3479  *  \param [in] name - the new field name.
3480  */
3481 void MEDFileFieldNameScope::setName(const char *fieldName) throw(INTERP_KERNEL::Exception)
3482 {
3483   _name=fieldName;
3484 }
3485
3486 std::string MEDFileFieldNameScope::getDtUnit() const throw(INTERP_KERNEL::Exception)
3487 {
3488   return _dt_unit;
3489 }
3490
3491 void MEDFileFieldNameScope::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
3492 {
3493   _dt_unit=dtUnit;
3494 }
3495
3496 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3497 {
3498   _name=other._name;
3499   _dt_unit=other._dt_unit;
3500 }
3501
3502 //= MEDFileAnyTypeField1TSWithoutSDA
3503
3504 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other) throw(INTERP_KERNEL::Exception)
3505 {
3506   _field_per_mesh.resize(other._field_per_mesh.size());
3507   std::size_t i=0;
3508   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3509     {
3510       if((const MEDFileFieldPerMesh *)*it)
3511         _field_per_mesh[i]=(*it)->deepCpy(this);
3512     }
3513 }
3514
3515 /*!
3516  * Prints a string describing \a this field into a stream. This string is outputted 
3517  * by \c print Python command.
3518  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3519  *  \param [in,out] oss - the out stream.
3520  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3521  *          info id printed, else, not.
3522  */
3523 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3524 {
3525   std::string startOfLine(bkOffset,' ');
3526   oss << startOfLine << "Field ";
3527   if(bkOffset==0)
3528     oss << "[Type=" << getTypeStr() << "] ";
3529   oss << "on One time Step ";
3530   if(f1tsId>=0)
3531     oss << "(" << f1tsId << ") ";
3532   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3533   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3534   const DataArray *arr=getUndergroundDataArray();
3535   if(arr)
3536     {
3537       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3538       if(f1tsId<0)
3539         {
3540           oss << startOfLine << "Field Name : \"" << arr->getName() << "\"." << std::endl;
3541           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3542           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3543             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3544         }
3545       if(arr->isAllocated())
3546         {
3547           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3548         }
3549       else
3550         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3551     }
3552   else
3553     {
3554       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3555     }
3556   oss << startOfLine << "----------------------" << std::endl;
3557   if(!_field_per_mesh.empty())
3558     {
3559       int i=0;
3560       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3561         {
3562           const MEDFileFieldPerMesh *cur=(*it2);
3563           if(cur)
3564             cur->simpleRepr(bkOffset,oss,i);
3565           else
3566             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3567         }
3568     }
3569   else
3570     {
3571       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3572     }
3573   oss << startOfLine << "----------------------" << std::endl;
3574 }
3575
3576 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const throw(INTERP_KERNEL::Exception)
3577 {
3578   const DataArray *arr(getUndergroundDataArray());
3579   if(!arr)
3580     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3581   int nbOfCompo=arr->getNumberOfComponents();
3582   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3583   for(int i=0;i<nbOfCompo;i++)
3584     {
3585       ret[i]=deepCpy();
3586       std::vector<int> v(1,i);
3587       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3588       ret[i]->setArray(arr2);
3589     }
3590   return ret;
3591 }
3592
3593 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order):MEDFileFieldNameScope(fieldName),_iteration(iteration),_order(order),_csit(csit),_nb_of_tuples_to_be_allocated(-2)
3594 {
3595 }
3596
3597 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3598 {
3599 }
3600
3601 /*!
3602  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3603  * empty. Returns -1 if this in on nodes.
3604  *  \return int - the dimension of \a this.
3605  */
3606 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3607 {
3608   int ret=-2;
3609   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3610     (*it)->getDimension(ret);
3611   return ret;
3612 }
3613
3614 /*!
3615  * Returns the mesh name.
3616  *  \return std::string - a string holding the mesh name.
3617  *  \throw If \c _field_per_mesh.empty()
3618  */
3619 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
3620 {
3621   if(_field_per_mesh.empty())
3622     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3623   return _field_per_mesh[0]->getMeshName();
3624 }
3625
3626 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
3627 {
3628   std::string oldName(getMeshName());
3629   std::vector< std::pair<std::string,std::string> > v(1);
3630   v[0].first=oldName; v[0].second=newMeshName;
3631   changeMeshNames(v);
3632 }
3633
3634 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
3635 {
3636   bool ret=false;
3637   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3638     {
3639       MEDFileFieldPerMesh *cur(*it);
3640       if(cur)
3641         ret=cur->changeMeshNames(modifTab) || ret;
3642     }
3643   return ret;
3644 }
3645
3646 /*!
3647  * Returns the number of iteration of the state of underlying mesh.
3648  *  \return int - the iteration number.
3649  *  \throw If \c _field_per_mesh.empty()
3650  */
3651 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const throw(INTERP_KERNEL::Exception)
3652 {
3653   if(_field_per_mesh.empty())
3654     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3655   return _field_per_mesh[0]->getMeshIteration();
3656 }
3657
3658 /*!
3659  * Returns the order number of iteration of the state of underlying mesh.
3660  *  \return int - the order number.
3661  *  \throw If \c _field_per_mesh.empty()
3662  */
3663 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const throw(INTERP_KERNEL::Exception)
3664 {
3665   if(_field_per_mesh.empty())
3666     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3667   return _field_per_mesh[0]->getMeshOrder();
3668 }
3669
3670 /*!
3671  * Checks if \a this field is tagged by a given iteration number and a given
3672  * iteration order number.
3673  *  \param [in] iteration - the iteration number of interest.
3674  *  \param [in] order - the iteration order number of interest.
3675  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3676  *          \a this->getOrder() == \a order.
3677  */
3678 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3679 {
3680   return iteration==_iteration && order==_order;
3681 }
3682
3683 /*!
3684  * Returns number of iteration and order number of iteration when
3685  * \a this field has been calculated.
3686  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3687  *          order number.
3688  */
3689 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3690 {
3691   std::pair<int,int> p;
3692   fillIteration(p);
3693   return p;
3694 }
3695
3696 /*!
3697  * Returns number of iteration and order number of iteration when
3698  * \a this field has been calculated.
3699  *  \param [in,out] p - a pair returning the iteration number and the iteration
3700  *          order number.
3701  */
3702 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3703 {
3704   p.first=_iteration;
3705   p.second=_order;
3706 }
3707
3708 /*!
3709  * Returns all types of spatial discretization of \a this field.
3710  *  \param [in,out] types - a sequence of types of \a this field.
3711  */
3712 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
3713 {
3714   std::set<TypeOfField> types2;
3715   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3716     {
3717       (*it)->fillTypesOfFieldAvailable(types2);
3718     }
3719   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3720   std::copy(types2.begin(),types2.end(),bi);
3721 }
3722
3723 /*!
3724  * Returns all types of spatial discretization of \a this field.
3725  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3726  *          of \a this field.
3727  */
3728 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
3729 {
3730   std::vector<TypeOfField> ret;
3731   fillTypesOfFieldAvailable(ret);
3732   return ret;
3733 }
3734
3735 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3736 {
3737   std::vector<std::string> ret;
3738   std::set<std::string> ret2;
3739   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3740     {
3741       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3742       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3743         if(ret2.find(*it2)==ret2.end())
3744           {
3745             ret.push_back(*it2);
3746             ret2.insert(*it2);
3747           }
3748     }
3749   return ret;
3750 }
3751
3752 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3753 {
3754   std::vector<std::string> ret;
3755   std::set<std::string> ret2;
3756   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3757     {
3758       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3759       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3760         if(ret2.find(*it2)==ret2.end())
3761           {
3762             ret.push_back(*it2);
3763             ret2.insert(*it2);
3764           }
3765     }
3766   return ret;
3767 }
3768
3769 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3770 {
3771   std::vector<std::string> ret;
3772   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3773     {
3774       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3775       ret.insert(ret.end(),tmp.begin(),tmp.end());
3776     }
3777   return ret;
3778 }
3779
3780 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3781 {
3782   std::vector<std::string> ret;
3783   std::set<std::string> ret2;
3784   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3785     {
3786       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3787       ret.insert(ret.end(),tmp.begin(),tmp.end());
3788     }
3789   return ret;
3790 }
3791
3792 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3793 {
3794   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3795     (*it)->changePflsRefsNamesGen(mapOfModif);
3796 }
3797
3798 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3799 {
3800   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3801     (*it)->changeLocsRefsNamesGen(mapOfModif);
3802 }
3803
3804 /*!
3805  * Returns all attributes of parts of \a this field lying on a given mesh.
3806  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3807  * item of every of returned sequences refers to the _i_-th part of \a this field.
3808  * Thus all sequences returned by this method are of the same length equal to number
3809  * of different types of supporting entities.<br>
3810  * A field part can include sub-parts with several different spatial discretizations,
3811  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3812  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3813  * of a nested sequence corresponds to a type of spatial discretization.<br>
3814  * This method allows for iteration over MEDFile DataStructure without any overhead.
3815  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3816  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3817  *          not checked if \a mname == \c NULL).
3818  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3819  *          a field part is returned. 
3820  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3821  *          This sequence is of the same length as \a types. 
3822  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3823  *          discretization. A profile name can be empty.
3824  *          Length of this and of nested sequences is the same as that of \a typesF.
3825  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3826  *          discretization. A localization name can be empty.
3827  *          Length of this and of nested sequences is the same as that of \a typesF.
3828  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3829  *          of ids of tuples within the data array, per each type of spatial
3830  *          discretization within one mesh entity type. 
3831  *          Length of this and of nested sequences is the same as that of \a typesF.
3832  *  \throw If no field is lying on \a mname.
3833  */
3834 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)
3835 {
3836   int meshId=0;
3837   if(mname)
3838     meshId=getMeshIdFromMeshName(mname);
3839   else
3840     if(_field_per_mesh.empty())
3841       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3842   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3843 }
3844
3845 /*!
3846  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
3847  * maximal absolute dimension and values returned via the out parameter \a levs are 
3848  * dimensions relative to the maximal absolute dimension. <br>
3849  * This method is designed for MEDFileField1TS instances that have a discretization
3850  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
3851  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
3852  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
3853  * Only these 3 discretizations will be taken into account here. If \a this is
3854  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
3855  * This method is useful to make the link between the dimension of the underlying mesh
3856  * and the levels of \a this, because it is possible that the highest dimension of \a this
3857  * field is not equal to the dimension of the underlying mesh.
3858  * 
3859  * Let's consider the following case:
3860  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
3861  * TETRA4, HEXA8, TRI3 and SEG2.
3862  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
3863  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
3864  *
3865  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
3866  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
3867  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
3868  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
3869  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
3870  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
3871  * For example<br>
3872  * to retrieve the highest level of
3873  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
3874  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
3875  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
3876  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
3877  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3878  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3879  *          not checked if \a mname == \c NULL).
3880  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
3881  *          absolute one. They are in decreasing order. This sequence is cleared before
3882  *          filling it in.
3883  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
3884  *  \throw If no field is lying on \a mname.
3885  */
3886 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
3887 {
3888   levs.clear();
3889   int meshId=getMeshIdFromMeshName(mname);
3890   std::vector<INTERP_KERNEL::NormalizedCellType> types;
3891   std::vector< std::vector<TypeOfField> > typesF;
3892   std::vector< std::vector<std::string> > pfls, locs;
3893   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3894   if(types.empty())
3895     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
3896   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
3897   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
3898     return -1;
3899   st.erase(INTERP_KERNEL::NORM_ERROR);
3900   std::set<int> ret1;
3901   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
3902     {
3903       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
3904       ret1.insert((int)cm.getDimension());
3905     }
3906   int ret=*std::max_element(ret1.begin(),ret1.end());
3907   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
3908   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
3909   return ret;
3910 }
3911
3912 /*!
3913  * \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.
3914  * \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.
3915  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3916  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3917  */
3918 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
3919 {
3920   int mid=getMeshIdFromMeshName(mName);
3921   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3922 }
3923
3924 /*!
3925  * \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.
3926  * \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.
3927  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3928  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3929  */
3930 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
3931 {
3932   int mid=getMeshIdFromMeshName(mName);
3933   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3934 }
3935
3936 /*!
3937  * \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.
3938  */
3939 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception)
3940 {
3941   if(_field_per_mesh.empty())
3942     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
3943   if(mName==0)
3944     return 0;
3945   std::string mName2(mName);
3946   int ret=0;
3947   std::vector<std::string> msg;
3948   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
3949     if(mName2==(*it)->getMeshName())
3950       return ret;
3951     else
3952       msg.push_back((*it)->getMeshName());
3953   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
3954   oss << "Possible meshes are : ";
3955   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
3956     oss << "\"" << (*it2) << "\" ";
3957   throw INTERP_KERNEL::Exception(oss.str().c_str());
3958 }
3959
3960 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
3961 {
3962   if(!mesh)
3963     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
3964   std::string tmp(mesh->getName());
3965   if(tmp.empty())
3966     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
3967   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
3968   int i=0;
3969   for(;it!=_field_per_mesh.end();it++,i++)
3970     {
3971       if((*it)->getMeshName()==tmp)
3972         return i;
3973     }
3974   int sz=_field_per_mesh.size();
3975   _field_per_mesh.resize(sz+1);
3976   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
3977   return sz;
3978 }
3979
3980 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
3981                                                             MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
3982 {
3983   bool ret=false;
3984   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3985     {
3986       MEDFileFieldPerMesh *fpm(*it);
3987       if(fpm)
3988         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
3989     }
3990   return ret;
3991 }
3992
3993 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
3994 {
3995   if(_field_per_mesh.empty())
3996     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
3997   if(_field_per_mesh.size()>1)
3998     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
3999   _field_per_mesh[0]->copyOptionsFrom(opts);
4000   _field_per_mesh[0]->writeLL(fid,nasc);
4001 }
4002
4003 void MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile() throw(INTERP_KERNEL::Exception)
4004 {
4005   if(_nb_of_tuples_to_be_allocated>=0)
4006     {
4007       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4008       _nb_of_tuples_to_be_allocated=-2;
4009       return ;
4010     }
4011   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4012     return ;
4013   if(_nb_of_tuples_to_be_allocated==-1)
4014     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4015   if(_nb_of_tuples_to_be_allocated<-3)
4016     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4017   
4018 }
4019
4020 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4021 {
4022   med_int numdt,numit;
4023   med_float dt;
4024   med_int nmesh;
4025   med_bool localMesh;
4026   med_int meshnumdt,meshnumit;
4027   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4028   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4029   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4030   if(_iteration!=numdt || _order!=numit)
4031     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4032   _field_per_mesh.resize(nmesh);
4033   for(int i=0;i<nmesh;i++)
4034     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i+1,meshnumdt,meshnumit,nasc);//tony
4035   _nb_of_tuples_to_be_allocated=0;
4036   for(int i=0;i<nmesh;i++)
4037     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4038 }
4039
4040 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4041 {
4042   allocIfNecessaryTheArrayToReceiveDataFromFile();
4043   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4044     (*it)->loadBigArraysRecursively(fid,nasc);
4045 }
4046
4047 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4048 {
4049   loadOnlyStructureOfDataRecursively(fid,nasc);
4050   loadBigArraysRecursively(fid,nasc);
4051 }
4052
4053 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySize() const
4054 {
4055   std::size_t ret=_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4056   if(getUndergroundDataArray())
4057     ret+=getUndergroundDataArray()->getHeapMemorySize();
4058   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4059     ret+=(*it)->getHeapMemorySize();
4060   return ret;
4061 }
4062
4063 /*!
4064  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4065  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4066  * "Sort By Type"), if not, an exception is thrown. 
4067  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4068  *  \param [in] arr - the array of values.
4069  *  \param [in,out] glob - the global data where profiles and localization present in
4070  *          \a field, if any, are added.
4071  *  \throw If the name of \a field is empty.
4072  *  \throw If the data array of \a field is not set.
4073  *  \throw If \a this->_arr is already allocated but has different number of components
4074  *         than \a field.
4075  *  \throw If the underlying mesh of \a field has no name.
4076  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4077  */
4078 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4079 {
4080   const MEDCouplingMesh *mesh=field->getMesh();
4081   //
4082   TypeOfField type=field->getTypeOfField();
4083   std::vector<DataArrayInt *> dummy;
4084   int start=copyTinyInfoFrom(field,arr);
4085   int pos=addNewEntryIfNecessary(mesh);
4086   if(type!=ON_NODES)
4087     {
4088       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4089       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4090     }
4091   else
4092     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4093 }
4094
4095 /*!
4096  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4097  * of a given mesh are used as the support of the given field (a real support is not used). 
4098  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4099  * Order of underlying mesh entities of the given field specified by \a profile parameter
4100  * is not prescribed; this method permutes field values to have them sorted by element
4101  * type as required for writing to MED file. A new profile is added only if no equal
4102  * profile is missing. 
4103  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4104  *  \param [in] arrOfVals - the values of the field \a field used.
4105  *  \param [in] mesh - the supporting mesh of \a field.
4106  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4107  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4108  *  \param [in,out] glob - the global data where profiles and localization present in
4109  *          \a field, if any, are added.
4110  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4111  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4112  *  \throw If the data array of \a field is not set.
4113  *  \throw If \a this->_arr is already allocated but has different number of components
4114  *         than \a field.
4115  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4116  *  \sa setFieldNoProfileSBT()
4117  */
4118 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)
4119 {
4120   TypeOfField type=field->getTypeOfField();
4121   int start=copyTinyInfoFrom(field,arrOfVals);
4122   std::vector<DataArrayInt *> idsInPflPerType;
4123   std::vector<DataArrayInt *> idsPerType;
4124   std::vector<int> code,code2;
4125   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4126   if(type!=ON_NODES)
4127     {
4128       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4129       code2=m->getDistributionOfTypes();
4130       //
4131       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size());
4132       for(std::size_t i=0;i<idsInPflPerType.size();i++)
4133         idsInPflPerType2[i]=idsInPflPerType[i];
4134       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size());
4135       for(std::size_t i=0;i<idsPerType.size();i++)
4136         idsPerType2[i]=idsPerType[i];
4137       //
4138       int pos=addNewEntryIfNecessary(m);
4139       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4140     }
4141   else
4142     {
4143       int pos=addNewEntryIfNecessary(m);
4144       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4145     }
4146 }
4147
4148 /*!
4149  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4150  */
4151 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples) throw(INTERP_KERNEL::Exception)
4152 {
4153   if(_nb_of_tuples_to_be_allocated>=0)
4154     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile : the object is expected to be appended to a data coming from a file but not loaded ! Load before appending data !");
4155   DataArray *arr(getOrCreateAndGetArray());
4156   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4157   _nb_of_tuples_to_be_allocated=-3;
4158 }
4159
4160 /*!
4161  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4162  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4163  * larger by the size of \a field. Returns an id of the first not filled
4164  * tuple of \a this->_arr.
4165  *  \param [in] field - the field to copy the info on components and the name from.
4166  *  \return int - the id of first not initialized tuple of \a this->_arr.
4167  *  \throw If the name of \a field is empty.
4168  *  \throw If the data array of \a field is not set.
4169  *  \throw If \a this->_arr is already allocated but has different number of components
4170  *         than \a field.
4171  */
4172 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
4173 {
4174   if(!field)
4175     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4176   std::string name(field->getName());
4177   setName(name.c_str());
4178   setDtUnit(field->getTimeUnit());
4179   if(name.empty())
4180     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4181   if(!arr)
4182     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4183   if(!arr->isAllocated())
4184     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4185   _dt=field->getTime(_iteration,_order);
4186   int nbOfComponents=arr->getNumberOfComponents();
4187   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4188   if(!getOrCreateAndGetArray()->isAllocated())
4189     {
4190       allocNotFromFile(arr->getNumberOfTuples());
4191       return 0;
4192     }
4193   else
4194     {
4195       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4196       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4197       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4198       _nb_of_tuples_to_be_allocated=-3;
4199       return oldNbOfTuples;
4200     }
4201 }
4202
4203 /*!
4204  * Returns number of components in \a this field
4205  *  \return int - the number of components.
4206  */
4207 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4208 {
4209   return getOrCreateAndGetArray()->getNumberOfComponents();
4210 }
4211
4212 /*!
4213  * Change info on components in \a this.
4214  * \throw If size of \a infos is not equal to the number of components already in \a this.
4215  */
4216 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
4217 {
4218   DataArray *arr=getOrCreateAndGetArray();
4219   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4220 }
4221
4222 /*!
4223  * Returns info on components of \a this field.
4224  *  \return const std::vector<std::string>& - a sequence of strings each being an
4225  *          information on _i_-th component.
4226  */
4227 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4228 {
4229   const DataArray *arr=getOrCreateAndGetArray();
4230   return arr->getInfoOnComponents();
4231 }
4232
4233 /*!
4234  * Returns a mutable info on components of \a this field.
4235  *  \return std::vector<std::string>& - a sequence of strings each being an
4236  *          information on _i_-th component.
4237  */
4238 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4239 {
4240   DataArray *arr=getOrCreateAndGetArray();
4241   return arr->getInfoOnComponents();
4242 }
4243
4244 /*!
4245  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4246  *  \param [in] type - a spatial discretization of the new field.
4247  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4248  *  \param [in] mName - a name of the supporting mesh.
4249  *  \param [in] renumPol - specifies how to permute values of the result field according to
4250  *          the optional numbers of cells and nodes, if any. The valid values are
4251  *          - 0 - do not permute.
4252  *          - 1 - permute cells.
4253  *          - 2 - permute nodes.
4254  *          - 3 - permute cells and nodes.
4255  *
4256  *  \param [in] glob - the global data storing profiles and localization.
4257  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4258  *          caller is to delete this field using decrRef() as it is no more needed. 
4259  *  \throw If the MED file is not readable.
4260  *  \throw If there is no mesh named \a mName in the MED file.
4261  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4262  *  \throw If no field of \a this is lying on the mesh \a mName.
4263  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4264  */
4265 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)
4266 {
4267   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4268   if(mName==0)
4269     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4270   else
4271     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4272   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4273 }
4274
4275 /*!
4276  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4277  *  \param [in] type - a spatial discretization of the new field.
4278  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4279  *  \param [in] renumPol - specifies how to permute values of the result field according to
4280  *          the optional numbers of cells and nodes, if any. The valid values are
4281  *          - 0 - do not permute.
4282  *          - 1 - permute cells.
4283  *          - 2 - permute nodes.
4284  *          - 3 - permute cells and nodes.
4285  *
4286  *  \param [in] glob - the global data storing profiles and localization.
4287  *  \param [in] mesh - the supporting mesh.
4288  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4289  *          caller is to delete this field using decrRef() as it is no more needed. 
4290  *  \throw If the MED file is not readable.
4291  *  \throw If no field of \a this is lying on \a mesh.
4292  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4293  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4294  */
4295 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)
4296 {
4297   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4298   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4299   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4300   if(meshDimRelToMax==1)
4301     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4302   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4303 }
4304
4305 /*!
4306  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4307  * given mesh. 
4308  *  \param [in] type - a spatial discretization of the new field.
4309  *  \param [in] mName - a name of the supporting mesh.
4310  *  \param [in] renumPol - specifies how to permute values of the result field according to
4311  *          the optional numbers of cells and nodes, if any. The valid values are
4312  *          - 0 - do not permute.
4313  *          - 1 - permute cells.
4314  *          - 2 - permute nodes.
4315  *          - 3 - permute cells and nodes.
4316  *
4317  *  \param [in] glob - the global data storing profiles and localization.
4318  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4319  *          caller is to delete this field using decrRef() as it is no more needed. 
4320  *  \throw If the MED file is not readable.
4321  *  \throw If there is no mesh named \a mName in the MED file.
4322  *  \throw If there are no mesh entities in the mesh.
4323  *  \throw If no field values of the given \a type are available.
4324  */
4325 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4326 {
4327    MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4328   if(mName==0)
4329     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4330   else
4331     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4332   int absDim=getDimension();
4333   int meshDimRelToMax=absDim-mm->getMeshDimension();
4334   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4335 }
4336
4337 /*!
4338  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4339  *  \param [in] type - a spatial discretization of the new field.
4340  *  \param [in] renumPol - specifies how to permute values of the result field according to
4341  *          the optional numbers of cells and nodes, if any. The valid values are
4342  *          - 0 - do not permute.
4343  *          - 1 - permute cells.
4344  *          - 2 - permute nodes.
4345  *          - 3 - permute cells and nodes.
4346  *
4347  *  \param [in] glob - the global data storing profiles and localization.
4348  *  \param [in] mesh - the supporting mesh.
4349  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4350  *         field according to \a renumPol.
4351  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4352  *         field according to \a renumPol.
4353  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4354  *          caller is to delete this field using decrRef() as it is no more needed. 
4355  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4356  *  \throw If no field of \a this is lying on \a mesh.
4357  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4358  */
4359 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)
4360 {
4361   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4362   int meshId=getMeshIdFromMeshName(mesh->getName());
4363   bool isPfl=false;
4364   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4365   switch(renumPol)
4366     {
4367     case 0:
4368       {
4369         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4370         return ret.retn();
4371       }
4372     case 3:
4373     case 1:
4374       {
4375         if(isPfl)
4376           throw INTERP_KERNEL::Exception(msg1);
4377         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4378         if(cellRenum)
4379           {
4380             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4381               {
4382                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4383                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4384                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4385               }
4386             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4387             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4388             std::vector<DataArray *> arrOut2(1,arrOut);
4389             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4390             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4391             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4392           }
4393         if(renumPol==1)
4394           return ret.retn();
4395       }
4396     case 2:
4397       {
4398         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4399         if(isPfl)
4400           throw INTERP_KERNEL::Exception(msg1);
4401         if(nodeRenum)
4402           {
4403             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4404               {
4405                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4406                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4407                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4408               }
4409             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4410             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4411               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4412             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4413           }
4414         return ret.retn();
4415       }
4416     default:
4417       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4418     }
4419 }
4420
4421 /*!
4422  * Returns values and a profile of the field of a given type lying on a given support.
4423  *  \param [in] type - a spatial discretization of the field.
4424  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4425  *  \param [in] mesh - the supporting mesh.
4426  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4427  *          field of interest lies on. If the field lies on all entities of the given
4428  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4429  *          using decrRef() as it is no more needed.  
4430  *  \param [in] glob - the global data storing profiles and localization.
4431  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4432  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4433  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4434  *  \throw If no field of \a this is lying on \a mesh.
4435  *  \throw If no field values of the given \a type are available.
4436  */
4437 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4438 {
4439   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4440   int meshId=getMeshIdFromMeshName(mesh->getName());
4441   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4442   ret->setName(nasc.getName().c_str());
4443   return ret.retn();
4444 }
4445
4446 //= MEDFileField1TSWithoutSDA
4447
4448 /*!
4449  * Throws if a given value is not a valid (non-extended) relative dimension.
4450  *  \param [in] meshDimRelToMax - the relative dimension value.
4451  *  \throw If \a meshDimRelToMax > 0.
4452  */
4453 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
4454 {
4455   if(meshDimRelToMax>0)
4456     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4457 }
4458
4459 /*!
4460  * Checks if elements of a given mesh are in the order suitable for writing 
4461  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4462  * vector describing types of elements and their number.
4463  *  \param [in] mesh - the mesh to check.
4464  *  \return std::vector<int> - a vector holding for each element type (1) item of
4465  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4466  *          These values are in full-interlace mode.
4467  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4468  */
4469 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
4470 {
4471   if(!mesh)
4472     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4473   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4474   int nbOfTypes=geoTypes.size();
4475   std::vector<int> code(3*nbOfTypes);
4476   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4477   arr1->alloc(nbOfTypes,1);
4478   int *arrPtr=arr1->getPointer();
4479   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4480   for(int i=0;i<nbOfTypes;i++,it++)
4481     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4482   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4483   const int *arrPtr2=arr2->getConstPointer();
4484   int i=0;
4485   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4486     {
4487       int pos=arrPtr2[i];
4488       int nbCells=mesh->getNumberOfCellsWithType(*it);
4489       code[3*pos]=(int)(*it);
4490       code[3*pos+1]=nbCells;
4491       code[3*pos+2]=-1;//no profiles
4492     }
4493   std::vector<const DataArrayInt *> idsPerType;//no profiles
4494   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4495   if(da)
4496     {
4497       da->decrRef();
4498       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4499     }
4500   return code;
4501 }
4502
4503 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const char *fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4504 {
4505   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4506 }
4507
4508 /*!
4509  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4510  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4511  * item of every of returned sequences refers to the _i_-th part of \a this field.
4512  * Thus all sequences returned by this method are of the same length equal to number
4513  * of different types of supporting entities.<br>
4514  * A field part can include sub-parts with several different spatial discretizations,
4515  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4516  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4517  * of a nested sequence corresponds to a type of spatial discretization.<br>
4518  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4519  * The overhead is due to selecting values into new instances of DataArrayDouble.
4520  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4521  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4522  *          not checked if \a mname == \c NULL).
4523  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4524  *          a field part is returned. 
4525  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4526  *          A field part can include sub-parts with several different spatial discretizations,
4527  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4528  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4529  *          This sequence is of the same length as \a types. 
4530  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4531  *          discretization. A profile name can be empty.
4532  *          Length of this and of nested sequences is the same as that of \a typesF.
4533  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4534  *          discretization. A localization name can be empty.
4535  *          Length of this and of nested sequences is the same as that of \a typesF.
4536  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4537  *          per each type of spatial discretization within one mesh entity type.
4538  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4539  *          Length of this and of nested sequences is the same as that of \a typesF.
4540  *  \throw If no field is lying on \a mname.
4541  */
4542 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)
4543 {
4544   int meshId=0;
4545   if(mname)
4546     meshId=getMeshIdFromMeshName(mname);
4547   else
4548     if(_field_per_mesh.empty())
4549       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4550   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4551   int nbOfRet=ret0.size();
4552   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4553   for(int i=0;i<nbOfRet;i++)
4554     {
4555       const std::vector< std::pair<int,int> >& p=ret0[i];
4556       int nbOfRet1=p.size();
4557       ret[i].resize(nbOfRet1);
4558       for(int j=0;j<nbOfRet1;j++)
4559         {
4560           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4561           ret[i][j]=tmp;
4562         }
4563     }
4564   return ret;
4565 }
4566
4567 /*!
4568  * Returns a pointer to the underground DataArrayDouble instance. So the
4569  * caller should not decrRef() it. This method allows for a direct access to the field
4570  * values. This method is quite unusable if there is more than a nodal field or a cell
4571  * field on single geometric cell type. 
4572  *  \return DataArrayDouble * - the pointer to the field values array.
4573  */
4574 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const throw(INTERP_KERNEL::Exception)
4575 {
4576   const DataArrayDouble *ret=_arr;
4577   if(ret)
4578     return const_cast<DataArrayDouble *>(ret);
4579   else
4580     return 0;
4581 }
4582
4583 const char *MEDFileField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
4584 {
4585   return TYPE_STR;
4586 }
4587
4588 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const throw(INTERP_KERNEL::Exception)
4589 {
4590   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
4591   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4592   ret->deepCpyLeavesFrom(*this);
4593   const DataArrayDouble *arr(_arr);
4594   if(arr)
4595     {
4596       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
4597       ret->setArray(arr2);
4598     }
4599   return ret.retn();
4600 }
4601
4602 /*!
4603  * Returns a pointer to the underground DataArrayDouble instance. So the
4604  * caller should not decrRef() it. This method allows for a direct access to the field
4605  * values. This method is quite unusable if there is more than a nodal field or a cell
4606  * field on single geometric cell type. 
4607  *  \return DataArrayDouble * - the pointer to the field values array.
4608  */
4609 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4610 {
4611   return getUndergroundDataArrayDouble();
4612 }
4613
4614 /*!
4615  * Returns a pointer to the underground DataArrayDouble instance and a
4616  * sequence describing parameters of a support of each part of \a this field. The
4617  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4618  * direct access to the field values. This method is intended for the field lying on one
4619  * mesh only.
4620  *  \param [in,out] entries - the sequence describing parameters of a support of each
4621  *         part of \a this field. Each item of this sequence consists of two parts. The
4622  *         first part describes a type of mesh entity and an id of discretization of a
4623  *         current field part. The second part describes a range of values [begin,end)
4624  *         within the returned array relating to the current field part.
4625  *  \return DataArrayDouble * - the pointer to the field values array.
4626  *  \throw If the number of underlying meshes is not equal to 1.
4627  *  \throw If no field values are available.
4628  *  \sa getUndergroundDataArray()
4629  */
4630 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4631 {
4632   if(_field_per_mesh.size()!=1)
4633     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4634   if(_field_per_mesh[0]==0)
4635     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4636   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4637   return getUndergroundDataArrayDouble();
4638 }
4639
4640 /*!
4641  * Returns a pointer to the underground DataArrayDouble instance and a
4642  * sequence describing parameters of a support of each part of \a this field. The
4643  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4644  * direct access to the field values. This method is intended for the field lying on one
4645  * mesh only.
4646  *  \param [in,out] entries - the sequence describing parameters of a support of each
4647  *         part of \a this field. Each item of this sequence consists of two parts. The
4648  *         first part describes a type of mesh entity and an id of discretization of a
4649  *         current field part. The second part describes a range of values [begin,end)
4650  *         within the returned array relating to the current field part.
4651  *  \return DataArrayDouble * - the pointer to the field values array.
4652  *  \throw If the number of underlying meshes is not equal to 1.
4653  *  \throw If no field values are available.
4654  *  \sa getUndergroundDataArray()
4655  */
4656 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4657 {
4658   return getUndergroundDataArrayDoubleExt(entries);
4659 }
4660
4661 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order,
4662                                                      const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4663 {
4664   DataArrayDouble *arr=getOrCreateAndGetArrayDouble();
4665   arr->setInfoAndChangeNbOfCompo(infos);
4666 }
4667
4668 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4669 {
4670 }
4671
4672 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
4673 {
4674   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
4675   ret->deepCpyLeavesFrom(*this);
4676   return ret.retn();
4677 }
4678
4679 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
4680 {
4681   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
4682   if((const DataArrayDouble *)_arr)
4683     ret->_arr=_arr->deepCpy();
4684   return ret.retn();
4685 }
4686
4687 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
4688 {
4689   if(!arr)
4690     _arr=0;
4691   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
4692   if(!arrC)
4693     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
4694   arrC->incrRef();
4695   _arr=arrC;
4696 }
4697
4698 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4699 {
4700   return DataArrayDouble::New();
4701 }
4702
4703 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
4704 {
4705   DataArrayDouble *ret=_arr;
4706   if(ret)
4707     return ret;
4708   _arr=DataArrayDouble::New();
4709   return _arr;
4710 }
4711
4712 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
4713 {
4714   return getOrCreateAndGetArrayDouble();
4715 }
4716
4717 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
4718 {
4719   const DataArrayDouble *ret=_arr;
4720   if(ret)
4721     return ret;
4722   DataArrayDouble *ret2=DataArrayDouble::New();
4723   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
4724   return ret2;
4725 }
4726
4727 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
4728 {
4729   return getOrCreateAndGetArrayDouble();
4730 }
4731
4732 //= MEDFileIntField1TSWithoutSDA
4733
4734 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const char *fieldName, int csit, int iteration, int order,
4735                                                                 const std::vector<std::string>& infos)
4736 {
4737   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4738 }
4739
4740 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4741 {
4742 }
4743
4744 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order,
4745                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4746 {
4747   DataArrayInt *arr=getOrCreateAndGetArrayInt();
4748   arr->setInfoAndChangeNbOfCompo(infos);
4749 }
4750
4751 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
4752 {
4753   return TYPE_STR;
4754 }
4755
4756 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const throw(INTERP_KERNEL::Exception)
4757 {
4758   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
4759   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4760   ret->deepCpyLeavesFrom(*this);
4761   const DataArrayInt *arr(_arr);
4762   if(arr)
4763     {
4764       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
4765       ret->setArray(arr2);
4766     }
4767   return ret.retn();
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 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4778 {
4779   return getUndergroundDataArrayInt();
4780 }
4781
4782 /*!
4783  * Returns a pointer to the underground DataArrayInt instance. So the
4784  * caller should not decrRef() it. This method allows for a direct access to the field
4785  * values. This method is quite unusable if there is more than a nodal field or a cell
4786  * field on single geometric cell type. 
4787  *  \return DataArrayInt * - the pointer to the field values array.
4788  */
4789 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const throw(INTERP_KERNEL::Exception)
4790 {
4791   const DataArrayInt *ret=_arr;
4792   if(ret)
4793     return const_cast<DataArrayInt *>(ret);
4794   else
4795     return 0;
4796 }
4797
4798 /*!
4799  * Returns a pointer to the underground DataArrayInt instance and a
4800  * sequence describing parameters of a support of each part of \a this field. The
4801  * caller should not decrRef() the returned DataArrayInt. This method allows for a
4802  * direct access to the field values. This method is intended for the field lying on one
4803  * mesh only.
4804  *  \param [in,out] entries - the sequence describing parameters of a support of each
4805  *         part of \a this field. Each item of this sequence consists of two parts. The
4806  *         first part describes a type of mesh entity and an id of discretization of a
4807  *         current field part. The second part describes a range of values [begin,end)
4808  *         within the returned array relating to the current field part.
4809  *  \return DataArrayInt * - the pointer to the field values array.
4810  *  \throw If the number of underlying meshes is not equal to 1.
4811  *  \throw If no field values are available.
4812  *  \sa getUndergroundDataArray()
4813  */
4814 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4815 {
4816   return getUndergroundDataArrayIntExt(entries);
4817 }
4818
4819 /*!
4820  * Returns a pointer to the underground DataArrayInt instance and a
4821  * sequence describing parameters of a support of each part of \a this field. The
4822  * caller should not decrRef() the returned DataArrayInt. This method allows for a
4823  * direct access to the field values. This method is intended for the field lying on one
4824  * mesh only.
4825  *  \param [in,out] entries - the sequence describing parameters of a support of each
4826  *         part of \a this field. Each item of this sequence consists of two parts. The
4827  *         first part describes a type of mesh entity and an id of discretization of a
4828  *         current field part. The second part describes a range of values [begin,end)
4829  *         within the returned array relating to the current field part.
4830  *  \return DataArrayInt * - the pointer to the field values array.
4831  *  \throw If the number of underlying meshes is not equal to 1.
4832  *  \throw If no field values are available.
4833  *  \sa getUndergroundDataArray()
4834  */
4835 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4836 {
4837   if(_field_per_mesh.size()!=1)
4838     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4839   if(_field_per_mesh[0]==0)
4840     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4841   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4842   return getUndergroundDataArrayInt();
4843 }
4844
4845 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
4846 {
4847   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
4848   ret->deepCpyLeavesFrom(*this);
4849   return ret.retn();
4850 }
4851
4852 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
4853 {
4854   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
4855   if((const DataArrayInt *)_arr)
4856     ret->_arr=_arr->deepCpy();
4857   return ret.retn();
4858 }
4859
4860 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
4861 {
4862   if(!arr)
4863     _arr=0;
4864   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
4865   if(!arrC)
4866     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
4867   arrC->incrRef();
4868   _arr=arrC;
4869 }
4870
4871 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4872 {
4873   return DataArrayInt::New();
4874 }
4875
4876 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
4877 {
4878   DataArrayInt *ret=_arr;
4879   if(ret)
4880     return ret;
4881   _arr=DataArrayInt::New();
4882   return _arr;
4883 }
4884
4885 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
4886 {
4887   return getOrCreateAndGetArrayInt();
4888 }
4889
4890 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
4891 {
4892   const DataArrayInt *ret=_arr;
4893   if(ret)
4894     return ret;
4895   DataArrayInt *ret2=DataArrayInt::New();
4896   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
4897   return ret2;
4898 }
4899
4900 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
4901 {
4902   return getOrCreateAndGetArrayInt();
4903 }
4904
4905 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
4906 {
4907 }
4908
4909 //= MEDFileAnyTypeField1TS
4910
4911 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
4912 {
4913   med_field_type typcha;
4914   //
4915   std::vector<std::string> infos;
4916   std::string dtunit,fieldName;
4917   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
4918   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
4919   switch(typcha)
4920     {
4921     case MED_FLOAT64:
4922       {
4923         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4924         break;
4925       }
4926     case MED_INT32:
4927       {
4928         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4929         break;
4930       }
4931     default:
4932       {
4933         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] !";
4934         throw INTERP_KERNEL::Exception(oss.str().c_str());
4935       }
4936     }
4937   ret->setDtUnit(dtunit.c_str());
4938   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
4939   //
4940   med_int numdt,numit;
4941   med_float dt;
4942   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
4943   ret->setTime(numdt,numit,dt);
4944   ret->_csit=1;
4945   if(loadAll)
4946     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
4947   else
4948     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
4949   return ret.retn();
4950 }
4951
4952 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
4953 try:MEDFileFieldGlobsReal(fileName)
4954 {
4955   MEDFileUtilities::CheckFileForRead(fileName);
4956   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
4957   _content=BuildContentFrom(fid,fileName,loadAll);
4958   loadGlobals(fid);
4959 }
4960 catch(INTERP_KERNEL::Exception& e)
4961   {
4962     throw e;
4963   }
4964
4965 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
4966 {
4967   med_field_type typcha;
4968   std::vector<std::string> infos;
4969   std::string dtunit;
4970   int iii=-1;
4971   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
4972   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
4973   switch(typcha)
4974     {
4975     case MED_FLOAT64:
4976       {
4977         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4978         break;
4979       }
4980     case MED_INT32:
4981       {
4982         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4983         break;
4984       }
4985     default:
4986       {
4987         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] !";
4988         throw INTERP_KERNEL::Exception(oss.str().c_str());
4989       }
4990     }
4991   ret->setDtUnit(dtunit.c_str());
4992   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
4993   //
4994   if(nbSteps<1)
4995     {
4996       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
4997       throw INTERP_KERNEL::Exception(oss.str().c_str());
4998     }
4999   //
5000   med_int numdt,numit;
5001   med_float dt;
5002   MEDfieldComputingStepInfo(fid,fieldName,1,&numdt,&numit,&dt);
5003   ret->setTime(numdt,numit,dt);
5004   ret->_csit=1;
5005   if(loadAll)
5006     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5007   else
5008     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5009   return ret.retn();
5010 }
5011
5012 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5013 try:MEDFileFieldGlobsReal(fileName)
5014 {
5015   MEDFileUtilities::CheckFileForRead(fileName);
5016   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5017   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
5018   loadGlobals(fid);
5019 }
5020 catch(INTERP_KERNEL::Exception& e)
5021   {
5022     throw e;
5023   }
5024
5025 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const char *fileName) throw(INTERP_KERNEL::Exception)
5026 {
5027   if(!c)
5028     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5029   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5030     {
5031       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5032       ret->setFileName(fileName);
5033       ret->_content=c; c->incrRef();
5034       return ret.retn();
5035     }
5036   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5037     {
5038       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5039       ret->setFileName(fileName);
5040       ret->_content=c; c->incrRef();
5041       return ret.retn();
5042     }
5043   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5044 }
5045
5046 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5047 {
5048   MEDFileUtilities::CheckFileForRead(fileName);
5049   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5050   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
5051   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5052   ret->loadGlobals(fid);
5053   return ret.retn();
5054 }
5055
5056 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5057 {
5058   MEDFileUtilities::CheckFileForRead(fileName);
5059   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5060   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
5061   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5062   ret->loadGlobals(fid);
5063   return ret.retn();
5064 }
5065
5066 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5067 {
5068   MEDFileUtilities::CheckFileForRead(fileName);
5069   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5070   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll);
5071   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5072   ret->loadGlobals(fid);
5073   return ret.retn();
5074 }
5075
5076 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5077 {
5078   med_field_type typcha;
5079   std::vector<std::string> infos;
5080   std::string dtunit;
5081   int iii=-1;
5082   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5083   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5084   switch(typcha)
5085     {
5086     case MED_FLOAT64:
5087       {
5088         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5089         break;
5090       }
5091     case MED_INT32:
5092       {
5093         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5094         break;
5095       }
5096     default:
5097       {
5098         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] !";
5099         throw INTERP_KERNEL::Exception(oss.str().c_str());
5100       }
5101     }
5102   ret->setDtUnit(dtunit.c_str());
5103   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5104   //
5105   bool found=false;
5106   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5107   for(int i=0;i<nbOfStep2 && !found;i++)
5108     {
5109       med_int numdt,numit;
5110       med_float dt;
5111       MEDfieldComputingStepInfo(fid,fieldName,i+1,&numdt,&numit,&dt);
5112       if(numdt==iteration && numit==order)
5113         {
5114           found=true;
5115           ret->_csit=i+1;
5116         }
5117       else
5118         dtits[i]=std::pair<int,int>(numdt,numit);
5119     }
5120   if(!found)
5121     {
5122       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5123       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5124         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5125       throw INTERP_KERNEL::Exception(oss.str().c_str());
5126     }
5127   ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5128   return ret.retn();
5129 }
5130
5131 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5132 try:MEDFileFieldGlobsReal(fileName)
5133 {
5134   MEDFileUtilities::CheckFileForRead(fileName);
5135   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5136   _content=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll);
5137   loadGlobals(fid);
5138 }
5139 catch(INTERP_KERNEL::Exception& e)
5140   {
5141     throw e;
5142   }
5143
5144 /*!
5145  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5146  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5147  *
5148  * \warning this is a shallow copy constructor
5149  */
5150 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5151 {
5152   if(!shallowCopyOfContent)
5153     {
5154       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5155       otherPtr->incrRef();
5156       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5157     }
5158   else
5159     {
5160       _content=other.shallowCpy();
5161     }
5162 }
5163
5164 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)
5165 {
5166   if(checkFieldId)
5167     {
5168       int nbFields=MEDnField(fid);
5169       if(fieldIdCFormat>=nbFields)
5170         {
5171           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5172           throw INTERP_KERNEL::Exception(oss.str().c_str());
5173         }
5174     }
5175   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5176   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5177   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5178   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5179   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5180   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5181   med_bool localMesh;
5182   int nbOfStep;
5183   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5184   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5185   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5186   infos.clear(); infos.resize(ncomp);
5187   for(int j=0;j<ncomp;j++)
5188     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5189   return nbOfStep;
5190 }
5191
5192 /*!
5193  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5194  * 
5195  * \param [out]
5196  * \return in case of success the number of time steps available for the field with name \a fieldName.
5197  */
5198 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)
5199 {
5200   int nbFields=MEDnField(fid);
5201   bool found=false;
5202   std::vector<std::string> fns(nbFields);
5203   int nbOfStep2=-1;
5204   for(int i=0;i<nbFields && !found;i++)
5205     {
5206       std::string tmp;
5207       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5208       fns[i]=tmp;
5209       found=(tmp==fieldName);
5210       if(found)
5211         posCFormat=i;
5212     }
5213   if(!found)
5214     {
5215       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5216       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5217         oss << "\"" << *it << "\" ";
5218       throw INTERP_KERNEL::Exception(oss.str().c_str());
5219     }
5220   return nbOfStep2;
5221 }
5222
5223 /*!
5224  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5225  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5226  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5227  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5228  * to keep a valid instance.
5229  * 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.
5230  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5231  * 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.
5232  *
5233  * \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.
5234  * \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.
5235  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5236  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5237  * \param [in] newLocName is the new localization name.
5238  * \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.
5239  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5240  */
5241 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newPflName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
5242 {
5243   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5244   std::string oldPflName=disc->getProfile();
5245   std::vector<std::string> vv=getPflsReallyUsedMulti();
5246   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5247   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5248     {
5249       disc->setProfile(newPflName);
5250       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5251       pfl->setName(newPflName);
5252     }
5253   else
5254     {
5255       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5256       throw INTERP_KERNEL::Exception(oss.str().c_str());
5257     }
5258 }
5259
5260 /*!
5261  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5262  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5263  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5264  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5265  * to keep a valid instance.
5266  * 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.
5267  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5268  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5269  * 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.
5270  *
5271  * \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.
5272  * \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.
5273  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5274  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5275  * \param [in] newLocName is the new localization name.
5276  * \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.
5277  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5278  */
5279 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newLocName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
5280 {
5281   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5282   std::string oldLocName=disc->getLocalization();
5283   std::vector<std::string> vv=getLocsReallyUsedMulti();
5284   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5285   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5286     {
5287       disc->setLocalization(newLocName);
5288       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5289       loc.setName(newLocName);
5290     }
5291   else
5292     {
5293       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5294       throw INTERP_KERNEL::Exception(oss.str().c_str());
5295     }
5296 }
5297
5298 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() throw(INTERP_KERNEL::Exception)
5299 {
5300   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5301   if(!ret)
5302     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5303   return ret;
5304 }
5305
5306 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const throw(INTERP_KERNEL::Exception)
5307 {
5308   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5309   if(!ret)
5310     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5311   return ret;
5312 }
5313
5314 /*!
5315  * Writes \a this field into a MED file specified by its name.
5316  *  \param [in] fileName - the MED file name.
5317  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5318  * - 2 - erase; an existing file is removed.
5319  * - 1 - append; same data should not be present in an existing file.
5320  * - 0 - overwrite; same data present in an existing file is overwritten.
5321  *  \throw If the field name is not set.
5322  *  \throw If no field data is set.
5323  *  \throw If \a mode == 1 and the same data is present in an existing file.
5324  */
5325 void MEDFileAnyTypeField1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
5326 {
5327   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5328   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
5329   writeLL(fid);
5330 }
5331
5332 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
5333 {
5334   int nbComp=getNumberOfComponents();
5335   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5336   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5337   for(int i=0;i<nbComp;i++)
5338     {
5339       std::string info=getInfo()[i];
5340       std::string c,u;
5341       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5342       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5343       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5344     }
5345   if(getName().empty())
5346     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5347   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5348   writeGlobals(fid,*this);
5349   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5350 }
5351
5352 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySize() const
5353 {
5354   std::size_t ret=0;
5355   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5356     ret+=_content->getHeapMemorySize();
5357   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
5358 }
5359
5360 /*!
5361  * Returns a string describing \a this field. This string is outputted 
5362  * by \c print Python command.
5363  */
5364 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5365 {
5366   std::ostringstream oss;
5367   contentNotNullBase()->simpleRepr(0,oss,-1);
5368   simpleReprGlobs(oss);
5369   return oss.str();
5370 }
5371
5372 /*!
5373  * This method returns all profiles whose name is non empty used.
5374  * \b WARNING If profile is used several times it will be reported \b only \b once.
5375  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5376  */
5377 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5378 {
5379   return contentNotNullBase()->getPflsReallyUsed2();
5380 }
5381
5382 /*!
5383  * This method returns all localizations whose name is non empty used.
5384  * \b WARNING If localization is used several times it will be reported \b only \b once.
5385  */
5386 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5387 {
5388   return contentNotNullBase()->getLocsReallyUsed2();
5389 }
5390
5391 /*!
5392  * This method returns all profiles whose name is non empty used.
5393  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5394  */
5395 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5396 {
5397   return contentNotNullBase()->getPflsReallyUsedMulti2();
5398 }
5399
5400 /*!
5401  * This method returns all localizations whose name is non empty used.
5402  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5403  */
5404 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5405 {
5406   return contentNotNullBase()->getLocsReallyUsedMulti2();
5407 }
5408
5409 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5410 {
5411   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5412 }
5413
5414 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5415 {
5416   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5417 }
5418
5419 int MEDFileAnyTypeField1TS::getDimension() const
5420 {
5421   return contentNotNullBase()->getDimension();
5422 }
5423
5424 int MEDFileAnyTypeField1TS::getIteration() const
5425 {
5426   return contentNotNullBase()->getIteration();
5427 }
5428
5429 int MEDFileAnyTypeField1TS::getOrder() const
5430 {
5431   return contentNotNullBase()->getOrder();
5432 }
5433
5434 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5435 {
5436   return contentNotNullBase()->getTime(iteration,order);
5437 }
5438
5439 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5440 {
5441   contentNotNullBase()->setTime(iteration,order,val);
5442 }
5443
5444 std::string MEDFileAnyTypeField1TS::getName() const
5445 {
5446   return contentNotNullBase()->getName();
5447 }
5448
5449 void MEDFileAnyTypeField1TS::setName(const char *name)
5450 {
5451   contentNotNullBase()->setName(name);
5452 }
5453
5454 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5455 {
5456   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5457 }
5458
5459 std::string MEDFileAnyTypeField1TS::getDtUnit() const throw(INTERP_KERNEL::Exception)
5460 {
5461   return contentNotNullBase()->getDtUnit();
5462 }
5463
5464 void MEDFileAnyTypeField1TS::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
5465 {
5466   contentNotNullBase()->setDtUnit(dtUnit);
5467 }
5468
5469 std::string MEDFileAnyTypeField1TS::getMeshName() const throw(INTERP_KERNEL::Exception)
5470 {
5471   return contentNotNullBase()->getMeshName();
5472 }
5473
5474 void MEDFileAnyTypeField1TS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
5475 {
5476   contentNotNullBase()->setMeshName(newMeshName);
5477 }
5478
5479 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
5480 {
5481   return contentNotNullBase()->changeMeshNames(modifTab);
5482 }
5483
5484 int MEDFileAnyTypeField1TS::getMeshIteration() const throw(INTERP_KERNEL::Exception)
5485 {
5486   return contentNotNullBase()->getMeshIteration();
5487 }
5488
5489 int MEDFileAnyTypeField1TS::getMeshOrder() const throw(INTERP_KERNEL::Exception)
5490 {
5491   return contentNotNullBase()->getMeshOrder();
5492 }
5493
5494 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5495 {
5496   return contentNotNullBase()->getNumberOfComponents();
5497 }
5498
5499 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5500 {
5501   return contentNotNullBase()->isDealingTS(iteration,order);
5502 }
5503
5504 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5505 {
5506   return contentNotNullBase()->getDtIt();
5507 }
5508
5509 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5510 {
5511   contentNotNullBase()->fillIteration(p);
5512 }
5513
5514 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
5515 {
5516   contentNotNullBase()->fillTypesOfFieldAvailable(types);
5517 }
5518
5519 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
5520 {
5521   contentNotNullBase()->setInfo(infos);
5522 }
5523
5524 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
5525 {
5526   return contentNotNullBase()->getInfo();
5527 }
5528 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
5529 {
5530   return contentNotNullBase()->getInfo();
5531 }
5532
5533 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
5534 {
5535   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5536 }
5537
5538 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
5539 {
5540   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5541 }
5542
5543 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
5544 {
5545   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
5546 }
5547
5548 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
5549 {
5550   return contentNotNullBase()->getTypesOfFieldAvailable();
5551 }
5552
5553 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,
5554                                                                                        std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
5555 {
5556   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5557 }
5558
5559 /*!
5560  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
5561  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5562  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
5563  */
5564 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const throw(INTERP_KERNEL::Exception)
5565 {
5566   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5567   if(!content)
5568     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
5569   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
5570   std::size_t sz(contentsSplit.size());
5571   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5572   for(std::size_t i=0;i<sz;i++)
5573     {
5574       ret[i]=shallowCpy();
5575       ret[i]->_content=contentsSplit[i];
5576     }
5577   return ret;
5578 }
5579
5580 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const throw(INTERP_KERNEL::Exception)
5581 {
5582   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
5583   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5584     ret->_content=_content->deepCpy();
5585   ret->deepCpyGlobs(*this);
5586   return ret.retn();
5587 }
5588
5589 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
5590 {
5591   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
5592 }
5593
5594 //= MEDFileField1TS
5595
5596 /*!
5597  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5598  * the first field that has been read from a specified MED file.
5599  *  \param [in] fileName - the name of the MED file to read.
5600  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5601  *          is to delete this field using decrRef() as it is no more needed.
5602  *  \throw If reading the file fails.
5603  */
5604 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5605 {
5606   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,loadAll);
5607   ret->contentNotNull();
5608   return ret.retn();
5609 }
5610
5611 /*!
5612  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5613  * a given field that has been read from a specified MED file.
5614  *  \param [in] fileName - the name of the MED file to read.
5615  *  \param [in] fieldName - the name of the field to read.
5616  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5617  *          is to delete this field using decrRef() as it is no more needed.
5618  *  \throw If reading the file fails.
5619  *  \throw If there is no field named \a fieldName in the file.
5620  */
5621 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5622 {
5623   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,loadAll);
5624   ret->contentNotNull();
5625   return ret.retn();
5626 }
5627
5628 /*!
5629  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
5630  * a given field that has been read from a specified MED file.
5631  *  \param [in] fileName - the name of the MED file to read.
5632  *  \param [in] fieldName - the name of the field to read.
5633  *  \param [in] iteration - the iteration number of a required time step.
5634  *  \param [in] order - the iteration order number of required time step.
5635  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5636  *          is to delete this field using decrRef() as it is no more needed.
5637  *  \throw If reading the file fails.
5638  *  \throw If there is no field named \a fieldName in the file.
5639  *  \throw If the required time step is missing from the file.
5640  */
5641 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5642 {
5643   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll);
5644   ret->contentNotNull();
5645   return ret.retn();
5646 }
5647
5648 /*!
5649  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5650  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5651  *
5652  * Returns a new instance of MEDFileField1TS holding either a shallow copy
5653  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
5654  * \warning this is a shallow copy constructor
5655  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
5656  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
5657  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5658  *          is to delete this field using decrRef() as it is no more needed.
5659  */
5660 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
5661 {
5662   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
5663   ret->contentNotNull();
5664   return ret.retn();
5665 }
5666
5667 /*!
5668  * Returns a new empty instance of MEDFileField1TS.
5669  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5670  *          is to delete this field using decrRef() as it is no more needed.
5671  */
5672 MEDFileField1TS *MEDFileField1TS::New()
5673 {
5674   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
5675   ret->contentNotNull();
5676   return ret.retn();
5677 }
5678
5679 /*!
5680  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
5681  * following the given input policy.
5682  *
5683  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
5684  *                            By default (true) the globals are deeply copied.
5685  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
5686  */
5687 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
5688 {
5689   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
5690   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5691   if(content)
5692     {
5693       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
5694       if(!contc)
5695         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
5696       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
5697       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
5698     }
5699   else
5700     ret=MEDFileIntField1TS::New();
5701   if(deepCpyGlobs)
5702     ret->deepCpyGlobs(*this);
5703   else
5704     ret->shallowCpyGlobs(*this);
5705   return ret.retn();
5706 }
5707
5708 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const throw(INTERP_KERNEL::Exception)
5709 {
5710   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
5711   if(!pt)
5712     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
5713   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
5714   if(!ret)
5715     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 !");
5716   return ret;
5717 }
5718
5719 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() throw(INTERP_KERNEL::Exception)
5720 {
5721   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
5722   if(!pt)
5723     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
5724   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
5725   if(!ret)
5726     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 !");
5727   return ret;
5728 }
5729
5730 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
5731 {
5732   if(!f)
5733     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
5734   if(!((DataArray*)arr))
5735     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
5736   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
5737   if(!arrOutC)
5738     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
5739   f->setArray(arrOutC);
5740 }
5741
5742 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
5743 {
5744   if(!((DataArray*)arr))
5745     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
5746   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
5747   if(!arrOutC)
5748     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
5749   arrOutC->incrRef();
5750   return arrOutC;
5751 }
5752
5753 MEDFileField1TS::MEDFileField1TS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5754 try:MEDFileAnyTypeField1TS(fileName,loadAll)
5755 {
5756 }
5757 catch(INTERP_KERNEL::Exception& e)
5758   { throw e; }
5759
5760 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5761 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
5762 {
5763 }
5764 catch(INTERP_KERNEL::Exception& e)
5765   { throw e; }
5766
5767 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5768 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
5769 {
5770 }
5771 catch(INTERP_KERNEL::Exception& e)
5772   { throw e; }
5773
5774 /*!
5775  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5776  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5777  *
5778  * \warning this is a shallow copy constructor
5779  */
5780 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
5781 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
5782 {
5783 }
5784 catch(INTERP_KERNEL::Exception& e)
5785   { throw e; }
5786
5787 MEDFileField1TS::MEDFileField1TS()
5788 {
5789   _content=new MEDFileField1TSWithoutSDA;
5790 }
5791
5792 /*!
5793  * Returns a new MEDCouplingFieldDouble of a given type lying on
5794  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
5795  * has not been constructed via file reading, an exception is thrown.
5796  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5797  *  \param [in] type - a spatial discretization of interest.
5798  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5799  *  \param [in] renumPol - specifies how to permute values of the result field according to
5800  *          the optional numbers of cells and nodes, if any. The valid values are
5801  *          - 0 - do not permute.
5802  *          - 1 - permute cells.
5803  *          - 2 - permute nodes.
5804  *          - 3 - permute cells and nodes.
5805  *
5806  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5807  *          caller is to delete this field using decrRef() as it is no more needed. 
5808  *  \throw If \a this field has not been constructed via file reading.
5809  *  \throw If the MED file is not readable.
5810  *  \throw If there is no mesh in the MED file.
5811  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5812  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5813  *  \sa getFieldOnMeshAtLevel()
5814  */
5815 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
5816 {
5817   if(getFileName2().empty())
5818     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
5819   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5820   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut,*contentNotNull());
5821   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5822   return ret.retn();
5823 }
5824
5825 /*!
5826  * Returns a new MEDCouplingFieldDouble of a given type lying on
5827  * the top level cells of the first mesh in MED file. If \a this field 
5828  * has not been constructed via file reading, an exception is thrown.
5829  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5830  *  \param [in] type - a spatial discretization of interest.
5831  *  \param [in] renumPol - specifies how to permute values of the result field according to
5832  *          the optional numbers of cells and nodes, if any. The valid values are
5833  *          - 0 - do not permute.
5834  *          - 1 - permute cells.
5835  *          - 2 - permute nodes.
5836  *          - 3 - permute cells and nodes.
5837  *
5838  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5839  *          caller is to delete this field using decrRef() as it is no more needed. 
5840  *  \throw If \a this field has not been constructed via file reading.
5841  *  \throw If the MED file is not readable.
5842  *  \throw If there is no mesh in the MED file.
5843  *  \throw If no field values of the given \a type.
5844  *  \throw If no field values lying on the top level support.
5845  *  \sa getFieldAtLevel()
5846  */
5847 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const throw(INTERP_KERNEL::Exception)
5848 {
5849   if(getFileName2().empty())
5850     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
5851   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5852   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,0,renumPol,this,arrOut,*contentNotNull());
5853   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5854   return ret.retn();
5855 }
5856
5857 /*!
5858  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
5859  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5860  *  \param [in] type - a spatial discretization of the new field.
5861  *  \param [in] mesh - the supporting mesh.
5862  *  \param [in] renumPol - specifies how to permute values of the result field according to
5863  *          the optional numbers of cells and nodes, if any. The valid values are
5864  *          - 0 - do not permute.
5865  *          - 1 - permute cells.
5866  *          - 2 - permute nodes.
5867  *          - 3 - permute cells and nodes.
5868  *
5869  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5870  *          caller is to delete this field using decrRef() as it is no more needed. 
5871  *  \throw If no field of \a this is lying on \a mesh.
5872  *  \throw If the mesh is empty.
5873  *  \throw If no field values of the given \a type are available.
5874  *  \sa getFieldAtLevel()
5875  *  \sa getFieldOnMeshAtLevel() 
5876  */
5877 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
5878 {
5879   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5880   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
5881   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5882   return ret.retn();
5883 }
5884
5885 /*!
5886  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
5887  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5888  *  \param [in] type - a spatial discretization of interest.
5889  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5890  *  \param [in] mesh - the supporting mesh.
5891  *  \param [in] renumPol - specifies how to permute values of the result field according to
5892  *          the optional numbers of cells and nodes, if any. The valid values are
5893  *          - 0 - do not permute.
5894  *          - 1 - permute cells.
5895  *          - 2 - permute nodes.
5896  *          - 3 - permute cells and nodes.
5897  *
5898  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5899  *          caller is to delete this field using decrRef() as it is no more needed. 
5900  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5901  *  \throw If no field of \a this is lying on \a mesh.
5902  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5903  *  \sa getFieldAtLevel()
5904  *  \sa getFieldOnMeshAtLevel() 
5905  */
5906 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
5907 {
5908   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5909   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
5910   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5911   return ret.retn();
5912 }
5913
5914 /*!
5915  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
5916  * This method is called "Old" because in MED3 norm a field has only one meshName
5917  * attached, so this method is for readers of MED2 files. If \a this field 
5918  * has not been constructed via file reading, an exception is thrown.
5919  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5920  *  \param [in] type - a spatial discretization of interest.
5921  *  \param [in] mName - a name of the supporting mesh.
5922  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5923  *  \param [in] renumPol - specifies how to permute values of the result field according to
5924  *          the optional numbers of cells and nodes, if any. The valid values are
5925  *          - 0 - do not permute.
5926  *          - 1 - permute cells.
5927  *          - 2 - permute nodes.
5928  *          - 3 - permute cells and nodes.
5929  *
5930  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5931  *          caller is to delete this field using decrRef() as it is no more needed. 
5932  *  \throw If the MED file is not readable.
5933  *  \throw If there is no mesh named \a mName in the MED file.
5934  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5935  *  \throw If \a this field has not been constructed via file reading.
5936  *  \throw If no field of \a this is lying on the mesh named \a mName.
5937  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5938  *  \sa getFieldAtLevel()
5939  */
5940 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
5941 {
5942   if(getFileName2().empty())
5943     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
5944   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5945   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
5946   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5947   return ret.retn();
5948 }
5949
5950 /*!
5951  * Returns values and a profile of the field of a given type lying on a given support.
5952  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5953  *  \param [in] type - a spatial discretization of the field.
5954  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5955  *  \param [in] mesh - the supporting mesh.
5956  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5957  *          field of interest lies on. If the field lies on all entities of the given
5958  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5959  *          using decrRef() as it is no more needed.  
5960  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5961  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5962  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5963  *  \throw If no field of \a this is lying on \a mesh.
5964  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5965  */
5966 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
5967 {
5968   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
5969   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
5970 }
5971
5972 /*!
5973  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
5974  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
5975  * "Sort By Type"), if not, an exception is thrown. 
5976  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5977  *  \param [in] field - the field to add to \a this.
5978  *  \throw If the name of \a field is empty.
5979  *  \throw If the data array of \a field is not set.
5980  *  \throw If the data array is already allocated but has different number of components
5981  *         than \a field.
5982  *  \throw If the underlying mesh of \a field has no name.
5983  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
5984  */
5985 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
5986 {
5987   setFileName("");
5988   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
5989 }
5990
5991 /*!
5992  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
5993  * of a given mesh are used as the support of the given field (a real support is not used). 
5994  * Elements of the given mesh must be sorted suitable for writing to MED file.
5995  * Order of underlying mesh entities of the given field specified by \a profile parameter
5996  * is not prescribed; this method permutes field values to have them sorted by element
5997  * type as required for writing to MED file. A new profile is added only if no equal
5998  * profile is missing.
5999  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6000  *  \param [in] field - the field to add to \a this.
6001  *  \param [in] mesh - the supporting mesh of \a field.
6002  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
6003  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6004  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6005  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6006  *  \throw If the data array of \a field is not set.
6007  *  \throw If the data array of \a this is already allocated but has different number of
6008  *         components than \a field.
6009  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6010  *  \sa setFieldNoProfileSBT()
6011  */
6012 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
6013 {
6014   setFileName("");
6015   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6016 }
6017
6018 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const throw(INTERP_KERNEL::Exception)
6019 {
6020   return new MEDFileField1TS(*this);
6021 }
6022
6023 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
6024 {
6025   return contentNotNull()->getUndergroundDataArrayDouble();
6026 }
6027
6028 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
6029 {
6030   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6031 }
6032
6033 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6034                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
6035 {
6036   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6037 }
6038
6039 //= MEDFileIntField1TS
6040
6041 MEDFileIntField1TS *MEDFileIntField1TS::New()
6042 {
6043   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6044   ret->contentNotNull();
6045   return ret.retn();
6046 }
6047
6048 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
6049 {
6050   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,loadAll);
6051   ret->contentNotNull();
6052   return ret.retn();
6053 }
6054
6055 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
6056 {
6057   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,loadAll);
6058   ret->contentNotNull();
6059   return ret.retn();
6060 }
6061
6062 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
6063 {
6064   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll);
6065   ret->contentNotNull();
6066   return ret.retn();
6067 }
6068
6069 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6070 {
6071   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6072   ret->contentNotNull();
6073   return ret.retn();
6074 }
6075
6076 MEDFileIntField1TS::MEDFileIntField1TS()
6077 {
6078   _content=new MEDFileIntField1TSWithoutSDA;
6079 }
6080
6081 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
6082 try:MEDFileAnyTypeField1TS(fileName,loadAll)
6083 {
6084 }
6085 catch(INTERP_KERNEL::Exception& e)
6086   { throw e; }
6087
6088 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
6089 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
6090 {
6091 }
6092 catch(INTERP_KERNEL::Exception& e)
6093   { throw e; }
6094
6095 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
6096 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
6097 {
6098 }
6099 catch(INTERP_KERNEL::Exception& e)
6100   { throw e; }
6101
6102 /*!
6103  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6104  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6105  *
6106  * \warning this is a shallow copy constructor
6107  */
6108 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6109 {
6110 }
6111
6112 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const throw(INTERP_KERNEL::Exception)
6113 {
6114   return new MEDFileIntField1TS(*this);
6115 }
6116
6117 /*!
6118  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6119  * following the given input policy.
6120  *
6121  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6122  *                            By default (true) the globals are deeply copied.
6123  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6124  */
6125 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
6126 {
6127   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6128   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6129   if(content)
6130     {
6131       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6132       if(!contc)
6133         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6134       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6135       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6136     }
6137   else
6138     ret=MEDFileField1TS::New();
6139   if(deepCpyGlobs)
6140     ret->deepCpyGlobs(*this);
6141   else
6142     ret->shallowCpyGlobs(*this);
6143   return ret.retn();
6144 }
6145
6146 /*!
6147  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6148  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6149  * "Sort By Type"), if not, an exception is thrown. 
6150  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6151  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6152  *  \param [in] arrOfVals - the values of the field \a field used.
6153  *  \throw If the name of \a field is empty.
6154  *  \throw If the data array of \a field is not set.
6155  *  \throw If the data array is already allocated but has different number of components
6156  *         than \a field.
6157  *  \throw If the underlying mesh of \a field has no name.
6158  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6159  */
6160 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception)
6161 {
6162   setFileName("");
6163   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6164 }
6165
6166 /*!
6167  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
6168  * of a given mesh are used as the support of the given field (a real support is not used). 
6169  * Elements of the given mesh must be sorted suitable for writing to MED file.
6170  * Order of underlying mesh entities of the given field specified by \a profile parameter
6171  * is not prescribed; this method permutes field values to have them sorted by element
6172  * type as required for writing to MED file. A new profile is added only if no equal
6173  * profile is missing.
6174  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6175  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6176  *  \param [in] arrOfVals - the values of the field \a field used.
6177  *  \param [in] mesh - the supporting mesh of \a field.
6178  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
6179  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6180  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6181  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6182  *  \throw If the data array of \a field is not set.
6183  *  \throw If the data array of \a this is already allocated but has different number of
6184  *         components than \a field.
6185  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6186  *  \sa setFieldNoProfileSBT()
6187  */
6188 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
6189 {
6190   setFileName("");
6191   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6192 }
6193
6194 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const throw(INTERP_KERNEL::Exception)
6195 {
6196   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6197   if(!pt)
6198     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6199   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6200   if(!ret)
6201     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 !");
6202   return ret;
6203 }
6204
6205 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6206 {
6207   if(getFileName2().empty())
6208     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6209   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6210   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut2,*contentNotNull());
6211   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6212   if(!arrOutC)
6213     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6214   arrOut=arrOutC;
6215   return ret.retn();
6216 }
6217
6218 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
6219 {
6220   if(!((DataArray *)arr))
6221     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6222   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6223   if(!arrC)
6224     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6225   arrC->incrRef();
6226   return arrC;
6227 }
6228
6229 /*!
6230  * Returns a new MEDCouplingFieldDouble of a given type lying on
6231  * the top level cells of the first mesh in MED file. If \a this field 
6232  * has not been constructed via file reading, an exception is thrown.
6233  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6234  *  \param [in] type - a spatial discretization of interest.
6235  *  \param [out] arrOut - the DataArrayInt containing values of field.
6236  *  \param [in] renumPol - specifies how to permute values of the result field according to
6237  *          the optional numbers of cells and nodes, if any. The valid values are
6238  *          - 0 - do not permute.
6239  *          - 1 - permute cells.
6240  *          - 2 - permute nodes.
6241  *          - 3 - permute cells and nodes.
6242  *
6243  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6244  *          caller is to delete this field using decrRef() as it is no more needed. 
6245  *  \throw If \a this field has not been constructed via file reading.
6246  *  \throw If the MED file is not readable.
6247  *  \throw If there is no mesh in the MED file.
6248  *  \throw If no field values of the given \a type.
6249  *  \throw If no field values lying on the top level support.
6250  *  \sa getFieldAtLevel()
6251  */
6252 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6253 {
6254   if(getFileName2().empty())
6255     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6256   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6257   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,0,renumPol,this,arr,*contentNotNull());
6258   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6259   return ret.retn();
6260 }
6261
6262 /*!
6263  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6264  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6265  *  \param [in] type - a spatial discretization of the new field.
6266  *  \param [in] mesh - the supporting mesh.
6267  *  \param [out] arrOut - the DataArrayInt containing values of field.
6268  *  \param [in] renumPol - specifies how to permute values of the result field according to
6269  *          the optional numbers of cells and nodes, if any. The valid values are
6270  *          - 0 - do not permute.
6271  *          - 1 - permute cells.
6272  *          - 2 - permute nodes.
6273  *          - 3 - permute cells and nodes.
6274  *
6275  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6276  *          caller is to delete this field using decrRef() as it is no more needed. 
6277  *  \throw If no field of \a this is lying on \a mesh.
6278  *  \throw If the mesh is empty.
6279  *  \throw If no field values of the given \a type are available.
6280  *  \sa getFieldAtLevel()
6281  *  \sa getFieldOnMeshAtLevel() 
6282  */
6283 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6284 {
6285   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6286   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6287   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6288   return ret.retn();
6289 }
6290
6291 /*!
6292  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6293  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6294  *  \param [in] type - a spatial discretization of interest.
6295  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6296  *  \param [out] arrOut - the DataArrayInt containing values of field.
6297  *  \param [in] mesh - the supporting mesh.
6298  *  \param [in] renumPol - specifies how to permute values of the result field according to
6299  *          the optional numbers of cells and nodes, if any. The valid values are
6300  *          - 0 - do not permute.
6301  *          - 1 - permute cells.
6302  *          - 2 - permute nodes.
6303  *          - 3 - permute cells and nodes.
6304  *
6305  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6306  *          caller is to delete this field using decrRef() as it is no more needed. 
6307  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6308  *  \throw If no field of \a this is lying on \a mesh.
6309  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6310  *  \sa getFieldAtLevel()
6311  *  \sa getFieldOnMeshAtLevel() 
6312  */
6313 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6314 {
6315   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6316   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6317   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6318   return ret.retn();
6319 }
6320
6321 /*!
6322  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6323  * This method is called "Old" because in MED3 norm a field has only one meshName
6324  * attached, so this method is for readers of MED2 files. If \a this field 
6325  * has not been constructed via file reading, an exception is thrown.
6326  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6327  *  \param [in] type - a spatial discretization of interest.
6328  *  \param [in] mName - a name of the supporting mesh.
6329  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6330  *  \param [out] arrOut - the DataArrayInt containing values of field.
6331  *  \param [in] renumPol - specifies how to permute values of the result field according to
6332  *          the optional numbers of cells and nodes, if any. The valid values are
6333  *          - 0 - do not permute.
6334  *          - 1 - permute cells.
6335  *          - 2 - permute nodes.
6336  *          - 3 - permute cells and nodes.
6337  *
6338  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6339  *          caller is to delete this field using decrRef() as it is no more needed. 
6340  *  \throw If the MED file is not readable.
6341  *  \throw If there is no mesh named \a mName in the MED file.
6342  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6343  *  \throw If \a this field has not been constructed via file reading.
6344  *  \throw If no field of \a this is lying on the mesh named \a mName.
6345  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6346  *  \sa getFieldAtLevel()
6347  */
6348 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6349 {
6350   if(getFileName2().empty())
6351     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6352   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6353   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6354   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6355   return ret.retn();
6356 }
6357
6358 /*!
6359  * Returns values and a profile of the field of a given type lying on a given support.
6360  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6361  *  \param [in] type - a spatial discretization of the field.
6362  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6363  *  \param [in] mesh - the supporting mesh.
6364  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6365  *          field of interest lies on. If the field lies on all entities of the given
6366  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6367  *          using decrRef() as it is no more needed.  
6368  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6369  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6370  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6371  *  \throw If no field of \a this is lying on \a mesh.
6372  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6373  */
6374 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
6375 {
6376   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6377   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6378 }
6379
6380 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() throw(INTERP_KERNEL::Exception)
6381 {
6382   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6383   if(!pt)
6384     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6385   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6386   if(!ret)
6387     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 !");
6388   return ret;
6389 }
6390
6391 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
6392 {
6393   return contentNotNull()->getUndergroundDataArrayInt();
6394 }
6395
6396 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6397
6398 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6399 {
6400 }
6401
6402 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const char *fieldName):MEDFileFieldNameScope(fieldName)
6403 {
6404 }
6405
6406 /*!
6407  * \param [in] fieldId field id in C mode
6408  */
6409 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll) throw(INTERP_KERNEL::Exception)
6410 {
6411   med_field_type typcha;
6412   std::string dtunitOut;
6413   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6414   setDtUnit(dtunitOut.c_str());
6415   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll);
6416 }
6417
6418 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll) throw(INTERP_KERNEL::Exception)
6419 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6420 {
6421   setDtUnit(dtunit.c_str());
6422   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll);
6423 }
6424 catch(INTERP_KERNEL::Exception& e)
6425 {
6426   throw e;
6427 }
6428
6429 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySize() const
6430 {
6431   std::size_t ret=_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>);
6432   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6433     ret+=(*it).capacity();
6434   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6435     if((const MEDFileAnyTypeField1TSWithoutSDA *)(*it))
6436       ret+=(*it)->getHeapMemorySize();
6437   return ret;
6438 }
6439
6440 /*!
6441  * 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
6442  * NULL.
6443  */
6444 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
6445 {
6446   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6447   ret->setInfo(_infos);
6448   int sz=(int)_time_steps.size();
6449   for(const int *id=startIds;id!=endIds;id++)
6450     {
6451       if(*id>=0 && *id<sz)
6452         {
6453           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6454           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6455           if(tse)
6456             {
6457               tse->incrRef();
6458               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6459             }
6460           ret->pushBackTimeStep(tse2);
6461         }
6462       else
6463         {
6464           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6465           oss << " ! Should be in [0," << sz << ") !";
6466           throw INTERP_KERNEL::Exception(oss.str().c_str());
6467         }
6468     }
6469   if(ret->getNumberOfTS()>0)
6470     ret->synchronizeNameScope();
6471   ret->copyNameScope(*this);
6472   return ret.retn();
6473 }
6474
6475 /*!
6476  * 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
6477  * NULL.
6478  */
6479 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
6480 {
6481   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6482   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6483   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6484   ret->setInfo(_infos);
6485   int sz=(int)_time_steps.size();
6486   int j=bg;
6487   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
6488     {
6489       if(j>=0 && j<sz)
6490         {
6491           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
6492           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6493           if(tse)
6494             {
6495               tse->incrRef();
6496               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6497             }
6498           ret->pushBackTimeStep(tse2);
6499         }
6500       else
6501         {
6502           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
6503           oss << " ! Should be in [0," << sz << ") !";
6504           throw INTERP_KERNEL::Exception(oss.str().c_str());
6505         }
6506     }
6507   if(ret->getNumberOfTS()>0)
6508     ret->synchronizeNameScope();
6509   ret->copyNameScope(*this);
6510   return ret.retn();
6511 }
6512
6513 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
6514 {
6515   int id=0;
6516   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6517   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6518     {
6519       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6520       if(!cur)
6521         continue;
6522       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6523       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
6524         ids->pushBackSilent(id);
6525     }
6526   return buildFromTimeStepIds(ids->begin(),ids->end());
6527 }
6528
6529 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
6530 {
6531   int id=0;
6532   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6533   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6534     {
6535       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6536       if(!cur)
6537         continue;
6538       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6539       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
6540         ids->pushBackSilent(id);
6541     }
6542   return buildFromTimeStepIds(ids->begin(),ids->end());
6543 }
6544
6545 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const throw(INTERP_KERNEL::Exception)
6546 {
6547   return _infos;
6548 }
6549
6550 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
6551 {
6552   _infos=info;
6553 }
6554
6555 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6556 {
6557   int ret=0;
6558   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6559     {
6560       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
6561       if(pt->isDealingTS(iteration,order))
6562         return ret;
6563     }
6564   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
6565   std::vector< std::pair<int,int> > vp=getIterations();
6566   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
6567     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
6568   throw INTERP_KERNEL::Exception(oss.str().c_str());
6569 }
6570
6571 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6572 {
6573   return *_time_steps[getTimeStepPos(iteration,order)];
6574 }
6575
6576 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) throw(INTERP_KERNEL::Exception)
6577 {
6578   return *_time_steps[getTimeStepPos(iteration,order)];
6579 }
6580
6581 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
6582 {
6583   if(_time_steps.empty())
6584     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
6585   return _time_steps[0]->getMeshName();
6586 }
6587
6588 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
6589 {
6590   std::string oldName(getMeshName());
6591   std::vector< std::pair<std::string,std::string> > v(1);
6592   v[0].first=oldName; v[0].second=newMeshName;
6593   changeMeshNames(v);
6594 }
6595
6596 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
6597 {
6598   bool ret=false;
6599   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6600     {
6601       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6602       if(cur)
6603         ret=cur->changeMeshNames(modifTab) || ret;
6604     }
6605   return ret;
6606 }
6607
6608 /*!
6609  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
6610  */
6611 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6612 {
6613   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
6614 }
6615
6616 /*!
6617  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
6618  */
6619 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)
6620 {
6621   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
6622 }
6623
6624 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
6625                                                                 MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
6626 {
6627   bool ret=false;
6628   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6629     {
6630       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
6631       if(f1ts)
6632         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
6633     }
6634   return ret;
6635 }
6636
6637 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
6638 {
6639   std::string startLine(bkOffset,' ');
6640   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
6641   if(fmtsId>=0)
6642     oss << " (" << fmtsId << ")";
6643   oss << " has the following name: \"" << _name << "\"." << std::endl;
6644   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
6645   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6646     {
6647       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
6648     }
6649   int i=0;
6650   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
6651     {
6652       std::string chapter(17,'0'+i);
6653       oss << startLine << chapter << std::endl;
6654       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6655       if(cur)
6656         cur->simpleRepr(bkOffset+2,oss,i);
6657       else
6658         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
6659       oss << startLine << chapter << std::endl;
6660     }
6661 }
6662
6663 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
6664 {
6665   std::size_t sz=_time_steps.size();
6666   std::vector< std::pair<int,int> > ret(sz);
6667   ret1.resize(sz);
6668   for(std::size_t i=0;i<sz;i++)
6669     {
6670       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
6671       if(f1ts)
6672         {
6673           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
6674         }
6675       else
6676         {
6677           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
6678           throw INTERP_KERNEL::Exception(oss.str().c_str());
6679         }
6680     }
6681   return ret;
6682 }
6683
6684 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse) throw(INTERP_KERNEL::Exception)
6685 {
6686   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
6687   if(!tse2)
6688     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
6689   checkCoherencyOfType(tse2);
6690   if(_time_steps.empty())
6691     {
6692       setName(tse2->getName().c_str());
6693       setInfo(tse2->getInfo());
6694     }
6695   checkThatComponentsMatch(tse2->getInfo());
6696   _time_steps.push_back(tse);
6697 }
6698
6699 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope() throw(INTERP_KERNEL::Exception)
6700 {
6701   std::size_t nbOfCompo=_infos.size();
6702   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6703     {
6704       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6705       if(cur)
6706         {
6707           if((cur->getInfo()).size()!=nbOfCompo)
6708             {
6709               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
6710               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
6711               throw INTERP_KERNEL::Exception(oss.str().c_str());
6712             }
6713           cur->copyNameScope(*this);
6714         }
6715     }
6716 }
6717
6718 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll) throw(INTERP_KERNEL::Exception)
6719 {
6720   _time_steps.resize(nbPdt);
6721   for(int i=0;i<nbPdt;i++)
6722     {
6723       std::vector< std::pair<int,int> > ts;
6724       med_int numdt=0,numo=0;
6725       med_int meshIt=0,meshOrder=0;
6726       med_float dt=0.0;
6727       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
6728       switch(fieldTyp)
6729         {
6730         case MED_FLOAT64:
6731           {
6732             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
6733             break;
6734           }
6735         case MED_INT32:
6736           {
6737             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
6738             break;
6739           }
6740         default:
6741           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
6742         }
6743       if(loadAll)
6744         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this);
6745       else
6746         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this);
6747     }
6748 }
6749
6750 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception)
6751 {
6752   if(_time_steps.empty())
6753     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
6754   checkThatNbOfCompoOfTSMatchThis();
6755   std::vector<std::string> infos(getInfo());
6756   int nbComp=infos.size();
6757   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
6758   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
6759   for(int i=0;i<nbComp;i++)
6760     {
6761       std::string info=infos[i];
6762       std::string c,u;
6763       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6764       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
6765       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
6766     }
6767   if(_name.empty())
6768     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
6769   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
6770   int nbOfTS=_time_steps.size();
6771   for(int i=0;i<nbOfTS;i++)
6772     _time_steps[i]->writeLL(fid,opts,*this);
6773 }
6774
6775 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
6776 {
6777   return _time_steps.size();
6778 }
6779
6780 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
6781 {
6782   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
6783   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6784     {
6785       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
6786       if(tmp)
6787         newTS.push_back(*it);
6788     }
6789   _time_steps=newTS;
6790 }
6791
6792 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
6793 {
6794   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
6795   int maxId=(int)_time_steps.size();
6796   int ii=0;
6797   std::set<int> idsToDel;
6798   for(const int *id=startIds;id!=endIds;id++,ii++)
6799     {
6800       if(*id>=0 && *id<maxId)
6801         {
6802           idsToDel.insert(*id);
6803         }
6804       else
6805         {
6806           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
6807           throw INTERP_KERNEL::Exception(oss.str().c_str());
6808         }
6809     }
6810   for(int iii=0;iii<maxId;iii++)
6811     if(idsToDel.find(iii)==idsToDel.end())
6812       newTS.push_back(_time_steps[iii]);
6813   _time_steps=newTS;
6814 }
6815
6816 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
6817 {
6818   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
6819   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6820   if(nbOfEntriesToKill==0)
6821     return ;
6822   std::size_t sz=_time_steps.size();
6823   std::vector<bool> b(sz,true);
6824   int j=bg;
6825   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
6826     b[j]=false;
6827   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
6828   for(std::size_t i=0;i<sz;i++)
6829     if(b[i])
6830       newTS.push_back(_time_steps[i]);
6831   _time_steps=newTS;
6832 }
6833
6834 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6835 {
6836   int ret=0;
6837   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
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           tmp->getTime(it2,ord);
6845           if(it2==iteration && order==ord)
6846             return ret;
6847           else
6848             oss << "(" << it2 << ","  << ord << "), ";
6849         }
6850     }
6851   throw INTERP_KERNEL::Exception(oss.str().c_str());
6852 }
6853
6854 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
6855 {
6856   int ret=0;
6857   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
6858   oss.precision(15);
6859   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6860     {
6861       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
6862       if(tmp)
6863         {
6864           int it2,ord;
6865           double ti=tmp->getTime(it2,ord);
6866           if(fabs(time-ti)<eps)
6867             return ret;
6868           else
6869             oss << ti << ", ";
6870         }
6871     }
6872   throw INTERP_KERNEL::Exception(oss.str().c_str());
6873 }
6874
6875 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
6876 {
6877   int lgth=_time_steps.size();
6878   std::vector< std::pair<int,int> > ret(lgth);
6879   for(int i=0;i<lgth;i++)
6880     _time_steps[i]->fillIteration(ret[i]);
6881   return ret;
6882 }
6883
6884 /*!
6885  * 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'
6886  * This method returns two things.
6887  * - The absolute dimension of 'this' in first parameter. 
6888  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
6889  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
6890  *
6891  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
6892  * Only these 3 discretizations will be taken into account here.
6893  *
6894  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
6895  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
6896  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
6897  *
6898  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
6899  * 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'.
6900  * 
6901  * Let's consider the typical following case :
6902  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
6903  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
6904  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
6905  *   TETRA4 and SEG2
6906  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
6907  *
6908  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
6909  * 
6910  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
6911  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
6912  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
6913  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
6914  */
6915 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
6916 {
6917   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
6918 }
6919
6920 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const throw(INTERP_KERNEL::Exception)
6921 {
6922   if(pos<0 || pos>=(int)_time_steps.size())
6923     {
6924       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
6925       throw INTERP_KERNEL::Exception(oss.str().c_str());
6926     }
6927   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
6928   if(item==0)
6929     {
6930       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
6931       oss << "\nTry to use following method eraseEmptyTS !";
6932       throw INTERP_KERNEL::Exception(oss.str().c_str());
6933     }
6934   return item;
6935 }
6936
6937 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) throw(INTERP_KERNEL::Exception)
6938 {
6939   if(pos<0 || pos>=(int)_time_steps.size())
6940     {
6941       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
6942       throw INTERP_KERNEL::Exception(oss.str().c_str());
6943     }
6944   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
6945   if(item==0)
6946     {
6947       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
6948       oss << "\nTry to use following method eraseEmptyTS !";
6949       throw INTERP_KERNEL::Exception(oss.str().c_str());
6950     }
6951   return item;
6952 }
6953
6954 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
6955 {
6956   std::vector<std::string> ret;
6957   std::set<std::string> ret2;
6958   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6959     {
6960       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
6961       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
6962         if(ret2.find(*it2)==ret2.end())
6963           {
6964             ret.push_back(*it2);
6965             ret2.insert(*it2);
6966           }
6967     }
6968   return ret;
6969 }
6970
6971 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
6972 {
6973   std::vector<std::string> ret;
6974   std::set<std::string> ret2;
6975   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6976     {
6977       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
6978       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
6979         if(ret2.find(*it2)==ret2.end())
6980           {
6981             ret.push_back(*it2);
6982             ret2.insert(*it2);
6983           }
6984     }
6985   return ret;
6986 }
6987
6988 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
6989 {
6990   std::vector<std::string> ret;
6991   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6992     {
6993       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
6994       ret.insert(ret.end(),tmp.begin(),tmp.end());
6995     }
6996   return ret;
6997 }
6998
6999 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7000 {
7001   std::vector<std::string> ret;
7002   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7003     {
7004       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7005       ret.insert(ret.end(),tmp.begin(),tmp.end());
7006     }
7007   return ret;
7008 }
7009
7010 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7011 {
7012   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7013     (*it)->changePflsRefsNamesGen2(mapOfModif);
7014 }
7015
7016 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7017 {
7018   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7019     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7020 }
7021
7022 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
7023 {
7024   int lgth=_time_steps.size();
7025   std::vector< std::vector<TypeOfField> > ret(lgth);
7026   for(int i=0;i<lgth;i++)
7027     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7028   return ret;
7029 }
7030
7031 /*!
7032  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7033  */
7034 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)
7035 {
7036   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7037 }
7038
7039 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
7040 {
7041   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7042   std::size_t i=0;
7043   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7044     {
7045       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7046         ret->_time_steps[i]=(*it)->deepCpy();
7047     }
7048   return ret.retn();
7049 }
7050
7051 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const throw(INTERP_KERNEL::Exception)
7052 {
7053   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7054   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7055   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7056   for(std::size_t i=0;i<sz;i++)
7057     {
7058       ret[i]=shallowCpy();
7059       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7060     }
7061   for(std::size_t i=0;i<sz2;i++)
7062     {
7063       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7064       if(ret1.size()!=sz)
7065         {
7066           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7067           throw INTERP_KERNEL::Exception(oss.str().c_str());
7068         }
7069       ts[i]=ret1;
7070     }
7071   for(std::size_t i=0;i<sz;i++)
7072     for(std::size_t j=0;j<sz2;j++)
7073       ret[i]->_time_steps[j]=ts[j][i];
7074   return ret;
7075 }
7076
7077 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
7078 {
7079   _name=field->getName();
7080   if(_name.empty())
7081     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7082   if(!arr)
7083     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7084   _infos=arr->getInfoOnComponents();
7085 }
7086
7087 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const throw(INTERP_KERNEL::Exception)
7088 {
7089   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7090   if(_name!=field->getName())
7091     {
7092       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7093       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7094       throw INTERP_KERNEL::Exception(oss.str().c_str());
7095     }
7096   if(!arr)
7097     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7098   checkThatComponentsMatch(arr->getInfoOnComponents());
7099 }
7100
7101 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const throw(INTERP_KERNEL::Exception)
7102 {
7103   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7104   if(getInfo().size()!=compos.size())
7105     {
7106       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7107       oss << " number of components of element to append (" << compos.size() << ") !";
7108       throw INTERP_KERNEL::Exception(oss.str().c_str());
7109     }
7110   if(_infos!=compos)
7111     {
7112       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7113       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7114       oss << " But compo in input fields are : ";
7115       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7116       oss << " !";
7117       throw INTERP_KERNEL::Exception(oss.str().c_str());
7118     }
7119 }
7120
7121 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const throw(INTERP_KERNEL::Exception)
7122 {
7123   std::size_t sz=_infos.size();
7124   int j=0;
7125   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7126     {
7127       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7128       if(elt)
7129         if(elt->getInfo().size()!=sz)
7130           {
7131             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7132             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7133             throw INTERP_KERNEL::Exception(oss.str().c_str());
7134           }
7135     }
7136 }
7137
7138 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
7139 {
7140   if(!field)
7141     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7142   if(!_time_steps.empty())
7143     checkCoherencyOfTinyInfo(field,arr);
7144   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7145   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7146   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7147   copyTinyInfoFrom(field,arr);
7148   _time_steps.push_back(obj);
7149 }
7150
7151 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
7152 {
7153   if(!field)
7154     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7155   if(!_time_steps.empty())
7156     checkCoherencyOfTinyInfo(field,arr);
7157   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7158   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7159   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7160   copyTinyInfoFrom(field,arr);
7161   _time_steps.push_back(obj);
7162 }
7163
7164 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts) throw(INTERP_KERNEL::Exception)
7165 {
7166   int sz=(int)_time_steps.size();
7167   if(i<0 || i>=sz)
7168     {
7169       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7170       throw INTERP_KERNEL::Exception(oss.str().c_str());
7171     }
7172   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7173   if(tsPtr)
7174     {
7175       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7176         {
7177           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7178           throw INTERP_KERNEL::Exception(oss.str().c_str());
7179         }
7180     }
7181   _time_steps[i]=ts;
7182 }
7183
7184 //= MEDFileFieldMultiTSWithoutSDA
7185
7186 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, bool loadAll) throw(INTERP_KERNEL::Exception)
7187 {
7188   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7189 }
7190
7191 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7192 {
7193 }
7194
7195 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const char *fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7196 {
7197 }
7198
7199 /*!
7200  * \param [in] fieldId field id in C mode
7201  */
7202 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll) throw(INTERP_KERNEL::Exception)
7203 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7204 {
7205 }
7206 catch(INTERP_KERNEL::Exception& e)
7207   { throw e; }
7208
7209 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll) throw(INTERP_KERNEL::Exception)
7210 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7211 {
7212 }
7213 catch(INTERP_KERNEL::Exception& e)
7214 { throw e; }
7215
7216 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const throw(INTERP_KERNEL::Exception)
7217 {
7218   return new MEDFileField1TSWithoutSDA;
7219 }
7220
7221 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const throw(INTERP_KERNEL::Exception)
7222 {
7223   if(!f1ts)
7224     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7225   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7226   if(!f1tsC)
7227     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7228 }
7229
7230 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
7231 {
7232   return MEDFileField1TSWithoutSDA::TYPE_STR;
7233 }
7234
7235 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
7236 {
7237   return new MEDFileFieldMultiTSWithoutSDA(*this);
7238 }
7239
7240 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const throw(INTERP_KERNEL::Exception)
7241 {
7242   return new MEDFileFieldMultiTSWithoutSDA;
7243 }
7244
7245 /*!
7246  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7247  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7248  */
7249 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)
7250 {
7251   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7252   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7253   if(!myF1TSC)
7254     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7255   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7256 }
7257
7258 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const throw(INTERP_KERNEL::Exception)
7259 {
7260   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7261   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7262   int i=0;
7263   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7264     {
7265       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7266       if(eltToConv)
7267         {
7268           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7269           if(!eltToConvC)
7270             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7271           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7272           ret->setIteration(i,elt);
7273         }
7274     }
7275   return ret.retn();
7276 }
7277
7278 //= MEDFileAnyTypeFieldMultiTS
7279
7280 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7281 {
7282 }
7283
7284 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
7285 try:MEDFileFieldGlobsReal(fileName)
7286 {
7287   MEDFileUtilities::CheckFileForRead(fileName);
7288   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7289   _content=BuildContentFrom(fid,fileName,loadAll);
7290   loadGlobals(fid);
7291 }
7292 catch(INTERP_KERNEL::Exception& e)
7293   {
7294     throw e;
7295   }
7296
7297 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
7298 {
7299   med_field_type typcha;
7300   std::vector<std::string> infos;
7301   std::string dtunit;
7302   int i=-1;
7303   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7304   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7305   switch(typcha)
7306     {
7307     case MED_FLOAT64:
7308       {
7309         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll);
7310         break;
7311       }
7312     case MED_INT32:
7313       {
7314         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll);
7315         break;
7316       }
7317     default:
7318       {
7319         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] !";
7320         throw INTERP_KERNEL::Exception(oss.str().c_str());
7321       }
7322     }
7323   ret->setDtUnit(dtunit.c_str());
7324   return ret.retn();
7325 }
7326
7327 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
7328 {
7329   med_field_type typcha;
7330   //
7331   std::vector<std::string> infos;
7332   std::string dtunit,fieldName;
7333   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
7334   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7335   switch(typcha)
7336     {
7337     case MED_FLOAT64:
7338       {
7339         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll);
7340         break;
7341       }
7342     case MED_INT32:
7343       {
7344         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll);
7345         break;
7346       }
7347     default:
7348       {
7349         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] !";
7350         throw INTERP_KERNEL::Exception(oss.str().c_str());
7351       }
7352     }
7353   ret->setDtUnit(dtunit.c_str());
7354   return ret.retn();
7355 }
7356
7357 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const char *fileName) throw(INTERP_KERNEL::Exception)
7358 {
7359   if(!c)
7360     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
7361   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
7362     {
7363       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
7364       ret->setFileName(fileName);
7365       ret->_content=c;  c->incrRef();
7366       return ret.retn();
7367     }
7368   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
7369     {
7370       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
7371       ret->setFileName(fileName);
7372       ret->_content=c;  c->incrRef();
7373       return ret.retn();
7374     }
7375   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
7376 }
7377
7378 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
7379 try:MEDFileFieldGlobsReal(fileName)
7380 {
7381   MEDFileUtilities::CheckFileForRead(fileName);
7382   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7383   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
7384   loadGlobals(fid);
7385 }
7386 catch(INTERP_KERNEL::Exception& e)
7387   {
7388     throw e;
7389   }
7390
7391 //= MEDFileIntFieldMultiTSWithoutSDA
7392
7393 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, bool loadAll) throw(INTERP_KERNEL::Exception)
7394 {
7395   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7396 }
7397
7398 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
7399 {
7400 }
7401
7402 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const char *fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7403 {
7404 }
7405
7406 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll) throw(INTERP_KERNEL::Exception)
7407 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7408 {
7409 }
7410 catch(INTERP_KERNEL::Exception& e)
7411 { throw e; }
7412
7413 /*!
7414  * \param [in] fieldId field id in C mode
7415  */
7416 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll) throw(INTERP_KERNEL::Exception)
7417 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7418 {
7419 }
7420 catch(INTERP_KERNEL::Exception& e)
7421   { throw e; }
7422
7423 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const throw(INTERP_KERNEL::Exception)
7424 {
7425   return new MEDFileIntField1TSWithoutSDA;
7426 }
7427
7428 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const throw(INTERP_KERNEL::Exception)
7429 {
7430   if(!f1ts)
7431     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7432   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
7433   if(!f1tsC)
7434     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
7435 }
7436
7437 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
7438 {
7439   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
7440 }
7441
7442 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
7443 {
7444   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
7445 }
7446
7447 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const throw(INTERP_KERNEL::Exception)
7448 {
7449   return new MEDFileIntFieldMultiTSWithoutSDA;
7450 }
7451
7452 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const throw(INTERP_KERNEL::Exception)
7453 {
7454   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
7455   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7456   int i=0;
7457   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7458     {
7459       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7460       if(eltToConv)
7461         {
7462           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
7463           if(!eltToConvC)
7464             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
7465           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
7466           ret->setIteration(i,elt);
7467         }
7468     }
7469   return ret.retn();
7470 }
7471
7472 //= MEDFileAnyTypeFieldMultiTS
7473
7474 /*!
7475  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
7476  * that has been read from a specified MED file.
7477  *  \param [in] fileName - the name of the MED file to read.
7478  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7479  *          is to delete this field using decrRef() as it is no more needed.
7480  *  \throw If reading the file fails.
7481  */
7482 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
7483 {
7484   MEDFileUtilities::CheckFileForRead(fileName);
7485   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7486   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
7487   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7488   ret->loadGlobals(fid);
7489   return ret.retn();
7490 }
7491
7492 /*!
7493  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
7494  * that has been read from a specified MED file.
7495  *  \param [in] fileName - the name of the MED file to read.
7496  *  \param [in] fieldName - the name of the field to read.
7497  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7498  *          is to delete this field using decrRef() as it is no more needed.
7499  *  \throw If reading the file fails.
7500  *  \throw If there is no field named \a fieldName in the file.
7501  */
7502 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
7503 {
7504   MEDFileUtilities::CheckFileForRead(fileName);
7505   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7506   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName);
7507   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7508   ret->loadGlobals(fid);
7509   return ret.retn();
7510 }
7511
7512 /*!
7513  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7514  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7515  *
7516  * \warning this is a shallow copy constructor
7517  */
7518 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7519 {
7520   if(!shallowCopyOfContent)
7521     {
7522       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
7523       otherPtr->incrRef();
7524       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
7525     }
7526   else
7527     {
7528       _content=other.shallowCpy();
7529     }
7530 }
7531
7532 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() throw(INTERP_KERNEL::Exception)
7533 {
7534   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7535   if(!ret)
7536     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
7537   return ret;
7538 }
7539
7540 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const throw(INTERP_KERNEL::Exception)
7541 {
7542   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7543   if(!ret)
7544     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
7545   return ret;
7546 }
7547
7548 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
7549 {
7550   return contentNotNullBase()->getPflsReallyUsed2();
7551 }
7552
7553 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
7554 {
7555   return contentNotNullBase()->getLocsReallyUsed2();
7556 }
7557
7558 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
7559 {
7560   return contentNotNullBase()->getPflsReallyUsedMulti2();
7561 }
7562
7563 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
7564 {
7565   return contentNotNullBase()->getLocsReallyUsedMulti2();
7566 }
7567
7568 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7569 {
7570   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
7571 }
7572
7573 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7574 {
7575   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
7576 }
7577
7578 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
7579 {
7580   return contentNotNullBase()->getNumberOfTS();
7581 }
7582
7583 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
7584 {
7585   contentNotNullBase()->eraseEmptyTS();
7586 }
7587
7588 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
7589 {
7590   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
7591 }
7592
7593 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
7594 {
7595   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
7596 }
7597
7598 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
7599 {
7600   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
7601   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7602   ret->_content=c;
7603   return ret.retn();
7604 }
7605
7606 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
7607 {
7608   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
7609   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7610   ret->_content=c;
7611   return ret.retn();
7612 }
7613
7614 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
7615 {
7616   return contentNotNullBase()->getIterations();
7617 }
7618
7619 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts) throw(INTERP_KERNEL::Exception)
7620 {
7621   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
7622     pushBackTimeStep(*it);
7623 }
7624
7625 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts) throw(INTERP_KERNEL::Exception)
7626 {
7627   if(!f1ts)
7628     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
7629   checkCoherencyOfType(f1ts);
7630   f1ts->incrRef();
7631   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
7632   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
7633   c->incrRef();
7634   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
7635   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
7636     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
7637   _content->pushBackTimeStep(cSafe);
7638   appendGlobs(*f1ts,1e-12);
7639 }
7640
7641 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope() throw(INTERP_KERNEL::Exception)
7642 {
7643   contentNotNullBase()->synchronizeNameScope();
7644 }
7645
7646 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
7647 {
7648   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
7649 }
7650
7651 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
7652 {
7653   return contentNotNullBase()->getPosGivenTime(time,eps);
7654 }
7655
7656 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
7657 {
7658   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
7659 }
7660
7661 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
7662 {
7663   return contentNotNullBase()->getTypesOfFieldAvailable();
7664 }
7665
7666 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)
7667 {
7668   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
7669 }
7670
7671 std::string MEDFileAnyTypeFieldMultiTS::getName() const
7672 {
7673   return contentNotNullBase()->getName();
7674 }
7675
7676 void MEDFileAnyTypeFieldMultiTS::setName(const char *name)
7677 {
7678   contentNotNullBase()->setName(name);
7679 }
7680
7681 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const throw(INTERP_KERNEL::Exception)
7682 {
7683   return contentNotNullBase()->getDtUnit();
7684 }
7685
7686 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
7687 {
7688   contentNotNullBase()->setDtUnit(dtUnit);
7689 }
7690
7691 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7692 {
7693   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
7694 }
7695
7696 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
7697 {
7698   return contentNotNullBase()->getTimeSteps(ret1);
7699 }
7700
7701 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const throw(INTERP_KERNEL::Exception)
7702 {
7703   return contentNotNullBase()->getMeshName();
7704 }
7705
7706 void MEDFileAnyTypeFieldMultiTS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
7707 {
7708   contentNotNullBase()->setMeshName(newMeshName);
7709 }
7710
7711 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
7712 {
7713   return contentNotNullBase()->changeMeshNames(modifTab);
7714 }
7715
7716 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const throw(INTERP_KERNEL::Exception)
7717 {
7718   return contentNotNullBase()->getInfo();
7719 }
7720
7721 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
7722 {
7723   return contentNotNullBase()->setInfo(info);
7724 }
7725
7726 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const throw(INTERP_KERNEL::Exception)
7727 {
7728   const std::vector<std::string> ret=getInfo();
7729   return (int)ret.size();
7730 }
7731
7732 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
7733 {
7734   writeGlobals(fid,*this);
7735   contentNotNullBase()->writeLL(fid,*this);
7736 }
7737
7738 /*!
7739  * Writes \a this field into a MED file specified by its name.
7740  *  \param [in] fileName - the MED file name.
7741  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
7742  * - 2 - erase; an existing file is removed.
7743  * - 1 - append; same data should not be present in an existing file.
7744  * - 0 - overwrite; same data present in an existing file is overwritten.
7745  *  \throw If the field name is not set.
7746  *  \throw If no field data is set.
7747  *  \throw If \a mode == 1 and the same data is present in an existing file.
7748  */
7749 void MEDFileAnyTypeFieldMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
7750 {
7751   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
7752   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
7753   writeLL(fid);
7754 }
7755
7756 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
7757 {
7758   std::ostringstream oss;
7759   contentNotNullBase()->simpleRepr(0,oss,-1);
7760   simpleReprGlobs(oss);
7761   return oss.str();
7762 }
7763
7764 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySize() const
7765 {
7766   std::size_t ret=0;
7767   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)_content)
7768     ret+=_content->getHeapMemorySize();
7769   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
7770 }
7771
7772 /*!
7773  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
7774  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
7775  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
7776  */
7777 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const throw(INTERP_KERNEL::Exception)
7778 {
7779   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
7780   if(!content)
7781     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
7782   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
7783   std::size_t sz(contentsSplit.size());
7784   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
7785   for(std::size_t i=0;i<sz;i++)
7786     {
7787       ret[i]=shallowCpy();
7788       ret[i]->_content=contentsSplit[i];
7789     }
7790   return ret;
7791 }
7792
7793 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception)
7794 {
7795   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7796   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
7797     ret->_content=_content->deepCpy();
7798   ret->deepCpyGlobs(*this);
7799   return ret.retn();
7800 }
7801
7802 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
7803 {
7804   return _content;
7805 }
7806
7807 /*!
7808  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
7809  *  \param [in] iteration - the iteration number of a required time step.
7810  *  \param [in] order - the iteration order number of required time step.
7811  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
7812  *          delete this field using decrRef() as it is no more needed.
7813  *  \throw If there is no required time step in \a this field.
7814  */
7815 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
7816 {
7817   int pos=getPosOfTimeStep(iteration,order);
7818   return getTimeStepAtPos(pos);
7819 }
7820
7821 /*!
7822  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
7823  *  \param [in] time - the time of the time step of interest.
7824  *  \param [in] eps - a precision used to compare time values.
7825  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
7826  *          delete this field using decrRef() as it is no more needed.
7827  *  \throw If there is no required time step in \a this field.
7828  */
7829 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
7830 {
7831   int pos=getPosGivenTime(time,eps);
7832   return getTimeStepAtPos(pos);
7833 }
7834
7835 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator() throw(INTERP_KERNEL::Exception)
7836 {
7837   return new MEDFileAnyTypeFieldMultiTSIterator(this);
7838 }
7839
7840 //= MEDFileFieldMultiTS
7841
7842 /*!
7843  * Returns a new empty instance of MEDFileFieldMultiTS.
7844  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
7845  *          is to delete this field using decrRef() as it is no more needed.
7846  */
7847 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
7848 {
7849   return new MEDFileFieldMultiTS;
7850 }
7851
7852 /*!
7853  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
7854  * that has been read from a specified MED file.
7855  *  \param [in] fileName - the name of the MED file to read.
7856  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
7857  *          is to delete this field using decrRef() as it is no more needed.
7858  *  \throw If reading the file fails.
7859  */
7860 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
7861 {
7862   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll);
7863   ret->contentNotNull();//to check that content type matches with \a this type.
7864   return ret.retn();
7865 }
7866
7867 /*!
7868  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
7869  * that has been read from a specified MED file.
7870  *  \param [in] fileName - the name of the MED file to read.
7871  *  \param [in] fieldName - the name of the field to read.
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  *  \throw If reading the file fails.
7875  *  \throw If there is no field named \a fieldName in the file.
7876  */
7877 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
7878 {
7879   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll);
7880   ret->contentNotNull();//to check that content type matches with \a this type.
7881   return ret.retn();
7882 }
7883
7884 /*!
7885  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7886  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7887  *
7888  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
7889  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
7890  * \warning this is a shallow copy constructor
7891  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
7892  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
7893  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
7894  *          is to delete this field using decrRef() as it is no more needed.
7895  */
7896 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7897 {
7898   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
7899 }
7900
7901 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const throw(INTERP_KERNEL::Exception)
7902 {
7903   return new MEDFileFieldMultiTS(*this);
7904 }
7905
7906 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception)
7907 {
7908   if(!f1ts)
7909     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7910   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
7911   if(!f1tsC)
7912     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7913 }
7914
7915 /*!
7916  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
7917  * following the given input policy.
7918  *
7919  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
7920  *                            By default (true) the globals are deeply copied.
7921  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
7922  */
7923 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
7924 {
7925   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
7926   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
7927   if(content)
7928     {
7929       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
7930       if(!contc)
7931         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
7932       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
7933       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
7934     }
7935   else
7936     ret=MEDFileIntFieldMultiTS::New();
7937   if(deepCpyGlobs)
7938     ret->deepCpyGlobs(*this);
7939   else
7940     ret->shallowCpyGlobs(*this);
7941   return ret.retn();
7942 }
7943
7944 /*!
7945  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
7946  *  \param [in] pos - a time step id.
7947  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
7948  *          delete this field using decrRef() as it is no more needed.
7949  *  \throw If \a pos is not a valid time step id.
7950  */
7951 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
7952 {
7953   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
7954   if(!item)
7955     {
7956       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
7957       throw INTERP_KERNEL::Exception(oss.str().c_str());
7958     }
7959   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
7960   if(itemC)
7961     {
7962       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
7963       ret->shallowCpyGlobs(*this);
7964       return ret.retn();
7965     }
7966   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
7967   throw INTERP_KERNEL::Exception(oss.str().c_str());
7968 }
7969
7970 /*!
7971  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
7972  * mesh entities of a given dimension of the first mesh in MED file.
7973  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7974  *  \param [in] type - a spatial discretization of interest.
7975  *  \param [in] iteration - the iteration number of a required time step.
7976  *  \param [in] order - the iteration order number of required time step.
7977  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7978  *  \param [in] renumPol - specifies how to permute values of the result field according to
7979  *          the optional numbers of cells and nodes, if any. The valid values are
7980  *          - 0 - do not permute.
7981  *          - 1 - permute cells.
7982  *          - 2 - permute nodes.
7983  *          - 3 - permute cells and nodes.
7984  *
7985  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7986  *          caller is to delete this field using decrRef() as it is no more needed. 
7987  *  \throw If the MED file is not readable.
7988  *  \throw If there is no mesh in the MED file.
7989  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7990  *  \throw If no field values of the required parameters are available.
7991  */
7992 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
7993 {
7994   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
7995   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7996   if(!myF1TSC)
7997     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
7998   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
7999   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut,*contentNotNullBase());
8000   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8001   return ret.retn();
8002 }
8003
8004 /*!
8005  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8006  * the top level cells of the first mesh in MED file.
8007  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8008  *  \param [in] type - a spatial discretization of interest.
8009  *  \param [in] iteration - the iteration number of a required time step.
8010  *  \param [in] order - the iteration order number of required time step.
8011  *  \param [in] renumPol - specifies how to permute values of the result field according to
8012  *          the optional numbers of cells and nodes, if any. The valid values are
8013  *          - 0 - do not permute.
8014  *          - 1 - permute cells.
8015  *          - 2 - permute nodes.
8016  *          - 3 - permute cells and nodes.
8017  *
8018  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8019  *          caller is to delete this field using decrRef() as it is no more needed. 
8020  *  \throw If the MED file is not readable.
8021  *  \throw If there is no mesh in the MED file.
8022  *  \throw If no field values of the required parameters are available.
8023  */
8024 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const throw(INTERP_KERNEL::Exception)
8025 {
8026   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8027   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8028   if(!myF1TSC)
8029     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
8030   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8031   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,0,renumPol,this,arrOut,*contentNotNullBase());
8032   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8033   return ret.retn();
8034 }
8035
8036 /*!
8037  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8038  * a given support.
8039  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8040  *  \param [in] type - a spatial discretization of interest.
8041  *  \param [in] iteration - the iteration number of a required time step.
8042  *  \param [in] order - the iteration order number of required time step.
8043  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8044  *  \param [in] mesh - the supporting mesh.
8045  *  \param [in] renumPol - specifies how to permute values of the result field according to
8046  *          the optional numbers of cells and nodes, if any. The valid values are
8047  *          - 0 - do not permute.
8048  *          - 1 - permute cells.
8049  *          - 2 - permute nodes.
8050  *          - 3 - permute cells and nodes.
8051  *
8052  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8053  *          caller is to delete this field using decrRef() as it is no more needed. 
8054  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8055  *  \throw If no field of \a this is lying on \a mesh.
8056  *  \throw If no field values of the required parameters are available.
8057  */
8058 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
8059 {
8060   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8061   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8062   if(!myF1TSC)
8063     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8064   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8065   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
8066   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8067   return ret.retn();
8068 }
8069
8070 /*!
8071  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8072  * given support. 
8073  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8074  *  \param [in] type - a spatial discretization of the new field.
8075  *  \param [in] iteration - the iteration number of a required time step.
8076  *  \param [in] order - the iteration order number of required time step.
8077  *  \param [in] mesh - the supporting mesh.
8078  *  \param [in] renumPol - specifies how to permute values of the result field according to
8079  *          the optional numbers of cells and nodes, if any. The valid values are
8080  *          - 0 - do not permute.
8081  *          - 1 - permute cells.
8082  *          - 2 - permute nodes.
8083  *          - 3 - permute cells and nodes.
8084  *
8085  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8086  *          caller is to delete this field using decrRef() as it is no more needed. 
8087  *  \throw If no field of \a this is lying on \a mesh.
8088  *  \throw If no field values of the required parameters are available.
8089  */
8090 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
8091 {
8092   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8093   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8094   if(!myF1TSC)
8095     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8096   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8097   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
8098   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8099   return ret.retn();
8100 }
8101
8102 /*!
8103  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
8104  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8105  * This method is useful for MED2 file format when field on different mesh was autorized.
8106  */
8107 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
8108 {
8109   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8110   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8111   if(!myF1TSC)
8112     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
8113   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8114   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
8115   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8116   return ret.retn();
8117 }
8118
8119 /*!
8120  * Returns values and a profile of the field of a given type, of a given time step,
8121  * lying on a given support.
8122  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8123  *  \param [in] type - a spatial discretization of the field.
8124  *  \param [in] iteration - the iteration number of a required time step.
8125  *  \param [in] order - the iteration order number of required time step.
8126  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8127  *  \param [in] mesh - the supporting mesh.
8128  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8129  *          field of interest lies on. If the field lies on all entities of the given
8130  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8131  *          using decrRef() as it is no more needed.  
8132  *  \param [in] glob - the global data storing profiles and localization.
8133  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
8134  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8135  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8136  *  \throw If no field of \a this is lying on \a mesh.
8137  *  \throw If no field values of the required parameters are available.
8138  */
8139 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
8140 {
8141   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8142   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8143   if(!myF1TSC)
8144     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
8145   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8146   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
8147 }
8148
8149 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const throw(INTERP_KERNEL::Exception)
8150 {
8151   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8152   if(!pt)
8153     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
8154   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
8155   if(!ret)
8156     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 !");
8157   return ret;
8158 }
8159
8160  MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() throw(INTERP_KERNEL::Exception)
8161 {
8162   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8163   if(!pt)
8164     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
8165   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
8166   if(!ret)
8167     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 !");
8168   return ret;
8169 }
8170
8171 /*!
8172  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8173  * the given field is checked if its elements are sorted suitable for writing to MED file
8174  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8175  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8176  *  \param [in] field - the field to add to \a this.
8177  *  \throw If the name of \a field is empty.
8178  *  \throw If the data array of \a field is not set.
8179  *  \throw If existing time steps have different name or number of components than \a field.
8180  *  \throw If the underlying mesh of \a field has no name.
8181  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8182  */
8183 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
8184 {
8185   const DataArrayDouble *arr=0;
8186   if(field)
8187     arr=field->getArray();
8188   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
8189 }
8190
8191 /*!
8192  * Adds a MEDCouplingFieldDouble to \a this as another time step. Specified entities of
8193  * a given dimension of a given mesh are used as the support of the given field.
8194  * Elements of the given mesh must be sorted suitable for writing to MED file. 
8195  * Order of underlying mesh entities of the given field specified by \a profile parameter
8196  * is not prescribed; this method permutes field values to have them sorted by element
8197  * type as required for writing to MED file.  
8198  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8199  *  \param [in] field - the field to add to \a this.
8200  *  \param [in] mesh - the supporting mesh of \a field.
8201  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
8202  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8203  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8204  *  \throw If existing time steps have different name or number of components than \a field.
8205  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8206  *  \throw If the data array of \a field is not set.
8207  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8208  */
8209 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
8210 {
8211   const DataArrayDouble *arr=0;
8212   if(field)
8213     arr=field->getArray();
8214   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
8215 }
8216
8217 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
8218 {
8219   _content=new MEDFileFieldMultiTSWithoutSDA;
8220 }
8221
8222 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
8223 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
8224 {
8225 }
8226 catch(INTERP_KERNEL::Exception& e)
8227   { throw e; }
8228
8229 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
8230 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
8231 {
8232 }
8233 catch(INTERP_KERNEL::Exception& e)
8234   { throw e; }
8235
8236 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8237 {
8238 }
8239
8240 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)
8241 {
8242   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
8243 }
8244
8245 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
8246 {
8247   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8248 }
8249
8250 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)
8251 {
8252   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
8253 }
8254
8255 //= MEDFileAnyTypeFieldMultiTSIterator
8256
8257 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
8258 {
8259   if(fmts)
8260     {
8261       fmts->incrRef();
8262       _nb_iter=fmts->getNumberOfTS();
8263     }
8264 }
8265
8266 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
8267 {
8268 }
8269
8270 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt() throw(INTERP_KERNEL::Exception)
8271 {
8272   if(_iter_id<_nb_iter)
8273     {
8274       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
8275       if(fmts)
8276         return fmts->getTimeStepAtPos(_iter_id++);
8277       else
8278         return 0;
8279     }
8280   else
8281     return 0;
8282 }
8283
8284 //= MEDFileIntFieldMultiTS
8285
8286 /*!
8287  * Returns a new empty instance of MEDFileFieldMultiTS.
8288  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8289  *          is to delete this field using decrRef() as it is no more needed.
8290  */
8291 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
8292 {
8293   return new MEDFileIntFieldMultiTS;
8294 }
8295
8296 /*!
8297  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
8298  * that has been read from a specified MED file.
8299  *  \param [in] fileName - the name of the MED file to read.
8300  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8301  *          is to delete this field using decrRef() as it is no more needed.
8302  *  \throw If reading the file fails.
8303  */
8304 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
8305 {
8306   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll);
8307   ret->contentNotNull();//to check that content type matches with \a this type.
8308   return ret.retn();
8309 }
8310
8311 /*!
8312  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
8313  * that has been read from a specified MED file.
8314  *  \param [in] fileName - the name of the MED file to read.
8315  *  \param [in] fieldName - the name of the field to read.
8316  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8317  *          is to delete this field using decrRef() as it is no more needed.
8318  *  \throw If reading the file fails.
8319  *  \throw If there is no field named \a fieldName in the file.
8320  */
8321 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
8322 {
8323   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll);
8324   ret->contentNotNull();//to check that content type matches with \a this type.
8325   return ret.retn();
8326 }
8327
8328 /*!
8329  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8330  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8331  *
8332  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
8333  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8334  * \warning this is a shallow copy constructor
8335  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
8336  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8337  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8338  *          is to delete this field using decrRef() as it is no more needed.
8339  */
8340 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8341 {
8342   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
8343 }
8344
8345 /*!
8346  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
8347  * following the given input policy.
8348  *
8349  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8350  *                            By default (true) the globals are deeply copied.
8351  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
8352  */
8353 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
8354 {
8355   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
8356   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8357   if(content)
8358     {
8359       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
8360       if(!contc)
8361         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
8362       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
8363       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
8364     }
8365   else
8366     ret=MEDFileFieldMultiTS::New();
8367   if(deepCpyGlobs)
8368     ret->deepCpyGlobs(*this);
8369   else
8370     ret->shallowCpyGlobs(*this);
8371   return ret.retn();
8372 }
8373
8374 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const throw(INTERP_KERNEL::Exception)
8375 {
8376   return new MEDFileIntFieldMultiTS(*this);
8377 }
8378
8379 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception)
8380 {
8381   if(!f1ts)
8382     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8383   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
8384   if(!f1tsC)
8385     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8386 }
8387
8388 /*!
8389  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8390  * mesh entities of a given dimension of the first mesh in MED file.
8391  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8392  *  \param [in] type - a spatial discretization of interest.
8393  *  \param [in] iteration - the iteration number of a required time step.
8394  *  \param [in] order - the iteration order number of required time step.
8395  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8396  *  \param [out] arrOut - the DataArrayInt containing values of field.
8397  *  \param [in] renumPol - specifies how to permute values of the result field according to
8398  *          the optional numbers of cells and nodes, if any. The valid values are
8399  *          - 0 - do not permute.
8400  *          - 1 - permute cells.
8401  *          - 2 - permute nodes.
8402  *          - 3 - permute cells and nodes.
8403  *
8404  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8405  *          caller is to delete this field using decrRef() as it is no more needed. 
8406  *  \throw If the MED file is not readable.
8407  *  \throw If there is no mesh in the MED file.
8408  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8409  *  \throw If no field values of the required parameters are available.
8410  */
8411 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8412 {
8413   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8414   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8415   if(!myF1TSC)
8416     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
8417   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8418   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arr,*contentNotNullBase());
8419   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8420   return ret.retn();
8421 }
8422
8423 /*!
8424  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8425  * the top level cells of the first mesh in MED file.
8426  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8427  *  \param [in] type - a spatial discretization of interest.
8428  *  \param [in] iteration - the iteration number of a required time step.
8429  *  \param [in] order - the iteration order number of required time step.
8430  *  \param [out] arrOut - the DataArrayInt containing values of field.
8431  *  \param [in] renumPol - specifies how to permute values of the result field according to
8432  *          the optional numbers of cells and nodes, if any. The valid values are
8433  *          - 0 - do not permute.
8434  *          - 1 - permute cells.
8435  *          - 2 - permute nodes.
8436  *          - 3 - permute cells and nodes.
8437  *
8438  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8439  *          caller is to delete this field using decrRef() as it is no more needed. 
8440  *  \throw If the MED file is not readable.
8441  *  \throw If there is no mesh in the MED file.
8442  *  \throw If no field values of the required parameters are available.
8443  */
8444 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8445 {
8446   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8447   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8448   if(!myF1TSC)
8449     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
8450   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8451   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,0,renumPol,this,arr,*contentNotNullBase());
8452   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8453   return ret.retn();
8454 }
8455
8456 /*!
8457  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8458  * a given support.
8459  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8460  *  \param [in] type - a spatial discretization of interest.
8461  *  \param [in] iteration - the iteration number of a required time step.
8462  *  \param [in] order - the iteration order number of required time step.
8463  *  \param [out] arrOut - the DataArrayInt containing values of field.
8464  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8465  *  \param [in] mesh - the supporting mesh.
8466  *  \param [in] renumPol - specifies how to permute values of the result field according to
8467  *          the optional numbers of cells and nodes, if any. The valid values are
8468  *          - 0 - do not permute.
8469  *          - 1 - permute cells.
8470  *          - 2 - permute nodes.
8471  *          - 3 - permute cells and nodes.
8472  *
8473  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8474  *          caller is to delete this field using decrRef() as it is no more needed. 
8475  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8476  *  \throw If no field of \a this is lying on \a mesh.
8477  *  \throw If no field values of the required parameters are available.
8478  */
8479 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8480 {
8481   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8482   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8483   if(!myF1TSC)
8484     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8485   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8486   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
8487   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8488   return ret.retn();
8489 }
8490
8491 /*!
8492  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8493  * given support. 
8494  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8495  *  \param [in] type - a spatial discretization of the new field.
8496  *  \param [in] iteration - the iteration number of a required time step.
8497  *  \param [in] order - the iteration order number of required time step.
8498  *  \param [in] mesh - the supporting mesh.
8499  *  \param [out] arrOut - the DataArrayInt containing values of field.
8500  *  \param [in] renumPol - specifies how to permute values of the result field according to
8501  *          the optional numbers of cells and nodes, if any. The valid values are
8502  *          - 0 - do not permute.
8503  *          - 1 - permute cells.
8504  *          - 2 - permute nodes.
8505  *          - 3 - permute cells and nodes.
8506  *
8507  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8508  *          caller is to delete this field using decrRef() as it is no more needed. 
8509  *  \throw If no field of \a this is lying on \a mesh.
8510  *  \throw If no field values of the required parameters are available.
8511  */
8512 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8513 {
8514   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8515   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8516   if(!myF1TSC)
8517     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8518   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8519   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
8520   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8521   return ret.retn();
8522 }
8523
8524 /*!
8525  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
8526  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8527  * This method is useful for MED2 file format when field on different mesh was autorized.
8528  */
8529 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const char *mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8530 {
8531   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8532   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8533   if(!myF1TSC)
8534     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8535   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8536   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
8537   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8538   return ret.retn();
8539 }
8540
8541 /*!
8542  * Returns values and a profile of the field of a given type, of a given time step,
8543  * lying on a given support.
8544  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8545  *  \param [in] type - a spatial discretization of the field.
8546  *  \param [in] iteration - the iteration number of a required time step.
8547  *  \param [in] order - the iteration order number of required time step.
8548  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8549  *  \param [in] mesh - the supporting mesh.
8550  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8551  *          field of interest lies on. If the field lies on all entities of the given
8552  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8553  *          using decrRef() as it is no more needed.  
8554  *  \param [in] glob - the global data storing profiles and localization.
8555  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
8556  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8557  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8558  *  \throw If no field of \a this is lying on \a mesh.
8559  *  \throw If no field values of the required parameters are available.
8560  */
8561 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
8562 {
8563   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8564   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8565   if(!myF1TSC)
8566     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
8567   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8568   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
8569 }
8570
8571 /*!
8572  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
8573  *  \param [in] pos - a time step id.
8574  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
8575  *          delete this field using decrRef() as it is no more needed.
8576  *  \throw If \a pos is not a valid time step id.
8577  */
8578 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
8579 {
8580   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8581   if(!item)
8582     {
8583       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8584       throw INTERP_KERNEL::Exception(oss.str().c_str());
8585     }
8586   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
8587   if(itemC)
8588     {
8589       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
8590       ret->shallowCpyGlobs(*this);
8591       return ret.retn();
8592     }
8593   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
8594   throw INTERP_KERNEL::Exception(oss.str().c_str());
8595 }
8596
8597 /*!
8598  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8599  * the given field is checked if its elements are sorted suitable for writing to MED file
8600  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8601  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8602  *  \param [in] field - the field to add to \a this.
8603  *  \throw If the name of \a field is empty.
8604  *  \throw If the data array of \a field is not set.
8605  *  \throw If existing time steps have different name or number of components than \a field.
8606  *  \throw If the underlying mesh of \a field has no name.
8607  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8608  */
8609 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception)
8610 {
8611   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
8612 }
8613
8614 /*!
8615  * Adds a MEDCouplingFieldDouble to \a this as another time step. Specified entities of
8616  * a given dimension of a given mesh are used as the support of the given field.
8617  * Elements of the given mesh must be sorted suitable for writing to MED file. 
8618  * Order of underlying mesh entities of the given field specified by \a profile parameter
8619  * is not prescribed; this method permutes field values to have them sorted by element
8620  * type as required for writing to MED file.  
8621  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8622  *  \param [in] field - the field to add to \a this.
8623  *  \param [in] mesh - the supporting mesh of \a field.
8624  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
8625  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8626  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8627  *  \throw If existing time steps have different name or number of components than \a field.
8628  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8629  *  \throw If the data array of \a field is not set.
8630  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8631  */
8632 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
8633 {
8634   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
8635 }
8636
8637 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const throw(INTERP_KERNEL::Exception)
8638 {
8639   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8640   if(!pt)
8641     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
8642   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
8643   if(!ret)
8644     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 !");
8645   return ret;
8646 }
8647
8648  MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() throw(INTERP_KERNEL::Exception)
8649 {
8650   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8651   if(!pt)
8652     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
8653   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
8654   if(!ret)
8655     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 !");
8656   return ret;
8657 }
8658
8659 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
8660 {
8661   _content=new MEDFileIntFieldMultiTSWithoutSDA;
8662 }
8663
8664 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8665 {
8666 }
8667
8668 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
8669 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
8670 {
8671 }
8672 catch(INTERP_KERNEL::Exception& e)
8673   { throw e; }
8674
8675 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
8676 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
8677 {
8678 }
8679 catch(INTERP_KERNEL::Exception& e)
8680   { throw e; }
8681
8682 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
8683 {
8684   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8685 }
8686
8687 //= MEDFileFields
8688
8689 MEDFileFields *MEDFileFields::New()
8690 {
8691   return new MEDFileFields;
8692 }
8693
8694 MEDFileFields *MEDFileFields::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
8695 {
8696   return new MEDFileFields(fileName,loadAll);
8697 }
8698
8699 std::size_t MEDFileFields::getHeapMemorySize() const
8700 {
8701   std::size_t ret=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
8702   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8703     if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it)
8704       ret+=(*it)->getHeapMemorySize();
8705   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
8706 }
8707
8708 MEDFileFields *MEDFileFields::deepCpy() const throw(INTERP_KERNEL::Exception)
8709 {
8710   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
8711   std::size_t i=0;
8712   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8713     {
8714       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
8715         ret->_fields[i]=(*it)->deepCpy();
8716     }
8717   ret->deepCpyGlobs(*this);
8718   return ret.retn();
8719 }
8720
8721 MEDFileFields *MEDFileFields::shallowCpy() const throw(INTERP_KERNEL::Exception)
8722 {
8723   return new MEDFileFields(*this);
8724 }
8725
8726 /*!
8727  * 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
8728  * 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.
8729  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
8730  *
8731  * \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.
8732  * \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.
8733  * 
8734  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
8735  */
8736 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const throw(INTERP_KERNEL::Exception)
8737 {
8738   std::set< std::pair<int,int> > s;
8739   bool firstShot=true;
8740   areThereSomeForgottenTS=false;
8741   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8742     {
8743       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
8744         continue;
8745       std::vector< std::pair<int,int> > v=(*it)->getIterations();
8746       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
8747       if(firstShot)
8748         { s=s1; firstShot=false; }
8749       else
8750         {
8751           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
8752           if(s!=s2)
8753             areThereSomeForgottenTS=true;
8754           s=s2;
8755         }
8756     }
8757   std::vector< std::pair<int,int> > ret;
8758   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
8759   return ret;
8760 }
8761
8762 int MEDFileFields::getNumberOfFields() const
8763 {
8764   return _fields.size();
8765 }
8766
8767 std::vector<std::string> MEDFileFields::getFieldsNames() const throw(INTERP_KERNEL::Exception)
8768 {
8769   std::vector<std::string> ret(_fields.size());
8770   int i=0;
8771   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8772     {
8773       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
8774       if(f)
8775         {
8776           ret[i]=f->getName();
8777         }
8778       else
8779         {
8780           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
8781           throw INTERP_KERNEL::Exception(oss.str().c_str());
8782         }
8783     }
8784   return ret;
8785 }
8786
8787 std::vector<std::string> MEDFileFields::getMeshesNames() const throw(INTERP_KERNEL::Exception)
8788 {
8789   std::vector<std::string> ret;
8790   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8791     {
8792       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
8793       if(cur)
8794         ret.push_back(cur->getMeshName());
8795     }
8796   return ret;
8797 }
8798
8799 std::string MEDFileFields::simpleRepr() const
8800 {
8801   std::ostringstream oss;
8802   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
8803   simpleRepr(0,oss);
8804   return oss.str();
8805 }
8806
8807 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
8808 {
8809   int nbOfFields=getNumberOfFields();
8810   std::string startLine(bkOffset,' ');
8811   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
8812   int i=0;
8813   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8814     {
8815       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
8816       if(cur)
8817         {
8818           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
8819         }
8820       else
8821         {
8822           oss << startLine << "  - not defined !" << std::endl;
8823         }
8824     }
8825   i=0;
8826   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8827     {
8828       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
8829       std::string chapter(17,'0'+i);
8830       oss << startLine << chapter << std::endl;
8831       if(cur)
8832         {
8833           cur->simpleRepr(bkOffset+2,oss,i);
8834         }
8835       else
8836         {
8837           oss << startLine << "  - not defined !" << std::endl;
8838         }
8839       oss << startLine << chapter << std::endl;
8840     }
8841   simpleReprGlobs(oss);
8842 }
8843
8844 MEDFileFields::MEDFileFields()
8845 {
8846 }
8847
8848 MEDFileFields::MEDFileFields(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
8849 try:MEDFileFieldGlobsReal(fileName)
8850   {
8851     MEDFileUtilities::CheckFileForRead(fileName);
8852     MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
8853     int nbFields=MEDnField(fid);
8854     _fields.resize(nbFields);
8855     med_field_type typcha;
8856     for(int i=0;i<nbFields;i++)
8857       {
8858         std::vector<std::string> infos;
8859         std::string fieldName,dtunit;
8860         int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit);
8861         switch(typcha)
8862           {
8863           case MED_FLOAT64:
8864             {
8865               _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
8866               break;
8867             }
8868           case MED_INT32:
8869             {
8870               _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
8871               break;
8872             }
8873           default:
8874             {
8875               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] !";
8876               throw INTERP_KERNEL::Exception(oss.str().c_str());
8877             }
8878           }
8879       }
8880     loadAllGlobals(fid);
8881   }
8882 catch(INTERP_KERNEL::Exception& e)
8883   {
8884     throw e;
8885   }
8886
8887 void MEDFileFields::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
8888 {
8889   int i=0;
8890   writeGlobals(fid,*this);
8891   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8892     {
8893       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
8894       if(!elt)
8895         {
8896           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
8897           throw INTERP_KERNEL::Exception(oss.str().c_str());
8898         }
8899       elt->writeLL(fid,*this);
8900     }
8901 }
8902
8903 void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
8904 {
8905   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8906   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
8907   writeLL(fid);
8908 }
8909
8910 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
8911 {
8912   std::vector<std::string> ret;
8913   std::set<std::string> ret2;
8914   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8915     {
8916       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
8917       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8918         if(ret2.find(*it2)==ret2.end())
8919           {
8920             ret.push_back(*it2);
8921             ret2.insert(*it2);
8922           }
8923     }
8924   return ret;
8925 }
8926
8927 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
8928 {
8929   std::vector<std::string> ret;
8930   std::set<std::string> ret2;
8931   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8932     {
8933       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8934       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8935         if(ret2.find(*it2)==ret2.end())
8936           {
8937             ret.push_back(*it2);
8938             ret2.insert(*it2);
8939           }
8940     }
8941   return ret;
8942 }
8943
8944 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
8945 {
8946   std::vector<std::string> ret;
8947   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8948     {
8949       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
8950       ret.insert(ret.end(),tmp.begin(),tmp.end());
8951     }
8952   return ret;
8953 }
8954
8955 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
8956 {
8957   std::vector<std::string> ret;
8958   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8959     {
8960       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8961       ret.insert(ret.end(),tmp.begin(),tmp.end());
8962     }
8963   return ret;
8964 }
8965
8966 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
8967 {
8968   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
8969     (*it)->changePflsRefsNamesGen2(mapOfModif);
8970 }
8971
8972 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
8973 {
8974   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
8975     (*it)->changeLocsRefsNamesGen2(mapOfModif);
8976 }
8977
8978 void MEDFileFields::resize(int newSize) throw(INTERP_KERNEL::Exception)
8979 {
8980   _fields.resize(newSize);
8981 }
8982
8983 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields) throw(INTERP_KERNEL::Exception)
8984 {
8985   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
8986     pushField(*it);
8987 }
8988
8989 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
8990 {
8991   if(!field)
8992     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
8993   _fields.push_back(field->getContent());
8994   appendGlobs(*field,1e-12);
8995 }
8996
8997 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
8998 {
8999   if(!field)
9000     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9001   if(i>=(int)_fields.size())
9002     _fields.resize(i+1);
9003   _fields[i]=field->getContent();
9004   appendGlobs(*field,1e-12);
9005 }
9006
9007 void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception)
9008 {
9009   destroyFieldsAtPos(&i,&i+1);
9010 }
9011
9012 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
9013 {
9014   std::vector<bool> b(_fields.size(),true);
9015   for(const int *i=startIds;i!=endIds;i++)
9016     {
9017       if(*i<0 || *i>=(int)_fields.size())
9018         {
9019           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9020           throw INTERP_KERNEL::Exception(oss.str().c_str());
9021         }
9022       b[*i]=false;
9023     }
9024   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9025   std::size_t j=0;
9026   for(std::size_t i=0;i<_fields.size();i++)
9027     if(b[i])
9028       fields[j++]=_fields[i];
9029   _fields=fields;
9030 }
9031
9032 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
9033 {
9034   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9035   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
9036   std::vector<bool> b(_fields.size(),true);
9037   int k=bg;
9038   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9039     {
9040       if(k<0 || k>=(int)_fields.size())
9041         {
9042           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9043           throw INTERP_KERNEL::Exception(oss.str().c_str());
9044         }
9045       b[k]=false;
9046     }
9047   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9048   std::size_t j=0;
9049   for(std::size_t i=0;i<_fields.size();i++)
9050     if(b[i])
9051       fields[j++]=_fields[i];
9052   _fields=fields;
9053 }
9054
9055 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) 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 *cur(*it);
9061       if(cur)
9062         ret=cur->changeMeshNames(modifTab) || ret;
9063     }
9064   return ret;
9065 }
9066
9067 /*!
9068  * \param [in] meshName the name of the mesh that will be renumbered.
9069  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9070  *             This code corresponds to the distribution of types in the corresponding mesh.
9071  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9072  * \param [in] renumO2N the old to new renumber array.
9073  * \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 
9074  *         field in \a this.
9075  */
9076 bool MEDFileFields::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N) throw(INTERP_KERNEL::Exception)
9077 {
9078   bool ret=false;
9079   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9080     {
9081       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9082       if(fmts)
9083         {
9084           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9085         }
9086     }
9087   return ret;
9088 }
9089
9090 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception)
9091 {
9092   if(i<0 || i>=(int)_fields.size())
9093     {
9094       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9095       throw INTERP_KERNEL::Exception(oss.str().c_str());
9096     }
9097   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9098   if(!fmts)
9099     return 0;
9100   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
9101   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
9102   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
9103   if(fmtsC)
9104     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9105   else if(fmtsC2)
9106     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9107   else
9108     {
9109       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
9110       throw INTERP_KERNEL::Exception(oss.str().c_str());
9111     }
9112   ret->shallowCpyGlobs(*this);
9113   return ret.retn();
9114 }
9115
9116 /*!
9117  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9118  * This method is accessible in python using __getitem__ with a list in input.
9119  * \return a new object that the caller should deal with.
9120  */
9121 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
9122 {
9123   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9124   std::size_t sz=std::distance(startIds,endIds);
9125   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9126   int j=0;
9127   for(const int *i=startIds;i!=endIds;i++,j++)
9128     {
9129       if(*i<0 || *i>=(int)_fields.size())
9130         {
9131           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9132           throw INTERP_KERNEL::Exception(oss.str().c_str());
9133         }
9134       fields[j]=_fields[*i];
9135     }
9136   ret->_fields=fields;
9137   return ret.retn();
9138 }
9139
9140 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
9141 {
9142   return getFieldAtPos(getPosFromFieldName(fieldName));
9143 }
9144
9145 /*!
9146  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9147  * This method can be seen as a filter applied on \a this, that returns an object containing
9148  * 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
9149  * shallow copied from \a this.
9150  * 
9151  * \param [in] meshName - the name of the mesh on w
9152  * \return a new object that the caller should deal with.
9153  */
9154 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const char *meshName) const throw(INTERP_KERNEL::Exception)
9155 {
9156   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9157   ret->shallowCpyOnlyUsedGlobs(*this);
9158   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9159     {
9160       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9161       if(!cur)
9162         continue;
9163       if(cur->getMeshName()==meshName)
9164         {
9165           cur->incrRef();
9166           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
9167           ret->_fields.push_back(cur2);
9168         }
9169     }
9170   return ret.retn();
9171 }
9172
9173 /*!
9174  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
9175  * Input time steps are specified using a pair of integer (iteration, order).
9176  * 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,
9177  * but for each multitimestep only the time steps in \a timeSteps are kept.
9178  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
9179  * 
9180  * The returned object points to shallow copy of elements in \a this.
9181  * 
9182  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
9183  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
9184  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9185  */
9186 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
9187 {
9188   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9189   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9190     {
9191       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9192       if(!cur)
9193         continue;
9194       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
9195       ret->_fields.push_back(elt);
9196     }
9197   ret->shallowCpyOnlyUsedGlobs(*this);
9198   return ret.retn();
9199 }
9200
9201 /*!
9202  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
9203  */
9204 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
9205 {
9206   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9207   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9208     {
9209       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9210       if(!cur)
9211         continue;
9212       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
9213       if(elt->getNumberOfTS()!=0)
9214         ret->_fields.push_back(elt);
9215     }
9216   ret->shallowCpyOnlyUsedGlobs(*this);
9217   return ret.retn();
9218 }
9219
9220 MEDFileFieldsIterator *MEDFileFields::iterator() throw(INTERP_KERNEL::Exception)
9221 {
9222   return new MEDFileFieldsIterator(this);
9223 }
9224
9225 int MEDFileFields::getPosFromFieldName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
9226 {
9227   std::string tmp(fieldName);
9228   std::vector<std::string> poss;
9229   for(std::size_t i=0;i<_fields.size();i++)
9230     {
9231       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
9232       if(f)
9233         {
9234           std::string fname(f->getName());
9235           if(tmp==fname)
9236             return i;
9237           else
9238             poss.push_back(fname);
9239         }
9240     }
9241   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
9242   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
9243   oss << " !";
9244   throw INTERP_KERNEL::Exception(oss.str().c_str());
9245 }
9246
9247 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
9248 {
9249   if(fs)
9250     {
9251       fs->incrRef();
9252       _nb_iter=fs->getNumberOfFields();
9253     }
9254 }
9255
9256 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
9257 {
9258 }
9259
9260 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
9261 {
9262   if(_iter_id<_nb_iter)
9263     {
9264       MEDFileFields *fs(_fs);
9265       if(fs)
9266         return fs->getFieldAtPos(_iter_id++);
9267       else
9268         return 0;
9269     }
9270   else
9271     return 0;
9272 }