Salome HOME
Merge from V6_main (dev of Anthony GEAY) 11/06/2013
[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 /*!
3526  * Prints a string describing \a this field into a stream. This string is outputted 
3527  * by \c print Python command.
3528  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3529  *  \param [in,out] oss - the out stream.
3530  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3531  *          info id printed, else, not.
3532  */
3533 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3534 {
3535   std::string startOfLine(bkOffset,' ');
3536   oss << startOfLine << "Field ";
3537   if(bkOffset==0)
3538     oss << "[Type=" << getTypeStr() << "] ";
3539   oss << "on One time Step ";
3540   if(f1tsId>=0)
3541     oss << "(" << f1tsId << ") ";
3542   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3543   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3544   const DataArray *arr=getUndergroundDataArray();
3545   if(arr)
3546     {
3547       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3548       if(f1tsId<0)
3549         {
3550           oss << startOfLine << "Field Name : \"" << arr->getName() << "\"." << std::endl;
3551           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3552           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3553             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3554         }
3555       if(arr->isAllocated())
3556         {
3557           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3558         }
3559       else
3560         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3561     }
3562   else
3563     {
3564       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3565     }
3566   oss << startOfLine << "----------------------" << std::endl;
3567   if(!_field_per_mesh.empty())
3568     {
3569       int i=0;
3570       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3571         {
3572           const MEDFileFieldPerMesh *cur=(*it2);
3573           if(cur)
3574             cur->simpleRepr(bkOffset,oss,i);
3575           else
3576             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3577         }
3578     }
3579   else
3580     {
3581       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3582     }
3583   oss << startOfLine << "----------------------" << std::endl;
3584 }
3585
3586 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const throw(INTERP_KERNEL::Exception)
3587 {
3588   const DataArray *arr(getUndergroundDataArray());
3589   if(!arr)
3590     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3591   int nbOfCompo=arr->getNumberOfComponents();
3592   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3593   for(int i=0;i<nbOfCompo;i++)
3594     {
3595       ret[i]=deepCpy();
3596       std::vector<int> v(1,i);
3597       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3598       ret[i]->setArray(arr2);
3599     }
3600   return ret;
3601 }
3602
3603 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order):MEDFileFieldNameScope(fieldName),_iteration(iteration),_order(order),_csit(csit)
3604 {
3605 }
3606
3607 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1)
3608 {
3609 }
3610
3611 /*!
3612  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3613  * empty. Returns -1 if this in on nodes.
3614  *  \return int - the dimension of \a this.
3615  */
3616 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3617 {
3618   int ret=-2;
3619   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3620     (*it)->getDimension(ret);
3621   return ret;
3622 }
3623
3624 /*!
3625  * Returns the mesh name.
3626  *  \return std::string - a string holding the mesh name.
3627  *  \throw If \c _field_per_mesh.empty()
3628  */
3629 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
3630 {
3631   if(_field_per_mesh.empty())
3632     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3633   return _field_per_mesh[0]->getMeshName();
3634 }
3635
3636 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
3637 {
3638   std::string oldName(getMeshName());
3639   std::vector< std::pair<std::string,std::string> > v(1);
3640   v[0].first=oldName; v[0].second=newMeshName;
3641   changeMeshNames(v);
3642 }
3643
3644 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
3645 {
3646   bool ret=false;
3647   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3648     {
3649       MEDFileFieldPerMesh *cur(*it);
3650       if(cur)
3651         ret=cur->changeMeshNames(modifTab) || ret;
3652     }
3653   return ret;
3654 }
3655
3656 /*!
3657  * Returns the number of iteration of the state of underlying mesh.
3658  *  \return int - the iteration number.
3659  *  \throw If \c _field_per_mesh.empty()
3660  */
3661 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const throw(INTERP_KERNEL::Exception)
3662 {
3663   if(_field_per_mesh.empty())
3664     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3665   return _field_per_mesh[0]->getMeshIteration();
3666 }
3667
3668 /*!
3669  * Returns the order number of iteration of the state of underlying mesh.
3670  *  \return int - the order number.
3671  *  \throw If \c _field_per_mesh.empty()
3672  */
3673 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const throw(INTERP_KERNEL::Exception)
3674 {
3675   if(_field_per_mesh.empty())
3676     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3677   return _field_per_mesh[0]->getMeshOrder();
3678 }
3679
3680 /*!
3681  * Checks if \a this field is tagged by a given iteration number and a given
3682  * iteration order number.
3683  *  \param [in] iteration - the iteration number of interest.
3684  *  \param [in] order - the iteration order number of interest.
3685  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3686  *          \a this->getOrder() == \a order.
3687  */
3688 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3689 {
3690   return iteration==_iteration && order==_order;
3691 }
3692
3693 /*!
3694  * Returns number of iteration and order number of iteration when
3695  * \a this field has been calculated.
3696  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3697  *          order number.
3698  */
3699 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3700 {
3701   std::pair<int,int> p;
3702   fillIteration(p);
3703   return p;
3704 }
3705
3706 /*!
3707  * Returns number of iteration and order number of iteration when
3708  * \a this field has been calculated.
3709  *  \param [in,out] p - a pair returning the iteration number and the iteration
3710  *          order number.
3711  */
3712 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3713 {
3714   p.first=_iteration;
3715   p.second=_order;
3716 }
3717
3718 /*!
3719  * Returns all types of spatial discretization of \a this field.
3720  *  \param [in,out] types - a sequence of types of \a this field.
3721  */
3722 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
3723 {
3724   std::set<TypeOfField> types2;
3725   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3726     {
3727       (*it)->fillTypesOfFieldAvailable(types2);
3728     }
3729   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3730   std::copy(types2.begin(),types2.end(),bi);
3731 }
3732
3733 /*!
3734  * Returns all types of spatial discretization of \a this field.
3735  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3736  *          of \a this field.
3737  */
3738 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
3739 {
3740   std::vector<TypeOfField> ret;
3741   fillTypesOfFieldAvailable(ret);
3742   return ret;
3743 }
3744
3745 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3746 {
3747   std::vector<std::string> ret;
3748   std::set<std::string> ret2;
3749   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3750     {
3751       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3752       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3753         if(ret2.find(*it2)==ret2.end())
3754           {
3755             ret.push_back(*it2);
3756             ret2.insert(*it2);
3757           }
3758     }
3759   return ret;
3760 }
3761
3762 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3763 {
3764   std::vector<std::string> ret;
3765   std::set<std::string> ret2;
3766   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3767     {
3768       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3769       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3770         if(ret2.find(*it2)==ret2.end())
3771           {
3772             ret.push_back(*it2);
3773             ret2.insert(*it2);
3774           }
3775     }
3776   return ret;
3777 }
3778
3779 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3780 {
3781   std::vector<std::string> ret;
3782   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3783     {
3784       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3785       ret.insert(ret.end(),tmp.begin(),tmp.end());
3786     }
3787   return ret;
3788 }
3789
3790 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3791 {
3792   std::vector<std::string> ret;
3793   std::set<std::string> ret2;
3794   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3795     {
3796       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3797       ret.insert(ret.end(),tmp.begin(),tmp.end());
3798     }
3799   return ret;
3800 }
3801
3802 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3803 {
3804   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3805     (*it)->changePflsRefsNamesGen(mapOfModif);
3806 }
3807
3808 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3809 {
3810   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3811     (*it)->changeLocsRefsNamesGen(mapOfModif);
3812 }
3813
3814 /*!
3815  * Returns all attributes of parts of \a this field lying on a given mesh.
3816  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3817  * item of every of returned sequences refers to the _i_-th part of \a this field.
3818  * Thus all sequences returned by this method are of the same length equal to number
3819  * of different types of supporting entities.<br>
3820  * A field part can include sub-parts with several different spatial discretizations,
3821  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3822  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3823  * of a nested sequence corresponds to a type of spatial discretization.<br>
3824  * This method allows for iteration over MEDFile DataStructure without any overhead.
3825  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3826  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3827  *          not checked if \a mname == \c NULL).
3828  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3829  *          a field part is returned. 
3830  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3831  *          This sequence is of the same length as \a types. 
3832  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3833  *          discretization. A profile name can be empty.
3834  *          Length of this and of nested sequences is the same as that of \a typesF.
3835  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3836  *          discretization. A localization name can be empty.
3837  *          Length of this and of nested sequences is the same as that of \a typesF.
3838  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3839  *          of ids of tuples within the data array, per each type of spatial
3840  *          discretization within one mesh entity type. 
3841  *          Length of this and of nested sequences is the same as that of \a typesF.
3842  *  \throw If no field is lying on \a mname.
3843  */
3844 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)
3845 {
3846   int meshId=0;
3847   if(mname)
3848     meshId=getMeshIdFromMeshName(mname);
3849   else
3850     if(_field_per_mesh.empty())
3851       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3852   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3853 }
3854
3855 /*!
3856  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
3857  * maximal absolute dimension and values returned via the out parameter \a levs are 
3858  * dimensions relative to the maximal absolute dimension. <br>
3859  * This method is designed for MEDFileField1TS instances that have a discretization
3860  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
3861  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
3862  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
3863  * Only these 3 discretizations will be taken into account here. If \a this is
3864  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
3865  * This method is useful to make the link between the dimension of the underlying mesh
3866  * and the levels of \a this, because it is possible that the highest dimension of \a this
3867  * field is not equal to the dimension of the underlying mesh.
3868  * 
3869  * Let's consider the following case:
3870  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
3871  * TETRA4, HEXA8, TRI3 and SEG2.
3872  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
3873  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
3874  *
3875  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
3876  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
3877  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
3878  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
3879  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
3880  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
3881  * For example<br>
3882  * to retrieve the highest level of
3883  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
3884  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
3885  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
3886  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
3887  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3888  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3889  *          not checked if \a mname == \c NULL).
3890  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
3891  *          absolute one. They are in decreasing order. This sequence is cleared before
3892  *          filling it in.
3893  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
3894  *  \throw If no field is lying on \a mname.
3895  */
3896 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
3897 {
3898   levs.clear();
3899   int meshId=getMeshIdFromMeshName(mname);
3900   std::vector<INTERP_KERNEL::NormalizedCellType> types;
3901   std::vector< std::vector<TypeOfField> > typesF;
3902   std::vector< std::vector<std::string> > pfls, locs;
3903   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3904   if(types.empty())
3905     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
3906   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
3907   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
3908     return -1;
3909   st.erase(INTERP_KERNEL::NORM_ERROR);
3910   std::set<int> ret1;
3911   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
3912     {
3913       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
3914       ret1.insert((int)cm.getDimension());
3915     }
3916   int ret=*std::max_element(ret1.begin(),ret1.end());
3917   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
3918   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
3919   return ret;
3920 }
3921
3922 /*!
3923  * \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.
3924  * \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.
3925  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3926  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3927  */
3928 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
3929 {
3930   int mid=getMeshIdFromMeshName(mName);
3931   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3932 }
3933
3934 /*!
3935  * \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.
3936  * \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.
3937  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3938  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3939  */
3940 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
3941 {
3942   int mid=getMeshIdFromMeshName(mName);
3943   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3944 }
3945
3946 /*!
3947  * \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.
3948  */
3949 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception)
3950 {
3951   if(_field_per_mesh.empty())
3952     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
3953   if(mName==0)
3954     return 0;
3955   std::string mName2(mName);
3956   int ret=0;
3957   std::vector<std::string> msg;
3958   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
3959     if(mName2==(*it)->getMeshName())
3960       return ret;
3961     else
3962       msg.push_back((*it)->getMeshName());
3963   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
3964   oss << "Possible meshes are : ";
3965   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
3966     oss << "\"" << (*it2) << "\" ";
3967   throw INTERP_KERNEL::Exception(oss.str().c_str());
3968 }
3969
3970 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
3971 {
3972   if(!mesh)
3973     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
3974   std::string tmp(mesh->getName());
3975   if(tmp.empty())
3976     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
3977   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
3978   int i=0;
3979   for(;it!=_field_per_mesh.end();it++,i++)
3980     {
3981       if((*it)->getMeshName()==tmp)
3982         return i;
3983     }
3984   int sz=_field_per_mesh.size();
3985   _field_per_mesh.resize(sz+1);
3986   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
3987   return sz;
3988 }
3989
3990 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
3991                                                             MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
3992 {
3993   bool ret=false;
3994   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3995     {
3996       MEDFileFieldPerMesh *fpm(*it);
3997       if(fpm)
3998         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
3999     }
4000   return ret;
4001 }
4002
4003 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4004 {
4005   if(_field_per_mesh.empty())
4006     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4007   if(_field_per_mesh.size()>1)
4008     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4009   _field_per_mesh[0]->copyOptionsFrom(opts);
4010   _field_per_mesh[0]->writeLL(fid,nasc);
4011 }
4012
4013 void MEDFileAnyTypeField1TSWithoutSDA::finishLoading(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4014 {
4015   med_int numdt,numit;
4016   med_float dt;
4017   med_int nmesh;
4018   med_bool localMesh;
4019   med_int meshnumdt,meshnumit;
4020   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4021   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4022   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4023   if(_iteration!=numdt || _order!=numit)
4024     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::finishLoading : unexpected exception internal error !");
4025   _field_per_mesh.resize(nmesh);
4026   for(int i=0;i<nmesh;i++)
4027     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i+1,meshnumdt,meshnumit,nasc);//tony
4028   int start=0;
4029   for(int i=0;i<nmesh;i++)
4030     {
4031       _field_per_mesh[i]->prepareLoading(fid,start,nasc);
4032     }
4033   getOrCreateAndGetArray()->alloc(start,getNumberOfComponents());
4034   for(int i=0;i<nmesh;i++)
4035     {
4036       _field_per_mesh[i]->finishLoading(fid,nasc);
4037     }
4038 }
4039
4040 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySize() const
4041 {
4042   std::size_t ret=_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4043   if(getUndergroundDataArray())
4044     ret+=getUndergroundDataArray()->getHeapMemorySize();
4045   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4046     ret+=(*it)->getHeapMemorySize();
4047   return ret;
4048 }
4049
4050 /*!
4051  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4052  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4053  * "Sort By Type"), if not, an exception is thrown. 
4054  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4055  *  \param [in] arr - the array of values.
4056  *  \param [in,out] glob - the global data where profiles and localization present in
4057  *          \a field, if any, are added.
4058  *  \throw If the name of \a field is empty.
4059  *  \throw If the data array of \a field is not set.
4060  *  \throw If \a this->_arr is already allocated but has different number of components
4061  *         than \a field.
4062  *  \throw If the underlying mesh of \a field has no name.
4063  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4064  */
4065 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4066 {
4067   const MEDCouplingMesh *mesh=field->getMesh();
4068   //
4069   TypeOfField type=field->getTypeOfField();
4070   std::vector<DataArrayInt *> dummy;
4071   int start=copyTinyInfoFrom(field,arr);
4072   int pos=addNewEntryIfNecessary(mesh);
4073   if(type!=ON_NODES)
4074     {
4075       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4076       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4077     }
4078   else
4079     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4080 }
4081
4082 /*!
4083  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4084  * of a given mesh are used as the support of the given field (a real support is not used). 
4085  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4086  * Order of underlying mesh entities of the given field specified by \a profile parameter
4087  * is not prescribed; this method permutes field values to have them sorted by element
4088  * type as required for writing to MED file. A new profile is added only if no equal
4089  * profile is missing. 
4090  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4091  *  \param [in] arrOfVals - the values of the field \a field used.
4092  *  \param [in] mesh - the supporting mesh of \a field.
4093  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4094  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4095  *  \param [in,out] glob - the global data where profiles and localization present in
4096  *          \a field, if any, are added.
4097  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4098  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4099  *  \throw If the data array of \a field is not set.
4100  *  \throw If \a this->_arr is already allocated but has different number of components
4101  *         than \a field.
4102  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4103  *  \sa setFieldNoProfileSBT()
4104  */
4105 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)
4106 {
4107   TypeOfField type=field->getTypeOfField();
4108   int start=copyTinyInfoFrom(field,arrOfVals);
4109   std::vector<DataArrayInt *> idsInPflPerType;
4110   std::vector<DataArrayInt *> idsPerType;
4111   std::vector<int> code,code2;
4112   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4113   if(type!=ON_NODES)
4114     {
4115       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4116       code2=m->getDistributionOfTypes();
4117       //
4118       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size());
4119       for(std::size_t i=0;i<idsInPflPerType.size();i++)
4120         idsInPflPerType2[i]=idsInPflPerType[i];
4121       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size());
4122       for(std::size_t i=0;i<idsPerType.size();i++)
4123         idsPerType2[i]=idsPerType[i];
4124       //
4125       int pos=addNewEntryIfNecessary(m);
4126       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4127     }
4128   else
4129     {
4130       int pos=addNewEntryIfNecessary(m);
4131       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4132     }
4133 }
4134
4135 /*!
4136  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4137  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4138  * larger by the size of \a field. Returns an id of the first not filled
4139  * tuple of \a this->_arr.
4140  *  \param [in] field - the field to copy the info on components and the name from.
4141  *  \return int - the id of first not initialized tuple of \a this->_arr.
4142  *  \throw If the name of \a field is empty.
4143  *  \throw If the data array of \a field is not set.
4144  *  \throw If \a this->_arr is already allocated but has different number of components
4145  *         than \a field.
4146  */
4147 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
4148 {
4149   if(!field)
4150     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4151   std::string name(field->getName());
4152   setName(name.c_str());
4153   setDtUnit(field->getTimeUnit());
4154   if(name.empty())
4155     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4156   if(!arr)
4157     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4158   _dt=field->getTime(_iteration,_order);
4159   int nbOfComponents=arr->getNumberOfComponents();
4160   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4161   if(!getOrCreateAndGetArray()->isAllocated())
4162     {
4163       getOrCreateAndGetArray()->alloc(arr->getNumberOfTuples(),arr->getNumberOfComponents());
4164       return 0;
4165     }
4166   else
4167     {
4168       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4169       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4170       MEDCouplingAutoRefCountObjectPtr<DataArray> tmp=createNewEmptyDataArrayInstance();
4171       tmp->alloc(newNbOfTuples,nbOfComponents);
4172       tmp->copyStringInfoFrom(*getOrCreateAndGetArray());
4173       DataArray *arrr=getOrCreateAndGetArray();      
4174       tmp->setContigPartOfSelectedValues2(0,arrr,0,oldNbOfTuples,1);
4175       setArray(tmp);
4176       return oldNbOfTuples;
4177     }
4178 }
4179
4180 /*!
4181  * Returns number of components in \a this field
4182  *  \return int - the number of components.
4183  */
4184 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4185 {
4186   return getOrCreateAndGetArray()->getNumberOfComponents();
4187 }
4188
4189 /*!
4190  * Change info on components in \a this.
4191  * \throw If size of \a infos is not equal to the number of components already in \a this.
4192  */
4193 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
4194 {
4195   DataArray *arr=getOrCreateAndGetArray();
4196   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4197 }
4198
4199 /*!
4200  * Returns info on components of \a this field.
4201  *  \return const std::vector<std::string>& - a sequence of strings each being an
4202  *          information on _i_-th component.
4203  */
4204 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4205 {
4206   const DataArray *arr=getOrCreateAndGetArray();
4207   return arr->getInfoOnComponents();
4208 }
4209
4210 /*!
4211  * Returns a mutable info on components of \a this field.
4212  *  \return std::vector<std::string>& - a sequence of strings each being an
4213  *          information on _i_-th component.
4214  */
4215 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4216 {
4217   DataArray *arr=getOrCreateAndGetArray();
4218   return arr->getInfoOnComponents();
4219 }
4220
4221 /*!
4222  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4223  *  \param [in] type - a spatial discretization of the new field.
4224  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4225  *  \param [in] mName - a name of the supporting mesh.
4226  *  \param [in] renumPol - specifies how to permute values of the result field according to
4227  *          the optional numbers of cells and nodes, if any. The valid values are
4228  *          - 0 - do not permute.
4229  *          - 1 - permute cells.
4230  *          - 2 - permute nodes.
4231  *          - 3 - permute cells and nodes.
4232  *
4233  *  \param [in] glob - the global data storing profiles and localization.
4234  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4235  *          caller is to delete this field using decrRef() as it is no more needed. 
4236  *  \throw If the MED file is not readable.
4237  *  \throw If there is no mesh named \a mName in the MED file.
4238  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4239  *  \throw If no field of \a this is lying on the mesh \a mName.
4240  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4241  */
4242 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)
4243 {
4244   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4245   if(mName==0)
4246     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4247   else
4248     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4249   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4250 }
4251
4252 /*!
4253  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4254  *  \param [in] type - a spatial discretization of the new field.
4255  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4256  *  \param [in] renumPol - specifies how to permute values of the result field according to
4257  *          the optional numbers of cells and nodes, if any. The valid values are
4258  *          - 0 - do not permute.
4259  *          - 1 - permute cells.
4260  *          - 2 - permute nodes.
4261  *          - 3 - permute cells and nodes.
4262  *
4263  *  \param [in] glob - the global data storing profiles and localization.
4264  *  \param [in] mesh - the supporting mesh.
4265  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4266  *          caller is to delete this field using decrRef() as it is no more needed. 
4267  *  \throw If the MED file is not readable.
4268  *  \throw If no field of \a this is lying on \a mesh.
4269  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4270  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4271  */
4272 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)
4273 {
4274   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4275   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4276   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4277   if(meshDimRelToMax==1)
4278     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4279   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4280 }
4281
4282 /*!
4283  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4284  * given mesh. 
4285  *  \param [in] type - a spatial discretization of the new field.
4286  *  \param [in] mName - a name of the supporting mesh.
4287  *  \param [in] renumPol - specifies how to permute values of the result field according to
4288  *          the optional numbers of cells and nodes, if any. The valid values are
4289  *          - 0 - do not permute.
4290  *          - 1 - permute cells.
4291  *          - 2 - permute nodes.
4292  *          - 3 - permute cells and nodes.
4293  *
4294  *  \param [in] glob - the global data storing profiles and localization.
4295  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4296  *          caller is to delete this field using decrRef() as it is no more needed. 
4297  *  \throw If the MED file is not readable.
4298  *  \throw If there is no mesh named \a mName in the MED file.
4299  *  \throw If there are no mesh entities in the mesh.
4300  *  \throw If no field values of the given \a type are available.
4301  */
4302 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4303 {
4304    MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4305   if(mName==0)
4306     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4307   else
4308     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4309   int absDim=getDimension();
4310   int meshDimRelToMax=absDim-mm->getMeshDimension();
4311   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4312 }
4313
4314 /*!
4315  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4316  *  \param [in] type - a spatial discretization of the new field.
4317  *  \param [in] renumPol - specifies how to permute values of the result field according to
4318  *          the optional numbers of cells and nodes, if any. The valid values are
4319  *          - 0 - do not permute.
4320  *          - 1 - permute cells.
4321  *          - 2 - permute nodes.
4322  *          - 3 - permute cells and nodes.
4323  *
4324  *  \param [in] glob - the global data storing profiles and localization.
4325  *  \param [in] mesh - the supporting mesh.
4326  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4327  *         field according to \a renumPol.
4328  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4329  *         field according to \a renumPol.
4330  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4331  *          caller is to delete this field using decrRef() as it is no more needed. 
4332  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4333  *  \throw If no field of \a this is lying on \a mesh.
4334  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4335  */
4336 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)
4337 {
4338   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4339   int meshId=getMeshIdFromMeshName(mesh->getName());
4340   bool isPfl=false;
4341   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4342   switch(renumPol)
4343     {
4344     case 0:
4345       {
4346         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4347         return ret.retn();
4348       }
4349     case 3:
4350     case 1:
4351       {
4352         if(isPfl)
4353           throw INTERP_KERNEL::Exception(msg1);
4354         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4355         if(cellRenum)
4356           {
4357             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4358               {
4359                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4360                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4361                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4362               }
4363             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4364             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4365             std::vector<DataArray *> arrOut2(1,arrOut);
4366             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4367             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4368             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4369           }
4370         if(renumPol==1)
4371           return ret.retn();
4372       }
4373     case 2:
4374       {
4375         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4376         if(isPfl)
4377           throw INTERP_KERNEL::Exception(msg1);
4378         if(nodeRenum)
4379           {
4380             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4381               {
4382                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4383                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4384                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4385               }
4386             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4387             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4388               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4389             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4390           }
4391         return ret.retn();
4392       }
4393     default:
4394       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4395     }
4396 }
4397
4398 /*!
4399  * Returns values and a profile of the field of a given type lying on a given support.
4400  *  \param [in] type - a spatial discretization of the field.
4401  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4402  *  \param [in] mesh - the supporting mesh.
4403  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4404  *          field of interest lies on. If the field lies on all entities of the given
4405  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4406  *          using decrRef() as it is no more needed.  
4407  *  \param [in] glob - the global data storing profiles and localization.
4408  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4409  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4410  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4411  *  \throw If no field of \a this is lying on \a mesh.
4412  *  \throw If no field values of the given \a type are available.
4413  */
4414 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4415 {
4416   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4417   int meshId=getMeshIdFromMeshName(mesh->getName());
4418   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4419   ret->setName(nasc.getName().c_str());
4420   return ret.retn();
4421 }
4422
4423 //= MEDFileField1TSWithoutSDA
4424
4425 /*!
4426  * Throws if a given value is not a valid (non-extended) relative dimension.
4427  *  \param [in] meshDimRelToMax - the relative dimension value.
4428  *  \throw If \a meshDimRelToMax > 0.
4429  */
4430 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
4431 {
4432   if(meshDimRelToMax>0)
4433     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4434 }
4435
4436 /*!
4437  * Checks if elements of a given mesh are in the order suitable for writing 
4438  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4439  * vector describing types of elements and their number.
4440  *  \param [in] mesh - the mesh to check.
4441  *  \return std::vector<int> - a vector holding for each element type (1) item of
4442  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4443  *          These values are in full-interlace mode.
4444  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4445  */
4446 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
4447 {
4448   if(!mesh)
4449     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4450   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4451   int nbOfTypes=geoTypes.size();
4452   std::vector<int> code(3*nbOfTypes);
4453   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4454   arr1->alloc(nbOfTypes,1);
4455   int *arrPtr=arr1->getPointer();
4456   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4457   for(int i=0;i<nbOfTypes;i++,it++)
4458     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4459   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4460   const int *arrPtr2=arr2->getConstPointer();
4461   int i=0;
4462   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4463     {
4464       int pos=arrPtr2[i];
4465       int nbCells=mesh->getNumberOfCellsWithType(*it);
4466       code[3*pos]=(int)(*it);
4467       code[3*pos+1]=nbCells;
4468       code[3*pos+2]=-1;//no profiles
4469     }
4470   std::vector<const DataArrayInt *> idsPerType;//no profiles
4471   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4472   if(da)
4473     {
4474       da->decrRef();
4475       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4476     }
4477   return code;
4478 }
4479
4480 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const char *fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4481 {
4482   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4483 }
4484
4485 /*!
4486  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4487  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4488  * item of every of returned sequences refers to the _i_-th part of \a this field.
4489  * Thus all sequences returned by this method are of the same length equal to number
4490  * of different types of supporting entities.<br>
4491  * A field part can include sub-parts with several different spatial discretizations,
4492  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4493  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4494  * of a nested sequence corresponds to a type of spatial discretization.<br>
4495  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4496  * The overhead is due to selecting values into new instances of DataArrayDouble.
4497  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4498  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4499  *          not checked if \a mname == \c NULL).
4500  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4501  *          a field part is returned. 
4502  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4503  *          A field part can include sub-parts with several different spatial discretizations,
4504  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4505  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4506  *          This sequence is of the same length as \a types. 
4507  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4508  *          discretization. A profile name can be empty.
4509  *          Length of this and of nested sequences is the same as that of \a typesF.
4510  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4511  *          discretization. A localization name can be empty.
4512  *          Length of this and of nested sequences is the same as that of \a typesF.
4513  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4514  *          per each type of spatial discretization within one mesh entity type.
4515  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4516  *          Length of this and of nested sequences is the same as that of \a typesF.
4517  *  \throw If no field is lying on \a mname.
4518  */
4519 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)
4520 {
4521   int meshId=0;
4522   if(mname)
4523     meshId=getMeshIdFromMeshName(mname);
4524   else
4525     if(_field_per_mesh.empty())
4526       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4527   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4528   int nbOfRet=ret0.size();
4529   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4530   for(int i=0;i<nbOfRet;i++)
4531     {
4532       const std::vector< std::pair<int,int> >& p=ret0[i];
4533       int nbOfRet1=p.size();
4534       ret[i].resize(nbOfRet1);
4535       for(int j=0;j<nbOfRet1;j++)
4536         {
4537           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4538           ret[i][j]=tmp;
4539         }
4540     }
4541   return ret;
4542 }
4543
4544 /*!
4545  * Returns a pointer to the underground DataArrayDouble instance. So the
4546  * caller should not decrRef() it. This method allows for a direct access to the field
4547  * values. This method is quite unusable if there is more than a nodal field or a cell
4548  * field on single geometric cell type. 
4549  *  \return DataArrayDouble * - the pointer to the field values array.
4550  */
4551 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const throw(INTERP_KERNEL::Exception)
4552 {
4553   const DataArrayDouble *ret=_arr;
4554   if(ret)
4555     return const_cast<DataArrayDouble *>(ret);
4556   else
4557     return 0;
4558 }
4559
4560 const char *MEDFileField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
4561 {
4562   return TYPE_STR;
4563 }
4564
4565 /*!
4566  * Returns a pointer to the underground DataArrayDouble instance. So the
4567  * caller should not decrRef() it. This method allows for a direct access to the field
4568  * values. This method is quite unusable if there is more than a nodal field or a cell
4569  * field on single geometric cell type. 
4570  *  \return DataArrayDouble * - the pointer to the field values array.
4571  */
4572 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4573 {
4574   return getUndergroundDataArrayDouble();
4575 }
4576
4577 /*!
4578  * Returns a pointer to the underground DataArrayDouble instance and a
4579  * sequence describing parameters of a support of each part of \a this field. The
4580  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4581  * direct access to the field values. This method is intended for the field lying on one
4582  * mesh only.
4583  *  \param [in,out] entries - the sequence describing parameters of a support of each
4584  *         part of \a this field. Each item of this sequence consists of two parts. The
4585  *         first part describes a type of mesh entity and an id of discretization of a
4586  *         current field part. The second part describes a range of values [begin,end)
4587  *         within the returned array relating to the current field part.
4588  *  \return DataArrayDouble * - the pointer to the field values array.
4589  *  \throw If the number of underlying meshes is not equal to 1.
4590  *  \throw If no field values are available.
4591  *  \sa getUndergroundDataArray()
4592  */
4593 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4594 {
4595   if(_field_per_mesh.size()!=1)
4596     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4597   if(_field_per_mesh[0]==0)
4598     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4599   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4600   return getUndergroundDataArrayDouble();
4601 }
4602
4603 /*!
4604  * Returns a pointer to the underground DataArrayDouble instance and a
4605  * sequence describing parameters of a support of each part of \a this field. The
4606  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4607  * direct access to the field values. This method is intended for the field lying on one
4608  * mesh only.
4609  *  \param [in,out] entries - the sequence describing parameters of a support of each
4610  *         part of \a this field. Each item of this sequence consists of two parts. The
4611  *         first part describes a type of mesh entity and an id of discretization of a
4612  *         current field part. The second part describes a range of values [begin,end)
4613  *         within the returned array relating to the current field part.
4614  *  \return DataArrayDouble * - the pointer to the field values array.
4615  *  \throw If the number of underlying meshes is not equal to 1.
4616  *  \throw If no field values are available.
4617  *  \sa getUndergroundDataArray()
4618  */
4619 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4620 {
4621   return getUndergroundDataArrayDoubleExt(entries);
4622 }
4623
4624 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order,
4625                                                      const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4626 {
4627   DataArrayDouble *arr=getOrCreateAndGetArrayDouble();
4628   arr->setInfoAndChangeNbOfCompo(infos);
4629 }
4630
4631 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4632 {
4633 }
4634
4635 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
4636 {
4637   return new MEDFileField1TSWithoutSDA(*this);
4638 }
4639
4640 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
4641 {
4642   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
4643   if((const DataArrayDouble *)_arr)
4644     ret->_arr=_arr->deepCpy();
4645   std::size_t i=0;
4646   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,i++)
4647     {
4648       if((const MEDFileFieldPerMesh *)*it)
4649         ret->_field_per_mesh[i]=(*it)->deepCpy((MEDFileField1TSWithoutSDA *)ret);
4650     }
4651   return ret.retn();
4652 }
4653
4654 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
4655 {
4656   if(!arr)
4657     _arr=0;
4658   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
4659   if(!arrC)
4660     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
4661   arrC->incrRef();
4662   _arr=arrC;
4663 }
4664
4665 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4666 {
4667   return DataArrayDouble::New();
4668 }
4669
4670 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
4671 {
4672   DataArrayDouble *ret=_arr;
4673   if(ret)
4674     return ret;
4675   _arr=DataArrayDouble::New();
4676   return _arr;
4677 }
4678
4679 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
4680 {
4681   return getOrCreateAndGetArrayDouble();
4682 }
4683
4684 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
4685 {
4686   const DataArrayDouble *ret=_arr;
4687   if(ret)
4688     return ret;
4689   DataArrayDouble *ret2=DataArrayDouble::New();
4690   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
4691   return ret2;
4692 }
4693
4694 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
4695 {
4696   return getOrCreateAndGetArrayDouble();
4697 }
4698
4699 //= MEDFileIntField1TSWithoutSDA
4700
4701 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const char *fieldName, int csit, int iteration, int order,
4702                                                                 const std::vector<std::string>& infos)
4703 {
4704   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4705 }
4706
4707 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4708 {
4709 }
4710
4711 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order,
4712                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4713 {
4714   DataArrayInt *arr=getOrCreateAndGetArrayInt();
4715   arr->setInfoAndChangeNbOfCompo(infos);
4716 }
4717
4718 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
4719 {
4720   return TYPE_STR;
4721 }
4722
4723 /*!
4724  * Returns a pointer to the underground DataArrayInt instance. So the
4725  * caller should not decrRef() it. This method allows for a direct access to the field
4726  * values. This method is quite unusable if there is more than a nodal field or a cell
4727  * field on single geometric cell type. 
4728  *  \return DataArrayInt * - the pointer to the field values array.
4729  */
4730 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4731 {
4732   return getUndergroundDataArrayInt();
4733 }
4734
4735 /*!
4736  * Returns a pointer to the underground DataArrayInt instance. So the
4737  * caller should not decrRef() it. This method allows for a direct access to the field
4738  * values. This method is quite unusable if there is more than a nodal field or a cell
4739  * field on single geometric cell type. 
4740  *  \return DataArrayInt * - the pointer to the field values array.
4741  */
4742 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const throw(INTERP_KERNEL::Exception)
4743 {
4744   const DataArrayInt *ret=_arr;
4745   if(ret)
4746     return const_cast<DataArrayInt *>(ret);
4747   else
4748     return 0;
4749 }
4750
4751 /*!
4752  * Returns a pointer to the underground DataArrayInt instance and a
4753  * sequence describing parameters of a support of each part of \a this field. The
4754  * caller should not decrRef() the returned DataArrayInt. This method allows for a
4755  * direct access to the field values. This method is intended for the field lying on one
4756  * mesh only.
4757  *  \param [in,out] entries - the sequence describing parameters of a support of each
4758  *         part of \a this field. Each item of this sequence consists of two parts. The
4759  *         first part describes a type of mesh entity and an id of discretization of a
4760  *         current field part. The second part describes a range of values [begin,end)
4761  *         within the returned array relating to the current field part.
4762  *  \return DataArrayInt * - the pointer to the field values array.
4763  *  \throw If the number of underlying meshes is not equal to 1.
4764  *  \throw If no field values are available.
4765  *  \sa getUndergroundDataArray()
4766  */
4767 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4768 {
4769   return getUndergroundDataArrayIntExt(entries);
4770 }
4771
4772 /*!
4773  * Returns a pointer to the underground DataArrayInt instance and a
4774  * sequence describing parameters of a support of each part of \a this field. The
4775  * caller should not decrRef() the returned DataArrayInt. This method allows for a
4776  * direct access to the field values. This method is intended for the field lying on one
4777  * mesh only.
4778  *  \param [in,out] entries - the sequence describing parameters of a support of each
4779  *         part of \a this field. Each item of this sequence consists of two parts. The
4780  *         first part describes a type of mesh entity and an id of discretization of a
4781  *         current field part. The second part describes a range of values [begin,end)
4782  *         within the returned array relating to the current field part.
4783  *  \return DataArrayInt * - the pointer to the field values array.
4784  *  \throw If the number of underlying meshes is not equal to 1.
4785  *  \throw If no field values are available.
4786  *  \sa getUndergroundDataArray()
4787  */
4788 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4789 {
4790   if(_field_per_mesh.size()!=1)
4791     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4792   if(_field_per_mesh[0]==0)
4793     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4794   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4795   return getUndergroundDataArrayInt();
4796 }
4797
4798 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
4799 {
4800   return new MEDFileIntField1TSWithoutSDA(*this);
4801 }
4802
4803 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
4804 {
4805   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
4806   if((const DataArrayInt *)_arr)
4807     ret->_arr=_arr->deepCpy();
4808   std::size_t i=0;
4809   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,i++)
4810     {
4811       if((const MEDFileFieldPerMesh *)*it)
4812         ret->_field_per_mesh[i]=(*it)->deepCpy((MEDFileIntField1TSWithoutSDA *)ret);
4813     }
4814   return ret.retn();
4815 }
4816
4817 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
4818 {
4819   if(!arr)
4820     _arr=0;
4821   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
4822   if(!arrC)
4823     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
4824   _arr=arrC;
4825 }
4826
4827 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4828 {
4829   return DataArrayInt::New();
4830 }
4831
4832 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
4833 {
4834   DataArrayInt *ret=_arr;
4835   if(ret)
4836     return ret;
4837   _arr=DataArrayInt::New();
4838   return _arr;
4839 }
4840
4841 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
4842 {
4843   return getOrCreateAndGetArrayInt();
4844 }
4845
4846 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
4847 {
4848   const DataArrayInt *ret=_arr;
4849   if(ret)
4850     return ret;
4851   DataArrayInt *ret2=DataArrayInt::New();
4852   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
4853   return ret2;
4854 }
4855
4856 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
4857 {
4858   return getOrCreateAndGetArrayInt();
4859 }
4860
4861 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
4862 {
4863 }
4864
4865 //= MEDFileAnyTypeField1TS
4866
4867 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName) throw(INTERP_KERNEL::Exception)
4868 {
4869   med_field_type typcha;
4870   //
4871   std::vector<std::string> infos;
4872   std::string dtunit,fieldName;
4873   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
4874   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
4875   switch(typcha)
4876     {
4877     case MED_FLOAT64:
4878       {
4879         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4880         break;
4881       }
4882     case MED_INT32:
4883       {
4884         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4885         break;
4886       }
4887     default:
4888       {
4889         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] !";
4890         throw INTERP_KERNEL::Exception(oss.str().c_str());
4891       }
4892     }
4893   ret->setDtUnit(dtunit.c_str());
4894   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
4895   //
4896   med_int numdt,numit;
4897   med_float dt;
4898   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
4899   ret->setTime(numdt,numit,dt);
4900   ret->_csit=1;
4901   ret->finishLoading(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
4902   return ret.retn();
4903 }
4904
4905 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName) throw(INTERP_KERNEL::Exception)
4906 try:MEDFileFieldGlobsReal(fileName)
4907 {
4908   MEDFileUtilities::CheckFileForRead(fileName);
4909   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
4910   _content=BuildContentFrom(fid,fileName);
4911   loadGlobals(fid);
4912 }
4913 catch(INTERP_KERNEL::Exception& e)
4914   {
4915     throw e;
4916   }
4917
4918 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
4919 {
4920   med_field_type typcha;
4921   std::vector<std::string> infos;
4922   std::string dtunit;
4923   int iii=-1;
4924   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
4925   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
4926   switch(typcha)
4927     {
4928     case MED_FLOAT64:
4929       {
4930         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4931         break;
4932       }
4933     case MED_INT32:
4934       {
4935         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
4936         break;
4937       }
4938     default:
4939       {
4940         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] !";
4941         throw INTERP_KERNEL::Exception(oss.str().c_str());
4942       }
4943     }
4944   ret->setDtUnit(dtunit.c_str());
4945   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
4946   //
4947   if(nbSteps<1)
4948     {
4949       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
4950       throw INTERP_KERNEL::Exception(oss.str().c_str());
4951     }
4952   //
4953   med_int numdt,numit;
4954   med_float dt;
4955   MEDfieldComputingStepInfo(fid,fieldName,1,&numdt,&numit,&dt);
4956   ret->setTime(numdt,numit,dt);
4957   ret->_csit=1;
4958   ret->finishLoading(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
4959   return ret.retn();
4960 }
4961
4962 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
4963 try:MEDFileFieldGlobsReal(fileName)
4964 {
4965   MEDFileUtilities::CheckFileForRead(fileName);
4966   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
4967   _content=BuildContentFrom(fid,fileName,fieldName);
4968   loadGlobals(fid);
4969 }
4970 catch(INTERP_KERNEL::Exception& e)
4971   {
4972     throw e;
4973   }
4974
4975 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const char *fileName) throw(INTERP_KERNEL::Exception)
4976 {
4977   if(!c)
4978     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
4979   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
4980     {
4981       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
4982       ret->setFileName(fileName);
4983       ret->_content=c; c->incrRef();
4984       return ret.retn();
4985     }
4986   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
4987     {
4988       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
4989       ret->setFileName(fileName);
4990       ret->_content=c; c->incrRef();
4991       return ret.retn();
4992     }
4993   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
4994 }
4995
4996 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
4997 {
4998   MEDFileUtilities::CheckFileForRead(fileName);
4999   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5000   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName);
5001   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5002   ret->loadGlobals(fid);
5003   return ret.retn();
5004 }
5005
5006 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
5007 {
5008   MEDFileUtilities::CheckFileForRead(fileName);
5009   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5010   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName);
5011   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5012   ret->loadGlobals(fid);
5013   return ret.retn();
5014 }
5015
5016 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
5017 {
5018   MEDFileUtilities::CheckFileForRead(fileName);
5019   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5020   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order);
5021   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5022   ret->loadGlobals(fid);
5023   return ret.retn();
5024 }
5025
5026 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
5027 {
5028   med_field_type typcha;
5029   std::vector<std::string> infos;
5030   std::string dtunit;
5031   int iii=-1;
5032   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5033   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5034   switch(typcha)
5035     {
5036     case MED_FLOAT64:
5037       {
5038         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5039         break;
5040       }
5041     case MED_INT32:
5042       {
5043         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5044         break;
5045       }
5046     default:
5047       {
5048         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] !";
5049         throw INTERP_KERNEL::Exception(oss.str().c_str());
5050       }
5051     }
5052   ret->setDtUnit(dtunit.c_str());
5053   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5054   //
5055   bool found=false;
5056   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5057   for(int i=0;i<nbOfStep2 && !found;i++)
5058     {
5059       med_int numdt,numit;
5060       med_float dt;
5061       MEDfieldComputingStepInfo(fid,fieldName,i+1,&numdt,&numit,&dt);
5062       if(numdt==iteration && numit==order)
5063         {
5064           found=true;
5065           ret->_csit=i+1;
5066         }
5067       else
5068         dtits[i]=std::pair<int,int>(numdt,numit);
5069     }
5070   if(!found)
5071     {
5072       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5073       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5074         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5075       throw INTERP_KERNEL::Exception(oss.str().c_str());
5076     }
5077   ret->finishLoading(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5078   return ret.retn();
5079 }
5080
5081 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
5082 try:MEDFileFieldGlobsReal(fileName)
5083 {
5084   MEDFileUtilities::CheckFileForRead(fileName);
5085   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5086   _content=BuildContentFrom(fid,fileName,fieldName,iteration,order);
5087   loadGlobals(fid);
5088 }
5089 catch(INTERP_KERNEL::Exception& e)
5090   {
5091     throw e;
5092   }
5093
5094 /*!
5095  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5096  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5097  *
5098  * \warning this is a shallow copy constructor
5099  */
5100 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5101 {
5102   if(!shallowCopyOfContent)
5103     {
5104       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5105       otherPtr->incrRef();
5106       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5107     }
5108   else
5109     {
5110       _content=other.shallowCpy();
5111     }
5112 }
5113
5114 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)
5115 {
5116   if(checkFieldId)
5117     {
5118       int nbFields=MEDnField(fid);
5119       if(fieldIdCFormat>=nbFields)
5120         {
5121           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5122           throw INTERP_KERNEL::Exception(oss.str().c_str());
5123         }
5124     }
5125   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5126   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5127   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5128   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5129   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5130   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5131   med_bool localMesh;
5132   int nbOfStep;
5133   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5134   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5135   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5136   infos.clear(); infos.resize(ncomp);
5137   for(int j=0;j<ncomp;j++)
5138     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5139   return nbOfStep;
5140 }
5141
5142 /*!
5143  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5144  * 
5145  * \param [out]
5146  * \return in case of success the number of time steps available for the field with name \a fieldName.
5147  */
5148 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)
5149 {
5150   int nbFields=MEDnField(fid);
5151   bool found=false;
5152   std::vector<std::string> fns(nbFields);
5153   int nbOfStep2=-1;
5154   for(int i=0;i<nbFields && !found;i++)
5155     {
5156       std::string tmp;
5157       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5158       fns[i]=tmp;
5159       found=(tmp==fieldName);
5160       if(found)
5161         posCFormat=i;
5162     }
5163   if(!found)
5164     {
5165       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5166       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5167         oss << "\"" << *it << "\" ";
5168       throw INTERP_KERNEL::Exception(oss.str().c_str());
5169     }
5170   return nbOfStep2;
5171 }
5172
5173 /*!
5174  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5175  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5176  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5177  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5178  * to keep a valid instance.
5179  * 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.
5180  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5181  * 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.
5182  *
5183  * \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.
5184  * \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.
5185  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5186  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5187  * \param [in] newLocName is the new localization name.
5188  * \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.
5189  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5190  */
5191 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newPflName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
5192 {
5193   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5194   std::string oldPflName=disc->getProfile();
5195   std::vector<std::string> vv=getPflsReallyUsedMulti();
5196   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5197   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5198     {
5199       disc->setProfile(newPflName);
5200       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5201       pfl->setName(newPflName);
5202     }
5203   else
5204     {
5205       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5206       throw INTERP_KERNEL::Exception(oss.str().c_str());
5207     }
5208 }
5209
5210 /*!
5211  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5212  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5213  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5214  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5215  * to keep a valid instance.
5216  * 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.
5217  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5218  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5219  * 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.
5220  *
5221  * \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.
5222  * \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.
5223  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5224  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5225  * \param [in] newLocName is the new localization name.
5226  * \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.
5227  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5228  */
5229 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newLocName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
5230 {
5231   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5232   std::string oldLocName=disc->getLocalization();
5233   std::vector<std::string> vv=getLocsReallyUsedMulti();
5234   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5235   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5236     {
5237       disc->setLocalization(newLocName);
5238       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5239       loc.setName(newLocName);
5240     }
5241   else
5242     {
5243       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5244       throw INTERP_KERNEL::Exception(oss.str().c_str());
5245     }
5246 }
5247
5248 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() throw(INTERP_KERNEL::Exception)
5249 {
5250   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5251   if(!ret)
5252     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5253   return ret;
5254 }
5255
5256 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const throw(INTERP_KERNEL::Exception)
5257 {
5258   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5259   if(!ret)
5260     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5261   return ret;
5262 }
5263
5264 /*!
5265  * Writes \a this field into a MED file specified by its name.
5266  *  \param [in] fileName - the MED file name.
5267  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5268  * - 2 - erase; an existing file is removed.
5269  * - 1 - append; same data should not be present in an existing file.
5270  * - 0 - overwrite; same data present in an existing file is overwritten.
5271  *  \throw If the field name is not set.
5272  *  \throw If no field data is set.
5273  *  \throw If \a mode == 1 and the same data is present in an existing file.
5274  */
5275 void MEDFileAnyTypeField1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
5276 {
5277   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5278   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
5279   writeLL(fid);
5280 }
5281
5282 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
5283 {
5284   int nbComp=getNumberOfComponents();
5285   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5286   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5287   for(int i=0;i<nbComp;i++)
5288     {
5289       std::string info=getInfo()[i];
5290       std::string c,u;
5291       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5292       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5293       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5294     }
5295   if(getName().empty())
5296     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5297   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5298   writeGlobals(fid,*this);
5299   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5300 }
5301
5302 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySize() const
5303 {
5304   std::size_t ret=0;
5305   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5306     ret+=_content->getHeapMemorySize();
5307   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
5308 }
5309
5310 /*!
5311  * Returns a string describing \a this field. This string is outputted 
5312  * by \c print Python command.
5313  */
5314 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5315 {
5316   std::ostringstream oss;
5317   contentNotNullBase()->simpleRepr(0,oss,-1);
5318   simpleReprGlobs(oss);
5319   return oss.str();
5320 }
5321
5322 /*!
5323  * This method returns all profiles whose name is non empty used.
5324  * \b WARNING If profile is used several times it will be reported \b only \b once.
5325  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5326  */
5327 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5328 {
5329   return contentNotNullBase()->getPflsReallyUsed2();
5330 }
5331
5332 /*!
5333  * This method returns all localizations whose name is non empty used.
5334  * \b WARNING If localization is used several times it will be reported \b only \b once.
5335  */
5336 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5337 {
5338   return contentNotNullBase()->getLocsReallyUsed2();
5339 }
5340
5341 /*!
5342  * This method returns all profiles whose name is non empty used.
5343  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5344  */
5345 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5346 {
5347   return contentNotNullBase()->getPflsReallyUsedMulti2();
5348 }
5349
5350 /*!
5351  * This method returns all localizations whose name is non empty used.
5352  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5353  */
5354 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5355 {
5356   return contentNotNullBase()->getLocsReallyUsedMulti2();
5357 }
5358
5359 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5360 {
5361   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5362 }
5363
5364 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5365 {
5366   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5367 }
5368
5369 int MEDFileAnyTypeField1TS::getDimension() const
5370 {
5371   return contentNotNullBase()->getDimension();
5372 }
5373
5374 int MEDFileAnyTypeField1TS::getIteration() const
5375 {
5376   return contentNotNullBase()->getIteration();
5377 }
5378
5379 int MEDFileAnyTypeField1TS::getOrder() const
5380 {
5381   return contentNotNullBase()->getOrder();
5382 }
5383
5384 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5385 {
5386   return contentNotNullBase()->getTime(iteration,order);
5387 }
5388
5389 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5390 {
5391   contentNotNullBase()->setTime(iteration,order,val);
5392 }
5393
5394 std::string MEDFileAnyTypeField1TS::getName() const
5395 {
5396   return contentNotNullBase()->getName();
5397 }
5398
5399 void MEDFileAnyTypeField1TS::setName(const char *name)
5400 {
5401   contentNotNullBase()->setName(name);
5402 }
5403
5404 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5405 {
5406   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5407 }
5408
5409 std::string MEDFileAnyTypeField1TS::getDtUnit() const throw(INTERP_KERNEL::Exception)
5410 {
5411   return contentNotNullBase()->getDtUnit();
5412 }
5413
5414 void MEDFileAnyTypeField1TS::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
5415 {
5416   contentNotNullBase()->setDtUnit(dtUnit);
5417 }
5418
5419 std::string MEDFileAnyTypeField1TS::getMeshName() const throw(INTERP_KERNEL::Exception)
5420 {
5421   return contentNotNullBase()->getMeshName();
5422 }
5423
5424 void MEDFileAnyTypeField1TS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
5425 {
5426   contentNotNullBase()->setMeshName(newMeshName);
5427 }
5428
5429 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
5430 {
5431   return contentNotNullBase()->changeMeshNames(modifTab);
5432 }
5433
5434 int MEDFileAnyTypeField1TS::getMeshIteration() const throw(INTERP_KERNEL::Exception)
5435 {
5436   return contentNotNullBase()->getMeshIteration();
5437 }
5438
5439 int MEDFileAnyTypeField1TS::getMeshOrder() const throw(INTERP_KERNEL::Exception)
5440 {
5441   return contentNotNullBase()->getMeshOrder();
5442 }
5443
5444 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5445 {
5446   return contentNotNullBase()->getNumberOfComponents();
5447 }
5448
5449 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5450 {
5451   return contentNotNullBase()->isDealingTS(iteration,order);
5452 }
5453
5454 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5455 {
5456   return contentNotNullBase()->getDtIt();
5457 }
5458
5459 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5460 {
5461   contentNotNullBase()->fillIteration(p);
5462 }
5463
5464 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
5465 {
5466   contentNotNullBase()->fillTypesOfFieldAvailable(types);
5467 }
5468
5469 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
5470 {
5471   contentNotNullBase()->setInfo(infos);
5472 }
5473
5474 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
5475 {
5476   return contentNotNullBase()->getInfo();
5477 }
5478 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
5479 {
5480   return contentNotNullBase()->getInfo();
5481 }
5482
5483 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
5484 {
5485   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5486 }
5487
5488 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
5489 {
5490   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5491 }
5492
5493 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
5494 {
5495   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
5496 }
5497
5498 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
5499 {
5500   return contentNotNullBase()->getTypesOfFieldAvailable();
5501 }
5502
5503 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,
5504                                                                                        std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
5505 {
5506   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5507 }
5508
5509 /*!
5510  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
5511  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5512  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
5513  */
5514 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const throw(INTERP_KERNEL::Exception)
5515 {
5516   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5517   if(!content)
5518     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
5519   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
5520   std::size_t sz(contentsSplit.size());
5521   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5522   for(std::size_t i=0;i<sz;i++)
5523     {
5524       ret[i]=shallowCpy();
5525       ret[i]->_content=contentsSplit[i];
5526     }
5527   return ret;
5528 }
5529
5530 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const throw(INTERP_KERNEL::Exception)
5531 {
5532   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
5533   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5534     ret->_content=_content->deepCpy();
5535   ret->deepCpyGlobs(*this);
5536   return ret.retn();
5537 }
5538
5539 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
5540 {
5541   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
5542 }
5543
5544 //= MEDFileField1TS
5545
5546 /*!
5547  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5548  * the first field that has been read from a specified MED file.
5549  *  \param [in] fileName - the name of the MED file to read.
5550  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5551  *          is to delete this field using decrRef() as it is no more needed.
5552  *  \throw If reading the file fails.
5553  */
5554 MEDFileField1TS *MEDFileField1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
5555 {
5556   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName);
5557   ret->contentNotNull();
5558   return ret.retn();
5559 }
5560
5561 /*!
5562  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5563  * a given field that has been read from a specified MED file.
5564  *  \param [in] fileName - the name of the MED file to read.
5565  *  \param [in] fieldName - the name of the field to read.
5566  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5567  *          is to delete this field using decrRef() as it is no more needed.
5568  *  \throw If reading the file fails.
5569  *  \throw If there is no field named \a fieldName in the file.
5570  */
5571 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
5572 {
5573   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName);
5574   ret->contentNotNull();
5575   return ret.retn();
5576 }
5577
5578 /*!
5579  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
5580  * a given field that has been read from a specified MED file.
5581  *  \param [in] fileName - the name of the MED file to read.
5582  *  \param [in] fieldName - the name of the field to read.
5583  *  \param [in] iteration - the iteration number of a required time step.
5584  *  \param [in] order - the iteration order number of required time step.
5585  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5586  *          is to delete this field using decrRef() as it is no more needed.
5587  *  \throw If reading the file fails.
5588  *  \throw If there is no field named \a fieldName in the file.
5589  *  \throw If the required time step is missing from the file.
5590  */
5591 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
5592 {
5593   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,iteration,order);
5594   ret->contentNotNull();
5595   return ret.retn();
5596 }
5597
5598 /*!
5599  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5600  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5601  *
5602  * Returns a new instance of MEDFileField1TS holding either a shallow copy
5603  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
5604  * \warning this is a shallow copy constructor
5605  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
5606  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
5607  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5608  *          is to delete this field using decrRef() as it is no more needed.
5609  */
5610 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
5611 {
5612   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
5613   ret->contentNotNull();
5614   return ret.retn();
5615 }
5616
5617 /*!
5618  * Returns a new empty instance of MEDFileField1TS.
5619  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5620  *          is to delete this field using decrRef() as it is no more needed.
5621  */
5622 MEDFileField1TS *MEDFileField1TS::New()
5623 {
5624   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
5625   ret->contentNotNull();
5626   return ret.retn();
5627 }
5628
5629 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const throw(INTERP_KERNEL::Exception)
5630 {
5631   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
5632   if(!pt)
5633     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
5634   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
5635   if(!ret)
5636     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 !");
5637   return ret;
5638 }
5639
5640 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() throw(INTERP_KERNEL::Exception)
5641 {
5642   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
5643   if(!pt)
5644     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
5645   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
5646   if(!ret)
5647     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 !");
5648   return ret;
5649 }
5650
5651 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
5652 {
5653   if(!f)
5654     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
5655   if(!((DataArray*)arr))
5656     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
5657   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
5658   if(!arrOutC)
5659     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
5660   f->setArray(arrOutC);
5661 }
5662
5663 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
5664 {
5665   if(!((DataArray*)arr))
5666     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
5667   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
5668   if(!arrOutC)
5669     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
5670   arrOutC->incrRef();
5671   return arrOutC;
5672 }
5673
5674 MEDFileField1TS::MEDFileField1TS(const char *fileName) throw(INTERP_KERNEL::Exception)
5675 try:MEDFileAnyTypeField1TS(fileName)
5676 {
5677 }
5678 catch(INTERP_KERNEL::Exception& e)
5679   { throw e; }
5680
5681 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
5682 try:MEDFileAnyTypeField1TS(fileName,fieldName)
5683 {
5684 }
5685 catch(INTERP_KERNEL::Exception& e)
5686   { throw e; }
5687
5688 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
5689 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order)
5690 {
5691 }
5692 catch(INTERP_KERNEL::Exception& e)
5693   { throw e; }
5694
5695 /*!
5696  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5697  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5698  *
5699  * \warning this is a shallow copy constructor
5700  */
5701 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
5702 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
5703 {
5704 }
5705 catch(INTERP_KERNEL::Exception& e)
5706   { throw e; }
5707
5708 MEDFileField1TS::MEDFileField1TS()
5709 {
5710   _content=new MEDFileField1TSWithoutSDA;
5711 }
5712
5713 /*!
5714  * Returns a new MEDCouplingFieldDouble of a given type lying on
5715  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
5716  * has not been constructed via file reading, an exception is thrown.
5717  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5718  *  \param [in] type - a spatial discretization of interest.
5719  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5720  *  \param [in] renumPol - specifies how to permute values of the result field according to
5721  *          the optional numbers of cells and nodes, if any. The valid values are
5722  *          - 0 - do not permute.
5723  *          - 1 - permute cells.
5724  *          - 2 - permute nodes.
5725  *          - 3 - permute cells and nodes.
5726  *
5727  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5728  *          caller is to delete this field using decrRef() as it is no more needed. 
5729  *  \throw If \a this field has not been constructed via file reading.
5730  *  \throw If the MED file is not readable.
5731  *  \throw If there is no mesh in the MED file.
5732  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5733  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5734  *  \sa getFieldOnMeshAtLevel()
5735  */
5736 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
5737 {
5738   if(getFileName2().empty())
5739     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
5740   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5741   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut,*contentNotNull());
5742   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5743   return ret.retn();
5744 }
5745
5746 /*!
5747  * Returns a new MEDCouplingFieldDouble of a given type lying on
5748  * the top level cells of the first mesh in MED file. If \a this field 
5749  * has not been constructed via file reading, an exception is thrown.
5750  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5751  *  \param [in] type - a spatial discretization of interest.
5752  *  \param [in] renumPol - specifies how to permute values of the result field according to
5753  *          the optional numbers of cells and nodes, if any. The valid values are
5754  *          - 0 - do not permute.
5755  *          - 1 - permute cells.
5756  *          - 2 - permute nodes.
5757  *          - 3 - permute cells and nodes.
5758  *
5759  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5760  *          caller is to delete this field using decrRef() as it is no more needed. 
5761  *  \throw If \a this field has not been constructed via file reading.
5762  *  \throw If the MED file is not readable.
5763  *  \throw If there is no mesh in the MED file.
5764  *  \throw If no field values of the given \a type.
5765  *  \throw If no field values lying on the top level support.
5766  *  \sa getFieldAtLevel()
5767  */
5768 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const throw(INTERP_KERNEL::Exception)
5769 {
5770   if(getFileName2().empty())
5771     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
5772   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5773   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,0,renumPol,this,arrOut,*contentNotNull());
5774   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5775   return ret.retn();
5776 }
5777
5778 /*!
5779  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
5780  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5781  *  \param [in] type - a spatial discretization of the new field.
5782  *  \param [in] mesh - the supporting mesh.
5783  *  \param [in] renumPol - specifies how to permute values of the result field according to
5784  *          the optional numbers of cells and nodes, if any. The valid values are
5785  *          - 0 - do not permute.
5786  *          - 1 - permute cells.
5787  *          - 2 - permute nodes.
5788  *          - 3 - permute cells and nodes.
5789  *
5790  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5791  *          caller is to delete this field using decrRef() as it is no more needed. 
5792  *  \throw If no field of \a this is lying on \a mesh.
5793  *  \throw If the mesh is empty.
5794  *  \throw If no field values of the given \a type are available.
5795  *  \sa getFieldAtLevel()
5796  *  \sa getFieldOnMeshAtLevel() 
5797  */
5798 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
5799 {
5800   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5801   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,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 a given support.
5808  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5809  *  \param [in] type - a spatial discretization of interest.
5810  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5811  *  \param [in] mesh - the supporting mesh.
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 there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5822  *  \throw If no field of \a this is lying on \a mesh.
5823  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5824  *  \sa getFieldAtLevel()
5825  *  \sa getFieldOnMeshAtLevel() 
5826  */
5827 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
5828 {
5829   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5830   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
5831   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5832   return ret.retn();
5833 }
5834
5835 /*!
5836  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
5837  * This method is called "Old" because in MED3 norm a field has only one meshName
5838  * attached, so this method is for readers of MED2 files. If \a this field 
5839  * has not been constructed via file reading, an exception is thrown.
5840  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5841  *  \param [in] type - a spatial discretization of interest.
5842  *  \param [in] mName - a name of the supporting mesh.
5843  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5844  *  \param [in] renumPol - specifies how to permute values of the result field according to
5845  *          the optional numbers of cells and nodes, if any. The valid values are
5846  *          - 0 - do not permute.
5847  *          - 1 - permute cells.
5848  *          - 2 - permute nodes.
5849  *          - 3 - permute cells and nodes.
5850  *
5851  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5852  *          caller is to delete this field using decrRef() as it is no more needed. 
5853  *  \throw If the MED file is not readable.
5854  *  \throw If there is no mesh named \a mName in the MED file.
5855  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5856  *  \throw If \a this field has not been constructed via file reading.
5857  *  \throw If no field of \a this is lying on the mesh named \a mName.
5858  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5859  *  \sa getFieldAtLevel()
5860  */
5861 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
5862 {
5863   if(getFileName2().empty())
5864     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
5865   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
5866   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
5867   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
5868   return ret.retn();
5869 }
5870
5871 /*!
5872  * Returns values and a profile of the field of a given type lying on a given support.
5873  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5874  *  \param [in] type - a spatial discretization of the field.
5875  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5876  *  \param [in] mesh - the supporting mesh.
5877  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5878  *          field of interest lies on. If the field lies on all entities of the given
5879  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5880  *          using decrRef() as it is no more needed.  
5881  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5882  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5883  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5884  *  \throw If no field of \a this is lying on \a mesh.
5885  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5886  */
5887 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
5888 {
5889   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
5890   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
5891 }
5892
5893 /*!
5894  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
5895  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
5896  * "Sort By Type"), if not, an exception is thrown. 
5897  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5898  *  \param [in] field - the field to add to \a this.
5899  *  \throw If the name of \a field is empty.
5900  *  \throw If the data array of \a field is not set.
5901  *  \throw If the data array is already allocated but has different number of components
5902  *         than \a field.
5903  *  \throw If the underlying mesh of \a field has no name.
5904  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
5905  */
5906 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
5907 {
5908   setFileName("");
5909   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
5910 }
5911
5912 /*!
5913  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
5914  * of a given mesh are used as the support of the given field (a real support is not used). 
5915  * Elements of the given mesh must be sorted suitable for writing to MED file.
5916  * Order of underlying mesh entities of the given field specified by \a profile parameter
5917  * is not prescribed; this method permutes field values to have them sorted by element
5918  * type as required for writing to MED file. A new profile is added only if no equal
5919  * profile is missing.
5920  * For more info, see \ref AdvMEDLoaderAPIFieldRW
5921  *  \param [in] field - the field to add to \a this.
5922  *  \param [in] mesh - the supporting mesh of \a field.
5923  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
5924  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
5925  *  \throw If either \a field or \a mesh or \a profile has an empty name.
5926  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5927  *  \throw If the data array of \a field is not set.
5928  *  \throw If the data array of \a this is already allocated but has different number of
5929  *         components than \a field.
5930  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5931  *  \sa setFieldNoProfileSBT()
5932  */
5933 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
5934 {
5935   setFileName("");
5936   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
5937 }
5938
5939 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const throw(INTERP_KERNEL::Exception)
5940 {
5941   return new MEDFileField1TS(*this);
5942 }
5943
5944 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
5945 {
5946   return contentNotNull()->getUndergroundDataArrayDouble();
5947 }
5948
5949 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
5950 {
5951   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
5952 }
5953
5954 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
5955                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
5956 {
5957   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
5958 }
5959
5960 //= MEDFileIntField1TS
5961
5962 MEDFileIntField1TS *MEDFileIntField1TS::New()
5963 {
5964   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
5965   ret->contentNotNull();
5966   return ret.retn();
5967 }
5968
5969 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
5970 {
5971   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName);
5972   ret->contentNotNull();
5973   return ret.retn();
5974 }
5975
5976 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
5977 {
5978   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName);
5979   ret->contentNotNull();
5980   return ret.retn();
5981 }
5982
5983 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
5984 {
5985   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,iteration,order);
5986   ret->contentNotNull();
5987   return ret.retn();
5988 }
5989
5990 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
5991 {
5992   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
5993   ret->contentNotNull();
5994   return ret.retn();
5995 }
5996
5997 MEDFileIntField1TS::MEDFileIntField1TS()
5998 {
5999   _content=new MEDFileIntField1TSWithoutSDA;
6000 }
6001
6002 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName) throw(INTERP_KERNEL::Exception)
6003 try:MEDFileAnyTypeField1TS(fileName)
6004 {
6005 }
6006 catch(INTERP_KERNEL::Exception& e)
6007   { throw e; }
6008
6009 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
6010 try:MEDFileAnyTypeField1TS(fileName,fieldName)
6011 {
6012 }
6013 catch(INTERP_KERNEL::Exception& e)
6014   { throw e; }
6015
6016 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
6017 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order)
6018 {
6019 }
6020 catch(INTERP_KERNEL::Exception& e)
6021   { throw e; }
6022
6023 /*!
6024  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6025  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6026  *
6027  * \warning this is a shallow copy constructor
6028  */
6029 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6030 {
6031 }
6032
6033 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const throw(INTERP_KERNEL::Exception)
6034 {
6035   return new MEDFileIntField1TS(*this);
6036 }
6037
6038 /*!
6039  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6040  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6041  * "Sort By Type"), if not, an exception is thrown. 
6042  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6043  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6044  *  \param [in] arrOfVals - the values of the field \a field used.
6045  *  \throw If the name of \a field is empty.
6046  *  \throw If the data array of \a field is not set.
6047  *  \throw If the data array is already allocated but has different number of components
6048  *         than \a field.
6049  *  \throw If the underlying mesh of \a field has no name.
6050  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6051  */
6052 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception)
6053 {
6054   setFileName("");
6055   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6056 }
6057
6058 /*!
6059  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
6060  * of a given mesh are used as the support of the given field (a real support is not used). 
6061  * Elements of the given mesh must be sorted suitable for writing to MED file.
6062  * Order of underlying mesh entities of the given field specified by \a profile parameter
6063  * is not prescribed; this method permutes field values to have them sorted by element
6064  * type as required for writing to MED file. A new profile is added only if no equal
6065  * profile is missing.
6066  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6067  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6068  *  \param [in] arrOfVals - the values of the field \a field used.
6069  *  \param [in] mesh - the supporting mesh of \a field.
6070  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
6071  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6072  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6073  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6074  *  \throw If the data array of \a field is not set.
6075  *  \throw If the data array of \a this is already allocated but has different number of
6076  *         components than \a field.
6077  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6078  *  \sa setFieldNoProfileSBT()
6079  */
6080 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
6081 {
6082   setFileName("");
6083   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6084 }
6085
6086 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const throw(INTERP_KERNEL::Exception)
6087 {
6088   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6089   if(!pt)
6090     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6091   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6092   if(!ret)
6093     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 !");
6094   return ret;
6095 }
6096
6097 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6098 {
6099   if(getFileName2().empty())
6100     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6101   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6102   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut2,*contentNotNull());
6103   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6104   if(!arrOutC)
6105     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6106   arrOut=arrOutC;
6107   return ret.retn();
6108 }
6109
6110 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
6111 {
6112   if(!((DataArray *)arr))
6113     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6114   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6115   if(!arrC)
6116     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6117   arrC->incrRef();
6118   return arrC;
6119 }
6120
6121 /*!
6122  * Returns a new MEDCouplingFieldDouble of a given type lying on
6123  * the top level cells of the first mesh in MED file. If \a this field 
6124  * has not been constructed via file reading, an exception is thrown.
6125  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6126  *  \param [in] type - a spatial discretization of interest.
6127  *  \param [out] arrOut - the DataArrayInt containing values of field.
6128  *  \param [in] renumPol - specifies how to permute values of the result field according to
6129  *          the optional numbers of cells and nodes, if any. The valid values are
6130  *          - 0 - do not permute.
6131  *          - 1 - permute cells.
6132  *          - 2 - permute nodes.
6133  *          - 3 - permute cells and nodes.
6134  *
6135  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6136  *          caller is to delete this field using decrRef() as it is no more needed. 
6137  *  \throw If \a this field has not been constructed via file reading.
6138  *  \throw If the MED file is not readable.
6139  *  \throw If there is no mesh in the MED file.
6140  *  \throw If no field values of the given \a type.
6141  *  \throw If no field values lying on the top level support.
6142  *  \sa getFieldAtLevel()
6143  */
6144 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6145 {
6146   if(getFileName2().empty())
6147     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6148   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6149   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,0,renumPol,this,arr,*contentNotNull());
6150   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6151   return ret.retn();
6152 }
6153
6154 /*!
6155  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6156  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6157  *  \param [in] type - a spatial discretization of the new field.
6158  *  \param [in] mesh - the supporting mesh.
6159  *  \param [out] arrOut - the DataArrayInt containing values of field.
6160  *  \param [in] renumPol - specifies how to permute values of the result field according to
6161  *          the optional numbers of cells and nodes, if any. The valid values are
6162  *          - 0 - do not permute.
6163  *          - 1 - permute cells.
6164  *          - 2 - permute nodes.
6165  *          - 3 - permute cells and nodes.
6166  *
6167  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6168  *          caller is to delete this field using decrRef() as it is no more needed. 
6169  *  \throw If no field of \a this is lying on \a mesh.
6170  *  \throw If the mesh is empty.
6171  *  \throw If no field values of the given \a type are available.
6172  *  \sa getFieldAtLevel()
6173  *  \sa getFieldOnMeshAtLevel() 
6174  */
6175 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6176 {
6177   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6178   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6179   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6180   return ret.retn();
6181 }
6182
6183 /*!
6184  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6185  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6186  *  \param [in] type - a spatial discretization of interest.
6187  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6188  *  \param [out] arrOut - the DataArrayInt containing values of field.
6189  *  \param [in] mesh - the supporting mesh.
6190  *  \param [in] renumPol - specifies how to permute values of the result field according to
6191  *          the optional numbers of cells and nodes, if any. The valid values are
6192  *          - 0 - do not permute.
6193  *          - 1 - permute cells.
6194  *          - 2 - permute nodes.
6195  *          - 3 - permute cells and nodes.
6196  *
6197  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6198  *          caller is to delete this field using decrRef() as it is no more needed. 
6199  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6200  *  \throw If no field of \a this is lying on \a mesh.
6201  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6202  *  \sa getFieldAtLevel()
6203  *  \sa getFieldOnMeshAtLevel() 
6204  */
6205 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6206 {
6207   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6208   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6209   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6210   return ret.retn();
6211 }
6212
6213 /*!
6214  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6215  * This method is called "Old" because in MED3 norm a field has only one meshName
6216  * attached, so this method is for readers of MED2 files. If \a this field 
6217  * has not been constructed via file reading, an exception is thrown.
6218  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6219  *  \param [in] type - a spatial discretization of interest.
6220  *  \param [in] mName - a name of the supporting mesh.
6221  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6222  *  \param [out] arrOut - the DataArrayInt containing values of field.
6223  *  \param [in] renumPol - specifies how to permute values of the result field according to
6224  *          the optional numbers of cells and nodes, if any. The valid values are
6225  *          - 0 - do not permute.
6226  *          - 1 - permute cells.
6227  *          - 2 - permute nodes.
6228  *          - 3 - permute cells and nodes.
6229  *
6230  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6231  *          caller is to delete this field using decrRef() as it is no more needed. 
6232  *  \throw If the MED file is not readable.
6233  *  \throw If there is no mesh named \a mName in the MED file.
6234  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6235  *  \throw If \a this field has not been constructed via file reading.
6236  *  \throw If no field of \a this is lying on the mesh named \a mName.
6237  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6238  *  \sa getFieldAtLevel()
6239  */
6240 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6241 {
6242   if(getFileName2().empty())
6243     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6244   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6245   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6246   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6247   return ret.retn();
6248 }
6249
6250 /*!
6251  * Returns values and a profile of the field of a given type lying on a given support.
6252  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6253  *  \param [in] type - a spatial discretization of the field.
6254  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6255  *  \param [in] mesh - the supporting mesh.
6256  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6257  *          field of interest lies on. If the field lies on all entities of the given
6258  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6259  *          using decrRef() as it is no more needed.  
6260  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6261  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6262  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6263  *  \throw If no field of \a this is lying on \a mesh.
6264  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6265  */
6266 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
6267 {
6268   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6269   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6270 }
6271
6272 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() throw(INTERP_KERNEL::Exception)
6273 {
6274   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6275   if(!pt)
6276     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6277   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6278   if(!ret)
6279     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 !");
6280   return ret;
6281 }
6282
6283 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
6284 {
6285   return contentNotNull()->getUndergroundDataArrayInt();
6286 }
6287
6288 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6289
6290 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6291 {
6292 }
6293
6294 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const char *fieldName):MEDFileFieldNameScope(fieldName)
6295 {
6296 }
6297
6298 /*!
6299  * \param [in] fieldId field id in C mode
6300  */
6301 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId) throw(INTERP_KERNEL::Exception)
6302 {
6303   med_field_type typcha;
6304   std::string dtunitOut;
6305   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6306   setDtUnit(dtunitOut.c_str());
6307   finishLoading(fid,nbOfStep,typcha);
6308 }
6309
6310 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)
6311 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6312 {
6313   setDtUnit(dtunit.c_str());
6314   finishLoading(fid,nbOfStep,fieldTyp);
6315 }
6316 catch(INTERP_KERNEL::Exception& e)
6317 {
6318   throw e;
6319 }
6320
6321 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySize() const
6322 {
6323   std::size_t ret=_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>);
6324   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6325     ret+=(*it).capacity();
6326   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6327     if((const MEDFileAnyTypeField1TSWithoutSDA *)(*it))
6328       ret+=(*it)->getHeapMemorySize();
6329   return ret;
6330 }
6331
6332 /*!
6333  * 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
6334  * NULL.
6335  */
6336 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
6337 {
6338   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6339   ret->setInfo(_infos);
6340   int sz=(int)_time_steps.size();
6341   for(const int *id=startIds;id!=endIds;id++)
6342     {
6343       if(*id>=0 && *id<sz)
6344         {
6345           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6346           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6347           if(tse)
6348             {
6349               tse->incrRef();
6350               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6351             }
6352           ret->pushBackTimeStep(tse2);
6353         }
6354       else
6355         {
6356           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6357           oss << " ! Should be in [0," << sz << ") !";
6358           throw INTERP_KERNEL::Exception(oss.str().c_str());
6359         }
6360     }
6361   if(ret->getNumberOfTS()>0)
6362     ret->synchronizeNameScope();
6363   ret->copyNameScope(*this);
6364   return ret.retn();
6365 }
6366
6367 /*!
6368  * 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
6369  * NULL.
6370  */
6371 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
6372 {
6373   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6374   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6375   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6376   ret->setInfo(_infos);
6377   int sz=(int)_time_steps.size();
6378   int j=bg;
6379   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
6380     {
6381       if(j>=0 && j<sz)
6382         {
6383           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
6384           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6385           if(tse)
6386             {
6387               tse->incrRef();
6388               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6389             }
6390           ret->pushBackTimeStep(tse2);
6391         }
6392       else
6393         {
6394           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
6395           oss << " ! Should be in [0," << sz << ") !";
6396           throw INTERP_KERNEL::Exception(oss.str().c_str());
6397         }
6398     }
6399   if(ret->getNumberOfTS()>0)
6400     ret->synchronizeNameScope();
6401   ret->copyNameScope(*this);
6402   return ret.retn();
6403 }
6404
6405 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
6406 {
6407   int id=0;
6408   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6409   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6410     {
6411       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6412       if(!cur)
6413         continue;
6414       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6415       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
6416         ids->pushBackSilent(id);
6417     }
6418   return buildFromTimeStepIds(ids->begin(),ids->end());
6419 }
6420
6421 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
6422 {
6423   int id=0;
6424   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6425   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6426     {
6427       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6428       if(!cur)
6429         continue;
6430       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6431       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
6432         ids->pushBackSilent(id);
6433     }
6434   return buildFromTimeStepIds(ids->begin(),ids->end());
6435 }
6436
6437 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const throw(INTERP_KERNEL::Exception)
6438 {
6439   return _infos;
6440 }
6441
6442 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
6443 {
6444   _infos=info;
6445 }
6446
6447 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6448 {
6449   int ret=0;
6450   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6451     {
6452       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
6453       if(pt->isDealingTS(iteration,order))
6454         return ret;
6455     }
6456   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
6457   std::vector< std::pair<int,int> > vp=getIterations();
6458   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
6459     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
6460   throw INTERP_KERNEL::Exception(oss.str().c_str());
6461 }
6462
6463 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6464 {
6465   return *_time_steps[getTimeStepPos(iteration,order)];
6466 }
6467
6468 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) throw(INTERP_KERNEL::Exception)
6469 {
6470   return *_time_steps[getTimeStepPos(iteration,order)];
6471 }
6472
6473 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
6474 {
6475   if(_time_steps.empty())
6476     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
6477   return _time_steps[0]->getMeshName();
6478 }
6479
6480 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
6481 {
6482   std::string oldName(getMeshName());
6483   std::vector< std::pair<std::string,std::string> > v(1);
6484   v[0].first=oldName; v[0].second=newMeshName;
6485   changeMeshNames(v);
6486 }
6487
6488 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
6489 {
6490   bool ret=false;
6491   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6492     {
6493       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6494       if(cur)
6495         ret=cur->changeMeshNames(modifTab) || ret;
6496     }
6497   return ret;
6498 }
6499
6500 /*!
6501  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
6502  */
6503 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6504 {
6505   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
6506 }
6507
6508 /*!
6509  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
6510  */
6511 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)
6512 {
6513   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
6514 }
6515
6516 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
6517                                                                 MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
6518 {
6519   bool ret=false;
6520   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6521     {
6522       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
6523       if(f1ts)
6524         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
6525     }
6526   return ret;
6527 }
6528
6529 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
6530 {
6531   std::string startLine(bkOffset,' ');
6532   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
6533   if(fmtsId>=0)
6534     oss << " (" << fmtsId << ")";
6535   oss << " has the following name: \"" << _name << "\"." << std::endl;
6536   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
6537   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6538     {
6539       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
6540     }
6541   int i=0;
6542   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
6543     {
6544       std::string chapter(17,'0'+i);
6545       oss << startLine << chapter << std::endl;
6546       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6547       if(cur)
6548         cur->simpleRepr(bkOffset+2,oss,i);
6549       else
6550         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
6551       oss << startLine << chapter << std::endl;
6552     }
6553 }
6554
6555 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
6556 {
6557   std::size_t sz=_time_steps.size();
6558   std::vector< std::pair<int,int> > ret(sz);
6559   ret1.resize(sz);
6560   for(std::size_t i=0;i<sz;i++)
6561     {
6562       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
6563       if(f1ts)
6564         {
6565           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
6566         }
6567       else
6568         {
6569           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
6570           throw INTERP_KERNEL::Exception(oss.str().c_str());
6571         }
6572     }
6573   return ret;
6574 }
6575
6576 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse) throw(INTERP_KERNEL::Exception)
6577 {
6578   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
6579   if(!tse2)
6580     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
6581   checkCoherencyOfType(tse2);
6582   if(_time_steps.empty())
6583     {
6584       setName(tse2->getName().c_str());
6585       setInfo(tse2->getInfo());
6586     }
6587   checkThatComponentsMatch(tse2->getInfo());
6588   _time_steps.push_back(tse);
6589 }
6590
6591 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope() throw(INTERP_KERNEL::Exception)
6592 {
6593   std::size_t nbOfCompo=_infos.size();
6594   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6595     {
6596       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6597       if(cur)
6598         {
6599           if((cur->getInfo()).size()!=nbOfCompo)
6600             {
6601               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
6602               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
6603               throw INTERP_KERNEL::Exception(oss.str().c_str());
6604             }
6605           cur->copyNameScope(*this);
6606         }
6607     }
6608 }
6609
6610 void MEDFileAnyTypeFieldMultiTSWithoutSDA::finishLoading(med_idt fid, int nbPdt, med_field_type fieldTyp) throw(INTERP_KERNEL::Exception)
6611 {
6612   _time_steps.resize(nbPdt);
6613   for(int i=0;i<nbPdt;i++)
6614     {
6615       std::vector< std::pair<int,int> > ts;
6616       med_int numdt=0,numo=0;
6617       med_int meshIt=0,meshOrder=0;
6618       med_float dt=0.0;
6619       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
6620       switch(fieldTyp)
6621         {
6622         case MED_FLOAT64:
6623           {
6624             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
6625             break;
6626           }
6627         case MED_INT32:
6628           {
6629             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
6630             break;
6631           }
6632         default:
6633           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::finishLoading : managed field type are : FLOAT64, INT32 !");
6634         }
6635       _time_steps[i]->finishLoading(fid,*this);
6636     }
6637 }
6638
6639 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception)
6640 {
6641   if(_time_steps.empty())
6642     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
6643   checkThatNbOfCompoOfTSMatchThis();
6644   std::vector<std::string> infos(getInfo());
6645   int nbComp=infos.size();
6646   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
6647   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
6648   for(int i=0;i<nbComp;i++)
6649     {
6650       std::string info=infos[i];
6651       std::string c,u;
6652       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6653       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
6654       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
6655     }
6656   if(_name.empty())
6657     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
6658   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
6659   int nbOfTS=_time_steps.size();
6660   for(int i=0;i<nbOfTS;i++)
6661     _time_steps[i]->writeLL(fid,opts,*this);
6662 }
6663
6664 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
6665 {
6666   return _time_steps.size();
6667 }
6668
6669 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
6670 {
6671   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
6672   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6673     {
6674       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
6675       if(tmp)
6676         newTS.push_back(*it);
6677     }
6678   _time_steps=newTS;
6679 }
6680
6681 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
6682 {
6683   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
6684   int maxId=(int)_time_steps.size();
6685   int ii=0;
6686   std::set<int> idsToDel;
6687   for(const int *id=startIds;id!=endIds;id++,ii++)
6688     {
6689       if(*id>=0 && *id<maxId)
6690         {
6691           idsToDel.insert(*id);
6692         }
6693       else
6694         {
6695           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
6696           throw INTERP_KERNEL::Exception(oss.str().c_str());
6697         }
6698     }
6699   for(int iii=0;iii<maxId;iii++)
6700     if(idsToDel.find(iii)==idsToDel.end())
6701       newTS.push_back(_time_steps[iii]);
6702   _time_steps=newTS;
6703 }
6704
6705 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
6706 {
6707   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
6708   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6709   if(nbOfEntriesToKill==0)
6710     return ;
6711   std::size_t sz=_time_steps.size();
6712   std::vector<bool> b(sz,true);
6713   int j=bg;
6714   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
6715     b[j]=false;
6716   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
6717   for(std::size_t i=0;i<sz;i++)
6718     if(b[i])
6719       newTS.push_back(_time_steps[i]);
6720   _time_steps=newTS;
6721 }
6722
6723 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6724 {
6725   int ret=0;
6726   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
6727   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6728     {
6729       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
6730       if(tmp)
6731         {
6732           int it2,ord;
6733           tmp->getTime(it2,ord);
6734           if(it2==iteration && order==ord)
6735             return ret;
6736           else
6737             oss << "(" << it2 << ","  << ord << "), ";
6738         }
6739     }
6740   throw INTERP_KERNEL::Exception(oss.str().c_str());
6741 }
6742
6743 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
6744 {
6745   int ret=0;
6746   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
6747   oss.precision(15);
6748   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6749     {
6750       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
6751       if(tmp)
6752         {
6753           int it2,ord;
6754           double ti=tmp->getTime(it2,ord);
6755           if(fabs(time-ti)<eps)
6756             return ret;
6757           else
6758             oss << ti << ", ";
6759         }
6760     }
6761   throw INTERP_KERNEL::Exception(oss.str().c_str());
6762 }
6763
6764 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
6765 {
6766   int lgth=_time_steps.size();
6767   std::vector< std::pair<int,int> > ret(lgth);
6768   for(int i=0;i<lgth;i++)
6769     _time_steps[i]->fillIteration(ret[i]);
6770   return ret;
6771 }
6772
6773 /*!
6774  * 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'
6775  * This method returns two things.
6776  * - The absolute dimension of 'this' in first parameter. 
6777  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
6778  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
6779  *
6780  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
6781  * Only these 3 discretizations will be taken into account here.
6782  *
6783  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
6784  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
6785  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
6786  *
6787  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
6788  * 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'.
6789  * 
6790  * Let's consider the typical following case :
6791  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
6792  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
6793  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
6794  *   TETRA4 and SEG2
6795  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
6796  *
6797  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
6798  * 
6799  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
6800  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
6801  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
6802  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
6803  */
6804 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
6805 {
6806   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
6807 }
6808
6809 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const throw(INTERP_KERNEL::Exception)
6810 {
6811   if(pos<0 || pos>=(int)_time_steps.size())
6812     {
6813       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
6814       throw INTERP_KERNEL::Exception(oss.str().c_str());
6815     }
6816   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
6817   if(item==0)
6818     {
6819       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
6820       oss << "\nTry to use following method eraseEmptyTS !";
6821       throw INTERP_KERNEL::Exception(oss.str().c_str());
6822     }
6823   return item;
6824 }
6825
6826 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) throw(INTERP_KERNEL::Exception)
6827 {
6828   if(pos<0 || pos>=(int)_time_steps.size())
6829     {
6830       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
6831       throw INTERP_KERNEL::Exception(oss.str().c_str());
6832     }
6833   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
6834   if(item==0)
6835     {
6836       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
6837       oss << "\nTry to use following method eraseEmptyTS !";
6838       throw INTERP_KERNEL::Exception(oss.str().c_str());
6839     }
6840   return item;
6841 }
6842
6843 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
6844 {
6845   std::vector<std::string> ret;
6846   std::set<std::string> ret2;
6847   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6848     {
6849       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
6850       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
6851         if(ret2.find(*it2)==ret2.end())
6852           {
6853             ret.push_back(*it2);
6854             ret2.insert(*it2);
6855           }
6856     }
6857   return ret;
6858 }
6859
6860 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
6861 {
6862   std::vector<std::string> ret;
6863   std::set<std::string> ret2;
6864   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6865     {
6866       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
6867       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
6868         if(ret2.find(*it2)==ret2.end())
6869           {
6870             ret.push_back(*it2);
6871             ret2.insert(*it2);
6872           }
6873     }
6874   return ret;
6875 }
6876
6877 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
6878 {
6879   std::vector<std::string> ret;
6880   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6881     {
6882       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
6883       ret.insert(ret.end(),tmp.begin(),tmp.end());
6884     }
6885   return ret;
6886 }
6887
6888 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
6889 {
6890   std::vector<std::string> ret;
6891   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6892     {
6893       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
6894       ret.insert(ret.end(),tmp.begin(),tmp.end());
6895     }
6896   return ret;
6897 }
6898
6899 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
6900 {
6901   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6902     (*it)->changePflsRefsNamesGen2(mapOfModif);
6903 }
6904
6905 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
6906 {
6907   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6908     (*it)->changeLocsRefsNamesGen2(mapOfModif);
6909 }
6910
6911 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
6912 {
6913   int lgth=_time_steps.size();
6914   std::vector< std::vector<TypeOfField> > ret(lgth);
6915   for(int i=0;i<lgth;i++)
6916     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
6917   return ret;
6918 }
6919
6920 /*!
6921  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
6922  */
6923 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)
6924 {
6925   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
6926 }
6927
6928 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
6929 {
6930   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
6931   std::size_t i=0;
6932   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
6933     {
6934       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
6935         ret->_time_steps[i]=(*it)->deepCpy();
6936     }
6937   return ret.retn();
6938 }
6939
6940 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const throw(INTERP_KERNEL::Exception)
6941 {
6942   std::size_t sz(_infos.size()),sz2(_time_steps.size());
6943   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
6944   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
6945   for(std::size_t i=0;i<sz;i++)
6946     {
6947       ret[i]=shallowCpy();
6948       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
6949     }
6950   for(std::size_t i=0;i<sz2;i++)
6951     {
6952       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
6953       if(ret1.size()!=sz)
6954         {
6955           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
6956           throw INTERP_KERNEL::Exception(oss.str().c_str());
6957         }
6958       ts[i]=ret1;
6959     }
6960   for(std::size_t i=0;i<sz;i++)
6961     for(std::size_t j=0;j<sz2;j++)
6962       ret[i]->_time_steps[j]=ts[j][i];
6963   return ret;
6964 }
6965
6966 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
6967 {
6968   _name=field->getName();
6969   if(_name.empty())
6970     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
6971   if(!arr)
6972     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
6973   _infos=arr->getInfoOnComponents();
6974 }
6975
6976 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const throw(INTERP_KERNEL::Exception)
6977 {
6978   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
6979   if(_name!=field->getName())
6980     {
6981       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
6982       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
6983       throw INTERP_KERNEL::Exception(oss.str().c_str());
6984     }
6985   if(!arr)
6986     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
6987   checkThatComponentsMatch(arr->getInfoOnComponents());
6988 }
6989
6990 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const throw(INTERP_KERNEL::Exception)
6991 {
6992   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
6993   if(getInfo().size()!=compos.size())
6994     {
6995       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
6996       oss << " number of components of element to append (" << compos.size() << ") !";
6997       throw INTERP_KERNEL::Exception(oss.str().c_str());
6998     }
6999   if(_infos!=compos)
7000     {
7001       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7002       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7003       oss << " But compo in input fields are : ";
7004       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7005       oss << " !";
7006       throw INTERP_KERNEL::Exception(oss.str().c_str());
7007     }
7008 }
7009
7010 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const throw(INTERP_KERNEL::Exception)
7011 {
7012   std::size_t sz=_infos.size();
7013   int j=0;
7014   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7015     {
7016       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7017       if(elt)
7018         if(elt->getInfo().size()!=sz)
7019           {
7020             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7021             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7022             throw INTERP_KERNEL::Exception(oss.str().c_str());
7023           }
7024     }
7025 }
7026
7027 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
7028 {
7029   if(!field)
7030     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7031   if(!_time_steps.empty())
7032     checkCoherencyOfTinyInfo(field,arr);
7033   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7034   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7035   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7036   copyTinyInfoFrom(field,arr);
7037   _time_steps.push_back(obj);
7038 }
7039
7040 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
7041 {
7042   if(!field)
7043     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7044   if(!_time_steps.empty())
7045     checkCoherencyOfTinyInfo(field,arr);
7046   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7047   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7048   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7049   copyTinyInfoFrom(field,arr);
7050   _time_steps.push_back(obj);
7051 }
7052
7053 //= MEDFileFieldMultiTSWithoutSDA
7054
7055 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)
7056 {
7057   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit);
7058 }
7059
7060 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7061 {
7062 }
7063
7064 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const char *fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7065 {
7066 }
7067
7068 /*!
7069  * \param [in] fieldId field id in C mode
7070  */
7071 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId) throw(INTERP_KERNEL::Exception)
7072 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId)
7073 {
7074 }
7075 catch(INTERP_KERNEL::Exception& e)
7076   { throw e; }
7077
7078 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)
7079 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit)
7080 {
7081 }
7082 catch(INTERP_KERNEL::Exception& e)
7083 { throw e; }
7084
7085 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const throw(INTERP_KERNEL::Exception)
7086 {
7087   return new MEDFileField1TSWithoutSDA;
7088 }
7089
7090 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const throw(INTERP_KERNEL::Exception)
7091 {
7092   if(!f1ts)
7093     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7094   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7095   if(!f1tsC)
7096     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7097 }
7098
7099 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
7100 {
7101   return MEDFileField1TSWithoutSDA::TYPE_STR;
7102 }
7103
7104 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
7105 {
7106   return new MEDFileFieldMultiTSWithoutSDA(*this);
7107 }
7108
7109 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const throw(INTERP_KERNEL::Exception)
7110 {
7111   return new MEDFileFieldMultiTSWithoutSDA;
7112 }
7113
7114 /*!
7115  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7116  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7117  */
7118 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)
7119 {
7120   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7121   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7122   if(!myF1TSC)
7123     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7124   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7125 }
7126
7127 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7128 {
7129 }
7130
7131 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
7132 try:MEDFileFieldGlobsReal(fileName)
7133 {
7134   MEDFileUtilities::CheckFileForRead(fileName);
7135   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7136   _content=BuildContentFrom(fid,fileName);
7137   loadGlobals(fid);
7138 }
7139 catch(INTERP_KERNEL::Exception& e)
7140   {
7141     throw e;
7142   }
7143
7144 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
7145 {
7146   med_field_type typcha;
7147   std::vector<std::string> infos;
7148   std::string dtunit;
7149   int i=-1;
7150   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7151   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7152   switch(typcha)
7153     {
7154     case MED_FLOAT64:
7155       {
7156         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i);
7157         break;
7158       }
7159     case MED_INT32:
7160       {
7161         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i);
7162         break;
7163       }
7164     default:
7165       {
7166         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] !";
7167         throw INTERP_KERNEL::Exception(oss.str().c_str());
7168       }
7169     }
7170   ret->setDtUnit(dtunit.c_str());
7171   return ret.retn();
7172 }
7173
7174 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const char *fileName) throw(INTERP_KERNEL::Exception)
7175 {
7176   med_field_type typcha;
7177   //
7178   std::vector<std::string> infos;
7179   std::string dtunit,fieldName;
7180   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
7181   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7182   switch(typcha)
7183     {
7184     case MED_FLOAT64:
7185       {
7186         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0);
7187         break;
7188       }
7189     case MED_INT32:
7190       {
7191         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0);
7192         break;
7193       }
7194     default:
7195       {
7196         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] !";
7197         throw INTERP_KERNEL::Exception(oss.str().c_str());
7198       }
7199     }
7200   ret->setDtUnit(dtunit.c_str());
7201   return ret.retn();
7202 }
7203
7204 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const char *fileName) throw(INTERP_KERNEL::Exception)
7205 {
7206   if(!c)
7207     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
7208   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
7209     {
7210       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
7211       ret->setFileName(fileName);
7212       ret->_content=c;  c->incrRef();
7213       return ret.retn();
7214     }
7215   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
7216     {
7217       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
7218       ret->setFileName(fileName);
7219       ret->_content=c;  c->incrRef();
7220       return ret.retn();
7221     }
7222   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
7223 }
7224
7225 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
7226 try:MEDFileFieldGlobsReal(fileName)
7227 {
7228   MEDFileUtilities::CheckFileForRead(fileName);
7229   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7230   _content=BuildContentFrom(fid,fileName,fieldName);
7231   loadGlobals(fid);
7232 }
7233 catch(INTERP_KERNEL::Exception& e)
7234   {
7235     throw e;
7236   }
7237
7238 //= MEDFileIntFieldMultiTSWithoutSDA
7239
7240 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)
7241 {
7242   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit);
7243 }
7244
7245 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
7246 {
7247 }
7248
7249 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const char *fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7250 {
7251 }
7252
7253 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)
7254 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit)
7255 {
7256 }
7257 catch(INTERP_KERNEL::Exception& e)
7258 { throw e; }
7259
7260 /*!
7261  * \param [in] fieldId field id in C mode
7262  */
7263 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId) throw(INTERP_KERNEL::Exception)
7264 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId)
7265 {
7266 }
7267 catch(INTERP_KERNEL::Exception& e)
7268   { throw e; }
7269
7270 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const throw(INTERP_KERNEL::Exception)
7271 {
7272   return new MEDFileIntField1TSWithoutSDA;
7273 }
7274
7275 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const throw(INTERP_KERNEL::Exception)
7276 {
7277   if(!f1ts)
7278     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7279   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
7280   if(!f1tsC)
7281     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
7282 }
7283
7284 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
7285 {
7286   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
7287 }
7288
7289 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
7290 {
7291   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
7292 }
7293
7294 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const throw(INTERP_KERNEL::Exception)
7295 {
7296   return new MEDFileIntFieldMultiTSWithoutSDA;
7297 }
7298
7299 //= MEDFileAnyTypeFieldMultiTS
7300
7301 /*!
7302  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
7303  * that has been read from a specified MED file.
7304  *  \param [in] fileName - the name of the MED file to read.
7305  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7306  *          is to delete this field using decrRef() as it is no more needed.
7307  *  \throw If reading the file fails.
7308  */
7309 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
7310 {
7311   MEDFileUtilities::CheckFileForRead(fileName);
7312   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7313   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName);
7314   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7315   ret->loadGlobals(fid);
7316   return ret.retn();
7317 }
7318
7319 /*!
7320  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
7321  * that has been read from a specified MED file.
7322  *  \param [in] fileName - the name of the MED file to read.
7323  *  \param [in] fieldName - the name of the field to read.
7324  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7325  *          is to delete this field using decrRef() as it is no more needed.
7326  *  \throw If reading the file fails.
7327  *  \throw If there is no field named \a fieldName in the file.
7328  */
7329 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
7330 {
7331   MEDFileUtilities::CheckFileForRead(fileName);
7332   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7333   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName);
7334   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7335   ret->loadGlobals(fid);
7336   return ret.retn();
7337 }
7338
7339 /*!
7340  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7341  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7342  *
7343  * \warning this is a shallow copy constructor
7344  */
7345 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7346 {
7347   if(!shallowCopyOfContent)
7348     {
7349       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
7350       otherPtr->incrRef();
7351       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
7352     }
7353   else
7354     {
7355       _content=other.shallowCpy();
7356     }
7357 }
7358
7359 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() throw(INTERP_KERNEL::Exception)
7360 {
7361   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7362   if(!ret)
7363     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
7364   return ret;
7365 }
7366
7367 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const throw(INTERP_KERNEL::Exception)
7368 {
7369   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7370   if(!ret)
7371     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
7372   return ret;
7373 }
7374
7375 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
7376 {
7377   return contentNotNullBase()->getPflsReallyUsed2();
7378 }
7379
7380 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
7381 {
7382   return contentNotNullBase()->getLocsReallyUsed2();
7383 }
7384
7385 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
7386 {
7387   return contentNotNullBase()->getPflsReallyUsedMulti2();
7388 }
7389
7390 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
7391 {
7392   return contentNotNullBase()->getLocsReallyUsedMulti2();
7393 }
7394
7395 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7396 {
7397   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
7398 }
7399
7400 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7401 {
7402   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
7403 }
7404
7405 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
7406 {
7407   return contentNotNullBase()->getNumberOfTS();
7408 }
7409
7410 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
7411 {
7412   contentNotNullBase()->eraseEmptyTS();
7413 }
7414
7415 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
7416 {
7417   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
7418 }
7419
7420 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
7421 {
7422   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
7423 }
7424
7425 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
7426 {
7427   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
7428   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7429   ret->_content=c;
7430   return ret.retn();
7431 }
7432
7433 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
7434 {
7435   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
7436   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7437   ret->_content=c;
7438   return ret.retn();
7439 }
7440
7441 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
7442 {
7443   return contentNotNullBase()->getIterations();
7444 }
7445
7446 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts) throw(INTERP_KERNEL::Exception)
7447 {
7448   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
7449     pushBackTimeStep(*it);
7450 }
7451
7452 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts) throw(INTERP_KERNEL::Exception)
7453 {
7454   if(!f1ts)
7455     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
7456   checkCoherencyOfType(f1ts);
7457   f1ts->incrRef();
7458   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
7459   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
7460   c->incrRef();
7461   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
7462   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
7463     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
7464   _content->pushBackTimeStep(cSafe);
7465   appendGlobs(*f1ts,1e-12);
7466 }
7467
7468 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope() throw(INTERP_KERNEL::Exception)
7469 {
7470   contentNotNullBase()->synchronizeNameScope();
7471 }
7472
7473 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
7474 {
7475   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
7476 }
7477
7478 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
7479 {
7480   return contentNotNullBase()->getPosGivenTime(time,eps);
7481 }
7482
7483 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
7484 {
7485   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
7486 }
7487
7488 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
7489 {
7490   return contentNotNullBase()->getTypesOfFieldAvailable();
7491 }
7492
7493 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)
7494 {
7495   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
7496 }
7497
7498 std::string MEDFileAnyTypeFieldMultiTS::getName() const
7499 {
7500   return contentNotNullBase()->getName();
7501 }
7502
7503 void MEDFileAnyTypeFieldMultiTS::setName(const char *name)
7504 {
7505   contentNotNullBase()->setName(name);
7506 }
7507
7508 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const throw(INTERP_KERNEL::Exception)
7509 {
7510   return contentNotNullBase()->getDtUnit();
7511 }
7512
7513 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
7514 {
7515   contentNotNullBase()->setDtUnit(dtUnit);
7516 }
7517
7518 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7519 {
7520   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
7521 }
7522
7523 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
7524 {
7525   return contentNotNullBase()->getTimeSteps(ret1);
7526 }
7527
7528 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const throw(INTERP_KERNEL::Exception)
7529 {
7530   return contentNotNullBase()->getMeshName();
7531 }
7532
7533 void MEDFileAnyTypeFieldMultiTS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
7534 {
7535   contentNotNullBase()->setMeshName(newMeshName);
7536 }
7537
7538 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
7539 {
7540   return contentNotNullBase()->changeMeshNames(modifTab);
7541 }
7542
7543 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const throw(INTERP_KERNEL::Exception)
7544 {
7545   return contentNotNullBase()->getInfo();
7546 }
7547
7548 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
7549 {
7550   return contentNotNullBase()->setInfo(info);
7551 }
7552
7553 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const throw(INTERP_KERNEL::Exception)
7554 {
7555   const std::vector<std::string> ret=getInfo();
7556   return (int)ret.size();
7557 }
7558
7559 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
7560 {
7561   writeGlobals(fid,*this);
7562   contentNotNullBase()->writeLL(fid,*this);
7563 }
7564
7565 /*!
7566  * Writes \a this field into a MED file specified by its name.
7567  *  \param [in] fileName - the MED file name.
7568  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
7569  * - 2 - erase; an existing file is removed.
7570  * - 1 - append; same data should not be present in an existing file.
7571  * - 0 - overwrite; same data present in an existing file is overwritten.
7572  *  \throw If the field name is not set.
7573  *  \throw If no field data is set.
7574  *  \throw If \a mode == 1 and the same data is present in an existing file.
7575  */
7576 void MEDFileAnyTypeFieldMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
7577 {
7578   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
7579   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
7580   writeLL(fid);
7581 }
7582
7583 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
7584 {
7585   std::ostringstream oss;
7586   contentNotNullBase()->simpleRepr(0,oss,-1);
7587   simpleReprGlobs(oss);
7588   return oss.str();
7589 }
7590
7591 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySize() const
7592 {
7593   std::size_t ret=0;
7594   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)_content)
7595     ret+=_content->getHeapMemorySize();
7596   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
7597 }
7598
7599 /*!
7600  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
7601  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
7602  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
7603  */
7604 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const throw(INTERP_KERNEL::Exception)
7605 {
7606   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
7607   if(!content)
7608     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
7609   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
7610   std::size_t sz(contentsSplit.size());
7611   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
7612   for(std::size_t i=0;i<sz;i++)
7613     {
7614       ret[i]=shallowCpy();
7615       ret[i]->_content=contentsSplit[i];
7616     }
7617   return ret;
7618 }
7619
7620 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception)
7621 {
7622   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7623   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
7624     ret->_content=_content->deepCpy();
7625   ret->deepCpyGlobs(*this);
7626   return ret.retn();
7627 }
7628
7629 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
7630 {
7631   return _content;
7632 }
7633
7634 /*!
7635  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
7636  *  \param [in] iteration - the iteration number of a required time step.
7637  *  \param [in] order - the iteration order number of required time step.
7638  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
7639  *          delete this field using decrRef() as it is no more needed.
7640  *  \throw If there is no required time step in \a this field.
7641  */
7642 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
7643 {
7644   int pos=getPosOfTimeStep(iteration,order);
7645   return getTimeStepAtPos(pos);
7646 }
7647
7648 /*!
7649  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
7650  *  \param [in] time - the time of the time step of interest.
7651  *  \param [in] eps - a precision used to compare time values.
7652  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
7653  *          delete this field using decrRef() as it is no more needed.
7654  *  \throw If there is no required time step in \a this field.
7655  */
7656 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
7657 {
7658   int pos=getPosGivenTime(time,eps);
7659   return getTimeStepAtPos(pos);
7660 }
7661
7662 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator() throw(INTERP_KERNEL::Exception)
7663 {
7664   return new MEDFileAnyTypeFieldMultiTSIterator(this);
7665 }
7666
7667 //= MEDFileFieldMultiTS
7668
7669 /*!
7670  * Returns a new empty instance of MEDFileFieldMultiTS.
7671  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
7672  *          is to delete this field using decrRef() as it is no more needed.
7673  */
7674 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
7675 {
7676   return new MEDFileFieldMultiTS;
7677 }
7678
7679 /*!
7680  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
7681  * that has been read from a specified MED file.
7682  *  \param [in] fileName - the name of the MED file to read.
7683  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
7684  *          is to delete this field using decrRef() as it is no more needed.
7685  *  \throw If reading the file fails.
7686  */
7687 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
7688 {
7689   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName);
7690   ret->contentNotNull();//to check that content type matches with \a this type.
7691   return ret.retn();
7692 }
7693
7694 /*!
7695  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
7696  * that has been read from a specified MED file.
7697  *  \param [in] fileName - the name of the MED file to read.
7698  *  \param [in] fieldName - the name of the field to read.
7699  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
7700  *          is to delete this field using decrRef() as it is no more needed.
7701  *  \throw If reading the file fails.
7702  *  \throw If there is no field named \a fieldName in the file.
7703  */
7704 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
7705 {
7706   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName);
7707   ret->contentNotNull();//to check that content type matches with \a this type.
7708   return ret.retn();
7709 }
7710
7711 /*!
7712  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7713  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7714  *
7715  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
7716  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
7717  * \warning this is a shallow copy constructor
7718  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
7719  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
7720  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
7721  *          is to delete this field using decrRef() as it is no more needed.
7722  */
7723 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7724 {
7725   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
7726 }
7727
7728 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const throw(INTERP_KERNEL::Exception)
7729 {
7730   return new MEDFileFieldMultiTS(*this);
7731 }
7732
7733 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception)
7734 {
7735   if(!f1ts)
7736     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7737   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
7738   if(!f1tsC)
7739     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7740 }
7741
7742 /*!
7743  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
7744  *  \param [in] pos - a time step id.
7745  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
7746  *          delete this field using decrRef() as it is no more needed.
7747  *  \throw If \a pos is not a valid time step id.
7748  */
7749 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
7750 {
7751   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
7752   if(!item)
7753     {
7754       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
7755       throw INTERP_KERNEL::Exception(oss.str().c_str());
7756     }
7757   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
7758   if(itemC)
7759     {
7760       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
7761       ret->shallowCpyGlobs(*this);
7762       return ret.retn();
7763     }
7764   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
7765   throw INTERP_KERNEL::Exception(oss.str().c_str());
7766 }
7767
7768 /*!
7769  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
7770  * mesh entities of a given dimension of the first mesh in MED file.
7771  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7772  *  \param [in] type - a spatial discretization of interest.
7773  *  \param [in] iteration - the iteration number of a required time step.
7774  *  \param [in] order - the iteration order number of required time step.
7775  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7776  *  \param [in] renumPol - specifies how to permute values of the result field according to
7777  *          the optional numbers of cells and nodes, if any. The valid values are
7778  *          - 0 - do not permute.
7779  *          - 1 - permute cells.
7780  *          - 2 - permute nodes.
7781  *          - 3 - permute cells and nodes.
7782  *
7783  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7784  *          caller is to delete this field using decrRef() as it is no more needed. 
7785  *  \throw If the MED file is not readable.
7786  *  \throw If there is no mesh in the MED file.
7787  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7788  *  \throw If no field values of the required parameters are available.
7789  */
7790 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
7791 {
7792   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
7793   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7794   if(!myF1TSC)
7795     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
7796   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
7797   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut,*contentNotNullBase());
7798   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7799   return ret.retn();
7800 }
7801
7802 /*!
7803  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
7804  * the top level cells of the first mesh in MED file.
7805  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7806  *  \param [in] type - a spatial discretization of interest.
7807  *  \param [in] iteration - the iteration number of a required time step.
7808  *  \param [in] order - the iteration order number of required time step.
7809  *  \param [in] renumPol - specifies how to permute values of the result field according to
7810  *          the optional numbers of cells and nodes, if any. The valid values are
7811  *          - 0 - do not permute.
7812  *          - 1 - permute cells.
7813  *          - 2 - permute nodes.
7814  *          - 3 - permute cells and nodes.
7815  *
7816  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7817  *          caller is to delete this field using decrRef() as it is no more needed. 
7818  *  \throw If the MED file is not readable.
7819  *  \throw If there is no mesh in the MED file.
7820  *  \throw If no field values of the required parameters are available.
7821  */
7822 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const throw(INTERP_KERNEL::Exception)
7823 {
7824   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
7825   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7826   if(!myF1TSC)
7827     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
7828   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
7829   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,0,renumPol,this,arrOut,*contentNotNullBase());
7830   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7831   return ret.retn();
7832 }
7833
7834 /*!
7835  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
7836  * a given support.
7837  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7838  *  \param [in] type - a spatial discretization of interest.
7839  *  \param [in] iteration - the iteration number of a required time step.
7840  *  \param [in] order - the iteration order number of required time step.
7841  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7842  *  \param [in] mesh - the supporting mesh.
7843  *  \param [in] renumPol - specifies how to permute values of the result field according to
7844  *          the optional numbers of cells and nodes, if any. The valid values are
7845  *          - 0 - do not permute.
7846  *          - 1 - permute cells.
7847  *          - 2 - permute nodes.
7848  *          - 3 - permute cells and nodes.
7849  *
7850  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7851  *          caller is to delete this field using decrRef() as it is no more needed. 
7852  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7853  *  \throw If no field of \a this is lying on \a mesh.
7854  *  \throw If no field values of the required parameters are available.
7855  */
7856 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
7857 {
7858   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
7859   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7860   if(!myF1TSC)
7861     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
7862   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
7863   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
7864   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7865   return ret.retn();
7866 }
7867
7868 /*!
7869  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
7870  * given support. 
7871  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7872  *  \param [in] type - a spatial discretization of the new field.
7873  *  \param [in] iteration - the iteration number of a required time step.
7874  *  \param [in] order - the iteration order number of required time step.
7875  *  \param [in] mesh - the supporting mesh.
7876  *  \param [in] renumPol - specifies how to permute values of the result field according to
7877  *          the optional numbers of cells and nodes, if any. The valid values are
7878  *          - 0 - do not permute.
7879  *          - 1 - permute cells.
7880  *          - 2 - permute nodes.
7881  *          - 3 - permute cells and nodes.
7882  *
7883  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7884  *          caller is to delete this field using decrRef() as it is no more needed. 
7885  *  \throw If no field of \a this is lying on \a mesh.
7886  *  \throw If no field values of the required parameters are available.
7887  */
7888 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
7889 {
7890   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
7891   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7892   if(!myF1TSC)
7893     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
7894   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
7895   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
7896   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7897   return ret.retn();
7898 }
7899
7900 /*!
7901  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
7902  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
7903  * This method is useful for MED2 file format when field on different mesh was autorized.
7904  */
7905 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
7906 {
7907   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
7908   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7909   if(!myF1TSC)
7910     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
7911   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
7912   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
7913   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7914   return ret.retn();
7915 }
7916
7917 /*!
7918  * Returns values and a profile of the field of a given type, of a given time step,
7919  * lying on a given support.
7920  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7921  *  \param [in] type - a spatial discretization of the field.
7922  *  \param [in] iteration - the iteration number of a required time step.
7923  *  \param [in] order - the iteration order number of required time step.
7924  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7925  *  \param [in] mesh - the supporting mesh.
7926  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7927  *          field of interest lies on. If the field lies on all entities of the given
7928  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7929  *          using decrRef() as it is no more needed.  
7930  *  \param [in] glob - the global data storing profiles and localization.
7931  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
7932  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7933  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7934  *  \throw If no field of \a this is lying on \a mesh.
7935  *  \throw If no field values of the required parameters are available.
7936  */
7937 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
7938 {
7939   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
7940   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7941   if(!myF1TSC)
7942     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
7943   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
7944   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
7945 }
7946
7947 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const throw(INTERP_KERNEL::Exception)
7948 {
7949   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
7950   if(!pt)
7951     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
7952   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
7953   if(!ret)
7954     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 !");
7955   return ret;
7956 }
7957
7958  MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() throw(INTERP_KERNEL::Exception)
7959 {
7960   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
7961   if(!pt)
7962     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
7963   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
7964   if(!ret)
7965     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 !");
7966   return ret;
7967 }
7968
7969 /*!
7970  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
7971  * the given field is checked if its elements are sorted suitable for writing to MED file
7972  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
7973  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7974  *  \param [in] field - the field to add to \a this.
7975  *  \throw If the name of \a field is empty.
7976  *  \throw If the data array of \a field is not set.
7977  *  \throw If existing time steps have different name or number of components than \a field.
7978  *  \throw If the underlying mesh of \a field has no name.
7979  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
7980  */
7981 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
7982 {
7983   const DataArrayDouble *arr=0;
7984   if(field)
7985     arr=field->getArray();
7986   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
7987 }
7988
7989 /*!
7990  * Adds a MEDCouplingFieldDouble to \a this as another time step. Specified entities of
7991  * a given dimension of a given mesh are used as the support of the given field.
7992  * Elements of the given mesh must be sorted suitable for writing to MED file. 
7993  * Order of underlying mesh entities of the given field specified by \a profile parameter
7994  * is not prescribed; this method permutes field values to have them sorted by element
7995  * type as required for writing to MED file.  
7996  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7997  *  \param [in] field - the field to add to \a this.
7998  *  \param [in] mesh - the supporting mesh of \a field.
7999  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
8000  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8001  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8002  *  \throw If existing time steps have different name or number of components than \a field.
8003  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8004  *  \throw If the data array of \a field is not set.
8005  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8006  */
8007 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
8008 {
8009   const DataArrayDouble *arr=0;
8010   if(field)
8011     arr=field->getArray();
8012   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
8013 }
8014
8015 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
8016 {
8017   _content=new MEDFileFieldMultiTSWithoutSDA;
8018 }
8019
8020 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
8021 try:MEDFileAnyTypeFieldMultiTS(fileName)
8022 {
8023 }
8024 catch(INTERP_KERNEL::Exception& e)
8025   { throw e; }
8026
8027 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
8028 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName)
8029 {
8030 }
8031 catch(INTERP_KERNEL::Exception& e)
8032   { throw e; }
8033
8034 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8035 {
8036 }
8037
8038 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)
8039 {
8040   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
8041 }
8042
8043 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
8044 {
8045   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8046 }
8047
8048 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)
8049 {
8050   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
8051 }
8052
8053 //= MEDFileAnyTypeFieldMultiTSIterator
8054
8055 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
8056 {
8057   if(fmts)
8058     {
8059       fmts->incrRef();
8060       _nb_iter=fmts->getNumberOfTS();
8061     }
8062 }
8063
8064 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
8065 {
8066 }
8067
8068 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt() throw(INTERP_KERNEL::Exception)
8069 {
8070   if(_iter_id<_nb_iter)
8071     {
8072       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
8073       if(fmts)
8074         return fmts->getTimeStepAtPos(_iter_id++);
8075       else
8076         return 0;
8077     }
8078   else
8079     return 0;
8080 }
8081
8082 //= MEDFileIntFieldMultiTS
8083
8084 /*!
8085  * Returns a new empty instance of MEDFileFieldMultiTS.
8086  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8087  *          is to delete this field using decrRef() as it is no more needed.
8088  */
8089 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
8090 {
8091   return new MEDFileIntFieldMultiTS;
8092 }
8093
8094 /*!
8095  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
8096  * that has been read from a specified MED file.
8097  *  \param [in] fileName - the name of the MED file to read.
8098  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8099  *          is to delete this field using decrRef() as it is no more needed.
8100  *  \throw If reading the file fails.
8101  */
8102 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
8103 {
8104   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName);
8105   ret->contentNotNull();//to check that content type matches with \a this type.
8106   return ret.retn();
8107 }
8108
8109 /*!
8110  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
8111  * that has been read from a specified MED file.
8112  *  \param [in] fileName - the name of the MED file to read.
8113  *  \param [in] fieldName - the name of the field to read.
8114  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8115  *          is to delete this field using decrRef() as it is no more needed.
8116  *  \throw If reading the file fails.
8117  *  \throw If there is no field named \a fieldName in the file.
8118  */
8119 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
8120 {
8121   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName);
8122   ret->contentNotNull();//to check that content type matches with \a this type.
8123   return ret.retn();
8124 }
8125
8126 /*!
8127  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8128  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8129  *
8130  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
8131  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8132  * \warning this is a shallow copy constructor
8133  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
8134  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8135  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8136  *          is to delete this field using decrRef() as it is no more needed.
8137  */
8138 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8139 {
8140   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
8141 }
8142
8143 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const throw(INTERP_KERNEL::Exception)
8144 {
8145   return new MEDFileIntFieldMultiTS(*this);
8146 }
8147
8148 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception)
8149 {
8150   if(!f1ts)
8151     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8152   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
8153   if(!f1tsC)
8154     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8155 }
8156
8157 /*!
8158  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8159  * mesh entities of a given dimension of the first mesh in MED file.
8160  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8161  *  \param [in] type - a spatial discretization of interest.
8162  *  \param [in] iteration - the iteration number of a required time step.
8163  *  \param [in] order - the iteration order number of required time step.
8164  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8165  *  \param [out] arrOut - the DataArrayInt containing values of field.
8166  *  \param [in] renumPol - specifies how to permute values of the result field according to
8167  *          the optional numbers of cells and nodes, if any. The valid values are
8168  *          - 0 - do not permute.
8169  *          - 1 - permute cells.
8170  *          - 2 - permute nodes.
8171  *          - 3 - permute cells and nodes.
8172  *
8173  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8174  *          caller is to delete this field using decrRef() as it is no more needed. 
8175  *  \throw If the MED file is not readable.
8176  *  \throw If there is no mesh in the MED file.
8177  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8178  *  \throw If no field values of the required parameters are available.
8179  */
8180 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8181 {
8182   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8183   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8184   if(!myF1TSC)
8185     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
8186   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8187   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arr,*contentNotNullBase());
8188   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8189   return ret.retn();
8190 }
8191
8192 /*!
8193  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8194  * the top level cells of the first mesh in MED file.
8195  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8196  *  \param [in] type - a spatial discretization of interest.
8197  *  \param [in] iteration - the iteration number of a required time step.
8198  *  \param [in] order - the iteration order number of required time step.
8199  *  \param [out] arrOut - the DataArrayInt containing values of field.
8200  *  \param [in] renumPol - specifies how to permute values of the result field according to
8201  *          the optional numbers of cells and nodes, if any. The valid values are
8202  *          - 0 - do not permute.
8203  *          - 1 - permute cells.
8204  *          - 2 - permute nodes.
8205  *          - 3 - permute cells and nodes.
8206  *
8207  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8208  *          caller is to delete this field using decrRef() as it is no more needed. 
8209  *  \throw If the MED file is not readable.
8210  *  \throw If there is no mesh in the MED file.
8211  *  \throw If no field values of the required parameters are available.
8212  */
8213 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8214 {
8215   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8216   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8217   if(!myF1TSC)
8218     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
8219   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8220   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,0,renumPol,this,arr,*contentNotNullBase());
8221   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8222   return ret.retn();
8223 }
8224
8225 /*!
8226  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8227  * a given support.
8228  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8229  *  \param [in] type - a spatial discretization of interest.
8230  *  \param [in] iteration - the iteration number of a required time step.
8231  *  \param [in] order - the iteration order number of required time step.
8232  *  \param [out] arrOut - the DataArrayInt containing values of field.
8233  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8234  *  \param [in] mesh - the supporting mesh.
8235  *  \param [in] renumPol - specifies how to permute values of the result field according to
8236  *          the optional numbers of cells and nodes, if any. The valid values are
8237  *          - 0 - do not permute.
8238  *          - 1 - permute cells.
8239  *          - 2 - permute nodes.
8240  *          - 3 - permute cells and nodes.
8241  *
8242  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8243  *          caller is to delete this field using decrRef() as it is no more needed. 
8244  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8245  *  \throw If no field of \a this is lying on \a mesh.
8246  *  \throw If no field values of the required parameters are available.
8247  */
8248 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8249 {
8250   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8251   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8252   if(!myF1TSC)
8253     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8254   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8255   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
8256   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8257   return ret.retn();
8258 }
8259
8260 /*!
8261  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8262  * given support. 
8263  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8264  *  \param [in] type - a spatial discretization of the new field.
8265  *  \param [in] iteration - the iteration number of a required time step.
8266  *  \param [in] order - the iteration order number of required time step.
8267  *  \param [in] mesh - the supporting mesh.
8268  *  \param [out] arrOut - the DataArrayInt containing values of field.
8269  *  \param [in] renumPol - specifies how to permute values of the result field according to
8270  *          the optional numbers of cells and nodes, if any. The valid values are
8271  *          - 0 - do not permute.
8272  *          - 1 - permute cells.
8273  *          - 2 - permute nodes.
8274  *          - 3 - permute cells and nodes.
8275  *
8276  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8277  *          caller is to delete this field using decrRef() as it is no more needed. 
8278  *  \throw If no field of \a this is lying on \a mesh.
8279  *  \throw If no field values of the required parameters are available.
8280  */
8281 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8282 {
8283   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8284   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8285   if(!myF1TSC)
8286     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8287   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8288   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
8289   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8290   return ret.retn();
8291 }
8292
8293 /*!
8294  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
8295  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8296  * This method is useful for MED2 file format when field on different mesh was autorized.
8297  */
8298 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const char *mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8299 {
8300   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8301   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8302   if(!myF1TSC)
8303     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
8304   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8305   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
8306   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8307   return ret.retn();
8308 }
8309
8310 /*!
8311  * Returns values and a profile of the field of a given type, of a given time step,
8312  * lying on a given support.
8313  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8314  *  \param [in] type - a spatial discretization of the field.
8315  *  \param [in] iteration - the iteration number of a required time step.
8316  *  \param [in] order - the iteration order number of required time step.
8317  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8318  *  \param [in] mesh - the supporting mesh.
8319  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8320  *          field of interest lies on. If the field lies on all entities of the given
8321  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8322  *          using decrRef() as it is no more needed.  
8323  *  \param [in] glob - the global data storing profiles and localization.
8324  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
8325  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8326  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8327  *  \throw If no field of \a this is lying on \a mesh.
8328  *  \throw If no field values of the required parameters are available.
8329  */
8330 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
8331 {
8332   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8333   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8334   if(!myF1TSC)
8335     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
8336   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8337   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
8338 }
8339
8340 /*!
8341  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
8342  *  \param [in] pos - a time step id.
8343  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
8344  *          delete this field using decrRef() as it is no more needed.
8345  *  \throw If \a pos is not a valid time step id.
8346  */
8347 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
8348 {
8349   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8350   if(!item)
8351     {
8352       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8353       throw INTERP_KERNEL::Exception(oss.str().c_str());
8354     }
8355   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
8356   if(itemC)
8357     {
8358       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
8359       ret->shallowCpyGlobs(*this);
8360       return ret.retn();
8361     }
8362   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
8363   throw INTERP_KERNEL::Exception(oss.str().c_str());
8364 }
8365
8366 /*!
8367  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8368  * the given field is checked if its elements are sorted suitable for writing to MED file
8369  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8370  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8371  *  \param [in] field - the field to add to \a this.
8372  *  \throw If the name of \a field is empty.
8373  *  \throw If the data array of \a field is not set.
8374  *  \throw If existing time steps have different name or number of components than \a field.
8375  *  \throw If the underlying mesh of \a field has no name.
8376  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8377  */
8378 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception)
8379 {
8380   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
8381 }
8382
8383 /*!
8384  * Adds a MEDCouplingFieldDouble to \a this as another time step. Specified entities of
8385  * a given dimension of a given mesh are used as the support of the given field.
8386  * Elements of the given mesh must be sorted suitable for writing to MED file. 
8387  * Order of underlying mesh entities of the given field specified by \a profile parameter
8388  * is not prescribed; this method permutes field values to have them sorted by element
8389  * type as required for writing to MED file.  
8390  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8391  *  \param [in] field - the field to add to \a this.
8392  *  \param [in] mesh - the supporting mesh of \a field.
8393  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
8394  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8395  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8396  *  \throw If existing time steps have different name or number of components than \a field.
8397  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8398  *  \throw If the data array of \a field is not set.
8399  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8400  */
8401 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
8402 {
8403   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
8404 }
8405
8406 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const throw(INTERP_KERNEL::Exception)
8407 {
8408   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8409   if(!pt)
8410     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
8411   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
8412   if(!ret)
8413     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 !");
8414   return ret;
8415 }
8416
8417  MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() throw(INTERP_KERNEL::Exception)
8418 {
8419   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8420   if(!pt)
8421     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
8422   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
8423   if(!ret)
8424     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 !");
8425   return ret;
8426 }
8427
8428 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
8429 {
8430   _content=new MEDFileIntFieldMultiTSWithoutSDA;
8431 }
8432
8433 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8434 {
8435 }
8436
8437 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
8438 try:MEDFileAnyTypeFieldMultiTS(fileName)
8439 {
8440 }
8441 catch(INTERP_KERNEL::Exception& e)
8442   { throw e; }
8443
8444 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
8445 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName)
8446 {
8447 }
8448 catch(INTERP_KERNEL::Exception& e)
8449   { throw e; }
8450
8451 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
8452 {
8453   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8454 }
8455
8456 //= MEDFileFields
8457
8458 MEDFileFields *MEDFileFields::New()
8459 {
8460   return new MEDFileFields;
8461 }
8462
8463 MEDFileFields *MEDFileFields::New(const char *fileName) throw(INTERP_KERNEL::Exception)
8464 {
8465   return new MEDFileFields(fileName);
8466 }
8467
8468 std::size_t MEDFileFields::getHeapMemorySize() const
8469 {
8470   std::size_t ret=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
8471   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8472     if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it)
8473       ret+=(*it)->getHeapMemorySize();
8474   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
8475 }
8476
8477 MEDFileFields *MEDFileFields::deepCpy() const throw(INTERP_KERNEL::Exception)
8478 {
8479   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
8480   std::size_t i=0;
8481   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8482     {
8483       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
8484         ret->_fields[i]=(*it)->deepCpy();
8485     }
8486   ret->deepCpyGlobs(*this);
8487   return ret.retn();
8488 }
8489
8490 MEDFileFields *MEDFileFields::shallowCpy() const throw(INTERP_KERNEL::Exception)
8491 {
8492   return new MEDFileFields(*this);
8493 }
8494
8495 /*!
8496  * 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
8497  * 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.
8498  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
8499  *
8500  * \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.
8501  * \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.
8502  * 
8503  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
8504  */
8505 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const throw(INTERP_KERNEL::Exception)
8506 {
8507   std::set< std::pair<int,int> > s;
8508   bool firstShot=true;
8509   areThereSomeForgottenTS=false;
8510   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8511     {
8512       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
8513         continue;
8514       std::vector< std::pair<int,int> > v=(*it)->getIterations();
8515       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
8516       if(firstShot)
8517         { s=s1; firstShot=false; }
8518       else
8519         {
8520           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
8521           if(s!=s2)
8522             areThereSomeForgottenTS=true;
8523           s=s2;
8524         }
8525     }
8526   std::vector< std::pair<int,int> > ret;
8527   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
8528   return ret;
8529 }
8530
8531 int MEDFileFields::getNumberOfFields() const
8532 {
8533   return _fields.size();
8534 }
8535
8536 std::vector<std::string> MEDFileFields::getFieldsNames() const throw(INTERP_KERNEL::Exception)
8537 {
8538   std::vector<std::string> ret(_fields.size());
8539   int i=0;
8540   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8541     {
8542       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
8543       if(f)
8544         {
8545           ret[i]=f->getName();
8546         }
8547       else
8548         {
8549           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
8550           throw INTERP_KERNEL::Exception(oss.str().c_str());
8551         }
8552     }
8553   return ret;
8554 }
8555
8556 std::vector<std::string> MEDFileFields::getMeshesNames() const throw(INTERP_KERNEL::Exception)
8557 {
8558   std::vector<std::string> ret;
8559   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8560     {
8561       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
8562       if(cur)
8563         ret.push_back(cur->getMeshName());
8564     }
8565   return ret;
8566 }
8567
8568 std::string MEDFileFields::simpleRepr() const
8569 {
8570   std::ostringstream oss;
8571   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
8572   simpleRepr(0,oss);
8573   return oss.str();
8574 }
8575
8576 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
8577 {
8578   int nbOfFields=getNumberOfFields();
8579   std::string startLine(bkOffset,' ');
8580   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
8581   int i=0;
8582   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8583     {
8584       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
8585       if(cur)
8586         {
8587           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
8588         }
8589       else
8590         {
8591           oss << startLine << "  - not defined !" << std::endl;
8592         }
8593     }
8594   i=0;
8595   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8596     {
8597       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
8598       std::string chapter(17,'0'+i);
8599       oss << startLine << chapter << std::endl;
8600       if(cur)
8601         {
8602           cur->simpleRepr(bkOffset+2,oss,i);
8603         }
8604       else
8605         {
8606           oss << startLine << "  - not defined !" << std::endl;
8607         }
8608       oss << startLine << chapter << std::endl;
8609     }
8610   simpleReprGlobs(oss);
8611 }
8612
8613 MEDFileFields::MEDFileFields()
8614 {
8615 }
8616
8617 MEDFileFields::MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception)
8618 try:MEDFileFieldGlobsReal(fileName)
8619   {
8620     MEDFileUtilities::CheckFileForRead(fileName);
8621     MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
8622     int nbFields=MEDnField(fid);
8623     _fields.resize(nbFields);
8624     med_field_type typcha;
8625     for(int i=0;i<nbFields;i++)
8626       {
8627         std::vector<std::string> infos;
8628         std::string fieldName,dtunit;
8629         int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit);
8630         switch(typcha)
8631           {
8632           case MED_FLOAT64:
8633             {
8634               _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit);
8635               break;
8636             }
8637           case MED_INT32:
8638             {
8639               _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit);
8640               break;
8641             }
8642           default:
8643             {
8644               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] !";
8645               throw INTERP_KERNEL::Exception(oss.str().c_str());
8646             }
8647           }
8648       }
8649     loadAllGlobals(fid);
8650   }
8651 catch(INTERP_KERNEL::Exception& e)
8652   {
8653     throw e;
8654   }
8655
8656 void MEDFileFields::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
8657 {
8658   int i=0;
8659   writeGlobals(fid,*this);
8660   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
8661     {
8662       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
8663       if(!elt)
8664         {
8665           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
8666           throw INTERP_KERNEL::Exception(oss.str().c_str());
8667         }
8668       elt->writeLL(fid,*this);
8669     }
8670 }
8671
8672 void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
8673 {
8674   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8675   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
8676   writeLL(fid);
8677 }
8678
8679 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
8680 {
8681   std::vector<std::string> ret;
8682   std::set<std::string> ret2;
8683   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8684     {
8685       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
8686       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8687         if(ret2.find(*it2)==ret2.end())
8688           {
8689             ret.push_back(*it2);
8690             ret2.insert(*it2);
8691           }
8692     }
8693   return ret;
8694 }
8695
8696 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
8697 {
8698   std::vector<std::string> ret;
8699   std::set<std::string> ret2;
8700   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8701     {
8702       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8703       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8704         if(ret2.find(*it2)==ret2.end())
8705           {
8706             ret.push_back(*it2);
8707             ret2.insert(*it2);
8708           }
8709     }
8710   return ret;
8711 }
8712
8713 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
8714 {
8715   std::vector<std::string> ret;
8716   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8717     {
8718       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
8719       ret.insert(ret.end(),tmp.begin(),tmp.end());
8720     }
8721   return ret;
8722 }
8723
8724 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
8725 {
8726   std::vector<std::string> ret;
8727   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8728     {
8729       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8730       ret.insert(ret.end(),tmp.begin(),tmp.end());
8731     }
8732   return ret;
8733 }
8734
8735 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
8736 {
8737   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
8738     (*it)->changePflsRefsNamesGen2(mapOfModif);
8739 }
8740
8741 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
8742 {
8743   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
8744     (*it)->changeLocsRefsNamesGen2(mapOfModif);
8745 }
8746
8747 void MEDFileFields::resize(int newSize) throw(INTERP_KERNEL::Exception)
8748 {
8749   _fields.resize(newSize);
8750 }
8751
8752 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields) throw(INTERP_KERNEL::Exception)
8753 {
8754   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
8755     pushField(*it);
8756 }
8757
8758 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
8759 {
8760   if(!field)
8761     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
8762   _fields.push_back(field->getContent());
8763   appendGlobs(*field,1e-12);
8764 }
8765
8766 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
8767 {
8768   if(!field)
8769     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
8770   if(i>=(int)_fields.size())
8771     _fields.resize(i+1);
8772   _fields[i]=field->getContent();
8773   appendGlobs(*field,1e-12);
8774 }
8775
8776 void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception)
8777 {
8778   destroyFieldsAtPos(&i,&i+1);
8779 }
8780
8781 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
8782 {
8783   std::vector<bool> b(_fields.size(),true);
8784   for(const int *i=startIds;i!=endIds;i++)
8785     {
8786       if(*i<0 || *i>=(int)_fields.size())
8787         {
8788           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
8789           throw INTERP_KERNEL::Exception(oss.str().c_str());
8790         }
8791       b[*i]=false;
8792     }
8793   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
8794   std::size_t j=0;
8795   for(std::size_t i=0;i<_fields.size();i++)
8796     if(b[i])
8797       fields[j++]=_fields[i];
8798   _fields=fields;
8799 }
8800
8801 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
8802 {
8803   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
8804   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
8805   std::vector<bool> b(_fields.size(),true);
8806   int k=bg;
8807   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
8808     {
8809       if(k<0 || k>=(int)_fields.size())
8810         {
8811           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
8812           throw INTERP_KERNEL::Exception(oss.str().c_str());
8813         }
8814       b[k]=false;
8815     }
8816   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
8817   std::size_t j=0;
8818   for(std::size_t i=0;i<_fields.size();i++)
8819     if(b[i])
8820       fields[j++]=_fields[i];
8821   _fields=fields;
8822 }
8823
8824 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
8825 {
8826   bool ret=false;
8827   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
8828     {
8829       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
8830       if(cur)
8831         ret=cur->changeMeshNames(modifTab) || ret;
8832     }
8833   return ret;
8834 }
8835
8836 /*!
8837  * \param [in] meshName the name of the mesh that will be renumbered.
8838  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
8839  *             This code corresponds to the distribution of types in the corresponding mesh.
8840  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
8841  * \param [in] renumO2N the old to new renumber array.
8842  * \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 
8843  *         field in \a this.
8844  */
8845 bool MEDFileFields::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N) throw(INTERP_KERNEL::Exception)
8846 {
8847   bool ret=false;
8848   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
8849     {
8850       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
8851       if(fmts)
8852         {
8853           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
8854         }
8855     }
8856   return ret;
8857 }
8858
8859 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception)
8860 {
8861   if(i<0 || i>=(int)_fields.size())
8862     {
8863       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
8864       throw INTERP_KERNEL::Exception(oss.str().c_str());
8865     }
8866   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
8867   if(!fmts)
8868     return 0;
8869   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
8870   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
8871   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
8872   if(fmtsC)
8873     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
8874   else if(fmtsC2)
8875     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
8876   else
8877     {
8878       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
8879       throw INTERP_KERNEL::Exception(oss.str().c_str());
8880     }
8881   ret->shallowCpyGlobs(*this);
8882   return ret.retn();
8883 }
8884
8885 /*!
8886  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
8887  * This method is accessible in python using __getitem__ with a list in input.
8888  * \return a new object that the caller should deal with.
8889  */
8890 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
8891 {
8892   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
8893   std::size_t sz=std::distance(startIds,endIds);
8894   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
8895   int j=0;
8896   for(const int *i=startIds;i!=endIds;i++,j++)
8897     {
8898       if(*i<0 || *i>=(int)_fields.size())
8899         {
8900           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
8901           throw INTERP_KERNEL::Exception(oss.str().c_str());
8902         }
8903       fields[j]=_fields[*i];
8904     }
8905   ret->_fields=fields;
8906   return ret.retn();
8907 }
8908
8909 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
8910 {
8911   return getFieldAtPos(getPosFromFieldName(fieldName));
8912 }
8913
8914 /*!
8915  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
8916  * This method can be seen as a filter applied on \a this, that returns an object containing
8917  * 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
8918  * shallow copied from \a this.
8919  * 
8920  * \param [in] meshName - the name of the mesh on w
8921  * \return a new object that the caller should deal with.
8922  */
8923 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const char *meshName) const throw(INTERP_KERNEL::Exception)
8924 {
8925   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
8926   ret->shallowCpyOnlyUsedGlobs(*this);
8927   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8928     {
8929       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
8930       if(!cur)
8931         continue;
8932       if(cur->getMeshName()==meshName)
8933         {
8934           cur->incrRef();
8935           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
8936           ret->_fields.push_back(cur2);
8937         }
8938     }
8939   return ret.retn();
8940 }
8941
8942 /*!
8943  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
8944  * Input time steps are specified using a pair of integer (iteration, order).
8945  * 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,
8946  * but for each multitimestep only the time steps in \a timeSteps are kept.
8947  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
8948  * 
8949  * The returned object points to shallow copy of elements in \a this.
8950  * 
8951  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
8952  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
8953  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
8954  */
8955 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
8956 {
8957   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
8958   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8959     {
8960       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
8961       if(!cur)
8962         continue;
8963       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
8964       ret->_fields.push_back(elt);
8965     }
8966   ret->shallowCpyOnlyUsedGlobs(*this);
8967   return ret.retn();
8968 }
8969
8970 /*!
8971  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
8972  */
8973 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
8974 {
8975   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
8976   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
8977     {
8978       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
8979       if(!cur)
8980         continue;
8981       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
8982       if(elt->getNumberOfTS()!=0)
8983         ret->_fields.push_back(elt);
8984     }
8985   ret->shallowCpyOnlyUsedGlobs(*this);
8986   return ret.retn();
8987 }
8988
8989 MEDFileFieldsIterator *MEDFileFields::iterator() throw(INTERP_KERNEL::Exception)
8990 {
8991   return new MEDFileFieldsIterator(this);
8992 }
8993
8994 int MEDFileFields::getPosFromFieldName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
8995 {
8996   std::string tmp(fieldName);
8997   std::vector<std::string> poss;
8998   for(std::size_t i=0;i<_fields.size();i++)
8999     {
9000       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
9001       if(f)
9002         {
9003           std::string fname(f->getName());
9004           if(tmp==fname)
9005             return i;
9006           else
9007             poss.push_back(fname);
9008         }
9009     }
9010   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
9011   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
9012   oss << " !";
9013   throw INTERP_KERNEL::Exception(oss.str().c_str());
9014 }
9015
9016 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
9017 {
9018   if(fs)
9019     {
9020       fs->incrRef();
9021       _nb_iter=fs->getNumberOfFields();
9022     }
9023 }
9024
9025 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
9026 {
9027 }
9028
9029 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
9030 {
9031   if(_iter_id<_nb_iter)
9032     {
9033       MEDFileFields *fs(_fs);
9034       if(fs)
9035         return fs->getFieldAtPos(_iter_id++);
9036       else
9037         return 0;
9038     }
9039   else
9040     return 0;
9041 }