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