Salome HOME
For the moment desactivate it !
[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   if(_start>_end)
486     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
487   if(_start==_end)
488     return ;
489   DataArray *arr=getOrCreateAndGetArray();//arr is not null due to the spec of getOrCreateAndGetArray
490   if(_start<0 || _start>=arr->getNumberOfTuples())
491     {
492       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
493       throw INTERP_KERNEL::Exception(oss.str().c_str());
494     }
495   if(_end<0 || _end>arr->getNumberOfTuples())
496     {
497       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
498       throw INTERP_KERNEL::Exception(oss.str().c_str());
499     }
500   med_int tmp1,nbi;
501   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
502   med_int nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
503   int nbOfCompo=arr->getNumberOfComponents();
504   if(_end-_start!=nbValsInFile*nbi)
505     {
506       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
507       throw INTERP_KERNEL::Exception(oss.str().c_str());
508     }
509   DataArrayDouble *arrD=dynamic_cast<DataArrayDouble *>(arr);
510   if(arrD)
511     {
512       double *startFeeding=arrD->getPointer()+_start*nbOfCompo;
513       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
514                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
515       return ;
516     }
517   DataArrayInt *arrI=dynamic_cast<DataArrayInt *>(arr);
518   if(arrI)
519     {
520       int *startFeeding=arrI->getPointer()+_start*nbOfCompo;
521       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
522                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
523       return ;
524     }
525   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
526 }
527
528 /*!
529  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
530  */
531 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart) throw(INTERP_KERNEL::Exception)
532 {
533   int delta=_end-_start;
534   _start=newValueOfStart;
535   _end=_start+delta;
536 }
537
538 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
539 {
540   return _father->getIteration();
541 }
542
543 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
544 {
545   return _father->getOrder();
546 }
547
548 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
549 {
550   return _father->getTime();
551 }
552
553 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
554 {
555   return _father->getMeshName();
556 }
557
558 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
559 {
560   const char startLine[]="    ## ";
561   std::string startLine2(bkOffset,' ');
562   startLine2+=startLine;
563   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
564   oss << startLine2 << "Localization #" << id << "." << std::endl;
565   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
566   delete tmp;
567   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
568   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
569   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
570 }
571
572 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
573 {
574   return _type;
575 }
576
577 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
578 {
579   types.insert(_type);
580 }
581
582 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
583 {
584   _type=newType;
585 }
586
587 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
588 {
589   return _father->getGeoType();
590 }
591
592 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
593 {
594   return _father->getNumberOfComponents();
595 }
596
597 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
598 {
599   return _end-_start;
600 }
601
602 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
603 {
604   return _father->getOrCreateAndGetArray();
605 }
606
607 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
608 {
609   const MEDFileFieldPerMeshPerType *fath=_father;
610   return fath->getOrCreateAndGetArray();
611 }
612
613 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
614 {
615   return _father->getInfo();
616 }
617
618 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
619 {
620   return _profile;
621 }
622
623 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const char *newPflName)
624 {
625   _profile=newPflName;
626 }
627
628 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
629 {
630   return _localization;
631 }
632
633 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const char *newLocName)
634 {
635   _localization=newLocName;
636 }
637
638 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
639 {
640   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
641     {
642       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
643         {
644           _profile=(*it2).second;
645           return;
646         }
647     }
648 }
649
650 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
651 {
652   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
653     {
654       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
655         {
656           _localization=(*it2).second;
657           return;
658         }
659     }
660 }
661
662 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
663 {
664   if(type!=_type)
665     return ;
666   dads.push_back(std::pair<int,int>(_start,_end));
667   geoTypes.push_back(getGeoType());
668   if(_profile.empty())
669     pfls.push_back(0);
670   else
671     {
672       pfls.push_back(glob->getProfile(_profile.c_str()));
673     }
674   if(_localization.empty())
675     locs.push_back(-1);
676   else
677     {
678       locs.push_back(glob->getLocalizationId(_localization.c_str()));
679     }
680 }
681
682 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
683 {
684   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));
685   startEntryId++;
686 }
687
688 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
689 {
690   TypeOfField type=getType();
691   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
692   med_geometry_type mgeoti;
693   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
694   const DataArray *arr=getOrCreateAndGetArray();
695   if(!arr)
696     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
697   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
698   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
699   const unsigned char *locToWrite=0;
700   if(arrD)
701     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
702   else if(arrI)
703     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
704   else
705     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
706   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
707                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
708                              locToWrite);
709 }
710
711 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const throw(INTERP_KERNEL::Exception)
712 {
713   type=_type;
714   pfl=_profile;
715   loc=_localization;
716   dad.first=_start; dad.second=_end;
717 }
718
719 /*!
720  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
721  *             This code corresponds to the distribution of types in the corresponding mesh.
722  * \param [out] ptToFill memory zone where the output will be stored.
723  * \return the size of data pushed into output param \a ptToFill
724  */
725 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const throw(INTERP_KERNEL::Exception)
726 {
727   _loc_id=offset;
728   std::ostringstream oss;
729   std::size_t nbOfType=codeOfMesh.size()/3;
730   int found=-1;
731   for(std::size_t i=0;i<nbOfType && found==-1;i++)
732     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
733       found=(int)i;
734   if(found==-1)
735     {
736       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
737       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
738       throw INTERP_KERNEL::Exception(oss.str().c_str());
739     }
740   int *work=ptToFill;
741   if(_profile.empty())
742     {
743       if(_nval!=codeOfMesh[3*found+1])
744         {
745           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
746           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
747           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
748           throw INTERP_KERNEL::Exception(oss.str().c_str());
749         }
750       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
751         *work++=ii;
752     }
753   else
754     {
755       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
756       if(pfl->getNumberOfTuples()!=_nval)
757         {
758           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
759           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
760           oss << _nval;
761           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
762           throw INTERP_KERNEL::Exception(oss.str().c_str());
763         }
764       int offset2=codeOfMesh[3*found+2];
765       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
766         {
767           if(*pflId<codeOfMesh[3*found+1])
768             *work++=offset2+*pflId;
769         }
770     }
771   return _nval;
772 }
773
774 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const throw(INTERP_KERNEL::Exception)
775 {
776   for(int i=_start;i<_end;i++)
777     *ptToFill++=i;
778   return _end-_start;
779 }
780
781 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId) throw(INTERP_KERNEL::Exception)
782 {
783   switch(type)
784     {
785     case ON_CELLS:
786       return -2;
787     case ON_GAUSS_NE:
788       return -1;
789     case ON_GAUSS_PT:
790       return locId;
791     default:
792       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
793     }
794 }
795
796 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
797 {
798   int id=0;
799   std::map<std::pair<std::string,TypeOfField>,int> m;
800   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
801   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
802     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
803       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
804   ret.resize(id);
805   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
806     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
807   return ret;
808 }
809
810 /*!
811  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
812  * 
813  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
814  * \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.
815  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
816  * \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)
817  * \param [in,out] glob if necessary by the method, new profiles can be added to it
818  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
819  * \param [out] result All new entries will be appended on it.
820  * \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 !)
821  */
822 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
823                                                        const DataArrayInt *explicitIdsInMesh,
824                                                        const std::vector<int>& newCode,
825                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
826                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
827 {
828   if(entriesOnSameDisc.empty())
829     return false;
830   TypeOfField type=entriesOnSameDisc[0]->getType();
831   int szEntities=0,szTuples=0;
832   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
833     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
834   int nbi=szTuples/szEntities;
835   if(szTuples%szEntities!=0)
836     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
837   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
838   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
839   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
840   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
841   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
842   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
843   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
844   int id=0;
845   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
846     {
847       int startOfEltIdOfChunk=(*it)->_start;
848       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
849       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
850       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
851       //
852       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
853       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
854       //
855       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
856       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
857     }
858   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
859   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
860   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
861   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
862   //
863   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
864   //
865   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
866   arrPart->renumberInPlace(renumTupleIds->begin());
867   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
868   bool ret=false;
869   const int *idIt=diffVals->begin();
870   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
871   int offset2=0;
872   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
873     {
874       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
875       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
876       int nbEntityElts=subIds->getNumberOfTuples();
877       bool ret2;
878       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
879         NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
880                                     offset+offset2,
881                                     li,glob,ret2);
882       ret=ret || ret2;
883       result.push_back(eltToAdd);
884       offset2+=nbEntityElts*nbi;
885     }
886   ret=ret || li.empty();
887   return ret;
888 }
889
890 /*!
891  * \param [in] typeF type of field of new chunk
892  * \param [in] geoType the geometric type of the chunk
893  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
894  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
895  * \param [in] nbi number of integration points
896  * \param [in] offset The offset in the **global array of data**.
897  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
898  *                 to the new chunk to create.
899  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
900  * \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
901  *              and corresponding entry erased from \a entriesOnSameDisc.
902  * \return a newly allocated chunk
903  */
904 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
905                                                                                                   bool isPfl, int nbi, int offset,
906                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
907                                                                                                   MEDFileFieldGlobsReal& glob,
908                                                                                                   bool &notInExisting) throw(INTERP_KERNEL::Exception)
909 {
910   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
911   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
912   for(;it!=entriesOnSameDisc.end();it++)
913     {
914       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
915         {
916           if(!isPfl)
917             {
918               if((*it)->_profile.empty())
919                 break;
920               else
921                 if(!(*it)->_profile.empty())
922                   {
923                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
924                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
925                       break;
926                   }
927             }
928         }
929     }
930   if(it==entriesOnSameDisc.end())
931     {
932       notInExisting=true;
933       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
934       ret->_type=typeF;
935       ret->_loc_id=(int)geoType;
936       ret->_nval=nbMeshEntities;
937       ret->_start=offset;
938       ret->_end=ret->_start+ret->_nval*nbi;
939       if(isPfl)
940         {
941           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
942           glob.appendProfile(idsOfMeshElt);
943           ret->_profile=idsOfMeshElt->getName();
944         }
945       //tony treatment of localization
946       return ret;
947     }
948   else
949     {
950       notInExisting=false;
951       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
952       ret->_loc_id=(int)geoType;
953       ret->setNewStart(offset);
954       entriesOnSameDisc.erase(it);
955       return ret;
956     }
957   
958 }
959
960 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
961 {
962   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc);
963 }
964
965 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
966 {
967   return new MEDFileFieldPerMeshPerType(fath,geoType);
968 }
969
970 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySize() const
971 {
972   std::size_t ret=_field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
973   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
974     ret+=(*it)->getHeapMemorySize();
975   return ret;
976 }
977
978 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const throw(INTERP_KERNEL::Exception)
979 {
980   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
981   ret->_father=father;
982   std::size_t i=0;
983   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
984     {
985       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
986         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
987     }
988   return ret.retn();
989 }
990
991 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
992 {
993   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
994   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
995     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
996 }
997
998 /*!
999  * This method is the most general one. No optimization is done here.
1000  * \param [in] multiTypePfl is the end user profile specified in high level API
1001  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1002  * \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.
1003  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1004  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1005  * \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.
1006  */
1007 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)
1008 {
1009   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1010   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1011     _field_pm_pt_pd[*it]->assignFieldProfile(start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1012 }
1013
1014 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1015 {
1016   _field_pm_pt_pd.resize(1);
1017   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1018   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1019 }
1020
1021 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1022 {
1023   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1024   if(!arr || !arr->isAllocated())
1025     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1026   _field_pm_pt_pd.resize(1);
1027   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1028   _field_pm_pt_pd[0]->assignFieldProfile(start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1029 }
1030
1031 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
1032 {
1033   TypeOfField type=field->getTypeOfField();
1034   if(type!=ON_GAUSS_PT)
1035     {
1036       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1037       int sz=_field_pm_pt_pd.size();
1038       bool found=false;
1039       for(int j=0;j<sz && !found;j++)
1040         {
1041           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1042             {
1043               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1044               found=true;
1045             }
1046         }
1047       if(!found)
1048         {
1049           _field_pm_pt_pd.resize(sz+1);
1050           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1051         }
1052       std::vector<int> ret(1,(int)sz);
1053       return ret;
1054     }
1055   else
1056     {
1057       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1058       int sz2=ret2.size();
1059       std::vector<int> ret3(sz2);
1060       int k=0;
1061       for(int i=0;i<sz2;i++)
1062         {
1063           int sz=_field_pm_pt_pd.size();
1064           int locIdToFind=ret2[i];
1065           bool found=false;
1066           for(int j=0;j<sz && !found;j++)
1067             {
1068               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1069                 {
1070                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1071                   ret3[k++]=j;
1072                   found=true;
1073                 }
1074             }
1075           if(!found)
1076             {
1077               _field_pm_pt_pd.resize(sz+1);
1078               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1079               ret3[k++]=sz;
1080             }
1081         }
1082       return ret3;
1083     }
1084 }
1085
1086 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
1087 {
1088   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1089   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1090   if(!disc2)
1091     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1092   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1093   if(!da)
1094     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1095   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1096   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1097   if(retTmp->presenceOfValue(-1))
1098     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1099   std::vector<int> ret(retTmp->begin(),retTmp->end());
1100   return ret;
1101 }
1102
1103 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1104 {
1105   TypeOfField type=field->getTypeOfField();
1106   if(type!=ON_GAUSS_PT)
1107     {
1108       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1109       int sz=_field_pm_pt_pd.size();
1110       bool found=false;
1111       for(int j=0;j<sz && !found;j++)
1112         {
1113           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1114             {
1115               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1116               found=true;
1117             }
1118         }
1119       if(!found)
1120         {
1121           _field_pm_pt_pd.resize(sz+1);
1122           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1123         }
1124       std::vector<int> ret(1,0);
1125       return ret;
1126     }
1127   else
1128     {
1129       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1130       int sz2=ret2.size();
1131       std::vector<int> ret3(sz2);
1132       int k=0;
1133       for(int i=0;i<sz2;i++)
1134         {
1135           int sz=_field_pm_pt_pd.size();
1136           int locIdToFind=ret2[i];
1137           bool found=false;
1138           for(int j=0;j<sz && !found;j++)
1139             {
1140               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1141                 {
1142                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1143                   ret3[k++]=j;
1144                   found=true;
1145                 }
1146             }
1147           if(!found)
1148             {
1149               _field_pm_pt_pd.resize(sz+1);
1150               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1151               ret3[k++]=sz;
1152             }
1153         }
1154       return ret3;
1155     }
1156 }
1157
1158 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1159 {
1160   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1161   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1162   if(!disc2)
1163     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1164   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1165   if(!da)
1166     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1167   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1168   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1169   if(retTmp->presenceOfValue(-1))
1170     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1171   std::vector<int> ret(retTmp->begin(),retTmp->end());
1172   return ret;
1173 }
1174
1175 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1176 {
1177   return _father;
1178 }
1179
1180 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1181 {
1182   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1183   int curDim=(int)cm.getDimension();
1184   dim=std::max(dim,curDim);
1185 }
1186
1187 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1188 {
1189   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1190     {
1191       (*it)->fillTypesOfFieldAvailable(types);
1192     }
1193 }
1194
1195 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)
1196 {
1197   int sz=_field_pm_pt_pd.size();
1198   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1199   for(int i=0;i<sz;i++)
1200     {
1201       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1202     }
1203 }
1204
1205 int MEDFileFieldPerMeshPerType::getIteration() const
1206 {
1207   return _father->getIteration();
1208 }
1209
1210 int MEDFileFieldPerMeshPerType::getOrder() const
1211 {
1212   return _father->getOrder();
1213 }
1214
1215 double MEDFileFieldPerMeshPerType::getTime() const
1216 {
1217   return _father->getTime();
1218 }
1219
1220 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1221 {
1222   return _father->getMeshName();
1223 }
1224
1225 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1226 {
1227   const char startLine[]="  ## ";
1228   std::string startLine2(bkOffset,' ');
1229   std::string startLine3(startLine2);
1230   startLine3+=startLine;
1231   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1232     {
1233       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1234       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1235     }
1236   else
1237     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1238   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1239   int i=0;
1240   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1241     {
1242       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1243       if(cur)
1244         cur->simpleRepr(bkOffset,oss,i);
1245       else
1246         {
1247           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1248         }
1249     }
1250 }
1251
1252 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1253 {
1254   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1255     {
1256       globalSz+=(*it)->getNumberOfTuples();
1257     }
1258   nbOfEntries+=(int)_field_pm_pt_pd.size();
1259 }
1260
1261 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1262 {
1263   return _geo_type;
1264 }
1265
1266
1267 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1268 {
1269   return _father->getNumberOfComponents();
1270 }
1271
1272 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1273 {
1274   return _father->getOrCreateAndGetArray();
1275 }
1276
1277 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1278 {
1279   const MEDFileFieldPerMesh *fath=_father;
1280   return fath->getOrCreateAndGetArray();
1281 }
1282
1283 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1284 {
1285   return _father->getInfo();
1286 }
1287
1288 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1289 {
1290   std::vector<std::string> ret;
1291   std::set<std::string> ret2;
1292   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1293     {
1294       std::string tmp=(*it1)->getProfile();
1295       if(!tmp.empty())
1296         if(ret2.find(tmp)==ret2.end())
1297           {
1298             ret.push_back(tmp);
1299             ret2.insert(tmp);
1300           }
1301     }
1302   return ret;
1303 }
1304
1305 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1306 {
1307   std::vector<std::string> ret;
1308   std::set<std::string> ret2;
1309   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1310     {
1311       std::string tmp=(*it1)->getLocalization();
1312       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1313         if(ret2.find(tmp)==ret2.end())
1314           {
1315             ret.push_back(tmp);
1316             ret2.insert(tmp);
1317           }
1318     }
1319   return ret;
1320 }
1321
1322 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1323 {
1324   std::vector<std::string> ret;
1325   std::set<std::string> ret2;
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)->getProfile();
1329       if(!tmp.empty())
1330         ret.push_back(tmp);
1331     }
1332   return ret;
1333 }
1334
1335 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1336 {
1337   std::vector<std::string> ret;
1338   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1339     {
1340       std::string tmp=(*it1)->getLocalization();
1341       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1342         ret.push_back(tmp);
1343     }
1344   return ret;
1345 }
1346
1347 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1348 {
1349   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1350     (*it1)->changePflsRefsNamesGen(mapOfModif);
1351 }
1352
1353 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1354 {
1355   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1356     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1357 }
1358
1359 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) throw(INTERP_KERNEL::Exception)
1360 {
1361   if(_field_pm_pt_pd.empty())
1362     {
1363       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1364       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1365       throw INTERP_KERNEL::Exception(oss.str().c_str());
1366     }
1367   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1368     return _field_pm_pt_pd[locId];
1369   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1370   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1371   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1372   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1373   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1374 }
1375
1376 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const throw(INTERP_KERNEL::Exception)
1377 {
1378   if(_field_pm_pt_pd.empty())
1379     {
1380       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1381       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1382       throw INTERP_KERNEL::Exception(oss.str().c_str());
1383     }
1384   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1385     return _field_pm_pt_pd[locId];
1386   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1387   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1388   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1389   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1390   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1391 }
1392
1393 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
1394 {
1395   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1396     {
1397       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1398       if(meshDim!=(int)cm.getDimension())
1399         return ;
1400     }
1401   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1402     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1403 }
1404
1405 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1406 {
1407   int i=0;
1408   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1409     {
1410       (*it)->fillValues(i,startEntryId,entries);
1411     }
1412 }
1413
1414 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1415 {
1416   _field_pm_pt_pd=leaves;
1417   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1418     (*it)->setFather(this);
1419 }
1420
1421 /*!
1422  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1423  *  \param [out] its - list of pair (start,stop) kept
1424  *  \return bool - false if the type of field \a tof is not contained in \a this.
1425  */
1426 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1427 {
1428   bool ret=false;
1429   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1430   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1431     if((*it)->getType()==tof)
1432       {
1433         newPmPtPd.push_back(*it);
1434         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1435         (*it)->setNewStart(globalNum);
1436         globalNum=(*it)->getEnd();
1437         its.push_back(bgEnd);
1438         ret=true;
1439       }
1440   if(ret)
1441     _field_pm_pt_pd=newPmPtPd;
1442   return ret;
1443 }
1444
1445 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType)
1446 {
1447 }
1448
1449 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)
1450 {
1451   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1452   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1453   med_geometry_type mgeoti;
1454   med_entity_type menti=ConvertIntoMEDFileType(type,geoType,mgeoti);
1455   int nbProfiles=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName);
1456   _field_pm_pt_pd.resize(nbProfiles);
1457   for(int i=0;i<nbProfiles;i++)
1458     {
1459       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i+1);
1460     }
1461 }
1462
1463 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1464 {
1465   int pflId=0;
1466   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1467     {
1468       (*it)->loadOnlyStructureOfDataRecursively(fid,pflId+1,start,nasc);//tony
1469     }
1470 }
1471
1472 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1473 {
1474   int pflId=0;
1475   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1476     {
1477       (*it)->loadBigArray(fid,pflId+1,nasc);//tony
1478     }
1479 }
1480
1481 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
1482 {
1483   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1484     {
1485       (*it)->copyOptionsFrom(*this);
1486       (*it)->writeLL(fid,nasc);
1487     }
1488 }
1489
1490 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1491 {
1492   switch(ikType)
1493     {
1494     case ON_CELLS:
1495       medfGeoType=typmai3[(int)ikGeoType];
1496       return MED_CELL;
1497     case ON_NODES:
1498       medfGeoType=MED_NONE;
1499       return MED_NODE;
1500     case ON_GAUSS_NE:
1501       medfGeoType=typmai3[(int)ikGeoType];
1502       return MED_NODE_ELEMENT;
1503     case ON_GAUSS_PT:
1504       medfGeoType=typmai3[(int)ikGeoType];
1505       return MED_CELL;
1506     default:
1507       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1508     }
1509   return MED_UNDEF_ENTITY_TYPE;
1510 }
1511
1512 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1513 {
1514   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc);
1515 }
1516
1517 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1518 {
1519   return new MEDFileFieldPerMesh(fath,mesh);
1520 }
1521
1522 std::size_t MEDFileFieldPerMesh::getHeapMemorySize() const
1523 {
1524   std::size_t ret=_mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1525   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1526     if((const MEDFileFieldPerMeshPerType *)*it)
1527       ret+=(*it)->getHeapMemorySize();
1528   return ret;
1529 }
1530
1531 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const throw(INTERP_KERNEL::Exception)
1532 {
1533   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1534   ret->_father=father;
1535   std::size_t i=0;
1536   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1537     {
1538       if((const MEDFileFieldPerMeshPerType *)*it)
1539         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1540     }
1541   return ret.retn();
1542 }
1543
1544 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1545 {
1546   std::string startLine(bkOffset,' ');
1547   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1548   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1549   int i=0;
1550   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1551     {
1552       const MEDFileFieldPerMeshPerType *cur=*it;
1553       if(cur)
1554         cur->simpleRepr(bkOffset,oss,i);
1555       else
1556         {
1557           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1558         }
1559     }
1560 }
1561
1562 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
1563 {
1564   _mesh_name=mesh->getName();
1565   mesh->getTime(_mesh_iteration,_mesh_order);
1566 }
1567
1568 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)
1569 {
1570   int nbOfTypes=code.size()/3;
1571   int offset=0;
1572   for(int i=0;i<nbOfTypes;i++)
1573     {
1574       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1575       int nbOfCells=code[3*i+1];
1576       int pos=addNewEntryIfNecessary(type);
1577       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1578       offset+=nbOfCells;
1579     }
1580 }
1581
1582 /*!
1583  * This method is the most general one. No optimization is done here.
1584  * \param [in] multiTypePfl is the end user profile specified in high level API
1585  * \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].
1586  * \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.
1587  * \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.
1588  * \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.
1589  * \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.
1590  */
1591 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)
1592 {
1593   int nbOfTypes=code.size()/3;
1594   for(int i=0;i<nbOfTypes;i++)
1595     {
1596       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1597       int pos=addNewEntryIfNecessary(type);
1598       DataArrayInt *pfl=0;
1599       if(code[3*i+2]!=-1)
1600         pfl=idsPerType[code[3*i+2]];
1601       int nbOfTupes2=code2.size()/3;
1602       int found=0;
1603       for(;found<nbOfTupes2;found++)
1604         if(code[3*i]==code2[3*found])
1605           break;
1606       if(found==nbOfTupes2)
1607         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1608       _field_pm_pt[pos]->assignFieldProfile(start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1609     }
1610 }
1611
1612 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1613 {
1614   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1615   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1616 }
1617
1618 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1619 {
1620   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1621   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1622 }
1623
1624 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1625 {
1626   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1627     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1628 }
1629
1630 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1631 {
1632   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1633     (*it)->loadBigArraysRecursively(fid,nasc);
1634 }
1635
1636 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
1637 {
1638   int nbOfTypes=_field_pm_pt.size();
1639   for(int i=0;i<nbOfTypes;i++)
1640     {
1641       _field_pm_pt[i]->copyOptionsFrom(*this);
1642       _field_pm_pt[i]->writeLL(fid,nasc);
1643     }
1644 }
1645
1646 void MEDFileFieldPerMesh::getDimension(int& dim) const
1647 {
1648   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1649     (*it)->getDimension(dim);
1650 }
1651
1652 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1653 {
1654   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1655     (*it)->fillTypesOfFieldAvailable(types);
1656 }
1657
1658 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)
1659 {
1660   int sz=_field_pm_pt.size();
1661   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1662   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1663   for(int i=0;i<sz;i++)
1664     {
1665       types[i]=_field_pm_pt[i]->getGeoType();
1666       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1667     }
1668   return ret;
1669 }
1670
1671 double MEDFileFieldPerMesh::getTime() const
1672 {
1673   int tmp1,tmp2;
1674   return _father->getTime(tmp1,tmp2);
1675 }
1676
1677 int MEDFileFieldPerMesh::getIteration() const
1678 {
1679   return _father->getIteration();
1680 }
1681
1682 int MEDFileFieldPerMesh::getOrder() const
1683 {
1684   return _father->getOrder();
1685 }
1686
1687 int MEDFileFieldPerMesh::getNumberOfComponents() const
1688 {
1689   return _father->getNumberOfComponents();
1690 }
1691
1692 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1693 {
1694   if(!_father)
1695     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1696   return _father->getOrCreateAndGetArray();
1697 }
1698
1699 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1700 {
1701   if(!_father)
1702     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1703   return _father->getOrCreateAndGetArray();
1704 }
1705
1706 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1707 {
1708   return _father->getInfo();
1709 }
1710
1711 /*!
1712  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1713  * 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.
1714  * It returns 2 output vectors :
1715  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1716  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1717  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1718  */
1719 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)
1720 {
1721   int notNullPflsSz=0;
1722   int nbOfArrs=geoTypes.size();
1723   for(int i=0;i<nbOfArrs;i++)
1724     if(pfls[i])
1725       notNullPflsSz++;
1726   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1727   int nbOfDiffGeoTypes=geoTypes3.size();
1728   code.resize(3*nbOfDiffGeoTypes);
1729   notNullPfls.resize(notNullPflsSz);
1730   notNullPflsSz=0;
1731   int j=0;
1732   for(int i=0;i<nbOfDiffGeoTypes;i++)
1733     {
1734       int startZone=j;
1735       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1736       std::vector<const DataArrayInt *> notNullTmp;
1737       if(pfls[j])
1738         notNullTmp.push_back(pfls[j]);
1739       j++;
1740       for(;j<nbOfArrs;j++)
1741         if(geoTypes[j]==refType)
1742           {
1743             if(pfls[j])
1744               notNullTmp.push_back(pfls[j]);
1745           }
1746         else
1747           break;
1748       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1749       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1750       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1751       code[3*i]=(int)refType;
1752       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1753       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1754       if(notNullTmp.empty())
1755         code[3*i+2]=-1;
1756       else
1757         {
1758           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1759           code[3*i+2]=notNullPflsSz++;
1760         }
1761     }
1762 }
1763
1764 /*!
1765  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1766  */
1767 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)
1768 {
1769   int sz=dads.size();
1770   int ret=0;
1771   for(int i=0;i<sz;i++)
1772     {
1773       if(locs[i]==-1)
1774         {
1775           if(type!=ON_GAUSS_NE)
1776             ret+=dads[i].second-dads[i].first;
1777           else
1778             {
1779               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1780               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1781             }
1782         }
1783       else
1784         {
1785           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1786           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1787         }
1788     }
1789   return ret;
1790 }
1791
1792 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1793 {
1794   std::vector<std::string> ret;
1795   std::set<std::string> ret2;
1796   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1797     {
1798       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1799       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1800         if(ret2.find(*it2)==ret2.end())
1801           {
1802             ret.push_back(*it2);
1803             ret2.insert(*it2);
1804           }
1805     }
1806   return ret;
1807 }
1808
1809 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1810 {
1811   std::vector<std::string> ret;
1812   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1813     {
1814       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1815       ret.insert(ret.end(),tmp.begin(),tmp.end());
1816     }
1817   return ret;
1818 }
1819
1820 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1821 {
1822   std::vector<std::string> ret;
1823   std::set<std::string> ret2;
1824   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1825     {
1826       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1827       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1828         if(ret2.find(*it2)==ret2.end())
1829           {
1830             ret.push_back(*it2);
1831             ret2.insert(*it2);
1832           }
1833     }
1834   return ret;
1835 }
1836
1837 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1838 {
1839   std::vector<std::string> ret;
1840   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1841     {
1842       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1843       ret.insert(ret.end(),tmp.begin(),tmp.end());
1844     }
1845   return ret;
1846 }
1847
1848 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
1849 {
1850   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1851     {
1852       if((*it).first==_mesh_name)
1853         {
1854           _mesh_name=(*it).second;
1855           return true;
1856         }
1857     }
1858   return false;
1859 }
1860
1861 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1862                                                       MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1863 {
1864   if(_mesh_name!=meshName)
1865     return false;
1866   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1867   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1868   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1869   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1870   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1871   getUndergroundDataArrayExt(entries);
1872   DataArray *arr0=getOrCreateAndGetArray();//tony
1873   if(!arr0)
1874     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
1875   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
1876   if(!arr0)
1877     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
1878   int sz=0;
1879   if(!arr)
1880     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1881   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1882     {
1883       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1884         {
1885           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1886           sz+=(*it).second.second-(*it).second.first;
1887         }
1888       else
1889         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1890     }
1891   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1892   ////////////////////
1893   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1894   int *workI2=explicitIdsOldInMesh->getPointer();
1895   int sz1=0,sz2=0,sid=1;
1896   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1897   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1898   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1899     {
1900       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1901       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1902       int *workI=explicitIdsOldInArr->getPointer();
1903       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1904         {
1905           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1906           (*itL2)->setLocId(sz2);
1907           (*itL2)->_tmp_work1=(*itL2)->getStart();
1908           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1909         }
1910       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1911     }
1912   explicitIdsOldInMesh->reAlloc(sz2);
1913   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1914   ////////////////////
1915   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1916   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1917   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1918   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1919     {
1920       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1921       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1922       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1923     }
1924   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1925   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1926   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
1927     {
1928       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1929       int newStart=elt->getLocId();
1930       elt->setLocId((*it)->getGeoType());
1931       elt->setNewStart(newStart);
1932       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
1933       entriesKeptNew.push_back(elt);
1934       entriesKeptNew2.push_back(elt);
1935     }
1936   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
1937   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
1938   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
1939   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
1940   bool ret=false;
1941   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
1942     {
1943       sid=0;
1944       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
1945         {
1946           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
1947           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
1948           }*/
1949       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
1950                                                             glob,arr2,otherEntriesNew) || ret;
1951     }
1952   if(!ret)
1953     return false;
1954   // Assign new dispatching
1955   assignNewLeaves(otherEntriesNew);
1956   arr->cpyFrom(*arr2);
1957   return true;
1958 }
1959
1960 /*!
1961  * \param [in,out] globalNum a global numbering counter for the renumbering.
1962  * \param [out] its - list of pair (start,stop) kept
1963  */
1964 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1965 {
1966   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
1967   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1968     {
1969       std::vector< std::pair<int,int> > its2;
1970       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
1971         {
1972           ret.push_back(*it);
1973           its.insert(its.end(),its2.begin(),its2.end());
1974         }
1975     }
1976   _field_pm_pt=ret;
1977 }
1978
1979 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1980 {
1981   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
1982   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
1983     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
1984   //
1985   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
1986   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
1987   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
1988   for(;it1!=types.end();it1++,it2++)
1989     {
1990       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
1991       elt->setLeaves((*it1).second);
1992       *it2=elt;
1993     }
1994   _field_pm_pt=fieldPmPt;
1995 }
1996
1997 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1998 {
1999   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2000     (*it)->changePflsRefsNamesGen(mapOfModif);
2001 }
2002
2003 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2004 {
2005   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2006     (*it)->changeLocsRefsNamesGen(mapOfModif);
2007 }
2008
2009 /*!
2010  * \param [in] mesh is the whole mesh
2011  */
2012 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2013 {
2014   if(_field_pm_pt.empty())
2015     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2016   //
2017   std::vector< std::pair<int,int> > dads;
2018   std::vector<const DataArrayInt *> pfls;
2019   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2020   std::vector<int> locs,code;
2021   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2022   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2023     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2024   // Sort by types
2025   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2026   if(code.empty())
2027     {
2028       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2029       throw INTERP_KERNEL::Exception(oss.str().c_str());
2030     }
2031   //
2032   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2033   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2034   if(type!=ON_NODES)
2035     {
2036       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2037       if(!arr)
2038         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2039       else
2040         {
2041           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2042           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2043         }
2044     }
2045   else
2046     {
2047       if(code.size()!=3)
2048         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2049       int nb=code[1];
2050       if(code[2]==-1)
2051         {
2052           if(nb!=mesh->getNumberOfNodes())
2053             {
2054               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2055               oss << " nodes in mesh !";
2056               throw INTERP_KERNEL::Exception(oss.str().c_str());
2057             }
2058           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2059         }
2060       else
2061         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2062     }
2063 }
2064
2065 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2066 {
2067   if(_field_pm_pt.empty())
2068     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2069   //
2070   std::vector<std::pair<int,int> > dads;
2071   std::vector<const DataArrayInt *> pfls;
2072   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2073   std::vector<int> locs,code;
2074   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2075   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2076     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2077   // Sort by types
2078   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2079   if(code.empty())
2080     {
2081       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2082       throw INTERP_KERNEL::Exception(oss.str().c_str());
2083     }
2084   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2085   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2086   if(type!=ON_NODES)
2087     {
2088       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2089       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2090     }
2091   else
2092     {
2093       if(code.size()!=3)
2094         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2095       int nb=code[1];
2096       if(code[2]==-1)
2097         {
2098           if(nb!=mesh->getNumberOfNodes())
2099             {
2100               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2101               oss << " nodes in mesh !";
2102               throw INTERP_KERNEL::Exception(oss.str().c_str());
2103             }
2104         }
2105       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2106     }
2107   //
2108   return 0;
2109 }
2110
2111 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
2112 {
2113   int globalSz=0;
2114   int nbOfEntries=0;
2115   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2116     {
2117       (*it)->getSizes(globalSz,nbOfEntries);
2118     }
2119   entries.resize(nbOfEntries);
2120   nbOfEntries=0;
2121   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2122     {
2123       (*it)->fillValues(nbOfEntries,entries);
2124     }
2125 }
2126
2127 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
2128 {
2129   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2130     {
2131       if((*it)->getGeoType()==typ)
2132         return (*it)->getLeafGivenLocId(locId);
2133     }
2134   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2135   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2136   oss << "Possiblities are : ";
2137   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2138     {
2139       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2140       oss << "\"" << cm2.getRepr() << "\", ";
2141     }
2142   throw INTERP_KERNEL::Exception(oss.str().c_str());
2143 }
2144
2145 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
2146 {
2147   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2148     {
2149       if((*it)->getGeoType()==typ)
2150         return (*it)->getLeafGivenLocId(locId);
2151     }
2152   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2153   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2154   oss << "Possiblities are : ";
2155   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2156     {
2157       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2158       oss << "\"" << cm2.getRepr() << "\", ";
2159     }
2160   throw INTERP_KERNEL::Exception(oss.str().c_str());
2161 }
2162
2163 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2164 {
2165   int i=0;
2166   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2167   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2168   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2169     {
2170       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2171       if(type==curType)
2172         return i;
2173       else
2174         {
2175           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2176           if(pos>pos2)
2177             it2=it+1;
2178         }
2179     }
2180   int ret=std::distance(_field_pm_pt.begin(),it2);
2181   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2182   return ret;
2183 }
2184
2185 /*!
2186  * 'dads' and 'locs' input parameters have the same number of elements
2187  * \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
2188  */
2189 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2190                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2191                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2192 {
2193   isPfl=false;
2194   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2195   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2196   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2197   const std::vector<std::string>& infos=getInfo();
2198   da->setInfoOnComponents(infos);
2199   da->setName("");
2200   if(type==ON_GAUSS_PT)
2201     {
2202       int offset=0;
2203       int nbOfArrs=dads.size();
2204       for(int i=0;i<nbOfArrs;i++)
2205         {
2206           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2207           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2208           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2209           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2210           di->alloc(nbOfElems,1);
2211           di->iota(offset);
2212           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2213           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2214           offset+=nbOfElems;
2215         }
2216     }
2217   arrOut=da;
2218   return ret.retn();
2219 }
2220
2221 /*!
2222  * 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.
2223  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2224  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2225  * The order of cells in the returned field is those imposed by the profile.
2226  * \param [in] mesh is the global mesh.
2227  */
2228 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2229                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2230                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2231                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2232 {
2233   if(da->isIdentity())
2234     {
2235       int nbOfTuples=da->getNumberOfTuples();
2236       if(nbOfTuples==mesh->getNumberOfCells())
2237         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2238     }
2239   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2240   m2->setName(mesh->getName());
2241   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2242   isPfl=true;
2243   return ret.retn();
2244 }
2245
2246 /*!
2247  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2248  */
2249 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2250                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2251                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2252 {
2253   if(da->isIdentity())
2254     {
2255       int nbOfTuples=da->getNumberOfTuples();
2256       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2257         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2258     }
2259   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2260   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2261   if(meshu)
2262     {
2263       if(meshu->getNodalConnectivity()==0)
2264         {
2265           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2266           int nb=da->getNbOfElems();
2267           const int *ptr=da->getConstPointer();
2268           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2269           meshuc->allocateCells(nb);
2270           for(int i=0;i<nb;i++)
2271             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2272           meshuc->finishInsertingCells();
2273           ret->setMesh(meshuc);
2274           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2275           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2276           disc->checkCoherencyBetween(meshuc,arrOut);
2277           return ret.retn();
2278         }
2279     }
2280   //
2281   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2282   isPfl=true;
2283   DataArrayInt *arr2=0;
2284   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2285   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2286   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2287   int nnodes=mesh2->getNumberOfNodes();
2288   if(nnodes==(int)da->getNbOfElems())
2289     {
2290       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2291       arrOut->renumberInPlace(da3->getConstPointer());
2292       mesh2->setName(mesh->getName());
2293       ret->setMesh(mesh2);
2294       return ret.retn();
2295     }
2296   else
2297     {
2298       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 !!!";
2299       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2300       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2301       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2302       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2303       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2304       throw INTERP_KERNEL::Exception(oss.str().c_str());
2305     }
2306   return 0;
2307 }
2308
2309 /*!
2310  * This method is the most light method of field retrieving.
2311  */
2312 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const throw(INTERP_KERNEL::Exception)
2313 {
2314   if(!pflIn)
2315     {
2316       pflOut=DataArrayInt::New();
2317       pflOut->alloc(nbOfElems,1);
2318       pflOut->iota(0);
2319     }
2320   else
2321     {
2322       pflOut=const_cast<DataArrayInt*>(pflIn);
2323       pflOut->incrRef();
2324     }
2325   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2326   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2327   const std::vector<std::string>& infos=getInfo();
2328   int nbOfComp=infos.size();
2329   for(int i=0;i<nbOfComp;i++)
2330     da->setInfoOnComponent(i,infos[i].c_str());
2331   safePfl->incrRef();
2332   return da.retn();
2333 }
2334
2335 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),
2336                                                                                                                                                                                                                  _mesh_csit(meshCsit),_father(fath)
2337 {
2338   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2339   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2340   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2341   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2342     {
2343       int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL,typmai[i],_mesh_csit,meshName,pflName,locName);
2344       if(nbProfile>0)
2345         {
2346           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i],nasc));
2347           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2348         }
2349       nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],_mesh_csit,meshName,pflName,locName);
2350       if(nbProfile>0)
2351         {
2352           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_GAUSS_NE,typmai2[i],nasc));
2353           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2354         }
2355     }
2356   int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,_mesh_csit,meshName,pflName,locName);
2357   if(nbProfile>0)
2358     {
2359       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc));
2360       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2361     }
2362 }
2363
2364 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2365 {
2366   copyTinyInfoFrom(mesh);
2367 }
2368
2369 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
2370 {
2371   if(id>=(int)_pfls.size())
2372     _pfls.resize(id+1);
2373   _pfls[id]=DataArrayInt::New();
2374   int lgth=MEDprofileSizeByName(fid,pflName);
2375   _pfls[id]->setName(pflName);
2376   _pfls[id]->alloc(lgth,1);
2377   MEDprofileRd(fid,pflName,_pfls[id]->getPointer());
2378   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2379 }
2380
2381 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2382 {
2383   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2384   int sz;
2385   MEDprofileInfo(fid,i+1,pflName,&sz);
2386   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2387   if(i>=(int)_pfls.size())
2388     _pfls.resize(i+1);
2389   _pfls[i]=DataArrayInt::New();
2390   _pfls[i]->alloc(sz,1);
2391   _pfls[i]->setName(pflCpp.c_str());
2392   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2393   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2394 }
2395
2396 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
2397 {
2398   int nbOfPfls=_pfls.size();
2399   for(int i=0;i<nbOfPfls;i++)
2400     {
2401       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2402       cpy->applyLin(1,1,0);
2403       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2404       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2405       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2406     }
2407   //
2408   int nbOfLocs=_locs.size();
2409   for(int i=0;i<nbOfLocs;i++)
2410     _locs[i]->writeLL(fid);
2411 }
2412
2413 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps) throw(INTERP_KERNEL::Exception)
2414 {
2415   std::vector<std::string> pfls=getPfls();
2416   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2417     {
2418       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2419       if(it2==pfls.end())
2420         {
2421           _pfls.push_back(*it);
2422         }
2423       else
2424         {
2425           int id=std::distance(pfls.begin(),it2);
2426           if(!(*it)->isEqual(*_pfls[id]))
2427             {
2428               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2429               throw INTERP_KERNEL::Exception(oss.str().c_str());
2430             }
2431         }
2432     }
2433   std::vector<std::string> locs=getLocs();
2434   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2435     {
2436       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2437       if(it2==locs.end())
2438         {
2439           _locs.push_back(*it);
2440         }
2441       else
2442         {
2443           int id=std::distance(locs.begin(),it2);
2444           if(!(*it)->isEqual(*_locs[id],eps))
2445             {
2446               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2447               throw INTERP_KERNEL::Exception(oss.str().c_str());
2448             }
2449         }
2450     }
2451 }
2452
2453 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const throw(INTERP_KERNEL::Exception)
2454 {
2455   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2456     getProfile((*it).c_str());
2457 }
2458
2459 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const throw(INTERP_KERNEL::Exception)
2460 {
2461   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2462     getLocalization((*it).c_str());
2463 }
2464
2465 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real) throw(INTERP_KERNEL::Exception)
2466 {
2467   std::vector<std::string> profiles=real.getPflsReallyUsed();
2468   int sz=profiles.size();
2469   _pfls.resize(sz);
2470   for(int i=0;i<sz;i++)
2471     loadProfileInFile(fid,i,profiles[i].c_str());
2472   //
2473   std::vector<std::string> locs=real.getLocsReallyUsed();
2474   sz=locs.size();
2475   _locs.resize(sz);
2476   for(int i=0;i<sz;i++)
2477     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2478 }
2479
2480 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2481 {
2482   int nProfil=MEDnProfile(fid);
2483   for(int i=0;i<nProfil;i++)
2484     loadProfileInFile(fid,i);
2485   int sz=MEDnLocalization(fid);
2486   _locs.resize(sz);
2487   for(int i=0;i<sz;i++)
2488     {
2489       _locs[i]=MEDFileFieldLoc::New(fid,i);
2490     }
2491 }
2492
2493 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const char *fname)
2494 {
2495   return new MEDFileFieldGlobs(fname);
2496 }
2497
2498 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2499 {
2500   return new MEDFileFieldGlobs;
2501 }
2502
2503 std::size_t MEDFileFieldGlobs::getHeapMemorySize() const
2504 {
2505   std::size_t ret=_file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2506   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2507     ret+=(*it)->getHeapMemorySize();
2508   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2509     ret+=(*it)->getHeapMemorySize();
2510   return ret;
2511 }
2512
2513 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const throw(INTERP_KERNEL::Exception)
2514 {
2515   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2516   std::size_t i=0;
2517   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2518     {
2519       if((const DataArrayInt *)*it)
2520         ret->_pfls[i]=(*it)->deepCpy();
2521     }
2522   i=0;
2523   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2524     {
2525       if((const MEDFileFieldLoc*)*it)
2526         ret->_locs[i]=(*it)->deepCpy();
2527     }
2528   return ret.retn();
2529 }
2530
2531 /*!
2532  * \throw if a profile in \a pfls in not in \a this.
2533  * \throw if a localization in \a locs in not in \a this.
2534  * \sa MEDFileFieldGlobs::deepCpyPart
2535  */
2536 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const throw(INTERP_KERNEL::Exception)
2537 {
2538   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2539   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2540     {
2541       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2542       if(!pfl)
2543         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2544       pfl->incrRef();
2545       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2546       ret->_pfls.push_back(pfl2);
2547     }
2548   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2549     {
2550       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2551       if(!loc)
2552         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2553       loc->incrRef();
2554       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2555       ret->_locs.push_back(loc2);
2556     }
2557   ret->setFileName(getFileName());
2558   return ret.retn();
2559 }
2560
2561 /*!
2562  * \throw if a profile in \a pfls in not in \a this.
2563  * \throw if a localization in \a locs in not in \a this.
2564  * \sa MEDFileFieldGlobs::shallowCpyPart
2565  */
2566 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const throw(INTERP_KERNEL::Exception)
2567 {
2568   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2569   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2570     {
2571       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2572       if(!pfl)
2573         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2574       ret->_pfls.push_back(pfl->deepCpy());
2575     }
2576   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2577     {
2578       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2579       if(!loc)
2580         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2581       ret->_locs.push_back(loc->deepCpy());
2582     }
2583   ret->setFileName(getFileName());
2584   return ret.retn();
2585 }
2586
2587 MEDFileFieldGlobs::MEDFileFieldGlobs(const char *fname):_file_name(fname)
2588 {
2589 }
2590
2591 MEDFileFieldGlobs::MEDFileFieldGlobs()
2592 {
2593 }
2594
2595 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2596 {
2597 }
2598
2599 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2600 {
2601   oss << "Profiles :\n";
2602   std::size_t n=_pfls.size();
2603   for(std::size_t i=0;i<n;i++)
2604     {
2605       oss << "  - #" << i << " ";
2606       const DataArrayInt *pfl=_pfls[i];
2607       if(pfl)
2608         oss << "\"" << pfl->getName() << "\"\n";
2609       else
2610         oss << "EMPTY !\n";
2611     }
2612   n=_locs.size();
2613   oss << "Localizations :\n";
2614   for(std::size_t i=0;i<n;i++)
2615     {
2616       oss << "  - #" << i << " ";
2617       const MEDFileFieldLoc *loc=_locs[i];
2618       if(loc)
2619         loc->simpleRepr(oss);
2620       else
2621         oss<< "EMPTY !\n";
2622     }
2623 }
2624
2625 void MEDFileFieldGlobs::setFileName(const char *fileName)
2626 {
2627   _file_name=fileName;
2628 }
2629
2630 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2631 {
2632   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2633     {
2634       DataArrayInt *elt(*it);
2635       if(elt)
2636         {
2637           std::string name(elt->getName());
2638           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2639             {
2640               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2641                 {
2642                   elt->setName((*it2).second.c_str());
2643                   return;
2644                 }
2645             }
2646         }
2647     }
2648 }
2649
2650 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2651 {
2652   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2653     {
2654       MEDFileFieldLoc *elt(*it);
2655       if(elt)
2656         {
2657           std::string name(elt->getName());
2658           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2659             {
2660               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2661                 {
2662                   elt->setName((*it2).second.c_str());
2663                   return;
2664                 }
2665             }
2666         }
2667     }
2668 }
2669
2670 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
2671 {
2672   if(locId<0 || locId>=(int)_locs.size())
2673     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2674   return _locs[locId]->getNbOfGaussPtPerCell();
2675 }
2676
2677 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
2678 {
2679   return getLocalizationFromId(getLocalizationId(locName));
2680 }
2681
2682 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
2683 {
2684   if(locId<0 || locId>=(int)_locs.size())
2685     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2686   return *_locs[locId];
2687 }
2688
2689 namespace ParaMEDMEMImpl
2690 {
2691   class LocFinder
2692   {
2693   public:
2694     LocFinder(const char *loc):_loc(loc) { }
2695     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2696   private:
2697     const char *_loc;
2698   };
2699
2700   class PflFinder
2701   {
2702   public:
2703     PflFinder(const std::string& pfl):_pfl(pfl) { }
2704     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2705   private:
2706     const std::string& _pfl;
2707   };
2708 }
2709
2710 int MEDFileFieldGlobs::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
2711 {
2712   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2713   if(it==_locs.end())
2714     {
2715       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2716       for(it=_locs.begin();it!=_locs.end();it++)
2717         oss << "\"" << (*it)->getName() << "\", ";
2718       throw INTERP_KERNEL::Exception(oss.str().c_str());
2719     }
2720   return std::distance(_locs.begin(),it);
2721 }
2722
2723 /*!
2724  * The returned value is never null.
2725  */
2726 const DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
2727 {
2728   std::string pflNameCpp(pflName);
2729   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2730   if(it==_pfls.end())
2731     {
2732       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2733       for(it=_pfls.begin();it!=_pfls.end();it++)
2734         oss << "\"" << (*it)->getName() << "\", ";
2735       throw INTERP_KERNEL::Exception(oss.str().c_str());
2736     }
2737   return *it;
2738 }
2739
2740 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
2741 {
2742   if(pflId<0 || pflId>=(int)_pfls.size())
2743     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2744   return _pfls[pflId];
2745 }
2746
2747 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
2748 {
2749   if(locId<0 || locId>=(int)_locs.size())
2750     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2751   return *_locs[locId];
2752 }
2753
2754 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
2755 {
2756   return getLocalizationFromId(getLocalizationId(locName));
2757 }
2758
2759 /*!
2760  * The returned value is never null.
2761  */
2762 DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
2763 {
2764   std::string pflNameCpp(pflName);
2765   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2766   if(it==_pfls.end())
2767     {
2768       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2769       for(it=_pfls.begin();it!=_pfls.end();it++)
2770         oss << "\"" << (*it)->getName() << "\", ";
2771       throw INTERP_KERNEL::Exception(oss.str().c_str());
2772     }
2773   return *it;
2774 }
2775
2776 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
2777 {
2778   if(pflId<0 || pflId>=(int)_pfls.size())
2779     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2780   return _pfls[pflId];
2781 }
2782
2783 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
2784 {
2785   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2786   int i=0;
2787   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2788     {
2789       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2790         newPfls.push_back(*it);
2791     }
2792   _pfls=newPfls;
2793 }
2794
2795 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
2796 {
2797   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2798   int i=0;
2799   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2800     {
2801       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2802         newLocs.push_back(*it);
2803     }
2804   _locs=newLocs;
2805 }
2806
2807 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2808 {
2809   int sz=_pfls.size();
2810   std::vector<std::string> ret(sz);
2811   for(int i=0;i<sz;i++)
2812     ret[i]=_pfls[i]->getName();
2813   return ret;
2814 }
2815
2816 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2817 {
2818   int sz=_locs.size();
2819   std::vector<std::string> ret(sz);
2820   for(int i=0;i<sz;i++)
2821     ret[i]=_locs[i]->getName();
2822   return ret;
2823 }
2824
2825 bool MEDFileFieldGlobs::existsPfl(const char *pflName) const
2826 {
2827   std::vector<std::string> v=getPfls();
2828   std::string s(pflName);
2829   return std::find(v.begin(),v.end(),s)!=v.end();
2830 }
2831
2832 bool MEDFileFieldGlobs::existsLoc(const char *locName) const
2833 {
2834   std::vector<std::string> v=getLocs();
2835   std::string s(locName);
2836   return std::find(v.begin(),v.end(),s)!=v.end();
2837 }
2838
2839 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2840 {
2841   std::map<int,std::vector<int> > m;
2842   int i=0;
2843   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2844     {
2845       const DataArrayInt *tmp=(*it);
2846       if(tmp)
2847         {
2848           m[tmp->getHashCode()].push_back(i);
2849         }
2850     }
2851   std::vector< std::vector<int> > ret;
2852   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2853     {
2854       if((*it2).second.size()>1)
2855         {
2856           std::vector<int> ret0;
2857           bool equalityOrNot=false;
2858           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2859             {
2860               std::vector<int>::const_iterator it4=it3; it4++;
2861               for(;it4!=(*it2).second.end();it4++)
2862                 {
2863                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2864                     {
2865                       if(!equalityOrNot)
2866                         ret0.push_back(*it3);
2867                       ret0.push_back(*it4);
2868                       equalityOrNot=true;
2869                     }
2870                 }
2871             }
2872           if(!ret0.empty())
2873             ret.push_back(ret0);
2874         }
2875     }
2876   return ret;
2877 }
2878
2879 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2880 {
2881   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2882 }
2883
2884 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
2885 {
2886   std::string name(pfl->getName());
2887   if(name.empty())
2888     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2889   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2890     if(name==(*it)->getName())
2891       {
2892         if(!pfl->isEqual(*(*it)))
2893           {
2894             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2895             throw INTERP_KERNEL::Exception(oss.str().c_str());
2896           }
2897       }
2898   pfl->incrRef();
2899   _pfls.push_back(pfl);
2900 }
2901
2902 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)
2903 {
2904   std::string name(locName);
2905   if(name.empty())
2906     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2907   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2908   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2909     if((*it)->isName(locName))
2910       {
2911         if(!(*it)->isEqual(*obj,1e-12))
2912           {
2913             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
2914             throw INTERP_KERNEL::Exception(oss.str().c_str());
2915           }
2916       }
2917   _locs.push_back(obj);
2918 }
2919
2920 std::string MEDFileFieldGlobs::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
2921 {
2922   std::vector<std::string> names=getPfls();
2923   return CreateNewNameNotIn("NewPfl_",names);
2924 }
2925
2926 std::string MEDFileFieldGlobs::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
2927 {
2928   std::vector<std::string> names=getLocs();
2929   return CreateNewNameNotIn("NewLoc_",names);
2930 }
2931
2932 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const char *prefix, const std::vector<std::string>& namesToAvoid) throw(INTERP_KERNEL::Exception)
2933 {
2934   for(std::size_t sz=0;sz<100000;sz++)
2935     {
2936       std::ostringstream tryName;
2937       tryName << prefix << sz;
2938       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
2939         return tryName.str();
2940     }
2941   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
2942 }
2943
2944 /*!
2945  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
2946  *  \param [in] fname - the file name.
2947  */
2948 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const char *fname):_globals(MEDFileFieldGlobs::New(fname))
2949 {
2950 }
2951
2952 /*!
2953  * Creates an empty MEDFileFieldGlobsReal.
2954  */
2955 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
2956 {
2957 }
2958
2959 std::size_t MEDFileFieldGlobsReal::getHeapMemorySize() const
2960 {
2961   std::size_t ret=0;
2962   if((const MEDFileFieldGlobs *)_globals)
2963     ret+=_globals->getHeapMemorySize();
2964   return ret;
2965 }
2966
2967 /*!
2968  * Returns a string describing profiles and Gauss points held in \a this.
2969  *  \return std::string - the description string.
2970  */
2971 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
2972 {
2973   const MEDFileFieldGlobs *glob=_globals;
2974   std::ostringstream oss2; oss2 << glob;
2975   std::string stars(oss2.str().length(),'*');
2976   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
2977   if(glob)
2978     glob->simpleRepr(oss);
2979   else
2980     oss << "NO GLOBAL INFORMATION !\n";
2981 }
2982
2983 void MEDFileFieldGlobsReal::resetContent()
2984 {
2985   _globals=MEDFileFieldGlobs::New();
2986 }
2987
2988 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
2989 {
2990 }
2991
2992 /*!
2993  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
2994  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
2995  */
2996 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
2997 {
2998   _globals=other._globals;
2999 }
3000
3001 /*!
3002  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3003  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3004  */
3005 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other) throw(INTERP_KERNEL::Exception)
3006 {
3007   const MEDFileFieldGlobs *otherg(other._globals);
3008   if(!otherg)
3009     return ;
3010   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3011 }
3012
3013 /*!
3014  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3015  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3016  */
3017 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other) throw(INTERP_KERNEL::Exception)
3018 {
3019   const MEDFileFieldGlobs *otherg(other._globals);
3020   if(!otherg)
3021     return ;
3022   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3023 }
3024
3025 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3026 {
3027   _globals=other._globals;
3028   if((const MEDFileFieldGlobs *)_globals)
3029     _globals=other._globals->deepCpy();
3030 }
3031
3032 /*!
3033  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3034  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3035  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3036  *         \a this and \a other MEDFileFieldGlobsReal.
3037  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3038  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3039  */
3040 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps) throw(INTERP_KERNEL::Exception)
3041 {
3042   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3043   if(thisGlobals==otherGlobals)
3044     return ;
3045   if(!thisGlobals)
3046     {
3047       _globals=other._globals;
3048       return ;
3049     }
3050   _globals->appendGlobs(*other._globals,eps);
3051 }
3052
3053 void MEDFileFieldGlobsReal::checkGlobsCoherency() const throw(INTERP_KERNEL::Exception)
3054 {
3055   checkGlobsPflsPartCoherency();
3056   checkGlobsLocsPartCoherency();
3057 }
3058
3059 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const throw(INTERP_KERNEL::Exception)
3060 {
3061   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3062 }
3063
3064 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const throw(INTERP_KERNEL::Exception)
3065 {
3066   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3067 }
3068
3069 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
3070 {
3071   contentNotNull()->loadProfileInFile(fid,id,pflName);
3072 }
3073
3074 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3075 {
3076   contentNotNull()->loadProfileInFile(fid,id);
3077 }
3078
3079 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
3080 {
3081   contentNotNull()->loadGlobals(fid,*this);
3082 }
3083
3084 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
3085 {
3086   contentNotNull()->loadAllGlobals(fid);
3087 }
3088
3089 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
3090 {
3091   contentNotNull()->writeGlobals(fid,opt);
3092 }
3093
3094 /*!
3095  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3096  * or getPflsReallyUsedMulti().
3097  *  \return std::vector<std::string> - a sequence of names of all profiles.
3098  */
3099 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3100 {
3101   return contentNotNull()->getPfls();
3102 }
3103
3104 /*!
3105  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3106  * or getLocsReallyUsedMulti().
3107  *  \return std::vector<std::string> - a sequence of names of all localizations.
3108  */
3109 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3110 {
3111   return contentNotNull()->getLocs();
3112 }
3113
3114 /*!
3115  * Checks if the profile with a given name exists.
3116  *  \param [in] pflName - the profile name of interest.
3117  *  \return bool - \c true if the profile named \a pflName exists.
3118  */
3119 bool MEDFileFieldGlobsReal::existsPfl(const char *pflName) const
3120 {
3121   return contentNotNull()->existsPfl(pflName);
3122 }
3123
3124 /*!
3125  * Checks if the localization with a given name exists.
3126  *  \param [in] locName - the localization name of interest.
3127  *  \return bool - \c true if the localization named \a locName exists.
3128  */
3129 bool MEDFileFieldGlobsReal::existsLoc(const char *locName) const
3130 {
3131   return contentNotNull()->existsLoc(locName);
3132 }
3133
3134 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
3135 {
3136   return contentNotNull()->createNewNameOfPfl();
3137 }
3138
3139 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
3140 {
3141   return contentNotNull()->createNewNameOfLoc();
3142 }
3143
3144 /*!
3145  * Sets the name of a MED file.
3146  *  \param [inout] fileName - the file name.
3147  */
3148 void MEDFileFieldGlobsReal::setFileName(const char *fileName)
3149 {
3150   contentNotNull()->setFileName(fileName);
3151 }
3152
3153 /*!
3154  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3155  * in the same order.
3156  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3157  *          Each item of this sequence is a vector containing ids of equal profiles.
3158  */
3159 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3160 {
3161   return contentNotNull()->whichAreEqualProfiles();
3162 }
3163
3164 /*!
3165  * Finds equal localizations.
3166  *  \param [in] eps - a precision used to compare real values of the localizations.
3167  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3168  *          Each item of this sequence is a vector containing ids of equal localizations.
3169  */
3170 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3171 {
3172   return contentNotNull()->whichAreEqualLocs(eps);
3173 }
3174
3175 /*!
3176  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3177  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3178  *        this sequence is a pair whose 
3179  *        - the first item is a vector of profile names to replace by the second item,
3180  *        - the second item is a profile name to replace every profile name of the first item.
3181  */
3182 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3183 {
3184   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3185 }
3186
3187 /*!
3188  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3189  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3190  *        this sequence is a pair whose 
3191  *        - the first item is a vector of localization names to replace by the second item,
3192  *        - the second item is a localization name to replace every localization name of the first item.
3193  */
3194 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3195 {
3196   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3197 }
3198
3199 /*!
3200  * Replaces references to some profiles (a reference is a profile name) by references
3201  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3202  * them-selves accordingly. <br>
3203  * This method is a generalization of changePflName().
3204  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3205  *        this sequence is a pair whose 
3206  *        - the first item is a vector of profile names to replace by the second item,
3207  *        - the second item is a profile name to replace every profile of the first item.
3208  * \sa changePflsRefsNamesGen()
3209  * \sa changePflName()
3210  */
3211 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3212 {
3213   changePflsRefsNamesGen(mapOfModif);
3214   changePflsNamesInStruct(mapOfModif);
3215 }
3216
3217 /*!
3218  * Replaces references to some localizations (a reference is a localization name) by references
3219  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3220  * them-selves accordingly. <br>
3221  * This method is a generalization of changeLocName().
3222  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3223  *        this sequence is a pair whose 
3224  *        - the first item is a vector of localization names to replace by the second item,
3225  *        - the second item is a localization name to replace every localization of the first item.
3226  * \sa changeLocsRefsNamesGen()
3227  * \sa changeLocName()
3228  */
3229 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3230 {
3231   changeLocsRefsNamesGen(mapOfModif);
3232   changeLocsNamesInStruct(mapOfModif);
3233 }
3234
3235 /*!
3236  * Renames the profile having a given name and updates references to this profile.
3237  *  \param [in] oldName - the name of the profile to rename.
3238  *  \param [in] newName - a new name of the profile.
3239  * \sa changePflsNames().
3240  */
3241 void MEDFileFieldGlobsReal::changePflName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
3242 {
3243   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3244   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3245   mapOfModif[0]=p;
3246   changePflsNames(mapOfModif);
3247 }
3248
3249 /*!
3250  * Renames the localization having a given name and updates references to this localization.
3251  *  \param [in] oldName - the name of the localization to rename.
3252  *  \param [in] newName - a new name of the localization.
3253  * \sa changeLocsNames().
3254  */
3255 void MEDFileFieldGlobsReal::changeLocName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
3256 {
3257   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3258   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3259   mapOfModif[0]=p;
3260   changeLocsNames(mapOfModif);
3261 }
3262
3263 /*!
3264  * Removes duplicated profiles. Returns a map used to update references to removed 
3265  * profiles via changePflsRefsNamesGen().
3266  * Equal profiles are found using whichAreEqualProfiles().
3267  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3268  *          a sequence describing the performed replacements of profiles. Each element of
3269  *          this sequence is a pair whose
3270  *          - the first item is a vector of profile names replaced by the second item,
3271  *          - the second item is a profile name replacing every profile of the first item.
3272  */
3273 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames() throw(INTERP_KERNEL::Exception)
3274 {
3275   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3276   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3277   int i=0;
3278   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3279     {
3280       std::vector< std::string > tmp((*it).size());
3281       int j=0;
3282       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3283         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3284       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3285       ret[i]=p;
3286       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3287       killProfileIds(tmp2);
3288     }
3289   changePflsRefsNamesGen(ret);
3290   return ret;
3291 }
3292
3293 /*!
3294  * Removes duplicated localizations. Returns a map used to update references to removed 
3295  * localizations via changeLocsRefsNamesGen().
3296  * Equal localizations are found using whichAreEqualLocs().
3297  *  \param [in] eps - a precision used to compare real values of the localizations.
3298  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3299  *          a sequence describing the performed replacements of localizations. Each element of
3300  *          this sequence is a pair whose
3301  *          - the first item is a vector of localization names replaced by the second item,
3302  *          - the second item is a localization name replacing every localization of the first item.
3303  */
3304 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps) throw(INTERP_KERNEL::Exception)
3305 {
3306   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3307   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3308   int i=0;
3309   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3310     {
3311       std::vector< std::string > tmp((*it).size());
3312       int j=0;
3313       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3314         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3315       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3316       ret[i]=p;
3317       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3318       killLocalizationIds(tmp2);
3319     }
3320   changeLocsRefsNamesGen(ret);
3321   return ret;
3322 }
3323
3324 /*!
3325  * Returns number of Gauss points per cell in a given localization.
3326  *  \param [in] locId - an id of the localization of interest.
3327  *  \return int - the number of the Gauss points per cell.
3328  */
3329 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
3330 {
3331   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3332 }
3333
3334 /*!
3335  * Returns an id of a localization by its name.
3336  *  \param [in] loc - the localization name of interest.
3337  *  \return int - the id of the localization.
3338  *  \throw If there is no a localization named \a loc.
3339  */
3340 int MEDFileFieldGlobsReal::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
3341 {
3342   return contentNotNull()->getLocalizationId(loc);
3343 }
3344
3345 /*!
3346  * Returns the name of the MED file.
3347  *  \return const char * - the MED file name.
3348  */
3349 const char *MEDFileFieldGlobsReal::getFileName() const
3350 {
3351   return contentNotNull()->getFileName();
3352 }
3353
3354 std::string MEDFileFieldGlobsReal::getFileName2() const
3355 {
3356   return contentNotNull()->getFileName2();
3357 }
3358
3359 /*!
3360  * Returns a localization object by its name.
3361  *  \param [in] locName - the name of the localization of interest.
3362  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3363  *  \throw If there is no a localization named \a locName.
3364  */
3365 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
3366 {
3367   return contentNotNull()->getLocalization(locName);
3368 }
3369
3370 /*!
3371  * Returns a localization object by its id.
3372  *  \param [in] locId - the id of the localization of interest.
3373  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3374  *  \throw If there is no a localization with id \a locId.
3375  */
3376 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
3377 {
3378   return contentNotNull()->getLocalizationFromId(locId);
3379 }
3380
3381 /*!
3382  * Returns a profile array by its name.
3383  *  \param [in] pflName - the name of the profile of interest.
3384  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3385  *  \throw If there is no a profile named \a pflName.
3386  */
3387 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
3388 {
3389   return contentNotNull()->getProfile(pflName);
3390 }
3391
3392 /*!
3393  * Returns a profile array by its id.
3394  *  \param [in] pflId - the id of the profile of interest.
3395  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3396  *  \throw If there is no a profile with id \a pflId.
3397  */
3398 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
3399 {
3400   return contentNotNull()->getProfileFromId(pflId);
3401 }
3402
3403 /*!
3404  * Returns a localization object, apt for modification, by its id.
3405  *  \param [in] locId - the id of the localization of interest.
3406  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3407  *          having the id \a locId.
3408  *  \throw If there is no a localization with id \a locId.
3409  */
3410 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
3411 {
3412   return contentNotNull()->getLocalizationFromId(locId);
3413 }
3414
3415 /*!
3416  * Returns a localization object, apt for modification, by its name.
3417  *  \param [in] locName - the name of the localization of interest.
3418  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3419  *          having the name \a locName.
3420  *  \throw If there is no a localization named \a locName.
3421  */
3422 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
3423 {
3424   return contentNotNull()->getLocalization(locName);
3425 }
3426
3427 /*!
3428  * Returns a profile array, apt for modification, by its name.
3429  *  \param [in] pflName - the name of the profile of interest.
3430  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3431  *  \throw If there is no a profile named \a pflName.
3432  */
3433 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
3434 {
3435   return contentNotNull()->getProfile(pflName);
3436 }
3437
3438 /*!
3439  * Returns a profile array, apt for modification, by its id.
3440  *  \param [in] pflId - the id of the profile of interest.
3441  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3442  *  \throw If there is no a profile with id \a pflId.
3443  */
3444 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
3445 {
3446   return contentNotNull()->getProfileFromId(pflId);
3447 }
3448
3449 /*!
3450  * Removes profiles given by their ids. No data is updated to track this removal.
3451  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3452  */
3453 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
3454 {
3455   contentNotNull()->killProfileIds(pflIds);
3456 }
3457
3458 /*!
3459  * Removes localizations given by their ids. No data is updated to track this removal.
3460  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3461  */
3462 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
3463 {
3464   contentNotNull()->killLocalizationIds(locIds);
3465 }
3466
3467 /*!
3468  * Stores a profile array.
3469  *  \param [in] pfl - the profile array to store.
3470  *  \throw If the name of \a pfl is empty.
3471  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3472  *         different ids.
3473  */
3474 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
3475 {
3476   contentNotNull()->appendProfile(pfl);
3477 }
3478
3479 /*!
3480  * Adds a new localization of Gauss points.
3481  *  \param [in] locName - the name of the new localization.
3482  *  \param [in] geoType - a geometrical type of the reference cell.
3483  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3484  *         must be \c nbOfNodesPerCell * \c dimOfType.
3485  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3486  *         must be  _wg_.size() * \c dimOfType.
3487  *  \param [in] w - the weights of Gauss points.
3488  *  \throw If \a locName is empty.
3489  *  \throw If a localization with the name \a locName already exists but is
3490  *         different form the new one.
3491  */
3492 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)
3493 {
3494   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3495 }
3496
3497 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() throw(INTERP_KERNEL::Exception)
3498 {
3499   MEDFileFieldGlobs *g(_globals);
3500   if(!g)
3501     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3502   return g;
3503 }
3504
3505 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const throw(INTERP_KERNEL::Exception)
3506 {
3507   const MEDFileFieldGlobs *g(_globals);
3508   if(!g)
3509     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3510   return g;
3511 }
3512
3513 //= MEDFileFieldNameScope
3514
3515 MEDFileFieldNameScope::MEDFileFieldNameScope()
3516 {
3517 }
3518
3519 MEDFileFieldNameScope::MEDFileFieldNameScope(const char *fieldName):_name(fieldName)
3520 {
3521 }
3522
3523 /*!
3524  * Returns the name of \a this field.
3525  *  \return std::string - a string containing the field name.
3526  */
3527 std::string MEDFileFieldNameScope::getName() const throw(INTERP_KERNEL::Exception)
3528 {
3529   return _name;
3530 }
3531
3532 /*!
3533  * Sets name of \a this field
3534  *  \param [in] name - the new field name.
3535  */
3536 void MEDFileFieldNameScope::setName(const char *fieldName) throw(INTERP_KERNEL::Exception)
3537 {
3538   _name=fieldName;
3539 }
3540
3541 std::string MEDFileFieldNameScope::getDtUnit() const throw(INTERP_KERNEL::Exception)
3542 {
3543   return _dt_unit;
3544 }
3545
3546 void MEDFileFieldNameScope::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
3547 {
3548   _dt_unit=dtUnit;
3549 }
3550
3551 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3552 {
3553   _name=other._name;
3554   _dt_unit=other._dt_unit;
3555 }
3556
3557 //= MEDFileAnyTypeField1TSWithoutSDA
3558
3559 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other) throw(INTERP_KERNEL::Exception)
3560 {
3561   _field_per_mesh.resize(other._field_per_mesh.size());
3562   std::size_t i=0;
3563   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3564     {
3565       if((const MEDFileFieldPerMesh *)*it)
3566         _field_per_mesh[i]=(*it)->deepCpy(this);
3567     }
3568 }
3569
3570 /*!
3571  * Prints a string describing \a this field into a stream. This string is outputted 
3572  * by \c print Python command.
3573  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3574  *  \param [in,out] oss - the out stream.
3575  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3576  *          info id printed, else, not.
3577  */
3578 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3579 {
3580   std::string startOfLine(bkOffset,' ');
3581   oss << startOfLine << "Field ";
3582   if(bkOffset==0)
3583     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3584   oss << "on one time Step ";
3585   if(f1tsId>=0)
3586     oss << "(" << f1tsId << ") ";
3587   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3588   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3589   const DataArray *arr=getUndergroundDataArray();
3590   if(arr)
3591     {
3592       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3593       if(f1tsId<0)
3594         {
3595           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3596           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3597             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3598         }
3599       if(arr->isAllocated())
3600         {
3601           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3602         }
3603       else
3604         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3605     }
3606   else
3607     {
3608       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3609     }
3610   oss << startOfLine << "----------------------" << std::endl;
3611   if(!_field_per_mesh.empty())
3612     {
3613       int i=0;
3614       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3615         {
3616           const MEDFileFieldPerMesh *cur=(*it2);
3617           if(cur)
3618             cur->simpleRepr(bkOffset,oss,i);
3619           else
3620             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3621         }
3622     }
3623   else
3624     {
3625       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3626     }
3627   oss << startOfLine << "----------------------" << std::endl;
3628 }
3629
3630 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const throw(INTERP_KERNEL::Exception)
3631 {
3632   const DataArray *arr(getUndergroundDataArray());
3633   if(!arr)
3634     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3635   int nbOfCompo=arr->getNumberOfComponents();
3636   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3637   for(int i=0;i<nbOfCompo;i++)
3638     {
3639       ret[i]=deepCpy();
3640       std::vector<int> v(1,i);
3641       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3642       ret[i]->setArray(arr2);
3643     }
3644   return ret;
3645 }
3646
3647 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)
3648 {
3649 }
3650
3651 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3652 {
3653 }
3654
3655 /*!
3656  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3657  * empty. Returns -1 if this in on nodes.
3658  *  \return int - the dimension of \a this.
3659  */
3660 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3661 {
3662   int ret=-2;
3663   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3664     (*it)->getDimension(ret);
3665   return ret;
3666 }
3667
3668 /*!
3669  * Returns the mesh name.
3670  *  \return std::string - a string holding the mesh name.
3671  *  \throw If \c _field_per_mesh.empty()
3672  */
3673 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
3674 {
3675   if(_field_per_mesh.empty())
3676     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3677   return _field_per_mesh[0]->getMeshName();
3678 }
3679
3680 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
3681 {
3682   std::string oldName(getMeshName());
3683   std::vector< std::pair<std::string,std::string> > v(1);
3684   v[0].first=oldName; v[0].second=newMeshName;
3685   changeMeshNames(v);
3686 }
3687
3688 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
3689 {
3690   bool ret=false;
3691   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3692     {
3693       MEDFileFieldPerMesh *cur(*it);
3694       if(cur)
3695         ret=cur->changeMeshNames(modifTab) || ret;
3696     }
3697   return ret;
3698 }
3699
3700 /*!
3701  * Returns the number of iteration of the state of underlying mesh.
3702  *  \return int - the iteration number.
3703  *  \throw If \c _field_per_mesh.empty()
3704  */
3705 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const throw(INTERP_KERNEL::Exception)
3706 {
3707   if(_field_per_mesh.empty())
3708     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3709   return _field_per_mesh[0]->getMeshIteration();
3710 }
3711
3712 /*!
3713  * Returns the order number of iteration of the state of underlying mesh.
3714  *  \return int - the order number.
3715  *  \throw If \c _field_per_mesh.empty()
3716  */
3717 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const throw(INTERP_KERNEL::Exception)
3718 {
3719   if(_field_per_mesh.empty())
3720     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3721   return _field_per_mesh[0]->getMeshOrder();
3722 }
3723
3724 /*!
3725  * Checks if \a this field is tagged by a given iteration number and a given
3726  * iteration order number.
3727  *  \param [in] iteration - the iteration number of interest.
3728  *  \param [in] order - the iteration order number of interest.
3729  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3730  *          \a this->getOrder() == \a order.
3731  */
3732 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3733 {
3734   return iteration==_iteration && order==_order;
3735 }
3736
3737 /*!
3738  * Returns number of iteration and order number of iteration when
3739  * \a this field has been calculated.
3740  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3741  *          order number.
3742  */
3743 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3744 {
3745   std::pair<int,int> p;
3746   fillIteration(p);
3747   return p;
3748 }
3749
3750 /*!
3751  * Returns number of iteration and order number of iteration when
3752  * \a this field has been calculated.
3753  *  \param [in,out] p - a pair returning the iteration number and the iteration
3754  *          order number.
3755  */
3756 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3757 {
3758   p.first=_iteration;
3759   p.second=_order;
3760 }
3761
3762 /*!
3763  * Returns all types of spatial discretization of \a this field.
3764  *  \param [in,out] types - a sequence of types of \a this field.
3765  */
3766 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
3767 {
3768   std::set<TypeOfField> types2;
3769   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3770     {
3771       (*it)->fillTypesOfFieldAvailable(types2);
3772     }
3773   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3774   std::copy(types2.begin(),types2.end(),bi);
3775 }
3776
3777 /*!
3778  * Returns all types of spatial discretization of \a this field.
3779  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3780  *          of \a this field.
3781  */
3782 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
3783 {
3784   std::vector<TypeOfField> ret;
3785   fillTypesOfFieldAvailable(ret);
3786   return ret;
3787 }
3788
3789 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3790 {
3791   std::vector<std::string> ret;
3792   std::set<std::string> ret2;
3793   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3794     {
3795       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3796       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3797         if(ret2.find(*it2)==ret2.end())
3798           {
3799             ret.push_back(*it2);
3800             ret2.insert(*it2);
3801           }
3802     }
3803   return ret;
3804 }
3805
3806 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3807 {
3808   std::vector<std::string> ret;
3809   std::set<std::string> ret2;
3810   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3811     {
3812       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3813       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3814         if(ret2.find(*it2)==ret2.end())
3815           {
3816             ret.push_back(*it2);
3817             ret2.insert(*it2);
3818           }
3819     }
3820   return ret;
3821 }
3822
3823 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3824 {
3825   std::vector<std::string> ret;
3826   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3827     {
3828       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3829       ret.insert(ret.end(),tmp.begin(),tmp.end());
3830     }
3831   return ret;
3832 }
3833
3834 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3835 {
3836   std::vector<std::string> ret;
3837   std::set<std::string> ret2;
3838   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3839     {
3840       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3841       ret.insert(ret.end(),tmp.begin(),tmp.end());
3842     }
3843   return ret;
3844 }
3845
3846 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3847 {
3848   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3849     (*it)->changePflsRefsNamesGen(mapOfModif);
3850 }
3851
3852 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3853 {
3854   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3855     (*it)->changeLocsRefsNamesGen(mapOfModif);
3856 }
3857
3858 /*!
3859  * Returns all attributes of parts of \a this field lying on a given mesh.
3860  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3861  * item of every of returned sequences refers to the _i_-th part of \a this field.
3862  * Thus all sequences returned by this method are of the same length equal to number
3863  * of different types of supporting entities.<br>
3864  * A field part can include sub-parts with several different spatial discretizations,
3865  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3866  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3867  * of a nested sequence corresponds to a type of spatial discretization.<br>
3868  * This method allows for iteration over MEDFile DataStructure without any overhead.
3869  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3870  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3871  *          not checked if \a mname == \c NULL).
3872  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3873  *          a field part is returned. 
3874  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3875  *          This sequence is of the same length as \a types. 
3876  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3877  *          discretization. A profile name can be empty.
3878  *          Length of this and of nested sequences is the same as that of \a typesF.
3879  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3880  *          discretization. A localization name can be empty.
3881  *          Length of this and of nested sequences is the same as that of \a typesF.
3882  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3883  *          of ids of tuples within the data array, per each type of spatial
3884  *          discretization within one mesh entity type. 
3885  *          Length of this and of nested sequences is the same as that of \a typesF.
3886  *  \throw If no field is lying on \a mname.
3887  */
3888 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)
3889 {
3890   int meshId=0;
3891   if(mname)
3892     meshId=getMeshIdFromMeshName(mname);
3893   else
3894     if(_field_per_mesh.empty())
3895       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3896   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3897 }
3898
3899 /*!
3900  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
3901  * maximal absolute dimension and values returned via the out parameter \a levs are 
3902  * dimensions relative to the maximal absolute dimension. <br>
3903  * This method is designed for MEDFileField1TS instances that have a discretization
3904  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
3905  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
3906  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
3907  * Only these 3 discretizations will be taken into account here. If \a this is
3908  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
3909  * This method is useful to make the link between the dimension of the underlying mesh
3910  * and the levels of \a this, because it is possible that the highest dimension of \a this
3911  * field is not equal to the dimension of the underlying mesh.
3912  * 
3913  * Let's consider the following case:
3914  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
3915  * TETRA4, HEXA8, TRI3 and SEG2.
3916  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
3917  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
3918  *
3919  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
3920  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
3921  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
3922  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
3923  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
3924  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
3925  * For example<br>
3926  * to retrieve the highest level of
3927  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
3928  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
3929  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
3930  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
3931  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3932  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3933  *          not checked if \a mname == \c NULL).
3934  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
3935  *          absolute one. They are in decreasing order. This sequence is cleared before
3936  *          filling it in.
3937  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
3938  *  \throw If no field is lying on \a mname.
3939  */
3940 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
3941 {
3942   levs.clear();
3943   int meshId=getMeshIdFromMeshName(mname);
3944   std::vector<INTERP_KERNEL::NormalizedCellType> types;
3945   std::vector< std::vector<TypeOfField> > typesF;
3946   std::vector< std::vector<std::string> > pfls, locs;
3947   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3948   if(types.empty())
3949     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
3950   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
3951   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
3952     return -1;
3953   st.erase(INTERP_KERNEL::NORM_ERROR);
3954   std::set<int> ret1;
3955   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
3956     {
3957       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
3958       ret1.insert((int)cm.getDimension());
3959     }
3960   int ret=*std::max_element(ret1.begin(),ret1.end());
3961   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
3962   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
3963   return ret;
3964 }
3965
3966 /*!
3967  * \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.
3968  * \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.
3969  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3970  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3971  */
3972 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
3973 {
3974   int mid=getMeshIdFromMeshName(mName);
3975   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3976 }
3977
3978 /*!
3979  * \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.
3980  * \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.
3981  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3982  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3983  */
3984 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
3985 {
3986   int mid=getMeshIdFromMeshName(mName);
3987   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3988 }
3989
3990 /*!
3991  * \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.
3992  */
3993 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception)
3994 {
3995   if(_field_per_mesh.empty())
3996     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
3997   if(mName==0)
3998     return 0;
3999   std::string mName2(mName);
4000   int ret=0;
4001   std::vector<std::string> msg;
4002   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4003     if(mName2==(*it)->getMeshName())
4004       return ret;
4005     else
4006       msg.push_back((*it)->getMeshName());
4007   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4008   oss << "Possible meshes are : ";
4009   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4010     oss << "\"" << (*it2) << "\" ";
4011   throw INTERP_KERNEL::Exception(oss.str().c_str());
4012 }
4013
4014 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
4015 {
4016   if(!mesh)
4017     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4018   std::string tmp(mesh->getName());
4019   if(tmp.empty())
4020     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4021   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4022   int i=0;
4023   for(;it!=_field_per_mesh.end();it++,i++)
4024     {
4025       if((*it)->getMeshName()==tmp)
4026         return i;
4027     }
4028   int sz=_field_per_mesh.size();
4029   _field_per_mesh.resize(sz+1);
4030   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4031   return sz;
4032 }
4033
4034 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4035                                                             MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
4036 {
4037   bool ret=false;
4038   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4039     {
4040       MEDFileFieldPerMesh *fpm(*it);
4041       if(fpm)
4042         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4043     }
4044   return ret;
4045 }
4046
4047 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const throw(INTERP_KERNEL::Exception)
4048 {
4049   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4050   std::vector< std::vector<TypeOfField> > typesF;
4051   std::vector< std::vector<std::string> > pfls,locs;
4052   std::vector< std::vector<std::pair<int,int> > > bgEnd=getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs);
4053   std::set<TypeOfField> allEnt;
4054   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4055     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4056       allEnt.insert(*it2);
4057   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4058   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4059   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4060     {
4061       std::vector< std::pair<int,int> > its;
4062       ret[i]=shallowCpy();
4063       int newLgth=ret[i]->keepOnlySpatialDiscretization(*it3,its);
4064       ret[i]->updateData(newLgth,its);
4065     }
4066   return ret;
4067 }
4068
4069 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
4070 {
4071   int globalCounter=0;
4072   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4073     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4074   return globalCounter;
4075 }
4076
4077 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops) throw(INTERP_KERNEL::Exception)
4078 {
4079   if(_nb_of_tuples_to_be_allocated>=0)
4080     {
4081       _nb_of_tuples_to_be_allocated=newLgth;
4082       return ;
4083     }
4084   if(_nb_of_tuples_to_be_allocated==-1)
4085     return ;
4086   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4087     {
4088       const DataArray *oldArr=getUndergroundDataArray();
4089       if(!oldArr || !oldArr->isAllocated())
4090         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4091       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr=createNewEmptyDataArrayInstance();
4092       newArr->alloc(newLgth,getNumberOfComponents());
4093       int pos=0;
4094       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4095         {
4096           if((*it).second<(*it).first)
4097             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4098           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4099           pos+=(*it).second-(*it).first;
4100         }
4101       setArray(newArr);
4102       return ;
4103     }
4104   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4105 }
4106
4107 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4108 {
4109   if(_field_per_mesh.empty())
4110     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4111   if(_field_per_mesh.size()>1)
4112     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4113   _field_per_mesh[0]->copyOptionsFrom(opts);
4114   _field_per_mesh[0]->writeLL(fid,nasc);
4115 }
4116
4117 /*!
4118  * This methods returns true is the allocation has been needed leading to a modification of state in \a this->_nb_of_tuples_to_be_allocated.
4119  * If false is returned the memory allocation is not required.
4120  */
4121 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile() throw(INTERP_KERNEL::Exception)
4122 {
4123   if(_nb_of_tuples_to_be_allocated>=0)
4124     {
4125       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4126       _nb_of_tuples_to_be_allocated=-2;
4127       return true;
4128     }
4129   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4130     return false;
4131   if(_nb_of_tuples_to_be_allocated==-1)
4132     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4133   if(_nb_of_tuples_to_be_allocated<-3)
4134     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4135   
4136 }
4137
4138 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4139 {
4140   med_int numdt,numit;
4141   med_float dt;
4142   med_int nmesh;
4143   med_bool localMesh;
4144   med_int meshnumdt,meshnumit;
4145   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4146   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4147   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4148   if(_iteration!=numdt || _order!=numit)
4149     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4150   _field_per_mesh.resize(nmesh);
4151   for(int i=0;i<nmesh;i++)
4152     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i+1,meshnumdt,meshnumit,nasc);//tony
4153   _nb_of_tuples_to_be_allocated=0;
4154   for(int i=0;i<nmesh;i++)
4155     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4156 }
4157
4158 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4159 {
4160   allocIfNecessaryTheArrayToReceiveDataFromFile();
4161   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4162     (*it)->loadBigArraysRecursively(fid,nasc);
4163 }
4164
4165 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4166 {
4167   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4168     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4169       (*it)->loadBigArraysRecursively(fid,nasc);
4170 }
4171
4172 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4173 {
4174   loadOnlyStructureOfDataRecursively(fid,nasc);
4175   loadBigArraysRecursively(fid,nasc);
4176 }
4177
4178 void MEDFileAnyTypeField1TSWithoutSDA::releaseArrays() throw(INTERP_KERNEL::Exception)
4179 {
4180   DataArray *thisArr(getUndergroundDataArray());
4181   if(thisArr && thisArr->isAllocated())
4182     {
4183       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4184       thisArr->desallocate();
4185     }
4186 }
4187
4188 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySize() const
4189 {
4190   std::size_t ret=_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4191   if(getUndergroundDataArray())
4192     ret+=getUndergroundDataArray()->getHeapMemorySize();
4193   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4194     ret+=(*it)->getHeapMemorySize();
4195   return ret;
4196 }
4197
4198 /*!
4199  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4200  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4201  * "Sort By Type"), if not, an exception is thrown. 
4202  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4203  *  \param [in] arr - the array of values.
4204  *  \param [in,out] glob - the global data where profiles and localization present in
4205  *          \a field, if any, are added.
4206  *  \throw If the name of \a field is empty.
4207  *  \throw If the data array of \a field is not set.
4208  *  \throw If \a this->_arr is already allocated but has different number of components
4209  *         than \a field.
4210  *  \throw If the underlying mesh of \a field has no name.
4211  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4212  */
4213 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4214 {
4215   const MEDCouplingMesh *mesh=field->getMesh();
4216   //
4217   TypeOfField type=field->getTypeOfField();
4218   std::vector<DataArrayInt *> dummy;
4219   int start=copyTinyInfoFrom(field,arr);
4220   int pos=addNewEntryIfNecessary(mesh);
4221   if(type!=ON_NODES)
4222     {
4223       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4224       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4225     }
4226   else
4227     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4228 }
4229
4230 /*!
4231  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4232  * of a given mesh are used as the support of the given field (a real support is not used). 
4233  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4234  * Order of underlying mesh entities of the given field specified by \a profile parameter
4235  * is not prescribed; this method permutes field values to have them sorted by element
4236  * type as required for writing to MED file. A new profile is added only if no equal
4237  * profile is missing. 
4238  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4239  *  \param [in] arrOfVals - the values of the field \a field used.
4240  *  \param [in] mesh - the supporting mesh of \a field.
4241  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4242  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4243  *  \param [in,out] glob - the global data where profiles and localization present in
4244  *          \a field, if any, are added.
4245  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4246  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4247  *  \throw If the data array of \a field is not set.
4248  *  \throw If \a this->_arr is already allocated but has different number of components
4249  *         than \a field.
4250  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4251  *  \sa setFieldNoProfileSBT()
4252  */
4253 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)
4254 {
4255   if(!field)
4256     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4257   if(!arrOfVals || !arrOfVals->isAllocated())
4258     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4259   TypeOfField type=field->getTypeOfField();
4260   std::vector<DataArrayInt *> idsInPflPerType;
4261   std::vector<DataArrayInt *> idsPerType;
4262   std::vector<int> code,code2;
4263   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4264   if(type!=ON_NODES)
4265     {
4266       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4267       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4268       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4269       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin()); 
4270       //int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4271       /*if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4272         {
4273           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4274           throw INTERP_KERNEL::Exception(oss.str().c_str());
4275           }*/
4276       int start=copyTinyInfoFrom(field,arrOfVals);
4277       code2=m->getDistributionOfTypes();
4278       //
4279       int pos=addNewEntryIfNecessary(m);
4280       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4281     }
4282   else
4283     {
4284       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4285         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4286       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4287       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4288       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4289       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4290         {
4291           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4292           throw INTERP_KERNEL::Exception(oss.str().c_str());
4293         }
4294       int start=copyTinyInfoFrom(field,arrOfVals);
4295       int pos=addNewEntryIfNecessary(m);
4296       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4297     }
4298 }
4299
4300 /*!
4301  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4302  */
4303 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples) throw(INTERP_KERNEL::Exception)
4304 {
4305   if(_nb_of_tuples_to_be_allocated>=0)
4306     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 !");
4307   DataArray *arr(getOrCreateAndGetArray());
4308   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4309   _nb_of_tuples_to_be_allocated=-3;
4310 }
4311
4312 /*!
4313  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4314  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4315  * larger by the size of \a field. Returns an id of the first not filled
4316  * tuple of \a this->_arr.
4317  *  \param [in] field - the field to copy the info on components and the name from.
4318  *  \return int - the id of first not initialized tuple of \a this->_arr.
4319  *  \throw If the name of \a field is empty.
4320  *  \throw If the data array of \a field is not set.
4321  *  \throw If \a this->_arr is already allocated but has different number of components
4322  *         than \a field.
4323  */
4324 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
4325 {
4326   if(!field)
4327     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4328   std::string name(field->getName());
4329   setName(name.c_str());
4330   setDtUnit(field->getTimeUnit());
4331   if(name.empty())
4332     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4333   if(!arr)
4334     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4335   if(!arr->isAllocated())
4336     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4337   _dt=field->getTime(_iteration,_order);
4338   int nbOfComponents=arr->getNumberOfComponents();
4339   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4340   if(!getOrCreateAndGetArray()->isAllocated())
4341     {
4342       allocNotFromFile(arr->getNumberOfTuples());
4343       return 0;
4344     }
4345   else
4346     {
4347       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4348       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4349       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4350       _nb_of_tuples_to_be_allocated=-3;
4351       return oldNbOfTuples;
4352     }
4353 }
4354
4355 /*!
4356  * Returns number of components in \a this field
4357  *  \return int - the number of components.
4358  */
4359 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4360 {
4361   return getOrCreateAndGetArray()->getNumberOfComponents();
4362 }
4363
4364 /*!
4365  * Change info on components in \a this.
4366  * \throw If size of \a infos is not equal to the number of components already in \a this.
4367  */
4368 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
4369 {
4370   DataArray *arr=getOrCreateAndGetArray();
4371   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4372 }
4373
4374 /*!
4375  * Returns info on components of \a this field.
4376  *  \return const std::vector<std::string>& - a sequence of strings each being an
4377  *          information on _i_-th component.
4378  */
4379 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4380 {
4381   const DataArray *arr=getOrCreateAndGetArray();
4382   return arr->getInfoOnComponents();
4383 }
4384
4385 /*!
4386  * Returns a mutable info on components of \a this field.
4387  *  \return std::vector<std::string>& - a sequence of strings each being an
4388  *          information on _i_-th component.
4389  */
4390 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4391 {
4392   DataArray *arr=getOrCreateAndGetArray();
4393   return arr->getInfoOnComponents();
4394 }
4395
4396 /*!
4397  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4398  *  \param [in] type - a spatial discretization of the new field.
4399  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4400  *  \param [in] mName - a name of the supporting mesh.
4401  *  \param [in] renumPol - specifies how to permute values of the result field according to
4402  *          the optional numbers of cells and nodes, if any. The valid values are
4403  *          - 0 - do not permute.
4404  *          - 1 - permute cells.
4405  *          - 2 - permute nodes.
4406  *          - 3 - permute cells and nodes.
4407  *
4408  *  \param [in] glob - the global data storing profiles and localization.
4409  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4410  *          caller is to delete this field using decrRef() as it is no more needed. 
4411  *  \throw If the MED file is not readable.
4412  *  \throw If there is no mesh named \a mName in the MED file.
4413  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4414  *  \throw If no field of \a this is lying on the mesh \a mName.
4415  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4416  */
4417 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)
4418 {
4419   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4420   if(mName==0)
4421     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4422   else
4423     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4424   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4425 }
4426
4427 /*!
4428  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4429  *  \param [in] type - a spatial discretization of the new field.
4430  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4431  *  \param [in] renumPol - specifies how to permute values of the result field according to
4432  *          the optional numbers of cells and nodes, if any. The valid values are
4433  *          - 0 - do not permute.
4434  *          - 1 - permute cells.
4435  *          - 2 - permute nodes.
4436  *          - 3 - permute cells and nodes.
4437  *
4438  *  \param [in] glob - the global data storing profiles and localization.
4439  *  \param [in] mesh - the supporting mesh.
4440  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4441  *          caller is to delete this field using decrRef() as it is no more needed. 
4442  *  \throw If the MED file is not readable.
4443  *  \throw If no field of \a this is lying on \a mesh.
4444  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4445  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4446  */
4447 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)
4448 {
4449   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4450   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4451   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4452   if(meshDimRelToMax==1)
4453     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4454   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4455 }
4456
4457 /*!
4458  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4459  * given mesh. 
4460  *  \param [in] type - a spatial discretization of the new field.
4461  *  \param [in] mName - a name of the supporting mesh.
4462  *  \param [in] renumPol - specifies how to permute values of the result field according to
4463  *          the optional numbers of cells and nodes, if any. The valid values are
4464  *          - 0 - do not permute.
4465  *          - 1 - permute cells.
4466  *          - 2 - permute nodes.
4467  *          - 3 - permute cells and nodes.
4468  *
4469  *  \param [in] glob - the global data storing profiles and localization.
4470  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4471  *          caller is to delete this field using decrRef() as it is no more needed. 
4472  *  \throw If the MED file is not readable.
4473  *  \throw If there is no mesh named \a mName in the MED file.
4474  *  \throw If there are no mesh entities in the mesh.
4475  *  \throw If no field values of the given \a type are available.
4476  */
4477 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4478 {
4479    MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4480   if(mName==0)
4481     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4482   else
4483     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4484   int absDim=getDimension();
4485   int meshDimRelToMax=absDim-mm->getMeshDimension();
4486   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4487 }
4488
4489 /*!
4490  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4491  *  \param [in] type - a spatial discretization of the new field.
4492  *  \param [in] renumPol - specifies how to permute values of the result field according to
4493  *          the optional numbers of cells and nodes, if any. The valid values are
4494  *          - 0 - do not permute.
4495  *          - 1 - permute cells.
4496  *          - 2 - permute nodes.
4497  *          - 3 - permute cells and nodes.
4498  *
4499  *  \param [in] glob - the global data storing profiles and localization.
4500  *  \param [in] mesh - the supporting mesh.
4501  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4502  *         field according to \a renumPol.
4503  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4504  *         field according to \a renumPol.
4505  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4506  *          caller is to delete this field using decrRef() as it is no more needed. 
4507  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4508  *  \throw If no field of \a this is lying on \a mesh.
4509  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4510  */
4511 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)
4512 {
4513   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4514   int meshId=getMeshIdFromMeshName(mesh->getName());
4515   bool isPfl=false;
4516   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4517   switch(renumPol)
4518     {
4519     case 0:
4520       {
4521         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4522         return ret.retn();
4523       }
4524     case 3:
4525     case 1:
4526       {
4527         if(isPfl)
4528           throw INTERP_KERNEL::Exception(msg1);
4529         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4530         if(cellRenum)
4531           {
4532             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4533               {
4534                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4535                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4536                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4537               }
4538             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4539             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4540             std::vector<DataArray *> arrOut2(1,arrOut);
4541             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4542             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4543             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4544           }
4545         if(renumPol==1)
4546           return ret.retn();
4547       }
4548     case 2:
4549       {
4550         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4551         if(isPfl)
4552           throw INTERP_KERNEL::Exception(msg1);
4553         if(nodeRenum)
4554           {
4555             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4556               {
4557                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4558                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4559                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4560               }
4561             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4562             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4563               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4564             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4565           }
4566         return ret.retn();
4567       }
4568     default:
4569       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4570     }
4571 }
4572
4573 /*!
4574  * Returns values and a profile of the field of a given type lying on a given support.
4575  *  \param [in] type - a spatial discretization of the field.
4576  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4577  *  \param [in] mesh - the supporting mesh.
4578  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4579  *          field of interest lies on. If the field lies on all entities of the given
4580  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4581  *          using decrRef() as it is no more needed.  
4582  *  \param [in] glob - the global data storing profiles and localization.
4583  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4584  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4585  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4586  *  \throw If no field of \a this is lying on \a mesh.
4587  *  \throw If no field values of the given \a type are available.
4588  */
4589 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4590 {
4591   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4592   int meshId=getMeshIdFromMeshName(mesh->getName());
4593   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4594   ret->setName(nasc.getName().c_str());
4595   return ret.retn();
4596 }
4597
4598 //= MEDFileField1TSWithoutSDA
4599
4600 /*!
4601  * Throws if a given value is not a valid (non-extended) relative dimension.
4602  *  \param [in] meshDimRelToMax - the relative dimension value.
4603  *  \throw If \a meshDimRelToMax > 0.
4604  */
4605 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
4606 {
4607   if(meshDimRelToMax>0)
4608     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4609 }
4610
4611 /*!
4612  * Checks if elements of a given mesh are in the order suitable for writing 
4613  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4614  * vector describing types of elements and their number.
4615  *  \param [in] mesh - the mesh to check.
4616  *  \return std::vector<int> - a vector holding for each element type (1) item of
4617  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4618  *          These values are in full-interlace mode.
4619  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4620  */
4621 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
4622 {
4623   if(!mesh)
4624     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4625   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4626   int nbOfTypes=geoTypes.size();
4627   std::vector<int> code(3*nbOfTypes);
4628   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4629   arr1->alloc(nbOfTypes,1);
4630   int *arrPtr=arr1->getPointer();
4631   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4632   for(int i=0;i<nbOfTypes;i++,it++)
4633     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4634   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4635   const int *arrPtr2=arr2->getConstPointer();
4636   int i=0;
4637   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4638     {
4639       int pos=arrPtr2[i];
4640       int nbCells=mesh->getNumberOfCellsWithType(*it);
4641       code[3*pos]=(int)(*it);
4642       code[3*pos+1]=nbCells;
4643       code[3*pos+2]=-1;//no profiles
4644     }
4645   std::vector<const DataArrayInt *> idsPerType;//no profiles
4646   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4647   if(da)
4648     {
4649       da->decrRef();
4650       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4651     }
4652   return code;
4653 }
4654
4655 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const char *fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4656 {
4657   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4658 }
4659
4660 /*!
4661  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4662  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4663  * item of every of returned sequences refers to the _i_-th part of \a this field.
4664  * Thus all sequences returned by this method are of the same length equal to number
4665  * of different types of supporting entities.<br>
4666  * A field part can include sub-parts with several different spatial discretizations,
4667  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4668  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4669  * of a nested sequence corresponds to a type of spatial discretization.<br>
4670  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4671  * The overhead is due to selecting values into new instances of DataArrayDouble.
4672  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4673  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4674  *          not checked if \a mname == \c NULL).
4675  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4676  *          a field part is returned. 
4677  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4678  *          A field part can include sub-parts with several different spatial discretizations,
4679  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4680  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4681  *          This sequence is of the same length as \a types. 
4682  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4683  *          discretization. A profile name can be empty.
4684  *          Length of this and of nested sequences is the same as that of \a typesF.
4685  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4686  *          discretization. A localization name can be empty.
4687  *          Length of this and of nested sequences is the same as that of \a typesF.
4688  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4689  *          per each type of spatial discretization within one mesh entity type.
4690  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4691  *          Length of this and of nested sequences is the same as that of \a typesF.
4692  *  \throw If no field is lying on \a mname.
4693  */
4694 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)
4695 {
4696   int meshId=0;
4697   if(mname)
4698     meshId=getMeshIdFromMeshName(mname);
4699   else
4700     if(_field_per_mesh.empty())
4701       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4702   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4703   int nbOfRet=ret0.size();
4704   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4705   for(int i=0;i<nbOfRet;i++)
4706     {
4707       const std::vector< std::pair<int,int> >& p=ret0[i];
4708       int nbOfRet1=p.size();
4709       ret[i].resize(nbOfRet1);
4710       for(int j=0;j<nbOfRet1;j++)
4711         {
4712           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4713           ret[i][j]=tmp;
4714         }
4715     }
4716   return ret;
4717 }
4718
4719 /*!
4720  * Returns a pointer to the underground DataArrayDouble instance. So the
4721  * caller should not decrRef() it. This method allows for a direct access to the field
4722  * values. This method is quite unusable if there is more than a nodal field or a cell
4723  * field on single geometric cell type. 
4724  *  \return DataArrayDouble * - the pointer to the field values array.
4725  */
4726 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const throw(INTERP_KERNEL::Exception)
4727 {
4728   const DataArrayDouble *ret=_arr;
4729   if(ret)
4730     return const_cast<DataArrayDouble *>(ret);
4731   else
4732     return 0;
4733 }
4734
4735 const char *MEDFileField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
4736 {
4737   return TYPE_STR;
4738 }
4739
4740 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const throw(INTERP_KERNEL::Exception)
4741 {
4742   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
4743   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4744   ret->deepCpyLeavesFrom(*this);
4745   const DataArrayDouble *arr(_arr);
4746   if(arr)
4747     {
4748       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
4749       ret->setArray(arr2);
4750     }
4751   return ret.retn();
4752 }
4753
4754 /*!
4755  * Returns a pointer to the underground DataArrayDouble instance. So the
4756  * caller should not decrRef() it. This method allows for a direct access to the field
4757  * values. This method is quite unusable if there is more than a nodal field or a cell
4758  * field on single geometric cell type. 
4759  *  \return DataArrayDouble * - the pointer to the field values array.
4760  */
4761 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4762 {
4763   return getUndergroundDataArrayDouble();
4764 }
4765
4766 /*!
4767  * Returns a pointer to the underground DataArrayDouble instance and a
4768  * sequence describing parameters of a support of each part of \a this field. The
4769  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4770  * direct access to the field values. This method is intended for the field lying on one
4771  * mesh only.
4772  *  \param [in,out] entries - the sequence describing parameters of a support of each
4773  *         part of \a this field. Each item of this sequence consists of two parts. The
4774  *         first part describes a type of mesh entity and an id of discretization of a
4775  *         current field part. The second part describes a range of values [begin,end)
4776  *         within the returned array relating to the current field part.
4777  *  \return DataArrayDouble * - the pointer to the field values array.
4778  *  \throw If the number of underlying meshes is not equal to 1.
4779  *  \throw If no field values are available.
4780  *  \sa getUndergroundDataArray()
4781  */
4782 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4783 {
4784   if(_field_per_mesh.size()!=1)
4785     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4786   if(_field_per_mesh[0]==0)
4787     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4788   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4789   return getUndergroundDataArrayDouble();
4790 }
4791
4792 /*!
4793  * Returns a pointer to the underground DataArrayDouble instance and a
4794  * sequence describing parameters of a support of each part of \a this field. The
4795  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4796  * direct access to the field values. This method is intended for the field lying on one
4797  * mesh only.
4798  *  \param [in,out] entries - the sequence describing parameters of a support of each
4799  *         part of \a this field. Each item of this sequence consists of two parts. The
4800  *         first part describes a type of mesh entity and an id of discretization of a
4801  *         current field part. The second part describes a range of values [begin,end)
4802  *         within the returned array relating to the current field part.
4803  *  \return DataArrayDouble * - the pointer to the field values array.
4804  *  \throw If the number of underlying meshes is not equal to 1.
4805  *  \throw If no field values are available.
4806  *  \sa getUndergroundDataArray()
4807  */
4808 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4809 {
4810   return getUndergroundDataArrayDoubleExt(entries);
4811 }
4812
4813 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order,
4814                                                      const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4815 {
4816   DataArrayDouble *arr=getOrCreateAndGetArrayDouble();
4817   arr->setInfoAndChangeNbOfCompo(infos);
4818 }
4819
4820 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4821 {
4822 }
4823
4824 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
4825 {
4826   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
4827   ret->deepCpyLeavesFrom(*this);
4828   return ret.retn();
4829 }
4830
4831 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
4832 {
4833   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
4834   if((const DataArrayDouble *)_arr)
4835     ret->_arr=_arr->deepCpy();
4836   return ret.retn();
4837 }
4838
4839 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
4840 {
4841   if(!arr)
4842     {
4843       _nb_of_tuples_to_be_allocated=-1;
4844       _arr=0;
4845       return ;
4846     }
4847   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
4848   if(!arrC)
4849     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
4850   else
4851     _nb_of_tuples_to_be_allocated=-3;
4852   arrC->incrRef();
4853   _arr=arrC;
4854 }
4855
4856 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4857 {
4858   return DataArrayDouble::New();
4859 }
4860
4861 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
4862 {
4863   DataArrayDouble *ret=_arr;
4864   if(ret)
4865     return ret;
4866   _arr=DataArrayDouble::New();
4867   return _arr;
4868 }
4869
4870 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
4871 {
4872   return getOrCreateAndGetArrayDouble();
4873 }
4874
4875 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
4876 {
4877   const DataArrayDouble *ret=_arr;
4878   if(ret)
4879     return ret;
4880   DataArrayDouble *ret2=DataArrayDouble::New();
4881   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
4882   return ret2;
4883 }
4884
4885 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
4886 {
4887   return getOrCreateAndGetArrayDouble();
4888 }
4889
4890 //= MEDFileIntField1TSWithoutSDA
4891
4892 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const char *fieldName, int csit, int iteration, int order,
4893                                                                 const std::vector<std::string>& infos)
4894 {
4895   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4896 }
4897
4898 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4899 {
4900 }
4901
4902 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order,
4903                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4904 {
4905   DataArrayInt *arr=getOrCreateAndGetArrayInt();
4906   arr->setInfoAndChangeNbOfCompo(infos);
4907 }
4908
4909 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
4910 {
4911   return TYPE_STR;
4912 }
4913
4914 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const throw(INTERP_KERNEL::Exception)
4915 {
4916   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
4917   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4918   ret->deepCpyLeavesFrom(*this);
4919   const DataArrayInt *arr(_arr);
4920   if(arr)
4921     {
4922       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
4923       ret->setArray(arr2);
4924     }
4925   return ret.retn();
4926 }
4927
4928 /*!
4929  * Returns a pointer to the underground DataArrayInt instance. So the
4930  * caller should not decrRef() it. This method allows for a direct access to the field
4931  * values. This method is quite unusable if there is more than a nodal field or a cell
4932  * field on single geometric cell type. 
4933  *  \return DataArrayInt * - the pointer to the field values array.
4934  */
4935 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4936 {
4937   return getUndergroundDataArrayInt();
4938 }
4939
4940 /*!
4941  * Returns a pointer to the underground DataArrayInt instance. So the
4942  * caller should not decrRef() it. This method allows for a direct access to the field
4943  * values. This method is quite unusable if there is more than a nodal field or a cell
4944  * field on single geometric cell type. 
4945  *  \return DataArrayInt * - the pointer to the field values array.
4946  */
4947 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const throw(INTERP_KERNEL::Exception)
4948 {
4949   const DataArrayInt *ret=_arr;
4950   if(ret)
4951     return const_cast<DataArrayInt *>(ret);
4952   else
4953     return 0;
4954 }
4955
4956 /*!
4957  * Returns a pointer to the underground DataArrayInt instance and a
4958  * sequence describing parameters of a support of each part of \a this field. The
4959  * caller should not decrRef() the returned DataArrayInt. This method allows for a
4960  * direct access to the field values. This method is intended for the field lying on one
4961  * mesh only.
4962  *  \param [in,out] entries - the sequence describing parameters of a support of each
4963  *         part of \a this field. Each item of this sequence consists of two parts. The
4964  *         first part describes a type of mesh entity and an id of discretization of a
4965  *         current field part. The second part describes a range of values [begin,end)
4966  *         within the returned array relating to the current field part.
4967  *  \return DataArrayInt * - the pointer to the field values array.
4968  *  \throw If the number of underlying meshes is not equal to 1.
4969  *  \throw If no field values are available.
4970  *  \sa getUndergroundDataArray()
4971  */
4972 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4973 {
4974   return getUndergroundDataArrayIntExt(entries);
4975 }
4976
4977 /*!
4978  * Returns a pointer to the underground DataArrayInt instance and a
4979  * sequence describing parameters of a support of each part of \a this field. The
4980  * caller should not decrRef() the returned DataArrayInt. This method allows for a
4981  * direct access to the field values. This method is intended for the field lying on one
4982  * mesh only.
4983  *  \param [in,out] entries - the sequence describing parameters of a support of each
4984  *         part of \a this field. Each item of this sequence consists of two parts. The
4985  *         first part describes a type of mesh entity and an id of discretization of a
4986  *         current field part. The second part describes a range of values [begin,end)
4987  *         within the returned array relating to the current field part.
4988  *  \return DataArrayInt * - the pointer to the field values array.
4989  *  \throw If the number of underlying meshes is not equal to 1.
4990  *  \throw If no field values are available.
4991  *  \sa getUndergroundDataArray()
4992  */
4993 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4994 {
4995   if(_field_per_mesh.size()!=1)
4996     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4997   if(_field_per_mesh[0]==0)
4998     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4999   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5000   return getUndergroundDataArrayInt();
5001 }
5002
5003 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
5004 {
5005   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5006   ret->deepCpyLeavesFrom(*this);
5007   return ret.retn();
5008 }
5009
5010 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
5011 {
5012   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5013   if((const DataArrayInt *)_arr)
5014     ret->_arr=_arr->deepCpy();
5015   return ret.retn();
5016 }
5017
5018 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
5019 {
5020   if(!arr)
5021     {
5022       _nb_of_tuples_to_be_allocated=-1;
5023       _arr=0;
5024       return ;
5025     }
5026   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5027   if(!arrC)
5028     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5029   else
5030     _nb_of_tuples_to_be_allocated=-3;
5031   arrC->incrRef();
5032   _arr=arrC;
5033 }
5034
5035 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5036 {
5037   return DataArrayInt::New();
5038 }
5039
5040 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5041 {
5042   DataArrayInt *ret=_arr;
5043   if(ret)
5044     return ret;
5045   _arr=DataArrayInt::New();
5046   return _arr;
5047 }
5048
5049 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5050 {
5051   return getOrCreateAndGetArrayInt();
5052 }
5053
5054 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5055 {
5056   const DataArrayInt *ret=_arr;
5057   if(ret)
5058     return ret;
5059   DataArrayInt *ret2=DataArrayInt::New();
5060   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5061   return ret2;
5062 }
5063
5064 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5065 {
5066   return getOrCreateAndGetArrayInt();
5067 }
5068
5069 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5070 {
5071 }
5072
5073 //= MEDFileAnyTypeField1TS
5074
5075 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5076 {
5077   med_field_type typcha;
5078   //
5079   std::vector<std::string> infos;
5080   std::string dtunit,fieldName;
5081   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5082   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5083   switch(typcha)
5084     {
5085     case MED_FLOAT64:
5086       {
5087         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5088         break;
5089       }
5090     case MED_INT32:
5091       {
5092         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5093         break;
5094       }
5095     default:
5096       {
5097         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] !";
5098         throw INTERP_KERNEL::Exception(oss.str().c_str());
5099       }
5100     }
5101   ret->setDtUnit(dtunit.c_str());
5102   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5103   //
5104   med_int numdt,numit;
5105   med_float dt;
5106   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5107   ret->setTime(numdt,numit,dt);
5108   ret->_csit=1;
5109   if(loadAll)
5110     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5111   else
5112     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5113   return ret.retn();
5114 }
5115
5116 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5117 try:MEDFileFieldGlobsReal(fileName)
5118 {
5119   MEDFileUtilities::CheckFileForRead(fileName);
5120   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5121   _content=BuildContentFrom(fid,fileName,loadAll);
5122   loadGlobals(fid);
5123 }
5124 catch(INTERP_KERNEL::Exception& e)
5125   {
5126     throw e;
5127   }
5128
5129 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5130 {
5131   med_field_type typcha;
5132   std::vector<std::string> infos;
5133   std::string dtunit;
5134   int iii=-1;
5135   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5136   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5137   switch(typcha)
5138     {
5139     case MED_FLOAT64:
5140       {
5141         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5142         break;
5143       }
5144     case MED_INT32:
5145       {
5146         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5147         break;
5148       }
5149     default:
5150       {
5151         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] !";
5152         throw INTERP_KERNEL::Exception(oss.str().c_str());
5153       }
5154     }
5155   ret->setDtUnit(dtunit.c_str());
5156   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5157   //
5158   if(nbSteps<1)
5159     {
5160       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5161       throw INTERP_KERNEL::Exception(oss.str().c_str());
5162     }
5163   //
5164   med_int numdt,numit;
5165   med_float dt;
5166   MEDfieldComputingStepInfo(fid,fieldName,1,&numdt,&numit,&dt);
5167   ret->setTime(numdt,numit,dt);
5168   ret->_csit=1;
5169   if(loadAll)
5170     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5171   else
5172     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5173   return ret.retn();
5174 }
5175
5176 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5177 try:MEDFileFieldGlobsReal(fileName)
5178 {
5179   MEDFileUtilities::CheckFileForRead(fileName);
5180   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5181   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
5182   loadGlobals(fid);
5183 }
5184 catch(INTERP_KERNEL::Exception& e)
5185   {
5186     throw e;
5187   }
5188
5189 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const char *fileName) throw(INTERP_KERNEL::Exception)
5190 {
5191   if(!c)
5192     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5193   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5194     {
5195       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5196       ret->setFileName(fileName);
5197       ret->_content=c; c->incrRef();
5198       return ret.retn();
5199     }
5200   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5201     {
5202       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5203       ret->setFileName(fileName);
5204       ret->_content=c; c->incrRef();
5205       return ret.retn();
5206     }
5207   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5208 }
5209
5210 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5211 {
5212   MEDFileUtilities::CheckFileForRead(fileName);
5213   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5214   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
5215   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5216   ret->loadGlobals(fid);
5217   return ret.retn();
5218 }
5219
5220 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5221 {
5222   MEDFileUtilities::CheckFileForRead(fileName);
5223   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5224   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
5225   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5226   ret->loadGlobals(fid);
5227   return ret.retn();
5228 }
5229
5230 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5231 {
5232   MEDFileUtilities::CheckFileForRead(fileName);
5233   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5234   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll);
5235   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5236   ret->loadGlobals(fid);
5237   return ret.retn();
5238 }
5239
5240 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5241 {
5242   med_field_type typcha;
5243   std::vector<std::string> infos;
5244   std::string dtunit;
5245   int iii=-1;
5246   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5247   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5248   switch(typcha)
5249     {
5250     case MED_FLOAT64:
5251       {
5252         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5253         break;
5254       }
5255     case MED_INT32:
5256       {
5257         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5258         break;
5259       }
5260     default:
5261       {
5262         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] !";
5263         throw INTERP_KERNEL::Exception(oss.str().c_str());
5264       }
5265     }
5266   ret->setDtUnit(dtunit.c_str());
5267   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5268   //
5269   bool found=false;
5270   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5271   for(int i=0;i<nbOfStep2 && !found;i++)
5272     {
5273       med_int numdt,numit;
5274       med_float dt;
5275       MEDfieldComputingStepInfo(fid,fieldName,i+1,&numdt,&numit,&dt);
5276       if(numdt==iteration && numit==order)
5277         {
5278           found=true;
5279           ret->_csit=i+1;
5280         }
5281       else
5282         dtits[i]=std::pair<int,int>(numdt,numit);
5283     }
5284   if(!found)
5285     {
5286       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5287       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5288         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5289       throw INTERP_KERNEL::Exception(oss.str().c_str());
5290     }
5291   if(loadAll)
5292     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5293   else
5294     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5295   return ret.retn();
5296 }
5297
5298 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5299 try:MEDFileFieldGlobsReal(fileName)
5300 {
5301   MEDFileUtilities::CheckFileForRead(fileName);
5302   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5303   _content=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll);
5304   loadGlobals(fid);
5305 }
5306 catch(INTERP_KERNEL::Exception& e)
5307   {
5308     throw e;
5309   }
5310
5311 /*!
5312  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5313  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5314  *
5315  * \warning this is a shallow copy constructor
5316  */
5317 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5318 {
5319   if(!shallowCopyOfContent)
5320     {
5321       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5322       otherPtr->incrRef();
5323       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5324     }
5325   else
5326     {
5327       _content=other.shallowCpy();
5328     }
5329 }
5330
5331 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)
5332 {
5333   if(checkFieldId)
5334     {
5335       int nbFields=MEDnField(fid);
5336       if(fieldIdCFormat>=nbFields)
5337         {
5338           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5339           throw INTERP_KERNEL::Exception(oss.str().c_str());
5340         }
5341     }
5342   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5343   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5344   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5345   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5346   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5347   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5348   med_bool localMesh;
5349   int nbOfStep;
5350   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5351   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5352   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5353   infos.clear(); infos.resize(ncomp);
5354   for(int j=0;j<ncomp;j++)
5355     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5356   return nbOfStep;
5357 }
5358
5359 /*!
5360  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5361  * 
5362  * \param [out]
5363  * \return in case of success the number of time steps available for the field with name \a fieldName.
5364  */
5365 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)
5366 {
5367   int nbFields=MEDnField(fid);
5368   bool found=false;
5369   std::vector<std::string> fns(nbFields);
5370   int nbOfStep2=-1;
5371   for(int i=0;i<nbFields && !found;i++)
5372     {
5373       std::string tmp;
5374       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5375       fns[i]=tmp;
5376       found=(tmp==fieldName);
5377       if(found)
5378         posCFormat=i;
5379     }
5380   if(!found)
5381     {
5382       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5383       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5384         oss << "\"" << *it << "\" ";
5385       throw INTERP_KERNEL::Exception(oss.str().c_str());
5386     }
5387   return nbOfStep2;
5388 }
5389
5390 /*!
5391  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5392  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5393  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5394  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5395  * to keep a valid instance.
5396  * 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.
5397  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5398  * 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.
5399  *
5400  * \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.
5401  * \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.
5402  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5403  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5404  * \param [in] newLocName is the new localization name.
5405  * \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.
5406  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5407  */
5408 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newPflName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
5409 {
5410   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5411   std::string oldPflName=disc->getProfile();
5412   std::vector<std::string> vv=getPflsReallyUsedMulti();
5413   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5414   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5415     {
5416       disc->setProfile(newPflName);
5417       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5418       pfl->setName(newPflName);
5419     }
5420   else
5421     {
5422       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5423       throw INTERP_KERNEL::Exception(oss.str().c_str());
5424     }
5425 }
5426
5427 /*!
5428  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5429  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5430  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5431  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5432  * to keep a valid instance.
5433  * 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.
5434  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5435  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5436  * 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.
5437  *
5438  * \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.
5439  * \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.
5440  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5441  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5442  * \param [in] newLocName is the new localization name.
5443  * \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.
5444  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5445  */
5446 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newLocName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
5447 {
5448   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5449   std::string oldLocName=disc->getLocalization();
5450   std::vector<std::string> vv=getLocsReallyUsedMulti();
5451   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5452   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5453     {
5454       disc->setLocalization(newLocName);
5455       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5456       loc.setName(newLocName);
5457     }
5458   else
5459     {
5460       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5461       throw INTERP_KERNEL::Exception(oss.str().c_str());
5462     }
5463 }
5464
5465 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() throw(INTERP_KERNEL::Exception)
5466 {
5467   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5468   if(!ret)
5469     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5470   return ret;
5471 }
5472
5473 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const throw(INTERP_KERNEL::Exception)
5474 {
5475   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5476   if(!ret)
5477     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5478   return ret;
5479 }
5480
5481 /*!
5482  * Writes \a this field into a MED file specified by its name.
5483  *  \param [in] fileName - the MED file name.
5484  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5485  * - 2 - erase; an existing file is removed.
5486  * - 1 - append; same data should not be present in an existing file.
5487  * - 0 - overwrite; same data present in an existing file is overwritten.
5488  *  \throw If the field name is not set.
5489  *  \throw If no field data is set.
5490  *  \throw If \a mode == 1 and the same data is present in an existing file.
5491  */
5492 void MEDFileAnyTypeField1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
5493 {
5494   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5495   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
5496   writeLL(fid);
5497 }
5498
5499 /*!
5500  * This method alloc the arrays and load potentially huge arrays contained in this field.
5501  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5502  * This method can be also called to refresh or reinit values from a file.
5503  * 
5504  * \throw If the fileName is not set or points to a non readable MED file.
5505  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5506  */
5507 void MEDFileAnyTypeField1TS::loadArrays() throw(INTERP_KERNEL::Exception)
5508 {
5509   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
5510   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5511 }
5512
5513 /*!
5514  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5515  * But once data loaded once, this method does nothing.
5516  * 
5517  * \throw If the fileName is not set or points to a non readable MED file.
5518  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::releaseArrays
5519  */
5520 void MEDFileAnyTypeField1TS::loadArraysIfNecessary() throw(INTERP_KERNEL::Exception)
5521 {
5522   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
5523   contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5524 }
5525
5526 /*!
5527  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5528  * This method does not release arrays set outside the context of a MED file.
5529  * 
5530  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary
5531  */
5532 void MEDFileAnyTypeField1TS::releaseArrays() throw(INTERP_KERNEL::Exception)
5533 {
5534   contentNotNullBase()->releaseArrays();
5535 }
5536
5537 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
5538 {
5539   int nbComp=getNumberOfComponents();
5540   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5541   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5542   for(int i=0;i<nbComp;i++)
5543     {
5544       std::string info=getInfo()[i];
5545       std::string c,u;
5546       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5547       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5548       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5549     }
5550   if(getName().empty())
5551     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5552   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5553   writeGlobals(fid,*this);
5554   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5555 }
5556
5557 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySize() const
5558 {
5559   std::size_t ret=0;
5560   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5561     ret+=_content->getHeapMemorySize();
5562   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
5563 }
5564
5565 /*!
5566  * Returns a string describing \a this field. This string is outputted 
5567  * by \c print Python command.
5568  */
5569 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5570 {
5571   std::ostringstream oss;
5572   contentNotNullBase()->simpleRepr(0,oss,-1);
5573   simpleReprGlobs(oss);
5574   return oss.str();
5575 }
5576
5577 /*!
5578  * This method returns all profiles whose name is non empty used.
5579  * \b WARNING If profile is used several times it will be reported \b only \b once.
5580  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5581  */
5582 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5583 {
5584   return contentNotNullBase()->getPflsReallyUsed2();
5585 }
5586
5587 /*!
5588  * This method returns all localizations whose name is non empty used.
5589  * \b WARNING If localization is used several times it will be reported \b only \b once.
5590  */
5591 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5592 {
5593   return contentNotNullBase()->getLocsReallyUsed2();
5594 }
5595
5596 /*!
5597  * This method returns all profiles whose name is non empty used.
5598  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5599  */
5600 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5601 {
5602   return contentNotNullBase()->getPflsReallyUsedMulti2();
5603 }
5604
5605 /*!
5606  * This method returns all localizations whose name is non empty used.
5607  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5608  */
5609 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5610 {
5611   return contentNotNullBase()->getLocsReallyUsedMulti2();
5612 }
5613
5614 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5615 {
5616   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5617 }
5618
5619 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5620 {
5621   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5622 }
5623
5624 int MEDFileAnyTypeField1TS::getDimension() const
5625 {
5626   return contentNotNullBase()->getDimension();
5627 }
5628
5629 int MEDFileAnyTypeField1TS::getIteration() const
5630 {
5631   return contentNotNullBase()->getIteration();
5632 }
5633
5634 int MEDFileAnyTypeField1TS::getOrder() const
5635 {
5636   return contentNotNullBase()->getOrder();
5637 }
5638
5639 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5640 {
5641   return contentNotNullBase()->getTime(iteration,order);
5642 }
5643
5644 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5645 {
5646   contentNotNullBase()->setTime(iteration,order,val);
5647 }
5648
5649 std::string MEDFileAnyTypeField1TS::getName() const
5650 {
5651   return contentNotNullBase()->getName();
5652 }
5653
5654 void MEDFileAnyTypeField1TS::setName(const char *name)
5655 {
5656   contentNotNullBase()->setName(name);
5657 }
5658
5659 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5660 {
5661   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5662 }
5663
5664 std::string MEDFileAnyTypeField1TS::getDtUnit() const throw(INTERP_KERNEL::Exception)
5665 {
5666   return contentNotNullBase()->getDtUnit();
5667 }
5668
5669 void MEDFileAnyTypeField1TS::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
5670 {
5671   contentNotNullBase()->setDtUnit(dtUnit);
5672 }
5673
5674 std::string MEDFileAnyTypeField1TS::getMeshName() const throw(INTERP_KERNEL::Exception)
5675 {
5676   return contentNotNullBase()->getMeshName();
5677 }
5678
5679 void MEDFileAnyTypeField1TS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
5680 {
5681   contentNotNullBase()->setMeshName(newMeshName);
5682 }
5683
5684 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
5685 {
5686   return contentNotNullBase()->changeMeshNames(modifTab);
5687 }
5688
5689 int MEDFileAnyTypeField1TS::getMeshIteration() const throw(INTERP_KERNEL::Exception)
5690 {
5691   return contentNotNullBase()->getMeshIteration();
5692 }
5693
5694 int MEDFileAnyTypeField1TS::getMeshOrder() const throw(INTERP_KERNEL::Exception)
5695 {
5696   return contentNotNullBase()->getMeshOrder();
5697 }
5698
5699 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5700 {
5701   return contentNotNullBase()->getNumberOfComponents();
5702 }
5703
5704 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5705 {
5706   return contentNotNullBase()->isDealingTS(iteration,order);
5707 }
5708
5709 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5710 {
5711   return contentNotNullBase()->getDtIt();
5712 }
5713
5714 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5715 {
5716   contentNotNullBase()->fillIteration(p);
5717 }
5718
5719 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
5720 {
5721   contentNotNullBase()->fillTypesOfFieldAvailable(types);
5722 }
5723
5724 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
5725 {
5726   contentNotNullBase()->setInfo(infos);
5727 }
5728
5729 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
5730 {
5731   return contentNotNullBase()->getInfo();
5732 }
5733 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
5734 {
5735   return contentNotNullBase()->getInfo();
5736 }
5737
5738 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
5739 {
5740   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5741 }
5742
5743 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
5744 {
5745   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5746 }
5747
5748 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
5749 {
5750   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
5751 }
5752
5753 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
5754 {
5755   return contentNotNullBase()->getTypesOfFieldAvailable();
5756 }
5757
5758 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,
5759                                                                                        std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
5760 {
5761   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5762 }
5763
5764 /*!
5765  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
5766  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5767  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
5768  */
5769 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const throw(INTERP_KERNEL::Exception)
5770 {
5771   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5772   if(!content)
5773     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
5774   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
5775   std::size_t sz(contentsSplit.size());
5776   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5777   for(std::size_t i=0;i<sz;i++)
5778     {
5779       ret[i]=shallowCpy();
5780       ret[i]->_content=contentsSplit[i];
5781     }
5782   return ret;
5783 }
5784
5785 /*!
5786  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
5787  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5788  */
5789 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const throw(INTERP_KERNEL::Exception)
5790 {
5791   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5792   if(!content)
5793     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
5794   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitDiscretizations();
5795   std::size_t sz(contentsSplit.size());
5796   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5797   for(std::size_t i=0;i<sz;i++)
5798     {
5799       ret[i]=shallowCpy();
5800       ret[i]->_content=contentsSplit[i];
5801     }
5802   return ret;
5803 }
5804
5805 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const throw(INTERP_KERNEL::Exception)
5806 {
5807   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
5808   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5809     ret->_content=_content->deepCpy();
5810   ret->deepCpyGlobs(*this);
5811   return ret.retn();
5812 }
5813
5814 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
5815 {
5816   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
5817 }
5818
5819 //= MEDFileField1TS
5820
5821 /*!
5822  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5823  * the first field that has been read from a specified MED file.
5824  *  \param [in] fileName - the name of the MED file to read.
5825  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5826  *          is to delete this field using decrRef() as it is no more needed.
5827  *  \throw If reading the file fails.
5828  */
5829 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5830 {
5831   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,loadAll);
5832   ret->contentNotNull();
5833   return ret.retn();
5834 }
5835
5836 /*!
5837  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5838  * a given field that has been read from a specified MED file.
5839  *  \param [in] fileName - the name of the MED file to read.
5840  *  \param [in] fieldName - the name of the field to read.
5841  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5842  *          is to delete this field using decrRef() as it is no more needed.
5843  *  \throw If reading the file fails.
5844  *  \throw If there is no field named \a fieldName in the file.
5845  */
5846 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5847 {
5848   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,loadAll);
5849   ret->contentNotNull();
5850   return ret.retn();
5851 }
5852
5853 /*!
5854  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
5855  * a given field that has been read from a specified MED file.
5856  *  \param [in] fileName - the name of the MED file to read.
5857  *  \param [in] fieldName - the name of the field to read.
5858  *  \param [in] iteration - the iteration number of a required time step.
5859  *  \param [in] order - the iteration order number of required time step.
5860  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5861  *          is to delete this field using decrRef() as it is no more needed.
5862  *  \throw If reading the file fails.
5863  *  \throw If there is no field named \a fieldName in the file.
5864  *  \throw If the required time step is missing from the file.
5865  */
5866 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5867 {
5868   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll);
5869   ret->contentNotNull();
5870   return ret.retn();
5871 }
5872
5873 /*!
5874  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5875  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5876  *
5877  * Returns a new instance of MEDFileField1TS holding either a shallow copy
5878  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
5879  * \warning this is a shallow copy constructor
5880  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
5881  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
5882  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5883  *          is to delete this field using decrRef() as it is no more needed.
5884  */
5885 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
5886 {
5887   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
5888   ret->contentNotNull();
5889   return ret.retn();
5890 }
5891
5892 /*!
5893  * Returns a new empty instance of MEDFileField1TS.
5894  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5895  *          is to delete this field using decrRef() as it is no more needed.
5896  */
5897 MEDFileField1TS *MEDFileField1TS::New()
5898 {
5899   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
5900   ret->contentNotNull();
5901   return ret.retn();
5902 }
5903
5904 /*!
5905  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
5906  * following the given input policy.
5907  *
5908  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
5909  *                            By default (true) the globals are deeply copied.
5910  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
5911  */
5912 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
5913 {
5914   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
5915   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5916   if(content)
5917     {
5918       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
5919       if(!contc)
5920         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
5921       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
5922       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
5923     }
5924   else
5925     ret=MEDFileIntField1TS::New();
5926   if(deepCpyGlobs)
5927     ret->deepCpyGlobs(*this);
5928   else
5929     ret->shallowCpyGlobs(*this);
5930   return ret.retn();
5931 }
5932
5933 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const throw(INTERP_KERNEL::Exception)
5934 {
5935   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
5936   if(!pt)
5937     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
5938   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
5939   if(!ret)
5940     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 !");
5941   return ret;
5942 }
5943
5944 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() throw(INTERP_KERNEL::Exception)
5945 {
5946   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
5947   if(!pt)
5948     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
5949   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
5950   if(!ret)
5951     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 !");
5952   return ret;
5953 }
5954
5955 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
5956 {
5957   if(!f)
5958     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
5959   if(!((DataArray*)arr))
5960     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
5961   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
5962   if(!arrOutC)
5963     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
5964   f->setArray(arrOutC);
5965 }
5966
5967 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
5968 {
5969   if(!((DataArray*)arr))
5970     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
5971   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
5972   if(!arrOutC)
5973     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
5974   arrOutC->incrRef();
5975   return arrOutC;
5976 }
5977
5978 MEDFileField1TS::MEDFileField1TS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5979 try:MEDFileAnyTypeField1TS(fileName,loadAll)
5980 {
5981 }
5982 catch(INTERP_KERNEL::Exception& e)
5983   { throw e; }
5984
5985 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5986 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
5987 {
5988 }
5989 catch(INTERP_KERNEL::Exception& e)
5990   { throw e; }
5991
5992 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5993 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
5994 {
5995 }
5996 catch(INTERP_KERNEL::Exception& e)
5997   { throw e; }
5998
5999 /*!
6000  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6001  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6002  *
6003  * \warning this is a shallow copy constructor
6004  */
6005 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6006 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6007 {
6008 }
6009 catch(INTERP_KERNEL::Exception& e)
6010   { throw e; }
6011
6012 MEDFileField1TS::MEDFileField1TS()
6013 {
6014   _content=new MEDFileField1TSWithoutSDA;
6015 }
6016
6017 /*!
6018  * Returns a new MEDCouplingFieldDouble of a given type lying on
6019  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6020  * has not been constructed via file reading, an exception is thrown.
6021  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6022  *  \param [in] type - a spatial discretization of interest.
6023  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6024  *  \param [in] renumPol - specifies how to permute values of the result field according to
6025  *          the optional numbers of cells and nodes, if any. The valid values are
6026  *          - 0 - do not permute.
6027  *          - 1 - permute cells.
6028  *          - 2 - permute nodes.
6029  *          - 3 - permute cells and nodes.
6030  *
6031  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6032  *          caller is to delete this field using decrRef() as it is no more needed. 
6033  *  \throw If \a this field has not been constructed via file reading.
6034  *  \throw If the MED file is not readable.
6035  *  \throw If there is no mesh in the MED file.
6036  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6037  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6038  *  \sa getFieldOnMeshAtLevel()
6039  */
6040 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
6041 {
6042   if(getFileName2().empty())
6043     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6044   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6045   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut,*contentNotNull());
6046   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6047   return ret.retn();
6048 }
6049
6050 /*!
6051  * Returns a new MEDCouplingFieldDouble of a given type lying on
6052  * the top level cells of the first mesh in MED file. If \a this field 
6053  * has not been constructed via file reading, an exception is thrown.
6054  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6055  *  \param [in] type - a spatial discretization of interest.
6056  *  \param [in] renumPol - specifies how to permute values of the result field according to
6057  *          the optional numbers of cells and nodes, if any. The valid values are
6058  *          - 0 - do not permute.
6059  *          - 1 - permute cells.
6060  *          - 2 - permute nodes.
6061  *          - 3 - permute cells and nodes.
6062  *
6063  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6064  *          caller is to delete this field using decrRef() as it is no more needed. 
6065  *  \throw If \a this field has not been constructed via file reading.
6066  *  \throw If the MED file is not readable.
6067  *  \throw If there is no mesh in the MED file.
6068  *  \throw If no field values of the given \a type.
6069  *  \throw If no field values lying on the top level support.
6070  *  \sa getFieldAtLevel()
6071  */
6072 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const throw(INTERP_KERNEL::Exception)
6073 {
6074   if(getFileName2().empty())
6075     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6076   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6077   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,0,renumPol,this,arrOut,*contentNotNull());
6078   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6079   return ret.retn();
6080 }
6081
6082 /*!
6083  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6084  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6085  *  \param [in] type - a spatial discretization of the new field.
6086  *  \param [in] mesh - the supporting mesh.
6087  *  \param [in] renumPol - specifies how to permute values of the result field according to
6088  *          the optional numbers of cells and nodes, if any. The valid values are
6089  *          - 0 - do not permute.
6090  *          - 1 - permute cells.
6091  *          - 2 - permute nodes.
6092  *          - 3 - permute cells and nodes.
6093  *
6094  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6095  *          caller is to delete this field using decrRef() as it is no more needed. 
6096  *  \throw If no field of \a this is lying on \a mesh.
6097  *  \throw If the mesh is empty.
6098  *  \throw If no field values of the given \a type are available.
6099  *  \sa getFieldAtLevel()
6100  *  \sa getFieldOnMeshAtLevel() 
6101  */
6102 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
6103 {
6104   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6105   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6106   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6107   return ret.retn();
6108 }
6109
6110 /*!
6111  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6112  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6113  *  \param [in] type - a spatial discretization of interest.
6114  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6115  *  \param [in] mesh - the supporting mesh.
6116  *  \param [in] renumPol - specifies how to permute values of the result field according to
6117  *          the optional numbers of cells and nodes, if any. The valid values are
6118  *          - 0 - do not permute.
6119  *          - 1 - permute cells.
6120  *          - 2 - permute nodes.
6121  *          - 3 - permute cells and nodes.
6122  *
6123  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6124  *          caller is to delete this field using decrRef() as it is no more needed. 
6125  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6126  *  \throw If no field of \a this is lying on \a mesh.
6127  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6128  *  \sa getFieldAtLevel()
6129  *  \sa getFieldOnMeshAtLevel() 
6130  */
6131 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
6132 {
6133   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6134   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6135   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6136   return ret.retn();
6137 }
6138
6139 /*!
6140  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6141  * This method is called "Old" because in MED3 norm a field has only one meshName
6142  * attached, so this method is for readers of MED2 files. If \a this field 
6143  * has not been constructed via file reading, an exception is thrown.
6144  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6145  *  \param [in] type - a spatial discretization of interest.
6146  *  \param [in] mName - a name of the supporting mesh.
6147  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6148  *  \param [in] renumPol - specifies how to permute values of the result field according to
6149  *          the optional numbers of cells and nodes, if any. The valid values are
6150  *          - 0 - do not permute.
6151  *          - 1 - permute cells.
6152  *          - 2 - permute nodes.
6153  *          - 3 - permute cells and nodes.
6154  *
6155  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6156  *          caller is to delete this field using decrRef() as it is no more needed. 
6157  *  \throw If the MED file is not readable.
6158  *  \throw If there is no mesh named \a mName in the MED file.
6159  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6160  *  \throw If \a this field has not been constructed via file reading.
6161  *  \throw If no field of \a this is lying on the mesh named \a mName.
6162  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6163  *  \sa getFieldAtLevel()
6164  */
6165 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
6166 {
6167   if(getFileName2().empty())
6168     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6169   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6170   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6171   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6172   return ret.retn();
6173 }
6174
6175 /*!
6176  * Returns values and a profile of the field of a given type lying on a given support.
6177  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6178  *  \param [in] type - a spatial discretization of the field.
6179  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6180  *  \param [in] mesh - the supporting mesh.
6181  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6182  *          field of interest lies on. If the field lies on all entities of the given
6183  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6184  *          using decrRef() as it is no more needed.  
6185  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6186  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6187  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6188  *  \throw If no field of \a this is lying on \a mesh.
6189  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6190  */
6191 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
6192 {
6193   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6194   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6195 }
6196
6197 /*!
6198  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6199  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6200  * "Sort By Type"), if not, an exception is thrown. 
6201  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6202  *  \param [in] field - the field to add to \a this.
6203  *  \throw If the name of \a field is empty.
6204  *  \throw If the data array of \a field is not set.
6205  *  \throw If the data array is already allocated but has different number of components
6206  *         than \a field.
6207  *  \throw If the underlying mesh of \a field has no name.
6208  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6209  */
6210 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
6211 {
6212   setFileName("");
6213   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6214 }
6215
6216 /*!
6217  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
6218  * of a given mesh are used as the support of the given field (a real support is not used). 
6219  * Elements of the given mesh must be sorted suitable for writing to MED file.
6220  * Order of underlying mesh entities of the given field specified by \a profile parameter
6221  * is not prescribed; this method permutes field values to have them sorted by element
6222  * type as required for writing to MED file. A new profile is added only if no equal
6223  * profile is missing.
6224  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6225  *  \param [in] field - the field to add to \a this.
6226  *  \param [in] mesh - the supporting mesh of \a field.
6227  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
6228  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6229  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6230  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6231  *  \throw If the data array of \a field is not set.
6232  *  \throw If the data array of \a this is already allocated but has different number of
6233  *         components than \a field.
6234  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6235  *  \sa setFieldNoProfileSBT()
6236  */
6237 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
6238 {
6239   setFileName("");
6240   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6241 }
6242
6243 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const throw(INTERP_KERNEL::Exception)
6244 {
6245   return new MEDFileField1TS(*this);
6246 }
6247
6248 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
6249 {
6250   return contentNotNull()->getUndergroundDataArrayDouble();
6251 }
6252
6253 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
6254 {
6255   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6256 }
6257
6258 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6259                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
6260 {
6261   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6262 }
6263
6264 //= MEDFileIntField1TS
6265
6266 MEDFileIntField1TS *MEDFileIntField1TS::New()
6267 {
6268   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6269   ret->contentNotNull();
6270   return ret.retn();
6271 }
6272
6273 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
6274 {
6275   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,loadAll);
6276   ret->contentNotNull();
6277   return ret.retn();
6278 }
6279
6280 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
6281 {
6282   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,loadAll);
6283   ret->contentNotNull();
6284   return ret.retn();
6285 }
6286
6287 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
6288 {
6289   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll);
6290   ret->contentNotNull();
6291   return ret.retn();
6292 }
6293
6294 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6295 {
6296   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6297   ret->contentNotNull();
6298   return ret.retn();
6299 }
6300
6301 MEDFileIntField1TS::MEDFileIntField1TS()
6302 {
6303   _content=new MEDFileIntField1TSWithoutSDA;
6304 }
6305
6306 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
6307 try:MEDFileAnyTypeField1TS(fileName,loadAll)
6308 {
6309 }
6310 catch(INTERP_KERNEL::Exception& e)
6311   { throw e; }
6312
6313 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
6314 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
6315 {
6316 }
6317 catch(INTERP_KERNEL::Exception& e)
6318   { throw e; }
6319
6320 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
6321 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
6322 {
6323 }
6324 catch(INTERP_KERNEL::Exception& e)
6325   { throw e; }
6326
6327 /*!
6328  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6329  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6330  *
6331  * \warning this is a shallow copy constructor
6332  */
6333 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6334 {
6335 }
6336
6337 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const throw(INTERP_KERNEL::Exception)
6338 {
6339   return new MEDFileIntField1TS(*this);
6340 }
6341
6342 /*!
6343  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6344  * following the given input policy.
6345  *
6346  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6347  *                            By default (true) the globals are deeply copied.
6348  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6349  */
6350 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
6351 {
6352   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6353   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6354   if(content)
6355     {
6356       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6357       if(!contc)
6358         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6359       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6360       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6361     }
6362   else
6363     ret=MEDFileField1TS::New();
6364   if(deepCpyGlobs)
6365     ret->deepCpyGlobs(*this);
6366   else
6367     ret->shallowCpyGlobs(*this);
6368   return ret.retn();
6369 }
6370
6371 /*!
6372  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6373  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6374  * "Sort By Type"), if not, an exception is thrown. 
6375  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6376  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6377  *  \param [in] arrOfVals - the values of the field \a field used.
6378  *  \throw If the name of \a field is empty.
6379  *  \throw If the data array of \a field is not set.
6380  *  \throw If the data array is already allocated but has different number of components
6381  *         than \a field.
6382  *  \throw If the underlying mesh of \a field has no name.
6383  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6384  */
6385 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception)
6386 {
6387   setFileName("");
6388   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6389 }
6390
6391 /*!
6392  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
6393  * of a given mesh are used as the support of the given field (a real support is not used). 
6394  * Elements of the given mesh must be sorted suitable for writing to MED file.
6395  * Order of underlying mesh entities of the given field specified by \a profile parameter
6396  * is not prescribed; this method permutes field values to have them sorted by element
6397  * type as required for writing to MED file. A new profile is added only if no equal
6398  * profile is missing.
6399  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6400  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6401  *  \param [in] arrOfVals - the values of the field \a field used.
6402  *  \param [in] mesh - the supporting mesh of \a field.
6403  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
6404  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6405  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6406  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6407  *  \throw If the data array of \a field is not set.
6408  *  \throw If the data array of \a this is already allocated but has different number of
6409  *         components than \a field.
6410  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6411  *  \sa setFieldNoProfileSBT()
6412  */
6413 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
6414 {
6415   setFileName("");
6416   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6417 }
6418
6419 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const throw(INTERP_KERNEL::Exception)
6420 {
6421   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6422   if(!pt)
6423     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6424   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6425   if(!ret)
6426     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 !");
6427   return ret;
6428 }
6429
6430 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6431 {
6432   if(getFileName2().empty())
6433     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6434   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6435   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut2,*contentNotNull());
6436   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6437   if(!arrOutC)
6438     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6439   arrOut=arrOutC;
6440   return ret.retn();
6441 }
6442
6443 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
6444 {
6445   if(!((DataArray *)arr))
6446     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6447   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6448   if(!arrC)
6449     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6450   arrC->incrRef();
6451   return arrC;
6452 }
6453
6454 /*!
6455  * Returns a new MEDCouplingFieldDouble of a given type lying on
6456  * the top level cells of the first mesh in MED file. If \a this field 
6457  * has not been constructed via file reading, an exception is thrown.
6458  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6459  *  \param [in] type - a spatial discretization of interest.
6460  *  \param [out] arrOut - the DataArrayInt containing values of field.
6461  *  \param [in] renumPol - specifies how to permute values of the result field according to
6462  *          the optional numbers of cells and nodes, if any. The valid values are
6463  *          - 0 - do not permute.
6464  *          - 1 - permute cells.
6465  *          - 2 - permute nodes.
6466  *          - 3 - permute cells and nodes.
6467  *
6468  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6469  *          caller is to delete this field using decrRef() as it is no more needed. 
6470  *  \throw If \a this field has not been constructed via file reading.
6471  *  \throw If the MED file is not readable.
6472  *  \throw If there is no mesh in the MED file.
6473  *  \throw If no field values of the given \a type.
6474  *  \throw If no field values lying on the top level support.
6475  *  \sa getFieldAtLevel()
6476  */
6477 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6478 {
6479   if(getFileName2().empty())
6480     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6481   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6482   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,0,renumPol,this,arr,*contentNotNull());
6483   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6484   return ret.retn();
6485 }
6486
6487 /*!
6488  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6489  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6490  *  \param [in] type - a spatial discretization of the new field.
6491  *  \param [in] mesh - the supporting mesh.
6492  *  \param [out] arrOut - the DataArrayInt containing values of field.
6493  *  \param [in] renumPol - specifies how to permute values of the result field according to
6494  *          the optional numbers of cells and nodes, if any. The valid values are
6495  *          - 0 - do not permute.
6496  *          - 1 - permute cells.
6497  *          - 2 - permute nodes.
6498  *          - 3 - permute cells and nodes.
6499  *
6500  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6501  *          caller is to delete this field using decrRef() as it is no more needed. 
6502  *  \throw If no field of \a this is lying on \a mesh.
6503  *  \throw If the mesh is empty.
6504  *  \throw If no field values of the given \a type are available.
6505  *  \sa getFieldAtLevel()
6506  *  \sa getFieldOnMeshAtLevel() 
6507  */
6508 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6509 {
6510   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6511   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6512   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6513   return ret.retn();
6514 }
6515
6516 /*!
6517  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6518  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6519  *  \param [in] type - a spatial discretization of interest.
6520  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6521  *  \param [out] arrOut - the DataArrayInt containing values of field.
6522  *  \param [in] mesh - the supporting mesh.
6523  *  \param [in] renumPol - specifies how to permute values of the result field according to
6524  *          the optional numbers of cells and nodes, if any. The valid values are
6525  *          - 0 - do not permute.
6526  *          - 1 - permute cells.
6527  *          - 2 - permute nodes.
6528  *          - 3 - permute cells and nodes.
6529  *
6530  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6531  *          caller is to delete this field using decrRef() as it is no more needed. 
6532  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6533  *  \throw If no field of \a this is lying on \a mesh.
6534  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6535  *  \sa getFieldAtLevel()
6536  *  \sa getFieldOnMeshAtLevel() 
6537  */
6538 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6539 {
6540   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6541   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6542   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6543   return ret.retn();
6544 }
6545
6546 /*!
6547  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6548  * This method is called "Old" because in MED3 norm a field has only one meshName
6549  * attached, so this method is for readers of MED2 files. If \a this field 
6550  * has not been constructed via file reading, an exception is thrown.
6551  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6552  *  \param [in] type - a spatial discretization of interest.
6553  *  \param [in] mName - a name of the supporting mesh.
6554  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6555  *  \param [out] arrOut - the DataArrayInt containing values of field.
6556  *  \param [in] renumPol - specifies how to permute values of the result field according to
6557  *          the optional numbers of cells and nodes, if any. The valid values are
6558  *          - 0 - do not permute.
6559  *          - 1 - permute cells.
6560  *          - 2 - permute nodes.
6561  *          - 3 - permute cells and nodes.
6562  *
6563  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6564  *          caller is to delete this field using decrRef() as it is no more needed. 
6565  *  \throw If the MED file is not readable.
6566  *  \throw If there is no mesh named \a mName in the MED file.
6567  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6568  *  \throw If \a this field has not been constructed via file reading.
6569  *  \throw If no field of \a this is lying on the mesh named \a mName.
6570  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6571  *  \sa getFieldAtLevel()
6572  */
6573 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6574 {
6575   if(getFileName2().empty())
6576     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6577   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6578   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6579   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6580   return ret.retn();
6581 }
6582
6583 /*!
6584  * Returns values and a profile of the field of a given type lying on a given support.
6585  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6586  *  \param [in] type - a spatial discretization of the field.
6587  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6588  *  \param [in] mesh - the supporting mesh.
6589  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6590  *          field of interest lies on. If the field lies on all entities of the given
6591  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6592  *          using decrRef() as it is no more needed.  
6593  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6594  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6595  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6596  *  \throw If no field of \a this is lying on \a mesh.
6597  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6598  */
6599 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
6600 {
6601   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6602   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6603 }
6604
6605 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() throw(INTERP_KERNEL::Exception)
6606 {
6607   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6608   if(!pt)
6609     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6610   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6611   if(!ret)
6612     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 !");
6613   return ret;
6614 }
6615
6616 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
6617 {
6618   return contentNotNull()->getUndergroundDataArrayInt();
6619 }
6620
6621 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6622
6623 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6624 {
6625 }
6626
6627 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const char *fieldName):MEDFileFieldNameScope(fieldName)
6628 {
6629 }
6630
6631 /*!
6632  * \param [in] fieldId field id in C mode
6633  */
6634 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll) throw(INTERP_KERNEL::Exception)
6635 {
6636   med_field_type typcha;
6637   std::string dtunitOut;
6638   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6639   setDtUnit(dtunitOut.c_str());
6640   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll);
6641 }
6642
6643 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)
6644 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6645 {
6646   setDtUnit(dtunit.c_str());
6647   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll);
6648 }
6649 catch(INTERP_KERNEL::Exception& e)
6650 {
6651   throw e;
6652 }
6653
6654 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySize() const
6655 {
6656   std::size_t ret=_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>);
6657   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6658     ret+=(*it).capacity();
6659   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6660     if((const MEDFileAnyTypeField1TSWithoutSDA *)(*it))
6661       ret+=(*it)->getHeapMemorySize();
6662   return ret;
6663 }
6664
6665 /*!
6666  * 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
6667  * NULL.
6668  */
6669 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
6670 {
6671   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6672   ret->setInfo(_infos);
6673   int sz=(int)_time_steps.size();
6674   for(const int *id=startIds;id!=endIds;id++)
6675     {
6676       if(*id>=0 && *id<sz)
6677         {
6678           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6679           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6680           if(tse)
6681             {
6682               tse->incrRef();
6683               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6684             }
6685           ret->pushBackTimeStep(tse2);
6686         }
6687       else
6688         {
6689           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6690           oss << " ! Should be in [0," << sz << ") !";
6691           throw INTERP_KERNEL::Exception(oss.str().c_str());
6692         }
6693     }
6694   if(ret->getNumberOfTS()>0)
6695     ret->synchronizeNameScope();
6696   ret->copyNameScope(*this);
6697   return ret.retn();
6698 }
6699
6700 /*!
6701  * 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
6702  * NULL.
6703  */
6704 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
6705 {
6706   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6707   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6708   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6709   ret->setInfo(_infos);
6710   int sz=(int)_time_steps.size();
6711   int j=bg;
6712   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
6713     {
6714       if(j>=0 && j<sz)
6715         {
6716           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
6717           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6718           if(tse)
6719             {
6720               tse->incrRef();
6721               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6722             }
6723           ret->pushBackTimeStep(tse2);
6724         }
6725       else
6726         {
6727           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
6728           oss << " ! Should be in [0," << sz << ") !";
6729           throw INTERP_KERNEL::Exception(oss.str().c_str());
6730         }
6731     }
6732   if(ret->getNumberOfTS()>0)
6733     ret->synchronizeNameScope();
6734   ret->copyNameScope(*this);
6735   return ret.retn();
6736 }
6737
6738 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
6739 {
6740   int id=0;
6741   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6742   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6743     {
6744       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6745       if(!cur)
6746         continue;
6747       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6748       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
6749         ids->pushBackSilent(id);
6750     }
6751   return buildFromTimeStepIds(ids->begin(),ids->end());
6752 }
6753
6754 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
6755 {
6756   int id=0;
6757   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6758   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6759     {
6760       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6761       if(!cur)
6762         continue;
6763       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6764       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
6765         ids->pushBackSilent(id);
6766     }
6767   return buildFromTimeStepIds(ids->begin(),ids->end());
6768 }
6769
6770 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const throw(INTERP_KERNEL::Exception)
6771 {
6772   return _infos;
6773 }
6774
6775 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
6776 {
6777   _infos=info;
6778 }
6779
6780 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6781 {
6782   int ret=0;
6783   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6784     {
6785       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
6786       if(pt->isDealingTS(iteration,order))
6787         return ret;
6788     }
6789   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
6790   std::vector< std::pair<int,int> > vp=getIterations();
6791   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
6792     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
6793   throw INTERP_KERNEL::Exception(oss.str().c_str());
6794 }
6795
6796 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6797 {
6798   return *_time_steps[getTimeStepPos(iteration,order)];
6799 }
6800
6801 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) throw(INTERP_KERNEL::Exception)
6802 {
6803   return *_time_steps[getTimeStepPos(iteration,order)];
6804 }
6805
6806 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
6807 {
6808   if(_time_steps.empty())
6809     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
6810   return _time_steps[0]->getMeshName();
6811 }
6812
6813 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
6814 {
6815   std::string oldName(getMeshName());
6816   std::vector< std::pair<std::string,std::string> > v(1);
6817   v[0].first=oldName; v[0].second=newMeshName;
6818   changeMeshNames(v);
6819 }
6820
6821 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
6822 {
6823   bool ret=false;
6824   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6825     {
6826       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6827       if(cur)
6828         ret=cur->changeMeshNames(modifTab) || ret;
6829     }
6830   return ret;
6831 }
6832
6833 /*!
6834  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
6835  */
6836 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6837 {
6838   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
6839 }
6840
6841 /*!
6842  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
6843  */
6844 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)
6845 {
6846   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
6847 }
6848
6849 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
6850                                                                 MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
6851 {
6852   bool ret=false;
6853   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6854     {
6855       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
6856       if(f1ts)
6857         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
6858     }
6859   return ret;
6860 }
6861
6862 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
6863 {
6864   std::string startLine(bkOffset,' ');
6865   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
6866   if(fmtsId>=0)
6867     oss << " (" << fmtsId << ")";
6868   oss << " has the following name: \"" << _name << "\"." << std::endl;
6869   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
6870   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6871     {
6872       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
6873     }
6874   int i=0;
6875   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
6876     {
6877       std::string chapter(17,'0'+i);
6878       oss << startLine << chapter << std::endl;
6879       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6880       if(cur)
6881         cur->simpleRepr(bkOffset+2,oss,i);
6882       else
6883         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
6884       oss << startLine << chapter << std::endl;
6885     }
6886 }
6887
6888 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
6889 {
6890   std::size_t sz=_time_steps.size();
6891   std::vector< std::pair<int,int> > ret(sz);
6892   ret1.resize(sz);
6893   for(std::size_t i=0;i<sz;i++)
6894     {
6895       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
6896       if(f1ts)
6897         {
6898           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
6899         }
6900       else
6901         {
6902           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
6903           throw INTERP_KERNEL::Exception(oss.str().c_str());
6904         }
6905     }
6906   return ret;
6907 }
6908
6909 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse) throw(INTERP_KERNEL::Exception)
6910 {
6911   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
6912   if(!tse2)
6913     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
6914   checkCoherencyOfType(tse2);
6915   if(_time_steps.empty())
6916     {
6917       setName(tse2->getName().c_str());
6918       setInfo(tse2->getInfo());
6919     }
6920   checkThatComponentsMatch(tse2->getInfo());
6921   _time_steps.push_back(tse);
6922 }
6923
6924 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope() throw(INTERP_KERNEL::Exception)
6925 {
6926   std::size_t nbOfCompo=_infos.size();
6927   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6928     {
6929       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6930       if(cur)
6931         {
6932           if((cur->getInfo()).size()!=nbOfCompo)
6933             {
6934               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
6935               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
6936               throw INTERP_KERNEL::Exception(oss.str().c_str());
6937             }
6938           cur->copyNameScope(*this);
6939         }
6940     }
6941 }
6942
6943 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll) throw(INTERP_KERNEL::Exception)
6944 {
6945   _time_steps.resize(nbPdt);
6946   for(int i=0;i<nbPdt;i++)
6947     {
6948       std::vector< std::pair<int,int> > ts;
6949       med_int numdt=0,numo=0;
6950       med_int meshIt=0,meshOrder=0;
6951       med_float dt=0.0;
6952       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
6953       switch(fieldTyp)
6954         {
6955         case MED_FLOAT64:
6956           {
6957             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
6958             break;
6959           }
6960         case MED_INT32:
6961           {
6962             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
6963             break;
6964           }
6965         default:
6966           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
6967         }
6968       if(loadAll)
6969         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this);
6970       else
6971         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this);
6972     }
6973 }
6974
6975 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception)
6976 {
6977   if(_time_steps.empty())
6978     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
6979   checkThatNbOfCompoOfTSMatchThis();
6980   std::vector<std::string> infos(getInfo());
6981   int nbComp=infos.size();
6982   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
6983   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
6984   for(int i=0;i<nbComp;i++)
6985     {
6986       std::string info=infos[i];
6987       std::string c,u;
6988       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6989       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
6990       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
6991     }
6992   if(_name.empty())
6993     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
6994   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
6995   int nbOfTS=_time_steps.size();
6996   for(int i=0;i<nbOfTS;i++)
6997     _time_steps[i]->writeLL(fid,opts,*this);
6998 }
6999
7000 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
7001 {
7002   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7003     {
7004       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7005       if(elt)
7006         elt->loadBigArraysRecursively(fid,nasc);
7007     }
7008 }
7009   
7010 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
7011 {
7012   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7013     {
7014       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7015       if(elt)
7016         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7017     }
7018 }
7019
7020 void MEDFileAnyTypeFieldMultiTSWithoutSDA::releaseArrays() throw(INTERP_KERNEL::Exception)
7021 {
7022   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7023     {
7024       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7025       if(elt)
7026         elt->releaseArrays();
7027     }
7028 }
7029
7030 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7031 {
7032   return _time_steps.size();
7033 }
7034
7035 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
7036 {
7037   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7038   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7039     {
7040       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7041       if(tmp)
7042         newTS.push_back(*it);
7043     }
7044   _time_steps=newTS;
7045 }
7046
7047 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
7048 {
7049   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7050   int maxId=(int)_time_steps.size();
7051   int ii=0;
7052   std::set<int> idsToDel;
7053   for(const int *id=startIds;id!=endIds;id++,ii++)
7054     {
7055       if(*id>=0 && *id<maxId)
7056         {
7057           idsToDel.insert(*id);
7058         }
7059       else
7060         {
7061           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7062           throw INTERP_KERNEL::Exception(oss.str().c_str());
7063         }
7064     }
7065   for(int iii=0;iii<maxId;iii++)
7066     if(idsToDel.find(iii)==idsToDel.end())
7067       newTS.push_back(_time_steps[iii]);
7068   _time_steps=newTS;
7069 }
7070
7071 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
7072 {
7073   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7074   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7075   if(nbOfEntriesToKill==0)
7076     return ;
7077   std::size_t sz=_time_steps.size();
7078   std::vector<bool> b(sz,true);
7079   int j=bg;
7080   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7081     b[j]=false;
7082   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7083   for(std::size_t i=0;i<sz;i++)
7084     if(b[i])
7085       newTS.push_back(_time_steps[i]);
7086   _time_steps=newTS;
7087 }
7088
7089 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
7090 {
7091   int ret=0;
7092   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7093   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7094     {
7095       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7096       if(tmp)
7097         {
7098           int it2,ord;
7099           tmp->getTime(it2,ord);
7100           if(it2==iteration && order==ord)
7101             return ret;
7102           else
7103             oss << "(" << it2 << ","  << ord << "), ";
7104         }
7105     }
7106   throw INTERP_KERNEL::Exception(oss.str().c_str());
7107 }
7108
7109 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
7110 {
7111   int ret=0;
7112   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7113   oss.precision(15);
7114   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7115     {
7116       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7117       if(tmp)
7118         {
7119           int it2,ord;
7120           double ti=tmp->getTime(it2,ord);
7121           if(fabs(time-ti)<eps)
7122             return ret;
7123           else
7124             oss << ti << ", ";
7125         }
7126     }
7127   throw INTERP_KERNEL::Exception(oss.str().c_str());
7128 }
7129
7130 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7131 {
7132   int lgth=_time_steps.size();
7133   std::vector< std::pair<int,int> > ret(lgth);
7134   for(int i=0;i<lgth;i++)
7135     _time_steps[i]->fillIteration(ret[i]);
7136   return ret;
7137 }
7138
7139 /*!
7140  * 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'
7141  * This method returns two things.
7142  * - The absolute dimension of 'this' in first parameter. 
7143  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7144  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7145  *
7146  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7147  * Only these 3 discretizations will be taken into account here.
7148  *
7149  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7150  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7151  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7152  *
7153  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7154  * 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'.
7155  * 
7156  * Let's consider the typical following case :
7157  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7158  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7159  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7160  *   TETRA4 and SEG2
7161  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7162  *
7163  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7164  * 
7165  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7166  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7167  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7168  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7169  */
7170 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
7171 {
7172   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7173 }
7174
7175 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const throw(INTERP_KERNEL::Exception)
7176 {
7177   if(pos<0 || pos>=(int)_time_steps.size())
7178     {
7179       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7180       throw INTERP_KERNEL::Exception(oss.str().c_str());
7181     }
7182   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7183   if(item==0)
7184     {
7185       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7186       oss << "\nTry to use following method eraseEmptyTS !";
7187       throw INTERP_KERNEL::Exception(oss.str().c_str());
7188     }
7189   return item;
7190 }
7191
7192 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) throw(INTERP_KERNEL::Exception)
7193 {
7194   if(pos<0 || pos>=(int)_time_steps.size())
7195     {
7196       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7197       throw INTERP_KERNEL::Exception(oss.str().c_str());
7198     }
7199   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7200   if(item==0)
7201     {
7202       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7203       oss << "\nTry to use following method eraseEmptyTS !";
7204       throw INTERP_KERNEL::Exception(oss.str().c_str());
7205     }
7206   return item;
7207 }
7208
7209 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7210 {
7211   std::vector<std::string> ret;
7212   std::set<std::string> ret2;
7213   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7214     {
7215       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7216       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7217         if(ret2.find(*it2)==ret2.end())
7218           {
7219             ret.push_back(*it2);
7220             ret2.insert(*it2);
7221           }
7222     }
7223   return ret;
7224 }
7225
7226 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7227 {
7228   std::vector<std::string> ret;
7229   std::set<std::string> ret2;
7230   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7231     {
7232       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7233       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7234         if(ret2.find(*it2)==ret2.end())
7235           {
7236             ret.push_back(*it2);
7237             ret2.insert(*it2);
7238           }
7239     }
7240   return ret;
7241 }
7242
7243 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7244 {
7245   std::vector<std::string> ret;
7246   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7247     {
7248       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7249       ret.insert(ret.end(),tmp.begin(),tmp.end());
7250     }
7251   return ret;
7252 }
7253
7254 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7255 {
7256   std::vector<std::string> ret;
7257   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7258     {
7259       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7260       ret.insert(ret.end(),tmp.begin(),tmp.end());
7261     }
7262   return ret;
7263 }
7264
7265 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7266 {
7267   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7268     (*it)->changePflsRefsNamesGen2(mapOfModif);
7269 }
7270
7271 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7272 {
7273   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7274     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7275 }
7276
7277 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
7278 {
7279   int lgth=_time_steps.size();
7280   std::vector< std::vector<TypeOfField> > ret(lgth);
7281   for(int i=0;i<lgth;i++)
7282     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7283   return ret;
7284 }
7285
7286 /*!
7287  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7288  */
7289 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)
7290 {
7291   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7292 }
7293
7294 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
7295 {
7296   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7297   std::size_t i=0;
7298   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7299     {
7300       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7301         ret->_time_steps[i]=(*it)->deepCpy();
7302     }
7303   return ret.retn();
7304 }
7305
7306 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const throw(INTERP_KERNEL::Exception)
7307 {
7308   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7309   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7310   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7311   for(std::size_t i=0;i<sz;i++)
7312     {
7313       ret[i]=shallowCpy();
7314       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7315     }
7316   for(std::size_t i=0;i<sz2;i++)
7317     {
7318       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7319       if(ret1.size()!=sz)
7320         {
7321           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7322           throw INTERP_KERNEL::Exception(oss.str().c_str());
7323         }
7324       ts[i]=ret1;
7325     }
7326   for(std::size_t i=0;i<sz;i++)
7327     for(std::size_t j=0;j<sz2;j++)
7328       ret[i]->_time_steps[j]=ts[j][i];
7329   return ret;
7330 }
7331
7332 /*!
7333  * This method splits into discretization each time steps in \a this.
7334  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7335  */
7336 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const throw(INTERP_KERNEL::Exception)
7337 {
7338   std::size_t sz(_time_steps.size());
7339   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7340   for(std::size_t i=0;i<sz;i++)
7341     {
7342       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7343       if(!timeStep)
7344         {
7345           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7346           throw INTERP_KERNEL::Exception(oss.str().c_str());
7347         }
7348       items[i]=timeStep->splitDiscretizations();  
7349     }
7350   //
7351   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7352   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7353   std::vector< TypeOfField > types;
7354   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7355     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7356       {
7357         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7358         if(ts.size()!=1)
7359           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7360         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7361         if(it2==types.end())
7362           types.push_back(ts[0]);
7363       }
7364   ret.resize(types.size()); ret2.resize(types.size());
7365   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7366     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7367       {
7368         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7369         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7370         ret2[pos].push_back(*it1);
7371       }
7372   for(std::size_t i=0;i<types.size();i++)
7373     {
7374       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=createNew();
7375       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7376         elt->pushBackTimeStep(*it1);//also updates infos in elt
7377       ret[i]=elt;
7378       elt->MEDFileFieldNameScope::operator=(*this);
7379     }
7380   return ret;
7381 }
7382
7383 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
7384 {
7385   _name=field->getName();
7386   if(_name.empty())
7387     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7388   if(!arr)
7389     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7390   _infos=arr->getInfoOnComponents();
7391 }
7392
7393 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const throw(INTERP_KERNEL::Exception)
7394 {
7395   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7396   if(_name!=field->getName())
7397     {
7398       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7399       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7400       throw INTERP_KERNEL::Exception(oss.str().c_str());
7401     }
7402   if(!arr)
7403     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7404   checkThatComponentsMatch(arr->getInfoOnComponents());
7405 }
7406
7407 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const throw(INTERP_KERNEL::Exception)
7408 {
7409   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7410   if(getInfo().size()!=compos.size())
7411     {
7412       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7413       oss << " number of components of element to append (" << compos.size() << ") !";
7414       throw INTERP_KERNEL::Exception(oss.str().c_str());
7415     }
7416   if(_infos!=compos)
7417     {
7418       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7419       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7420       oss << " But compo in input fields are : ";
7421       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7422       oss << " !";
7423       throw INTERP_KERNEL::Exception(oss.str().c_str());
7424     }
7425 }
7426
7427 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const throw(INTERP_KERNEL::Exception)
7428 {
7429   std::size_t sz=_infos.size();
7430   int j=0;
7431   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7432     {
7433       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7434       if(elt)
7435         if(elt->getInfo().size()!=sz)
7436           {
7437             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7438             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7439             throw INTERP_KERNEL::Exception(oss.str().c_str());
7440           }
7441     }
7442 }
7443
7444 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
7445 {
7446   if(!field)
7447     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7448   if(!_time_steps.empty())
7449     checkCoherencyOfTinyInfo(field,arr);
7450   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7451   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7452   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7453   copyTinyInfoFrom(field,arr);
7454   _time_steps.push_back(obj);
7455 }
7456
7457 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
7458 {
7459   if(!field)
7460     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7461   if(!_time_steps.empty())
7462     checkCoherencyOfTinyInfo(field,arr);
7463   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7464   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7465   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7466   copyTinyInfoFrom(field,arr);
7467   _time_steps.push_back(obj);
7468 }
7469
7470 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts) throw(INTERP_KERNEL::Exception)
7471 {
7472   int sz=(int)_time_steps.size();
7473   if(i<0 || i>=sz)
7474     {
7475       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7476       throw INTERP_KERNEL::Exception(oss.str().c_str());
7477     }
7478   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7479   if(tsPtr)
7480     {
7481       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7482         {
7483           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7484           throw INTERP_KERNEL::Exception(oss.str().c_str());
7485         }
7486     }
7487   _time_steps[i]=ts;
7488 }
7489
7490 //= MEDFileFieldMultiTSWithoutSDA
7491
7492 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)
7493 {
7494   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7495 }
7496
7497 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7498 {
7499 }
7500
7501 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const char *fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7502 {
7503 }
7504
7505 /*!
7506  * \param [in] fieldId field id in C mode
7507  */
7508 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll) throw(INTERP_KERNEL::Exception)
7509 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7510 {
7511 }
7512 catch(INTERP_KERNEL::Exception& e)
7513   { throw e; }
7514
7515 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)
7516 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7517 {
7518 }
7519 catch(INTERP_KERNEL::Exception& e)
7520 { throw e; }
7521
7522 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const throw(INTERP_KERNEL::Exception)
7523 {
7524   return new MEDFileField1TSWithoutSDA;
7525 }
7526
7527 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const throw(INTERP_KERNEL::Exception)
7528 {
7529   if(!f1ts)
7530     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7531   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7532   if(!f1tsC)
7533     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7534 }
7535
7536 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
7537 {
7538   return MEDFileField1TSWithoutSDA::TYPE_STR;
7539 }
7540
7541 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
7542 {
7543   return new MEDFileFieldMultiTSWithoutSDA(*this);
7544 }
7545
7546 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const throw(INTERP_KERNEL::Exception)
7547 {
7548   return new MEDFileFieldMultiTSWithoutSDA;
7549 }
7550
7551 /*!
7552  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7553  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7554  */
7555 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)
7556 {
7557   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7558   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7559   if(!myF1TSC)
7560     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7561   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7562 }
7563
7564 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const throw(INTERP_KERNEL::Exception)
7565 {
7566   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7567   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7568   int i=0;
7569   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7570     {
7571       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7572       if(eltToConv)
7573         {
7574           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7575           if(!eltToConvC)
7576             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7577           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7578           ret->setIteration(i,elt);
7579         }
7580     }
7581   return ret.retn();
7582 }
7583
7584 //= MEDFileAnyTypeFieldMultiTS
7585
7586 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7587 {
7588 }
7589
7590 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
7591 try:MEDFileFieldGlobsReal(fileName)
7592 {
7593   MEDFileUtilities::CheckFileForRead(fileName);
7594   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7595   _content=BuildContentFrom(fid,fileName,loadAll);
7596   loadGlobals(fid);
7597 }
7598 catch(INTERP_KERNEL::Exception& e)
7599   {
7600     throw e;
7601   }
7602
7603 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
7604 {
7605   med_field_type typcha;
7606   std::vector<std::string> infos;
7607   std::string dtunit;
7608   int i=-1;
7609   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7610   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7611   switch(typcha)
7612     {
7613     case MED_FLOAT64:
7614       {
7615         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll);
7616         break;
7617       }
7618     case MED_INT32:
7619       {
7620         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll);
7621         break;
7622       }
7623     default:
7624       {
7625         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] !";
7626         throw INTERP_KERNEL::Exception(oss.str().c_str());
7627       }
7628     }
7629   ret->setDtUnit(dtunit.c_str());
7630   return ret.retn();
7631 }
7632
7633 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
7634 {
7635   med_field_type typcha;
7636   //
7637   std::vector<std::string> infos;
7638   std::string dtunit,fieldName;
7639   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
7640   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7641   switch(typcha)
7642     {
7643     case MED_FLOAT64:
7644       {
7645         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll);
7646         break;
7647       }
7648     case MED_INT32:
7649       {
7650         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll);
7651         break;
7652       }
7653     default:
7654       {
7655         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] !";
7656         throw INTERP_KERNEL::Exception(oss.str().c_str());
7657       }
7658     }
7659   ret->setDtUnit(dtunit.c_str());
7660   return ret.retn();
7661 }
7662
7663 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const char *fileName) throw(INTERP_KERNEL::Exception)
7664 {
7665   if(!c)
7666     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
7667   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
7668     {
7669       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
7670       ret->setFileName(fileName);
7671       ret->_content=c;  c->incrRef();
7672       return ret.retn();
7673     }
7674   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
7675     {
7676       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
7677       ret->setFileName(fileName);
7678       ret->_content=c;  c->incrRef();
7679       return ret.retn();
7680     }
7681   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
7682 }
7683
7684 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
7685 try:MEDFileFieldGlobsReal(fileName)
7686 {
7687   MEDFileUtilities::CheckFileForRead(fileName);
7688   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7689   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
7690   loadGlobals(fid);
7691 }
7692 catch(INTERP_KERNEL::Exception& e)
7693   {
7694     throw e;
7695   }
7696
7697 //= MEDFileIntFieldMultiTSWithoutSDA
7698
7699 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)
7700 {
7701   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7702 }
7703
7704 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
7705 {
7706 }
7707
7708 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const char *fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7709 {
7710 }
7711
7712 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)
7713 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7714 {
7715 }
7716 catch(INTERP_KERNEL::Exception& e)
7717 { throw e; }
7718
7719 /*!
7720  * \param [in] fieldId field id in C mode
7721  */
7722 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll) throw(INTERP_KERNEL::Exception)
7723 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7724 {
7725 }
7726 catch(INTERP_KERNEL::Exception& e)
7727   { throw e; }
7728
7729 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const throw(INTERP_KERNEL::Exception)
7730 {
7731   return new MEDFileIntField1TSWithoutSDA;
7732 }
7733
7734 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const throw(INTERP_KERNEL::Exception)
7735 {
7736   if(!f1ts)
7737     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7738   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
7739   if(!f1tsC)
7740     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
7741 }
7742
7743 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
7744 {
7745   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
7746 }
7747
7748 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
7749 {
7750   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
7751 }
7752
7753 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const throw(INTERP_KERNEL::Exception)
7754 {
7755   return new MEDFileIntFieldMultiTSWithoutSDA;
7756 }
7757
7758 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const throw(INTERP_KERNEL::Exception)
7759 {
7760   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
7761   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7762   int i=0;
7763   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7764     {
7765       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7766       if(eltToConv)
7767         {
7768           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
7769           if(!eltToConvC)
7770             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
7771           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
7772           ret->setIteration(i,elt);
7773         }
7774     }
7775   return ret.retn();
7776 }
7777
7778 //= MEDFileAnyTypeFieldMultiTS
7779
7780 /*!
7781  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
7782  * that has been read from a specified MED file.
7783  *  \param [in] fileName - the name of the MED file to read.
7784  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7785  *          is to delete this field using decrRef() as it is no more needed.
7786  *  \throw If reading the file fails.
7787  */
7788 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
7789 {
7790   MEDFileUtilities::CheckFileForRead(fileName);
7791   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7792   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
7793   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7794   ret->loadGlobals(fid);
7795   return ret.retn();
7796 }
7797
7798 /*!
7799  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
7800  * that has been read from a specified MED file.
7801  *  \param [in] fileName - the name of the MED file to read.
7802  *  \param [in] fieldName - the name of the field to read.
7803  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7804  *          is to delete this field using decrRef() as it is no more needed.
7805  *  \throw If reading the file fails.
7806  *  \throw If there is no field named \a fieldName in the file.
7807  */
7808 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
7809 {
7810   MEDFileUtilities::CheckFileForRead(fileName);
7811   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7812   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
7813   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7814   ret->loadGlobals(fid);
7815   return ret.retn();
7816 }
7817
7818 /*!
7819  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7820  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7821  *
7822  * \warning this is a shallow copy constructor
7823  */
7824 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7825 {
7826   if(!shallowCopyOfContent)
7827     {
7828       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
7829       otherPtr->incrRef();
7830       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
7831     }
7832   else
7833     {
7834       _content=other.shallowCpy();
7835     }
7836 }
7837
7838 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() throw(INTERP_KERNEL::Exception)
7839 {
7840   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7841   if(!ret)
7842     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
7843   return ret;
7844 }
7845
7846 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const throw(INTERP_KERNEL::Exception)
7847 {
7848   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7849   if(!ret)
7850     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
7851   return ret;
7852 }
7853
7854 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
7855 {
7856   return contentNotNullBase()->getPflsReallyUsed2();
7857 }
7858
7859 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
7860 {
7861   return contentNotNullBase()->getLocsReallyUsed2();
7862 }
7863
7864 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
7865 {
7866   return contentNotNullBase()->getPflsReallyUsedMulti2();
7867 }
7868
7869 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
7870 {
7871   return contentNotNullBase()->getLocsReallyUsedMulti2();
7872 }
7873
7874 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7875 {
7876   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
7877 }
7878
7879 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7880 {
7881   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
7882 }
7883
7884 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
7885 {
7886   return contentNotNullBase()->getNumberOfTS();
7887 }
7888
7889 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
7890 {
7891   contentNotNullBase()->eraseEmptyTS();
7892 }
7893
7894 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
7895 {
7896   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
7897 }
7898
7899 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
7900 {
7901   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
7902 }
7903
7904 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
7905 {
7906   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
7907   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7908   ret->_content=c;
7909   return ret.retn();
7910 }
7911
7912 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
7913 {
7914   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
7915   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7916   ret->_content=c;
7917   return ret.retn();
7918 }
7919
7920 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
7921 {
7922   return contentNotNullBase()->getIterations();
7923 }
7924
7925 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts) throw(INTERP_KERNEL::Exception)
7926 {
7927   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
7928     pushBackTimeStep(*it);
7929 }
7930
7931 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts) throw(INTERP_KERNEL::Exception)
7932 {
7933   if(!f1ts)
7934     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
7935   checkCoherencyOfType(f1ts);
7936   f1ts->incrRef();
7937   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
7938   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
7939   c->incrRef();
7940   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
7941   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
7942     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
7943   _content->pushBackTimeStep(cSafe);
7944   appendGlobs(*f1ts,1e-12);
7945 }
7946
7947 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope() throw(INTERP_KERNEL::Exception)
7948 {
7949   contentNotNullBase()->synchronizeNameScope();
7950 }
7951
7952 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
7953 {
7954   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
7955 }
7956
7957 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
7958 {
7959   return contentNotNullBase()->getPosGivenTime(time,eps);
7960 }
7961
7962 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
7963 {
7964   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
7965 }
7966
7967 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
7968 {
7969   return contentNotNullBase()->getTypesOfFieldAvailable();
7970 }
7971
7972 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)
7973 {
7974   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
7975 }
7976
7977 std::string MEDFileAnyTypeFieldMultiTS::getName() const
7978 {
7979   return contentNotNullBase()->getName();
7980 }
7981
7982 void MEDFileAnyTypeFieldMultiTS::setName(const char *name)
7983 {
7984   contentNotNullBase()->setName(name);
7985 }
7986
7987 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const throw(INTERP_KERNEL::Exception)
7988 {
7989   return contentNotNullBase()->getDtUnit();
7990 }
7991
7992 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
7993 {
7994   contentNotNullBase()->setDtUnit(dtUnit);
7995 }
7996
7997 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7998 {
7999   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8000 }
8001
8002 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
8003 {
8004   return contentNotNullBase()->getTimeSteps(ret1);
8005 }
8006
8007 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const throw(INTERP_KERNEL::Exception)
8008 {
8009   return contentNotNullBase()->getMeshName();
8010 }
8011
8012 void MEDFileAnyTypeFieldMultiTS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
8013 {
8014   contentNotNullBase()->setMeshName(newMeshName);
8015 }
8016
8017 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
8018 {
8019   return contentNotNullBase()->changeMeshNames(modifTab);
8020 }
8021
8022 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const throw(INTERP_KERNEL::Exception)
8023 {
8024   return contentNotNullBase()->getInfo();
8025 }
8026
8027 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
8028 {
8029   return contentNotNullBase()->setInfo(info);
8030 }
8031
8032 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const throw(INTERP_KERNEL::Exception)
8033 {
8034   const std::vector<std::string> ret=getInfo();
8035   return (int)ret.size();
8036 }
8037
8038 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
8039 {
8040   writeGlobals(fid,*this);
8041   contentNotNullBase()->writeLL(fid,*this);
8042 }
8043
8044 /*!
8045  * Writes \a this field into a MED file specified by its name.
8046  *  \param [in] fileName - the MED file name.
8047  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8048  * - 2 - erase; an existing file is removed.
8049  * - 1 - append; same data should not be present in an existing file.
8050  * - 0 - overwrite; same data present in an existing file is overwritten.
8051  *  \throw If the field name is not set.
8052  *  \throw If no field data is set.
8053  *  \throw If \a mode == 1 and the same data is present in an existing file.
8054  */
8055 void MEDFileAnyTypeFieldMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
8056 {
8057   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8058   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
8059   writeLL(fid);
8060 }
8061
8062 /*!
8063  * This method alloc the arrays and load potentially huge arrays contained in this field.
8064  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8065  * This method can be also called to refresh or reinit values from a file.
8066  * 
8067  * \throw If the fileName is not set or points to a non readable MED file.
8068  */
8069 void MEDFileAnyTypeFieldMultiTS::loadArrays() throw(INTERP_KERNEL::Exception)
8070 {
8071   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
8072   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8073 }
8074
8075 /*!
8076  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8077  * But once data loaded once, this method does nothing.
8078  * 
8079  * \throw If the fileName is not set or points to a non readable MED file.
8080  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::releaseArrays
8081  */
8082 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary() throw(INTERP_KERNEL::Exception)
8083 {
8084   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
8085   contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8086 }
8087
8088 /*!
8089  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8090  * This method does not release arrays set outside the context of a MED file.
8091  * 
8092  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8093  */
8094 void MEDFileAnyTypeFieldMultiTS::releaseArrays() throw(INTERP_KERNEL::Exception)
8095 {
8096   contentNotNullBase()->releaseArrays();
8097 }
8098
8099 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8100 {
8101   std::ostringstream oss;
8102   contentNotNullBase()->simpleRepr(0,oss,-1);
8103   simpleReprGlobs(oss);
8104   return oss.str();
8105 }
8106
8107 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySize() const
8108 {
8109   std::size_t ret=0;
8110   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)_content)
8111     ret+=_content->getHeapMemorySize();
8112   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
8113 }
8114
8115 /*!
8116  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8117  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8118  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8119  */
8120 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const throw(INTERP_KERNEL::Exception)
8121 {
8122   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8123   if(!content)
8124     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8125   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8126   std::size_t sz(contentsSplit.size());
8127   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8128   for(std::size_t i=0;i<sz;i++)
8129     {
8130       ret[i]=shallowCpy();
8131       ret[i]->_content=contentsSplit[i];
8132     }
8133   return ret;
8134 }
8135
8136 /*!
8137  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8138  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8139  */
8140 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const throw(INTERP_KERNEL::Exception)
8141 {
8142   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8143   if(!content)
8144     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8145   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitDiscretizations();
8146   std::size_t sz(contentsSplit.size());
8147   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8148   for(std::size_t i=0;i<sz;i++)
8149     {
8150       ret[i]=shallowCpy();
8151       ret[i]->_content=contentsSplit[i];
8152     }
8153   return ret;
8154 }
8155
8156 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception)
8157 {
8158   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8159   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8160     ret->_content=_content->deepCpy();
8161   ret->deepCpyGlobs(*this);
8162   return ret.retn();
8163 }
8164
8165 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8166 {
8167   return _content;
8168 }
8169
8170 /*!
8171  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8172  *  \param [in] iteration - the iteration number of a required time step.
8173  *  \param [in] order - the iteration order number of required time step.
8174  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8175  *          delete this field using decrRef() as it is no more needed.
8176  *  \throw If there is no required time step in \a this field.
8177  */
8178 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
8179 {
8180   int pos=getPosOfTimeStep(iteration,order);
8181   return getTimeStepAtPos(pos);
8182 }
8183
8184 /*!
8185  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8186  *  \param [in] time - the time of the time step of interest.
8187  *  \param [in] eps - a precision used to compare time values.
8188  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8189  *          delete this field using decrRef() as it is no more needed.
8190  *  \throw If there is no required time step in \a this field.
8191  */
8192 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
8193 {
8194   int pos=getPosGivenTime(time,eps);
8195   return getTimeStepAtPos(pos);
8196 }
8197
8198 /*!
8199  * This method groups not null items in \a vectFMTS per time step series. Two time series are considered equal if the list of their pair of integers iteration,order are equal.
8200  * The float64 value of time attached to the pair of integers are not considered here.
8201  * 
8202  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8203  * \throw If there is a null pointer in \a vectFMTS.
8204  */
8205 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS) throw(INTERP_KERNEL::Exception)
8206 {
8207   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8208   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8209   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8210   while(!lstFMTS.empty())
8211     {
8212       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8213       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8214       if(!curIt)
8215         throw INTERP_KERNEL::Exception(msg);
8216       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8217       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8218       elt.push_back(curIt); it=lstFMTS.erase(it);
8219       while(it!=lstFMTS.end())
8220         {
8221           curIt=*it;
8222           if(!curIt)
8223             throw INTERP_KERNEL::Exception(msg);
8224           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8225           if(refIts==curIts)
8226             { elt.push_back(curIt); it=lstFMTS.erase(it);}
8227           else
8228             it++;
8229         }
8230       ret.push_back(elt);
8231     }
8232   return ret;
8233 }
8234
8235 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator() throw(INTERP_KERNEL::Exception)
8236 {
8237   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8238 }
8239
8240 //= MEDFileFieldMultiTS
8241
8242 /*!
8243  * Returns a new empty instance of MEDFileFieldMultiTS.
8244  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8245  *          is to delete this field using decrRef() as it is no more needed.
8246  */
8247 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8248 {
8249   return new MEDFileFieldMultiTS;
8250 }
8251
8252 /*!
8253  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8254  * that has been read from a specified MED file.
8255  *  \param [in] fileName - the name of the MED file to read.
8256  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8257  *          is to delete this field using decrRef() as it is no more needed.
8258  *  \throw If reading the file fails.
8259  */
8260 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
8261 {
8262   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll);
8263   ret->contentNotNull();//to check that content type matches with \a this type.
8264   return ret.retn();
8265 }
8266
8267 /*!
8268  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8269  * that has been read from a specified MED file.
8270  *  \param [in] fileName - the name of the MED file to read.
8271  *  \param [in] fieldName - the name of the field to read.
8272  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8273  *          is to delete this field using decrRef() as it is no more needed.
8274  *  \throw If reading the file fails.
8275  *  \throw If there is no field named \a fieldName in the file.
8276  */
8277 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
8278 {
8279   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll);
8280   ret->contentNotNull();//to check that content type matches with \a this type.
8281   return ret.retn();
8282 }
8283
8284 /*!
8285  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8286  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8287  *
8288  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8289  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8290  * \warning this is a shallow copy constructor
8291  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8292  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8293  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8294  *          is to delete this field using decrRef() as it is no more needed.
8295  */
8296 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8297 {
8298   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8299 }
8300
8301 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const throw(INTERP_KERNEL::Exception)
8302 {
8303   return new MEDFileFieldMultiTS(*this);
8304 }
8305
8306 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception)
8307 {
8308   if(!f1ts)
8309     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8310   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8311   if(!f1tsC)
8312     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8313 }
8314
8315 /*!
8316  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8317  * following the given input policy.
8318  *
8319  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8320  *                            By default (true) the globals are deeply copied.
8321  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8322  */
8323 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
8324 {
8325   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
8326   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8327   if(content)
8328     {
8329       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8330       if(!contc)
8331         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8332       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8333       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
8334     }
8335   else
8336     ret=MEDFileIntFieldMultiTS::New();
8337   if(deepCpyGlobs)
8338     ret->deepCpyGlobs(*this);
8339   else
8340     ret->shallowCpyGlobs(*this);
8341   return ret.retn();
8342 }
8343
8344 /*!
8345  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
8346  *  \param [in] pos - a time step id.
8347  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8348  *          delete this field using decrRef() as it is no more needed.
8349  *  \throw If \a pos is not a valid time step id.
8350  */
8351 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
8352 {
8353   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8354   if(!item)
8355     {
8356       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8357       throw INTERP_KERNEL::Exception(oss.str().c_str());
8358     }
8359   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
8360   if(itemC)
8361     {
8362       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
8363       ret->shallowCpyGlobs(*this);
8364       return ret.retn();
8365     }
8366   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
8367   throw INTERP_KERNEL::Exception(oss.str().c_str());
8368 }
8369
8370 /*!
8371  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8372  * mesh entities of a given dimension of the first mesh in MED file.
8373  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8374  *  \param [in] type - a spatial discretization of interest.
8375  *  \param [in] iteration - the iteration number of a required time step.
8376  *  \param [in] order - the iteration order number of required time step.
8377  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8378  *  \param [in] renumPol - specifies how to permute values of the result field according to
8379  *          the optional numbers of cells and nodes, if any. The valid values are
8380  *          - 0 - do not permute.
8381  *          - 1 - permute cells.
8382  *          - 2 - permute nodes.
8383  *          - 3 - permute cells and nodes.
8384  *
8385  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8386  *          caller is to delete this field using decrRef() as it is no more needed. 
8387  *  \throw If the MED file is not readable.
8388  *  \throw If there is no mesh in the MED file.
8389  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8390  *  \throw If no field values of the required parameters are available.
8391  */
8392 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
8393 {
8394   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8395   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8396   if(!myF1TSC)
8397     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
8398   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8399   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut,*contentNotNullBase());
8400   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8401   return ret.retn();
8402 }
8403
8404 /*!
8405  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8406  * the top level cells of the first mesh in MED file.
8407  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8408  *  \param [in] type - a spatial discretization of interest.
8409  *  \param [in] iteration - the iteration number of a required time step.
8410  *  \param [in] order - the iteration order number of required time step.
8411  *  \param [in] renumPol - specifies how to permute values of the result field according to
8412  *          the optional numbers of cells and nodes, if any. The valid values are
8413  *          - 0 - do not permute.
8414  *          - 1 - permute cells.
8415  *          - 2 - permute nodes.
8416  *          - 3 - permute cells and nodes.
8417  *
8418  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8419  *          caller is to delete this field using decrRef() as it is no more needed. 
8420  *  \throw If the MED file is not readable.
8421  *  \throw If there is no mesh in the MED file.
8422  *  \throw If no field values of the required parameters are available.
8423  */
8424 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const throw(INTERP_KERNEL::Exception)
8425 {
8426   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8427   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8428   if(!myF1TSC)
8429     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
8430   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8431   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,0,renumPol,this,arrOut,*contentNotNullBase());
8432   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8433   return ret.retn();
8434 }
8435
8436 /*!
8437  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8438  * a given support.
8439  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8440  *  \param [in] type - a spatial discretization of interest.
8441  *  \param [in] iteration - the iteration number of a required time step.
8442  *  \param [in] order - the iteration order number of required time step.
8443  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8444  *  \param [in] mesh - the supporting mesh.
8445  *  \param [in] renumPol - specifies how to permute values of the result field according to
8446  *          the optional numbers of cells and nodes, if any. The valid values are
8447  *          - 0 - do not permute.
8448  *          - 1 - permute cells.
8449  *          - 2 - permute nodes.
8450  *          - 3 - permute cells and nodes.
8451  *
8452  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8453  *          caller is to delete this field using decrRef() as it is no more needed. 
8454  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8455  *  \throw If no field of \a this is lying on \a mesh.
8456  *  \throw If no field values of the required parameters are available.
8457  */
8458 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
8459 {
8460   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8461   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8462   if(!myF1TSC)
8463     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8464   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8465   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
8466   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8467   return ret.retn();
8468 }
8469
8470 /*!
8471  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8472  * given support. 
8473  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8474  *  \param [in] type - a spatial discretization of the new field.
8475  *  \param [in] iteration - the iteration number of a required time step.
8476  *  \param [in] order - the iteration order number of required time step.
8477  *  \param [in] mesh - the supporting mesh.
8478  *  \param [in] renumPol - specifies how to permute values of the result field according to
8479  *          the optional numbers of cells and nodes, if any. The valid values are
8480  *          - 0 - do not permute.
8481  *          - 1 - permute cells.
8482  *          - 2 - permute nodes.
8483  *          - 3 - permute cells and nodes.
8484  *
8485  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8486  *          caller is to delete this field using decrRef() as it is no more needed. 
8487  *  \throw If no field of \a this is lying on \a mesh.
8488  *  \throw If no field values of the required parameters are available.
8489  */
8490 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
8491 {
8492   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8493   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8494   if(!myF1TSC)
8495     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8496   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8497   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
8498   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8499   return ret.retn();
8500 }
8501
8502 /*!
8503  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
8504  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8505  * This method is useful for MED2 file format when field on different mesh was autorized.
8506  */
8507 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
8508 {
8509   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8510   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8511   if(!myF1TSC)
8512     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
8513   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8514   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
8515   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8516   return ret.retn();
8517 }
8518
8519 /*!
8520  * Returns values and a profile of the field of a given type, of a given time step,
8521  * lying on a given support.
8522  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8523  *  \param [in] type - a spatial discretization of the field.
8524  *  \param [in] iteration - the iteration number of a required time step.
8525  *  \param [in] order - the iteration order number of required time step.
8526  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8527  *  \param [in] mesh - the supporting mesh.
8528  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8529  *          field of interest lies on. If the field lies on all entities of the given
8530  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8531  *          using decrRef() as it is no more needed.  
8532  *  \param [in] glob - the global data storing profiles and localization.
8533  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
8534  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8535  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8536  *  \throw If no field of \a this is lying on \a mesh.
8537  *  \throw If no field values of the required parameters are available.
8538  */
8539 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
8540 {
8541   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8542   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8543   if(!myF1TSC)
8544     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
8545   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8546   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
8547 }
8548
8549 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const throw(INTERP_KERNEL::Exception)
8550 {
8551   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8552   if(!pt)
8553     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
8554   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
8555   if(!ret)
8556     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 !");
8557   return ret;
8558 }
8559
8560  MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() throw(INTERP_KERNEL::Exception)
8561 {
8562   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8563   if(!pt)
8564     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
8565   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
8566   if(!ret)
8567     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 !");
8568   return ret;
8569 }
8570
8571 /*!
8572  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8573  * the given field is checked if its elements are sorted suitable for writing to MED file
8574  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8575  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8576  *  \param [in] field - the field to add to \a this.
8577  *  \throw If the name of \a field is empty.
8578  *  \throw If the data array of \a field is not set.
8579  *  \throw If existing time steps have different name or number of components than \a field.
8580  *  \throw If the underlying mesh of \a field has no name.
8581  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8582  */
8583 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
8584 {
8585   const DataArrayDouble *arr=0;
8586   if(field)
8587     arr=field->getArray();
8588   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
8589 }
8590
8591 /*!
8592  * Adds a MEDCouplingFieldDouble to \a this as another time step. Specified entities of
8593  * a given dimension of a given mesh are used as the support of the given field.
8594  * Elements of the given mesh must be sorted suitable for writing to MED file. 
8595  * Order of underlying mesh entities of the given field specified by \a profile parameter
8596  * is not prescribed; this method permutes field values to have them sorted by element
8597  * type as required for writing to MED file.  
8598  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8599  *  \param [in] field - the field to add to \a this.
8600  *  \param [in] mesh - the supporting mesh of \a field.
8601  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
8602  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8603  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8604  *  \throw If existing time steps have different name or number of components than \a field.
8605  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8606  *  \throw If the data array of \a field is not set.
8607  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8608  */
8609 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
8610 {
8611   const DataArrayDouble *arr=0;
8612   if(field)
8613     arr=field->getArray();
8614   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
8615 }
8616
8617 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
8618 {
8619   _content=new MEDFileFieldMultiTSWithoutSDA;
8620 }
8621
8622 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
8623 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
8624 {
8625 }
8626 catch(INTERP_KERNEL::Exception& e)
8627   { throw e; }
8628
8629 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
8630 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
8631 {
8632 }
8633 catch(INTERP_KERNEL::Exception& e)
8634   { throw e; }
8635
8636 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8637 {
8638 }
8639
8640 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)
8641 {
8642   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
8643 }
8644
8645 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
8646 {
8647   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8648 }
8649
8650 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)
8651 {
8652   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
8653 }
8654
8655 //= MEDFileAnyTypeFieldMultiTSIterator
8656
8657 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
8658 {
8659   if(fmts)
8660     {
8661       fmts->incrRef();
8662       _nb_iter=fmts->getNumberOfTS();
8663     }
8664 }
8665
8666 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
8667 {
8668 }
8669
8670 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt() throw(INTERP_KERNEL::Exception)
8671 {
8672   if(_iter_id<_nb_iter)
8673     {
8674       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
8675       if(fmts)
8676         return fmts->getTimeStepAtPos(_iter_id++);
8677       else
8678         return 0;
8679     }
8680   else
8681     return 0;
8682 }
8683
8684 //= MEDFileIntFieldMultiTS
8685
8686 /*!
8687  * Returns a new empty instance of MEDFileFieldMultiTS.
8688  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8689  *          is to delete this field using decrRef() as it is no more needed.
8690  */
8691 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
8692 {
8693   return new MEDFileIntFieldMultiTS;
8694 }
8695
8696 /*!
8697  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
8698  * that has been read from a specified MED file.
8699  *  \param [in] fileName - the name of the MED file to read.
8700  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8701  *          is to delete this field using decrRef() as it is no more needed.
8702  *  \throw If reading the file fails.
8703  */
8704 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
8705 {
8706   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll);
8707   ret->contentNotNull();//to check that content type matches with \a this type.
8708   return ret.retn();
8709 }
8710
8711 /*!
8712  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
8713  * that has been read from a specified MED file.
8714  *  \param [in] fileName - the name of the MED file to read.
8715  *  \param [in] fieldName - the name of the field to read.
8716  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8717  *          is to delete this field using decrRef() as it is no more needed.
8718  *  \throw If reading the file fails.
8719  *  \throw If there is no field named \a fieldName in the file.
8720  */
8721 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
8722 {
8723   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll);
8724   ret->contentNotNull();//to check that content type matches with \a this type.
8725   return ret.retn();
8726 }
8727
8728 /*!
8729  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8730  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8731  *
8732  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
8733  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8734  * \warning this is a shallow copy constructor
8735  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
8736  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8737  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8738  *          is to delete this field using decrRef() as it is no more needed.
8739  */
8740 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8741 {
8742   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
8743 }
8744
8745 /*!
8746  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
8747  * following the given input policy.
8748  *
8749  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8750  *                            By default (true) the globals are deeply copied.
8751  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
8752  */
8753 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
8754 {
8755   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
8756   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8757   if(content)
8758     {
8759       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
8760       if(!contc)
8761         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
8762       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
8763       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
8764     }
8765   else
8766     ret=MEDFileFieldMultiTS::New();
8767   if(deepCpyGlobs)
8768     ret->deepCpyGlobs(*this);
8769   else
8770     ret->shallowCpyGlobs(*this);
8771   return ret.retn();
8772 }
8773
8774 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const throw(INTERP_KERNEL::Exception)
8775 {
8776   return new MEDFileIntFieldMultiTS(*this);
8777 }
8778
8779 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception)
8780 {
8781   if(!f1ts)
8782     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8783   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
8784   if(!f1tsC)
8785     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8786 }
8787
8788 /*!
8789  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8790  * mesh entities of a given dimension of the first mesh in MED file.
8791  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8792  *  \param [in] type - a spatial discretization of interest.
8793  *  \param [in] iteration - the iteration number of a required time step.
8794  *  \param [in] order - the iteration order number of required time step.
8795  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8796  *  \param [out] arrOut - the DataArrayInt containing values of field.
8797  *  \param [in] renumPol - specifies how to permute values of the result field according to
8798  *          the optional numbers of cells and nodes, if any. The valid values are
8799  *          - 0 - do not permute.
8800  *          - 1 - permute cells.
8801  *          - 2 - permute nodes.
8802  *          - 3 - permute cells and nodes.
8803  *
8804  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8805  *          caller is to delete this field using decrRef() as it is no more needed. 
8806  *  \throw If the MED file is not readable.
8807  *  \throw If there is no mesh in the MED file.
8808  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8809  *  \throw If no field values of the required parameters are available.
8810  */
8811 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8812 {
8813   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8814   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8815   if(!myF1TSC)
8816     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
8817   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8818   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arr,*contentNotNullBase());
8819   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8820   return ret.retn();
8821 }
8822
8823 /*!
8824  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8825  * the top level cells of the first mesh in MED file.
8826  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8827  *  \param [in] type - a spatial discretization of interest.
8828  *  \param [in] iteration - the iteration number of a required time step.
8829  *  \param [in] order - the iteration order number of required time step.
8830  *  \param [out] arrOut - the DataArrayInt containing values of field.
8831  *  \param [in] renumPol - specifies how to permute values of the result field according to
8832  *          the optional numbers of cells and nodes, if any. The valid values are
8833  *          - 0 - do not permute.
8834  *          - 1 - permute cells.
8835  *          - 2 - permute nodes.
8836  *          - 3 - permute cells and nodes.
8837  *
8838  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8839  *          caller is to delete this field using decrRef() as it is no more needed. 
8840  *  \throw If the MED file is not readable.
8841  *  \throw If there is no mesh in the MED file.
8842  *  \throw If no field values of the required parameters are available.
8843  */
8844 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8845 {
8846   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8847   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8848   if(!myF1TSC)
8849     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
8850   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8851   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,0,renumPol,this,arr,*contentNotNullBase());
8852   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8853   return ret.retn();
8854 }
8855
8856 /*!
8857  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8858  * a given support.
8859  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8860  *  \param [in] type - a spatial discretization of interest.
8861  *  \param [in] iteration - the iteration number of a required time step.
8862  *  \param [in] order - the iteration order number of required time step.
8863  *  \param [out] arrOut - the DataArrayInt containing values of field.
8864  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8865  *  \param [in] mesh - the supporting mesh.
8866  *  \param [in] renumPol - specifies how to permute values of the result field according to
8867  *          the optional numbers of cells and nodes, if any. The valid values are
8868  *          - 0 - do not permute.
8869  *          - 1 - permute cells.
8870  *          - 2 - permute nodes.
8871  *          - 3 - permute cells and nodes.
8872  *
8873  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8874  *          caller is to delete this field using decrRef() as it is no more needed. 
8875  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8876  *  \throw If no field of \a this is lying on \a mesh.
8877  *  \throw If no field values of the required parameters are available.
8878  */
8879 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8880 {
8881   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8882   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8883   if(!myF1TSC)
8884     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8885   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8886   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
8887   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8888   return ret.retn();
8889 }
8890
8891 /*!
8892  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8893  * given support. 
8894  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8895  *  \param [in] type - a spatial discretization of the new field.
8896  *  \param [in] iteration - the iteration number of a required time step.
8897  *  \param [in] order - the iteration order number of required time step.
8898  *  \param [in] mesh - the supporting mesh.
8899  *  \param [out] arrOut - the DataArrayInt containing values of field.
8900  *  \param [in] renumPol - specifies how to permute values of the result field according to
8901  *          the optional numbers of cells and nodes, if any. The valid values are
8902  *          - 0 - do not permute.
8903  *          - 1 - permute cells.
8904  *          - 2 - permute nodes.
8905  *          - 3 - permute cells and nodes.
8906  *
8907  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8908  *          caller is to delete this field using decrRef() as it is no more needed. 
8909  *  \throw If no field of \a this is lying on \a mesh.
8910  *  \throw If no field values of the required parameters are available.
8911  */
8912 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8913 {
8914   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8915   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8916   if(!myF1TSC)
8917     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8918   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8919   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
8920   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8921   return ret.retn();
8922 }
8923
8924 /*!
8925  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
8926  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8927  * This method is useful for MED2 file format when field on different mesh was autorized.
8928  */
8929 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const char *mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8930 {
8931   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8932   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8933   if(!myF1TSC)
8934     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8935   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8936   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
8937   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8938   return ret.retn();
8939 }
8940
8941 /*!
8942  * Returns values and a profile of the field of a given type, of a given time step,
8943  * lying on a given support.
8944  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8945  *  \param [in] type - a spatial discretization of the field.
8946  *  \param [in] iteration - the iteration number of a required time step.
8947  *  \param [in] order - the iteration order number of required time step.
8948  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8949  *  \param [in] mesh - the supporting mesh.
8950  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8951  *          field of interest lies on. If the field lies on all entities of the given
8952  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8953  *          using decrRef() as it is no more needed.  
8954  *  \param [in] glob - the global data storing profiles and localization.
8955  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
8956  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8957  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8958  *  \throw If no field of \a this is lying on \a mesh.
8959  *  \throw If no field values of the required parameters are available.
8960  */
8961 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
8962 {
8963   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8964   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8965   if(!myF1TSC)
8966     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
8967   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8968   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
8969 }
8970
8971 /*!
8972  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
8973  *  \param [in] pos - a time step id.
8974  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
8975  *          delete this field using decrRef() as it is no more needed.
8976  *  \throw If \a pos is not a valid time step id.
8977  */
8978 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
8979 {
8980   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8981   if(!item)
8982     {
8983       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8984       throw INTERP_KERNEL::Exception(oss.str().c_str());
8985     }
8986   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
8987   if(itemC)
8988     {
8989       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
8990       ret->shallowCpyGlobs(*this);
8991       return ret.retn();
8992     }
8993   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
8994   throw INTERP_KERNEL::Exception(oss.str().c_str());
8995 }
8996
8997 /*!
8998  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8999  * the given field is checked if its elements are sorted suitable for writing to MED file
9000  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9001  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9002  *  \param [in] field - the field to add to \a this.
9003  *  \throw If the name of \a field is empty.
9004  *  \throw If the data array of \a field is not set.
9005  *  \throw If existing time steps have different name or number of components than \a field.
9006  *  \throw If the underlying mesh of \a field has no name.
9007  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9008  */
9009 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception)
9010 {
9011   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9012 }
9013
9014 /*!
9015  * Adds a MEDCouplingFieldDouble to \a this as another time step. Specified entities of
9016  * a given dimension of a given mesh are used as the support of the given field.
9017  * Elements of the given mesh must be sorted suitable for writing to MED file. 
9018  * Order of underlying mesh entities of the given field specified by \a profile parameter
9019  * is not prescribed; this method permutes field values to have them sorted by element
9020  * type as required for writing to MED file.  
9021  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9022  *  \param [in] field - the field to add to \a this.
9023  *  \param [in] mesh - the supporting mesh of \a field.
9024  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
9025  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9026  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9027  *  \throw If existing time steps have different name or number of components than \a field.
9028  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9029  *  \throw If the data array of \a field is not set.
9030  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9031  */
9032 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
9033 {
9034   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9035 }
9036
9037 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const throw(INTERP_KERNEL::Exception)
9038 {
9039   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9040   if(!pt)
9041     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9042   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9043   if(!ret)
9044     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 !");
9045   return ret;
9046 }
9047
9048  MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() throw(INTERP_KERNEL::Exception)
9049 {
9050   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9051   if(!pt)
9052     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9053   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9054   if(!ret)
9055     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 !");
9056   return ret;
9057 }
9058
9059 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9060 {
9061   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9062 }
9063
9064 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9065 {
9066 }
9067
9068 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
9069 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
9070 {
9071 }
9072 catch(INTERP_KERNEL::Exception& e)
9073   { throw e; }
9074
9075 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
9076 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
9077 {
9078 }
9079 catch(INTERP_KERNEL::Exception& e)
9080   { throw e; }
9081
9082 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
9083 {
9084   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9085 }
9086
9087 //= MEDFileFields
9088
9089 MEDFileFields *MEDFileFields::New()
9090 {
9091   return new MEDFileFields;
9092 }
9093
9094 MEDFileFields *MEDFileFields::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
9095 {
9096   return new MEDFileFields(fileName,loadAll);
9097 }
9098
9099 std::size_t MEDFileFields::getHeapMemorySize() const
9100 {
9101   std::size_t ret=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9102   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9103     if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it)
9104       ret+=(*it)->getHeapMemorySize();
9105   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
9106 }
9107
9108 MEDFileFields *MEDFileFields::deepCpy() const throw(INTERP_KERNEL::Exception)
9109 {
9110   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9111   std::size_t i=0;
9112   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9113     {
9114       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9115         ret->_fields[i]=(*it)->deepCpy();
9116     }
9117   ret->deepCpyGlobs(*this);
9118   return ret.retn();
9119 }
9120
9121 MEDFileFields *MEDFileFields::shallowCpy() const throw(INTERP_KERNEL::Exception)
9122 {
9123   return new MEDFileFields(*this);
9124 }
9125
9126 /*!
9127  * 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
9128  * 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.
9129  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9130  *
9131  * \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.
9132  * \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.
9133  * 
9134  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9135  */
9136 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const throw(INTERP_KERNEL::Exception)
9137 {
9138   std::set< std::pair<int,int> > s;
9139   bool firstShot=true;
9140   areThereSomeForgottenTS=false;
9141   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9142     {
9143       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9144         continue;
9145       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9146       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9147       if(firstShot)
9148         { s=s1; firstShot=false; }
9149       else
9150         {
9151           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9152           if(s!=s2)
9153             areThereSomeForgottenTS=true;
9154           s=s2;
9155         }
9156     }
9157   std::vector< std::pair<int,int> > ret;
9158   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9159   return ret;
9160 }
9161
9162 int MEDFileFields::getNumberOfFields() const
9163 {
9164   return _fields.size();
9165 }
9166
9167 std::vector<std::string> MEDFileFields::getFieldsNames() const throw(INTERP_KERNEL::Exception)
9168 {
9169   std::vector<std::string> ret(_fields.size());
9170   int i=0;
9171   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9172     {
9173       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9174       if(f)
9175         {
9176           ret[i]=f->getName();
9177         }
9178       else
9179         {
9180           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9181           throw INTERP_KERNEL::Exception(oss.str().c_str());
9182         }
9183     }
9184   return ret;
9185 }
9186
9187 std::vector<std::string> MEDFileFields::getMeshesNames() const throw(INTERP_KERNEL::Exception)
9188 {
9189   std::vector<std::string> ret;
9190   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9191     {
9192       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9193       if(cur)
9194         ret.push_back(cur->getMeshName());
9195     }
9196   return ret;
9197 }
9198
9199 std::string MEDFileFields::simpleRepr() const
9200 {
9201   std::ostringstream oss;
9202   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9203   simpleRepr(0,oss);
9204   return oss.str();
9205 }
9206
9207 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9208 {
9209   int nbOfFields=getNumberOfFields();
9210   std::string startLine(bkOffset,' ');
9211   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9212   int i=0;
9213   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9214     {
9215       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9216       if(cur)
9217         {
9218           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9219         }
9220       else
9221         {
9222           oss << startLine << "  - not defined !" << std::endl;
9223         }
9224     }
9225   i=0;
9226   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9227     {
9228       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9229       std::string chapter(17,'0'+i);
9230       oss << startLine << chapter << std::endl;
9231       if(cur)
9232         {
9233           cur->simpleRepr(bkOffset+2,oss,i);
9234         }
9235       else
9236         {
9237           oss << startLine << "  - not defined !" << std::endl;
9238         }
9239       oss << startLine << chapter << std::endl;
9240     }
9241   simpleReprGlobs(oss);
9242 }
9243
9244 MEDFileFields::MEDFileFields()
9245 {
9246 }
9247
9248 MEDFileFields::MEDFileFields(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
9249 try:MEDFileFieldGlobsReal(fileName)
9250   {
9251     MEDFileUtilities::CheckFileForRead(fileName);
9252     MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
9253     int nbFields=MEDnField(fid);
9254     _fields.resize(nbFields);
9255     med_field_type typcha;
9256     for(int i=0;i<nbFields;i++)
9257       {
9258         std::vector<std::string> infos;
9259         std::string fieldName,dtunit;
9260         int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit);
9261         switch(typcha)
9262           {
9263           case MED_FLOAT64:
9264             {
9265               _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
9266               break;
9267             }
9268           case MED_INT32:
9269             {
9270               _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
9271               break;
9272             }
9273           default:
9274             {
9275               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] !";
9276               throw INTERP_KERNEL::Exception(oss.str().c_str());
9277             }
9278           }
9279       }
9280     loadAllGlobals(fid);
9281   }
9282 catch(INTERP_KERNEL::Exception& e)
9283   {
9284     throw e;
9285   }
9286
9287 void MEDFileFields::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
9288 {
9289   int i=0;
9290   writeGlobals(fid,*this);
9291   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9292     {
9293       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9294       if(!elt)
9295         {
9296           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9297           throw INTERP_KERNEL::Exception(oss.str().c_str());
9298         }
9299       elt->writeLL(fid,*this);
9300     }
9301 }
9302
9303 void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
9304 {
9305   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
9306   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
9307   writeLL(fid);
9308 }
9309
9310 /*!
9311  * This method alloc the arrays and load potentially huge arrays contained in this field.
9312  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9313  * This method can be also called to refresh or reinit values from a file.
9314  * 
9315  * \throw If the fileName is not set or points to a non readable MED file.
9316  */
9317 void MEDFileFields::loadArrays() throw(INTERP_KERNEL::Exception)
9318 {
9319   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
9320   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9321     {
9322       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9323       if(elt)
9324         elt->loadBigArraysRecursively(fid,*elt);
9325     }
9326 }
9327
9328 /*!
9329  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9330  * But once data loaded once, this method does nothing.
9331  * 
9332  * \throw If the fileName is not set or points to a non readable MED file.
9333  * \sa MEDFileFields::loadArrays, MEDFileFields::releaseArrays
9334  */
9335 void MEDFileFields::loadArraysIfNecessary() throw(INTERP_KERNEL::Exception)
9336 {
9337   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
9338   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9339     {
9340       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9341       if(elt)
9342         elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9343     }
9344 }
9345
9346 /*!
9347  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9348  * This method does not release arrays set outside the context of a MED file.
9349  * 
9350  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary
9351  */
9352 void MEDFileFields::releaseArrays() throw(INTERP_KERNEL::Exception)
9353 {
9354   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
9355   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9356     {
9357       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9358       if(elt)
9359         elt->releaseArrays();
9360     }
9361 }
9362
9363 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9364 {
9365   std::vector<std::string> ret;
9366   std::set<std::string> ret2;
9367   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9368     {
9369       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9370       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9371         if(ret2.find(*it2)==ret2.end())
9372           {
9373             ret.push_back(*it2);
9374             ret2.insert(*it2);
9375           }
9376     }
9377   return ret;
9378 }
9379
9380 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9381 {
9382   std::vector<std::string> ret;
9383   std::set<std::string> ret2;
9384   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9385     {
9386       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9387       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9388         if(ret2.find(*it2)==ret2.end())
9389           {
9390             ret.push_back(*it2);
9391             ret2.insert(*it2);
9392           }
9393     }
9394   return ret;
9395 }
9396
9397 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
9398 {
9399   std::vector<std::string> ret;
9400   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9401     {
9402       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
9403       ret.insert(ret.end(),tmp.begin(),tmp.end());
9404     }
9405   return ret;
9406 }
9407
9408 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
9409 {
9410   std::vector<std::string> ret;
9411   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9412     {
9413       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9414       ret.insert(ret.end(),tmp.begin(),tmp.end());
9415     }
9416   return ret;
9417 }
9418
9419 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
9420 {
9421   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9422     (*it)->changePflsRefsNamesGen2(mapOfModif);
9423 }
9424
9425 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
9426 {
9427   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9428     (*it)->changeLocsRefsNamesGen2(mapOfModif);
9429 }
9430
9431 void MEDFileFields::resize(int newSize) throw(INTERP_KERNEL::Exception)
9432 {
9433   _fields.resize(newSize);
9434 }
9435
9436 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields) throw(INTERP_KERNEL::Exception)
9437 {
9438   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
9439     pushField(*it);
9440 }
9441
9442 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
9443 {
9444   if(!field)
9445     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
9446   _fields.push_back(field->getContent());
9447   appendGlobs(*field,1e-12);
9448 }
9449
9450 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
9451 {
9452   if(!field)
9453     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9454   if(i>=(int)_fields.size())
9455     _fields.resize(i+1);
9456   _fields[i]=field->getContent();
9457   appendGlobs(*field,1e-12);
9458 }
9459
9460 void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception)
9461 {
9462   destroyFieldsAtPos(&i,&i+1);
9463 }
9464
9465 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
9466 {
9467   std::vector<bool> b(_fields.size(),true);
9468   for(const int *i=startIds;i!=endIds;i++)
9469     {
9470       if(*i<0 || *i>=(int)_fields.size())
9471         {
9472           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9473           throw INTERP_KERNEL::Exception(oss.str().c_str());
9474         }
9475       b[*i]=false;
9476     }
9477   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9478   std::size_t j=0;
9479   for(std::size_t i=0;i<_fields.size();i++)
9480     if(b[i])
9481       fields[j++]=_fields[i];
9482   _fields=fields;
9483 }
9484
9485 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
9486 {
9487   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9488   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
9489   std::vector<bool> b(_fields.size(),true);
9490   int k=bg;
9491   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9492     {
9493       if(k<0 || k>=(int)_fields.size())
9494         {
9495           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9496           throw INTERP_KERNEL::Exception(oss.str().c_str());
9497         }
9498       b[k]=false;
9499     }
9500   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9501   std::size_t j=0;
9502   for(std::size_t i=0;i<_fields.size();i++)
9503     if(b[i])
9504       fields[j++]=_fields[i];
9505   _fields=fields;
9506 }
9507
9508 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
9509 {
9510   bool ret=false;
9511   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9512     {
9513       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9514       if(cur)
9515         ret=cur->changeMeshNames(modifTab) || ret;
9516     }
9517   return ret;
9518 }
9519
9520 /*!
9521  * \param [in] meshName the name of the mesh that will be renumbered.
9522  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9523  *             This code corresponds to the distribution of types in the corresponding mesh.
9524  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9525  * \param [in] renumO2N the old to new renumber array.
9526  * \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 
9527  *         field in \a this.
9528  */
9529 bool MEDFileFields::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N) throw(INTERP_KERNEL::Exception)
9530 {
9531   bool ret=false;
9532   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9533     {
9534       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9535       if(fmts)
9536         {
9537           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9538         }
9539     }
9540   return ret;
9541 }
9542
9543 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception)
9544 {
9545   if(i<0 || i>=(int)_fields.size())
9546     {
9547       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9548       throw INTERP_KERNEL::Exception(oss.str().c_str());
9549     }
9550   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9551   if(!fmts)
9552     return 0;
9553   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
9554   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
9555   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
9556   if(fmtsC)
9557     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9558   else if(fmtsC2)
9559     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9560   else
9561     {
9562       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
9563       throw INTERP_KERNEL::Exception(oss.str().c_str());
9564     }
9565   ret->shallowCpyGlobs(*this);
9566   return ret.retn();
9567 }
9568
9569 /*!
9570  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9571  * This method is accessible in python using __getitem__ with a list in input.
9572  * \return a new object that the caller should deal with.
9573  */
9574 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
9575 {
9576   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9577   std::size_t sz=std::distance(startIds,endIds);
9578   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9579   int j=0;
9580   for(const int *i=startIds;i!=endIds;i++,j++)
9581     {
9582       if(*i<0 || *i>=(int)_fields.size())
9583         {
9584           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9585           throw INTERP_KERNEL::Exception(oss.str().c_str());
9586         }
9587       fields[j]=_fields[*i];
9588     }
9589   ret->_fields=fields;
9590   return ret.retn();
9591 }
9592
9593 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
9594 {
9595   return getFieldAtPos(getPosFromFieldName(fieldName));
9596 }
9597
9598 /*!
9599  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9600  * This method can be seen as a filter applied on \a this, that returns an object containing
9601  * 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
9602  * shallow copied from \a this.
9603  * 
9604  * \param [in] meshName - the name of the mesh on w
9605  * \return a new object that the caller should deal with.
9606  */
9607 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const char *meshName) const throw(INTERP_KERNEL::Exception)
9608 {
9609   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9610   ret->shallowCpyOnlyUsedGlobs(*this);
9611   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9612     {
9613       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9614       if(!cur)
9615         continue;
9616       if(cur->getMeshName()==meshName)
9617         {
9618           cur->incrRef();
9619           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
9620           ret->_fields.push_back(cur2);
9621         }
9622     }
9623   return ret.retn();
9624 }
9625
9626 /*!
9627  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
9628  * Input time steps are specified using a pair of integer (iteration, order).
9629  * 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,
9630  * but for each multitimestep only the time steps in \a timeSteps are kept.
9631  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
9632  * 
9633  * The returned object points to shallow copy of elements in \a this.
9634  * 
9635  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
9636  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
9637  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9638  */
9639 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
9640 {
9641   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9642   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9643     {
9644       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9645       if(!cur)
9646         continue;
9647       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
9648       ret->_fields.push_back(elt);
9649     }
9650   ret->shallowCpyOnlyUsedGlobs(*this);
9651   return ret.retn();
9652 }
9653
9654 /*!
9655  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
9656  */
9657 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
9658 {
9659   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9660   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9661     {
9662       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9663       if(!cur)
9664         continue;
9665       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
9666       if(elt->getNumberOfTS()!=0)
9667         ret->_fields.push_back(elt);
9668     }
9669   ret->shallowCpyOnlyUsedGlobs(*this);
9670   return ret.retn();
9671 }
9672
9673 MEDFileFieldsIterator *MEDFileFields::iterator() throw(INTERP_KERNEL::Exception)
9674 {
9675   return new MEDFileFieldsIterator(this);
9676 }
9677
9678 int MEDFileFields::getPosFromFieldName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
9679 {
9680   std::string tmp(fieldName);
9681   std::vector<std::string> poss;
9682   for(std::size_t i=0;i<_fields.size();i++)
9683     {
9684       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
9685       if(f)
9686         {
9687           std::string fname(f->getName());
9688           if(tmp==fname)
9689             return i;
9690           else
9691             poss.push_back(fname);
9692         }
9693     }
9694   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
9695   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
9696   oss << " !";
9697   throw INTERP_KERNEL::Exception(oss.str().c_str());
9698 }
9699
9700 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
9701 {
9702   if(fs)
9703     {
9704       fs->incrRef();
9705       _nb_iter=fs->getNumberOfFields();
9706     }
9707 }
9708
9709 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
9710 {
9711 }
9712
9713 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
9714 {
9715   if(_iter_id<_nb_iter)
9716     {
9717       MEDFileFields *fs(_fs);
9718       if(fs)
9719         return fs->getFieldAtPos(_iter_id++);
9720       else
9721         return 0;
9722     }
9723   else
9724     return 0;
9725 }