Salome HOME
On the road of last imps for MEDReader
[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 #include "MEDFileFieldOverView.hxx"
26
27 #include "MEDCouplingFieldDouble.hxx"
28 #include "MEDCouplingFieldDiscretization.hxx"
29
30 #include "InterpKernelAutoPtr.hxx"
31 #include "CellModel.hxx"
32
33 #include <algorithm>
34 #include <iterator>
35
36 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
37 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
38 extern med_geometry_type typmainoeud[1];
39 extern med_geometry_type typmai3[32];
40
41 using namespace ParaMEDMEM;
42
43 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
44 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
45
46 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const char *locName)
47 {
48   return new MEDFileFieldLoc(fid,locName);
49 }
50
51 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
52 {
53   return new MEDFileFieldLoc(fid,id);
54 }
55
56 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)
57 {
58   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
59 }
60
61 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const char *locName):_name(locName)
62 {
63   med_geometry_type geotype;
64   med_geometry_type sectiongeotype;
65   int nsectionmeshcell;
66   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
67   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
68   MEDlocalizationInfoByName(fid,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
69   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+32,geotype)));
70   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
71   _nb_node_per_cell=cm.getNumberOfNodes();
72   _ref_coo.resize(_dim*_nb_node_per_cell);
73   _gs_coo.resize(_dim*_nb_gauss_pt);
74   _w.resize(_nb_gauss_pt);
75   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
76 }
77
78 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
79 {
80   med_geometry_type geotype;
81   med_geometry_type sectiongeotype;
82   int nsectionmeshcell;
83   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
84   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
85   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
86   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
87   _name=locName;
88   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+32,geotype)));
89   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
90   _nb_node_per_cell=cm.getNumberOfNodes();
91   _ref_coo.resize(_dim*_nb_node_per_cell);
92   _gs_coo.resize(_dim*_nb_gauss_pt);
93   _w.resize(_nb_gauss_pt);
94   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
95 }
96
97 MEDFileFieldLoc::MEDFileFieldLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType,
98                                  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),
99                                                                                                                                     _w(w)
100 {
101   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
102   _dim=cm.getDimension();
103   _nb_node_per_cell=cm.getNumberOfNodes();
104   _nb_gauss_pt=_w.size();
105 }
106
107 MEDFileFieldLoc *MEDFileFieldLoc::deepCpy() const
108 {
109   return new MEDFileFieldLoc(*this);
110 }
111
112 std::size_t MEDFileFieldLoc::getHeapMemorySize() const
113 {
114   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
115 }
116
117 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
118 {
119   static const char OFF7[]="\n    ";
120   oss << "\"" << _name << "\"" << OFF7;
121   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
122   oss << "Dimension=" << _dim << OFF7;
123   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
124   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
125   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
126   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
127   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
128 }
129
130 void MEDFileFieldLoc::setName(const char *name)
131 {
132   _name=name;
133 }
134
135 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
136 {
137   if(_name!=other._name)
138     return false;
139   if(_dim!=other._dim)
140     return false;
141   if(_nb_gauss_pt!=other._nb_gauss_pt)
142     return false;
143   if(_nb_node_per_cell!=other._nb_node_per_cell)
144     return false;
145   if(_geo_type!=other._geo_type)
146     return false;
147   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
148     return false;
149   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
150     return false;
151   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
152     return false;
153   
154   return true;
155 }
156
157 void MEDFileFieldLoc::writeLL(med_idt fid) const
158 {
159   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);
160 }
161
162 std::string MEDFileFieldLoc::repr() const
163 {
164   std::ostringstream oss; oss.precision(15);
165   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
166   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
167   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
168   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
169   oss << "\n  - Ref coords are : ";
170   int sz=_ref_coo.size();
171   if(sz%_dim==0)
172     {
173       int nbOfTuples=sz/_dim;
174       for(int i=0;i<nbOfTuples;i++)
175         {
176           oss << "(";
177           for(int j=0;j<_dim;j++)
178             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
179           oss << ") ";
180         }
181     }
182   else
183     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
184   oss << "\n  - Gauss coords in reference element : ";
185   sz=_gs_coo.size();
186   if(sz%_dim==0)
187     {
188       int nbOfTuples=sz/_dim;
189       for(int i=0;i<nbOfTuples;i++)
190         {
191           oss << "(";
192           for(int j=0;j<_dim;j++)
193             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
194           oss << ") ";
195         }
196     }
197   else
198     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
199   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
200   return oss.str();
201 }
202
203 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
204 {
205   _type=field->getTypeOfField();
206   _start=start;
207   switch(_type)
208     {
209     case ON_CELLS:
210       {
211         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,offset,offset+nbOfCells,1);
212         _end=_start+nbOfCells;
213         _nval=nbOfCells;
214         break;
215       }
216     case ON_GAUSS_NE:
217       {
218         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
219         const int *arrPtr=arr->getConstPointer();
220         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
221         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
222         _nval=nbOfCells;
223         break;
224       }
225     case ON_GAUSS_PT:
226       {
227         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
228         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
229         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
230         if(!disc2)
231           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
232         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
233         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
234         const int *dai2Ptr=dai2->getConstPointer();
235         int nbi=gsLoc.getWeights().size();
236         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=dai->selectByTupleId2(offset,offset+nbOfCells,1);
237         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
238         const int *da3Ptr=da3->getConstPointer();
239         if(da3->getNumberOfTuples()!=nbOfCells)
240           {//profile : for gauss even in NoProfile !!!
241             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
242             _profile=oss.str();
243             da3->setName(_profile.c_str());
244             glob.appendProfile(da3);
245           }
246         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=DataArrayInt::New();
247         _nval=da3->getNbOfElems();
248         da4->alloc(_nval*nbi,1);
249         int *da4Ptr=da4->getPointer();
250         for(int i=0;i<_nval;i++)
251           {
252             int ref=dai2Ptr[offset+da3Ptr[i]];
253             for(int j=0;j<nbi;j++)
254               *da4Ptr++=ref+j;
255           }
256         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
257         _localization=oss2.str();
258         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
259         _end=_start+_nval*nbi;
260         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
261         break;
262       }
263     default:
264       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
265     }
266   start=_end;
267 }
268
269 /*!
270  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
271  * \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).
272  * \param [in] multiTypePfl is the end user profile specified in high level API
273  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
274  * \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.
275  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
276  * \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.
277  */
278 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)
279 {
280   _profile.clear();
281   _type=field->getTypeOfField();
282   std::string pflName(multiTypePfl->getName());
283   std::ostringstream oss; oss << pflName;
284   if(_type!=ON_NODES) { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); } else { oss << "_NODE"; }
285   if(locIds)
286     {
287       if(pflName.empty())
288         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
289       if(_type!=ON_GAUSS_PT)
290         {
291           locIds->setName(oss.str().c_str());
292           glob.appendProfile(locIds);
293           _profile=oss.str();
294         }
295     }
296   _start=start;
297   switch(_type)
298     {
299     case ON_NODES:
300       {
301          _nval=idsInPfl->getNumberOfTuples();
302          getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,arrr->getNumberOfTuples(),1);
303          _end=_start+_nval;
304          break;
305       }
306     case ON_CELLS:
307       {
308         _nval=idsInPfl->getNumberOfTuples();
309         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
310         _end=_start+_nval;
311         break;
312       }
313     case ON_GAUSS_NE:
314       {
315         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
316         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr->deltaShiftIndex();
317         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
318         arr3->computeOffsets2();
319         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
320         int trueNval=tmp->getNumberOfTuples();
321         _nval=idsInPfl->getNumberOfTuples();
322         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
323         _end=_start+trueNval;
324         break;
325       }
326     case ON_GAUSS_PT:
327       {
328         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
329         if(!disc2)
330           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
331         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
332         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
333         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
334         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
335         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
336         //
337         MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
338         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
339         //
340         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New();
341         int trueNval=0;
342         for(const int *pt=da4->begin();pt!=da4->end();pt++)
343           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
344         tmp->alloc(trueNval,1);
345         int *tmpPtr=tmp->getPointer();
346         for(const int *pt=da4->begin();pt!=da4->end();pt++)
347           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
348             *tmpPtr++=j;
349         //
350         _nval=da4->getNumberOfTuples();
351         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
352         _end=_start+trueNval;
353         oss << "_loc_" << _loc_id;
354         if(locIds)
355           {
356             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
357             da5->setName(oss.str().c_str());
358             glob.appendProfile(da5);
359             _profile=oss.str();
360           }
361         else
362           {
363             if(da3->getNumberOfTuples()!=nbOfEltsInWholeMesh || !da3->isIdentity())
364               {
365                 da3->setName(oss.str().c_str());
366                 glob.appendProfile(da3);
367                 _profile=oss.str();
368               }
369           }
370         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
371         _localization=oss2.str();
372         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
373         break;
374       }
375     default:
376       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
377     }
378   start=_end;
379 }
380
381 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
382 {
383   _start=start;
384   _nval=arrr->getNumberOfTuples();
385   getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,_nval,1);
386   _end=_start+_nval;
387   start=_end;
388 }
389
390 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt) throw(INTERP_KERNEL::Exception)
391 {
392   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt);
393 }
394
395 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
396 {
397   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
398 }
399
400 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
401 {
402   return new MEDFileFieldPerMeshPerTypePerDisc(other);
403 }
404
405 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySize() const
406 {
407   return _profile.capacity()+_localization.capacity()+5*sizeof(int);
408 }
409
410 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const throw(INTERP_KERNEL::Exception)
411 {
412   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
413   ret->_father=father;
414   return ret.retn();
415 }
416
417 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt) throw(INTERP_KERNEL::Exception)
418 try:_type(atype),_father(fath),_profile_it(profileIt)
419   {
420   }
421 catch(INTERP_KERNEL::Exception& e)
422 {
423   throw e;
424 }
425
426 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
427 {
428 }
429
430 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)
431 {
432 }
433
434 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
435                                                                        _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
436 {
437 }
438
439 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
440 {
441   return _father;
442 }
443
444 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
445 {
446   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
447   INTERP_KERNEL::AutoPtr<char> pflname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
448   std::string fieldName=nasc.getName();
449   std::string meshName=getMeshName();
450   int iteration=getIteration();
451   int order=getOrder();
452   TypeOfField type=getType();
453   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
454   int profilesize,nbi;
455   med_geometry_type mgeoti;
456   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
457   _nval=MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it,MED_COMPACT_PFLMODE,
458                                   pflname,&profilesize,locname,&nbi);
459   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
460   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
461   _start=start;
462   _end=start+_nval*nbi;
463   start=_end;
464   if(type==ON_CELLS && !_localization.empty())
465     {
466       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
467         setType(ON_GAUSS_PT);
468       else
469         {
470           setType(ON_GAUSS_NE);
471           _localization.clear();
472         }
473     }
474 }
475
476 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
477 {
478   std::string fieldName=nasc.getName();
479   std::string meshName=getMeshName();
480   int iteration=getIteration();
481   int order=getOrder();
482   TypeOfField type=getType();
483   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
484   med_geometry_type mgeoti;
485   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
486   if(_start>_end)
487     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
488   if(_start==_end)
489     return ;
490   DataArray *arr=getOrCreateAndGetArray();//arr is not null due to the spec of getOrCreateAndGetArray
491   if(_start<0 || _start>=arr->getNumberOfTuples())
492     {
493       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
494       throw INTERP_KERNEL::Exception(oss.str().c_str());
495     }
496   if(_end<0 || _end>arr->getNumberOfTuples())
497     {
498       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
499       throw INTERP_KERNEL::Exception(oss.str().c_str());
500     }
501   med_int tmp1,nbi;
502   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
503   med_int nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
504   int nbOfCompo=arr->getNumberOfComponents();
505   if(_end-_start!=nbValsInFile*nbi)
506     {
507       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
508       throw INTERP_KERNEL::Exception(oss.str().c_str());
509     }
510   DataArrayDouble *arrD=dynamic_cast<DataArrayDouble *>(arr);
511   if(arrD)
512     {
513       double *startFeeding=arrD->getPointer()+_start*nbOfCompo;
514       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
515                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
516       return ;
517     }
518   DataArrayInt *arrI=dynamic_cast<DataArrayInt *>(arr);
519   if(arrI)
520     {
521       int *startFeeding=arrI->getPointer()+_start*nbOfCompo;
522       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
523                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
524       return ;
525     }
526   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
527 }
528
529 /*!
530  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
531  */
532 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart) throw(INTERP_KERNEL::Exception)
533 {
534   int delta=_end-_start;
535   _start=newValueOfStart;
536   _end=_start+delta;
537 }
538
539 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
540 {
541   return _father->getIteration();
542 }
543
544 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
545 {
546   return _father->getOrder();
547 }
548
549 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
550 {
551   return _father->getTime();
552 }
553
554 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
555 {
556   return _father->getMeshName();
557 }
558
559 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
560 {
561   const char startLine[]="    ## ";
562   std::string startLine2(bkOffset,' ');
563   startLine2+=startLine;
564   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
565   oss << startLine2 << "Localization #" << id << "." << std::endl;
566   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
567   delete tmp;
568   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
569   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
570   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
571 }
572
573 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
574 {
575   return _type;
576 }
577
578 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
579 {
580   types.insert(_type);
581 }
582
583 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
584 {
585   _type=newType;
586 }
587
588 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
589 {
590   return _father->getGeoType();
591 }
592
593 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
594 {
595   return _father->getNumberOfComponents();
596 }
597
598 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
599 {
600   return _end-_start;
601 }
602
603 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
604 {
605   return _father->getOrCreateAndGetArray();
606 }
607
608 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
609 {
610   const MEDFileFieldPerMeshPerType *fath=_father;
611   return fath->getOrCreateAndGetArray();
612 }
613
614 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
615 {
616   return _father->getInfo();
617 }
618
619 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
620 {
621   return _profile;
622 }
623
624 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const char *newPflName)
625 {
626   _profile=newPflName;
627 }
628
629 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
630 {
631   return _localization;
632 }
633
634 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const char *newLocName)
635 {
636   _localization=newLocName;
637 }
638
639 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
640 {
641   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
642     {
643       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
644         {
645           _profile=(*it2).second;
646           return;
647         }
648     }
649 }
650
651 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
652 {
653   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
654     {
655       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
656         {
657           _localization=(*it2).second;
658           return;
659         }
660     }
661 }
662
663 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
664 {
665   if(type!=_type)
666     return ;
667   dads.push_back(std::pair<int,int>(_start,_end));
668   geoTypes.push_back(getGeoType());
669   if(_profile.empty())
670     pfls.push_back(0);
671   else
672     {
673       pfls.push_back(glob->getProfile(_profile.c_str()));
674     }
675   if(_localization.empty())
676     locs.push_back(-1);
677   else
678     {
679       locs.push_back(glob->getLocalizationId(_localization.c_str()));
680     }
681 }
682
683 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
684 {
685   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));
686   startEntryId++;
687 }
688
689 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
690 {
691   TypeOfField type=getType();
692   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
693   med_geometry_type mgeoti;
694   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
695   const DataArray *arr=getOrCreateAndGetArray();
696   if(!arr)
697     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
698   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
699   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
700   const unsigned char *locToWrite=0;
701   if(arrD)
702     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
703   else if(arrI)
704     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
705   else
706     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
707   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
708                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
709                              locToWrite);
710 }
711
712 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const throw(INTERP_KERNEL::Exception)
713 {
714   type=_type;
715   pfl=_profile;
716   loc=_localization;
717   dad.first=_start; dad.second=_end;
718 }
719
720 /*!
721  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
722  *             This code corresponds to the distribution of types in the corresponding mesh.
723  * \param [out] ptToFill memory zone where the output will be stored.
724  * \return the size of data pushed into output param \a ptToFill
725  */
726 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const throw(INTERP_KERNEL::Exception)
727 {
728   _loc_id=offset;
729   std::ostringstream oss;
730   std::size_t nbOfType=codeOfMesh.size()/3;
731   int found=-1;
732   for(std::size_t i=0;i<nbOfType && found==-1;i++)
733     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
734       found=(int)i;
735   if(found==-1)
736     {
737       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
738       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
739       throw INTERP_KERNEL::Exception(oss.str().c_str());
740     }
741   int *work=ptToFill;
742   if(_profile.empty())
743     {
744       if(_nval!=codeOfMesh[3*found+1])
745         {
746           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
747           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
748           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
749           throw INTERP_KERNEL::Exception(oss.str().c_str());
750         }
751       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
752         *work++=ii;
753     }
754   else
755     {
756       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
757       if(pfl->getNumberOfTuples()!=_nval)
758         {
759           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
760           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
761           oss << _nval;
762           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
763           throw INTERP_KERNEL::Exception(oss.str().c_str());
764         }
765       int offset2=codeOfMesh[3*found+2];
766       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
767         {
768           if(*pflId<codeOfMesh[3*found+1])
769             *work++=offset2+*pflId;
770         }
771     }
772   return _nval;
773 }
774
775 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const throw(INTERP_KERNEL::Exception)
776 {
777   for(int i=_start;i<_end;i++)
778     *ptToFill++=i;
779   return _end-_start;
780 }
781
782 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId) throw(INTERP_KERNEL::Exception)
783 {
784   switch(type)
785     {
786     case ON_CELLS:
787       return -2;
788     case ON_GAUSS_NE:
789       return -1;
790     case ON_GAUSS_PT:
791       return locId;
792     default:
793       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
794     }
795 }
796
797 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
798 {
799   int id=0;
800   std::map<std::pair<std::string,TypeOfField>,int> m;
801   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
802   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
803     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
804       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
805   ret.resize(id);
806   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
807     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
808   return ret;
809 }
810
811 /*!
812  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
813  * 
814  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
815  * \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.
816  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
817  * \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)
818  * \param [in,out] glob if necessary by the method, new profiles can be added to it
819  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
820  * \param [out] result All new entries will be appended on it.
821  * \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 !)
822  */
823 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
824                                                        const DataArrayInt *explicitIdsInMesh,
825                                                        const std::vector<int>& newCode,
826                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
827                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
828 {
829   if(entriesOnSameDisc.empty())
830     return false;
831   TypeOfField type=entriesOnSameDisc[0]->getType();
832   int szEntities=0,szTuples=0;
833   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
834     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
835   int nbi=szTuples/szEntities;
836   if(szTuples%szEntities!=0)
837     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
838   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
839   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
840   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
841   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
842   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
843   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
844   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
845   int id=0;
846   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
847     {
848       int startOfEltIdOfChunk=(*it)->_start;
849       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
850       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
851       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
852       //
853       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
854       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
855       //
856       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
857       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
858     }
859   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
860   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
861   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
862   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
863   //
864   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
865   //
866   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
867   arrPart->renumberInPlace(renumTupleIds->begin());
868   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
869   bool ret=false;
870   const int *idIt=diffVals->begin();
871   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
872   int offset2=0;
873   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
874     {
875       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
876       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
877       int nbEntityElts=subIds->getNumberOfTuples();
878       bool ret2;
879       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
880         NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
881                                     offset+offset2,
882                                     li,glob,ret2);
883       ret=ret || ret2;
884       result.push_back(eltToAdd);
885       offset2+=nbEntityElts*nbi;
886     }
887   ret=ret || li.empty();
888   return ret;
889 }
890
891 /*!
892  * \param [in] typeF type of field of new chunk
893  * \param [in] geoType the geometric type of the chunk
894  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
895  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
896  * \param [in] nbi number of integration points
897  * \param [in] offset The offset in the **global array of data**.
898  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
899  *                 to the new chunk to create.
900  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
901  * \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
902  *              and corresponding entry erased from \a entriesOnSameDisc.
903  * \return a newly allocated chunk
904  */
905 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
906                                                                                                   bool isPfl, int nbi, int offset,
907                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
908                                                                                                   MEDFileFieldGlobsReal& glob,
909                                                                                                   bool &notInExisting) throw(INTERP_KERNEL::Exception)
910 {
911   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
912   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
913   for(;it!=entriesOnSameDisc.end();it++)
914     {
915       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
916         {
917           if(!isPfl)
918             {
919               if((*it)->_profile.empty())
920                 break;
921               else
922                 if(!(*it)->_profile.empty())
923                   {
924                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
925                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
926                       break;
927                   }
928             }
929         }
930     }
931   if(it==entriesOnSameDisc.end())
932     {
933       notInExisting=true;
934       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
935       ret->_type=typeF;
936       ret->_loc_id=(int)geoType;
937       ret->_nval=nbMeshEntities;
938       ret->_start=offset;
939       ret->_end=ret->_start+ret->_nval*nbi;
940       if(isPfl)
941         {
942           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
943           glob.appendProfile(idsOfMeshElt);
944           ret->_profile=idsOfMeshElt->getName();
945         }
946       //tony treatment of localization
947       return ret;
948     }
949   else
950     {
951       notInExisting=false;
952       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
953       ret->_loc_id=(int)geoType;
954       ret->setNewStart(offset);
955       entriesOnSameDisc.erase(it);
956       return ret;
957     }
958   
959 }
960
961 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
962 {
963   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc);
964 }
965
966 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
967 {
968   return new MEDFileFieldPerMeshPerType(fath,geoType);
969 }
970
971 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySize() const
972 {
973   std::size_t ret=_field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
974   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
975     ret+=(*it)->getHeapMemorySize();
976   return ret;
977 }
978
979 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const throw(INTERP_KERNEL::Exception)
980 {
981   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
982   ret->_father=father;
983   std::size_t i=0;
984   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
985     {
986       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
987         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
988     }
989   return ret.retn();
990 }
991
992 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
993 {
994   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
995   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
996     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
997 }
998
999 /*!
1000  * This method is the most general one. No optimization is done here.
1001  * \param [in] multiTypePfl is the end user profile specified in high level API
1002  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1003  * \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.
1004  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1005  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1006  * \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.
1007  */
1008 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)
1009 {
1010   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1011   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1012     _field_pm_pt_pd[*it]->assignFieldProfile(start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1013 }
1014
1015 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1016 {
1017   _field_pm_pt_pd.resize(1);
1018   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1019   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1020 }
1021
1022 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1023 {
1024   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1025   if(!arr || !arr->isAllocated())
1026     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1027   _field_pm_pt_pd.resize(1);
1028   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1029   _field_pm_pt_pd[0]->assignFieldProfile(start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1030 }
1031
1032 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
1033 {
1034   TypeOfField type=field->getTypeOfField();
1035   if(type!=ON_GAUSS_PT)
1036     {
1037       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1038       int sz=_field_pm_pt_pd.size();
1039       bool found=false;
1040       for(int j=0;j<sz && !found;j++)
1041         {
1042           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1043             {
1044               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1045               found=true;
1046             }
1047         }
1048       if(!found)
1049         {
1050           _field_pm_pt_pd.resize(sz+1);
1051           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1052         }
1053       std::vector<int> ret(1,(int)sz);
1054       return ret;
1055     }
1056   else
1057     {
1058       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1059       int sz2=ret2.size();
1060       std::vector<int> ret3(sz2);
1061       int k=0;
1062       for(int i=0;i<sz2;i++)
1063         {
1064           int sz=_field_pm_pt_pd.size();
1065           int locIdToFind=ret2[i];
1066           bool found=false;
1067           for(int j=0;j<sz && !found;j++)
1068             {
1069               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1070                 {
1071                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1072                   ret3[k++]=j;
1073                   found=true;
1074                 }
1075             }
1076           if(!found)
1077             {
1078               _field_pm_pt_pd.resize(sz+1);
1079               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1080               ret3[k++]=sz;
1081             }
1082         }
1083       return ret3;
1084     }
1085 }
1086
1087 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
1088 {
1089   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1090   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1091   if(!disc2)
1092     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1093   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1094   if(!da)
1095     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1096   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1097   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1098   if(retTmp->presenceOfValue(-1))
1099     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1100   std::vector<int> ret(retTmp->begin(),retTmp->end());
1101   return ret;
1102 }
1103
1104 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1105 {
1106   TypeOfField type=field->getTypeOfField();
1107   if(type!=ON_GAUSS_PT)
1108     {
1109       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1110       int sz=_field_pm_pt_pd.size();
1111       bool found=false;
1112       for(int j=0;j<sz && !found;j++)
1113         {
1114           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1115             {
1116               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1117               found=true;
1118             }
1119         }
1120       if(!found)
1121         {
1122           _field_pm_pt_pd.resize(sz+1);
1123           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1124         }
1125       std::vector<int> ret(1,0);
1126       return ret;
1127     }
1128   else
1129     {
1130       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1131       int sz2=ret2.size();
1132       std::vector<int> ret3(sz2);
1133       int k=0;
1134       for(int i=0;i<sz2;i++)
1135         {
1136           int sz=_field_pm_pt_pd.size();
1137           int locIdToFind=ret2[i];
1138           bool found=false;
1139           for(int j=0;j<sz && !found;j++)
1140             {
1141               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1142                 {
1143                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1144                   ret3[k++]=j;
1145                   found=true;
1146                 }
1147             }
1148           if(!found)
1149             {
1150               _field_pm_pt_pd.resize(sz+1);
1151               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1152               ret3[k++]=sz;
1153             }
1154         }
1155       return ret3;
1156     }
1157 }
1158
1159 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1160 {
1161   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1162   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1163   if(!disc2)
1164     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1165   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1166   if(!da)
1167     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1168   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1169   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1170   if(retTmp->presenceOfValue(-1))
1171     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1172   std::vector<int> ret(retTmp->begin(),retTmp->end());
1173   return ret;
1174 }
1175
1176 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1177 {
1178   return _father;
1179 }
1180
1181 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1182 {
1183   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1184   int curDim=(int)cm.getDimension();
1185   dim=std::max(dim,curDim);
1186 }
1187
1188 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1189 {
1190   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1191     {
1192       (*it)->fillTypesOfFieldAvailable(types);
1193     }
1194 }
1195
1196 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)
1197 {
1198   int sz=_field_pm_pt_pd.size();
1199   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1200   for(int i=0;i<sz;i++)
1201     {
1202       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1203     }
1204 }
1205
1206 int MEDFileFieldPerMeshPerType::getIteration() const
1207 {
1208   return _father->getIteration();
1209 }
1210
1211 int MEDFileFieldPerMeshPerType::getOrder() const
1212 {
1213   return _father->getOrder();
1214 }
1215
1216 double MEDFileFieldPerMeshPerType::getTime() const
1217 {
1218   return _father->getTime();
1219 }
1220
1221 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1222 {
1223   return _father->getMeshName();
1224 }
1225
1226 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1227 {
1228   const char startLine[]="  ## ";
1229   std::string startLine2(bkOffset,' ');
1230   std::string startLine3(startLine2);
1231   startLine3+=startLine;
1232   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1233     {
1234       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1235       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1236     }
1237   else
1238     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1239   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1240   int i=0;
1241   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1242     {
1243       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1244       if(cur)
1245         cur->simpleRepr(bkOffset,oss,i);
1246       else
1247         {
1248           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1249         }
1250     }
1251 }
1252
1253 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1254 {
1255   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1256     {
1257       globalSz+=(*it)->getNumberOfTuples();
1258     }
1259   nbOfEntries+=(int)_field_pm_pt_pd.size();
1260 }
1261
1262 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1263 {
1264   return _geo_type;
1265 }
1266
1267
1268 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1269 {
1270   return _father->getNumberOfComponents();
1271 }
1272
1273 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1274 {
1275   return _father->getOrCreateAndGetArray();
1276 }
1277
1278 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1279 {
1280   const MEDFileFieldPerMesh *fath=_father;
1281   return fath->getOrCreateAndGetArray();
1282 }
1283
1284 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1285 {
1286   return _father->getInfo();
1287 }
1288
1289 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1290 {
1291   std::vector<std::string> ret;
1292   std::set<std::string> ret2;
1293   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1294     {
1295       std::string tmp=(*it1)->getProfile();
1296       if(!tmp.empty())
1297         if(ret2.find(tmp)==ret2.end())
1298           {
1299             ret.push_back(tmp);
1300             ret2.insert(tmp);
1301           }
1302     }
1303   return ret;
1304 }
1305
1306 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1307 {
1308   std::vector<std::string> ret;
1309   std::set<std::string> ret2;
1310   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1311     {
1312       std::string tmp=(*it1)->getLocalization();
1313       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1314         if(ret2.find(tmp)==ret2.end())
1315           {
1316             ret.push_back(tmp);
1317             ret2.insert(tmp);
1318           }
1319     }
1320   return ret;
1321 }
1322
1323 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1324 {
1325   std::vector<std::string> ret;
1326   std::set<std::string> ret2;
1327   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1328     {
1329       std::string tmp=(*it1)->getProfile();
1330       if(!tmp.empty())
1331         ret.push_back(tmp);
1332     }
1333   return ret;
1334 }
1335
1336 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1337 {
1338   std::vector<std::string> ret;
1339   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1340     {
1341       std::string tmp=(*it1)->getLocalization();
1342       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1343         ret.push_back(tmp);
1344     }
1345   return ret;
1346 }
1347
1348 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1349 {
1350   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1351     (*it1)->changePflsRefsNamesGen(mapOfModif);
1352 }
1353
1354 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1355 {
1356   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1357     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1358 }
1359
1360 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) throw(INTERP_KERNEL::Exception)
1361 {
1362   if(_field_pm_pt_pd.empty())
1363     {
1364       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1365       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1366       throw INTERP_KERNEL::Exception(oss.str().c_str());
1367     }
1368   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1369     return _field_pm_pt_pd[locId];
1370   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1371   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1372   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1373   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1374   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1375 }
1376
1377 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const throw(INTERP_KERNEL::Exception)
1378 {
1379   if(_field_pm_pt_pd.empty())
1380     {
1381       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1382       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1383       throw INTERP_KERNEL::Exception(oss.str().c_str());
1384     }
1385   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1386     return _field_pm_pt_pd[locId];
1387   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1388   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1389   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1390   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1391   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1392 }
1393
1394 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
1395 {
1396   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1397     {
1398       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1399       if(meshDim!=(int)cm.getDimension())
1400         return ;
1401     }
1402   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1403     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1404 }
1405
1406 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1407 {
1408   int i=0;
1409   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1410     {
1411       (*it)->fillValues(i,startEntryId,entries);
1412     }
1413 }
1414
1415 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1416 {
1417   _field_pm_pt_pd=leaves;
1418   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1419     (*it)->setFather(this);
1420 }
1421
1422 /*!
1423  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1424  *  \param [out] its - list of pair (start,stop) kept
1425  *  \return bool - false if the type of field \a tof is not contained in \a this.
1426  */
1427 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1428 {
1429   bool ret=false;
1430   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1431   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1432     if((*it)->getType()==tof)
1433       {
1434         newPmPtPd.push_back(*it);
1435         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1436         (*it)->setNewStart(globalNum);
1437         globalNum=(*it)->getEnd();
1438         its.push_back(bgEnd);
1439         ret=true;
1440       }
1441   if(ret)
1442     _field_pm_pt_pd=newPmPtPd;
1443   return ret;
1444 }
1445
1446 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType)
1447 {
1448 }
1449
1450 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)
1451 {
1452   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1453   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1454   med_geometry_type mgeoti;
1455   med_entity_type menti;
1456   menti=ConvertIntoMEDFileType(type,geoType,mgeoti);
1457   int nbProfiles=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName);
1458   _field_pm_pt_pd.resize(nbProfiles);
1459   for(int i=0;i<nbProfiles;i++)
1460     {
1461       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i+1);
1462     }
1463   if(type==ON_CELLS)
1464     {
1465       int nbProfiles2=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName);
1466       for(int i=0;i<nbProfiles2;i++)
1467         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i+1));
1468     }
1469 }
1470
1471 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1472 {
1473   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1474     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1475 }
1476
1477 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1478 {
1479   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1480     (*it)->loadBigArray(fid,nasc);
1481 }
1482
1483 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
1484 {
1485   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1486     {
1487       (*it)->copyOptionsFrom(*this);
1488       (*it)->writeLL(fid,nasc);
1489     }
1490 }
1491
1492 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1493 {
1494   switch(ikType)
1495     {
1496     case ON_CELLS:
1497       medfGeoType=typmai3[(int)ikGeoType];
1498       return MED_CELL;
1499     case ON_NODES:
1500       medfGeoType=MED_NONE;
1501       return MED_NODE;
1502     case ON_GAUSS_NE:
1503       medfGeoType=typmai3[(int)ikGeoType];
1504       return MED_NODE_ELEMENT;
1505     case ON_GAUSS_PT:
1506       medfGeoType=typmai3[(int)ikGeoType];
1507       return MED_CELL;
1508     default:
1509       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1510     }
1511   return MED_UNDEF_ENTITY_TYPE;
1512 }
1513
1514 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1515 {
1516   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc);
1517 }
1518
1519 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1520 {
1521   return new MEDFileFieldPerMesh(fath,mesh);
1522 }
1523
1524 std::size_t MEDFileFieldPerMesh::getHeapMemorySize() const
1525 {
1526   std::size_t ret=_mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1527   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1528     if((const MEDFileFieldPerMeshPerType *)*it)
1529       ret+=(*it)->getHeapMemorySize();
1530   return ret;
1531 }
1532
1533 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const throw(INTERP_KERNEL::Exception)
1534 {
1535   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1536   ret->_father=father;
1537   std::size_t i=0;
1538   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1539     {
1540       if((const MEDFileFieldPerMeshPerType *)*it)
1541         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1542     }
1543   return ret.retn();
1544 }
1545
1546 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1547 {
1548   std::string startLine(bkOffset,' ');
1549   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1550   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1551   int i=0;
1552   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1553     {
1554       const MEDFileFieldPerMeshPerType *cur=*it;
1555       if(cur)
1556         cur->simpleRepr(bkOffset,oss,i);
1557       else
1558         {
1559           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1560         }
1561     }
1562 }
1563
1564 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
1565 {
1566   _mesh_name=mesh->getName();
1567   mesh->getTime(_mesh_iteration,_mesh_order);
1568 }
1569
1570 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)
1571 {
1572   int nbOfTypes=code.size()/3;
1573   int offset=0;
1574   for(int i=0;i<nbOfTypes;i++)
1575     {
1576       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1577       int nbOfCells=code[3*i+1];
1578       int pos=addNewEntryIfNecessary(type);
1579       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1580       offset+=nbOfCells;
1581     }
1582 }
1583
1584 /*!
1585  * This method is the most general one. No optimization is done here.
1586  * \param [in] multiTypePfl is the end user profile specified in high level API
1587  * \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].
1588  * \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.
1589  * \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.
1590  * \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.
1591  * \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.
1592  */
1593 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)
1594 {
1595   int nbOfTypes=code.size()/3;
1596   for(int i=0;i<nbOfTypes;i++)
1597     {
1598       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1599       int pos=addNewEntryIfNecessary(type);
1600       DataArrayInt *pfl=0;
1601       if(code[3*i+2]!=-1)
1602         pfl=idsPerType[code[3*i+2]];
1603       int nbOfTupes2=code2.size()/3;
1604       int found=0;
1605       for(;found<nbOfTupes2;found++)
1606         if(code[3*i]==code2[3*found])
1607           break;
1608       if(found==nbOfTupes2)
1609         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1610       _field_pm_pt[pos]->assignFieldProfile(start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1611     }
1612 }
1613
1614 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1615 {
1616   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1617   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1618 }
1619
1620 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1621 {
1622   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1623   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1624 }
1625
1626 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1627 {
1628   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1629     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1630 }
1631
1632 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
1633 {
1634   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1635     (*it)->loadBigArraysRecursively(fid,nasc);
1636 }
1637
1638 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
1639 {
1640   int nbOfTypes=_field_pm_pt.size();
1641   for(int i=0;i<nbOfTypes;i++)
1642     {
1643       _field_pm_pt[i]->copyOptionsFrom(*this);
1644       _field_pm_pt[i]->writeLL(fid,nasc);
1645     }
1646 }
1647
1648 void MEDFileFieldPerMesh::getDimension(int& dim) const
1649 {
1650   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1651     (*it)->getDimension(dim);
1652 }
1653
1654 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1655 {
1656   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1657     (*it)->fillTypesOfFieldAvailable(types);
1658 }
1659
1660 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)
1661 {
1662   int sz=_field_pm_pt.size();
1663   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1664   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1665   for(int i=0;i<sz;i++)
1666     {
1667       types[i]=_field_pm_pt[i]->getGeoType();
1668       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1669     }
1670   return ret;
1671 }
1672
1673 double MEDFileFieldPerMesh::getTime() const
1674 {
1675   int tmp1,tmp2;
1676   return _father->getTime(tmp1,tmp2);
1677 }
1678
1679 int MEDFileFieldPerMesh::getIteration() const
1680 {
1681   return _father->getIteration();
1682 }
1683
1684 int MEDFileFieldPerMesh::getOrder() const
1685 {
1686   return _father->getOrder();
1687 }
1688
1689 int MEDFileFieldPerMesh::getNumberOfComponents() const
1690 {
1691   return _father->getNumberOfComponents();
1692 }
1693
1694 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1695 {
1696   if(!_father)
1697     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1698   return _father->getOrCreateAndGetArray();
1699 }
1700
1701 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1702 {
1703   if(!_father)
1704     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1705   return _father->getOrCreateAndGetArray();
1706 }
1707
1708 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1709 {
1710   return _father->getInfo();
1711 }
1712
1713 /*!
1714  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1715  * 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.
1716  * It returns 2 output vectors :
1717  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1718  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1719  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1720  */
1721 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)
1722 {
1723   int notNullPflsSz=0;
1724   int nbOfArrs=geoTypes.size();
1725   for(int i=0;i<nbOfArrs;i++)
1726     if(pfls[i])
1727       notNullPflsSz++;
1728   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1729   int nbOfDiffGeoTypes=geoTypes3.size();
1730   code.resize(3*nbOfDiffGeoTypes);
1731   notNullPfls.resize(notNullPflsSz);
1732   notNullPflsSz=0;
1733   int j=0;
1734   for(int i=0;i<nbOfDiffGeoTypes;i++)
1735     {
1736       int startZone=j;
1737       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1738       std::vector<const DataArrayInt *> notNullTmp;
1739       if(pfls[j])
1740         notNullTmp.push_back(pfls[j]);
1741       j++;
1742       for(;j<nbOfArrs;j++)
1743         if(geoTypes[j]==refType)
1744           {
1745             if(pfls[j])
1746               notNullTmp.push_back(pfls[j]);
1747           }
1748         else
1749           break;
1750       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1751       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1752       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1753       code[3*i]=(int)refType;
1754       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1755       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1756       if(notNullTmp.empty())
1757         code[3*i+2]=-1;
1758       else
1759         {
1760           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1761           code[3*i+2]=notNullPflsSz++;
1762         }
1763     }
1764 }
1765
1766 /*!
1767  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1768  */
1769 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)
1770 {
1771   int sz=dads.size();
1772   int ret=0;
1773   for(int i=0;i<sz;i++)
1774     {
1775       if(locs[i]==-1)
1776         {
1777           if(type!=ON_GAUSS_NE)
1778             ret+=dads[i].second-dads[i].first;
1779           else
1780             {
1781               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1782               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1783             }
1784         }
1785       else
1786         {
1787           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1788           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1789         }
1790     }
1791   return ret;
1792 }
1793
1794 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1795 {
1796   std::vector<std::string> ret;
1797   std::set<std::string> ret2;
1798   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1799     {
1800       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1801       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1802         if(ret2.find(*it2)==ret2.end())
1803           {
1804             ret.push_back(*it2);
1805             ret2.insert(*it2);
1806           }
1807     }
1808   return ret;
1809 }
1810
1811 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1812 {
1813   std::vector<std::string> ret;
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)->getPflsReallyUsedMulti();
1817       ret.insert(ret.end(),tmp.begin(),tmp.end());
1818     }
1819   return ret;
1820 }
1821
1822 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1823 {
1824   std::vector<std::string> ret;
1825   std::set<std::string> ret2;
1826   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1827     {
1828       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1829       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1830         if(ret2.find(*it2)==ret2.end())
1831           {
1832             ret.push_back(*it2);
1833             ret2.insert(*it2);
1834           }
1835     }
1836   return ret;
1837 }
1838
1839 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1840 {
1841   std::vector<std::string> ret;
1842   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1843     {
1844       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1845       ret.insert(ret.end(),tmp.begin(),tmp.end());
1846     }
1847   return ret;
1848 }
1849
1850 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
1851 {
1852   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1853     {
1854       if((*it).first==_mesh_name)
1855         {
1856           _mesh_name=(*it).second;
1857           return true;
1858         }
1859     }
1860   return false;
1861 }
1862
1863 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1864                                                       MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1865 {
1866   if(_mesh_name!=meshName)
1867     return false;
1868   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1869   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1870   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1871   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1872   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1873   getUndergroundDataArrayExt(entries);
1874   DataArray *arr0=getOrCreateAndGetArray();//tony
1875   if(!arr0)
1876     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
1877   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
1878   if(!arr0)
1879     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
1880   int sz=0;
1881   if(!arr)
1882     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1883   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1884     {
1885       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1886         {
1887           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1888           sz+=(*it).second.second-(*it).second.first;
1889         }
1890       else
1891         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1892     }
1893   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1894   ////////////////////
1895   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1896   int *workI2=explicitIdsOldInMesh->getPointer();
1897   int sz1=0,sz2=0,sid=1;
1898   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1899   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1900   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1901     {
1902       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1903       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1904       int *workI=explicitIdsOldInArr->getPointer();
1905       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1906         {
1907           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1908           (*itL2)->setLocId(sz2);
1909           (*itL2)->_tmp_work1=(*itL2)->getStart();
1910           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1911         }
1912       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1913     }
1914   explicitIdsOldInMesh->reAlloc(sz2);
1915   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1916   ////////////////////
1917   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1918   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1919   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1920   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1921     {
1922       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1923       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1924       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1925     }
1926   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1927   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1928   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
1929     {
1930       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1931       int newStart=elt->getLocId();
1932       elt->setLocId((*it)->getGeoType());
1933       elt->setNewStart(newStart);
1934       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
1935       entriesKeptNew.push_back(elt);
1936       entriesKeptNew2.push_back(elt);
1937     }
1938   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
1939   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
1940   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
1941   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
1942   bool ret=false;
1943   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
1944     {
1945       sid=0;
1946       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
1947         {
1948           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
1949           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
1950           }*/
1951       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
1952                                                             glob,arr2,otherEntriesNew) || ret;
1953     }
1954   if(!ret)
1955     return false;
1956   // Assign new dispatching
1957   assignNewLeaves(otherEntriesNew);
1958   arr->cpyFrom(*arr2);
1959   return true;
1960 }
1961
1962 /*!
1963  * \param [in,out] globalNum a global numbering counter for the renumbering.
1964  * \param [out] its - list of pair (start,stop) kept
1965  */
1966 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1967 {
1968   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
1969   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1970     {
1971       std::vector< std::pair<int,int> > its2;
1972       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
1973         {
1974           ret.push_back(*it);
1975           its.insert(its.end(),its2.begin(),its2.end());
1976         }
1977     }
1978   _field_pm_pt=ret;
1979 }
1980
1981 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1982 {
1983   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
1984   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
1985     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
1986   //
1987   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
1988   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
1989   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
1990   for(;it1!=types.end();it1++,it2++)
1991     {
1992       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
1993       elt->setLeaves((*it1).second);
1994       *it2=elt;
1995     }
1996   _field_pm_pt=fieldPmPt;
1997 }
1998
1999 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2000 {
2001   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2002     (*it)->changePflsRefsNamesGen(mapOfModif);
2003 }
2004
2005 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2006 {
2007   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2008     (*it)->changeLocsRefsNamesGen(mapOfModif);
2009 }
2010
2011 /*!
2012  * \param [in] mesh is the whole mesh
2013  */
2014 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2015 {
2016   if(_field_pm_pt.empty())
2017     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2018   //
2019   std::vector< std::pair<int,int> > dads;
2020   std::vector<const DataArrayInt *> pfls;
2021   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2022   std::vector<int> locs,code;
2023   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2024   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2025     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2026   // Sort by types
2027   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2028   if(code.empty())
2029     {
2030       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2031       throw INTERP_KERNEL::Exception(oss.str().c_str());
2032     }
2033   //
2034   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2035   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2036   if(type!=ON_NODES)
2037     {
2038       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2039       if(!arr)
2040         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2041       else
2042         {
2043           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2044           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2045         }
2046     }
2047   else
2048     {
2049       if(code.size()!=3)
2050         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2051       int nb=code[1];
2052       if(code[2]==-1)
2053         {
2054           if(nb!=mesh->getNumberOfNodes())
2055             {
2056               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2057               oss << " nodes in mesh !";
2058               throw INTERP_KERNEL::Exception(oss.str().c_str());
2059             }
2060           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2061         }
2062       else
2063         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2064     }
2065 }
2066
2067 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2068 {
2069   if(_field_pm_pt.empty())
2070     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2071   //
2072   std::vector<std::pair<int,int> > dads;
2073   std::vector<const DataArrayInt *> pfls;
2074   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2075   std::vector<int> locs,code;
2076   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2077   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2078     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2079   // Sort by types
2080   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2081   if(code.empty())
2082     {
2083       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2084       throw INTERP_KERNEL::Exception(oss.str().c_str());
2085     }
2086   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2087   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2088   if(type!=ON_NODES)
2089     {
2090       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2091       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2092     }
2093   else
2094     {
2095       if(code.size()!=3)
2096         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2097       int nb=code[1];
2098       if(code[2]==-1)
2099         {
2100           if(nb!=mesh->getNumberOfNodes())
2101             {
2102               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2103               oss << " nodes in mesh !";
2104               throw INTERP_KERNEL::Exception(oss.str().c_str());
2105             }
2106         }
2107       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2108     }
2109   //
2110   return 0;
2111 }
2112
2113 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
2114 {
2115   int globalSz=0;
2116   int nbOfEntries=0;
2117   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2118     {
2119       (*it)->getSizes(globalSz,nbOfEntries);
2120     }
2121   entries.resize(nbOfEntries);
2122   nbOfEntries=0;
2123   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2124     {
2125       (*it)->fillValues(nbOfEntries,entries);
2126     }
2127 }
2128
2129 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
2130 {
2131   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2132     {
2133       if((*it)->getGeoType()==typ)
2134         return (*it)->getLeafGivenLocId(locId);
2135     }
2136   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2137   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2138   oss << "Possiblities are : ";
2139   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2140     {
2141       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2142       oss << "\"" << cm2.getRepr() << "\", ";
2143     }
2144   throw INTERP_KERNEL::Exception(oss.str().c_str());
2145 }
2146
2147 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
2148 {
2149   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2150     {
2151       if((*it)->getGeoType()==typ)
2152         return (*it)->getLeafGivenLocId(locId);
2153     }
2154   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2155   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2156   oss << "Possiblities are : ";
2157   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2158     {
2159       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2160       oss << "\"" << cm2.getRepr() << "\", ";
2161     }
2162   throw INTERP_KERNEL::Exception(oss.str().c_str());
2163 }
2164
2165 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2166 {
2167   int i=0;
2168   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2169   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2170   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2171     {
2172       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2173       if(type==curType)
2174         return i;
2175       else
2176         {
2177           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2178           if(pos>pos2)
2179             it2=it+1;
2180         }
2181     }
2182   int ret=std::distance(_field_pm_pt.begin(),it2);
2183   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2184   return ret;
2185 }
2186
2187 /*!
2188  * 'dads' and 'locs' input parameters have the same number of elements
2189  * \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
2190  */
2191 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2192                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2193                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2194 {
2195   isPfl=false;
2196   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2197   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2198   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2199   const std::vector<std::string>& infos=getInfo();
2200   da->setInfoOnComponents(infos);
2201   da->setName("");
2202   if(type==ON_GAUSS_PT)
2203     {
2204       int offset=0;
2205       int nbOfArrs=dads.size();
2206       for(int i=0;i<nbOfArrs;i++)
2207         {
2208           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2209           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2210           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2211           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2212           di->alloc(nbOfElems,1);
2213           di->iota(offset);
2214           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2215           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2216           offset+=nbOfElems;
2217         }
2218     }
2219   arrOut=da;
2220   return ret.retn();
2221 }
2222
2223 /*!
2224  * 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.
2225  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2226  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2227  * The order of cells in the returned field is those imposed by the profile.
2228  * \param [in] mesh is the global mesh.
2229  */
2230 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2231                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2232                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2233                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2234 {
2235   if(da->isIdentity())
2236     {
2237       int nbOfTuples=da->getNumberOfTuples();
2238       if(nbOfTuples==mesh->getNumberOfCells())
2239         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2240     }
2241   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2242   m2->setName(mesh->getName());
2243   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2244   isPfl=true;
2245   return ret.retn();
2246 }
2247
2248 /*!
2249  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2250  */
2251 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2252                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2253                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2254 {
2255   if(da->isIdentity())
2256     {
2257       int nbOfTuples=da->getNumberOfTuples();
2258       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2259         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2260     }
2261   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2262   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2263   if(meshu)
2264     {
2265       if(meshu->getNodalConnectivity()==0)
2266         {
2267           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2268           int nb=da->getNbOfElems();
2269           const int *ptr=da->getConstPointer();
2270           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2271           meshuc->allocateCells(nb);
2272           for(int i=0;i<nb;i++)
2273             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2274           meshuc->finishInsertingCells();
2275           ret->setMesh(meshuc);
2276           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2277           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2278           disc->checkCoherencyBetween(meshuc,arrOut);
2279           return ret.retn();
2280         }
2281     }
2282   //
2283   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2284   isPfl=true;
2285   DataArrayInt *arr2=0;
2286   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2287   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2288   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2289   int nnodes=mesh2->getNumberOfNodes();
2290   if(nnodes==(int)da->getNbOfElems())
2291     {
2292       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2293       arrOut->renumberInPlace(da3->getConstPointer());
2294       mesh2->setName(mesh->getName());
2295       ret->setMesh(mesh2);
2296       return ret.retn();
2297     }
2298   else
2299     {
2300       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 !!!";
2301       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2302       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2303       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2304       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2305       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2306       throw INTERP_KERNEL::Exception(oss.str().c_str());
2307     }
2308   return 0;
2309 }
2310
2311 /*!
2312  * This method is the most light method of field retrieving.
2313  */
2314 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const throw(INTERP_KERNEL::Exception)
2315 {
2316   if(!pflIn)
2317     {
2318       pflOut=DataArrayInt::New();
2319       pflOut->alloc(nbOfElems,1);
2320       pflOut->iota(0);
2321     }
2322   else
2323     {
2324       pflOut=const_cast<DataArrayInt*>(pflIn);
2325       pflOut->incrRef();
2326     }
2327   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2328   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2329   const std::vector<std::string>& infos=getInfo();
2330   int nbOfComp=infos.size();
2331   for(int i=0;i<nbOfComp;i++)
2332     da->setInfoOnComponent(i,infos[i].c_str());
2333   safePfl->incrRef();
2334   return da.retn();
2335 }
2336
2337 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),
2338                                                                                                                                                                                                                  _mesh_csit(meshCsit),_father(fath)
2339 {
2340   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2341   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2342   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2343   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2344     {
2345       int nbProfile =MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[i],_mesh_csit,meshName,pflName,locName);
2346       int nbProfile2=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],_mesh_csit,meshName,pflName,locName);
2347       if(nbProfile>0 || nbProfile2>0)
2348         {
2349           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i],nasc));
2350           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2351         }
2352     }
2353   int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,_mesh_csit,meshName,pflName,locName);
2354   if(nbProfile>0)
2355     {
2356       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc));
2357       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2358     }
2359 }
2360
2361 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2362 {
2363   copyTinyInfoFrom(mesh);
2364 }
2365
2366 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
2367 {
2368   if(id>=(int)_pfls.size())
2369     _pfls.resize(id+1);
2370   _pfls[id]=DataArrayInt::New();
2371   int lgth=MEDprofileSizeByName(fid,pflName);
2372   _pfls[id]->setName(pflName);
2373   _pfls[id]->alloc(lgth,1);
2374   MEDprofileRd(fid,pflName,_pfls[id]->getPointer());
2375   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2376 }
2377
2378 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2379 {
2380   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2381   int sz;
2382   MEDprofileInfo(fid,i+1,pflName,&sz);
2383   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2384   if(i>=(int)_pfls.size())
2385     _pfls.resize(i+1);
2386   _pfls[i]=DataArrayInt::New();
2387   _pfls[i]->alloc(sz,1);
2388   _pfls[i]->setName(pflCpp.c_str());
2389   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2390   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2391 }
2392
2393 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
2394 {
2395   int nbOfPfls=_pfls.size();
2396   for(int i=0;i<nbOfPfls;i++)
2397     {
2398       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2399       cpy->applyLin(1,1,0);
2400       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2401       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2402       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2403     }
2404   //
2405   int nbOfLocs=_locs.size();
2406   for(int i=0;i<nbOfLocs;i++)
2407     _locs[i]->writeLL(fid);
2408 }
2409
2410 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps) throw(INTERP_KERNEL::Exception)
2411 {
2412   std::vector<std::string> pfls=getPfls();
2413   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2414     {
2415       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2416       if(it2==pfls.end())
2417         {
2418           _pfls.push_back(*it);
2419         }
2420       else
2421         {
2422           int id=std::distance(pfls.begin(),it2);
2423           if(!(*it)->isEqual(*_pfls[id]))
2424             {
2425               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2426               throw INTERP_KERNEL::Exception(oss.str().c_str());
2427             }
2428         }
2429     }
2430   std::vector<std::string> locs=getLocs();
2431   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2432     {
2433       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2434       if(it2==locs.end())
2435         {
2436           _locs.push_back(*it);
2437         }
2438       else
2439         {
2440           int id=std::distance(locs.begin(),it2);
2441           if(!(*it)->isEqual(*_locs[id],eps))
2442             {
2443               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2444               throw INTERP_KERNEL::Exception(oss.str().c_str());
2445             }
2446         }
2447     }
2448 }
2449
2450 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const throw(INTERP_KERNEL::Exception)
2451 {
2452   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2453     getProfile((*it).c_str());
2454 }
2455
2456 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const throw(INTERP_KERNEL::Exception)
2457 {
2458   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2459     getLocalization((*it).c_str());
2460 }
2461
2462 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real) throw(INTERP_KERNEL::Exception)
2463 {
2464   std::vector<std::string> profiles=real.getPflsReallyUsed();
2465   int sz=profiles.size();
2466   _pfls.resize(sz);
2467   for(int i=0;i<sz;i++)
2468     loadProfileInFile(fid,i,profiles[i].c_str());
2469   //
2470   std::vector<std::string> locs=real.getLocsReallyUsed();
2471   sz=locs.size();
2472   _locs.resize(sz);
2473   for(int i=0;i<sz;i++)
2474     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2475 }
2476
2477 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2478 {
2479   int nProfil=MEDnProfile(fid);
2480   for(int i=0;i<nProfil;i++)
2481     loadProfileInFile(fid,i);
2482   int sz=MEDnLocalization(fid);
2483   _locs.resize(sz);
2484   for(int i=0;i<sz;i++)
2485     {
2486       _locs[i]=MEDFileFieldLoc::New(fid,i);
2487     }
2488 }
2489
2490 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const char *fname)
2491 {
2492   return new MEDFileFieldGlobs(fname);
2493 }
2494
2495 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2496 {
2497   return new MEDFileFieldGlobs;
2498 }
2499
2500 std::size_t MEDFileFieldGlobs::getHeapMemorySize() const
2501 {
2502   std::size_t ret=_file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2503   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2504     ret+=(*it)->getHeapMemorySize();
2505   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2506     ret+=(*it)->getHeapMemorySize();
2507   return ret;
2508 }
2509
2510 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const throw(INTERP_KERNEL::Exception)
2511 {
2512   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2513   std::size_t i=0;
2514   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2515     {
2516       if((const DataArrayInt *)*it)
2517         ret->_pfls[i]=(*it)->deepCpy();
2518     }
2519   i=0;
2520   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2521     {
2522       if((const MEDFileFieldLoc*)*it)
2523         ret->_locs[i]=(*it)->deepCpy();
2524     }
2525   return ret.retn();
2526 }
2527
2528 /*!
2529  * \throw if a profile in \a pfls in not in \a this.
2530  * \throw if a localization in \a locs in not in \a this.
2531  * \sa MEDFileFieldGlobs::deepCpyPart
2532  */
2533 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const throw(INTERP_KERNEL::Exception)
2534 {
2535   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2536   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2537     {
2538       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2539       if(!pfl)
2540         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2541       pfl->incrRef();
2542       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2543       ret->_pfls.push_back(pfl2);
2544     }
2545   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2546     {
2547       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2548       if(!loc)
2549         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2550       loc->incrRef();
2551       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2552       ret->_locs.push_back(loc2);
2553     }
2554   ret->setFileName(getFileName());
2555   return ret.retn();
2556 }
2557
2558 /*!
2559  * \throw if a profile in \a pfls in not in \a this.
2560  * \throw if a localization in \a locs in not in \a this.
2561  * \sa MEDFileFieldGlobs::shallowCpyPart
2562  */
2563 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const throw(INTERP_KERNEL::Exception)
2564 {
2565   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2566   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2567     {
2568       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2569       if(!pfl)
2570         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2571       ret->_pfls.push_back(pfl->deepCpy());
2572     }
2573   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2574     {
2575       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2576       if(!loc)
2577         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2578       ret->_locs.push_back(loc->deepCpy());
2579     }
2580   ret->setFileName(getFileName());
2581   return ret.retn();
2582 }
2583
2584 MEDFileFieldGlobs::MEDFileFieldGlobs(const char *fname):_file_name(fname)
2585 {
2586 }
2587
2588 MEDFileFieldGlobs::MEDFileFieldGlobs()
2589 {
2590 }
2591
2592 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2593 {
2594 }
2595
2596 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2597 {
2598   oss << "Profiles :\n";
2599   std::size_t n=_pfls.size();
2600   for(std::size_t i=0;i<n;i++)
2601     {
2602       oss << "  - #" << i << " ";
2603       const DataArrayInt *pfl=_pfls[i];
2604       if(pfl)
2605         oss << "\"" << pfl->getName() << "\"\n";
2606       else
2607         oss << "EMPTY !\n";
2608     }
2609   n=_locs.size();
2610   oss << "Localizations :\n";
2611   for(std::size_t i=0;i<n;i++)
2612     {
2613       oss << "  - #" << i << " ";
2614       const MEDFileFieldLoc *loc=_locs[i];
2615       if(loc)
2616         loc->simpleRepr(oss);
2617       else
2618         oss<< "EMPTY !\n";
2619     }
2620 }
2621
2622 void MEDFileFieldGlobs::setFileName(const char *fileName)
2623 {
2624   _file_name=fileName;
2625 }
2626
2627 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2628 {
2629   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2630     {
2631       DataArrayInt *elt(*it);
2632       if(elt)
2633         {
2634           std::string name(elt->getName());
2635           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2636             {
2637               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2638                 {
2639                   elt->setName((*it2).second.c_str());
2640                   return;
2641                 }
2642             }
2643         }
2644     }
2645 }
2646
2647 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2648 {
2649   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2650     {
2651       MEDFileFieldLoc *elt(*it);
2652       if(elt)
2653         {
2654           std::string name(elt->getName());
2655           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2656             {
2657               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2658                 {
2659                   elt->setName((*it2).second.c_str());
2660                   return;
2661                 }
2662             }
2663         }
2664     }
2665 }
2666
2667 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
2668 {
2669   if(locId<0 || locId>=(int)_locs.size())
2670     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2671   return _locs[locId]->getNbOfGaussPtPerCell();
2672 }
2673
2674 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
2675 {
2676   return getLocalizationFromId(getLocalizationId(locName));
2677 }
2678
2679 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
2680 {
2681   if(locId<0 || locId>=(int)_locs.size())
2682     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2683   return *_locs[locId];
2684 }
2685
2686 namespace ParaMEDMEMImpl
2687 {
2688   class LocFinder
2689   {
2690   public:
2691     LocFinder(const char *loc):_loc(loc) { }
2692     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2693   private:
2694     const char *_loc;
2695   };
2696
2697   class PflFinder
2698   {
2699   public:
2700     PflFinder(const std::string& pfl):_pfl(pfl) { }
2701     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2702   private:
2703     const std::string& _pfl;
2704   };
2705 }
2706
2707 int MEDFileFieldGlobs::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
2708 {
2709   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2710   if(it==_locs.end())
2711     {
2712       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2713       for(it=_locs.begin();it!=_locs.end();it++)
2714         oss << "\"" << (*it)->getName() << "\", ";
2715       throw INTERP_KERNEL::Exception(oss.str().c_str());
2716     }
2717   return std::distance(_locs.begin(),it);
2718 }
2719
2720 /*!
2721  * The returned value is never null.
2722  */
2723 const DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
2724 {
2725   std::string pflNameCpp(pflName);
2726   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2727   if(it==_pfls.end())
2728     {
2729       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2730       for(it=_pfls.begin();it!=_pfls.end();it++)
2731         oss << "\"" << (*it)->getName() << "\", ";
2732       throw INTERP_KERNEL::Exception(oss.str().c_str());
2733     }
2734   return *it;
2735 }
2736
2737 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
2738 {
2739   if(pflId<0 || pflId>=(int)_pfls.size())
2740     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2741   return _pfls[pflId];
2742 }
2743
2744 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
2745 {
2746   if(locId<0 || locId>=(int)_locs.size())
2747     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2748   return *_locs[locId];
2749 }
2750
2751 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
2752 {
2753   return getLocalizationFromId(getLocalizationId(locName));
2754 }
2755
2756 /*!
2757  * The returned value is never null.
2758  */
2759 DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
2760 {
2761   std::string pflNameCpp(pflName);
2762   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2763   if(it==_pfls.end())
2764     {
2765       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2766       for(it=_pfls.begin();it!=_pfls.end();it++)
2767         oss << "\"" << (*it)->getName() << "\", ";
2768       throw INTERP_KERNEL::Exception(oss.str().c_str());
2769     }
2770   return *it;
2771 }
2772
2773 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
2774 {
2775   if(pflId<0 || pflId>=(int)_pfls.size())
2776     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2777   return _pfls[pflId];
2778 }
2779
2780 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
2781 {
2782   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2783   int i=0;
2784   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2785     {
2786       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2787         newPfls.push_back(*it);
2788     }
2789   _pfls=newPfls;
2790 }
2791
2792 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
2793 {
2794   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2795   int i=0;
2796   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2797     {
2798       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2799         newLocs.push_back(*it);
2800     }
2801   _locs=newLocs;
2802 }
2803
2804 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2805 {
2806   int sz=_pfls.size();
2807   std::vector<std::string> ret(sz);
2808   for(int i=0;i<sz;i++)
2809     ret[i]=_pfls[i]->getName();
2810   return ret;
2811 }
2812
2813 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2814 {
2815   int sz=_locs.size();
2816   std::vector<std::string> ret(sz);
2817   for(int i=0;i<sz;i++)
2818     ret[i]=_locs[i]->getName();
2819   return ret;
2820 }
2821
2822 bool MEDFileFieldGlobs::existsPfl(const char *pflName) const
2823 {
2824   std::vector<std::string> v=getPfls();
2825   std::string s(pflName);
2826   return std::find(v.begin(),v.end(),s)!=v.end();
2827 }
2828
2829 bool MEDFileFieldGlobs::existsLoc(const char *locName) const
2830 {
2831   std::vector<std::string> v=getLocs();
2832   std::string s(locName);
2833   return std::find(v.begin(),v.end(),s)!=v.end();
2834 }
2835
2836 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2837 {
2838   std::map<int,std::vector<int> > m;
2839   int i=0;
2840   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2841     {
2842       const DataArrayInt *tmp=(*it);
2843       if(tmp)
2844         {
2845           m[tmp->getHashCode()].push_back(i);
2846         }
2847     }
2848   std::vector< std::vector<int> > ret;
2849   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2850     {
2851       if((*it2).second.size()>1)
2852         {
2853           std::vector<int> ret0;
2854           bool equalityOrNot=false;
2855           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2856             {
2857               std::vector<int>::const_iterator it4=it3; it4++;
2858               for(;it4!=(*it2).second.end();it4++)
2859                 {
2860                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2861                     {
2862                       if(!equalityOrNot)
2863                         ret0.push_back(*it3);
2864                       ret0.push_back(*it4);
2865                       equalityOrNot=true;
2866                     }
2867                 }
2868             }
2869           if(!ret0.empty())
2870             ret.push_back(ret0);
2871         }
2872     }
2873   return ret;
2874 }
2875
2876 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2877 {
2878   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2879 }
2880
2881 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
2882 {
2883   std::string name(pfl->getName());
2884   if(name.empty())
2885     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2886   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2887     if(name==(*it)->getName())
2888       {
2889         if(!pfl->isEqual(*(*it)))
2890           {
2891             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2892             throw INTERP_KERNEL::Exception(oss.str().c_str());
2893           }
2894       }
2895   pfl->incrRef();
2896   _pfls.push_back(pfl);
2897 }
2898
2899 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)
2900 {
2901   std::string name(locName);
2902   if(name.empty())
2903     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2904   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2905   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2906     if((*it)->isName(locName))
2907       {
2908         if(!(*it)->isEqual(*obj,1e-12))
2909           {
2910             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
2911             throw INTERP_KERNEL::Exception(oss.str().c_str());
2912           }
2913       }
2914   _locs.push_back(obj);
2915 }
2916
2917 std::string MEDFileFieldGlobs::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
2918 {
2919   std::vector<std::string> names=getPfls();
2920   return CreateNewNameNotIn("NewPfl_",names);
2921 }
2922
2923 std::string MEDFileFieldGlobs::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
2924 {
2925   std::vector<std::string> names=getLocs();
2926   return CreateNewNameNotIn("NewLoc_",names);
2927 }
2928
2929 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const char *prefix, const std::vector<std::string>& namesToAvoid) throw(INTERP_KERNEL::Exception)
2930 {
2931   for(std::size_t sz=0;sz<100000;sz++)
2932     {
2933       std::ostringstream tryName;
2934       tryName << prefix << sz;
2935       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
2936         return tryName.str();
2937     }
2938   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
2939 }
2940
2941 /*!
2942  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
2943  *  \param [in] fname - the file name.
2944  */
2945 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const char *fname):_globals(MEDFileFieldGlobs::New(fname))
2946 {
2947 }
2948
2949 /*!
2950  * Creates an empty MEDFileFieldGlobsReal.
2951  */
2952 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
2953 {
2954 }
2955
2956 std::size_t MEDFileFieldGlobsReal::getHeapMemorySize() const
2957 {
2958   std::size_t ret=0;
2959   if((const MEDFileFieldGlobs *)_globals)
2960     ret+=_globals->getHeapMemorySize();
2961   return ret;
2962 }
2963
2964 /*!
2965  * Returns a string describing profiles and Gauss points held in \a this.
2966  *  \return std::string - the description string.
2967  */
2968 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
2969 {
2970   const MEDFileFieldGlobs *glob=_globals;
2971   std::ostringstream oss2; oss2 << glob;
2972   std::string stars(oss2.str().length(),'*');
2973   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
2974   if(glob)
2975     glob->simpleRepr(oss);
2976   else
2977     oss << "NO GLOBAL INFORMATION !\n";
2978 }
2979
2980 void MEDFileFieldGlobsReal::resetContent()
2981 {
2982   _globals=MEDFileFieldGlobs::New();
2983 }
2984
2985 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
2986 {
2987 }
2988
2989 /*!
2990  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
2991  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
2992  */
2993 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
2994 {
2995   _globals=other._globals;
2996 }
2997
2998 /*!
2999  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3000  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3001  */
3002 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other) throw(INTERP_KERNEL::Exception)
3003 {
3004   const MEDFileFieldGlobs *otherg(other._globals);
3005   if(!otherg)
3006     return ;
3007   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3008 }
3009
3010 /*!
3011  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3012  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3013  */
3014 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other) throw(INTERP_KERNEL::Exception)
3015 {
3016   const MEDFileFieldGlobs *otherg(other._globals);
3017   if(!otherg)
3018     return ;
3019   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3020 }
3021
3022 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3023 {
3024   _globals=other._globals;
3025   if((const MEDFileFieldGlobs *)_globals)
3026     _globals=other._globals->deepCpy();
3027 }
3028
3029 /*!
3030  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3031  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3032  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3033  *         \a this and \a other MEDFileFieldGlobsReal.
3034  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3035  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3036  */
3037 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps) throw(INTERP_KERNEL::Exception)
3038 {
3039   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3040   if(thisGlobals==otherGlobals)
3041     return ;
3042   if(!thisGlobals)
3043     {
3044       _globals=other._globals;
3045       return ;
3046     }
3047   _globals->appendGlobs(*other._globals,eps);
3048 }
3049
3050 void MEDFileFieldGlobsReal::checkGlobsCoherency() const throw(INTERP_KERNEL::Exception)
3051 {
3052   checkGlobsPflsPartCoherency();
3053   checkGlobsLocsPartCoherency();
3054 }
3055
3056 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const throw(INTERP_KERNEL::Exception)
3057 {
3058   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3059 }
3060
3061 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const throw(INTERP_KERNEL::Exception)
3062 {
3063   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3064 }
3065
3066 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
3067 {
3068   contentNotNull()->loadProfileInFile(fid,id,pflName);
3069 }
3070
3071 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3072 {
3073   contentNotNull()->loadProfileInFile(fid,id);
3074 }
3075
3076 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
3077 {
3078   contentNotNull()->loadGlobals(fid,*this);
3079 }
3080
3081 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
3082 {
3083   contentNotNull()->loadAllGlobals(fid);
3084 }
3085
3086 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
3087 {
3088   contentNotNull()->writeGlobals(fid,opt);
3089 }
3090
3091 /*!
3092  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3093  * or getPflsReallyUsedMulti().
3094  *  \return std::vector<std::string> - a sequence of names of all profiles.
3095  */
3096 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3097 {
3098   return contentNotNull()->getPfls();
3099 }
3100
3101 /*!
3102  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3103  * or getLocsReallyUsedMulti().
3104  *  \return std::vector<std::string> - a sequence of names of all localizations.
3105  */
3106 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3107 {
3108   return contentNotNull()->getLocs();
3109 }
3110
3111 /*!
3112  * Checks if the profile with a given name exists.
3113  *  \param [in] pflName - the profile name of interest.
3114  *  \return bool - \c true if the profile named \a pflName exists.
3115  */
3116 bool MEDFileFieldGlobsReal::existsPfl(const char *pflName) const
3117 {
3118   return contentNotNull()->existsPfl(pflName);
3119 }
3120
3121 /*!
3122  * Checks if the localization with a given name exists.
3123  *  \param [in] locName - the localization name of interest.
3124  *  \return bool - \c true if the localization named \a locName exists.
3125  */
3126 bool MEDFileFieldGlobsReal::existsLoc(const char *locName) const
3127 {
3128   return contentNotNull()->existsLoc(locName);
3129 }
3130
3131 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
3132 {
3133   return contentNotNull()->createNewNameOfPfl();
3134 }
3135
3136 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
3137 {
3138   return contentNotNull()->createNewNameOfLoc();
3139 }
3140
3141 /*!
3142  * Sets the name of a MED file.
3143  *  \param [inout] fileName - the file name.
3144  */
3145 void MEDFileFieldGlobsReal::setFileName(const char *fileName)
3146 {
3147   contentNotNull()->setFileName(fileName);
3148 }
3149
3150 /*!
3151  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3152  * in the same order.
3153  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3154  *          Each item of this sequence is a vector containing ids of equal profiles.
3155  */
3156 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3157 {
3158   return contentNotNull()->whichAreEqualProfiles();
3159 }
3160
3161 /*!
3162  * Finds equal localizations.
3163  *  \param [in] eps - a precision used to compare real values of the localizations.
3164  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3165  *          Each item of this sequence is a vector containing ids of equal localizations.
3166  */
3167 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3168 {
3169   return contentNotNull()->whichAreEqualLocs(eps);
3170 }
3171
3172 /*!
3173  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3174  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3175  *        this sequence is a pair whose 
3176  *        - the first item is a vector of profile names to replace by the second item,
3177  *        - the second item is a profile name to replace every profile name of the first item.
3178  */
3179 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3180 {
3181   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3182 }
3183
3184 /*!
3185  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3186  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3187  *        this sequence is a pair whose 
3188  *        - the first item is a vector of localization names to replace by the second item,
3189  *        - the second item is a localization name to replace every localization name of the first item.
3190  */
3191 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3192 {
3193   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3194 }
3195
3196 /*!
3197  * Replaces references to some profiles (a reference is a profile name) by references
3198  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3199  * them-selves accordingly. <br>
3200  * This method is a generalization of changePflName().
3201  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3202  *        this sequence is a pair whose 
3203  *        - the first item is a vector of profile names to replace by the second item,
3204  *        - the second item is a profile name to replace every profile of the first item.
3205  * \sa changePflsRefsNamesGen()
3206  * \sa changePflName()
3207  */
3208 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3209 {
3210   changePflsRefsNamesGen(mapOfModif);
3211   changePflsNamesInStruct(mapOfModif);
3212 }
3213
3214 /*!
3215  * Replaces references to some localizations (a reference is a localization name) by references
3216  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3217  * them-selves accordingly. <br>
3218  * This method is a generalization of changeLocName().
3219  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3220  *        this sequence is a pair whose 
3221  *        - the first item is a vector of localization names to replace by the second item,
3222  *        - the second item is a localization name to replace every localization of the first item.
3223  * \sa changeLocsRefsNamesGen()
3224  * \sa changeLocName()
3225  */
3226 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3227 {
3228   changeLocsRefsNamesGen(mapOfModif);
3229   changeLocsNamesInStruct(mapOfModif);
3230 }
3231
3232 /*!
3233  * Renames the profile having a given name and updates references to this profile.
3234  *  \param [in] oldName - the name of the profile to rename.
3235  *  \param [in] newName - a new name of the profile.
3236  * \sa changePflsNames().
3237  */
3238 void MEDFileFieldGlobsReal::changePflName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
3239 {
3240   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3241   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3242   mapOfModif[0]=p;
3243   changePflsNames(mapOfModif);
3244 }
3245
3246 /*!
3247  * Renames the localization having a given name and updates references to this localization.
3248  *  \param [in] oldName - the name of the localization to rename.
3249  *  \param [in] newName - a new name of the localization.
3250  * \sa changeLocsNames().
3251  */
3252 void MEDFileFieldGlobsReal::changeLocName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
3253 {
3254   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3255   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3256   mapOfModif[0]=p;
3257   changeLocsNames(mapOfModif);
3258 }
3259
3260 /*!
3261  * Removes duplicated profiles. Returns a map used to update references to removed 
3262  * profiles via changePflsRefsNamesGen().
3263  * Equal profiles are found using whichAreEqualProfiles().
3264  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3265  *          a sequence describing the performed replacements of profiles. Each element of
3266  *          this sequence is a pair whose
3267  *          - the first item is a vector of profile names replaced by the second item,
3268  *          - the second item is a profile name replacing every profile of the first item.
3269  */
3270 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames() throw(INTERP_KERNEL::Exception)
3271 {
3272   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
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(getProfileFromId(*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       killProfileIds(tmp2);
3285     }
3286   changePflsRefsNamesGen(ret);
3287   return ret;
3288 }
3289
3290 /*!
3291  * Removes duplicated localizations. Returns a map used to update references to removed 
3292  * localizations via changeLocsRefsNamesGen().
3293  * Equal localizations are found using whichAreEqualLocs().
3294  *  \param [in] eps - a precision used to compare real values of the localizations.
3295  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3296  *          a sequence describing the performed replacements of localizations. Each element of
3297  *          this sequence is a pair whose
3298  *          - the first item is a vector of localization names replaced by the second item,
3299  *          - the second item is a localization name replacing every localization of the first item.
3300  */
3301 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps) throw(INTERP_KERNEL::Exception)
3302 {
3303   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3304   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3305   int i=0;
3306   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3307     {
3308       std::vector< std::string > tmp((*it).size());
3309       int j=0;
3310       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3311         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3312       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3313       ret[i]=p;
3314       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3315       killLocalizationIds(tmp2);
3316     }
3317   changeLocsRefsNamesGen(ret);
3318   return ret;
3319 }
3320
3321 /*!
3322  * Returns number of Gauss points per cell in a given localization.
3323  *  \param [in] locId - an id of the localization of interest.
3324  *  \return int - the number of the Gauss points per cell.
3325  */
3326 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
3327 {
3328   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3329 }
3330
3331 /*!
3332  * Returns an id of a localization by its name.
3333  *  \param [in] loc - the localization name of interest.
3334  *  \return int - the id of the localization.
3335  *  \throw If there is no a localization named \a loc.
3336  */
3337 int MEDFileFieldGlobsReal::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
3338 {
3339   return contentNotNull()->getLocalizationId(loc);
3340 }
3341
3342 /*!
3343  * Returns the name of the MED file.
3344  *  \return const char * - the MED file name.
3345  */
3346 const char *MEDFileFieldGlobsReal::getFileName() const
3347 {
3348   return contentNotNull()->getFileName();
3349 }
3350
3351 std::string MEDFileFieldGlobsReal::getFileName2() const
3352 {
3353   return contentNotNull()->getFileName2();
3354 }
3355
3356 /*!
3357  * Returns a localization object by its name.
3358  *  \param [in] locName - the name of the localization of interest.
3359  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3360  *  \throw If there is no a localization named \a locName.
3361  */
3362 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
3363 {
3364   return contentNotNull()->getLocalization(locName);
3365 }
3366
3367 /*!
3368  * Returns a localization object by its id.
3369  *  \param [in] locId - the id of the localization of interest.
3370  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3371  *  \throw If there is no a localization with id \a locId.
3372  */
3373 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
3374 {
3375   return contentNotNull()->getLocalizationFromId(locId);
3376 }
3377
3378 /*!
3379  * Returns a profile array by its name.
3380  *  \param [in] pflName - the name of the profile of interest.
3381  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3382  *  \throw If there is no a profile named \a pflName.
3383  */
3384 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
3385 {
3386   return contentNotNull()->getProfile(pflName);
3387 }
3388
3389 /*!
3390  * Returns a profile array by its id.
3391  *  \param [in] pflId - the id of the profile of interest.
3392  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3393  *  \throw If there is no a profile with id \a pflId.
3394  */
3395 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
3396 {
3397   return contentNotNull()->getProfileFromId(pflId);
3398 }
3399
3400 /*!
3401  * Returns a localization object, apt for modification, by its id.
3402  *  \param [in] locId - the id of the localization of interest.
3403  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3404  *          having the id \a locId.
3405  *  \throw If there is no a localization with id \a locId.
3406  */
3407 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
3408 {
3409   return contentNotNull()->getLocalizationFromId(locId);
3410 }
3411
3412 /*!
3413  * Returns a localization object, apt for modification, by its name.
3414  *  \param [in] locName - the name of the localization of interest.
3415  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3416  *          having the name \a locName.
3417  *  \throw If there is no a localization named \a locName.
3418  */
3419 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
3420 {
3421   return contentNotNull()->getLocalization(locName);
3422 }
3423
3424 /*!
3425  * Returns a profile array, apt for modification, by its name.
3426  *  \param [in] pflName - the name of the profile of interest.
3427  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3428  *  \throw If there is no a profile named \a pflName.
3429  */
3430 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
3431 {
3432   return contentNotNull()->getProfile(pflName);
3433 }
3434
3435 /*!
3436  * Returns a profile array, apt for modification, by its id.
3437  *  \param [in] pflId - the id of the profile of interest.
3438  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3439  *  \throw If there is no a profile with id \a pflId.
3440  */
3441 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
3442 {
3443   return contentNotNull()->getProfileFromId(pflId);
3444 }
3445
3446 /*!
3447  * Removes profiles given by their ids. No data is updated to track this removal.
3448  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3449  */
3450 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
3451 {
3452   contentNotNull()->killProfileIds(pflIds);
3453 }
3454
3455 /*!
3456  * Removes localizations given by their ids. No data is updated to track this removal.
3457  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3458  */
3459 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
3460 {
3461   contentNotNull()->killLocalizationIds(locIds);
3462 }
3463
3464 /*!
3465  * Stores a profile array.
3466  *  \param [in] pfl - the profile array to store.
3467  *  \throw If the name of \a pfl is empty.
3468  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3469  *         different ids.
3470  */
3471 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
3472 {
3473   contentNotNull()->appendProfile(pfl);
3474 }
3475
3476 /*!
3477  * Adds a new localization of Gauss points.
3478  *  \param [in] locName - the name of the new localization.
3479  *  \param [in] geoType - a geometrical type of the reference cell.
3480  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3481  *         must be \c nbOfNodesPerCell * \c dimOfType.
3482  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3483  *         must be  _wg_.size() * \c dimOfType.
3484  *  \param [in] w - the weights of Gauss points.
3485  *  \throw If \a locName is empty.
3486  *  \throw If a localization with the name \a locName already exists but is
3487  *         different form the new one.
3488  */
3489 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)
3490 {
3491   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3492 }
3493
3494 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() throw(INTERP_KERNEL::Exception)
3495 {
3496   MEDFileFieldGlobs *g(_globals);
3497   if(!g)
3498     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3499   return g;
3500 }
3501
3502 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const throw(INTERP_KERNEL::Exception)
3503 {
3504   const MEDFileFieldGlobs *g(_globals);
3505   if(!g)
3506     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3507   return g;
3508 }
3509
3510 //= MEDFileFieldNameScope
3511
3512 MEDFileFieldNameScope::MEDFileFieldNameScope()
3513 {
3514 }
3515
3516 MEDFileFieldNameScope::MEDFileFieldNameScope(const char *fieldName):_name(fieldName)
3517 {
3518 }
3519
3520 /*!
3521  * Returns the name of \a this field.
3522  *  \return std::string - a string containing the field name.
3523  */
3524 std::string MEDFileFieldNameScope::getName() const throw(INTERP_KERNEL::Exception)
3525 {
3526   return _name;
3527 }
3528
3529 /*!
3530  * Sets name of \a this field
3531  *  \param [in] name - the new field name.
3532  */
3533 void MEDFileFieldNameScope::setName(const char *fieldName) throw(INTERP_KERNEL::Exception)
3534 {
3535   _name=fieldName;
3536 }
3537
3538 std::string MEDFileFieldNameScope::getDtUnit() const throw(INTERP_KERNEL::Exception)
3539 {
3540   return _dt_unit;
3541 }
3542
3543 void MEDFileFieldNameScope::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
3544 {
3545   _dt_unit=dtUnit;
3546 }
3547
3548 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3549 {
3550   _name=other._name;
3551   _dt_unit=other._dt_unit;
3552 }
3553
3554 //= MEDFileAnyTypeField1TSWithoutSDA
3555
3556 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other) throw(INTERP_KERNEL::Exception)
3557 {
3558   _field_per_mesh.resize(other._field_per_mesh.size());
3559   std::size_t i=0;
3560   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3561     {
3562       if((const MEDFileFieldPerMesh *)*it)
3563         _field_per_mesh[i]=(*it)->deepCpy(this);
3564     }
3565 }
3566
3567 /*!
3568  * Prints a string describing \a this field into a stream. This string is outputted 
3569  * by \c print Python command.
3570  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3571  *  \param [in,out] oss - the out stream.
3572  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3573  *          info id printed, else, not.
3574  */
3575 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3576 {
3577   std::string startOfLine(bkOffset,' ');
3578   oss << startOfLine << "Field ";
3579   if(bkOffset==0)
3580     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3581   oss << "on one time Step ";
3582   if(f1tsId>=0)
3583     oss << "(" << f1tsId << ") ";
3584   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3585   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3586   const DataArray *arr=getUndergroundDataArray();
3587   if(arr)
3588     {
3589       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3590       if(f1tsId<0)
3591         {
3592           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3593           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3594             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3595         }
3596       if(arr->isAllocated())
3597         {
3598           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3599         }
3600       else
3601         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3602     }
3603   else
3604     {
3605       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3606     }
3607   oss << startOfLine << "----------------------" << std::endl;
3608   if(!_field_per_mesh.empty())
3609     {
3610       int i=0;
3611       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3612         {
3613           const MEDFileFieldPerMesh *cur=(*it2);
3614           if(cur)
3615             cur->simpleRepr(bkOffset,oss,i);
3616           else
3617             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3618         }
3619     }
3620   else
3621     {
3622       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3623     }
3624   oss << startOfLine << "----------------------" << std::endl;
3625 }
3626
3627 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const throw(INTERP_KERNEL::Exception)
3628 {
3629   const DataArray *arr(getUndergroundDataArray());
3630   if(!arr)
3631     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3632   int nbOfCompo=arr->getNumberOfComponents();
3633   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3634   for(int i=0;i<nbOfCompo;i++)
3635     {
3636       ret[i]=deepCpy();
3637       std::vector<int> v(1,i);
3638       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3639       ret[i]->setArray(arr2);
3640     }
3641   return ret;
3642 }
3643
3644 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order):MEDFileFieldNameScope(fieldName),_iteration(iteration),_order(order),_csit(csit),_nb_of_tuples_to_be_allocated(-2)
3645 {
3646 }
3647
3648 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3649 {
3650 }
3651
3652 /*!
3653  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3654  * empty. Returns -1 if this in on nodes.
3655  *  \return int - the dimension of \a this.
3656  */
3657 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3658 {
3659   int ret=-2;
3660   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3661     (*it)->getDimension(ret);
3662   return ret;
3663 }
3664
3665 /*!
3666  * Returns the mesh name.
3667  *  \return std::string - a string holding the mesh name.
3668  *  \throw If \c _field_per_mesh.empty()
3669  */
3670 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
3671 {
3672   if(_field_per_mesh.empty())
3673     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3674   return _field_per_mesh[0]->getMeshName();
3675 }
3676
3677 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
3678 {
3679   std::string oldName(getMeshName());
3680   std::vector< std::pair<std::string,std::string> > v(1);
3681   v[0].first=oldName; v[0].second=newMeshName;
3682   changeMeshNames(v);
3683 }
3684
3685 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
3686 {
3687   bool ret=false;
3688   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3689     {
3690       MEDFileFieldPerMesh *cur(*it);
3691       if(cur)
3692         ret=cur->changeMeshNames(modifTab) || ret;
3693     }
3694   return ret;
3695 }
3696
3697 /*!
3698  * Returns the number of iteration of the state of underlying mesh.
3699  *  \return int - the iteration number.
3700  *  \throw If \c _field_per_mesh.empty()
3701  */
3702 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const throw(INTERP_KERNEL::Exception)
3703 {
3704   if(_field_per_mesh.empty())
3705     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3706   return _field_per_mesh[0]->getMeshIteration();
3707 }
3708
3709 /*!
3710  * Returns the order number of iteration of the state of underlying mesh.
3711  *  \return int - the order number.
3712  *  \throw If \c _field_per_mesh.empty()
3713  */
3714 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const throw(INTERP_KERNEL::Exception)
3715 {
3716   if(_field_per_mesh.empty())
3717     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3718   return _field_per_mesh[0]->getMeshOrder();
3719 }
3720
3721 /*!
3722  * Checks if \a this field is tagged by a given iteration number and a given
3723  * iteration order number.
3724  *  \param [in] iteration - the iteration number of interest.
3725  *  \param [in] order - the iteration order number of interest.
3726  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3727  *          \a this->getOrder() == \a order.
3728  */
3729 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3730 {
3731   return iteration==_iteration && order==_order;
3732 }
3733
3734 /*!
3735  * Returns number of iteration and order number of iteration when
3736  * \a this field has been calculated.
3737  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3738  *          order number.
3739  */
3740 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3741 {
3742   std::pair<int,int> p;
3743   fillIteration(p);
3744   return p;
3745 }
3746
3747 /*!
3748  * Returns number of iteration and order number of iteration when
3749  * \a this field has been calculated.
3750  *  \param [in,out] p - a pair returning the iteration number and the iteration
3751  *          order number.
3752  */
3753 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3754 {
3755   p.first=_iteration;
3756   p.second=_order;
3757 }
3758
3759 /*!
3760  * Returns all types of spatial discretization of \a this field.
3761  *  \param [in,out] types - a sequence of types of \a this field.
3762  */
3763 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
3764 {
3765   std::set<TypeOfField> types2;
3766   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3767     {
3768       (*it)->fillTypesOfFieldAvailable(types2);
3769     }
3770   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3771   std::copy(types2.begin(),types2.end(),bi);
3772 }
3773
3774 /*!
3775  * Returns all types of spatial discretization of \a this field.
3776  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3777  *          of \a this field.
3778  */
3779 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
3780 {
3781   std::vector<TypeOfField> ret;
3782   fillTypesOfFieldAvailable(ret);
3783   return ret;
3784 }
3785
3786 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3787 {
3788   std::vector<std::string> ret;
3789   std::set<std::string> ret2;
3790   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3791     {
3792       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3793       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3794         if(ret2.find(*it2)==ret2.end())
3795           {
3796             ret.push_back(*it2);
3797             ret2.insert(*it2);
3798           }
3799     }
3800   return ret;
3801 }
3802
3803 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3804 {
3805   std::vector<std::string> ret;
3806   std::set<std::string> ret2;
3807   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3808     {
3809       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3810       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3811         if(ret2.find(*it2)==ret2.end())
3812           {
3813             ret.push_back(*it2);
3814             ret2.insert(*it2);
3815           }
3816     }
3817   return ret;
3818 }
3819
3820 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3821 {
3822   std::vector<std::string> ret;
3823   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3824     {
3825       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3826       ret.insert(ret.end(),tmp.begin(),tmp.end());
3827     }
3828   return ret;
3829 }
3830
3831 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3832 {
3833   std::vector<std::string> ret;
3834   std::set<std::string> ret2;
3835   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3836     {
3837       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3838       ret.insert(ret.end(),tmp.begin(),tmp.end());
3839     }
3840   return ret;
3841 }
3842
3843 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3844 {
3845   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3846     (*it)->changePflsRefsNamesGen(mapOfModif);
3847 }
3848
3849 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3850 {
3851   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3852     (*it)->changeLocsRefsNamesGen(mapOfModif);
3853 }
3854
3855 /*!
3856  * Returns all attributes of parts of \a this field lying on a given mesh.
3857  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3858  * item of every of returned sequences refers to the _i_-th part of \a this field.
3859  * Thus all sequences returned by this method are of the same length equal to number
3860  * of different types of supporting entities.<br>
3861  * A field part can include sub-parts with several different spatial discretizations,
3862  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3863  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3864  * of a nested sequence corresponds to a type of spatial discretization.<br>
3865  * This method allows for iteration over MEDFile DataStructure without any overhead.
3866  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3867  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3868  *          not checked if \a mname == \c NULL).
3869  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3870  *          a field part is returned. 
3871  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3872  *          This sequence is of the same length as \a types. 
3873  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3874  *          discretization. A profile name can be empty.
3875  *          Length of this and of nested sequences is the same as that of \a typesF.
3876  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3877  *          discretization. A localization name can be empty.
3878  *          Length of this and of nested sequences is the same as that of \a typesF.
3879  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3880  *          of ids of tuples within the data array, per each type of spatial
3881  *          discretization within one mesh entity type. 
3882  *          Length of this and of nested sequences is the same as that of \a typesF.
3883  *  \throw If no field is lying on \a mname.
3884  */
3885 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)
3886 {
3887   int meshId=0;
3888   if(mname)
3889     meshId=getMeshIdFromMeshName(mname);
3890   else
3891     if(_field_per_mesh.empty())
3892       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3893   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3894 }
3895
3896 /*!
3897  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
3898  * maximal absolute dimension and values returned via the out parameter \a levs are 
3899  * dimensions relative to the maximal absolute dimension. <br>
3900  * This method is designed for MEDFileField1TS instances that have a discretization
3901  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
3902  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
3903  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
3904  * Only these 3 discretizations will be taken into account here. If \a this is
3905  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
3906  * This method is useful to make the link between the dimension of the underlying mesh
3907  * and the levels of \a this, because it is possible that the highest dimension of \a this
3908  * field is not equal to the dimension of the underlying mesh.
3909  * 
3910  * Let's consider the following case:
3911  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
3912  * TETRA4, HEXA8, TRI3 and SEG2.
3913  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
3914  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
3915  *
3916  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
3917  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
3918  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
3919  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
3920  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
3921  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
3922  * For example<br>
3923  * to retrieve the highest level of
3924  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
3925  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
3926  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
3927  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
3928  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3929  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3930  *          not checked if \a mname == \c NULL).
3931  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
3932  *          absolute one. They are in decreasing order. This sequence is cleared before
3933  *          filling it in.
3934  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
3935  *  \throw If no field is lying on \a mname.
3936  */
3937 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
3938 {
3939   levs.clear();
3940   int meshId=getMeshIdFromMeshName(mname);
3941   std::vector<INTERP_KERNEL::NormalizedCellType> types;
3942   std::vector< std::vector<TypeOfField> > typesF;
3943   std::vector< std::vector<std::string> > pfls, locs;
3944   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3945   if(types.empty())
3946     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
3947   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
3948   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
3949     return -1;
3950   st.erase(INTERP_KERNEL::NORM_ERROR);
3951   std::set<int> ret1;
3952   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
3953     {
3954       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
3955       ret1.insert((int)cm.getDimension());
3956     }
3957   int ret=*std::max_element(ret1.begin(),ret1.end());
3958   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
3959   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
3960   return ret;
3961 }
3962
3963 /*!
3964  * \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.
3965  * \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.
3966  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3967  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3968  */
3969 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
3970 {
3971   int mid=getMeshIdFromMeshName(mName);
3972   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3973 }
3974
3975 /*!
3976  * \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.
3977  * \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.
3978  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3979  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3980  */
3981 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
3982 {
3983   int mid=getMeshIdFromMeshName(mName);
3984   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3985 }
3986
3987 /*!
3988  * \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.
3989  */
3990 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception)
3991 {
3992   if(_field_per_mesh.empty())
3993     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
3994   if(mName==0)
3995     return 0;
3996   std::string mName2(mName);
3997   int ret=0;
3998   std::vector<std::string> msg;
3999   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4000     if(mName2==(*it)->getMeshName())
4001       return ret;
4002     else
4003       msg.push_back((*it)->getMeshName());
4004   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4005   oss << "Possible meshes are : ";
4006   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4007     oss << "\"" << (*it2) << "\" ";
4008   throw INTERP_KERNEL::Exception(oss.str().c_str());
4009 }
4010
4011 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
4012 {
4013   if(!mesh)
4014     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4015   std::string tmp(mesh->getName());
4016   if(tmp.empty())
4017     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4018   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4019   int i=0;
4020   for(;it!=_field_per_mesh.end();it++,i++)
4021     {
4022       if((*it)->getMeshName()==tmp)
4023         return i;
4024     }
4025   int sz=_field_per_mesh.size();
4026   _field_per_mesh.resize(sz+1);
4027   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4028   return sz;
4029 }
4030
4031 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4032                                                             MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
4033 {
4034   bool ret=false;
4035   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4036     {
4037       MEDFileFieldPerMesh *fpm(*it);
4038       if(fpm)
4039         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4040     }
4041   return ret;
4042 }
4043
4044 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const throw(INTERP_KERNEL::Exception)
4045 {
4046   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4047   std::vector< std::vector<TypeOfField> > typesF;
4048   std::vector< std::vector<std::string> > pfls,locs;
4049   std::vector< std::vector<std::pair<int,int> > > bgEnd=getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs);
4050   std::set<TypeOfField> allEnt;
4051   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4052     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4053       allEnt.insert(*it2);
4054   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4055   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4056   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4057     {
4058       std::vector< std::pair<int,int> > its;
4059       ret[i]=shallowCpy();
4060       int newLgth=ret[i]->keepOnlySpatialDiscretization(*it3,its);
4061       ret[i]->updateData(newLgth,its);
4062     }
4063   return ret;
4064 }
4065
4066 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
4067 {
4068   int globalCounter=0;
4069   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4070     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4071   return globalCounter;
4072 }
4073
4074 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops) throw(INTERP_KERNEL::Exception)
4075 {
4076   if(_nb_of_tuples_to_be_allocated>=0)
4077     {
4078       _nb_of_tuples_to_be_allocated=newLgth;
4079       return ;
4080     }
4081   if(_nb_of_tuples_to_be_allocated==-1)
4082     return ;
4083   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4084     {
4085       const DataArray *oldArr=getUndergroundDataArray();
4086       if(!oldArr || !oldArr->isAllocated())
4087         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4088       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr=createNewEmptyDataArrayInstance();
4089       newArr->alloc(newLgth,getNumberOfComponents());
4090       int pos=0;
4091       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4092         {
4093           if((*it).second<(*it).first)
4094             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4095           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4096           pos+=(*it).second-(*it).first;
4097         }
4098       setArray(newArr);
4099       return ;
4100     }
4101   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4102 }
4103
4104 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4105 {
4106   if(_field_per_mesh.empty())
4107     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4108   if(_field_per_mesh.size()>1)
4109     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4110   _field_per_mesh[0]->copyOptionsFrom(opts);
4111   _field_per_mesh[0]->writeLL(fid,nasc);
4112 }
4113
4114 /*!
4115  * This methods returns true is the allocation has been needed leading to a modification of state in \a this->_nb_of_tuples_to_be_allocated.
4116  * If false is returned the memory allocation is not required.
4117  */
4118 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile() throw(INTERP_KERNEL::Exception)
4119 {
4120   if(_nb_of_tuples_to_be_allocated>=0)
4121     {
4122       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4123       _nb_of_tuples_to_be_allocated=-2;
4124       return true;
4125     }
4126   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4127     return false;
4128   if(_nb_of_tuples_to_be_allocated==-1)
4129     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4130   if(_nb_of_tuples_to_be_allocated<-3)
4131     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4132   
4133 }
4134
4135 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4136 {
4137   med_int numdt,numit;
4138   med_float dt;
4139   med_int nmesh;
4140   med_bool localMesh;
4141   med_int meshnumdt,meshnumit;
4142   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4143   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4144   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4145   if(_iteration!=numdt || _order!=numit)
4146     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4147   _field_per_mesh.resize(nmesh);
4148   for(int i=0;i<nmesh;i++)
4149     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i+1,meshnumdt,meshnumit,nasc);//tony
4150   _nb_of_tuples_to_be_allocated=0;
4151   for(int i=0;i<nmesh;i++)
4152     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4153 }
4154
4155 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4156 {
4157   allocIfNecessaryTheArrayToReceiveDataFromFile();
4158   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4159     (*it)->loadBigArraysRecursively(fid,nasc);
4160 }
4161
4162 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4163 {
4164   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4165     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4166       (*it)->loadBigArraysRecursively(fid,nasc);
4167 }
4168
4169 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4170 {
4171   loadOnlyStructureOfDataRecursively(fid,nasc);
4172   loadBigArraysRecursively(fid,nasc);
4173 }
4174
4175 void MEDFileAnyTypeField1TSWithoutSDA::releaseArrays() throw(INTERP_KERNEL::Exception)
4176 {
4177   DataArray *thisArr(getUndergroundDataArray());
4178   if(thisArr && thisArr->isAllocated())
4179     {
4180       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4181       thisArr->desallocate();
4182     }
4183 }
4184
4185 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySize() const
4186 {
4187   std::size_t ret=_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4188   if(getUndergroundDataArray())
4189     ret+=getUndergroundDataArray()->getHeapMemorySize();
4190   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4191     ret+=(*it)->getHeapMemorySize();
4192   return ret;
4193 }
4194
4195 /*!
4196  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4197  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4198  * "Sort By Type"), if not, an exception is thrown. 
4199  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4200  *  \param [in] arr - the array of values.
4201  *  \param [in,out] glob - the global data where profiles and localization present in
4202  *          \a field, if any, are added.
4203  *  \throw If the name of \a field is empty.
4204  *  \throw If the data array of \a field is not set.
4205  *  \throw If \a this->_arr is already allocated but has different number of components
4206  *         than \a field.
4207  *  \throw If the underlying mesh of \a field has no name.
4208  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4209  */
4210 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
4211 {
4212   const MEDCouplingMesh *mesh=field->getMesh();
4213   //
4214   TypeOfField type=field->getTypeOfField();
4215   std::vector<DataArrayInt *> dummy;
4216   int start=copyTinyInfoFrom(field,arr);
4217   int pos=addNewEntryIfNecessary(mesh);
4218   if(type!=ON_NODES)
4219     {
4220       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4221       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4222     }
4223   else
4224     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4225 }
4226
4227 /*!
4228  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4229  * of a given mesh are used as the support of the given field (a real support is not used). 
4230  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4231  * Order of underlying mesh entities of the given field specified by \a profile parameter
4232  * is not prescribed; this method permutes field values to have them sorted by element
4233  * type as required for writing to MED file. A new profile is added only if no equal
4234  * profile is missing. 
4235  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4236  *  \param [in] arrOfVals - the values of the field \a field used.
4237  *  \param [in] mesh - the supporting mesh of \a field.
4238  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4239  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4240  *  \param [in,out] glob - the global data where profiles and localization present in
4241  *          \a field, if any, are added.
4242  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4243  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4244  *  \throw If the data array of \a field is not set.
4245  *  \throw If \a this->_arr is already allocated but has different number of components
4246  *         than \a field.
4247  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4248  *  \sa setFieldNoProfileSBT()
4249  */
4250 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)
4251 {
4252   if(!field)
4253     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4254   if(!arrOfVals || !arrOfVals->isAllocated())
4255     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4256   TypeOfField type=field->getTypeOfField();
4257   std::vector<DataArrayInt *> idsInPflPerType;
4258   std::vector<DataArrayInt *> idsPerType;
4259   std::vector<int> code,code2;
4260   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4261   if(type!=ON_NODES)
4262     {
4263       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4264       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4265       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4266       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4267       // start of check
4268       MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2=field->clone(false);
4269       if(type==ON_GAUSS_NE)
4270         {
4271           MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mPart=m->buildPart(profile->begin(),profile->end());
4272           field2->setMesh(mPart);
4273         }
4274       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4275       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4276         {
4277           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4278           throw INTERP_KERNEL::Exception(oss.str().c_str());
4279         }
4280       // end of check
4281       int start=copyTinyInfoFrom(field,arrOfVals);
4282       code2=m->getDistributionOfTypes();
4283       //
4284       int pos=addNewEntryIfNecessary(m);
4285       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4286     }
4287   else
4288     {
4289       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4290         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4291       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4292       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4293       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4294       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4295         {
4296           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4297           throw INTERP_KERNEL::Exception(oss.str().c_str());
4298         }
4299       int start=copyTinyInfoFrom(field,arrOfVals);
4300       int pos=addNewEntryIfNecessary(m);
4301       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4302     }
4303 }
4304
4305 /*!
4306  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4307  */
4308 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples) throw(INTERP_KERNEL::Exception)
4309 {
4310   if(_nb_of_tuples_to_be_allocated>=0)
4311     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile : the object is expected to be appended to a data coming from a file but not loaded ! Load before appending data !");
4312   DataArray *arr(getOrCreateAndGetArray());
4313   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4314   _nb_of_tuples_to_be_allocated=-3;
4315 }
4316
4317 /*!
4318  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4319  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4320  * larger by the size of \a field. Returns an id of the first not filled
4321  * tuple of \a this->_arr.
4322  *  \param [in] field - the field to copy the info on components and the name from.
4323  *  \return int - the id of first not initialized tuple of \a this->_arr.
4324  *  \throw If the name of \a field is empty.
4325  *  \throw If the data array of \a field is not set.
4326  *  \throw If \a this->_arr is already allocated but has different number of components
4327  *         than \a field.
4328  */
4329 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
4330 {
4331   if(!field)
4332     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4333   std::string name(field->getName());
4334   setName(name.c_str());
4335   setDtUnit(field->getTimeUnit());
4336   if(name.empty())
4337     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4338   if(!arr)
4339     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4340   if(!arr->isAllocated())
4341     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4342   _dt=field->getTime(_iteration,_order);
4343   int nbOfComponents=arr->getNumberOfComponents();
4344   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4345   if(!getOrCreateAndGetArray()->isAllocated())
4346     {
4347       allocNotFromFile(arr->getNumberOfTuples());
4348       return 0;
4349     }
4350   else
4351     {
4352       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4353       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4354       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4355       _nb_of_tuples_to_be_allocated=-3;
4356       return oldNbOfTuples;
4357     }
4358 }
4359
4360 /*!
4361  * Returns number of components in \a this field
4362  *  \return int - the number of components.
4363  */
4364 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4365 {
4366   return getOrCreateAndGetArray()->getNumberOfComponents();
4367 }
4368
4369 /*!
4370  * Change info on components in \a this.
4371  * \throw If size of \a infos is not equal to the number of components already in \a this.
4372  */
4373 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
4374 {
4375   DataArray *arr=getOrCreateAndGetArray();
4376   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4377 }
4378
4379 /*!
4380  * Returns info on components of \a this field.
4381  *  \return const std::vector<std::string>& - a sequence of strings each being an
4382  *          information on _i_-th component.
4383  */
4384 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4385 {
4386   const DataArray *arr=getOrCreateAndGetArray();
4387   return arr->getInfoOnComponents();
4388 }
4389
4390 /*!
4391  * Returns a mutable info on components of \a this field.
4392  *  \return std::vector<std::string>& - a sequence of strings each being an
4393  *          information on _i_-th component.
4394  */
4395 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4396 {
4397   DataArray *arr=getOrCreateAndGetArray();
4398   return arr->getInfoOnComponents();
4399 }
4400
4401 /*!
4402  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4403  *  \param [in] type - a spatial discretization of the new field.
4404  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4405  *  \param [in] mName - a name of the supporting mesh.
4406  *  \param [in] renumPol - specifies how to permute values of the result field according to
4407  *          the optional numbers of cells and nodes, if any. The valid values are
4408  *          - 0 - do not permute.
4409  *          - 1 - permute cells.
4410  *          - 2 - permute nodes.
4411  *          - 3 - permute cells and nodes.
4412  *
4413  *  \param [in] glob - the global data storing profiles and localization.
4414  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4415  *          caller is to delete this field using decrRef() as it is no more needed. 
4416  *  \throw If the MED file is not readable.
4417  *  \throw If there is no mesh named \a mName in the MED file.
4418  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4419  *  \throw If no field of \a this is lying on the mesh \a mName.
4420  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4421  */
4422 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)
4423 {
4424   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4425   if(mName==0)
4426     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4427   else
4428     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4429   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4430 }
4431
4432 /*!
4433  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4434  *  \param [in] type - a spatial discretization of the new field.
4435  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4436  *  \param [in] renumPol - specifies how to permute values of the result field according to
4437  *          the optional numbers of cells and nodes, if any. The valid values are
4438  *          - 0 - do not permute.
4439  *          - 1 - permute cells.
4440  *          - 2 - permute nodes.
4441  *          - 3 - permute cells and nodes.
4442  *
4443  *  \param [in] glob - the global data storing profiles and localization.
4444  *  \param [in] mesh - the supporting mesh.
4445  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4446  *          caller is to delete this field using decrRef() as it is no more needed. 
4447  *  \throw If the MED file is not readable.
4448  *  \throw If no field of \a this is lying on \a mesh.
4449  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4450  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4451  */
4452 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)
4453 {
4454   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4455   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4456   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4457   if(meshDimRelToMax==1)
4458     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4459   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4460 }
4461
4462 /*!
4463  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4464  * given mesh. 
4465  *  \param [in] type - a spatial discretization of the new field.
4466  *  \param [in] mName - a name of the supporting mesh.
4467  *  \param [in] renumPol - specifies how to permute values of the result field according to
4468  *          the optional numbers of cells and nodes, if any. The valid values are
4469  *          - 0 - do not permute.
4470  *          - 1 - permute cells.
4471  *          - 2 - permute nodes.
4472  *          - 3 - permute cells and nodes.
4473  *
4474  *  \param [in] glob - the global data storing profiles and localization.
4475  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4476  *          caller is to delete this field using decrRef() as it is no more needed. 
4477  *  \throw If the MED file is not readable.
4478  *  \throw If there is no mesh named \a mName in the MED file.
4479  *  \throw If there are no mesh entities in the mesh.
4480  *  \throw If no field values of the given \a type are available.
4481  */
4482 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4483 {
4484    MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4485   if(mName==0)
4486     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4487   else
4488     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4489   int absDim=getDimension();
4490   int meshDimRelToMax=absDim-mm->getMeshDimension();
4491   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4492 }
4493
4494 /*!
4495  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4496  *  \param [in] type - a spatial discretization of the new field.
4497  *  \param [in] renumPol - specifies how to permute values of the result field according to
4498  *          the optional numbers of cells and nodes, if any. The valid values are
4499  *          - 0 - do not permute.
4500  *          - 1 - permute cells.
4501  *          - 2 - permute nodes.
4502  *          - 3 - permute cells and nodes.
4503  *
4504  *  \param [in] glob - the global data storing profiles and localization.
4505  *  \param [in] mesh - the supporting mesh.
4506  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4507  *         field according to \a renumPol.
4508  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4509  *         field according to \a renumPol.
4510  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4511  *          caller is to delete this field using decrRef() as it is no more needed. 
4512  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4513  *  \throw If no field of \a this is lying on \a mesh.
4514  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4515  */
4516 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)
4517 {
4518   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4519   int meshId=getMeshIdFromMeshName(mesh->getName());
4520   bool isPfl=false;
4521   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4522   switch(renumPol)
4523     {
4524     case 0:
4525       {
4526         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4527         return ret.retn();
4528       }
4529     case 3:
4530     case 1:
4531       {
4532         if(isPfl)
4533           throw INTERP_KERNEL::Exception(msg1);
4534         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4535         if(cellRenum)
4536           {
4537             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4538               {
4539                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4540                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4541                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4542               }
4543             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4544             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4545             std::vector<DataArray *> arrOut2(1,arrOut);
4546             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4547             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4548             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4549           }
4550         if(renumPol==1)
4551           return ret.retn();
4552       }
4553     case 2:
4554       {
4555         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4556         if(isPfl)
4557           throw INTERP_KERNEL::Exception(msg1);
4558         if(nodeRenum)
4559           {
4560             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4561               {
4562                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4563                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4564                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4565               }
4566             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4567             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4568               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4569             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4570           }
4571         return ret.retn();
4572       }
4573     default:
4574       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4575     }
4576 }
4577
4578 /*!
4579  * Returns values and a profile of the field of a given type lying on a given support.
4580  *  \param [in] type - a spatial discretization of the field.
4581  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4582  *  \param [in] mesh - the supporting mesh.
4583  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4584  *          field of interest lies on. If the field lies on all entities of the given
4585  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4586  *          using decrRef() as it is no more needed.  
4587  *  \param [in] glob - the global data storing profiles and localization.
4588  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4589  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4590  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4591  *  \throw If no field of \a this is lying on \a mesh.
4592  *  \throw If no field values of the given \a type are available.
4593  */
4594 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
4595 {
4596   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4597   int meshId=getMeshIdFromMeshName(mesh->getName());
4598   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4599   ret->setName(nasc.getName().c_str());
4600   return ret.retn();
4601 }
4602
4603 //= MEDFileField1TSWithoutSDA
4604
4605 /*!
4606  * Throws if a given value is not a valid (non-extended) relative dimension.
4607  *  \param [in] meshDimRelToMax - the relative dimension value.
4608  *  \throw If \a meshDimRelToMax > 0.
4609  */
4610 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
4611 {
4612   if(meshDimRelToMax>0)
4613     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4614 }
4615
4616 /*!
4617  * Checks if elements of a given mesh are in the order suitable for writing 
4618  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4619  * vector describing types of elements and their number.
4620  *  \param [in] mesh - the mesh to check.
4621  *  \return std::vector<int> - a vector holding for each element type (1) item of
4622  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4623  *          These values are in full-interlace mode.
4624  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4625  */
4626 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
4627 {
4628   if(!mesh)
4629     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4630   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4631   int nbOfTypes=geoTypes.size();
4632   std::vector<int> code(3*nbOfTypes);
4633   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4634   arr1->alloc(nbOfTypes,1);
4635   int *arrPtr=arr1->getPointer();
4636   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4637   for(int i=0;i<nbOfTypes;i++,it++)
4638     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4639   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4640   const int *arrPtr2=arr2->getConstPointer();
4641   int i=0;
4642   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4643     {
4644       int pos=arrPtr2[i];
4645       int nbCells=mesh->getNumberOfCellsWithType(*it);
4646       code[3*pos]=(int)(*it);
4647       code[3*pos+1]=nbCells;
4648       code[3*pos+2]=-1;//no profiles
4649     }
4650   std::vector<const DataArrayInt *> idsPerType;//no profiles
4651   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4652   if(da)
4653     {
4654       da->decrRef();
4655       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4656     }
4657   return code;
4658 }
4659
4660 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const char *fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4661 {
4662   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4663 }
4664
4665 /*!
4666  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4667  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4668  * item of every of returned sequences refers to the _i_-th part of \a this field.
4669  * Thus all sequences returned by this method are of the same length equal to number
4670  * of different types of supporting entities.<br>
4671  * A field part can include sub-parts with several different spatial discretizations,
4672  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4673  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4674  * of a nested sequence corresponds to a type of spatial discretization.<br>
4675  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4676  * The overhead is due to selecting values into new instances of DataArrayDouble.
4677  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4678  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4679  *          not checked if \a mname == \c NULL).
4680  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4681  *          a field part is returned. 
4682  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4683  *          A field part can include sub-parts with several different spatial discretizations,
4684  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4685  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4686  *          This sequence is of the same length as \a types. 
4687  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4688  *          discretization. A profile name can be empty.
4689  *          Length of this and of nested sequences is the same as that of \a typesF.
4690  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4691  *          discretization. A localization name can be empty.
4692  *          Length of this and of nested sequences is the same as that of \a typesF.
4693  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4694  *          per each type of spatial discretization within one mesh entity type.
4695  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4696  *          Length of this and of nested sequences is the same as that of \a typesF.
4697  *  \throw If no field is lying on \a mname.
4698  */
4699 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)
4700 {
4701   int meshId=0;
4702   if(mname)
4703     meshId=getMeshIdFromMeshName(mname);
4704   else
4705     if(_field_per_mesh.empty())
4706       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4707   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4708   int nbOfRet=ret0.size();
4709   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4710   for(int i=0;i<nbOfRet;i++)
4711     {
4712       const std::vector< std::pair<int,int> >& p=ret0[i];
4713       int nbOfRet1=p.size();
4714       ret[i].resize(nbOfRet1);
4715       for(int j=0;j<nbOfRet1;j++)
4716         {
4717           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4718           ret[i][j]=tmp;
4719         }
4720     }
4721   return ret;
4722 }
4723
4724 /*!
4725  * Returns a pointer to the underground DataArrayDouble instance. So the
4726  * caller should not decrRef() it. This method allows for a direct access to the field
4727  * values. This method is quite unusable if there is more than a nodal field or a cell
4728  * field on single geometric cell type. 
4729  *  \return DataArrayDouble * - the pointer to the field values array.
4730  */
4731 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const throw(INTERP_KERNEL::Exception)
4732 {
4733   const DataArrayDouble *ret=_arr;
4734   if(ret)
4735     return const_cast<DataArrayDouble *>(ret);
4736   else
4737     return 0;
4738 }
4739
4740 const char *MEDFileField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
4741 {
4742   return TYPE_STR;
4743 }
4744
4745 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const throw(INTERP_KERNEL::Exception)
4746 {
4747   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
4748   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4749   ret->deepCpyLeavesFrom(*this);
4750   const DataArrayDouble *arr(_arr);
4751   if(arr)
4752     {
4753       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
4754       ret->setArray(arr2);
4755     }
4756   return ret.retn();
4757 }
4758
4759 /*!
4760  * Returns a pointer to the underground DataArrayDouble instance. So the
4761  * caller should not decrRef() it. This method allows for a direct access to the field
4762  * values. This method is quite unusable if there is more than a nodal field or a cell
4763  * field on single geometric cell type. 
4764  *  \return DataArrayDouble * - the pointer to the field values array.
4765  */
4766 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4767 {
4768   return getUndergroundDataArrayDouble();
4769 }
4770
4771 /*!
4772  * Returns a pointer to the underground DataArrayDouble instance and a
4773  * sequence describing parameters of a support of each part of \a this field. The
4774  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4775  * direct access to the field values. This method is intended for the field lying on one
4776  * mesh only.
4777  *  \param [in,out] entries - the sequence describing parameters of a support of each
4778  *         part of \a this field. Each item of this sequence consists of two parts. The
4779  *         first part describes a type of mesh entity and an id of discretization of a
4780  *         current field part. The second part describes a range of values [begin,end)
4781  *         within the returned array relating to the current field part.
4782  *  \return DataArrayDouble * - the pointer to the field values array.
4783  *  \throw If the number of underlying meshes is not equal to 1.
4784  *  \throw If no field values are available.
4785  *  \sa getUndergroundDataArray()
4786  */
4787 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4788 {
4789   if(_field_per_mesh.size()!=1)
4790     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4791   if(_field_per_mesh[0]==0)
4792     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4793   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4794   return getUndergroundDataArrayDouble();
4795 }
4796
4797 /*!
4798  * Returns a pointer to the underground DataArrayDouble instance and a
4799  * sequence describing parameters of a support of each part of \a this field. The
4800  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4801  * direct access to the field values. This method is intended for the field lying on one
4802  * mesh only.
4803  *  \param [in,out] entries - the sequence describing parameters of a support of each
4804  *         part of \a this field. Each item of this sequence consists of two parts. The
4805  *         first part describes a type of mesh entity and an id of discretization of a
4806  *         current field part. The second part describes a range of values [begin,end)
4807  *         within the returned array relating to the current field part.
4808  *  \return DataArrayDouble * - the pointer to the field values array.
4809  *  \throw If the number of underlying meshes is not equal to 1.
4810  *  \throw If no field values are available.
4811  *  \sa getUndergroundDataArray()
4812  */
4813 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4814 {
4815   return getUndergroundDataArrayDoubleExt(entries);
4816 }
4817
4818 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order,
4819                                                      const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4820 {
4821   DataArrayDouble *arr=getOrCreateAndGetArrayDouble();
4822   arr->setInfoAndChangeNbOfCompo(infos);
4823 }
4824
4825 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4826 {
4827 }
4828
4829 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
4830 {
4831   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
4832   ret->deepCpyLeavesFrom(*this);
4833   return ret.retn();
4834 }
4835
4836 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
4837 {
4838   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
4839   if((const DataArrayDouble *)_arr)
4840     ret->_arr=_arr->deepCpy();
4841   return ret.retn();
4842 }
4843
4844 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
4845 {
4846   if(!arr)
4847     {
4848       _nb_of_tuples_to_be_allocated=-1;
4849       _arr=0;
4850       return ;
4851     }
4852   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
4853   if(!arrC)
4854     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
4855   else
4856     _nb_of_tuples_to_be_allocated=-3;
4857   arrC->incrRef();
4858   _arr=arrC;
4859 }
4860
4861 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4862 {
4863   return DataArrayDouble::New();
4864 }
4865
4866 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
4867 {
4868   DataArrayDouble *ret=_arr;
4869   if(ret)
4870     return ret;
4871   _arr=DataArrayDouble::New();
4872   return _arr;
4873 }
4874
4875 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
4876 {
4877   return getOrCreateAndGetArrayDouble();
4878 }
4879
4880 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
4881 {
4882   const DataArrayDouble *ret=_arr;
4883   if(ret)
4884     return ret;
4885   DataArrayDouble *ret2=DataArrayDouble::New();
4886   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
4887   return ret2;
4888 }
4889
4890 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
4891 {
4892   return getOrCreateAndGetArrayDouble();
4893 }
4894
4895 //= MEDFileIntField1TSWithoutSDA
4896
4897 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const char *fieldName, int csit, int iteration, int order,
4898                                                                 const std::vector<std::string>& infos)
4899 {
4900   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4901 }
4902
4903 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4904 {
4905 }
4906
4907 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order,
4908                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4909 {
4910   DataArrayInt *arr=getOrCreateAndGetArrayInt();
4911   arr->setInfoAndChangeNbOfCompo(infos);
4912 }
4913
4914 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
4915 {
4916   return TYPE_STR;
4917 }
4918
4919 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const throw(INTERP_KERNEL::Exception)
4920 {
4921   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
4922   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4923   ret->deepCpyLeavesFrom(*this);
4924   const DataArrayInt *arr(_arr);
4925   if(arr)
4926     {
4927       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
4928       ret->setArray(arr2);
4929     }
4930   return ret.retn();
4931 }
4932
4933 /*!
4934  * Returns a pointer to the underground DataArrayInt instance. So the
4935  * caller should not decrRef() it. This method allows for a direct access to the field
4936  * values. This method is quite unusable if there is more than a nodal field or a cell
4937  * field on single geometric cell type. 
4938  *  \return DataArrayInt * - the pointer to the field values array.
4939  */
4940 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4941 {
4942   return getUndergroundDataArrayInt();
4943 }
4944
4945 /*!
4946  * Returns a pointer to the underground DataArrayInt instance. So the
4947  * caller should not decrRef() it. This method allows for a direct access to the field
4948  * values. This method is quite unusable if there is more than a nodal field or a cell
4949  * field on single geometric cell type. 
4950  *  \return DataArrayInt * - the pointer to the field values array.
4951  */
4952 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const throw(INTERP_KERNEL::Exception)
4953 {
4954   const DataArrayInt *ret=_arr;
4955   if(ret)
4956     return const_cast<DataArrayInt *>(ret);
4957   else
4958     return 0;
4959 }
4960
4961 /*!
4962  * Returns a pointer to the underground DataArrayInt instance and a
4963  * sequence describing parameters of a support of each part of \a this field. The
4964  * caller should not decrRef() the returned DataArrayInt. This method allows for a
4965  * direct access to the field values. This method is intended for the field lying on one
4966  * mesh only.
4967  *  \param [in,out] entries - the sequence describing parameters of a support of each
4968  *         part of \a this field. Each item of this sequence consists of two parts. The
4969  *         first part describes a type of mesh entity and an id of discretization of a
4970  *         current field part. The second part describes a range of values [begin,end)
4971  *         within the returned array relating to the current field part.
4972  *  \return DataArrayInt * - the pointer to the field values array.
4973  *  \throw If the number of underlying meshes is not equal to 1.
4974  *  \throw If no field values are available.
4975  *  \sa getUndergroundDataArray()
4976  */
4977 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4978 {
4979   return getUndergroundDataArrayIntExt(entries);
4980 }
4981
4982 /*!
4983  * Returns a pointer to the underground DataArrayInt instance and a
4984  * sequence describing parameters of a support of each part of \a this field. The
4985  * caller should not decrRef() the returned DataArrayInt. This method allows for a
4986  * direct access to the field values. This method is intended for the field lying on one
4987  * mesh only.
4988  *  \param [in,out] entries - the sequence describing parameters of a support of each
4989  *         part of \a this field. Each item of this sequence consists of two parts. The
4990  *         first part describes a type of mesh entity and an id of discretization of a
4991  *         current field part. The second part describes a range of values [begin,end)
4992  *         within the returned array relating to the current field part.
4993  *  \return DataArrayInt * - the pointer to the field values array.
4994  *  \throw If the number of underlying meshes is not equal to 1.
4995  *  \throw If no field values are available.
4996  *  \sa getUndergroundDataArray()
4997  */
4998 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4999 {
5000   if(_field_per_mesh.size()!=1)
5001     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5002   if(_field_per_mesh[0]==0)
5003     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5004   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5005   return getUndergroundDataArrayInt();
5006 }
5007
5008 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
5009 {
5010   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5011   ret->deepCpyLeavesFrom(*this);
5012   return ret.retn();
5013 }
5014
5015 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
5016 {
5017   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5018   if((const DataArrayInt *)_arr)
5019     ret->_arr=_arr->deepCpy();
5020   return ret.retn();
5021 }
5022
5023 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr) throw(INTERP_KERNEL::Exception)
5024 {
5025   if(!arr)
5026     {
5027       _nb_of_tuples_to_be_allocated=-1;
5028       _arr=0;
5029       return ;
5030     }
5031   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5032   if(!arrC)
5033     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5034   else
5035     _nb_of_tuples_to_be_allocated=-3;
5036   arrC->incrRef();
5037   _arr=arrC;
5038 }
5039
5040 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5041 {
5042   return DataArrayInt::New();
5043 }
5044
5045 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5046 {
5047   DataArrayInt *ret=_arr;
5048   if(ret)
5049     return ret;
5050   _arr=DataArrayInt::New();
5051   return _arr;
5052 }
5053
5054 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5055 {
5056   return getOrCreateAndGetArrayInt();
5057 }
5058
5059 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5060 {
5061   const DataArrayInt *ret=_arr;
5062   if(ret)
5063     return ret;
5064   DataArrayInt *ret2=DataArrayInt::New();
5065   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5066   return ret2;
5067 }
5068
5069 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5070 {
5071   return getOrCreateAndGetArrayInt();
5072 }
5073
5074 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5075 {
5076 }
5077
5078 //= MEDFileAnyTypeField1TS
5079
5080 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5081 {
5082   med_field_type typcha;
5083   //
5084   std::vector<std::string> infos;
5085   std::string dtunit,fieldName;
5086   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5087   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5088   switch(typcha)
5089     {
5090     case MED_FLOAT64:
5091       {
5092         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5093         break;
5094       }
5095     case MED_INT32:
5096       {
5097         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5098         break;
5099       }
5100     default:
5101       {
5102         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] !";
5103         throw INTERP_KERNEL::Exception(oss.str().c_str());
5104       }
5105     }
5106   ret->setDtUnit(dtunit.c_str());
5107   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5108   //
5109   med_int numdt,numit;
5110   med_float dt;
5111   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5112   ret->setTime(numdt,numit,dt);
5113   ret->_csit=1;
5114   if(loadAll)
5115     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5116   else
5117     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5118   return ret.retn();
5119 }
5120
5121 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5122 try:MEDFileFieldGlobsReal(fileName)
5123 {
5124   MEDFileUtilities::CheckFileForRead(fileName);
5125   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5126   _content=BuildContentFrom(fid,fileName,loadAll);
5127   loadGlobals(fid);
5128 }
5129 catch(INTERP_KERNEL::Exception& e)
5130   {
5131     throw e;
5132   }
5133
5134 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5135 {
5136   med_field_type typcha;
5137   std::vector<std::string> infos;
5138   std::string dtunit;
5139   int iii=-1;
5140   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5141   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5142   switch(typcha)
5143     {
5144     case MED_FLOAT64:
5145       {
5146         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5147         break;
5148       }
5149     case MED_INT32:
5150       {
5151         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5152         break;
5153       }
5154     default:
5155       {
5156         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] !";
5157         throw INTERP_KERNEL::Exception(oss.str().c_str());
5158       }
5159     }
5160   ret->setDtUnit(dtunit.c_str());
5161   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5162   //
5163   if(nbSteps<1)
5164     {
5165       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5166       throw INTERP_KERNEL::Exception(oss.str().c_str());
5167     }
5168   //
5169   med_int numdt,numit;
5170   med_float dt;
5171   MEDfieldComputingStepInfo(fid,fieldName,1,&numdt,&numit,&dt);
5172   ret->setTime(numdt,numit,dt);
5173   ret->_csit=1;
5174   if(loadAll)
5175     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5176   else
5177     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5178   return ret.retn();
5179 }
5180
5181 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5182 try:MEDFileFieldGlobsReal(fileName)
5183 {
5184   MEDFileUtilities::CheckFileForRead(fileName);
5185   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5186   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
5187   loadGlobals(fid);
5188 }
5189 catch(INTERP_KERNEL::Exception& e)
5190   {
5191     throw e;
5192   }
5193
5194 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const char *fileName) throw(INTERP_KERNEL::Exception)
5195 {
5196   if(!c)
5197     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5198   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5199     {
5200       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5201       ret->setFileName(fileName);
5202       ret->_content=c; c->incrRef();
5203       return ret.retn();
5204     }
5205   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5206     {
5207       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5208       ret->setFileName(fileName);
5209       ret->_content=c; c->incrRef();
5210       return ret.retn();
5211     }
5212   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5213 }
5214
5215 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5216 {
5217   MEDFileUtilities::CheckFileForRead(fileName);
5218   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5219   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
5220   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5221   ret->loadGlobals(fid);
5222   return ret.retn();
5223 }
5224
5225 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5226 {
5227   MEDFileUtilities::CheckFileForRead(fileName);
5228   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5229   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
5230   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5231   ret->loadGlobals(fid);
5232   return ret.retn();
5233 }
5234
5235 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5236 {
5237   MEDFileUtilities::CheckFileForRead(fileName);
5238   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5239   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll);
5240   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5241   ret->loadGlobals(fid);
5242   return ret.retn();
5243 }
5244
5245 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5246 {
5247   med_field_type typcha;
5248   std::vector<std::string> infos;
5249   std::string dtunit;
5250   int iii=-1;
5251   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5252   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5253   switch(typcha)
5254     {
5255     case MED_FLOAT64:
5256       {
5257         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5258         break;
5259       }
5260     case MED_INT32:
5261       {
5262         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5263         break;
5264       }
5265     default:
5266       {
5267         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] !";
5268         throw INTERP_KERNEL::Exception(oss.str().c_str());
5269       }
5270     }
5271   ret->setDtUnit(dtunit.c_str());
5272   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5273   //
5274   bool found=false;
5275   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5276   for(int i=0;i<nbOfStep2 && !found;i++)
5277     {
5278       med_int numdt,numit;
5279       med_float dt;
5280       MEDfieldComputingStepInfo(fid,fieldName,i+1,&numdt,&numit,&dt);
5281       if(numdt==iteration && numit==order)
5282         {
5283           found=true;
5284           ret->_csit=i+1;
5285         }
5286       else
5287         dtits[i]=std::pair<int,int>(numdt,numit);
5288     }
5289   if(!found)
5290     {
5291       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5292       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5293         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5294       throw INTERP_KERNEL::Exception(oss.str().c_str());
5295     }
5296   if(loadAll)
5297     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5298   else
5299     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5300   return ret.retn();
5301 }
5302
5303 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5304 try:MEDFileFieldGlobsReal(fileName)
5305 {
5306   MEDFileUtilities::CheckFileForRead(fileName);
5307   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5308   _content=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll);
5309   loadGlobals(fid);
5310 }
5311 catch(INTERP_KERNEL::Exception& e)
5312   {
5313     throw e;
5314   }
5315
5316 /*!
5317  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5318  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5319  *
5320  * \warning this is a shallow copy constructor
5321  */
5322 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5323 {
5324   if(!shallowCopyOfContent)
5325     {
5326       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5327       otherPtr->incrRef();
5328       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5329     }
5330   else
5331     {
5332       _content=other.shallowCpy();
5333     }
5334 }
5335
5336 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)
5337 {
5338   if(checkFieldId)
5339     {
5340       int nbFields=MEDnField(fid);
5341       if(fieldIdCFormat>=nbFields)
5342         {
5343           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5344           throw INTERP_KERNEL::Exception(oss.str().c_str());
5345         }
5346     }
5347   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5348   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5349   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5350   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5351   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5352   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5353   med_bool localMesh;
5354   int nbOfStep;
5355   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5356   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5357   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5358   infos.clear(); infos.resize(ncomp);
5359   for(int j=0;j<ncomp;j++)
5360     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5361   return nbOfStep;
5362 }
5363
5364 /*!
5365  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5366  * 
5367  * \param [out]
5368  * \return in case of success the number of time steps available for the field with name \a fieldName.
5369  */
5370 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)
5371 {
5372   int nbFields=MEDnField(fid);
5373   bool found=false;
5374   std::vector<std::string> fns(nbFields);
5375   int nbOfStep2=-1;
5376   for(int i=0;i<nbFields && !found;i++)
5377     {
5378       std::string tmp;
5379       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5380       fns[i]=tmp;
5381       found=(tmp==fieldName);
5382       if(found)
5383         posCFormat=i;
5384     }
5385   if(!found)
5386     {
5387       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5388       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5389         oss << "\"" << *it << "\" ";
5390       throw INTERP_KERNEL::Exception(oss.str().c_str());
5391     }
5392   return nbOfStep2;
5393 }
5394
5395 /*!
5396  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5397  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5398  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5399  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5400  * to keep a valid instance.
5401  * 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.
5402  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5403  * 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.
5404  *
5405  * \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.
5406  * \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.
5407  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5408  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5409  * \param [in] newLocName is the new localization name.
5410  * \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.
5411  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5412  */
5413 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newPflName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
5414 {
5415   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5416   std::string oldPflName=disc->getProfile();
5417   std::vector<std::string> vv=getPflsReallyUsedMulti();
5418   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5419   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5420     {
5421       disc->setProfile(newPflName);
5422       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5423       pfl->setName(newPflName);
5424     }
5425   else
5426     {
5427       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5428       throw INTERP_KERNEL::Exception(oss.str().c_str());
5429     }
5430 }
5431
5432 /*!
5433  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5434  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5435  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5436  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5437  * to keep a valid instance.
5438  * 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.
5439  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5440  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5441  * 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.
5442  *
5443  * \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.
5444  * \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.
5445  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5446  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5447  * \param [in] newLocName is the new localization name.
5448  * \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.
5449  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5450  */
5451 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newLocName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
5452 {
5453   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5454   std::string oldLocName=disc->getLocalization();
5455   std::vector<std::string> vv=getLocsReallyUsedMulti();
5456   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5457   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5458     {
5459       disc->setLocalization(newLocName);
5460       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5461       loc.setName(newLocName);
5462     }
5463   else
5464     {
5465       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5466       throw INTERP_KERNEL::Exception(oss.str().c_str());
5467     }
5468 }
5469
5470 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() throw(INTERP_KERNEL::Exception)
5471 {
5472   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5473   if(!ret)
5474     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5475   return ret;
5476 }
5477
5478 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const throw(INTERP_KERNEL::Exception)
5479 {
5480   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5481   if(!ret)
5482     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5483   return ret;
5484 }
5485
5486 /*!
5487  * Writes \a this field into a MED file specified by its name.
5488  *  \param [in] fileName - the MED file name.
5489  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5490  * - 2 - erase; an existing file is removed.
5491  * - 1 - append; same data should not be present in an existing file.
5492  * - 0 - overwrite; same data present in an existing file is overwritten.
5493  *  \throw If the field name is not set.
5494  *  \throw If no field data is set.
5495  *  \throw If \a mode == 1 and the same data is present in an existing file.
5496  */
5497 void MEDFileAnyTypeField1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
5498 {
5499   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5500   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
5501   writeLL(fid);
5502 }
5503
5504 /*!
5505  * This method alloc the arrays and load potentially huge arrays contained in this field.
5506  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5507  * This method can be also called to refresh or reinit values from a file.
5508  * 
5509  * \throw If the fileName is not set or points to a non readable MED file.
5510  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5511  */
5512 void MEDFileAnyTypeField1TS::loadArrays() throw(INTERP_KERNEL::Exception)
5513 {
5514   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
5515   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5516 }
5517
5518 /*!
5519  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5520  * But once data loaded once, this method does nothing.
5521  * 
5522  * \throw If the fileName is not set or points to a non readable MED file.
5523  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::releaseArrays
5524  */
5525 void MEDFileAnyTypeField1TS::loadArraysIfNecessary() throw(INTERP_KERNEL::Exception)
5526 {
5527   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
5528   contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5529 }
5530
5531 /*!
5532  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5533  * This method does not release arrays set outside the context of a MED file.
5534  * 
5535  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary
5536  */
5537 void MEDFileAnyTypeField1TS::releaseArrays() throw(INTERP_KERNEL::Exception)
5538 {
5539   contentNotNullBase()->releaseArrays();
5540 }
5541
5542 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
5543 {
5544   int nbComp=getNumberOfComponents();
5545   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5546   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5547   for(int i=0;i<nbComp;i++)
5548     {
5549       std::string info=getInfo()[i];
5550       std::string c,u;
5551       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5552       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5553       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5554     }
5555   if(getName().empty())
5556     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5557   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5558   writeGlobals(fid,*this);
5559   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5560 }
5561
5562 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySize() const
5563 {
5564   std::size_t ret=0;
5565   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5566     ret+=_content->getHeapMemorySize();
5567   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
5568 }
5569
5570 /*!
5571  * Returns a string describing \a this field. This string is outputted 
5572  * by \c print Python command.
5573  */
5574 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5575 {
5576   std::ostringstream oss;
5577   contentNotNullBase()->simpleRepr(0,oss,-1);
5578   simpleReprGlobs(oss);
5579   return oss.str();
5580 }
5581
5582 /*!
5583  * This method returns all profiles whose name is non empty used.
5584  * \b WARNING If profile is used several times it will be reported \b only \b once.
5585  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5586  */
5587 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5588 {
5589   return contentNotNullBase()->getPflsReallyUsed2();
5590 }
5591
5592 /*!
5593  * This method returns all localizations whose name is non empty used.
5594  * \b WARNING If localization is used several times it will be reported \b only \b once.
5595  */
5596 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5597 {
5598   return contentNotNullBase()->getLocsReallyUsed2();
5599 }
5600
5601 /*!
5602  * This method returns all profiles whose name is non empty used.
5603  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5604  */
5605 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5606 {
5607   return contentNotNullBase()->getPflsReallyUsedMulti2();
5608 }
5609
5610 /*!
5611  * This method returns all localizations whose name is non empty used.
5612  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5613  */
5614 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5615 {
5616   return contentNotNullBase()->getLocsReallyUsedMulti2();
5617 }
5618
5619 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5620 {
5621   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5622 }
5623
5624 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5625 {
5626   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5627 }
5628
5629 int MEDFileAnyTypeField1TS::getDimension() const
5630 {
5631   return contentNotNullBase()->getDimension();
5632 }
5633
5634 int MEDFileAnyTypeField1TS::getIteration() const
5635 {
5636   return contentNotNullBase()->getIteration();
5637 }
5638
5639 int MEDFileAnyTypeField1TS::getOrder() const
5640 {
5641   return contentNotNullBase()->getOrder();
5642 }
5643
5644 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5645 {
5646   return contentNotNullBase()->getTime(iteration,order);
5647 }
5648
5649 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5650 {
5651   contentNotNullBase()->setTime(iteration,order,val);
5652 }
5653
5654 std::string MEDFileAnyTypeField1TS::getName() const
5655 {
5656   return contentNotNullBase()->getName();
5657 }
5658
5659 void MEDFileAnyTypeField1TS::setName(const char *name)
5660 {
5661   contentNotNullBase()->setName(name);
5662 }
5663
5664 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5665 {
5666   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5667 }
5668
5669 std::string MEDFileAnyTypeField1TS::getDtUnit() const throw(INTERP_KERNEL::Exception)
5670 {
5671   return contentNotNullBase()->getDtUnit();
5672 }
5673
5674 void MEDFileAnyTypeField1TS::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
5675 {
5676   contentNotNullBase()->setDtUnit(dtUnit);
5677 }
5678
5679 std::string MEDFileAnyTypeField1TS::getMeshName() const throw(INTERP_KERNEL::Exception)
5680 {
5681   return contentNotNullBase()->getMeshName();
5682 }
5683
5684 void MEDFileAnyTypeField1TS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
5685 {
5686   contentNotNullBase()->setMeshName(newMeshName);
5687 }
5688
5689 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
5690 {
5691   return contentNotNullBase()->changeMeshNames(modifTab);
5692 }
5693
5694 int MEDFileAnyTypeField1TS::getMeshIteration() const throw(INTERP_KERNEL::Exception)
5695 {
5696   return contentNotNullBase()->getMeshIteration();
5697 }
5698
5699 int MEDFileAnyTypeField1TS::getMeshOrder() const throw(INTERP_KERNEL::Exception)
5700 {
5701   return contentNotNullBase()->getMeshOrder();
5702 }
5703
5704 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5705 {
5706   return contentNotNullBase()->getNumberOfComponents();
5707 }
5708
5709 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5710 {
5711   return contentNotNullBase()->isDealingTS(iteration,order);
5712 }
5713
5714 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5715 {
5716   return contentNotNullBase()->getDtIt();
5717 }
5718
5719 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5720 {
5721   contentNotNullBase()->fillIteration(p);
5722 }
5723
5724 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
5725 {
5726   contentNotNullBase()->fillTypesOfFieldAvailable(types);
5727 }
5728
5729 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
5730 {
5731   contentNotNullBase()->setInfo(infos);
5732 }
5733
5734 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
5735 {
5736   return contentNotNullBase()->getInfo();
5737 }
5738 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
5739 {
5740   return contentNotNullBase()->getInfo();
5741 }
5742
5743 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
5744 {
5745   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5746 }
5747
5748 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
5749 {
5750   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5751 }
5752
5753 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
5754 {
5755   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
5756 }
5757
5758 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
5759 {
5760   return contentNotNullBase()->getTypesOfFieldAvailable();
5761 }
5762
5763 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,
5764                                                                                        std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
5765 {
5766   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5767 }
5768
5769 /*!
5770  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
5771  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5772  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
5773  */
5774 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const throw(INTERP_KERNEL::Exception)
5775 {
5776   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5777   if(!content)
5778     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
5779   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
5780   std::size_t sz(contentsSplit.size());
5781   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5782   for(std::size_t i=0;i<sz;i++)
5783     {
5784       ret[i]=shallowCpy();
5785       ret[i]->_content=contentsSplit[i];
5786     }
5787   return ret;
5788 }
5789
5790 /*!
5791  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
5792  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5793  */
5794 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const throw(INTERP_KERNEL::Exception)
5795 {
5796   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5797   if(!content)
5798     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
5799   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitDiscretizations();
5800   std::size_t sz(contentsSplit.size());
5801   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5802   for(std::size_t i=0;i<sz;i++)
5803     {
5804       ret[i]=shallowCpy();
5805       ret[i]->_content=contentsSplit[i];
5806     }
5807   return ret;
5808 }
5809
5810 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const throw(INTERP_KERNEL::Exception)
5811 {
5812   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
5813   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5814     ret->_content=_content->deepCpy();
5815   ret->deepCpyGlobs(*this);
5816   return ret.retn();
5817 }
5818
5819 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
5820 {
5821   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
5822 }
5823
5824 //= MEDFileField1TS
5825
5826 /*!
5827  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5828  * the first field that has been read from a specified MED file.
5829  *  \param [in] fileName - the name of the MED file to read.
5830  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5831  *          is to delete this field using decrRef() as it is no more needed.
5832  *  \throw If reading the file fails.
5833  */
5834 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5835 {
5836   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,loadAll);
5837   ret->contentNotNull();
5838   return ret.retn();
5839 }
5840
5841 /*!
5842  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5843  * a given field that has been read from a specified MED file.
5844  *  \param [in] fileName - the name of the MED file to read.
5845  *  \param [in] fieldName - the name of the field to read.
5846  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5847  *          is to delete this field using decrRef() as it is no more needed.
5848  *  \throw If reading the file fails.
5849  *  \throw If there is no field named \a fieldName in the file.
5850  */
5851 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5852 {
5853   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,loadAll);
5854   ret->contentNotNull();
5855   return ret.retn();
5856 }
5857
5858 /*!
5859  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
5860  * a given field that has been read from a specified MED file.
5861  *  \param [in] fileName - the name of the MED file to read.
5862  *  \param [in] fieldName - the name of the field to read.
5863  *  \param [in] iteration - the iteration number of a required time step.
5864  *  \param [in] order - the iteration order number of required time step.
5865  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5866  *          is to delete this field using decrRef() as it is no more needed.
5867  *  \throw If reading the file fails.
5868  *  \throw If there is no field named \a fieldName in the file.
5869  *  \throw If the required time step is missing from the file.
5870  */
5871 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5872 {
5873   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll);
5874   ret->contentNotNull();
5875   return ret.retn();
5876 }
5877
5878 /*!
5879  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5880  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5881  *
5882  * Returns a new instance of MEDFileField1TS holding either a shallow copy
5883  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
5884  * \warning this is a shallow copy constructor
5885  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
5886  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
5887  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5888  *          is to delete this field using decrRef() as it is no more needed.
5889  */
5890 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
5891 {
5892   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
5893   ret->contentNotNull();
5894   return ret.retn();
5895 }
5896
5897 /*!
5898  * Returns a new empty instance of MEDFileField1TS.
5899  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5900  *          is to delete this field using decrRef() as it is no more needed.
5901  */
5902 MEDFileField1TS *MEDFileField1TS::New()
5903 {
5904   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
5905   ret->contentNotNull();
5906   return ret.retn();
5907 }
5908
5909 /*!
5910  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
5911  * following the given input policy.
5912  *
5913  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
5914  *                            By default (true) the globals are deeply copied.
5915  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
5916  */
5917 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
5918 {
5919   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
5920   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5921   if(content)
5922     {
5923       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
5924       if(!contc)
5925         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
5926       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
5927       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
5928     }
5929   else
5930     ret=MEDFileIntField1TS::New();
5931   if(deepCpyGlobs)
5932     ret->deepCpyGlobs(*this);
5933   else
5934     ret->shallowCpyGlobs(*this);
5935   return ret.retn();
5936 }
5937
5938 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const throw(INTERP_KERNEL::Exception)
5939 {
5940   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
5941   if(!pt)
5942     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
5943   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
5944   if(!ret)
5945     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 !");
5946   return ret;
5947 }
5948
5949 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() throw(INTERP_KERNEL::Exception)
5950 {
5951   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
5952   if(!pt)
5953     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
5954   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
5955   if(!ret)
5956     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 !");
5957   return ret;
5958 }
5959
5960 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
5961 {
5962   if(!f)
5963     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
5964   if(!((DataArray*)arr))
5965     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
5966   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
5967   if(!arrOutC)
5968     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
5969   f->setArray(arrOutC);
5970 }
5971
5972 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
5973 {
5974   if(!((DataArray*)arr))
5975     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
5976   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
5977   if(!arrOutC)
5978     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
5979   arrOutC->incrRef();
5980   return arrOutC;
5981 }
5982
5983 MEDFileField1TS::MEDFileField1TS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
5984 try:MEDFileAnyTypeField1TS(fileName,loadAll)
5985 {
5986 }
5987 catch(INTERP_KERNEL::Exception& e)
5988   { throw e; }
5989
5990 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
5991 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
5992 {
5993 }
5994 catch(INTERP_KERNEL::Exception& e)
5995   { throw e; }
5996
5997 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
5998 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
5999 {
6000 }
6001 catch(INTERP_KERNEL::Exception& e)
6002   { throw e; }
6003
6004 /*!
6005  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6006  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6007  *
6008  * \warning this is a shallow copy constructor
6009  */
6010 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6011 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6012 {
6013 }
6014 catch(INTERP_KERNEL::Exception& e)
6015   { throw e; }
6016
6017 MEDFileField1TS::MEDFileField1TS()
6018 {
6019   _content=new MEDFileField1TSWithoutSDA;
6020 }
6021
6022 /*!
6023  * Returns a new MEDCouplingFieldDouble of a given type lying on
6024  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6025  * has not been constructed via file reading, an exception is thrown.
6026  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6027  *  \param [in] type - a spatial discretization of interest.
6028  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6029  *  \param [in] renumPol - specifies how to permute values of the result field according to
6030  *          the optional numbers of cells and nodes, if any. The valid values are
6031  *          - 0 - do not permute.
6032  *          - 1 - permute cells.
6033  *          - 2 - permute nodes.
6034  *          - 3 - permute cells and nodes.
6035  *
6036  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6037  *          caller is to delete this field using decrRef() as it is no more needed. 
6038  *  \throw If \a this field has not been constructed via file reading.
6039  *  \throw If the MED file is not readable.
6040  *  \throw If there is no mesh in the MED file.
6041  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6042  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6043  *  \sa getFieldOnMeshAtLevel()
6044  */
6045 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
6046 {
6047   if(getFileName2().empty())
6048     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6049   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6050   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut,*contentNotNull());
6051   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6052   return ret.retn();
6053 }
6054
6055 /*!
6056  * Returns a new MEDCouplingFieldDouble of a given type lying on
6057  * the top level cells of the first mesh in MED file. If \a this field 
6058  * has not been constructed via file reading, an exception is thrown.
6059  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6060  *  \param [in] type - a spatial discretization of interest.
6061  *  \param [in] renumPol - specifies how to permute values of the result field according to
6062  *          the optional numbers of cells and nodes, if any. The valid values are
6063  *          - 0 - do not permute.
6064  *          - 1 - permute cells.
6065  *          - 2 - permute nodes.
6066  *          - 3 - permute cells and nodes.
6067  *
6068  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6069  *          caller is to delete this field using decrRef() as it is no more needed. 
6070  *  \throw If \a this field has not been constructed via file reading.
6071  *  \throw If the MED file is not readable.
6072  *  \throw If there is no mesh in the MED file.
6073  *  \throw If no field values of the given \a type.
6074  *  \throw If no field values lying on the top level support.
6075  *  \sa getFieldAtLevel()
6076  */
6077 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const throw(INTERP_KERNEL::Exception)
6078 {
6079   if(getFileName2().empty())
6080     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6081   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6082   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,0,renumPol,this,arrOut,*contentNotNull());
6083   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6084   return ret.retn();
6085 }
6086
6087 /*!
6088  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6089  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6090  *  \param [in] type - a spatial discretization of the new field.
6091  *  \param [in] mesh - the supporting mesh.
6092  *  \param [in] renumPol - specifies how to permute values of the result field according to
6093  *          the optional numbers of cells and nodes, if any. The valid values are
6094  *          - 0 - do not permute.
6095  *          - 1 - permute cells.
6096  *          - 2 - permute nodes.
6097  *          - 3 - permute cells and nodes.
6098  *
6099  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6100  *          caller is to delete this field using decrRef() as it is no more needed. 
6101  *  \throw If no field of \a this is lying on \a mesh.
6102  *  \throw If the mesh is empty.
6103  *  \throw If no field values of the given \a type are available.
6104  *  \sa getFieldAtLevel()
6105  *  \sa getFieldOnMeshAtLevel() 
6106  */
6107 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
6108 {
6109   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6110   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6111   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6112   return ret.retn();
6113 }
6114
6115 /*!
6116  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6117  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6118  *  \param [in] type - a spatial discretization of interest.
6119  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6120  *  \param [in] mesh - the supporting mesh.
6121  *  \param [in] renumPol - specifies how to permute values of the result field according to
6122  *          the optional numbers of cells and nodes, if any. The valid values are
6123  *          - 0 - do not permute.
6124  *          - 1 - permute cells.
6125  *          - 2 - permute nodes.
6126  *          - 3 - permute cells and nodes.
6127  *
6128  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6129  *          caller is to delete this field using decrRef() as it is no more needed. 
6130  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6131  *  \throw If no field of \a this is lying on \a mesh.
6132  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6133  *  \sa getFieldAtLevel()
6134  *  \sa getFieldOnMeshAtLevel() 
6135  */
6136 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
6137 {
6138   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6139   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6140   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6141   return ret.retn();
6142 }
6143
6144 /*!
6145  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6146  * This method is called "Old" because in MED3 norm a field has only one meshName
6147  * attached, so this method is for readers of MED2 files. If \a this field 
6148  * has not been constructed via file reading, an exception is thrown.
6149  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6150  *  \param [in] type - a spatial discretization of interest.
6151  *  \param [in] mName - a name of the supporting mesh.
6152  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6153  *  \param [in] renumPol - specifies how to permute values of the result field according to
6154  *          the optional numbers of cells and nodes, if any. The valid values are
6155  *          - 0 - do not permute.
6156  *          - 1 - permute cells.
6157  *          - 2 - permute nodes.
6158  *          - 3 - permute cells and nodes.
6159  *
6160  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6161  *          caller is to delete this field using decrRef() as it is no more needed. 
6162  *  \throw If the MED file is not readable.
6163  *  \throw If there is no mesh named \a mName in the MED file.
6164  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6165  *  \throw If \a this field has not been constructed via file reading.
6166  *  \throw If no field of \a this is lying on the mesh named \a mName.
6167  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6168  *  \sa getFieldAtLevel()
6169  */
6170 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
6171 {
6172   if(getFileName2().empty())
6173     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6174   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6175   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6176   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6177   return ret.retn();
6178 }
6179
6180 /*!
6181  * Returns values and a profile of the field of a given type lying on a given support.
6182  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6183  *  \param [in] type - a spatial discretization of the field.
6184  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6185  *  \param [in] mesh - the supporting mesh.
6186  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6187  *          field of interest lies on. If the field lies on all entities of the given
6188  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6189  *          using decrRef() as it is no more needed.  
6190  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6191  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6192  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6193  *  \throw If no field of \a this is lying on \a mesh.
6194  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6195  */
6196 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
6197 {
6198   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6199   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6200 }
6201
6202 /*!
6203  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6204  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6205  * "Sort By Type"), if not, an exception is thrown. 
6206  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6207  *  \param [in] field - the field to add to \a this.
6208  *  \throw If the name of \a field is empty.
6209  *  \throw If the data array of \a field is not set.
6210  *  \throw If the data array is already allocated but has different number of components
6211  *         than \a field.
6212  *  \throw If the underlying mesh of \a field has no name.
6213  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6214  */
6215 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
6216 {
6217   setFileName("");
6218   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6219 }
6220
6221 /*!
6222  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6223  * can be an aggregation of several MEDCouplingFieldDouble instances.
6224  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6225  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6226  * and \a profile.
6227  *
6228  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6229  * A new profile is added only if no equal profile is missing.
6230  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6231  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6232  *  \param [in] mesh - the supporting mesh of \a field.
6233  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6234  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6235  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6236  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6237  *  \throw If the data array of \a field is not set.
6238  *  \throw If the data array of \a this is already allocated but has different number of
6239  *         components than \a field.
6240  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6241  *  \sa setFieldNoProfileSBT()
6242  */
6243 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
6244 {
6245   setFileName("");
6246   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6247 }
6248
6249 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const throw(INTERP_KERNEL::Exception)
6250 {
6251   return new MEDFileField1TS(*this);
6252 }
6253
6254 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
6255 {
6256   return contentNotNull()->getUndergroundDataArrayDouble();
6257 }
6258
6259 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
6260 {
6261   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6262 }
6263
6264 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6265                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
6266 {
6267   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6268 }
6269
6270 //= MEDFileIntField1TS
6271
6272 MEDFileIntField1TS *MEDFileIntField1TS::New()
6273 {
6274   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6275   ret->contentNotNull();
6276   return ret.retn();
6277 }
6278
6279 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
6280 {
6281   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,loadAll);
6282   ret->contentNotNull();
6283   return ret.retn();
6284 }
6285
6286 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
6287 {
6288   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,loadAll);
6289   ret->contentNotNull();
6290   return ret.retn();
6291 }
6292
6293 MEDFileIntField1TS *MEDFileIntField1TS::New(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
6294 {
6295   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll);
6296   ret->contentNotNull();
6297   return ret.retn();
6298 }
6299
6300 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6301 {
6302   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6303   ret->contentNotNull();
6304   return ret.retn();
6305 }
6306
6307 MEDFileIntField1TS::MEDFileIntField1TS()
6308 {
6309   _content=new MEDFileIntField1TSWithoutSDA;
6310 }
6311
6312 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
6313 try:MEDFileAnyTypeField1TS(fileName,loadAll)
6314 {
6315 }
6316 catch(INTERP_KERNEL::Exception& e)
6317   { throw e; }
6318
6319 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
6320 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
6321 {
6322 }
6323 catch(INTERP_KERNEL::Exception& e)
6324   { throw e; }
6325
6326 MEDFileIntField1TS::MEDFileIntField1TS(const char *fileName, const char *fieldName, int iteration, int order, bool loadAll) throw(INTERP_KERNEL::Exception)
6327 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
6328 {
6329 }
6330 catch(INTERP_KERNEL::Exception& e)
6331   { throw e; }
6332
6333 /*!
6334  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6335  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6336  *
6337  * \warning this is a shallow copy constructor
6338  */
6339 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6340 {
6341 }
6342
6343 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const throw(INTERP_KERNEL::Exception)
6344 {
6345   return new MEDFileIntField1TS(*this);
6346 }
6347
6348 /*!
6349  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6350  * following the given input policy.
6351  *
6352  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6353  *                            By default (true) the globals are deeply copied.
6354  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6355  */
6356 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
6357 {
6358   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6359   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6360   if(content)
6361     {
6362       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6363       if(!contc)
6364         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6365       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6366       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6367     }
6368   else
6369     ret=MEDFileField1TS::New();
6370   if(deepCpyGlobs)
6371     ret->deepCpyGlobs(*this);
6372   else
6373     ret->shallowCpyGlobs(*this);
6374   return ret.retn();
6375 }
6376
6377 /*!
6378  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6379  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6380  * "Sort By Type"), if not, an exception is thrown. 
6381  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6382  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6383  *  \param [in] arrOfVals - the values of the field \a field used.
6384  *  \throw If the name of \a field is empty.
6385  *  \throw If the data array of \a field is not set.
6386  *  \throw If the data array is already allocated but has different number of components
6387  *         than \a field.
6388  *  \throw If the underlying mesh of \a field has no name.
6389  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6390  */
6391 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception)
6392 {
6393   setFileName("");
6394   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6395 }
6396
6397 /*!
6398  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6399  * can be an aggregation of several MEDCouplingFieldDouble instances.
6400  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6401  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6402  * and \a profile.
6403  *
6404  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6405  * A new profile is added only if no equal profile is missing.
6406  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6407  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6408  *  \param [in] arrOfVals - the values of the field \a field used.
6409  *  \param [in] mesh - the supporting mesh of \a field.
6410  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6411  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6412  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6413  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6414  *  \throw If the data array of \a field is not set.
6415  *  \throw If the data array of \a this is already allocated but has different number of
6416  *         components than \a field.
6417  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6418  *  \sa setFieldNoProfileSBT()
6419  */
6420 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
6421 {
6422   setFileName("");
6423   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6424 }
6425
6426 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const throw(INTERP_KERNEL::Exception)
6427 {
6428   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6429   if(!pt)
6430     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6431   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6432   if(!ret)
6433     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 !");
6434   return ret;
6435 }
6436
6437 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6438 {
6439   if(getFileName2().empty())
6440     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6441   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6442   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut2,*contentNotNull());
6443   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6444   if(!arrOutC)
6445     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6446   arrOut=arrOutC;
6447   return ret.retn();
6448 }
6449
6450 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr) throw(INTERP_KERNEL::Exception)
6451 {
6452   if(!((DataArray *)arr))
6453     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6454   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6455   if(!arrC)
6456     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6457   arrC->incrRef();
6458   return arrC;
6459 }
6460
6461 /*!
6462  * Returns a new MEDCouplingFieldDouble of a given type lying on
6463  * the top level cells of the first mesh in MED file. If \a this field 
6464  * has not been constructed via file reading, an exception is thrown.
6465  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6466  *  \param [in] type - a spatial discretization of interest.
6467  *  \param [out] arrOut - the DataArrayInt containing values of field.
6468  *  \param [in] renumPol - specifies how to permute values of the result field according to
6469  *          the optional numbers of cells and nodes, if any. The valid values are
6470  *          - 0 - do not permute.
6471  *          - 1 - permute cells.
6472  *          - 2 - permute nodes.
6473  *          - 3 - permute cells and nodes.
6474  *
6475  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6476  *          caller is to delete this field using decrRef() as it is no more needed. 
6477  *  \throw If \a this field has not been constructed via file reading.
6478  *  \throw If the MED file is not readable.
6479  *  \throw If there is no mesh in the MED file.
6480  *  \throw If no field values of the given \a type.
6481  *  \throw If no field values lying on the top level support.
6482  *  \sa getFieldAtLevel()
6483  */
6484 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6485 {
6486   if(getFileName2().empty())
6487     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6488   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6489   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,0,renumPol,this,arr,*contentNotNull());
6490   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6491   return ret.retn();
6492 }
6493
6494 /*!
6495  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6496  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6497  *  \param [in] type - a spatial discretization of the new field.
6498  *  \param [in] mesh - the supporting mesh.
6499  *  \param [out] arrOut - the DataArrayInt containing values of field.
6500  *  \param [in] renumPol - specifies how to permute values of the result field according to
6501  *          the optional numbers of cells and nodes, if any. The valid values are
6502  *          - 0 - do not permute.
6503  *          - 1 - permute cells.
6504  *          - 2 - permute nodes.
6505  *          - 3 - permute cells and nodes.
6506  *
6507  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6508  *          caller is to delete this field using decrRef() as it is no more needed. 
6509  *  \throw If no field of \a this is lying on \a mesh.
6510  *  \throw If the mesh is empty.
6511  *  \throw If no field values of the given \a type are available.
6512  *  \sa getFieldAtLevel()
6513  *  \sa getFieldOnMeshAtLevel() 
6514  */
6515 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6516 {
6517   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6518   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6519   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6520   return ret.retn();
6521 }
6522
6523 /*!
6524  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6525  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6526  *  \param [in] type - a spatial discretization of interest.
6527  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6528  *  \param [out] arrOut - the DataArrayInt containing values of field.
6529  *  \param [in] mesh - the supporting mesh.
6530  *  \param [in] renumPol - specifies how to permute values of the result field according to
6531  *          the optional numbers of cells and nodes, if any. The valid values are
6532  *          - 0 - do not permute.
6533  *          - 1 - permute cells.
6534  *          - 2 - permute nodes.
6535  *          - 3 - permute cells and nodes.
6536  *
6537  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6538  *          caller is to delete this field using decrRef() as it is no more needed. 
6539  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6540  *  \throw If no field of \a this is lying on \a mesh.
6541  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6542  *  \sa getFieldAtLevel()
6543  *  \sa getFieldOnMeshAtLevel() 
6544  */
6545 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6546 {
6547   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6548   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6549   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6550   return ret.retn();
6551 }
6552
6553 /*!
6554  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6555  * This method is called "Old" because in MED3 norm a field has only one meshName
6556  * attached, so this method is for readers of MED2 files. If \a this field 
6557  * has not been constructed via file reading, an exception is thrown.
6558  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6559  *  \param [in] type - a spatial discretization of interest.
6560  *  \param [in] mName - a name of the supporting mesh.
6561  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6562  *  \param [out] arrOut - the DataArrayInt containing values of field.
6563  *  \param [in] renumPol - specifies how to permute values of the result field according to
6564  *          the optional numbers of cells and nodes, if any. The valid values are
6565  *          - 0 - do not permute.
6566  *          - 1 - permute cells.
6567  *          - 2 - permute nodes.
6568  *          - 3 - permute cells and nodes.
6569  *
6570  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6571  *          caller is to delete this field using decrRef() as it is no more needed. 
6572  *  \throw If the MED file is not readable.
6573  *  \throw If there is no mesh named \a mName in the MED file.
6574  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6575  *  \throw If \a this field has not been constructed via file reading.
6576  *  \throw If no field of \a this is lying on the mesh named \a mName.
6577  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6578  *  \sa getFieldAtLevel()
6579  */
6580 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
6581 {
6582   if(getFileName2().empty())
6583     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6584   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6585   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6586   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6587   return ret.retn();
6588 }
6589
6590 /*!
6591  * Returns values and a profile of the field of a given type lying on a given support.
6592  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6593  *  \param [in] type - a spatial discretization of the field.
6594  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6595  *  \param [in] mesh - the supporting mesh.
6596  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6597  *          field of interest lies on. If the field lies on all entities of the given
6598  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6599  *          using decrRef() as it is no more needed.  
6600  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6601  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6602  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6603  *  \throw If no field of \a this is lying on \a mesh.
6604  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6605  */
6606 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
6607 {
6608   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6609   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6610 }
6611
6612 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() throw(INTERP_KERNEL::Exception)
6613 {
6614   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6615   if(!pt)
6616     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6617   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6618   if(!ret)
6619     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 !");
6620   return ret;
6621 }
6622
6623 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
6624 {
6625   return contentNotNull()->getUndergroundDataArrayInt();
6626 }
6627
6628 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6629
6630 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6631 {
6632 }
6633
6634 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const char *fieldName):MEDFileFieldNameScope(fieldName)
6635 {
6636 }
6637
6638 /*!
6639  * \param [in] fieldId field id in C mode
6640  */
6641 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll) throw(INTERP_KERNEL::Exception)
6642 {
6643   med_field_type typcha;
6644   std::string dtunitOut;
6645   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6646   setDtUnit(dtunitOut.c_str());
6647   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll);
6648 }
6649
6650 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll) throw(INTERP_KERNEL::Exception)
6651 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6652 {
6653   setDtUnit(dtunit.c_str());
6654   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll);
6655 }
6656 catch(INTERP_KERNEL::Exception& e)
6657 {
6658   throw e;
6659 }
6660
6661 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySize() const
6662 {
6663   std::size_t ret=_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>);
6664   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6665     ret+=(*it).capacity();
6666   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6667     if((const MEDFileAnyTypeField1TSWithoutSDA *)(*it))
6668       ret+=(*it)->getHeapMemorySize();
6669   return ret;
6670 }
6671
6672 /*!
6673  * 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
6674  * NULL.
6675  */
6676 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
6677 {
6678   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6679   ret->setInfo(_infos);
6680   int sz=(int)_time_steps.size();
6681   for(const int *id=startIds;id!=endIds;id++)
6682     {
6683       if(*id>=0 && *id<sz)
6684         {
6685           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6686           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6687           if(tse)
6688             {
6689               tse->incrRef();
6690               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6691             }
6692           ret->pushBackTimeStep(tse2);
6693         }
6694       else
6695         {
6696           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6697           oss << " ! Should be in [0," << sz << ") !";
6698           throw INTERP_KERNEL::Exception(oss.str().c_str());
6699         }
6700     }
6701   if(ret->getNumberOfTS()>0)
6702     ret->synchronizeNameScope();
6703   ret->copyNameScope(*this);
6704   return ret.retn();
6705 }
6706
6707 /*!
6708  * 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
6709  * NULL.
6710  */
6711 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
6712 {
6713   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6714   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6715   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6716   ret->setInfo(_infos);
6717   int sz=(int)_time_steps.size();
6718   int j=bg;
6719   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
6720     {
6721       if(j>=0 && j<sz)
6722         {
6723           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
6724           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6725           if(tse)
6726             {
6727               tse->incrRef();
6728               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6729             }
6730           ret->pushBackTimeStep(tse2);
6731         }
6732       else
6733         {
6734           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
6735           oss << " ! Should be in [0," << sz << ") !";
6736           throw INTERP_KERNEL::Exception(oss.str().c_str());
6737         }
6738     }
6739   if(ret->getNumberOfTS()>0)
6740     ret->synchronizeNameScope();
6741   ret->copyNameScope(*this);
6742   return ret.retn();
6743 }
6744
6745 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
6746 {
6747   int id=0;
6748   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6749   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6750     {
6751       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6752       if(!cur)
6753         continue;
6754       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6755       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
6756         ids->pushBackSilent(id);
6757     }
6758   return buildFromTimeStepIds(ids->begin(),ids->end());
6759 }
6760
6761 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
6762 {
6763   int id=0;
6764   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6765   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6766     {
6767       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6768       if(!cur)
6769         continue;
6770       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6771       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
6772         ids->pushBackSilent(id);
6773     }
6774   return buildFromTimeStepIds(ids->begin(),ids->end());
6775 }
6776
6777 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const throw(INTERP_KERNEL::Exception)
6778 {
6779   return _infos;
6780 }
6781
6782 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
6783 {
6784   _infos=info;
6785 }
6786
6787 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6788 {
6789   int ret=0;
6790   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6791     {
6792       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
6793       if(pt->isDealingTS(iteration,order))
6794         return ret;
6795     }
6796   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
6797   std::vector< std::pair<int,int> > vp=getIterations();
6798   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
6799     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
6800   throw INTERP_KERNEL::Exception(oss.str().c_str());
6801 }
6802
6803 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6804 {
6805   return *_time_steps[getTimeStepPos(iteration,order)];
6806 }
6807
6808 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) throw(INTERP_KERNEL::Exception)
6809 {
6810   return *_time_steps[getTimeStepPos(iteration,order)];
6811 }
6812
6813 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
6814 {
6815   if(_time_steps.empty())
6816     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
6817   return _time_steps[0]->getMeshName();
6818 }
6819
6820 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
6821 {
6822   std::string oldName(getMeshName());
6823   std::vector< std::pair<std::string,std::string> > v(1);
6824   v[0].first=oldName; v[0].second=newMeshName;
6825   changeMeshNames(v);
6826 }
6827
6828 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
6829 {
6830   bool ret=false;
6831   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6832     {
6833       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6834       if(cur)
6835         ret=cur->changeMeshNames(modifTab) || ret;
6836     }
6837   return ret;
6838 }
6839
6840 /*!
6841  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
6842  */
6843 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
6844 {
6845   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
6846 }
6847
6848 /*!
6849  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
6850  */
6851 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)
6852 {
6853   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
6854 }
6855
6856 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
6857                                                                 MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
6858 {
6859   bool ret=false;
6860   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6861     {
6862       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
6863       if(f1ts)
6864         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
6865     }
6866   return ret;
6867 }
6868
6869 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
6870 {
6871   std::string startLine(bkOffset,' ');
6872   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
6873   if(fmtsId>=0)
6874     oss << " (" << fmtsId << ")";
6875   oss << " has the following name: \"" << _name << "\"." << std::endl;
6876   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
6877   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6878     {
6879       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
6880     }
6881   int i=0;
6882   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
6883     {
6884       std::string chapter(17,'0'+i);
6885       oss << startLine << chapter << std::endl;
6886       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6887       if(cur)
6888         cur->simpleRepr(bkOffset+2,oss,i);
6889       else
6890         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
6891       oss << startLine << chapter << std::endl;
6892     }
6893 }
6894
6895 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
6896 {
6897   std::size_t sz=_time_steps.size();
6898   std::vector< std::pair<int,int> > ret(sz);
6899   ret1.resize(sz);
6900   for(std::size_t i=0;i<sz;i++)
6901     {
6902       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
6903       if(f1ts)
6904         {
6905           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
6906         }
6907       else
6908         {
6909           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
6910           throw INTERP_KERNEL::Exception(oss.str().c_str());
6911         }
6912     }
6913   return ret;
6914 }
6915
6916 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse) throw(INTERP_KERNEL::Exception)
6917 {
6918   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
6919   if(!tse2)
6920     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
6921   checkCoherencyOfType(tse2);
6922   if(_time_steps.empty())
6923     {
6924       setName(tse2->getName().c_str());
6925       setInfo(tse2->getInfo());
6926     }
6927   checkThatComponentsMatch(tse2->getInfo());
6928   _time_steps.push_back(tse);
6929 }
6930
6931 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope() throw(INTERP_KERNEL::Exception)
6932 {
6933   std::size_t nbOfCompo=_infos.size();
6934   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6935     {
6936       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6937       if(cur)
6938         {
6939           if((cur->getInfo()).size()!=nbOfCompo)
6940             {
6941               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
6942               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
6943               throw INTERP_KERNEL::Exception(oss.str().c_str());
6944             }
6945           cur->copyNameScope(*this);
6946         }
6947     }
6948 }
6949
6950 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll) throw(INTERP_KERNEL::Exception)
6951 {
6952   _time_steps.resize(nbPdt);
6953   for(int i=0;i<nbPdt;i++)
6954     {
6955       std::vector< std::pair<int,int> > ts;
6956       med_int numdt=0,numo=0;
6957       med_int meshIt=0,meshOrder=0;
6958       med_float dt=0.0;
6959       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
6960       switch(fieldTyp)
6961         {
6962         case MED_FLOAT64:
6963           {
6964             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
6965             break;
6966           }
6967         case MED_INT32:
6968           {
6969             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
6970             break;
6971           }
6972         default:
6973           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
6974         }
6975       if(loadAll)
6976         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this);
6977       else
6978         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this);
6979     }
6980 }
6981
6982 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception)
6983 {
6984   if(_time_steps.empty())
6985     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
6986   checkThatNbOfCompoOfTSMatchThis();
6987   std::vector<std::string> infos(getInfo());
6988   int nbComp=infos.size();
6989   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
6990   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
6991   for(int i=0;i<nbComp;i++)
6992     {
6993       std::string info=infos[i];
6994       std::string c,u;
6995       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6996       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
6997       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
6998     }
6999   if(_name.empty())
7000     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7001   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
7002   int nbOfTS=_time_steps.size();
7003   for(int i=0;i<nbOfTS;i++)
7004     _time_steps[i]->writeLL(fid,opts,*this);
7005 }
7006
7007 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
7008 {
7009   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7010     {
7011       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7012       if(elt)
7013         elt->loadBigArraysRecursively(fid,nasc);
7014     }
7015 }
7016   
7017 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc) throw(INTERP_KERNEL::Exception)
7018 {
7019   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7020     {
7021       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7022       if(elt)
7023         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7024     }
7025 }
7026
7027 void MEDFileAnyTypeFieldMultiTSWithoutSDA::releaseArrays() throw(INTERP_KERNEL::Exception)
7028 {
7029   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7030     {
7031       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7032       if(elt)
7033         elt->releaseArrays();
7034     }
7035 }
7036
7037 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7038 {
7039   return _time_steps.size();
7040 }
7041
7042 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
7043 {
7044   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7045   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7046     {
7047       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7048       if(tmp)
7049         newTS.push_back(*it);
7050     }
7051   _time_steps=newTS;
7052 }
7053
7054 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
7055 {
7056   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7057   int maxId=(int)_time_steps.size();
7058   int ii=0;
7059   std::set<int> idsToDel;
7060   for(const int *id=startIds;id!=endIds;id++,ii++)
7061     {
7062       if(*id>=0 && *id<maxId)
7063         {
7064           idsToDel.insert(*id);
7065         }
7066       else
7067         {
7068           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7069           throw INTERP_KERNEL::Exception(oss.str().c_str());
7070         }
7071     }
7072   for(int iii=0;iii<maxId;iii++)
7073     if(idsToDel.find(iii)==idsToDel.end())
7074       newTS.push_back(_time_steps[iii]);
7075   _time_steps=newTS;
7076 }
7077
7078 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
7079 {
7080   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7081   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7082   if(nbOfEntriesToKill==0)
7083     return ;
7084   std::size_t sz=_time_steps.size();
7085   std::vector<bool> b(sz,true);
7086   int j=bg;
7087   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7088     b[j]=false;
7089   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7090   for(std::size_t i=0;i<sz;i++)
7091     if(b[i])
7092       newTS.push_back(_time_steps[i]);
7093   _time_steps=newTS;
7094 }
7095
7096 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
7097 {
7098   int ret=0;
7099   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7100   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7101     {
7102       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7103       if(tmp)
7104         {
7105           int it2,ord;
7106           tmp->getTime(it2,ord);
7107           if(it2==iteration && order==ord)
7108             return ret;
7109           else
7110             oss << "(" << it2 << ","  << ord << "), ";
7111         }
7112     }
7113   throw INTERP_KERNEL::Exception(oss.str().c_str());
7114 }
7115
7116 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
7117 {
7118   int ret=0;
7119   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7120   oss.precision(15);
7121   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7122     {
7123       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7124       if(tmp)
7125         {
7126           int it2,ord;
7127           double ti=tmp->getTime(it2,ord);
7128           if(fabs(time-ti)<eps)
7129             return ret;
7130           else
7131             oss << ti << ", ";
7132         }
7133     }
7134   throw INTERP_KERNEL::Exception(oss.str().c_str());
7135 }
7136
7137 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7138 {
7139   int lgth=_time_steps.size();
7140   std::vector< std::pair<int,int> > ret(lgth);
7141   for(int i=0;i<lgth;i++)
7142     _time_steps[i]->fillIteration(ret[i]);
7143   return ret;
7144 }
7145
7146 /*!
7147  * 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'
7148  * This method returns two things.
7149  * - The absolute dimension of 'this' in first parameter. 
7150  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7151  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7152  *
7153  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7154  * Only these 3 discretizations will be taken into account here.
7155  *
7156  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7157  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7158  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7159  *
7160  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7161  * 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'.
7162  * 
7163  * Let's consider the typical following case :
7164  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7165  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7166  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7167  *   TETRA4 and SEG2
7168  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7169  *
7170  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7171  * 
7172  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7173  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7174  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7175  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7176  */
7177 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
7178 {
7179   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7180 }
7181
7182 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const throw(INTERP_KERNEL::Exception)
7183 {
7184   if(pos<0 || pos>=(int)_time_steps.size())
7185     {
7186       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7187       throw INTERP_KERNEL::Exception(oss.str().c_str());
7188     }
7189   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7190   if(item==0)
7191     {
7192       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7193       oss << "\nTry to use following method eraseEmptyTS !";
7194       throw INTERP_KERNEL::Exception(oss.str().c_str());
7195     }
7196   return item;
7197 }
7198
7199 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) throw(INTERP_KERNEL::Exception)
7200 {
7201   if(pos<0 || pos>=(int)_time_steps.size())
7202     {
7203       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7204       throw INTERP_KERNEL::Exception(oss.str().c_str());
7205     }
7206   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7207   if(item==0)
7208     {
7209       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7210       oss << "\nTry to use following method eraseEmptyTS !";
7211       throw INTERP_KERNEL::Exception(oss.str().c_str());
7212     }
7213   return item;
7214 }
7215
7216 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7217 {
7218   std::vector<std::string> ret;
7219   std::set<std::string> ret2;
7220   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7221     {
7222       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7223       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7224         if(ret2.find(*it2)==ret2.end())
7225           {
7226             ret.push_back(*it2);
7227             ret2.insert(*it2);
7228           }
7229     }
7230   return ret;
7231 }
7232
7233 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7234 {
7235   std::vector<std::string> ret;
7236   std::set<std::string> ret2;
7237   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7238     {
7239       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7240       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7241         if(ret2.find(*it2)==ret2.end())
7242           {
7243             ret.push_back(*it2);
7244             ret2.insert(*it2);
7245           }
7246     }
7247   return ret;
7248 }
7249
7250 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7251 {
7252   std::vector<std::string> ret;
7253   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7254     {
7255       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7256       ret.insert(ret.end(),tmp.begin(),tmp.end());
7257     }
7258   return ret;
7259 }
7260
7261 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7262 {
7263   std::vector<std::string> ret;
7264   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7265     {
7266       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7267       ret.insert(ret.end(),tmp.begin(),tmp.end());
7268     }
7269   return ret;
7270 }
7271
7272 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7273 {
7274   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7275     (*it)->changePflsRefsNamesGen2(mapOfModif);
7276 }
7277
7278 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7279 {
7280   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7281     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7282 }
7283
7284 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
7285 {
7286   int lgth=_time_steps.size();
7287   std::vector< std::vector<TypeOfField> > ret(lgth);
7288   for(int i=0;i<lgth;i++)
7289     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7290   return ret;
7291 }
7292
7293 /*!
7294  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7295  */
7296 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)
7297 {
7298   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7299 }
7300
7301 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception)
7302 {
7303   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7304   std::size_t i=0;
7305   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7306     {
7307       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7308         ret->_time_steps[i]=(*it)->deepCpy();
7309     }
7310   return ret.retn();
7311 }
7312
7313 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const throw(INTERP_KERNEL::Exception)
7314 {
7315   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7316   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7317   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7318   for(std::size_t i=0;i<sz;i++)
7319     {
7320       ret[i]=shallowCpy();
7321       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7322     }
7323   for(std::size_t i=0;i<sz2;i++)
7324     {
7325       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7326       if(ret1.size()!=sz)
7327         {
7328           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7329           throw INTERP_KERNEL::Exception(oss.str().c_str());
7330         }
7331       ts[i]=ret1;
7332     }
7333   for(std::size_t i=0;i<sz;i++)
7334     for(std::size_t j=0;j<sz2;j++)
7335       ret[i]->_time_steps[j]=ts[j][i];
7336   return ret;
7337 }
7338
7339 /*!
7340  * This method splits into discretization each time steps in \a this.
7341  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7342  */
7343 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const throw(INTERP_KERNEL::Exception)
7344 {
7345   std::size_t sz(_time_steps.size());
7346   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7347   for(std::size_t i=0;i<sz;i++)
7348     {
7349       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7350       if(!timeStep)
7351         {
7352           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7353           throw INTERP_KERNEL::Exception(oss.str().c_str());
7354         }
7355       items[i]=timeStep->splitDiscretizations();  
7356     }
7357   //
7358   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7359   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7360   std::vector< TypeOfField > types;
7361   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7362     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7363       {
7364         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7365         if(ts.size()!=1)
7366           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7367         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7368         if(it2==types.end())
7369           types.push_back(ts[0]);
7370       }
7371   ret.resize(types.size()); ret2.resize(types.size());
7372   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7373     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7374       {
7375         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7376         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7377         ret2[pos].push_back(*it1);
7378       }
7379   for(std::size_t i=0;i<types.size();i++)
7380     {
7381       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=createNew();
7382       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7383         elt->pushBackTimeStep(*it1);//also updates infos in elt
7384       ret[i]=elt;
7385       elt->MEDFileFieldNameScope::operator=(*this);
7386     }
7387   return ret;
7388 }
7389
7390 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception)
7391 {
7392   _name=field->getName();
7393   if(_name.empty())
7394     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7395   if(!arr)
7396     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7397   _infos=arr->getInfoOnComponents();
7398 }
7399
7400 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const throw(INTERP_KERNEL::Exception)
7401 {
7402   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7403   if(_name!=field->getName())
7404     {
7405       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7406       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7407       throw INTERP_KERNEL::Exception(oss.str().c_str());
7408     }
7409   if(!arr)
7410     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7411   checkThatComponentsMatch(arr->getInfoOnComponents());
7412 }
7413
7414 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const throw(INTERP_KERNEL::Exception)
7415 {
7416   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7417   if(getInfo().size()!=compos.size())
7418     {
7419       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7420       oss << " number of components of element to append (" << compos.size() << ") !";
7421       throw INTERP_KERNEL::Exception(oss.str().c_str());
7422     }
7423   if(_infos!=compos)
7424     {
7425       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7426       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7427       oss << " But compo in input fields are : ";
7428       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7429       oss << " !";
7430       throw INTERP_KERNEL::Exception(oss.str().c_str());
7431     }
7432 }
7433
7434 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const throw(INTERP_KERNEL::Exception)
7435 {
7436   std::size_t sz=_infos.size();
7437   int j=0;
7438   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7439     {
7440       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7441       if(elt)
7442         if(elt->getInfo().size()!=sz)
7443           {
7444             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7445             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7446             throw INTERP_KERNEL::Exception(oss.str().c_str());
7447           }
7448     }
7449 }
7450
7451 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
7452 {
7453   if(!field)
7454     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7455   if(!_time_steps.empty())
7456     checkCoherencyOfTinyInfo(field,arr);
7457   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7458   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7459   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7460   copyTinyInfoFrom(field,arr);
7461   _time_steps.push_back(obj);
7462 }
7463
7464 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
7465 {
7466   if(!field)
7467     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7468   if(!_time_steps.empty())
7469     checkCoherencyOfTinyInfo(field,arr);
7470   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7471   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7472   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7473   copyTinyInfoFrom(field,arr);
7474   _time_steps.push_back(obj);
7475 }
7476
7477 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts) throw(INTERP_KERNEL::Exception)
7478 {
7479   int sz=(int)_time_steps.size();
7480   if(i<0 || i>=sz)
7481     {
7482       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7483       throw INTERP_KERNEL::Exception(oss.str().c_str());
7484     }
7485   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7486   if(tsPtr)
7487     {
7488       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7489         {
7490           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7491           throw INTERP_KERNEL::Exception(oss.str().c_str());
7492         }
7493     }
7494   _time_steps[i]=ts;
7495 }
7496
7497 //= MEDFileFieldMultiTSWithoutSDA
7498
7499 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll) throw(INTERP_KERNEL::Exception)
7500 {
7501   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7502 }
7503
7504 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7505 {
7506 }
7507
7508 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const char *fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7509 {
7510 }
7511
7512 /*!
7513  * \param [in] fieldId field id in C mode
7514  */
7515 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll) throw(INTERP_KERNEL::Exception)
7516 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7517 {
7518 }
7519 catch(INTERP_KERNEL::Exception& e)
7520   { throw e; }
7521
7522 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll) throw(INTERP_KERNEL::Exception)
7523 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7524 {
7525 }
7526 catch(INTERP_KERNEL::Exception& e)
7527 { throw e; }
7528
7529 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const throw(INTERP_KERNEL::Exception)
7530 {
7531   return new MEDFileField1TSWithoutSDA;
7532 }
7533
7534 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const throw(INTERP_KERNEL::Exception)
7535 {
7536   if(!f1ts)
7537     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7538   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7539   if(!f1tsC)
7540     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7541 }
7542
7543 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
7544 {
7545   return MEDFileField1TSWithoutSDA::TYPE_STR;
7546 }
7547
7548 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
7549 {
7550   return new MEDFileFieldMultiTSWithoutSDA(*this);
7551 }
7552
7553 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const throw(INTERP_KERNEL::Exception)
7554 {
7555   return new MEDFileFieldMultiTSWithoutSDA;
7556 }
7557
7558 /*!
7559  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7560  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7561  */
7562 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)
7563 {
7564   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7565   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7566   if(!myF1TSC)
7567     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7568   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7569 }
7570
7571 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const throw(INTERP_KERNEL::Exception)
7572 {
7573   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7574   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7575   int i=0;
7576   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7577     {
7578       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7579       if(eltToConv)
7580         {
7581           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7582           if(!eltToConvC)
7583             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7584           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7585           ret->setIteration(i,elt);
7586         }
7587     }
7588   return ret.retn();
7589 }
7590
7591 //= MEDFileAnyTypeFieldMultiTS
7592
7593 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7594 {
7595 }
7596
7597 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
7598 try:MEDFileFieldGlobsReal(fileName)
7599 {
7600   MEDFileUtilities::CheckFileForRead(fileName);
7601   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7602   _content=BuildContentFrom(fid,fileName,loadAll);
7603   loadGlobals(fid);
7604 }
7605 catch(INTERP_KERNEL::Exception& e)
7606   {
7607     throw e;
7608   }
7609
7610 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
7611 {
7612   med_field_type typcha;
7613   std::vector<std::string> infos;
7614   std::string dtunit;
7615   int i=-1;
7616   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7617   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7618   switch(typcha)
7619     {
7620     case MED_FLOAT64:
7621       {
7622         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll);
7623         break;
7624       }
7625     case MED_INT32:
7626       {
7627         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll);
7628         break;
7629       }
7630     default:
7631       {
7632         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] !";
7633         throw INTERP_KERNEL::Exception(oss.str().c_str());
7634       }
7635     }
7636   ret->setDtUnit(dtunit.c_str());
7637   return ret.retn();
7638 }
7639
7640 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
7641 {
7642   med_field_type typcha;
7643   //
7644   std::vector<std::string> infos;
7645   std::string dtunit,fieldName;
7646   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
7647   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7648   switch(typcha)
7649     {
7650     case MED_FLOAT64:
7651       {
7652         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll);
7653         break;
7654       }
7655     case MED_INT32:
7656       {
7657         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll);
7658         break;
7659       }
7660     default:
7661       {
7662         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] !";
7663         throw INTERP_KERNEL::Exception(oss.str().c_str());
7664       }
7665     }
7666   ret->setDtUnit(dtunit.c_str());
7667   return ret.retn();
7668 }
7669
7670 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const char *fileName) throw(INTERP_KERNEL::Exception)
7671 {
7672   if(!c)
7673     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
7674   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
7675     {
7676       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
7677       ret->setFileName(fileName);
7678       ret->_content=c;  c->incrRef();
7679       return ret.retn();
7680     }
7681   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
7682     {
7683       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
7684       ret->setFileName(fileName);
7685       ret->_content=c;  c->incrRef();
7686       return ret.retn();
7687     }
7688   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
7689 }
7690
7691 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
7692 try:MEDFileFieldGlobsReal(fileName)
7693 {
7694   MEDFileUtilities::CheckFileForRead(fileName);
7695   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7696   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
7697   loadGlobals(fid);
7698 }
7699 catch(INTERP_KERNEL::Exception& e)
7700   {
7701     throw e;
7702   }
7703
7704 //= MEDFileIntFieldMultiTSWithoutSDA
7705
7706 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll) throw(INTERP_KERNEL::Exception)
7707 {
7708   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7709 }
7710
7711 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
7712 {
7713 }
7714
7715 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const char *fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7716 {
7717 }
7718
7719 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll) throw(INTERP_KERNEL::Exception)
7720 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7721 {
7722 }
7723 catch(INTERP_KERNEL::Exception& e)
7724 { throw e; }
7725
7726 /*!
7727  * \param [in] fieldId field id in C mode
7728  */
7729 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll) throw(INTERP_KERNEL::Exception)
7730 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7731 {
7732 }
7733 catch(INTERP_KERNEL::Exception& e)
7734   { throw e; }
7735
7736 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const throw(INTERP_KERNEL::Exception)
7737 {
7738   return new MEDFileIntField1TSWithoutSDA;
7739 }
7740
7741 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const throw(INTERP_KERNEL::Exception)
7742 {
7743   if(!f1ts)
7744     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7745   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
7746   if(!f1tsC)
7747     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
7748 }
7749
7750 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::Exception)
7751 {
7752   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
7753 }
7754
7755 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception)
7756 {
7757   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
7758 }
7759
7760 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const throw(INTERP_KERNEL::Exception)
7761 {
7762   return new MEDFileIntFieldMultiTSWithoutSDA;
7763 }
7764
7765 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const throw(INTERP_KERNEL::Exception)
7766 {
7767   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
7768   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7769   int i=0;
7770   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7771     {
7772       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7773       if(eltToConv)
7774         {
7775           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
7776           if(!eltToConvC)
7777             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
7778           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
7779           ret->setIteration(i,elt);
7780         }
7781     }
7782   return ret.retn();
7783 }
7784
7785 //= MEDFileAnyTypeFieldMultiTS
7786
7787 /*!
7788  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
7789  * that has been read from a specified MED file.
7790  *  \param [in] fileName - the name of the MED file to read.
7791  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7792  *          is to delete this field using decrRef() as it is no more needed.
7793  *  \throw If reading the file fails.
7794  */
7795 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
7796 {
7797   MEDFileUtilities::CheckFileForRead(fileName);
7798   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7799   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
7800   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7801   ret->loadGlobals(fid);
7802   return ret.retn();
7803 }
7804
7805 /*!
7806  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
7807  * that has been read from a specified MED file.
7808  *  \param [in] fileName - the name of the MED file to read.
7809  *  \param [in] fieldName - the name of the field to read.
7810  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7811  *          is to delete this field using decrRef() as it is no more needed.
7812  *  \throw If reading the file fails.
7813  *  \throw If there is no field named \a fieldName in the file.
7814  */
7815 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
7816 {
7817   MEDFileUtilities::CheckFileForRead(fileName);
7818   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
7819   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
7820   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7821   ret->loadGlobals(fid);
7822   return ret.retn();
7823 }
7824
7825 /*!
7826  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7827  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7828  *
7829  * \warning this is a shallow copy constructor
7830  */
7831 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7832 {
7833   if(!shallowCopyOfContent)
7834     {
7835       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
7836       otherPtr->incrRef();
7837       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
7838     }
7839   else
7840     {
7841       _content=other.shallowCpy();
7842     }
7843 }
7844
7845 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() throw(INTERP_KERNEL::Exception)
7846 {
7847   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7848   if(!ret)
7849     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
7850   return ret;
7851 }
7852
7853 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const throw(INTERP_KERNEL::Exception)
7854 {
7855   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7856   if(!ret)
7857     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
7858   return ret;
7859 }
7860
7861 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
7862 {
7863   return contentNotNullBase()->getPflsReallyUsed2();
7864 }
7865
7866 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
7867 {
7868   return contentNotNullBase()->getLocsReallyUsed2();
7869 }
7870
7871 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
7872 {
7873   return contentNotNullBase()->getPflsReallyUsedMulti2();
7874 }
7875
7876 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
7877 {
7878   return contentNotNullBase()->getLocsReallyUsedMulti2();
7879 }
7880
7881 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7882 {
7883   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
7884 }
7885
7886 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
7887 {
7888   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
7889 }
7890
7891 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
7892 {
7893   return contentNotNullBase()->getNumberOfTS();
7894 }
7895
7896 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
7897 {
7898   contentNotNullBase()->eraseEmptyTS();
7899 }
7900
7901 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
7902 {
7903   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
7904 }
7905
7906 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
7907 {
7908   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
7909 }
7910
7911 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
7912 {
7913   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
7914   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7915   ret->_content=c;
7916   return ret.retn();
7917 }
7918
7919 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
7920 {
7921   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
7922   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7923   ret->_content=c;
7924   return ret.retn();
7925 }
7926
7927 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
7928 {
7929   return contentNotNullBase()->getIterations();
7930 }
7931
7932 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts) throw(INTERP_KERNEL::Exception)
7933 {
7934   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
7935     pushBackTimeStep(*it);
7936 }
7937
7938 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts) throw(INTERP_KERNEL::Exception)
7939 {
7940   if(!f1ts)
7941     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
7942   checkCoherencyOfType(f1ts);
7943   f1ts->incrRef();
7944   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
7945   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
7946   c->incrRef();
7947   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
7948   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
7949     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
7950   _content->pushBackTimeStep(cSafe);
7951   appendGlobs(*f1ts,1e-12);
7952 }
7953
7954 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope() throw(INTERP_KERNEL::Exception)
7955 {
7956   contentNotNullBase()->synchronizeNameScope();
7957 }
7958
7959 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
7960 {
7961   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
7962 }
7963
7964 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
7965 {
7966   return contentNotNullBase()->getPosGivenTime(time,eps);
7967 }
7968
7969 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
7970 {
7971   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
7972 }
7973
7974 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
7975 {
7976   return contentNotNullBase()->getTypesOfFieldAvailable();
7977 }
7978
7979 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)
7980 {
7981   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
7982 }
7983
7984 std::string MEDFileAnyTypeFieldMultiTS::getName() const
7985 {
7986   return contentNotNullBase()->getName();
7987 }
7988
7989 void MEDFileAnyTypeFieldMultiTS::setName(const char *name)
7990 {
7991   contentNotNullBase()->setName(name);
7992 }
7993
7994 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const throw(INTERP_KERNEL::Exception)
7995 {
7996   return contentNotNullBase()->getDtUnit();
7997 }
7998
7999 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const char *dtUnit) throw(INTERP_KERNEL::Exception)
8000 {
8001   contentNotNullBase()->setDtUnit(dtUnit);
8002 }
8003
8004 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8005 {
8006   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8007 }
8008
8009 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
8010 {
8011   return contentNotNullBase()->getTimeSteps(ret1);
8012 }
8013
8014 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const throw(INTERP_KERNEL::Exception)
8015 {
8016   return contentNotNullBase()->getMeshName();
8017 }
8018
8019 void MEDFileAnyTypeFieldMultiTS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
8020 {
8021   contentNotNullBase()->setMeshName(newMeshName);
8022 }
8023
8024 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
8025 {
8026   return contentNotNullBase()->changeMeshNames(modifTab);
8027 }
8028
8029 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const throw(INTERP_KERNEL::Exception)
8030 {
8031   return contentNotNullBase()->getInfo();
8032 }
8033
8034 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
8035 {
8036   return contentNotNullBase()->setInfo(info);
8037 }
8038
8039 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const throw(INTERP_KERNEL::Exception)
8040 {
8041   const std::vector<std::string> ret=getInfo();
8042   return (int)ret.size();
8043 }
8044
8045 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
8046 {
8047   writeGlobals(fid,*this);
8048   contentNotNullBase()->writeLL(fid,*this);
8049 }
8050
8051 /*!
8052  * Writes \a this field into a MED file specified by its name.
8053  *  \param [in] fileName - the MED file name.
8054  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8055  * - 2 - erase; an existing file is removed.
8056  * - 1 - append; same data should not be present in an existing file.
8057  * - 0 - overwrite; same data present in an existing file is overwritten.
8058  *  \throw If the field name is not set.
8059  *  \throw If no field data is set.
8060  *  \throw If \a mode == 1 and the same data is present in an existing file.
8061  */
8062 void MEDFileAnyTypeFieldMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
8063 {
8064   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8065   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
8066   writeLL(fid);
8067 }
8068
8069 /*!
8070  * This method alloc the arrays and load potentially huge arrays contained in this field.
8071  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8072  * This method can be also called to refresh or reinit values from a file.
8073  * 
8074  * \throw If the fileName is not set or points to a non readable MED file.
8075  */
8076 void MEDFileAnyTypeFieldMultiTS::loadArrays() throw(INTERP_KERNEL::Exception)
8077 {
8078   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
8079   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8080 }
8081
8082 /*!
8083  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8084  * But once data loaded once, this method does nothing.
8085  * 
8086  * \throw If the fileName is not set or points to a non readable MED file.
8087  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::releaseArrays
8088  */
8089 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary() throw(INTERP_KERNEL::Exception)
8090 {
8091   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
8092   contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8093 }
8094
8095 /*!
8096  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8097  * This method does not release arrays set outside the context of a MED file.
8098  * 
8099  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8100  */
8101 void MEDFileAnyTypeFieldMultiTS::releaseArrays() throw(INTERP_KERNEL::Exception)
8102 {
8103   contentNotNullBase()->releaseArrays();
8104 }
8105
8106 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8107 {
8108   std::ostringstream oss;
8109   contentNotNullBase()->simpleRepr(0,oss,-1);
8110   simpleReprGlobs(oss);
8111   return oss.str();
8112 }
8113
8114 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySize() const
8115 {
8116   std::size_t ret=0;
8117   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)_content)
8118     ret+=_content->getHeapMemorySize();
8119   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
8120 }
8121
8122 /*!
8123  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8124  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8125  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8126  */
8127 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const throw(INTERP_KERNEL::Exception)
8128 {
8129   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8130   if(!content)
8131     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8132   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8133   std::size_t sz(contentsSplit.size());
8134   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8135   for(std::size_t i=0;i<sz;i++)
8136     {
8137       ret[i]=shallowCpy();
8138       ret[i]->_content=contentsSplit[i];
8139     }
8140   return ret;
8141 }
8142
8143 /*!
8144  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8145  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8146  */
8147 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const throw(INTERP_KERNEL::Exception)
8148 {
8149   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8150   if(!content)
8151     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8152   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitDiscretizations();
8153   std::size_t sz(contentsSplit.size());
8154   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8155   for(std::size_t i=0;i<sz;i++)
8156     {
8157       ret[i]=shallowCpy();
8158       ret[i]->_content=contentsSplit[i];
8159     }
8160   return ret;
8161 }
8162
8163 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception)
8164 {
8165   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8166   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8167     ret->_content=_content->deepCpy();
8168   ret->deepCpyGlobs(*this);
8169   return ret.retn();
8170 }
8171
8172 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8173 {
8174   return _content;
8175 }
8176
8177 /*!
8178  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8179  *  \param [in] iteration - the iteration number of a required time step.
8180  *  \param [in] order - the iteration order number of required time step.
8181  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8182  *          delete this field using decrRef() as it is no more needed.
8183  *  \throw If there is no required time step in \a this field.
8184  */
8185 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
8186 {
8187   int pos=getPosOfTimeStep(iteration,order);
8188   return getTimeStepAtPos(pos);
8189 }
8190
8191 /*!
8192  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8193  *  \param [in] time - the time of the time step of interest.
8194  *  \param [in] eps - a precision used to compare time values.
8195  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8196  *          delete this field using decrRef() as it is no more needed.
8197  *  \throw If there is no required time step in \a this field.
8198  */
8199 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
8200 {
8201   int pos=getPosGivenTime(time,eps);
8202   return getTimeStepAtPos(pos);
8203 }
8204
8205 /*!
8206  * This method groups not null items in \a vectFMTS per time step series. Two time series are considered equal if the list of their pair of integers iteration,order are equal.
8207  * The float64 value of time attached to the pair of integers are not considered here.
8208  * 
8209  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8210  * \throw If there is a null pointer in \a vectFMTS.
8211  */
8212 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS) throw(INTERP_KERNEL::Exception)
8213 {
8214   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8215   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8216   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8217   while(!lstFMTS.empty())
8218     {
8219       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8220       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8221       if(!curIt)
8222         throw INTERP_KERNEL::Exception(msg);
8223       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8224       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8225       elt.push_back(curIt); it=lstFMTS.erase(it);
8226       while(it!=lstFMTS.end())
8227         {
8228           curIt=*it;
8229           if(!curIt)
8230             throw INTERP_KERNEL::Exception(msg);
8231           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8232           if(refIts==curIts)
8233             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8234           else
8235             it++;
8236         }
8237       ret.push_back(elt);
8238     }
8239   return ret;
8240 }
8241
8242 /*!
8243  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8244  * All returned instances in a subvector can be safely loaded, rendered along time
8245  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8246  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8247  * All items in \a vectFMTS must lie on the mesh (located by meshname and time step) and compatible with the input mesh \a mesh (having the same name than those in items).
8248  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8249  * For items in \a vectFMTS that are ON_NODES it is possible to appear several times (more than once or once) in the returned vector.
8250  *
8251  * \param [in] vectFMTS - list of multi times step part all defined each on a same spatial discretization along time and pointing to a mesh whose name is equal to \c mesh->getName().
8252  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8253  *
8254  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8255  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8256  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8257  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8258  * \throw If mesh is null.
8259  * \throw If an element in \a vectFMTS is null.
8260  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8261  */
8262 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception)
8263 {
8264   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8265   if(!mesh)
8266     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8267   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8268   if(vectFMTS.empty())
8269     return ret;
8270   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8271   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8272   std::size_t i=0;
8273   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8274   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8275   for(;it!=vectFMTS.end();it++,i++)
8276     {
8277       TypeOfField tof0,tof1;
8278       int ret=CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1);
8279       if(ret>0)
8280         {
8281           if(tof1!=ON_NODES)
8282             vectFMTSNotNodes.push_back(*it);
8283           else
8284             vectFMTSNodes.push_back(*it);
8285         }
8286       else
8287         vectFMTSNotNodes.push_back(*it);
8288     }
8289   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8290   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8291   ret=retCell;
8292   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8293     {
8294       i=0;
8295       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8296         {
8297           if((*it0).empty())
8298             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8299           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8300             ret[i].push_back(*it2);
8301           else
8302             {
8303               std::vector<MEDFileAnyTypeFieldMultiTS *> ret0(1,*it2);
8304               ret.push_back(ret0);
8305             }
8306         }
8307     }
8308   return ret;
8309 }
8310
8311 /*!
8312  * WARNING no check here. The caller must be sure that all items in vectFMTS are coherent each other in time steps, only one same spatial discretization and not ON_NODES.
8313  * \param [out] cmps - same size than the returned vector.
8314  */
8315 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps) throw(INTERP_KERNEL::Exception)
8316 {
8317   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8318   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8319   while(!lstFMTS.empty())
8320     {
8321       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8322       MEDFileAnyTypeFieldMultiTS *ref(*it);
8323       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8324       elt.push_back(ref); it=lstFMTS.erase(it);
8325       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mesh,ref));
8326       while(it!=lstFMTS.end())
8327         {
8328           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8329           if(cmp->isEqual(curIt))
8330             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8331           else
8332             it++;
8333         }
8334       ret.push_back(elt); cmps.push_back(cmp);
8335     }
8336   return ret;
8337 }
8338
8339 /*!
8340  * This method scan the two main structs along time of \a f0 and \a f1 to see if there are all lying on the same mesh along time than those in \a mesh.
8341  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8342  *
8343  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8344  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8345  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8346  * \thorw If \a f0 and \a f1 do not have the same times steps.
8347  * \throw If mesh is null.
8348  * \throw If \a f0 or \a f1 is null.
8349  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8350  */
8351 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1) throw(INTERP_KERNEL::Exception)
8352 {
8353   if(!mesh)
8354     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8355   if(!f0 || !f1)
8356     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8357   if(f0->getMeshName()!=mesh->getName())
8358     {
8359       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8360       throw INTERP_KERNEL::Exception(oss.str().c_str());
8361     }
8362   if(f1->getMeshName()!=mesh->getName())
8363     {
8364       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8365       throw INTERP_KERNEL::Exception(oss.str().c_str());
8366     }
8367   int nts=f0->getNumberOfTS();
8368   if(nts!=f1->getNumberOfTS())
8369     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8370   if(nts==0)
8371     return nts;
8372   for(int i=0;i<nts;i++)
8373     {
8374       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8375       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8376       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8377       if(tofs0.size()!=1 || tofs1.size()!=1)
8378         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8379       if(i!=0)
8380         {
8381           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8382             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8383         }
8384       else
8385         { tof0=tofs0[0]; tof1=tofs1[0]; }
8386       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8387         {
8388           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh time step (" << f0cur->getMeshIteration() << ","<< f0cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !";
8389           throw INTERP_KERNEL::Exception(oss.str().c_str());
8390         }
8391       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8392         {
8393           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh time step (" << f1cur->getMeshIteration() << ","<< f1cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !";
8394           throw INTERP_KERNEL::Exception(oss.str().c_str());
8395         }
8396       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8397         {
8398           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : all the time steps must be the same ! it is not the case (" << f0cur->getIteration() << "," << f0cur->getOrder() << ")!=(" << f1cur->getIteration() << "," << f1cur->getOrder() << ") !";
8399           throw INTERP_KERNEL::Exception(oss.str().c_str());
8400         }
8401     }
8402   return nts;
8403 }
8404
8405 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator() throw(INTERP_KERNEL::Exception)
8406 {
8407   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8408 }
8409
8410 //= MEDFileFieldMultiTS
8411
8412 /*!
8413  * Returns a new empty instance of MEDFileFieldMultiTS.
8414  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8415  *          is to delete this field using decrRef() as it is no more needed.
8416  */
8417 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8418 {
8419   return new MEDFileFieldMultiTS;
8420 }
8421
8422 /*!
8423  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8424  * that has been read from a specified MED file.
8425  *  \param [in] fileName - the name of the MED file to read.
8426  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8427  *          is to delete this field using decrRef() as it is no more needed.
8428  *  \throw If reading the file fails.
8429  */
8430 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
8431 {
8432   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll);
8433   ret->contentNotNull();//to check that content type matches with \a this type.
8434   return ret.retn();
8435 }
8436
8437 /*!
8438  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8439  * that has been read from a specified MED file.
8440  *  \param [in] fileName - the name of the MED file to read.
8441  *  \param [in] fieldName - the name of the field to read.
8442  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8443  *          is to delete this field using decrRef() as it is no more needed.
8444  *  \throw If reading the file fails.
8445  *  \throw If there is no field named \a fieldName in the file.
8446  */
8447 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
8448 {
8449   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll);
8450   ret->contentNotNull();//to check that content type matches with \a this type.
8451   return ret.retn();
8452 }
8453
8454 /*!
8455  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8456  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8457  *
8458  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8459  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8460  * \warning this is a shallow copy constructor
8461  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8462  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8463  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8464  *          is to delete this field using decrRef() as it is no more needed.
8465  */
8466 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8467 {
8468   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8469 }
8470
8471 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const throw(INTERP_KERNEL::Exception)
8472 {
8473   return new MEDFileFieldMultiTS(*this);
8474 }
8475
8476 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception)
8477 {
8478   if(!f1ts)
8479     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8480   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8481   if(!f1tsC)
8482     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8483 }
8484
8485 /*!
8486  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8487  * following the given input policy.
8488  *
8489  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8490  *                            By default (true) the globals are deeply copied.
8491  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8492  */
8493 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
8494 {
8495   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
8496   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8497   if(content)
8498     {
8499       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8500       if(!contc)
8501         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8502       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8503       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
8504     }
8505   else
8506     ret=MEDFileIntFieldMultiTS::New();
8507   if(deepCpyGlobs)
8508     ret->deepCpyGlobs(*this);
8509   else
8510     ret->shallowCpyGlobs(*this);
8511   return ret.retn();
8512 }
8513
8514 /*!
8515  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
8516  *  \param [in] pos - a time step id.
8517  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8518  *          delete this field using decrRef() as it is no more needed.
8519  *  \throw If \a pos is not a valid time step id.
8520  */
8521 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
8522 {
8523   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8524   if(!item)
8525     {
8526       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8527       throw INTERP_KERNEL::Exception(oss.str().c_str());
8528     }
8529   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
8530   if(itemC)
8531     {
8532       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
8533       ret->shallowCpyGlobs(*this);
8534       return ret.retn();
8535     }
8536   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
8537   throw INTERP_KERNEL::Exception(oss.str().c_str());
8538 }
8539
8540 /*!
8541  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8542  * mesh entities of a given dimension of the first mesh in MED file.
8543  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8544  *  \param [in] type - a spatial discretization of interest.
8545  *  \param [in] iteration - the iteration number of a required time step.
8546  *  \param [in] order - the iteration order number of required time step.
8547  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8548  *  \param [in] renumPol - specifies how to permute values of the result field according to
8549  *          the optional numbers of cells and nodes, if any. The valid values are
8550  *          - 0 - do not permute.
8551  *          - 1 - permute cells.
8552  *          - 2 - permute nodes.
8553  *          - 3 - permute cells and nodes.
8554  *
8555  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8556  *          caller is to delete this field using decrRef() as it is no more needed. 
8557  *  \throw If the MED file is not readable.
8558  *  \throw If there is no mesh in the MED file.
8559  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8560  *  \throw If no field values of the required parameters are available.
8561  */
8562 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
8563 {
8564   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8565   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8566   if(!myF1TSC)
8567     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
8568   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8569   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arrOut,*contentNotNullBase());
8570   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8571   return ret.retn();
8572 }
8573
8574 /*!
8575  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8576  * the top level cells of the first mesh in MED file.
8577  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8578  *  \param [in] type - a spatial discretization of interest.
8579  *  \param [in] iteration - the iteration number of a required time step.
8580  *  \param [in] order - the iteration order number of required time step.
8581  *  \param [in] renumPol - specifies how to permute values of the result field according to
8582  *          the optional numbers of cells and nodes, if any. The valid values are
8583  *          - 0 - do not permute.
8584  *          - 1 - permute cells.
8585  *          - 2 - permute nodes.
8586  *          - 3 - permute cells and nodes.
8587  *
8588  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8589  *          caller is to delete this field using decrRef() as it is no more needed. 
8590  *  \throw If the MED file is not readable.
8591  *  \throw If there is no mesh in the MED file.
8592  *  \throw If no field values of the required parameters are available.
8593  */
8594 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const throw(INTERP_KERNEL::Exception)
8595 {
8596   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8597   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8598   if(!myF1TSC)
8599     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
8600   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8601   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,0,renumPol,this,arrOut,*contentNotNullBase());
8602   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8603   return ret.retn();
8604 }
8605
8606 /*!
8607  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8608  * a given support.
8609  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8610  *  \param [in] type - a spatial discretization of interest.
8611  *  \param [in] iteration - the iteration number of a required time step.
8612  *  \param [in] order - the iteration order number of required time step.
8613  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8614  *  \param [in] mesh - the supporting mesh.
8615  *  \param [in] renumPol - specifies how to permute values of the result field according to
8616  *          the optional numbers of cells and nodes, if any. The valid values are
8617  *          - 0 - do not permute.
8618  *          - 1 - permute cells.
8619  *          - 2 - permute nodes.
8620  *          - 3 - permute cells and nodes.
8621  *
8622  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8623  *          caller is to delete this field using decrRef() as it is no more needed. 
8624  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8625  *  \throw If no field of \a this is lying on \a mesh.
8626  *  \throw If no field values of the required parameters are available.
8627  */
8628 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
8629 {
8630   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8631   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8632   if(!myF1TSC)
8633     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8634   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8635   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
8636   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8637   return ret.retn();
8638 }
8639
8640 /*!
8641  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8642  * given support. 
8643  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8644  *  \param [in] type - a spatial discretization of the new field.
8645  *  \param [in] iteration - the iteration number of a required time step.
8646  *  \param [in] order - the iteration order number of required time step.
8647  *  \param [in] mesh - the supporting mesh.
8648  *  \param [in] renumPol - specifies how to permute values of the result field according to
8649  *          the optional numbers of cells and nodes, if any. The valid values are
8650  *          - 0 - do not permute.
8651  *          - 1 - permute cells.
8652  *          - 2 - permute nodes.
8653  *          - 3 - permute cells and nodes.
8654  *
8655  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8656  *          caller is to delete this field using decrRef() as it is no more needed. 
8657  *  \throw If no field of \a this is lying on \a mesh.
8658  *  \throw If no field values of the required parameters are available.
8659  */
8660 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
8661 {
8662   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8663   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8664   if(!myF1TSC)
8665     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8666   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8667   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
8668   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8669   return ret.retn();
8670 }
8671
8672 /*!
8673  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
8674  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8675  * This method is useful for MED2 file format when field on different mesh was autorized.
8676  */
8677 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
8678 {
8679   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8680   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8681   if(!myF1TSC)
8682     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
8683   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8684   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
8685   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8686   return ret.retn();
8687 }
8688
8689 /*!
8690  * Returns values and a profile of the field of a given type, of a given time step,
8691  * lying on a given support.
8692  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8693  *  \param [in] type - a spatial discretization of the field.
8694  *  \param [in] iteration - the iteration number of a required time step.
8695  *  \param [in] order - the iteration order number of required time step.
8696  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8697  *  \param [in] mesh - the supporting mesh.
8698  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8699  *          field of interest lies on. If the field lies on all entities of the given
8700  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8701  *          using decrRef() as it is no more needed.  
8702  *  \param [in] glob - the global data storing profiles and localization.
8703  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
8704  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8705  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8706  *  \throw If no field of \a this is lying on \a mesh.
8707  *  \throw If no field values of the required parameters are available.
8708  */
8709 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
8710 {
8711   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8712   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8713   if(!myF1TSC)
8714     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
8715   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8716   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
8717 }
8718
8719 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const throw(INTERP_KERNEL::Exception)
8720 {
8721   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8722   if(!pt)
8723     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
8724   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
8725   if(!ret)
8726     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 !");
8727   return ret;
8728 }
8729
8730  MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() throw(INTERP_KERNEL::Exception)
8731 {
8732   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8733   if(!pt)
8734     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
8735   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
8736   if(!ret)
8737     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 !");
8738   return ret;
8739 }
8740
8741 /*!
8742  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8743  * the given field is checked if its elements are sorted suitable for writing to MED file
8744  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8745  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8746  *  \param [in] field - the field to add to \a this.
8747  *  \throw If the name of \a field is empty.
8748  *  \throw If the data array of \a field is not set.
8749  *  \throw If existing time steps have different name or number of components than \a field.
8750  *  \throw If the underlying mesh of \a field has no name.
8751  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8752  */
8753 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
8754 {
8755   const DataArrayDouble *arr=0;
8756   if(field)
8757     arr=field->getArray();
8758   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
8759 }
8760
8761 /*!
8762  * Adds a MEDCouplingFieldDouble to \a this as another time step.
8763  * The mesh support of input parameter \a field is ignored here, it can be NULL.
8764  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
8765  * and \a profile.
8766  *
8767  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
8768  * A new profile is added only if no equal profile is missing.
8769  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8770  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
8771  *  \param [in] mesh - the supporting mesh of \a field.
8772  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
8773  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8774  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8775  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8776  *  \throw If the data array of \a field is not set.
8777  *  \throw If the data array of \a this is already allocated but has different number of
8778  *         components than \a field.
8779  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8780  *  \sa setFieldNoProfileSBT()
8781  */
8782 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
8783 {
8784   const DataArrayDouble *arr=0;
8785   if(field)
8786     arr=field->getArray();
8787   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
8788 }
8789
8790 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
8791 {
8792   _content=new MEDFileFieldMultiTSWithoutSDA;
8793 }
8794
8795 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
8796 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
8797 {
8798 }
8799 catch(INTERP_KERNEL::Exception& e)
8800   { throw e; }
8801
8802 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
8803 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
8804 {
8805 }
8806 catch(INTERP_KERNEL::Exception& e)
8807   { throw e; }
8808
8809 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8810 {
8811 }
8812
8813 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)
8814 {
8815   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
8816 }
8817
8818 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
8819 {
8820   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8821 }
8822
8823 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)
8824 {
8825   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
8826 }
8827
8828 //= MEDFileAnyTypeFieldMultiTSIterator
8829
8830 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
8831 {
8832   if(fmts)
8833     {
8834       fmts->incrRef();
8835       _nb_iter=fmts->getNumberOfTS();
8836     }
8837 }
8838
8839 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
8840 {
8841 }
8842
8843 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt() throw(INTERP_KERNEL::Exception)
8844 {
8845   if(_iter_id<_nb_iter)
8846     {
8847       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
8848       if(fmts)
8849         return fmts->getTimeStepAtPos(_iter_id++);
8850       else
8851         return 0;
8852     }
8853   else
8854     return 0;
8855 }
8856
8857 //= MEDFileIntFieldMultiTS
8858
8859 /*!
8860  * Returns a new empty instance of MEDFileFieldMultiTS.
8861  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8862  *          is to delete this field using decrRef() as it is no more needed.
8863  */
8864 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
8865 {
8866   return new MEDFileIntFieldMultiTS;
8867 }
8868
8869 /*!
8870  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
8871  * that has been read from a specified MED file.
8872  *  \param [in] fileName - the name of the MED file to read.
8873  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8874  *          is to delete this field using decrRef() as it is no more needed.
8875  *  \throw If reading the file fails.
8876  */
8877 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
8878 {
8879   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll);
8880   ret->contentNotNull();//to check that content type matches with \a this type.
8881   return ret.retn();
8882 }
8883
8884 /*!
8885  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
8886  * that has been read from a specified MED file.
8887  *  \param [in] fileName - the name of the MED file to read.
8888  *  \param [in] fieldName - the name of the field to read.
8889  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8890  *          is to delete this field using decrRef() as it is no more needed.
8891  *  \throw If reading the file fails.
8892  *  \throw If there is no field named \a fieldName in the file.
8893  */
8894 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
8895 {
8896   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll);
8897   ret->contentNotNull();//to check that content type matches with \a this type.
8898   return ret.retn();
8899 }
8900
8901 /*!
8902  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8903  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8904  *
8905  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
8906  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8907  * \warning this is a shallow copy constructor
8908  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
8909  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8910  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8911  *          is to delete this field using decrRef() as it is no more needed.
8912  */
8913 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8914 {
8915   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
8916 }
8917
8918 /*!
8919  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
8920  * following the given input policy.
8921  *
8922  * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8923  *                            By default (true) the globals are deeply copied.
8924  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
8925  */
8926 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception)
8927 {
8928   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
8929   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8930   if(content)
8931     {
8932       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
8933       if(!contc)
8934         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
8935       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
8936       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
8937     }
8938   else
8939     ret=MEDFileFieldMultiTS::New();
8940   if(deepCpyGlobs)
8941     ret->deepCpyGlobs(*this);
8942   else
8943     ret->shallowCpyGlobs(*this);
8944   return ret.retn();
8945 }
8946
8947 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const throw(INTERP_KERNEL::Exception)
8948 {
8949   return new MEDFileIntFieldMultiTS(*this);
8950 }
8951
8952 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception)
8953 {
8954   if(!f1ts)
8955     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8956   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
8957   if(!f1tsC)
8958     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8959 }
8960
8961 /*!
8962  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8963  * mesh entities of a given dimension of the first mesh in MED file.
8964  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8965  *  \param [in] type - a spatial discretization of interest.
8966  *  \param [in] iteration - the iteration number of a required time step.
8967  *  \param [in] order - the iteration order number of required time step.
8968  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8969  *  \param [out] arrOut - the DataArrayInt containing values of field.
8970  *  \param [in] renumPol - specifies how to permute values of the result field according to
8971  *          the optional numbers of cells and nodes, if any. The valid values are
8972  *          - 0 - do not permute.
8973  *          - 1 - permute cells.
8974  *          - 2 - permute nodes.
8975  *          - 3 - permute cells and nodes.
8976  *
8977  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8978  *          caller is to delete this field using decrRef() as it is no more needed. 
8979  *  \throw If the MED file is not readable.
8980  *  \throw If there is no mesh in the MED file.
8981  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8982  *  \throw If no field values of the required parameters are available.
8983  */
8984 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
8985 {
8986   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8987   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
8988   if(!myF1TSC)
8989     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
8990   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
8991   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this,arr,*contentNotNullBase());
8992   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
8993   return ret.retn();
8994 }
8995
8996 /*!
8997  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8998  * the top level cells of the first mesh in MED file.
8999  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9000  *  \param [in] type - a spatial discretization of interest.
9001  *  \param [in] iteration - the iteration number of a required time step.
9002  *  \param [in] order - the iteration order number of required time step.
9003  *  \param [out] arrOut - the DataArrayInt containing values of field.
9004  *  \param [in] renumPol - specifies how to permute values of the result field according to
9005  *          the optional numbers of cells and nodes, if any. The valid values are
9006  *          - 0 - do not permute.
9007  *          - 1 - permute cells.
9008  *          - 2 - permute nodes.
9009  *          - 3 - permute cells and nodes.
9010  *
9011  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9012  *          caller is to delete this field using decrRef() as it is no more needed. 
9013  *  \throw If the MED file is not readable.
9014  *  \throw If there is no mesh in the MED file.
9015  *  \throw If no field values of the required parameters are available.
9016  */
9017 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
9018 {
9019   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9020   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9021   if(!myF1TSC)
9022     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9023   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9024   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,0,renumPol,this,arr,*contentNotNullBase());
9025   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9026   return ret.retn();
9027 }
9028
9029 /*!
9030  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9031  * a given support.
9032  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9033  *  \param [in] type - a spatial discretization of interest.
9034  *  \param [in] iteration - the iteration number of a required time step.
9035  *  \param [in] order - the iteration order number of required time step.
9036  *  \param [out] arrOut - the DataArrayInt containing values of field.
9037  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9038  *  \param [in] mesh - the supporting mesh.
9039  *  \param [in] renumPol - specifies how to permute values of the result field according to
9040  *          the optional numbers of cells and nodes, if any. The valid values are
9041  *          - 0 - do not permute.
9042  *          - 1 - permute cells.
9043  *          - 2 - permute nodes.
9044  *          - 3 - permute cells and nodes.
9045  *
9046  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9047  *          caller is to delete this field using decrRef() as it is no more needed. 
9048  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9049  *  \throw If no field of \a this is lying on \a mesh.
9050  *  \throw If no field values of the required parameters are available.
9051  */
9052 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
9053 {
9054   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9055   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9056   if(!myF1TSC)
9057     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9058   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9059   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9060   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9061   return ret.retn();
9062 }
9063
9064 /*!
9065  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9066  * given support. 
9067  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9068  *  \param [in] type - a spatial discretization of the new field.
9069  *  \param [in] iteration - the iteration number of a required time step.
9070  *  \param [in] order - the iteration order number of required time step.
9071  *  \param [in] mesh - the supporting mesh.
9072  *  \param [out] arrOut - the DataArrayInt containing values of field.
9073  *  \param [in] renumPol - specifies how to permute values of the result field according to
9074  *          the optional numbers of cells and nodes, if any. The valid values are
9075  *          - 0 - do not permute.
9076  *          - 1 - permute cells.
9077  *          - 2 - permute nodes.
9078  *          - 3 - permute cells and nodes.
9079  *
9080  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9081  *          caller is to delete this field using decrRef() as it is no more needed. 
9082  *  \throw If no field of \a this is lying on \a mesh.
9083  *  \throw If no field values of the required parameters are available.
9084  */
9085 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
9086 {
9087   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9088   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9089   if(!myF1TSC)
9090     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9091   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9092   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9093   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9094   return ret.retn();
9095 }
9096
9097 /*!
9098  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9099  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9100  * This method is useful for MED2 file format when field on different mesh was autorized.
9101  */
9102 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const char *mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const throw(INTERP_KERNEL::Exception)
9103 {
9104   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9105   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9106   if(!myF1TSC)
9107     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9108   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9109   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9110   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9111   return ret.retn();
9112 }
9113
9114 /*!
9115  * Returns values and a profile of the field of a given type, of a given time step,
9116  * lying on a given support.
9117  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9118  *  \param [in] type - a spatial discretization of the field.
9119  *  \param [in] iteration - the iteration number of a required time step.
9120  *  \param [in] order - the iteration order number of required time step.
9121  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9122  *  \param [in] mesh - the supporting mesh.
9123  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9124  *          field of interest lies on. If the field lies on all entities of the given
9125  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9126  *          using decrRef() as it is no more needed.  
9127  *  \param [in] glob - the global data storing profiles and localization.
9128  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9129  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9130  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9131  *  \throw If no field of \a this is lying on \a mesh.
9132  *  \throw If no field values of the required parameters are available.
9133  */
9134 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
9135 {
9136   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9137   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9138   if(!myF1TSC)
9139     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9140   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9141   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9142 }
9143
9144 /*!
9145  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9146  *  \param [in] pos - a time step id.
9147  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9148  *          delete this field using decrRef() as it is no more needed.
9149  *  \throw If \a pos is not a valid time step id.
9150  */
9151 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
9152 {
9153   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9154   if(!item)
9155     {
9156       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9157       throw INTERP_KERNEL::Exception(oss.str().c_str());
9158     }
9159   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9160   if(itemC)
9161     {
9162       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9163       ret->shallowCpyGlobs(*this);
9164       return ret.retn();
9165     }
9166   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9167   throw INTERP_KERNEL::Exception(oss.str().c_str());
9168 }
9169
9170 /*!
9171  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9172  * the given field is checked if its elements are sorted suitable for writing to MED file
9173  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9174  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9175  *  \param [in] field - the field to add to \a this.
9176  *  \throw If the name of \a field is empty.
9177  *  \throw If the data array of \a field is not set.
9178  *  \throw If existing time steps have different name or number of components than \a field.
9179  *  \throw If the underlying mesh of \a field has no name.
9180  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9181  */
9182 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception)
9183 {
9184   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9185 }
9186
9187 /*!
9188  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9189  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9190  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9191  * and \a profile.
9192  *
9193  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9194  * A new profile is added only if no equal profile is missing.
9195  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9196  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9197  *  \param [in] arrOfVals - the values of the field \a field used.
9198  *  \param [in] mesh - the supporting mesh of \a field.
9199  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9200  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9201  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9202  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9203  *  \throw If the data array of \a field is not set.
9204  *  \throw If the data array of \a this is already allocated but has different number of
9205  *         components than \a field.
9206  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9207  *  \sa setFieldNoProfileSBT()
9208  */
9209 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
9210 {
9211   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9212 }
9213
9214 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const throw(INTERP_KERNEL::Exception)
9215 {
9216   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9217   if(!pt)
9218     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9219   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9220   if(!ret)
9221     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 !");
9222   return ret;
9223 }
9224
9225  MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() throw(INTERP_KERNEL::Exception)
9226 {
9227   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9228   if(!pt)
9229     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9230   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9231   if(!ret)
9232     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 !");
9233   return ret;
9234 }
9235
9236 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9237 {
9238   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9239 }
9240
9241 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9242 {
9243 }
9244
9245 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
9246 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
9247 {
9248 }
9249 catch(INTERP_KERNEL::Exception& e)
9250   { throw e; }
9251
9252 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const char *fileName, const char *fieldName, bool loadAll) throw(INTERP_KERNEL::Exception)
9253 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
9254 {
9255 }
9256 catch(INTERP_KERNEL::Exception& e)
9257   { throw e; }
9258
9259 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
9260 {
9261   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9262 }
9263
9264 //= MEDFileFields
9265
9266 MEDFileFields *MEDFileFields::New()
9267 {
9268   return new MEDFileFields;
9269 }
9270
9271 MEDFileFields *MEDFileFields::New(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
9272 {
9273   return new MEDFileFields(fileName,loadAll);
9274 }
9275
9276 std::size_t MEDFileFields::getHeapMemorySize() const
9277 {
9278   std::size_t ret=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9279   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9280     if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it)
9281       ret+=(*it)->getHeapMemorySize();
9282   return ret+MEDFileFieldGlobsReal::getHeapMemorySize();
9283 }
9284
9285 MEDFileFields *MEDFileFields::deepCpy() const throw(INTERP_KERNEL::Exception)
9286 {
9287   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9288   std::size_t i=0;
9289   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9290     {
9291       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9292         ret->_fields[i]=(*it)->deepCpy();
9293     }
9294   ret->deepCpyGlobs(*this);
9295   return ret.retn();
9296 }
9297
9298 MEDFileFields *MEDFileFields::shallowCpy() const throw(INTERP_KERNEL::Exception)
9299 {
9300   return new MEDFileFields(*this);
9301 }
9302
9303 /*!
9304  * 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
9305  * 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.
9306  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9307  *
9308  * \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.
9309  * \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.
9310  * 
9311  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9312  */
9313 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const throw(INTERP_KERNEL::Exception)
9314 {
9315   std::set< std::pair<int,int> > s;
9316   bool firstShot=true;
9317   areThereSomeForgottenTS=false;
9318   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9319     {
9320       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9321         continue;
9322       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9323       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9324       if(firstShot)
9325         { s=s1; firstShot=false; }
9326       else
9327         {
9328           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9329           if(s!=s2)
9330             areThereSomeForgottenTS=true;
9331           s=s2;
9332         }
9333     }
9334   std::vector< std::pair<int,int> > ret;
9335   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9336   return ret;
9337 }
9338
9339 int MEDFileFields::getNumberOfFields() const
9340 {
9341   return _fields.size();
9342 }
9343
9344 std::vector<std::string> MEDFileFields::getFieldsNames() const throw(INTERP_KERNEL::Exception)
9345 {
9346   std::vector<std::string> ret(_fields.size());
9347   int i=0;
9348   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9349     {
9350       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9351       if(f)
9352         {
9353           ret[i]=f->getName();
9354         }
9355       else
9356         {
9357           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9358           throw INTERP_KERNEL::Exception(oss.str().c_str());
9359         }
9360     }
9361   return ret;
9362 }
9363
9364 std::vector<std::string> MEDFileFields::getMeshesNames() const throw(INTERP_KERNEL::Exception)
9365 {
9366   std::vector<std::string> ret;
9367   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9368     {
9369       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9370       if(cur)
9371         ret.push_back(cur->getMeshName());
9372     }
9373   return ret;
9374 }
9375
9376 std::string MEDFileFields::simpleRepr() const
9377 {
9378   std::ostringstream oss;
9379   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9380   simpleRepr(0,oss);
9381   return oss.str();
9382 }
9383
9384 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9385 {
9386   int nbOfFields=getNumberOfFields();
9387   std::string startLine(bkOffset,' ');
9388   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9389   int i=0;
9390   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9391     {
9392       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9393       if(cur)
9394         {
9395           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9396         }
9397       else
9398         {
9399           oss << startLine << "  - not defined !" << std::endl;
9400         }
9401     }
9402   i=0;
9403   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9404     {
9405       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9406       std::string chapter(17,'0'+i);
9407       oss << startLine << chapter << std::endl;
9408       if(cur)
9409         {
9410           cur->simpleRepr(bkOffset+2,oss,i);
9411         }
9412       else
9413         {
9414           oss << startLine << "  - not defined !" << std::endl;
9415         }
9416       oss << startLine << chapter << std::endl;
9417     }
9418   simpleReprGlobs(oss);
9419 }
9420
9421 MEDFileFields::MEDFileFields()
9422 {
9423 }
9424
9425 MEDFileFields::MEDFileFields(const char *fileName, bool loadAll) throw(INTERP_KERNEL::Exception)
9426 try:MEDFileFieldGlobsReal(fileName)
9427   {
9428     MEDFileUtilities::CheckFileForRead(fileName);
9429     MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
9430     int nbFields=MEDnField(fid);
9431     _fields.resize(nbFields);
9432     med_field_type typcha;
9433     for(int i=0;i<nbFields;i++)
9434       {
9435         std::vector<std::string> infos;
9436         std::string fieldName,dtunit;
9437         int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit);
9438         switch(typcha)
9439           {
9440           case MED_FLOAT64:
9441             {
9442               _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
9443               break;
9444             }
9445           case MED_INT32:
9446             {
9447               _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
9448               break;
9449             }
9450           default:
9451             {
9452               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] !";
9453               throw INTERP_KERNEL::Exception(oss.str().c_str());
9454             }
9455           }
9456       }
9457     loadAllGlobals(fid);
9458   }
9459 catch(INTERP_KERNEL::Exception& e)
9460   {
9461     throw e;
9462   }
9463
9464 void MEDFileFields::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
9465 {
9466   int i=0;
9467   writeGlobals(fid,*this);
9468   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9469     {
9470       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9471       if(!elt)
9472         {
9473           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9474           throw INTERP_KERNEL::Exception(oss.str().c_str());
9475         }
9476       elt->writeLL(fid,*this);
9477     }
9478 }
9479
9480 void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
9481 {
9482   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
9483   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
9484   writeLL(fid);
9485 }
9486
9487 /*!
9488  * This method alloc the arrays and load potentially huge arrays contained in this field.
9489  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9490  * This method can be also called to refresh or reinit values from a file.
9491  * 
9492  * \throw If the fileName is not set or points to a non readable MED file.
9493  */
9494 void MEDFileFields::loadArrays() throw(INTERP_KERNEL::Exception)
9495 {
9496   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
9497   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9498     {
9499       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9500       if(elt)
9501         elt->loadBigArraysRecursively(fid,*elt);
9502     }
9503 }
9504
9505 /*!
9506  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9507  * But once data loaded once, this method does nothing.
9508  * 
9509  * \throw If the fileName is not set or points to a non readable MED file.
9510  * \sa MEDFileFields::loadArrays, MEDFileFields::releaseArrays
9511  */
9512 void MEDFileFields::loadArraysIfNecessary() throw(INTERP_KERNEL::Exception)
9513 {
9514   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
9515   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9516     {
9517       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9518       if(elt)
9519         elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9520     }
9521 }
9522
9523 /*!
9524  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9525  * This method does not release arrays set outside the context of a MED file.
9526  * 
9527  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary
9528  */
9529 void MEDFileFields::releaseArrays() throw(INTERP_KERNEL::Exception)
9530 {
9531   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName(),MED_ACC_RDONLY);
9532   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9533     {
9534       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9535       if(elt)
9536         elt->releaseArrays();
9537     }
9538 }
9539
9540 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9541 {
9542   std::vector<std::string> ret;
9543   std::set<std::string> ret2;
9544   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9545     {
9546       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9547       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9548         if(ret2.find(*it2)==ret2.end())
9549           {
9550             ret.push_back(*it2);
9551             ret2.insert(*it2);
9552           }
9553     }
9554   return ret;
9555 }
9556
9557 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9558 {
9559   std::vector<std::string> ret;
9560   std::set<std::string> ret2;
9561   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9562     {
9563       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9564       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9565         if(ret2.find(*it2)==ret2.end())
9566           {
9567             ret.push_back(*it2);
9568             ret2.insert(*it2);
9569           }
9570     }
9571   return ret;
9572 }
9573
9574 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
9575 {
9576   std::vector<std::string> ret;
9577   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9578     {
9579       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
9580       ret.insert(ret.end(),tmp.begin(),tmp.end());
9581     }
9582   return ret;
9583 }
9584
9585 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
9586 {
9587   std::vector<std::string> ret;
9588   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9589     {
9590       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9591       ret.insert(ret.end(),tmp.begin(),tmp.end());
9592     }
9593   return ret;
9594 }
9595
9596 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
9597 {
9598   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9599     (*it)->changePflsRefsNamesGen2(mapOfModif);
9600 }
9601
9602 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
9603 {
9604   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9605     (*it)->changeLocsRefsNamesGen2(mapOfModif);
9606 }
9607
9608 void MEDFileFields::resize(int newSize) throw(INTERP_KERNEL::Exception)
9609 {
9610   _fields.resize(newSize);
9611 }
9612
9613 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields) throw(INTERP_KERNEL::Exception)
9614 {
9615   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
9616     pushField(*it);
9617 }
9618
9619 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
9620 {
9621   if(!field)
9622     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
9623   _fields.push_back(field->getContent());
9624   appendGlobs(*field,1e-12);
9625 }
9626
9627 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
9628 {
9629   if(!field)
9630     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9631   if(i>=(int)_fields.size())
9632     _fields.resize(i+1);
9633   _fields[i]=field->getContent();
9634   appendGlobs(*field,1e-12);
9635 }
9636
9637 void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception)
9638 {
9639   destroyFieldsAtPos(&i,&i+1);
9640 }
9641
9642 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
9643 {
9644   std::vector<bool> b(_fields.size(),true);
9645   for(const int *i=startIds;i!=endIds;i++)
9646     {
9647       if(*i<0 || *i>=(int)_fields.size())
9648         {
9649           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9650           throw INTERP_KERNEL::Exception(oss.str().c_str());
9651         }
9652       b[*i]=false;
9653     }
9654   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9655   std::size_t j=0;
9656   for(std::size_t i=0;i<_fields.size();i++)
9657     if(b[i])
9658       fields[j++]=_fields[i];
9659   _fields=fields;
9660 }
9661
9662 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step) throw(INTERP_KERNEL::Exception)
9663 {
9664   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9665   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
9666   std::vector<bool> b(_fields.size(),true);
9667   int k=bg;
9668   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9669     {
9670       if(k<0 || k>=(int)_fields.size())
9671         {
9672           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9673           throw INTERP_KERNEL::Exception(oss.str().c_str());
9674         }
9675       b[k]=false;
9676     }
9677   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9678   std::size_t j=0;
9679   for(std::size_t i=0;i<_fields.size();i++)
9680     if(b[i])
9681       fields[j++]=_fields[i];
9682   _fields=fields;
9683 }
9684
9685 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
9686 {
9687   bool ret=false;
9688   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9689     {
9690       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9691       if(cur)
9692         ret=cur->changeMeshNames(modifTab) || ret;
9693     }
9694   return ret;
9695 }
9696
9697 /*!
9698  * \param [in] meshName the name of the mesh that will be renumbered.
9699  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9700  *             This code corresponds to the distribution of types in the corresponding mesh.
9701  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9702  * \param [in] renumO2N the old to new renumber array.
9703  * \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 
9704  *         field in \a this.
9705  */
9706 bool MEDFileFields::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N) throw(INTERP_KERNEL::Exception)
9707 {
9708   bool ret=false;
9709   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9710     {
9711       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9712       if(fmts)
9713         {
9714           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9715         }
9716     }
9717   return ret;
9718 }
9719
9720 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception)
9721 {
9722   if(i<0 || i>=(int)_fields.size())
9723     {
9724       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9725       throw INTERP_KERNEL::Exception(oss.str().c_str());
9726     }
9727   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9728   if(!fmts)
9729     return 0;
9730   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
9731   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
9732   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
9733   if(fmtsC)
9734     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9735   else if(fmtsC2)
9736     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9737   else
9738     {
9739       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
9740       throw INTERP_KERNEL::Exception(oss.str().c_str());
9741     }
9742   ret->shallowCpyGlobs(*this);
9743   return ret.retn();
9744 }
9745
9746 /*!
9747  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9748  * This method is accessible in python using __getitem__ with a list in input.
9749  * \return a new object that the caller should deal with.
9750  */
9751 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const throw(INTERP_KERNEL::Exception)
9752 {
9753   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9754   std::size_t sz=std::distance(startIds,endIds);
9755   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9756   int j=0;
9757   for(const int *i=startIds;i!=endIds;i++,j++)
9758     {
9759       if(*i<0 || *i>=(int)_fields.size())
9760         {
9761           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9762           throw INTERP_KERNEL::Exception(oss.str().c_str());
9763         }
9764       fields[j]=_fields[*i];
9765     }
9766   ret->_fields=fields;
9767   return ret.retn();
9768 }
9769
9770 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
9771 {
9772   return getFieldAtPos(getPosFromFieldName(fieldName));
9773 }
9774
9775 /*!
9776  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9777  * This method can be seen as a filter applied on \a this, that returns an object containing
9778  * 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
9779  * shallow copied from \a this.
9780  * 
9781  * \param [in] meshName - the name of the mesh on w
9782  * \return a new object that the caller should deal with.
9783  */
9784 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const char *meshName) const throw(INTERP_KERNEL::Exception)
9785 {
9786   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9787   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9788     {
9789       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9790       if(!cur)
9791         continue;
9792       if(cur->getMeshName()==meshName)
9793         {
9794           cur->incrRef();
9795           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
9796           ret->_fields.push_back(cur2);
9797         }
9798     }
9799   ret->shallowCpyOnlyUsedGlobs(*this);
9800   return ret.retn();
9801 }
9802
9803 /*!
9804  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
9805  * Input time steps are specified using a pair of integer (iteration, order).
9806  * 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,
9807  * but for each multitimestep only the time steps in \a timeSteps are kept.
9808  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
9809  * 
9810  * The returned object points to shallow copy of elements in \a this.
9811  * 
9812  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
9813  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
9814  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9815  */
9816 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
9817 {
9818   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9819   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9820     {
9821       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9822       if(!cur)
9823         continue;
9824       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
9825       ret->_fields.push_back(elt);
9826     }
9827   ret->shallowCpyOnlyUsedGlobs(*this);
9828   return ret.retn();
9829 }
9830
9831 /*!
9832  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
9833  */
9834 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const throw(INTERP_KERNEL::Exception)
9835 {
9836   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9837   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9838     {
9839       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9840       if(!cur)
9841         continue;
9842       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
9843       if(elt->getNumberOfTS()!=0)
9844         ret->_fields.push_back(elt);
9845     }
9846   ret->shallowCpyOnlyUsedGlobs(*this);
9847   return ret.retn();
9848 }
9849
9850 MEDFileFieldsIterator *MEDFileFields::iterator() throw(INTERP_KERNEL::Exception)
9851 {
9852   return new MEDFileFieldsIterator(this);
9853 }
9854
9855 int MEDFileFields::getPosFromFieldName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
9856 {
9857   std::string tmp(fieldName);
9858   std::vector<std::string> poss;
9859   for(std::size_t i=0;i<_fields.size();i++)
9860     {
9861       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
9862       if(f)
9863         {
9864           std::string fname(f->getName());
9865           if(tmp==fname)
9866             return i;
9867           else
9868             poss.push_back(fname);
9869         }
9870     }
9871   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
9872   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
9873   oss << " !";
9874   throw INTERP_KERNEL::Exception(oss.str().c_str());
9875 }
9876
9877 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
9878 {
9879   if(fs)
9880     {
9881       fs->incrRef();
9882       _nb_iter=fs->getNumberOfFields();
9883     }
9884 }
9885
9886 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
9887 {
9888 }
9889
9890 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
9891 {
9892   if(_iter_id<_nb_iter)
9893     {
9894       MEDFileFields *fs(_fs);
9895       if(fs)
9896         return fs->getFieldAtPos(_iter_id++);
9897       else
9898         return 0;
9899     }
9900   else
9901     return 0;
9902 }