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