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