Salome HOME
Safe call of MEDfile functions.
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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 "MEDFileSafeCaller.txx"
26 #include "MEDFileFieldOverView.hxx"
27
28 #include "MEDCouplingFieldDouble.hxx"
29 #include "MEDCouplingFieldDiscretization.hxx"
30
31 #include "InterpKernelAutoPtr.hxx"
32 #include "CellModel.hxx"
33
34 #include <algorithm>
35 #include <iterator>
36
37 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
38 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
39 extern med_geometry_type typmainoeud[1];
40 extern med_geometry_type typmai3[34];
41
42 using namespace ParaMEDMEM;
43
44 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
45 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
46
47 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
48 {
49   return new MEDFileFieldLoc(fid,locName);
50 }
51
52 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
53 {
54   return new MEDFileFieldLoc(fid,id);
55 }
56
57 MEDFileFieldLoc *MEDFileFieldLoc::New(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
58 {
59   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
60 }
61
62 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
63 {
64   med_geometry_type geotype;
65   med_geometry_type sectiongeotype;
66   int nsectionmeshcell;
67   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
68   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
69   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
70   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
71   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
72   _nb_node_per_cell=cm.getNumberOfNodes();
73   _ref_coo.resize(_dim*_nb_node_per_cell);
74   _gs_coo.resize(_dim*_nb_gauss_pt);
75   _w.resize(_nb_gauss_pt);
76   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
77 }
78
79 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
80 {
81   med_geometry_type geotype;
82   med_geometry_type sectiongeotype;
83   int nsectionmeshcell;
84   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
85   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
86   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
87   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
88   _name=locName;
89   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
90   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
91   _nb_node_per_cell=cm.getNumberOfNodes();
92   _ref_coo.resize(_dim*_nb_node_per_cell);
93   _gs_coo.resize(_dim*_nb_gauss_pt);
94   _w.resize(_nb_gauss_pt);
95   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
96 }
97
98 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
99                                  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),
100                                      _w(w)
101 {
102   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
103   _dim=cm.getDimension();
104   _nb_node_per_cell=cm.getNumberOfNodes();
105   _nb_gauss_pt=_w.size();
106 }
107
108 MEDFileFieldLoc *MEDFileFieldLoc::deepCpy() const
109 {
110   return new MEDFileFieldLoc(*this);
111 }
112
113 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
114 {
115   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
116 }
117
118 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
119 {
120   return std::vector<const BigMemoryObject *>();
121 }
122
123 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
124 {
125   static const char OFF7[]="\n    ";
126   oss << "\"" << _name << "\"" << OFF7;
127   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
128   oss << "Dimension=" << _dim << OFF7;
129   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
130   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
131   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
132   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
133   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
134 }
135
136 void MEDFileFieldLoc::setName(const std::string& name)
137 {
138   _name=name;
139 }
140
141 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
142 {
143   if(_name!=other._name)
144     return false;
145   if(_dim!=other._dim)
146     return false;
147   if(_nb_gauss_pt!=other._nb_gauss_pt)
148     return false;
149   if(_nb_node_per_cell!=other._nb_node_per_cell)
150     return false;
151   if(_geo_type!=other._geo_type)
152     return false;
153   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
154     return false;
155   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
156     return false;
157   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
158     return false;
159
160   return true;
161 }
162
163 void MEDFileFieldLoc::writeLL(med_idt fid) const
164 {
165   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);
166 }
167
168 std::string MEDFileFieldLoc::repr() const
169 {
170   std::ostringstream oss; oss.precision(15);
171   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
172   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
173   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
174   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
175   oss << "\n  - Ref coords are : ";
176   int sz=_ref_coo.size();
177   if(sz%_dim==0)
178     {
179       int nbOfTuples=sz/_dim;
180       for(int i=0;i<nbOfTuples;i++)
181         {
182           oss << "(";
183           for(int j=0;j<_dim;j++)
184             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
185           oss << ") ";
186         }
187     }
188   else
189     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
190   oss << "\n  - Gauss coords in reference element : ";
191   sz=_gs_coo.size();
192   if(sz%_dim==0)
193     {
194       int nbOfTuples=sz/_dim;
195       for(int i=0;i<nbOfTuples;i++)
196         {
197           oss << "(";
198           for(int j=0;j<_dim;j++)
199             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
200           oss << ") ";
201         }
202     }
203   else
204     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
205   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
206   return oss.str();
207 }
208
209 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
210 {
211   _type=field->getTypeOfField();
212   _start=start;
213   switch(_type)
214   {
215     case ON_CELLS:
216       {
217         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,offset,offset+nbOfCells,1);
218         _end=_start+nbOfCells;
219         _nval=nbOfCells;
220         break;
221       }
222     case ON_GAUSS_NE:
223       {
224         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
225         const int *arrPtr=arr->getConstPointer();
226         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
227         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
228         _nval=nbOfCells;
229         break;
230       }
231     case ON_GAUSS_PT:
232       {
233         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
234         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
235         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
236         if(!disc2)
237           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
238         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
239         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
240         const int *dai2Ptr=dai2->getConstPointer();
241         int nbi=gsLoc.getWeights().size();
242         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=dai->selectByTupleId2(offset,offset+nbOfCells,1);
243         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
244         const int *da3Ptr=da3->getConstPointer();
245         if(da3->getNumberOfTuples()!=nbOfCells)
246           {//profile : for gauss even in NoProfile !!!
247             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
248             _profile=oss.str();
249             da3->setName(_profile.c_str());
250             glob.appendProfile(da3);
251           }
252         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=DataArrayInt::New();
253         _nval=da3->getNbOfElems();
254         da4->alloc(_nval*nbi,1);
255         int *da4Ptr=da4->getPointer();
256         for(int i=0;i<_nval;i++)
257           {
258             int ref=dai2Ptr[offset+da3Ptr[i]];
259             for(int j=0;j<nbi;j++)
260               *da4Ptr++=ref+j;
261           }
262         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
263         _localization=oss2.str();
264         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
265         _end=_start+_nval*nbi;
266         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
267         break;
268       }
269     default:
270       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
271   }
272   start=_end;
273 }
274
275 /*!
276  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
277  * \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).
278  * \param [in] multiTypePfl is the end user profile specified in high level API
279  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
280  * \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.
281  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
282  * \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.
283  */
284 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, 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)
285 {
286   _profile.clear();
287   _type=field->getTypeOfField();
288   std::string pflName(multiTypePfl->getName());
289   std::ostringstream oss; oss << pflName;
290   if(_type!=ON_NODES)
291     {
292       if(!isPflAlone)
293         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
294     }
295   else
296     { oss << "_NODE"; }
297   if(locIds)
298     {
299       if(pflName.empty())
300         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
301       if(_type!=ON_GAUSS_PT)
302         {
303           locIds->setName(oss.str().c_str());
304           glob.appendProfile(locIds);
305           _profile=oss.str();
306         }
307     }
308   _start=start;
309   switch(_type)
310   {
311     case ON_NODES:
312       {
313         _nval=idsInPfl->getNumberOfTuples();
314         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,arrr->getNumberOfTuples(),1);
315         _end=_start+_nval;
316         break;
317       }
318     case ON_CELLS:
319       {
320         _nval=idsInPfl->getNumberOfTuples();
321         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
322         _end=_start+_nval;
323         break;
324       }
325     case ON_GAUSS_NE:
326       {
327         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
328         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr->deltaShiftIndex();
329         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
330         arr3->computeOffsets2();
331         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
332         int trueNval=tmp->getNumberOfTuples();
333         _nval=idsInPfl->getNumberOfTuples();
334         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
335         _end=_start+trueNval;
336         break;
337       }
338     case ON_GAUSS_PT:
339       {
340         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
341         if(!disc2)
342           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
343         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
344         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
345         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
346         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
347         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
348         //
349         MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
350         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
351         //
352         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New();
353         int trueNval=0;
354         for(const int *pt=da4->begin();pt!=da4->end();pt++)
355           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
356         tmp->alloc(trueNval,1);
357         int *tmpPtr=tmp->getPointer();
358         for(const int *pt=da4->begin();pt!=da4->end();pt++)
359           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
360             *tmpPtr++=j;
361         //
362         _nval=da4->getNumberOfTuples();
363         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
364         _end=_start+trueNval;
365         oss << "_loc_" << _loc_id;
366         if(locIds)
367           {
368             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
369             da5->setName(oss.str().c_str());
370             glob.appendProfile(da5);
371             _profile=oss.str();
372           }
373         else
374           {
375             if(da3->getNumberOfTuples()!=nbOfEltsInWholeMesh || !da3->isIdentity())
376               {
377                 da3->setName(oss.str().c_str());
378                 glob.appendProfile(da3);
379                 _profile=oss.str();
380               }
381           }
382         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
383         _localization=oss2.str();
384         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
385         break;
386       }
387     default:
388       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
389   }
390   start=_end;
391 }
392
393 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
394 {
395   _start=start;
396   _nval=arrr->getNumberOfTuples();
397   getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,_nval,1);
398   _end=_start+_nval;
399   start=_end;
400 }
401
402 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
403 {
404   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
405 }
406
407 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
408 {
409   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
410 }
411
412 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
413 {
414   return new MEDFileFieldPerMeshPerTypePerDisc(other);
415 }
416
417 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
418 {
419   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
420 }
421
422 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
423 {
424   std::vector<const BigMemoryObject *> ret(1);
425   ret[0]=(const PartDefinition*)_pd;
426   return ret;
427 }
428
429 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const
430 {
431   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
432   ret->_father=father;
433   return ret.retn();
434 }
435
436 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
437 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
438 {
439   if(pd)
440     pd->incrRef();
441 }
442 catch(INTERP_KERNEL::Exception& e)
443 {
444     throw e;
445 }
446
447 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
448 {
449 }
450
451 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& other):RefCountObject(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),_profile_it(other._profile_it),_pd(other._pd),_tmp_work1(other._tmp_work1)
452 {
453 }
454
455 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
456     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
457 {
458 }
459
460 void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const std::string& fieldName, int nbOfCompo, int iteration, int order, med_entity_type menti, med_geometry_type mgeoti, unsigned char *startFeedingPtr)
461 {
462   const PartDefinition *pd(_pd);
463   if(!pd)
464     {
465       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
466       int nbi,tmp1;
467       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
468       if(_end-_start!=nbValsInFile*nbi)
469         {
470           std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
471           throw INTERP_KERNEL::Exception(oss.str().c_str());
472         }
473       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
474     }
475   else
476     {
477       if(!_profile.empty())
478         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
479       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
480       int profilesize,nbi;
481       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
482       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
483       if(spd)
484         {
485           int start,stop,step;
486           spd->getSlice(start,stop,step);
487           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
488           med_filter filter=MED_FILTER_INIT;
489           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
490                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
491                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
492                                    /*lastblocksize=useless because count=1*/0,&filter);
493           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
494           MEDfilterClose(&filter);
495           return ;
496         }
497       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
498       if(dpd)
499         {
500           dpd->checkCoherency();
501           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> myIds(dpd->toDAI());
502           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
503           myIds->applyLin(1,-a);
504           int nbOfEltsToLoad(b-a+1);
505           med_filter filter=MED_FILTER_INIT;
506           {//TODO : manage int32 !
507             MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(DataArrayDouble::New());
508             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
509             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
510                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
511                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
512                                      /*lastblocksize=useless because count=1*/0,&filter);
513             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
514             MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> feeder(DataArrayDouble::New());
515             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
516             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
517           }
518           MEDfilterClose(&filter);
519         }
520       else
521         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
522     }
523 }
524
525 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
526 {
527   return _father;
528 }
529
530 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
531 {
532   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
533   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
534   std::string fieldName(nasc.getName()),meshName(getMeshName());
535   int iteration(getIteration()),order(getOrder());
536   TypeOfField type(getType());
537   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
538   int profilesize,nbi;
539   med_geometry_type mgeoti;
540   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
541   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
542   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
543   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
544   const PartDefinition *pd(_pd);
545   if(!pd)
546     {
547       _nval=zeNVal;
548     }
549   else
550     {
551       if(!_profile.empty())
552         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
553       _nval=pd->getNumberOfElems();
554     }
555   _start=start;
556   _end=start+_nval*nbi;
557   start=_end;
558   if(type==ON_CELLS && !_localization.empty())
559     {
560       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
561         setType(ON_GAUSS_PT);
562       else
563         {
564           setType(ON_GAUSS_NE);
565           _localization.clear();
566         }
567     }
568 }
569
570 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
571 {
572   std::string fieldName(nasc.getName()),meshName(getMeshName());
573   int iteration(getIteration()),order(getOrder());
574   TypeOfField type(getType());
575   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
576   med_geometry_type mgeoti;
577   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
578   if(_start>_end)
579     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
580   if(_start==_end)
581     return ;
582   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
583   if(_start<0 || _start>=arr->getNumberOfTuples())
584     {
585       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
586       throw INTERP_KERNEL::Exception(oss.str().c_str());
587     }
588   if(_end<0 || _end>arr->getNumberOfTuples())
589     {
590       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
591       throw INTERP_KERNEL::Exception(oss.str().c_str());
592     }
593   int nbOfCompo(arr->getNumberOfComponents());
594   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
595   if(arrD)
596     {
597       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
598       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
599       return ;
600     }
601   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
602   if(arrI)
603     {
604       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
605       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
606       return ;
607     }
608   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
609 }
610
611 /*!
612  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
613  */
614 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
615 {
616   int delta=_end-_start;
617   _start=newValueOfStart;
618   _end=_start+delta;
619 }
620
621 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
622 {
623   return _father->getIteration();
624 }
625
626 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
627 {
628   return _father->getOrder();
629 }
630
631 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
632 {
633   return _father->getTime();
634 }
635
636 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
637 {
638   return _father->getMeshName();
639 }
640
641 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
642 {
643   const char startLine[]="    ## ";
644   std::string startLine2(bkOffset,' ');
645   startLine2+=startLine;
646   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
647   oss << startLine2 << "Localization #" << id << "." << std::endl;
648   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
649   delete tmp;
650   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
651   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
652   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
653 }
654
655 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
656 {
657   return _type;
658 }
659
660 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
661 {
662   types.insert(_type);
663 }
664
665 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
666 {
667   _type=newType;
668 }
669
670 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
671 {
672   return _father->getGeoType();
673 }
674
675 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
676 {
677   return _father->getNumberOfComponents();
678 }
679
680 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
681 {
682   return _end-_start;
683 }
684
685 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
686 {
687   return _father->getOrCreateAndGetArray();
688 }
689
690 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
691 {
692   const MEDFileFieldPerMeshPerType *fath=_father;
693   return fath->getOrCreateAndGetArray();
694 }
695
696 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
697 {
698   return _father->getInfo();
699 }
700
701 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
702 {
703   return _profile;
704 }
705
706 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
707 {
708   _profile=newPflName;
709 }
710
711 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
712 {
713   return _localization;
714 }
715
716 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
717 {
718   _localization=newLocName;
719 }
720
721 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
722 {
723   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
724     {
725       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
726         {
727           _profile=(*it2).second;
728           return;
729         }
730     }
731 }
732
733 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
734 {
735   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
736     {
737       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
738         {
739           _localization=(*it2).second;
740           return;
741         }
742     }
743 }
744
745 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
746 {
747   if(type!=_type)
748     return ;
749   dads.push_back(std::pair<int,int>(_start,_end));
750   geoTypes.push_back(getGeoType());
751   if(_profile.empty())
752     pfls.push_back(0);
753   else
754     {
755       pfls.push_back(glob->getProfile(_profile.c_str()));
756     }
757   if(_localization.empty())
758     locs.push_back(-1);
759   else
760     {
761       locs.push_back(glob->getLocalizationId(_localization.c_str()));
762     }
763 }
764
765 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
766 {
767   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));
768   startEntryId++;
769 }
770
771 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
772 {
773   TypeOfField type=getType();
774   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
775   med_geometry_type mgeoti;
776   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
777   const DataArray *arr=getOrCreateAndGetArray();
778   if(!arr)
779     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
780   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
781   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
782   const unsigned char *locToWrite=0;
783   if(arrD)
784     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
785   else if(arrI)
786     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
787   else
788     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
789   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
790                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
791                                                    locToWrite));
792 }
793
794 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
795 {
796   type=_type;
797   pfl=_profile;
798   loc=_localization;
799   dad.first=_start; dad.second=_end;
800 }
801
802 /*!
803  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
804  *             This code corresponds to the distribution of types in the corresponding mesh.
805  * \param [out] ptToFill memory zone where the output will be stored.
806  * \return the size of data pushed into output param \a ptToFill
807  */
808 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
809 {
810   _loc_id=offset;
811   std::ostringstream oss;
812   std::size_t nbOfType=codeOfMesh.size()/3;
813   int found=-1;
814   for(std::size_t i=0;i<nbOfType && found==-1;i++)
815     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
816       found=(int)i;
817   if(found==-1)
818     {
819       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
820       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
821       throw INTERP_KERNEL::Exception(oss.str().c_str());
822     }
823   int *work=ptToFill;
824   if(_profile.empty())
825     {
826       if(_nval!=codeOfMesh[3*found+1])
827         {
828           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
829           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
830           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
831           throw INTERP_KERNEL::Exception(oss.str().c_str());
832         }
833       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
834         *work++=ii;
835     }
836   else
837     {
838       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
839       if(pfl->getNumberOfTuples()!=_nval)
840         {
841           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
842           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
843           oss << _nval;
844           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
845           throw INTERP_KERNEL::Exception(oss.str().c_str());
846         }
847       int offset2=codeOfMesh[3*found+2];
848       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
849         {
850           if(*pflId<codeOfMesh[3*found+1])
851             *work++=offset2+*pflId;
852         }
853     }
854   return _nval;
855 }
856
857 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
858 {
859   for(int i=_start;i<_end;i++)
860     *ptToFill++=i;
861   return _end-_start;
862 }
863
864 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
865 {
866   switch(type)
867   {
868     case ON_CELLS:
869       return -2;
870     case ON_GAUSS_NE:
871       return -1;
872     case ON_GAUSS_PT:
873       return locId;
874     default:
875       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
876   }
877 }
878
879 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
880 {
881   int id=0;
882   std::map<std::pair<std::string,TypeOfField>,int> m;
883   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
884   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
885     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
886       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
887   ret.resize(id);
888   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
889     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
890   return ret;
891 }
892
893 /*!
894  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
895  * 
896  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
897  * \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.
898  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
899  * \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)
900  * \param [in,out] glob if necessary by the method, new profiles can be added to it
901  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
902  * \param [out] result All new entries will be appended on it.
903  * \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 !)
904  */
905 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
906                                                        const DataArrayInt *explicitIdsInMesh,
907                                                        const std::vector<int>& newCode,
908                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
909                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
910 {
911   if(entriesOnSameDisc.empty())
912     return false;
913   TypeOfField type=entriesOnSameDisc[0]->getType();
914   int szEntities=0,szTuples=0;
915   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
916     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
917   int nbi=szTuples/szEntities;
918   if(szTuples%szEntities!=0)
919     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
920   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
921   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
922   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
923   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
924   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
925   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
926   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
927   int id=0;
928   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
929     {
930       int startOfEltIdOfChunk=(*it)->_start;
931       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
932       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
933       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
934       //
935       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
936       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
937       //
938       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
939       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
940     }
941   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
942   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
943   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
944   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
945   //
946   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
947   //
948   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
949   arrPart->renumberInPlace(renumTupleIds->begin());
950   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
951   bool ret=false;
952   const int *idIt=diffVals->begin();
953   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
954   int offset2=0;
955   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
956     {
957       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
958       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
959       int nbEntityElts=subIds->getNumberOfTuples();
960       bool ret2;
961       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
962           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
963                                       offset+offset2,
964                                       li,glob,ret2);
965       ret=ret || ret2;
966       result.push_back(eltToAdd);
967       offset2+=nbEntityElts*nbi;
968     }
969   ret=ret || li.empty();
970   return ret;
971 }
972
973 /*!
974  * \param [in] typeF type of field of new chunk
975  * \param [in] geoType the geometric type of the chunk
976  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
977  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
978  * \param [in] nbi number of integration points
979  * \param [in] offset The offset in the **global array of data**.
980  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
981  *                 to the new chunk to create.
982  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
983  * \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
984  *              and corresponding entry erased from \a entriesOnSameDisc.
985  * \return a newly allocated chunk
986  */
987 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
988                                                                                                   bool isPfl, int nbi, int offset,
989                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
990                                                                                                   MEDFileFieldGlobsReal& glob,
991                                                                                                   bool &notInExisting)
992 {
993   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
994   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
995   for(;it!=entriesOnSameDisc.end();it++)
996     {
997       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
998         {
999           if(!isPfl)
1000             {
1001               if((*it)->_profile.empty())
1002                 break;
1003               else
1004                 if(!(*it)->_profile.empty())
1005                   {
1006                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1007                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1008                       break;
1009                   }
1010             }
1011         }
1012     }
1013   if(it==entriesOnSameDisc.end())
1014     {
1015       notInExisting=true;
1016       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1017       ret->_type=typeF;
1018       ret->_loc_id=(int)geoType;
1019       ret->_nval=nbMeshEntities;
1020       ret->_start=offset;
1021       ret->_end=ret->_start+ret->_nval*nbi;
1022       if(isPfl)
1023         {
1024           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1025           glob.appendProfile(idsOfMeshElt);
1026           ret->_profile=idsOfMeshElt->getName();
1027         }
1028       //tony treatment of localization
1029       return ret;
1030     }
1031   else
1032     {
1033       notInExisting=false;
1034       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1035       ret->_loc_id=(int)geoType;
1036       ret->setNewStart(offset);
1037       entriesOnSameDisc.erase(it);
1038       return ret;
1039     }
1040
1041 }
1042
1043 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1044 {
1045   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1046 }
1047
1048 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1049 {
1050   return new MEDFileFieldPerMeshPerType(fath,geoType);
1051 }
1052
1053 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
1054 {
1055   return _field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
1056 }
1057
1058 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
1059 {
1060   std::vector<const BigMemoryObject *> ret;
1061   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1062     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1063   return ret;
1064 }
1065
1066 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const
1067 {
1068   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1069   ret->_father=father;
1070   std::size_t i=0;
1071   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1072     {
1073       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1074         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
1075     }
1076   return ret.retn();
1077 }
1078
1079 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1080 {
1081   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1082   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1083     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1084 }
1085
1086 /*!
1087  * This method is the most general one. No optimization is done here.
1088  * \param [in] multiTypePfl is the end user profile specified in high level API
1089  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1090  * \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.
1091  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1092  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1093  * \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.
1094  */
1095 void MEDFileFieldPerMeshPerType::assignFieldProfile(bool isPflAlone, 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)
1096 {
1097   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1098   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1099     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1100 }
1101
1102 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1103 {
1104   _field_pm_pt_pd.resize(1);
1105   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1106   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1107 }
1108
1109 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1110 {
1111   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1112   if(!arr || !arr->isAllocated())
1113     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1114   _field_pm_pt_pd.resize(1);
1115   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1116   _field_pm_pt_pd[0]->assignFieldProfile(true,start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1117 }
1118
1119 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1120 {
1121   TypeOfField type=field->getTypeOfField();
1122   if(type!=ON_GAUSS_PT)
1123     {
1124       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1125       int sz=_field_pm_pt_pd.size();
1126       bool found=false;
1127       for(int j=0;j<sz && !found;j++)
1128         {
1129           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1130             {
1131               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1132               found=true;
1133             }
1134         }
1135       if(!found)
1136         {
1137           _field_pm_pt_pd.resize(sz+1);
1138           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1139         }
1140       std::vector<int> ret(1,(int)sz);
1141       return ret;
1142     }
1143   else
1144     {
1145       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1146       int sz2=ret2.size();
1147       std::vector<int> ret3(sz2);
1148       int k=0;
1149       for(int i=0;i<sz2;i++)
1150         {
1151           int sz=_field_pm_pt_pd.size();
1152           int locIdToFind=ret2[i];
1153           bool found=false;
1154           for(int j=0;j<sz && !found;j++)
1155             {
1156               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1157                 {
1158                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1159                   ret3[k++]=j;
1160                   found=true;
1161                 }
1162             }
1163           if(!found)
1164             {
1165               _field_pm_pt_pd.resize(sz+1);
1166               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1167               ret3[k++]=sz;
1168             }
1169         }
1170       return ret3;
1171     }
1172 }
1173
1174 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1175 {
1176   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1177   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1178   if(!disc2)
1179     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1180   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1181   if(!da)
1182     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1183   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1184   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1185   if(retTmp->presenceOfValue(-1))
1186     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1187   std::vector<int> ret(retTmp->begin(),retTmp->end());
1188   return ret;
1189 }
1190
1191 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1192 {
1193   TypeOfField type=field->getTypeOfField();
1194   if(type!=ON_GAUSS_PT)
1195     {
1196       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1197       int sz=_field_pm_pt_pd.size();
1198       bool found=false;
1199       for(int j=0;j<sz && !found;j++)
1200         {
1201           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1202             {
1203               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1204               found=true;
1205             }
1206         }
1207       if(!found)
1208         {
1209           _field_pm_pt_pd.resize(sz+1);
1210           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1211         }
1212       std::vector<int> ret(1,0);
1213       return ret;
1214     }
1215   else
1216     {
1217       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1218       int sz2=ret2.size();
1219       std::vector<int> ret3(sz2);
1220       int k=0;
1221       for(int i=0;i<sz2;i++)
1222         {
1223           int sz=_field_pm_pt_pd.size();
1224           int locIdToFind=ret2[i];
1225           bool found=false;
1226           for(int j=0;j<sz && !found;j++)
1227             {
1228               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1229                 {
1230                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1231                   ret3[k++]=j;
1232                   found=true;
1233                 }
1234             }
1235           if(!found)
1236             {
1237               _field_pm_pt_pd.resize(sz+1);
1238               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1239               ret3[k++]=sz;
1240             }
1241         }
1242       return ret3;
1243     }
1244 }
1245
1246 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1247 {
1248   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1249   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1250   if(!disc2)
1251     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1252   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1253   if(!da)
1254     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1255   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1256   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1257   if(retTmp->presenceOfValue(-1))
1258     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1259   std::vector<int> ret(retTmp->begin(),retTmp->end());
1260   return ret;
1261 }
1262
1263 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1264 {
1265   return _father;
1266 }
1267
1268 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1269 {
1270   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1271   int curDim=(int)cm.getDimension();
1272   dim=std::max(dim,curDim);
1273 }
1274
1275 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1276 {
1277   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1278     {
1279       (*it)->fillTypesOfFieldAvailable(types);
1280     }
1281 }
1282
1283 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
1284 {
1285   int sz=_field_pm_pt_pd.size();
1286   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1287   for(int i=0;i<sz;i++)
1288     {
1289       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1290     }
1291 }
1292
1293 int MEDFileFieldPerMeshPerType::getIteration() const
1294 {
1295   return _father->getIteration();
1296 }
1297
1298 int MEDFileFieldPerMeshPerType::getOrder() const
1299 {
1300   return _father->getOrder();
1301 }
1302
1303 double MEDFileFieldPerMeshPerType::getTime() const
1304 {
1305   return _father->getTime();
1306 }
1307
1308 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1309 {
1310   return _father->getMeshName();
1311 }
1312
1313 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1314 {
1315   const char startLine[]="  ## ";
1316   std::string startLine2(bkOffset,' ');
1317   std::string startLine3(startLine2);
1318   startLine3+=startLine;
1319   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1320     {
1321       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1322       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1323     }
1324   else
1325     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1326   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1327   int i=0;
1328   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1329     {
1330       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1331       if(cur)
1332         cur->simpleRepr(bkOffset,oss,i);
1333       else
1334         {
1335           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1336         }
1337     }
1338 }
1339
1340 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1341 {
1342   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1343     {
1344       globalSz+=(*it)->getNumberOfTuples();
1345     }
1346   nbOfEntries+=(int)_field_pm_pt_pd.size();
1347 }
1348
1349 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1350 {
1351   return _geo_type;
1352 }
1353
1354
1355 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1356 {
1357   return _father->getNumberOfComponents();
1358 }
1359
1360 bool MEDFileFieldPerMeshPerType::presenceOfMultiDiscPerGeoType() const
1361 {
1362   std::size_t nb(0);
1363   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1364     {
1365       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1366       if(fmtd)
1367         nb++;
1368     }
1369   return nb>1;
1370 }
1371
1372 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1373 {
1374   return _father->getOrCreateAndGetArray();
1375 }
1376
1377 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1378 {
1379   const MEDFileFieldPerMesh *fath=_father;
1380   return fath->getOrCreateAndGetArray();
1381 }
1382
1383 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1384 {
1385   return _father->getInfo();
1386 }
1387
1388 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1389 {
1390   std::vector<std::string> ret;
1391   std::set<std::string> ret2;
1392   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1393     {
1394       std::string tmp=(*it1)->getProfile();
1395       if(!tmp.empty())
1396         if(ret2.find(tmp)==ret2.end())
1397           {
1398             ret.push_back(tmp);
1399             ret2.insert(tmp);
1400           }
1401     }
1402   return ret;
1403 }
1404
1405 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1406 {
1407   std::vector<std::string> ret;
1408   std::set<std::string> ret2;
1409   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1410     {
1411       std::string tmp=(*it1)->getLocalization();
1412       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1413         if(ret2.find(tmp)==ret2.end())
1414           {
1415             ret.push_back(tmp);
1416             ret2.insert(tmp);
1417           }
1418     }
1419   return ret;
1420 }
1421
1422 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1423 {
1424   std::vector<std::string> ret;
1425   std::set<std::string> ret2;
1426   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1427     {
1428       std::string tmp=(*it1)->getProfile();
1429       if(!tmp.empty())
1430         ret.push_back(tmp);
1431     }
1432   return ret;
1433 }
1434
1435 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1436 {
1437   std::vector<std::string> ret;
1438   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1439     {
1440       std::string tmp=(*it1)->getLocalization();
1441       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1442         ret.push_back(tmp);
1443     }
1444   return ret;
1445 }
1446
1447 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1448 {
1449   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1450     (*it1)->changePflsRefsNamesGen(mapOfModif);
1451 }
1452
1453 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1454 {
1455   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1456     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1457 }
1458
1459 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1460 {
1461   if(_field_pm_pt_pd.empty())
1462     {
1463       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1464       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1465       throw INTERP_KERNEL::Exception(oss.str().c_str());
1466     }
1467   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1468     return _field_pm_pt_pd[locId];
1469   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1470   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1471   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1472   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1473   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1474 }
1475
1476 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1477 {
1478   if(_field_pm_pt_pd.empty())
1479     {
1480       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1481       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1482       throw INTERP_KERNEL::Exception(oss.str().c_str());
1483     }
1484   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1485     return _field_pm_pt_pd[locId];
1486   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1487   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1488   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1489   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1490   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1491 }
1492
1493 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
1494 {
1495   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1496     {
1497       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1498       if(meshDim!=(int)cm.getDimension())
1499         return ;
1500     }
1501   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1502     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1503 }
1504
1505 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1506 {
1507   int i=0;
1508   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1509     {
1510       (*it)->fillValues(i,startEntryId,entries);
1511     }
1512 }
1513
1514 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1515 {
1516   _field_pm_pt_pd=leaves;
1517   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1518     (*it)->setFather(this);
1519 }
1520
1521 /*!
1522  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1523  *  \param [out] its - list of pair (start,stop) kept
1524  *  \return bool - false if the type of field \a tof is not contained in \a this.
1525  */
1526 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1527 {
1528   bool ret(false);
1529   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1530   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1531     if((*it)->getType()==tof)
1532       {
1533         newPmPtPd.push_back(*it);
1534         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1535         (*it)->setNewStart(globalNum);
1536         globalNum=(*it)->getEnd();
1537         its.push_back(bgEnd);
1538         ret=true;
1539       }
1540   if(ret)
1541     _field_pm_pt_pd=newPmPtPd;
1542   return ret;
1543 }
1544
1545 /*!
1546  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1547  *  \param [out] its - list of pair (start,stop) kept
1548  *  \return bool - false if the type of field \a tof is not contained in \a this.
1549  */
1550 bool MEDFileFieldPerMeshPerType::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1551 {
1552   if(_field_pm_pt_pd.size()<=idOfDisc)
1553     return false;
1554   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1555   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1556   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1557   elt->setNewStart(globalNum);
1558   globalNum=elt->getEnd();
1559   its.push_back(bgEnd);
1560   _field_pm_pt_pd=newPmPtPd;
1561   return true;
1562 }
1563
1564 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1565 {
1566 }
1567
1568 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType)
1569 {
1570   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1571   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1572   med_geometry_type mgeoti;
1573   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1574   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1575   _field_pm_pt_pd.resize(nbProfiles);
1576   for(int i=0;i<nbProfiles;i++)
1577     {
1578       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1579     }
1580   if(type==ON_CELLS)
1581     {
1582       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1583       for(int i=0;i<nbProfiles2;i++)
1584         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1585     }
1586 }
1587
1588 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1589 {
1590   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1591     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1592 }
1593
1594 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1595 {
1596   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1597     (*it)->loadBigArray(fid,nasc);
1598 }
1599
1600 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1601 {
1602   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1603     {
1604       (*it)->copyOptionsFrom(*this);
1605       (*it)->writeLL(fid,nasc);
1606     }
1607 }
1608
1609 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1610 {
1611   switch(ikType)
1612   {
1613     case ON_CELLS:
1614       medfGeoType=typmai3[(int)ikGeoType];
1615       return MED_CELL;
1616     case ON_NODES:
1617       medfGeoType=MED_NONE;
1618       return MED_NODE;
1619     case ON_GAUSS_NE:
1620       medfGeoType=typmai3[(int)ikGeoType];
1621       return MED_NODE_ELEMENT;
1622     case ON_GAUSS_PT:
1623       medfGeoType=typmai3[(int)ikGeoType];
1624       return MED_CELL;
1625     default:
1626       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1627   }
1628   return MED_UNDEF_ENTITY_TYPE;
1629 }
1630
1631 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
1632 {
1633   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1634 }
1635
1636 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1637 {
1638   return new MEDFileFieldPerMesh(fath,mesh);
1639 }
1640
1641 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1642 {
1643   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1644 }
1645
1646 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1647 {
1648   std::vector<const BigMemoryObject *> ret;
1649   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1650     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1651   return ret;
1652 }
1653
1654 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1655 {
1656   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1657   ret->_father=father;
1658   std::size_t i=0;
1659   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1660     {
1661       if((const MEDFileFieldPerMeshPerType *)*it)
1662         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1663     }
1664   return ret.retn();
1665 }
1666
1667 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1668 {
1669   std::string startLine(bkOffset,' ');
1670   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1671   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1672   int i=0;
1673   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1674     {
1675       const MEDFileFieldPerMeshPerType *cur=*it;
1676       if(cur)
1677         cur->simpleRepr(bkOffset,oss,i);
1678       else
1679         {
1680           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1681         }
1682     }
1683 }
1684
1685 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1686 {
1687   _mesh_name=mesh->getName();
1688   mesh->getTime(_mesh_iteration,_mesh_order);
1689 }
1690
1691 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1692 {
1693   int nbOfTypes=code.size()/3;
1694   int offset=0;
1695   for(int i=0;i<nbOfTypes;i++)
1696     {
1697       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1698       int nbOfCells=code[3*i+1];
1699       int pos=addNewEntryIfNecessary(type);
1700       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1701       offset+=nbOfCells;
1702     }
1703 }
1704
1705 /*!
1706  * This method is the most general one. No optimization is done here.
1707  * \param [in] multiTypePfl is the end user profile specified in high level API
1708  * \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].
1709  * \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.
1710  * \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.
1711  * \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.
1712  * \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.
1713  */
1714 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)
1715 {
1716   int nbOfTypes(code.size()/3);
1717   for(int i=0;i<nbOfTypes;i++)
1718     {
1719       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1720       int pos=addNewEntryIfNecessary(type);
1721       DataArrayInt *pfl=0;
1722       if(code[3*i+2]!=-1)
1723         pfl=idsPerType[code[3*i+2]];
1724       int nbOfTupes2=code2.size()/3;
1725       int found=0;
1726       for(;found<nbOfTupes2;found++)
1727         if(code[3*i]==code2[3*found])
1728           break;
1729       if(found==nbOfTupes2)
1730         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1731       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1732     }
1733 }
1734
1735 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1736 {
1737   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1738   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1739 }
1740
1741 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1742 {
1743   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1744   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1745 }
1746
1747 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1748 {
1749   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1750     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1751 }
1752
1753 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1754 {
1755   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1756     (*it)->loadBigArraysRecursively(fid,nasc);
1757 }
1758
1759 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1760 {
1761   int nbOfTypes=_field_pm_pt.size();
1762   for(int i=0;i<nbOfTypes;i++)
1763     {
1764       _field_pm_pt[i]->copyOptionsFrom(*this);
1765       _field_pm_pt[i]->writeLL(fid,nasc);
1766     }
1767 }
1768
1769 void MEDFileFieldPerMesh::getDimension(int& dim) const
1770 {
1771   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1772     (*it)->getDimension(dim);
1773 }
1774
1775 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1776 {
1777   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1778     (*it)->fillTypesOfFieldAvailable(types);
1779 }
1780
1781 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
1782 {
1783   int sz=_field_pm_pt.size();
1784   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1785   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1786   for(int i=0;i<sz;i++)
1787     {
1788       types[i]=_field_pm_pt[i]->getGeoType();
1789       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1790     }
1791   return ret;
1792 }
1793
1794 double MEDFileFieldPerMesh::getTime() const
1795 {
1796   int tmp1,tmp2;
1797   return _father->getTime(tmp1,tmp2);
1798 }
1799
1800 int MEDFileFieldPerMesh::getIteration() const
1801 {
1802   return _father->getIteration();
1803 }
1804
1805 int MEDFileFieldPerMesh::getOrder() const
1806 {
1807   return _father->getOrder();
1808 }
1809
1810 int MEDFileFieldPerMesh::getNumberOfComponents() const
1811 {
1812   return _father->getNumberOfComponents();
1813 }
1814
1815 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1816 {
1817   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1818     {
1819       const MEDFileFieldPerMeshPerType *fpmt(*it);
1820       if(!fpmt)
1821         continue;
1822       if(fpmt->presenceOfMultiDiscPerGeoType())
1823         return true;
1824     }
1825   return false;
1826 }
1827
1828 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1829 {
1830   if(!_father)
1831     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1832   return _father->getOrCreateAndGetArray();
1833 }
1834
1835 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1836 {
1837   if(!_father)
1838     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1839   return _father->getOrCreateAndGetArray();
1840 }
1841
1842 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1843 {
1844   return _father->getInfo();
1845 }
1846
1847 /*!
1848  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1849  * 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.
1850  * It returns 2 output vectors :
1851  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1852  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1853  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1854  */
1855 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)
1856 {
1857   int notNullPflsSz=0;
1858   int nbOfArrs=geoTypes.size();
1859   for(int i=0;i<nbOfArrs;i++)
1860     if(pfls[i])
1861       notNullPflsSz++;
1862   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1863   int nbOfDiffGeoTypes=geoTypes3.size();
1864   code.resize(3*nbOfDiffGeoTypes);
1865   notNullPfls.resize(notNullPflsSz);
1866   notNullPflsSz=0;
1867   int j=0;
1868   for(int i=0;i<nbOfDiffGeoTypes;i++)
1869     {
1870       int startZone=j;
1871       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1872       std::vector<const DataArrayInt *> notNullTmp;
1873       if(pfls[j])
1874         notNullTmp.push_back(pfls[j]);
1875       j++;
1876       for(;j<nbOfArrs;j++)
1877         if(geoTypes[j]==refType)
1878           {
1879             if(pfls[j])
1880               notNullTmp.push_back(pfls[j]);
1881           }
1882         else
1883           break;
1884       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1885       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1886       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1887       code[3*i]=(int)refType;
1888       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1889       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1890       if(notNullTmp.empty())
1891         code[3*i+2]=-1;
1892       else
1893         {
1894           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1895           code[3*i+2]=notNullPflsSz++;
1896         }
1897     }
1898 }
1899
1900 /*!
1901  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1902  */
1903 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)
1904 {
1905   int sz=dads.size();
1906   int ret=0;
1907   for(int i=0;i<sz;i++)
1908     {
1909       if(locs[i]==-1)
1910         {
1911           if(type!=ON_GAUSS_NE)
1912             ret+=dads[i].second-dads[i].first;
1913           else
1914             {
1915               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1916               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1917             }
1918         }
1919       else
1920         {
1921           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1922           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1923         }
1924     }
1925   return ret;
1926 }
1927
1928 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1929 {
1930   std::vector<std::string> ret;
1931   std::set<std::string> ret2;
1932   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1933     {
1934       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1935       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1936         if(ret2.find(*it2)==ret2.end())
1937           {
1938             ret.push_back(*it2);
1939             ret2.insert(*it2);
1940           }
1941     }
1942   return ret;
1943 }
1944
1945 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1946 {
1947   std::vector<std::string> ret;
1948   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1949     {
1950       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1951       ret.insert(ret.end(),tmp.begin(),tmp.end());
1952     }
1953   return ret;
1954 }
1955
1956 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1957 {
1958   std::vector<std::string> ret;
1959   std::set<std::string> ret2;
1960   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1961     {
1962       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1963       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1964         if(ret2.find(*it2)==ret2.end())
1965           {
1966             ret.push_back(*it2);
1967             ret2.insert(*it2);
1968           }
1969     }
1970   return ret;
1971 }
1972
1973 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1974 {
1975   std::vector<std::string> ret;
1976   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1977     {
1978       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1979       ret.insert(ret.end(),tmp.begin(),tmp.end());
1980     }
1981   return ret;
1982 }
1983
1984 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1985 {
1986   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1987     {
1988       if((*it).first==_mesh_name)
1989         {
1990           _mesh_name=(*it).second;
1991           return true;
1992         }
1993     }
1994   return false;
1995 }
1996
1997 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1998                                                       MEDFileFieldGlobsReal& glob)
1999 {
2000   if(_mesh_name!=meshName)
2001     return false;
2002   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2003   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2004   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2005   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2006   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2007   getUndergroundDataArrayExt(entries);
2008   DataArray *arr0=getOrCreateAndGetArray();//tony
2009   if(!arr0)
2010     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2011   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
2012   if(!arr0)
2013     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2014   int sz=0;
2015   if(!arr)
2016     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2017   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2018     {
2019       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2020         {
2021           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2022           sz+=(*it).second.second-(*it).second.first;
2023         }
2024       else
2025         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2026     }
2027   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2028   ////////////////////
2029   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2030   int *workI2=explicitIdsOldInMesh->getPointer();
2031   int sz1=0,sz2=0,sid=1;
2032   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2033   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2034   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2035     {
2036       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2037       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2038       int *workI=explicitIdsOldInArr->getPointer();
2039       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2040         {
2041           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2042           (*itL2)->setLocId(sz2);
2043           (*itL2)->_tmp_work1=(*itL2)->getStart();
2044           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2045         }
2046       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2047     }
2048   explicitIdsOldInMesh->reAlloc(sz2);
2049   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2050   ////////////////////
2051   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2052   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2053   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2054   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2055     {
2056       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2057       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2058       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2059     }
2060   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2061   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2062   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2063     {
2064       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2065       int newStart=elt->getLocId();
2066       elt->setLocId((*it)->getGeoType());
2067       elt->setNewStart(newStart);
2068       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2069       entriesKeptNew.push_back(elt);
2070       entriesKeptNew2.push_back(elt);
2071     }
2072   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2073   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2074   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2075   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2076   bool ret=false;
2077   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2078     {
2079       sid=0;
2080       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2081         {
2082           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2083           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2084           }*/
2085       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2086                                                             glob,arr2,otherEntriesNew) || ret;
2087     }
2088   if(!ret)
2089     return false;
2090   // Assign new dispatching
2091   assignNewLeaves(otherEntriesNew);
2092   arr->cpyFrom(*arr2);
2093   return true;
2094 }
2095
2096 /*!
2097  * \param [in,out] globalNum a global numbering counter for the renumbering.
2098  * \param [out] its - list of pair (start,stop) kept
2099  */
2100 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2101 {
2102   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
2103   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2104     {
2105       std::vector< std::pair<int,int> > its2;
2106       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2107         {
2108           ret.push_back(*it);
2109           its.insert(its.end(),its2.begin(),its2.end());
2110         }
2111     }
2112   _field_pm_pt=ret;
2113 }
2114
2115 /*!
2116  * \param [in,out] globalNum a global numbering counter for the renumbering.
2117  * \param [out] its - list of pair (start,stop) kept
2118  */
2119 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2120 {
2121   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
2122   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2123     {
2124       std::vector< std::pair<int,int> > its2;
2125       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2126         {
2127           ret.push_back(*it);
2128           its.insert(its.end(),its2.begin(),its2.end());
2129         }
2130     }
2131   _field_pm_pt=ret;
2132 }
2133
2134 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2135 {
2136   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2137   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2138     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2139   //
2140   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2141   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2142   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2143   for(;it1!=types.end();it1++,it2++)
2144     {
2145       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2146       elt->setLeaves((*it1).second);
2147       *it2=elt;
2148     }
2149   _field_pm_pt=fieldPmPt;
2150 }
2151
2152 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2153 {
2154   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2155     (*it)->changePflsRefsNamesGen(mapOfModif);
2156 }
2157
2158 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2159 {
2160   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2161     (*it)->changeLocsRefsNamesGen(mapOfModif);
2162 }
2163
2164 /*!
2165  * \param [in] mesh is the whole mesh
2166  */
2167 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2168 {
2169   if(_field_pm_pt.empty())
2170     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2171   //
2172   std::vector< std::pair<int,int> > dads;
2173   std::vector<const DataArrayInt *> pfls;
2174   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2175   std::vector<int> locs,code;
2176   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2177   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2178     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2179   // Sort by types
2180   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2181   if(code.empty())
2182     {
2183       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2184       throw INTERP_KERNEL::Exception(oss.str().c_str());
2185     }
2186   //
2187   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2188   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2189   if(type!=ON_NODES)
2190     {
2191       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2192       if(!arr)
2193         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2194       else
2195         {
2196           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2197           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2198         }
2199     }
2200   else
2201     {
2202       if(code.size()!=3)
2203         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2204       int nb=code[1];
2205       if(code[2]==-1)
2206         {
2207           if(nb!=mesh->getNumberOfNodes())
2208             {
2209               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2210               oss << " nodes in mesh !";
2211               throw INTERP_KERNEL::Exception(oss.str().c_str());
2212             }
2213           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2214         }
2215       else
2216         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2217     }
2218 }
2219
2220 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2221 {
2222   if(_field_pm_pt.empty())
2223     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2224   //
2225   std::vector<std::pair<int,int> > dads;
2226   std::vector<const DataArrayInt *> pfls;
2227   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2228   std::vector<int> locs,code;
2229   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2230   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2231     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2232   // Sort by types
2233   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2234   if(code.empty())
2235     {
2236       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2237       throw INTERP_KERNEL::Exception(oss.str().c_str());
2238     }
2239   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2240   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2241   if(type!=ON_NODES)
2242     {
2243       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2244       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2245     }
2246   else
2247     {
2248       if(code.size()!=3)
2249         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2250       int nb=code[1];
2251       if(code[2]==-1)
2252         {
2253           if(nb!=mesh->getNumberOfNodes())
2254             {
2255               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2256               oss << " nodes in mesh !";
2257               throw INTERP_KERNEL::Exception(oss.str().c_str());
2258             }
2259         }
2260       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2261     }
2262   //
2263   return 0;
2264 }
2265
2266 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2267 {
2268   int globalSz=0;
2269   int nbOfEntries=0;
2270   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2271     {
2272       (*it)->getSizes(globalSz,nbOfEntries);
2273     }
2274   entries.resize(nbOfEntries);
2275   nbOfEntries=0;
2276   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2277     {
2278       (*it)->fillValues(nbOfEntries,entries);
2279     }
2280 }
2281
2282 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2283 {
2284   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2285     {
2286       if((*it)->getGeoType()==typ)
2287         return (*it)->getLeafGivenLocId(locId);
2288     }
2289   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2290   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2291   oss << "Possiblities are : ";
2292   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2293     {
2294       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2295       oss << "\"" << cm2.getRepr() << "\", ";
2296     }
2297   throw INTERP_KERNEL::Exception(oss.str().c_str());
2298 }
2299
2300 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2301 {
2302   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2303     {
2304       if((*it)->getGeoType()==typ)
2305         return (*it)->getLeafGivenLocId(locId);
2306     }
2307   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2308   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2309   oss << "Possiblities are : ";
2310   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2311     {
2312       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2313       oss << "\"" << cm2.getRepr() << "\", ";
2314     }
2315   throw INTERP_KERNEL::Exception(oss.str().c_str());
2316 }
2317
2318 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2319 {
2320   int i=0;
2321   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2322   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2323   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2324     {
2325       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2326       if(type==curType)
2327         return i;
2328       else
2329         {
2330           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2331           if(pos>pos2)
2332             it2=it+1;
2333         }
2334     }
2335   int ret=std::distance(_field_pm_pt.begin(),it2);
2336   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2337   return ret;
2338 }
2339
2340 /*!
2341  * 'dads' and 'locs' input parameters have the same number of elements
2342  * \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
2343  */
2344 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2345                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2346                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2347 {
2348   isPfl=false;
2349   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2350   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2351   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2352   const std::vector<std::string>& infos=getInfo();
2353   da->setInfoOnComponents(infos);
2354   da->setName("");
2355   if(type==ON_GAUSS_PT)
2356     {
2357       int offset=0;
2358       int nbOfArrs=dads.size();
2359       for(int i=0;i<nbOfArrs;i++)
2360         {
2361           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2362           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2363           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2364           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2365           di->alloc(nbOfElems,1);
2366           di->iota(offset);
2367           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2368           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2369           offset+=nbOfElems;
2370         }
2371     }
2372   arrOut=da;
2373   return ret.retn();
2374 }
2375
2376 /*!
2377  * 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.
2378  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2379  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2380  * The order of cells in the returned field is those imposed by the profile.
2381  * \param [in] mesh is the global mesh.
2382  */
2383 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2384                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2385                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2386                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2387 {
2388   if(da->isIdentity())
2389     {
2390       int nbOfTuples=da->getNumberOfTuples();
2391       if(nbOfTuples==mesh->getNumberOfCells())
2392         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2393     }
2394   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2395   m2->setName(mesh->getName().c_str());
2396   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2397   isPfl=true;
2398   return ret.retn();
2399 }
2400
2401 /*!
2402  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2403  */
2404 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2405                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2406                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2407 {
2408   if(da->isIdentity())
2409     {
2410       int nbOfTuples=da->getNumberOfTuples();
2411       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2412         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2413     }
2414   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2415   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2416   if(meshu)
2417     {
2418       if(meshu->getNodalConnectivity()==0)
2419         {
2420           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2421           int nb=da->getNbOfElems();
2422           const int *ptr=da->getConstPointer();
2423           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2424           meshuc->allocateCells(nb);
2425           for(int i=0;i<nb;i++)
2426             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2427           meshuc->finishInsertingCells();
2428           ret->setMesh(meshuc);
2429           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2430           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2431           disc->checkCoherencyBetween(meshuc,arrOut);
2432           return ret.retn();
2433         }
2434     }
2435   //
2436   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2437   isPfl=true;
2438   DataArrayInt *arr2=0;
2439   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2440   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2441   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2442   int nnodes=mesh2->getNumberOfNodes();
2443   if(nnodes==(int)da->getNbOfElems())
2444     {
2445       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2446       arrOut->renumberInPlace(da3->getConstPointer());
2447       mesh2->setName(mesh->getName().c_str());
2448       ret->setMesh(mesh2);
2449       return ret.retn();
2450     }
2451   else
2452     {
2453       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 !!!";
2454       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2455       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2456       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2457       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2458       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2459       throw INTERP_KERNEL::Exception(oss.str().c_str());
2460     }
2461   return 0;
2462 }
2463
2464 /*!
2465  * This method is the most light method of field retrieving.
2466  */
2467 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2468 {
2469   if(!pflIn)
2470     {
2471       pflOut=DataArrayInt::New();
2472       pflOut->alloc(nbOfElems,1);
2473       pflOut->iota(0);
2474     }
2475   else
2476     {
2477       pflOut=const_cast<DataArrayInt*>(pflIn);
2478       pflOut->incrRef();
2479     }
2480   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2481   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2482   const std::vector<std::string>& infos=getInfo();
2483   int nbOfComp=infos.size();
2484   for(int i=0;i<nbOfComp;i++)
2485     da->setInfoOnComponent(i,infos[i].c_str());
2486   safePfl->incrRef();
2487   return da.retn();
2488 }
2489
2490
2491 /// @cond INTERNAL
2492
2493 class MFFPMIter
2494 {
2495 public:
2496   static MFFPMIter *NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2497   static bool IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2498   virtual ~MFFPMIter() { }
2499   virtual void begin() = 0;
2500   virtual bool finished() const = 0;
2501   virtual void next() = 0;
2502   virtual int current() const = 0;
2503 };
2504
2505 class MFFPMIterSimple : public MFFPMIter
2506 {
2507 public:
2508   MFFPMIterSimple():_pos(0) { }
2509   void begin() { _pos=0; }
2510   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2511   void next() { _pos++; }
2512   int current() const { return _pos; }
2513 private:
2514   int _pos;
2515 };
2516
2517 class MFFPMIter2 : public MFFPMIter
2518 {
2519 public:
2520   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2521   void begin() { _it=_ids.begin(); }
2522   bool finished() const { return _it==_ids.end(); }
2523   void next() { _it++; }
2524   int current() const { return *_it; }
2525 private:
2526   std::vector<int> _ids;
2527   std::vector<int>::const_iterator _it;
2528 };
2529
2530 MFFPMIter *MFFPMIter::NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2531 {
2532   if(!entities)
2533     return new MFFPMIterSimple;
2534   else
2535     {
2536       std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2537       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2538         {
2539           if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2540             tmp.push_back((*it).second);
2541         }
2542       return new MFFPMIter2(tmp);
2543     }
2544 }
2545
2546 bool MFFPMIter::IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2547 {
2548   if(!entities)
2549     return true;
2550   else
2551     {
2552       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2553         if((*it).first==ON_NODES)
2554           return true;
2555       return false;
2556     }
2557 }
2558
2559 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2560 {
2561   std::size_t sz(cts.size());
2562   _ids.resize(sz);
2563   for(std::size_t i=0;i<sz;i++)
2564     {
2565       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2566       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2567         _ids[i]=(int)std::distance(typmai2,loc);
2568       else
2569         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2570     }
2571 }
2572
2573 /// @cond INTERNAL
2574
2575 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2576     _father(fath)
2577 {
2578   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2579   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2580   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2581   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2582   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2583   for(iter0->begin();!iter0->finished();iter0->next())
2584     {
2585       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2586       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2587       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2588       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2589       if(nbProfile>0 || nbProfile2>0)
2590         {
2591           const PartDefinition *pd(0);
2592           if(mmu)
2593             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2594           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2595           if(nbProfile>0)
2596             _mesh_name=name0;
2597           else
2598             _mesh_name=name1;
2599         }
2600     }
2601   if(MFFPMIter::IsPresenceOfNode(entities))
2602     {
2603       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2604       if(nbProfile>0)
2605         {
2606           const PartDefinition *pd(0);
2607           if(mmu)
2608             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2609           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2610           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2611         }
2612     }
2613 }
2614
2615 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2616 {
2617   copyTinyInfoFrom(mesh);
2618 }
2619
2620 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2621 {
2622   if(id>=(int)_pfls.size())
2623     _pfls.resize(id+1);
2624   _pfls[id]=DataArrayInt::New();
2625   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2626   _pfls[id]->setName(pflName);
2627   _pfls[id]->alloc(lgth,1);
2628   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2629   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2630 }
2631
2632 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2633 {
2634   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2635   int sz;
2636   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
2637   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2638   if(i>=(int)_pfls.size())
2639     _pfls.resize(i+1);
2640   _pfls[i]=DataArrayInt::New();
2641   _pfls[i]->alloc(sz,1);
2642   _pfls[i]->setName(pflCpp.c_str());
2643   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
2644   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2645 }
2646
2647 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2648 {
2649   int nbOfPfls=_pfls.size();
2650   for(int i=0;i<nbOfPfls;i++)
2651     {
2652       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2653       cpy->applyLin(1,1,0);
2654       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2655       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2656       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
2657     }
2658   //
2659   int nbOfLocs=_locs.size();
2660   for(int i=0;i<nbOfLocs;i++)
2661     _locs[i]->writeLL(fid);
2662 }
2663
2664 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2665 {
2666   std::vector<std::string> pfls=getPfls();
2667   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2668     {
2669       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2670       if(it2==pfls.end())
2671         {
2672           _pfls.push_back(*it);
2673         }
2674       else
2675         {
2676           int id=std::distance(pfls.begin(),it2);
2677           if(!(*it)->isEqual(*_pfls[id]))
2678             {
2679               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2680               throw INTERP_KERNEL::Exception(oss.str().c_str());
2681             }
2682         }
2683     }
2684   std::vector<std::string> locs=getLocs();
2685   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2686     {
2687       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2688       if(it2==locs.end())
2689         {
2690           _locs.push_back(*it);
2691         }
2692       else
2693         {
2694           int id=std::distance(locs.begin(),it2);
2695           if(!(*it)->isEqual(*_locs[id],eps))
2696             {
2697               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2698               throw INTERP_KERNEL::Exception(oss.str().c_str());
2699             }
2700         }
2701     }
2702 }
2703
2704 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2705 {
2706   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2707     getProfile((*it).c_str());
2708 }
2709
2710 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2711 {
2712   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2713     getLocalization((*it).c_str());
2714 }
2715
2716 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2717 {
2718   std::vector<std::string> profiles=real.getPflsReallyUsed();
2719   int sz=profiles.size();
2720   _pfls.resize(sz);
2721   for(int i=0;i<sz;i++)
2722     loadProfileInFile(fid,i,profiles[i].c_str());
2723   //
2724   std::vector<std::string> locs=real.getLocsReallyUsed();
2725   sz=locs.size();
2726   _locs.resize(sz);
2727   for(int i=0;i<sz;i++)
2728     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2729 }
2730
2731 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2732 {
2733   int nProfil=MEDnProfile(fid);
2734   for(int i=0;i<nProfil;i++)
2735     loadProfileInFile(fid,i);
2736   int sz=MEDnLocalization(fid);
2737   _locs.resize(sz);
2738   for(int i=0;i<sz;i++)
2739     {
2740       _locs[i]=MEDFileFieldLoc::New(fid,i);
2741     }
2742 }
2743
2744 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2745 {
2746   return new MEDFileFieldGlobs(fname);
2747 }
2748
2749 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2750 {
2751   return new MEDFileFieldGlobs;
2752 }
2753
2754 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2755 {
2756   return _file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2757 }
2758
2759 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2760 {
2761   std::vector<const BigMemoryObject *> ret;
2762   for(std::vector< MEDCouplingAutoRefCountObjectPtr< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2763     ret.push_back((const DataArrayInt *)*it);
2764   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2765     ret.push_back((const MEDFileFieldLoc *)*it);
2766   return ret;
2767 }
2768
2769 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const
2770 {
2771   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2772   std::size_t i=0;
2773   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2774     {
2775       if((const DataArrayInt *)*it)
2776         ret->_pfls[i]=(*it)->deepCpy();
2777     }
2778   i=0;
2779   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2780     {
2781       if((const MEDFileFieldLoc*)*it)
2782         ret->_locs[i]=(*it)->deepCpy();
2783     }
2784   return ret.retn();
2785 }
2786
2787 /*!
2788  * \throw if a profile in \a pfls in not in \a this.
2789  * \throw if a localization in \a locs in not in \a this.
2790  * \sa MEDFileFieldGlobs::deepCpyPart
2791  */
2792 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2793 {
2794   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2795   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2796     {
2797       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2798       if(!pfl)
2799         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2800       pfl->incrRef();
2801       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2802       ret->_pfls.push_back(pfl2);
2803     }
2804   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2805     {
2806       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2807       if(!loc)
2808         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2809       loc->incrRef();
2810       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2811       ret->_locs.push_back(loc2);
2812     }
2813   ret->setFileName(getFileName());
2814   return ret.retn();
2815 }
2816
2817 /*!
2818  * \throw if a profile in \a pfls in not in \a this.
2819  * \throw if a localization in \a locs in not in \a this.
2820  * \sa MEDFileFieldGlobs::shallowCpyPart
2821  */
2822 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2823 {
2824   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2825   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2826     {
2827       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2828       if(!pfl)
2829         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2830       ret->_pfls.push_back(pfl->deepCpy());
2831     }
2832   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2833     {
2834       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2835       if(!loc)
2836         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2837       ret->_locs.push_back(loc->deepCpy());
2838     }
2839   ret->setFileName(getFileName());
2840   return ret.retn();
2841 }
2842
2843 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2844 {
2845 }
2846
2847 MEDFileFieldGlobs::MEDFileFieldGlobs()
2848 {
2849 }
2850
2851 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2852 {
2853 }
2854
2855 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2856 {
2857   oss << "Profiles :\n";
2858   std::size_t n=_pfls.size();
2859   for(std::size_t i=0;i<n;i++)
2860     {
2861       oss << "  - #" << i << " ";
2862       const DataArrayInt *pfl=_pfls[i];
2863       if(pfl)
2864         oss << "\"" << pfl->getName() << "\"\n";
2865       else
2866         oss << "EMPTY !\n";
2867     }
2868   n=_locs.size();
2869   oss << "Localizations :\n";
2870   for(std::size_t i=0;i<n;i++)
2871     {
2872       oss << "  - #" << i << " ";
2873       const MEDFileFieldLoc *loc=_locs[i];
2874       if(loc)
2875         loc->simpleRepr(oss);
2876       else
2877         oss<< "EMPTY !\n";
2878     }
2879 }
2880
2881 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2882 {
2883   _file_name=fileName;
2884 }
2885
2886 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2887 {
2888   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2889     {
2890       DataArrayInt *elt(*it);
2891       if(elt)
2892         {
2893           std::string name(elt->getName());
2894           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2895             {
2896               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2897                 {
2898                   elt->setName((*it2).second.c_str());
2899                   return;
2900                 }
2901             }
2902         }
2903     }
2904 }
2905
2906 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2907 {
2908   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2909     {
2910       MEDFileFieldLoc *elt(*it);
2911       if(elt)
2912         {
2913           std::string name(elt->getName());
2914           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2915             {
2916               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2917                 {
2918                   elt->setName((*it2).second.c_str());
2919                   return;
2920                 }
2921             }
2922         }
2923     }
2924 }
2925
2926 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2927 {
2928   if(locId<0 || locId>=(int)_locs.size())
2929     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2930   return _locs[locId]->getNbOfGaussPtPerCell();
2931 }
2932
2933 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2934 {
2935   return getLocalizationFromId(getLocalizationId(locName));
2936 }
2937
2938 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2939 {
2940   if(locId<0 || locId>=(int)_locs.size())
2941     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2942   return *_locs[locId];
2943 }
2944
2945 namespace ParaMEDMEMImpl
2946 {
2947   class LocFinder
2948   {
2949   public:
2950     LocFinder(const std::string& loc):_loc(loc) { }
2951     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2952   private:
2953     const std::string &_loc;
2954   };
2955
2956   class PflFinder
2957   {
2958   public:
2959     PflFinder(const std::string& pfl):_pfl(pfl) { }
2960     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2961   private:
2962     const std::string& _pfl;
2963   };
2964 }
2965
2966 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2967 {
2968   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2969   if(it==_locs.end())
2970     {
2971       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2972       for(it=_locs.begin();it!=_locs.end();it++)
2973         oss << "\"" << (*it)->getName() << "\", ";
2974       throw INTERP_KERNEL::Exception(oss.str().c_str());
2975     }
2976   return std::distance(_locs.begin(),it);
2977 }
2978
2979 /*!
2980  * The returned value is never null.
2981  */
2982 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2983 {
2984   std::string pflNameCpp(pflName);
2985   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2986   if(it==_pfls.end())
2987     {
2988       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2989       for(it=_pfls.begin();it!=_pfls.end();it++)
2990         oss << "\"" << (*it)->getName() << "\", ";
2991       throw INTERP_KERNEL::Exception(oss.str().c_str());
2992     }
2993   return *it;
2994 }
2995
2996 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2997 {
2998   if(pflId<0 || pflId>=(int)_pfls.size())
2999     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3000   return _pfls[pflId];
3001 }
3002
3003 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3004 {
3005   if(locId<0 || locId>=(int)_locs.size())
3006     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3007   return *_locs[locId];
3008 }
3009
3010 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3011 {
3012   return getLocalizationFromId(getLocalizationId(locName));
3013 }
3014
3015 /*!
3016  * The returned value is never null.
3017  */
3018 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3019 {
3020   std::string pflNameCpp(pflName);
3021   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
3022   if(it==_pfls.end())
3023     {
3024       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3025       for(it=_pfls.begin();it!=_pfls.end();it++)
3026         oss << "\"" << (*it)->getName() << "\", ";
3027       throw INTERP_KERNEL::Exception(oss.str().c_str());
3028     }
3029   return *it;
3030 }
3031
3032 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3033 {
3034   if(pflId<0 || pflId>=(int)_pfls.size())
3035     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3036   return _pfls[pflId];
3037 }
3038
3039 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3040 {
3041   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
3042   int i=0;
3043   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3044     {
3045       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3046         newPfls.push_back(*it);
3047     }
3048   _pfls=newPfls;
3049 }
3050
3051 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3052 {
3053   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
3054   int i=0;
3055   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3056     {
3057       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3058         newLocs.push_back(*it);
3059     }
3060   _locs=newLocs;
3061 }
3062
3063 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3064 {
3065   int sz=_pfls.size();
3066   std::vector<std::string> ret(sz);
3067   for(int i=0;i<sz;i++)
3068     ret[i]=_pfls[i]->getName();
3069   return ret;
3070 }
3071
3072 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3073 {
3074   int sz=_locs.size();
3075   std::vector<std::string> ret(sz);
3076   for(int i=0;i<sz;i++)
3077     ret[i]=_locs[i]->getName();
3078   return ret;
3079 }
3080
3081 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3082 {
3083   std::vector<std::string> v=getPfls();
3084   std::string s(pflName);
3085   return std::find(v.begin(),v.end(),s)!=v.end();
3086 }
3087
3088 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3089 {
3090   std::vector<std::string> v=getLocs();
3091   std::string s(locName);
3092   return std::find(v.begin(),v.end(),s)!=v.end();
3093 }
3094
3095 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3096 {
3097   std::map<int,std::vector<int> > m;
3098   int i=0;
3099   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3100     {
3101       const DataArrayInt *tmp=(*it);
3102       if(tmp)
3103         {
3104           m[tmp->getHashCode()].push_back(i);
3105         }
3106     }
3107   std::vector< std::vector<int> > ret;
3108   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3109     {
3110       if((*it2).second.size()>1)
3111         {
3112           std::vector<int> ret0;
3113           bool equalityOrNot=false;
3114           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3115             {
3116               std::vector<int>::const_iterator it4=it3; it4++;
3117               for(;it4!=(*it2).second.end();it4++)
3118                 {
3119                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3120                     {
3121                       if(!equalityOrNot)
3122                         ret0.push_back(*it3);
3123                       ret0.push_back(*it4);
3124                       equalityOrNot=true;
3125                     }
3126                 }
3127             }
3128           if(!ret0.empty())
3129             ret.push_back(ret0);
3130         }
3131     }
3132   return ret;
3133 }
3134
3135 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3136 {
3137   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3138 }
3139
3140 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3141 {
3142   std::string name(pfl->getName());
3143   if(name.empty())
3144     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3145   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3146     if(name==(*it)->getName())
3147       {
3148         if(!pfl->isEqual(*(*it)))
3149           {
3150             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3151             throw INTERP_KERNEL::Exception(oss.str().c_str());
3152           }
3153       }
3154   pfl->incrRef();
3155   _pfls.push_back(pfl);
3156 }
3157
3158 void MEDFileFieldGlobs::appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
3159 {
3160   std::string name(locName);
3161   if(name.empty())
3162     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3163   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3164   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3165     if((*it)->isName(locName))
3166       {
3167         if(!(*it)->isEqual(*obj,1e-12))
3168           {
3169             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3170             throw INTERP_KERNEL::Exception(oss.str().c_str());
3171           }
3172       }
3173   _locs.push_back(obj);
3174 }
3175
3176 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3177 {
3178   std::vector<std::string> names=getPfls();
3179   return CreateNewNameNotIn("NewPfl_",names);
3180 }
3181
3182 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3183 {
3184   std::vector<std::string> names=getLocs();
3185   return CreateNewNameNotIn("NewLoc_",names);
3186 }
3187
3188 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3189 {
3190   for(std::size_t sz=0;sz<100000;sz++)
3191     {
3192       std::ostringstream tryName;
3193       tryName << prefix << sz;
3194       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3195         return tryName.str();
3196     }
3197   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3198 }
3199
3200 /*!
3201  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3202  *  \param [in] fname - the file name.
3203  */
3204 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
3205 {
3206 }
3207
3208 /*!
3209  * Creates an empty MEDFileFieldGlobsReal.
3210  */
3211 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3212 {
3213 }
3214
3215 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3216 {
3217   return 0;
3218 }
3219
3220 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3221 {
3222   std::vector<const BigMemoryObject *> ret;
3223   ret.push_back((const MEDFileFieldGlobs *)_globals);
3224   return ret;
3225 }
3226
3227 /*!
3228  * Returns a string describing profiles and Gauss points held in \a this.
3229  *  \return std::string - the description string.
3230  */
3231 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3232 {
3233   const MEDFileFieldGlobs *glob=_globals;
3234   std::ostringstream oss2; oss2 << glob;
3235   std::string stars(oss2.str().length(),'*');
3236   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3237   if(glob)
3238     glob->simpleRepr(oss);
3239   else
3240     oss << "NO GLOBAL INFORMATION !\n";
3241 }
3242
3243 void MEDFileFieldGlobsReal::resetContent()
3244 {
3245   _globals=MEDFileFieldGlobs::New();
3246 }
3247
3248 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3249 {
3250 }
3251
3252 /*!
3253  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3254  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3255  */
3256 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3257 {
3258   _globals=other._globals;
3259 }
3260
3261 /*!
3262  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3263  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3264  */
3265 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3266 {
3267   const MEDFileFieldGlobs *otherg(other._globals);
3268   if(!otherg)
3269     return ;
3270   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3271 }
3272
3273 /*!
3274  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3275  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3276  */
3277 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3278 {
3279   const MEDFileFieldGlobs *otherg(other._globals);
3280   if(!otherg)
3281     return ;
3282   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3283 }
3284
3285 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3286 {
3287   _globals=other._globals;
3288   if((const MEDFileFieldGlobs *)_globals)
3289     _globals=other._globals->deepCpy();
3290 }
3291
3292 /*!
3293  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3294  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3295  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3296  *         \a this and \a other MEDFileFieldGlobsReal.
3297  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3298  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3299  */
3300 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3301 {
3302   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3303   if(thisGlobals==otherGlobals)
3304     return ;
3305   if(!thisGlobals)
3306     {
3307       _globals=other._globals;
3308       return ;
3309     }
3310   _globals->appendGlobs(*other._globals,eps);
3311 }
3312
3313 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3314 {
3315   checkGlobsPflsPartCoherency();
3316   checkGlobsLocsPartCoherency();
3317 }
3318
3319 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3320 {
3321   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3322 }
3323
3324 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3325 {
3326   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3327 }
3328
3329 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3330 {
3331   contentNotNull()->loadProfileInFile(fid,id,pflName);
3332 }
3333
3334 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3335 {
3336   contentNotNull()->loadProfileInFile(fid,id);
3337 }
3338
3339 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3340 {
3341   contentNotNull()->loadGlobals(fid,*this);
3342 }
3343
3344 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3345 {
3346   contentNotNull()->loadAllGlobals(fid);
3347 }
3348
3349 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3350 {
3351   contentNotNull()->writeGlobals(fid,opt);
3352 }
3353
3354 /*!
3355  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3356  * or getPflsReallyUsedMulti().
3357  *  \return std::vector<std::string> - a sequence of names of all profiles.
3358  */
3359 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3360 {
3361   return contentNotNull()->getPfls();
3362 }
3363
3364 /*!
3365  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3366  * or getLocsReallyUsedMulti().
3367  *  \return std::vector<std::string> - a sequence of names of all localizations.
3368  */
3369 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3370 {
3371   return contentNotNull()->getLocs();
3372 }
3373
3374 /*!
3375  * Checks if the profile with a given name exists.
3376  *  \param [in] pflName - the profile name of interest.
3377  *  \return bool - \c true if the profile named \a pflName exists.
3378  */
3379 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3380 {
3381   return contentNotNull()->existsPfl(pflName);
3382 }
3383
3384 /*!
3385  * Checks if the localization with a given name exists.
3386  *  \param [in] locName - the localization name of interest.
3387  *  \return bool - \c true if the localization named \a locName exists.
3388  */
3389 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3390 {
3391   return contentNotNull()->existsLoc(locName);
3392 }
3393
3394 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3395 {
3396   return contentNotNull()->createNewNameOfPfl();
3397 }
3398
3399 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3400 {
3401   return contentNotNull()->createNewNameOfLoc();
3402 }
3403
3404 /*!
3405  * Sets the name of a MED file.
3406  *  \param [inout] fileName - the file name.
3407  */
3408 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3409 {
3410   contentNotNull()->setFileName(fileName);
3411 }
3412
3413 /*!
3414  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3415  * in the same order.
3416  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3417  *          Each item of this sequence is a vector containing ids of equal profiles.
3418  */
3419 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3420 {
3421   return contentNotNull()->whichAreEqualProfiles();
3422 }
3423
3424 /*!
3425  * Finds equal localizations.
3426  *  \param [in] eps - a precision used to compare real values of the localizations.
3427  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3428  *          Each item of this sequence is a vector containing ids of equal localizations.
3429  */
3430 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3431 {
3432   return contentNotNull()->whichAreEqualLocs(eps);
3433 }
3434
3435 /*!
3436  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3437  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3438  *        this sequence is a pair whose 
3439  *        - the first item is a vector of profile names to replace by the second item,
3440  *        - the second item is a profile name to replace every profile name of the first item.
3441  */
3442 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3443 {
3444   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3445 }
3446
3447 /*!
3448  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3449  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3450  *        this sequence is a pair whose 
3451  *        - the first item is a vector of localization names to replace by the second item,
3452  *        - the second item is a localization name to replace every localization name of the first item.
3453  */
3454 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3455 {
3456   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3457 }
3458
3459 /*!
3460  * Replaces references to some profiles (a reference is a profile name) by references
3461  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3462  * them-selves accordingly. <br>
3463  * This method is a generalization of changePflName().
3464  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3465  *        this sequence is a pair whose 
3466  *        - the first item is a vector of profile names to replace by the second item,
3467  *        - the second item is a profile name to replace every profile of the first item.
3468  * \sa changePflsRefsNamesGen()
3469  * \sa changePflName()
3470  */
3471 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3472 {
3473   changePflsRefsNamesGen(mapOfModif);
3474   changePflsNamesInStruct(mapOfModif);
3475 }
3476
3477 /*!
3478  * Replaces references to some localizations (a reference is a localization name) by references
3479  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3480  * them-selves accordingly. <br>
3481  * This method is a generalization of changeLocName().
3482  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3483  *        this sequence is a pair whose 
3484  *        - the first item is a vector of localization names to replace by the second item,
3485  *        - the second item is a localization name to replace every localization of the first item.
3486  * \sa changeLocsRefsNamesGen()
3487  * \sa changeLocName()
3488  */
3489 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3490 {
3491   changeLocsRefsNamesGen(mapOfModif);
3492   changeLocsNamesInStruct(mapOfModif);
3493 }
3494
3495 /*!
3496  * Renames the profile having a given name and updates references to this profile.
3497  *  \param [in] oldName - the name of the profile to rename.
3498  *  \param [in] newName - a new name of the profile.
3499  * \sa changePflsNames().
3500  */
3501 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3502 {
3503   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3504   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3505   mapOfModif[0]=p;
3506   changePflsNames(mapOfModif);
3507 }
3508
3509 /*!
3510  * Renames the localization having a given name and updates references to this localization.
3511  *  \param [in] oldName - the name of the localization to rename.
3512  *  \param [in] newName - a new name of the localization.
3513  * \sa changeLocsNames().
3514  */
3515 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3516 {
3517   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3518   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3519   mapOfModif[0]=p;
3520   changeLocsNames(mapOfModif);
3521 }
3522
3523 /*!
3524  * Removes duplicated profiles. Returns a map used to update references to removed 
3525  * profiles via changePflsRefsNamesGen().
3526  * Equal profiles are found using whichAreEqualProfiles().
3527  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3528  *          a sequence describing the performed replacements of profiles. Each element of
3529  *          this sequence is a pair whose
3530  *          - the first item is a vector of profile names replaced by the second item,
3531  *          - the second item is a profile name replacing every profile of the first item.
3532  */
3533 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3534 {
3535   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3536   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3537   int i=0;
3538   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3539     {
3540       std::vector< std::string > tmp((*it).size());
3541       int j=0;
3542       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3543         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3544       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3545       ret[i]=p;
3546       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3547       killProfileIds(tmp2);
3548     }
3549   changePflsRefsNamesGen(ret);
3550   return ret;
3551 }
3552
3553 /*!
3554  * Removes duplicated localizations. Returns a map used to update references to removed 
3555  * localizations via changeLocsRefsNamesGen().
3556  * Equal localizations are found using whichAreEqualLocs().
3557  *  \param [in] eps - a precision used to compare real values of the localizations.
3558  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3559  *          a sequence describing the performed replacements of localizations. Each element of
3560  *          this sequence is a pair whose
3561  *          - the first item is a vector of localization names replaced by the second item,
3562  *          - the second item is a localization name replacing every localization of the first item.
3563  */
3564 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3565 {
3566   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3567   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3568   int i=0;
3569   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3570     {
3571       std::vector< std::string > tmp((*it).size());
3572       int j=0;
3573       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3574         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3575       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3576       ret[i]=p;
3577       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3578       killLocalizationIds(tmp2);
3579     }
3580   changeLocsRefsNamesGen(ret);
3581   return ret;
3582 }
3583
3584 /*!
3585  * Returns number of Gauss points per cell in a given localization.
3586  *  \param [in] locId - an id of the localization of interest.
3587  *  \return int - the number of the Gauss points per cell.
3588  */
3589 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3590 {
3591   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3592 }
3593
3594 /*!
3595  * Returns an id of a localization by its name.
3596  *  \param [in] loc - the localization name of interest.
3597  *  \return int - the id of the localization.
3598  *  \throw If there is no a localization named \a loc.
3599  */
3600 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3601 {
3602   return contentNotNull()->getLocalizationId(loc);
3603 }
3604
3605 /*!
3606  * Returns the name of the MED file.
3607  *  \return const std::string&  - the MED file name.
3608  */
3609 std::string MEDFileFieldGlobsReal::getFileName() const
3610 {
3611   return contentNotNull()->getFileName();
3612 }
3613
3614 /*!
3615  * Returns a localization object by its name.
3616  *  \param [in] locName - the name of the localization of interest.
3617  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3618  *  \throw If there is no a localization named \a locName.
3619  */
3620 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3621 {
3622   return contentNotNull()->getLocalization(locName);
3623 }
3624
3625 /*!
3626  * Returns a localization object by its id.
3627  *  \param [in] locId - the id of the localization of interest.
3628  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3629  *  \throw If there is no a localization with id \a locId.
3630  */
3631 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3632 {
3633   return contentNotNull()->getLocalizationFromId(locId);
3634 }
3635
3636 /*!
3637  * Returns a profile array by its name.
3638  *  \param [in] pflName - the name of the profile of interest.
3639  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3640  *  \throw If there is no a profile named \a pflName.
3641  */
3642 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3643 {
3644   return contentNotNull()->getProfile(pflName);
3645 }
3646
3647 /*!
3648  * Returns a profile array by its id.
3649  *  \param [in] pflId - the id of the profile of interest.
3650  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3651  *  \throw If there is no a profile with id \a pflId.
3652  */
3653 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3654 {
3655   return contentNotNull()->getProfileFromId(pflId);
3656 }
3657
3658 /*!
3659  * Returns a localization object, apt for modification, by its id.
3660  *  \param [in] locId - the id of the localization of interest.
3661  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3662  *          having the id \a locId.
3663  *  \throw If there is no a localization with id \a locId.
3664  */
3665 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3666 {
3667   return contentNotNull()->getLocalizationFromId(locId);
3668 }
3669
3670 /*!
3671  * Returns a localization object, apt for modification, by its name.
3672  *  \param [in] locName - the name of the localization of interest.
3673  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3674  *          having the name \a locName.
3675  *  \throw If there is no a localization named \a locName.
3676  */
3677 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3678 {
3679   return contentNotNull()->getLocalization(locName);
3680 }
3681
3682 /*!
3683  * Returns a profile array, apt for modification, by its name.
3684  *  \param [in] pflName - the name of the profile of interest.
3685  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3686  *  \throw If there is no a profile named \a pflName.
3687  */
3688 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3689 {
3690   return contentNotNull()->getProfile(pflName);
3691 }
3692
3693 /*!
3694  * Returns a profile array, apt for modification, by its id.
3695  *  \param [in] pflId - the id of the profile of interest.
3696  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3697  *  \throw If there is no a profile with id \a pflId.
3698  */
3699 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3700 {
3701   return contentNotNull()->getProfileFromId(pflId);
3702 }
3703
3704 /*!
3705  * Removes profiles given by their ids. No data is updated to track this removal.
3706  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3707  */
3708 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3709 {
3710   contentNotNull()->killProfileIds(pflIds);
3711 }
3712
3713 /*!
3714  * Removes localizations given by their ids. No data is updated to track this removal.
3715  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3716  */
3717 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3718 {
3719   contentNotNull()->killLocalizationIds(locIds);
3720 }
3721
3722 /*!
3723  * Stores a profile array.
3724  *  \param [in] pfl - the profile array to store.
3725  *  \throw If the name of \a pfl is empty.
3726  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3727  *         different ids.
3728  */
3729 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3730 {
3731   contentNotNull()->appendProfile(pfl);
3732 }
3733
3734 /*!
3735  * Adds a new localization of Gauss points.
3736  *  \param [in] locName - the name of the new localization.
3737  *  \param [in] geoType - a geometrical type of the reference cell.
3738  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3739  *         must be \c nbOfNodesPerCell * \c dimOfType.
3740  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3741  *         must be  _wg_.size() * \c dimOfType.
3742  *  \param [in] w - the weights of Gauss points.
3743  *  \throw If \a locName is empty.
3744  *  \throw If a localization with the name \a locName already exists but is
3745  *         different form the new one.
3746  */
3747 void MEDFileFieldGlobsReal::appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
3748 {
3749   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3750 }
3751
3752 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3753 {
3754   MEDFileFieldGlobs *g(_globals);
3755   if(!g)
3756     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3757   return g;
3758 }
3759
3760 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3761 {
3762   const MEDFileFieldGlobs *g(_globals);
3763   if(!g)
3764     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3765   return g;
3766 }
3767
3768 //= MEDFileFieldNameScope
3769
3770 MEDFileFieldNameScope::MEDFileFieldNameScope()
3771 {
3772 }
3773
3774 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3775 {
3776 }
3777
3778 /*!
3779  * Returns the name of \a this field.
3780  *  \return std::string - a string containing the field name.
3781  */
3782 std::string MEDFileFieldNameScope::getName() const
3783 {
3784   return _name;
3785 }
3786
3787 /*!
3788  * Sets name of \a this field
3789  *  \param [in] name - the new field name.
3790  */
3791 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3792 {
3793   _name=fieldName;
3794 }
3795
3796 std::string MEDFileFieldNameScope::getDtUnit() const
3797 {
3798   return _dt_unit;
3799 }
3800
3801 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3802 {
3803   _dt_unit=dtUnit;
3804 }
3805
3806 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3807 {
3808   _name=other._name;
3809   _dt_unit=other._dt_unit;
3810 }
3811
3812 //= MEDFileAnyTypeField1TSWithoutSDA
3813
3814 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3815 {
3816   _field_per_mesh.resize(other._field_per_mesh.size());
3817   std::size_t i=0;
3818   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3819     {
3820       if((const MEDFileFieldPerMesh *)*it)
3821         _field_per_mesh[i]=(*it)->deepCpy(this);
3822     }
3823 }
3824
3825 /*!
3826  * Prints a string describing \a this field into a stream. This string is outputted 
3827  * by \c print Python command.
3828  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3829  *  \param [in,out] oss - the out stream.
3830  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3831  *          info id printed, else, not.
3832  */
3833 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3834 {
3835   std::string startOfLine(bkOffset,' ');
3836   oss << startOfLine << "Field ";
3837   if(bkOffset==0)
3838     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3839   oss << "on one time Step ";
3840   if(f1tsId>=0)
3841     oss << "(" << f1tsId << ") ";
3842   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3843   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3844   const DataArray *arr=getUndergroundDataArray();
3845   if(arr)
3846     {
3847       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3848       if(f1tsId<0)
3849         {
3850           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3851           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3852             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3853         }
3854       if(arr->isAllocated())
3855         {
3856           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3857         }
3858       else
3859         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3860     }
3861   else
3862     {
3863       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3864     }
3865   oss << startOfLine << "----------------------" << std::endl;
3866   if(!_field_per_mesh.empty())
3867     {
3868       int i=0;
3869       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3870         {
3871           const MEDFileFieldPerMesh *cur=(*it2);
3872           if(cur)
3873             cur->simpleRepr(bkOffset,oss,i);
3874           else
3875             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3876         }
3877     }
3878   else
3879     {
3880       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3881     }
3882   oss << startOfLine << "----------------------" << std::endl;
3883 }
3884
3885 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3886 {
3887   const DataArray *arr(getUndergroundDataArray());
3888   if(!arr)
3889     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3890   int nbOfCompo=arr->getNumberOfComponents();
3891   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3892   for(int i=0;i<nbOfCompo;i++)
3893     {
3894       ret[i]=deepCpy();
3895       std::vector<int> v(1,i);
3896       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3897       ret[i]->setArray(arr2);
3898     }
3899   return ret;
3900 }
3901
3902 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order):MEDFileFieldNameScope(fieldName),_iteration(iteration),_order(order),_csit(csit),_nb_of_tuples_to_be_allocated(-2)
3903 {
3904 }
3905
3906 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3907 {
3908 }
3909
3910 /*!
3911  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3912  * empty. Returns -1 if this in on nodes.
3913  *  \return int - the dimension of \a this.
3914  */
3915 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3916 {
3917   int ret=-2;
3918   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3919     (*it)->getDimension(ret);
3920   return ret;
3921 }
3922
3923 /*!
3924  * Returns the mesh name.
3925  *  \return std::string - a string holding the mesh name.
3926  *  \throw If \c _field_per_mesh.empty()
3927  */
3928 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3929 {
3930   if(_field_per_mesh.empty())
3931     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3932   return _field_per_mesh[0]->getMeshName();
3933 }
3934
3935 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3936 {
3937   std::string oldName(getMeshName());
3938   std::vector< std::pair<std::string,std::string> > v(1);
3939   v[0].first=oldName; v[0].second=newMeshName;
3940   changeMeshNames(v);
3941 }
3942
3943 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3944 {
3945   bool ret=false;
3946   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3947     {
3948       MEDFileFieldPerMesh *cur(*it);
3949       if(cur)
3950         ret=cur->changeMeshNames(modifTab) || ret;
3951     }
3952   return ret;
3953 }
3954
3955 /*!
3956  * Returns the number of iteration of the state of underlying mesh.
3957  *  \return int - the iteration number.
3958  *  \throw If \c _field_per_mesh.empty()
3959  */
3960 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3961 {
3962   if(_field_per_mesh.empty())
3963     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3964   return _field_per_mesh[0]->getMeshIteration();
3965 }
3966
3967 /*!
3968  * Returns the order number of iteration of the state of underlying mesh.
3969  *  \return int - the order number.
3970  *  \throw If \c _field_per_mesh.empty()
3971  */
3972 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3973 {
3974   if(_field_per_mesh.empty())
3975     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3976   return _field_per_mesh[0]->getMeshOrder();
3977 }
3978
3979 /*!
3980  * Checks if \a this field is tagged by a given iteration number and a given
3981  * iteration order number.
3982  *  \param [in] iteration - the iteration number of interest.
3983  *  \param [in] order - the iteration order number of interest.
3984  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3985  *          \a this->getOrder() == \a order.
3986  */
3987 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3988 {
3989   return iteration==_iteration && order==_order;
3990 }
3991
3992 /*!
3993  * Returns number of iteration and order number of iteration when
3994  * \a this field has been calculated.
3995  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3996  *          order number.
3997  */
3998 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3999 {
4000   std::pair<int,int> p;
4001   fillIteration(p);
4002   return p;
4003 }
4004
4005 /*!
4006  * Returns number of iteration and order number of iteration when
4007  * \a this field has been calculated.
4008  *  \param [in,out] p - a pair returning the iteration number and the iteration
4009  *          order number.
4010  */
4011 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4012 {
4013   p.first=_iteration;
4014   p.second=_order;
4015 }
4016
4017 /*!
4018  * Returns all types of spatial discretization of \a this field.
4019  *  \param [in,out] types - a sequence of types of \a this field.
4020  */
4021 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4022 {
4023   std::set<TypeOfField> types2;
4024   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4025     {
4026       (*it)->fillTypesOfFieldAvailable(types2);
4027     }
4028   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4029   std::copy(types2.begin(),types2.end(),bi);
4030 }
4031
4032 /*!
4033  * Returns all types of spatial discretization of \a this field.
4034  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4035  *          of \a this field.
4036  */
4037 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4038 {
4039   std::vector<TypeOfField> ret;
4040   fillTypesOfFieldAvailable(ret);
4041   return ret;
4042 }
4043
4044 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4045 {
4046   std::vector<std::string> ret;
4047   std::set<std::string> ret2;
4048   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4049     {
4050       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4051       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4052         if(ret2.find(*it2)==ret2.end())
4053           {
4054             ret.push_back(*it2);
4055             ret2.insert(*it2);
4056           }
4057     }
4058   return ret;
4059 }
4060
4061 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4062 {
4063   std::vector<std::string> ret;
4064   std::set<std::string> ret2;
4065   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4066     {
4067       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4068       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4069         if(ret2.find(*it2)==ret2.end())
4070           {
4071             ret.push_back(*it2);
4072             ret2.insert(*it2);
4073           }
4074     }
4075   return ret;
4076 }
4077
4078 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4079 {
4080   std::vector<std::string> ret;
4081   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4082     {
4083       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4084       ret.insert(ret.end(),tmp.begin(),tmp.end());
4085     }
4086   return ret;
4087 }
4088
4089 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4090 {
4091   std::vector<std::string> ret;
4092   std::set<std::string> ret2;
4093   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4094     {
4095       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4096       ret.insert(ret.end(),tmp.begin(),tmp.end());
4097     }
4098   return ret;
4099 }
4100
4101 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4102 {
4103   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4104     (*it)->changePflsRefsNamesGen(mapOfModif);
4105 }
4106
4107 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4108 {
4109   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4110     (*it)->changeLocsRefsNamesGen(mapOfModif);
4111 }
4112
4113 /*!
4114  * Returns all attributes of parts of \a this field lying on a given mesh.
4115  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4116  * item of every of returned sequences refers to the _i_-th part of \a this field.
4117  * Thus all sequences returned by this method are of the same length equal to number
4118  * of different types of supporting entities.<br>
4119  * A field part can include sub-parts with several different spatial discretizations,
4120  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4121  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4122  * of a nested sequence corresponds to a type of spatial discretization.<br>
4123  * This method allows for iteration over MEDFile DataStructure without any overhead.
4124  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4125  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4126  *          not checked if \a mname == \c NULL).
4127  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4128  *          a field part is returned. 
4129  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4130  *          This sequence is of the same length as \a types. 
4131  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4132  *          discretization. A profile name can be empty.
4133  *          Length of this and of nested sequences is the same as that of \a typesF.
4134  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4135  *          discretization. A localization name can be empty.
4136  *          Length of this and of nested sequences is the same as that of \a typesF.
4137  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4138  *          of ids of tuples within the data array, per each type of spatial
4139  *          discretization within one mesh entity type. 
4140  *          Length of this and of nested sequences is the same as that of \a typesF.
4141  *  \throw If no field is lying on \a mname.
4142  */
4143 std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeField1TSWithoutSDA::getFieldSplitedByType(const std::string& 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
4144 {
4145   int meshId=0;
4146   if(!mname.empty())
4147     meshId=getMeshIdFromMeshName(mname);
4148   else
4149     if(_field_per_mesh.empty())
4150       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4151   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4152 }
4153
4154 /*!
4155  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4156  * maximal absolute dimension and values returned via the out parameter \a levs are 
4157  * dimensions relative to the maximal absolute dimension. <br>
4158  * This method is designed for MEDFileField1TS instances that have a discretization
4159  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
4160  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
4161  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
4162  * Only these 3 discretizations will be taken into account here. If \a this is
4163  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4164  * This method is useful to make the link between the dimension of the underlying mesh
4165  * and the levels of \a this, because it is possible that the highest dimension of \a this
4166  * field is not equal to the dimension of the underlying mesh.
4167  * 
4168  * Let's consider the following case:
4169  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4170  * TETRA4, HEXA8, TRI3 and SEG2.
4171  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4172  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4173  *
4174  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4175  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4176  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4177  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4178  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4179  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4180  * For example<br>
4181  * to retrieve the highest level of
4182  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4183  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4184  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4185  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4186  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4187  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4188  *          not checked if \a mname == \c NULL).
4189  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4190  *          absolute one. They are in decreasing order. This sequence is cleared before
4191  *          filling it in.
4192  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4193  *  \throw If no field is lying on \a mname.
4194  */
4195 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4196 {
4197   levs.clear();
4198   int meshId=getMeshIdFromMeshName(mname);
4199   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4200   std::vector< std::vector<TypeOfField> > typesF;
4201   std::vector< std::vector<std::string> > pfls, locs;
4202   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4203   if(types.empty())
4204     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4205   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4206   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4207     return -1;
4208   st.erase(INTERP_KERNEL::NORM_ERROR);
4209   std::set<int> ret1;
4210   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4211     {
4212       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4213       ret1.insert((int)cm.getDimension());
4214     }
4215   int ret=*std::max_element(ret1.begin(),ret1.end());
4216   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4217   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4218   return ret;
4219 }
4220
4221 /*!
4222  * \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.
4223  * \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.
4224  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4225  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4226  */
4227 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4228 {
4229   int mid=getMeshIdFromMeshName(mName);
4230   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4231 }
4232
4233 /*!
4234  * \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.
4235  * \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.
4236  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4237  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4238  */
4239 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4240 {
4241   int mid=getMeshIdFromMeshName(mName);
4242   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4243 }
4244
4245 /*!
4246  * \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.
4247  */
4248 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4249 {
4250   if(_field_per_mesh.empty())
4251     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4252   if(mName.empty())
4253     return 0;
4254   std::string mName2(mName);
4255   int ret=0;
4256   std::vector<std::string> msg;
4257   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4258     if(mName2==(*it)->getMeshName())
4259       return ret;
4260     else
4261       msg.push_back((*it)->getMeshName());
4262   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4263   oss << "Possible meshes are : ";
4264   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4265     oss << "\"" << (*it2) << "\" ";
4266   throw INTERP_KERNEL::Exception(oss.str().c_str());
4267 }
4268
4269 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4270 {
4271   if(!mesh)
4272     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4273   std::string tmp(mesh->getName());
4274   if(tmp.empty())
4275     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4276   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4277   int i=0;
4278   for(;it!=_field_per_mesh.end();it++,i++)
4279     {
4280       if((*it)->getMeshName()==tmp)
4281         return i;
4282     }
4283   int sz=_field_per_mesh.size();
4284   _field_per_mesh.resize(sz+1);
4285   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4286   return sz;
4287 }
4288
4289 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4290                                                                    MEDFileFieldGlobsReal& glob)
4291 {
4292   bool ret=false;
4293   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4294     {
4295       MEDFileFieldPerMesh *fpm(*it);
4296       if(fpm)
4297         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4298     }
4299   return ret;
4300 }
4301
4302 /*!
4303  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4304  * splitting that leads to single spatial discretization of this.
4305  *
4306  * \sa splitMultiDiscrPerGeoTypes
4307  */
4308 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4309 {
4310   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4311   std::vector< std::vector<TypeOfField> > typesF;
4312   std::vector< std::vector<std::string> > pfls,locs;
4313   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4314   std::set<TypeOfField> allEnt;
4315   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4316     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4317       allEnt.insert(*it2);
4318   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4319   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4320   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4321     {
4322       std::vector< std::pair<int,int> > its;
4323       ret[i]=shallowCpy();
4324       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4325       ret[i]->updateData(newLgth,its);
4326     }
4327   return ret;
4328 }
4329
4330 /*!
4331  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4332  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4333  *
4334  * \sa splitDiscretizations
4335  */
4336 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4337 {
4338   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4339   std::vector< std::vector<TypeOfField> > typesF;
4340   std::vector< std::vector<std::string> > pfls,locs;
4341   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4342   std::set<TypeOfField> allEnt;
4343   std::size_t nbOfMDPGT(0),ii(0);
4344   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4345     {
4346       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4347       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4348         allEnt.insert(*it2);
4349     }
4350   if(allEnt.size()!=1)
4351     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4352   if(nbOfMDPGT==0)
4353     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4354   if(nbOfMDPGT==1)
4355     {
4356       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4357       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4358       return ret0;
4359     }
4360   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4361   for(std::size_t i=0;i<nbOfMDPGT;i++)
4362     {
4363       std::vector< std::pair<int,int> > its;
4364       ret[i]=shallowCpy();
4365       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4366       ret[i]->updateData(newLgth,its);
4367     }
4368   return ret;
4369 }
4370
4371 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4372 {
4373   int globalCounter(0);
4374   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4375     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4376   return globalCounter;
4377 }
4378
4379 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4380 {
4381   int globalCounter(0);
4382   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4383     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4384   return globalCounter;
4385 }
4386
4387 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4388 {
4389   if(_nb_of_tuples_to_be_allocated>=0)
4390     {
4391       _nb_of_tuples_to_be_allocated=newLgth;
4392       const DataArray *oldArr(getUndergroundDataArray());
4393       if(oldArr)
4394         {
4395           MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4396           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4397           setArray(newArr);
4398           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4399         }
4400       return ;
4401     }
4402   if(_nb_of_tuples_to_be_allocated==-1)
4403     return ;
4404   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4405     {
4406       const DataArray *oldArr(getUndergroundDataArray());
4407       if(!oldArr || !oldArr->isAllocated())
4408         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4409       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4410       newArr->alloc(newLgth,getNumberOfComponents());
4411       if(oldArr)
4412         newArr->copyStringInfoFrom(*oldArr);
4413       int pos=0;
4414       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4415         {
4416           if((*it).second<(*it).first)
4417             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4418           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4419           pos+=(*it).second-(*it).first;
4420         }
4421       setArray(newArr);
4422       return ;
4423     }
4424   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4425 }
4426
4427 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4428 {
4429   if(_field_per_mesh.empty())
4430     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4431   if(_field_per_mesh.size()>1)
4432     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4433   _field_per_mesh[0]->copyOptionsFrom(opts);
4434   _field_per_mesh[0]->writeLL(fid,nasc);
4435 }
4436
4437 /*!
4438  * 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.
4439  * If false is returned the memory allocation is not required.
4440  */
4441 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4442 {
4443   if(_nb_of_tuples_to_be_allocated>=0)
4444     {
4445       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4446       _nb_of_tuples_to_be_allocated=-2;
4447       return true;
4448     }
4449   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4450     return false;
4451   if(_nb_of_tuples_to_be_allocated==-1)
4452     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4453   if(_nb_of_tuples_to_be_allocated<-3)
4454     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4455   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4456 }
4457
4458 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4459 {
4460   med_int numdt,numit;
4461   med_float dt;
4462   med_int nmesh;
4463   med_bool localMesh;
4464   med_int meshnumdt,meshnumit;
4465   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4466   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4467   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4468   if(_iteration!=numdt || _order!=numit)
4469     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4470   _field_per_mesh.resize(nmesh);
4471   //
4472   MEDFileMesh *mm(0);
4473   if(ms)
4474     {
4475       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4476       mm=ms->getMeshWithName(meshNameCpp);
4477     }
4478   //
4479   for(int i=0;i<nmesh;i++)
4480     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4481   _nb_of_tuples_to_be_allocated=0;
4482   for(int i=0;i<nmesh;i++)
4483     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4484 }
4485
4486 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4487 {
4488   allocIfNecessaryTheArrayToReceiveDataFromFile();
4489   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4490     (*it)->loadBigArraysRecursively(fid,nasc);
4491 }
4492
4493 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4494 {
4495   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4496     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4497       (*it)->loadBigArraysRecursively(fid,nasc);
4498 }
4499
4500 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4501 {
4502   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4503   loadBigArraysRecursively(fid,nasc);
4504 }
4505
4506 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4507 {
4508   DataArray *thisArr(getUndergroundDataArray());
4509   if(thisArr && thisArr->isAllocated())
4510     {
4511       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4512       thisArr->desallocate();
4513     }
4514 }
4515
4516 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4517 {
4518   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4519 }
4520
4521 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4522 {
4523   std::vector<const BigMemoryObject *> ret;
4524   if(getUndergroundDataArray())
4525     ret.push_back(getUndergroundDataArray());
4526   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4527     ret.push_back((const MEDFileFieldPerMesh *)*it);
4528   return ret;
4529 }
4530
4531 /*!
4532  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4533  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4534  * "Sort By Type"), if not, an exception is thrown. 
4535  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4536  *  \param [in] arr - the array of values.
4537  *  \param [in,out] glob - the global data where profiles and localization present in
4538  *          \a field, if any, are added.
4539  *  \throw If the name of \a field is empty.
4540  *  \throw If the data array of \a field is not set.
4541  *  \throw If \a this->_arr is already allocated but has different number of components
4542  *         than \a field.
4543  *  \throw If the underlying mesh of \a field has no name.
4544  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4545  */
4546 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4547 {
4548   const MEDCouplingMesh *mesh=field->getMesh();
4549   //
4550   TypeOfField type=field->getTypeOfField();
4551   std::vector<DataArrayInt *> dummy;
4552   int start=copyTinyInfoFrom(field,arr);
4553   int pos=addNewEntryIfNecessary(mesh);
4554   if(type!=ON_NODES)
4555     {
4556       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4557       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4558     }
4559   else
4560     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4561 }
4562
4563 /*!
4564  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4565  * of a given mesh are used as the support of the given field (a real support is not used). 
4566  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4567  * Order of underlying mesh entities of the given field specified by \a profile parameter
4568  * is not prescribed; this method permutes field values to have them sorted by element
4569  * type as required for writing to MED file. A new profile is added only if no equal
4570  * profile is missing. 
4571  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4572  *  \param [in] arrOfVals - the values of the field \a field used.
4573  *  \param [in] mesh - the supporting mesh of \a field.
4574  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4575  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4576  *  \param [in,out] glob - the global data where profiles and localization present in
4577  *          \a field, if any, are added.
4578  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4579  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4580  *  \throw If the data array of \a field is not set.
4581  *  \throw If \a this->_arr is already allocated but has different number of components
4582  *         than \a field.
4583  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4584  *  \sa setFieldNoProfileSBT()
4585  */
4586 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4587 {
4588   if(!field)
4589     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4590   if(!arrOfVals || !arrOfVals->isAllocated())
4591     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4592   TypeOfField type=field->getTypeOfField();
4593   std::vector<DataArrayInt *> idsInPflPerType;
4594   std::vector<DataArrayInt *> idsPerType;
4595   std::vector<int> code,code2;
4596   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4597   if(type!=ON_NODES)
4598     {
4599       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4600       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4601       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4602       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4603       // start of check
4604       MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2=field->clone(false);
4605       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4606       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4607         {
4608           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4609           throw INTERP_KERNEL::Exception(oss.str().c_str());
4610         }
4611       // end of check
4612       int start=copyTinyInfoFrom(field,arrOfVals);
4613       code2=m->getDistributionOfTypes();
4614       //
4615       int pos=addNewEntryIfNecessary(m);
4616       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4617     }
4618   else
4619     {
4620       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4621         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4622       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4623       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4624       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4625       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4626         {
4627           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4628           throw INTERP_KERNEL::Exception(oss.str().c_str());
4629         }
4630       int start=copyTinyInfoFrom(field,arrOfVals);
4631       int pos=addNewEntryIfNecessary(m);
4632       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4633     }
4634 }
4635
4636 /*!
4637  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4638  */
4639 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4640 {
4641   if(_nb_of_tuples_to_be_allocated>=0)
4642     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 !");
4643   DataArray *arr(getOrCreateAndGetArray());
4644   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4645   _nb_of_tuples_to_be_allocated=-3;
4646 }
4647
4648 /*!
4649  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4650  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4651  * larger by the size of \a field. Returns an id of the first not filled
4652  * tuple of \a this->_arr.
4653  *  \param [in] field - the field to copy the info on components and the name from.
4654  *  \return int - the id of first not initialized tuple of \a this->_arr.
4655  *  \throw If the name of \a field is empty.
4656  *  \throw If the data array of \a field is not set.
4657  *  \throw If \a this->_arr is already allocated but has different number of components
4658  *         than \a field.
4659  */
4660 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4661 {
4662   if(!field)
4663     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4664   std::string name(field->getName());
4665   setName(name.c_str());
4666   setDtUnit(field->getTimeUnit());
4667   if(name.empty())
4668     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4669   if(!arr)
4670     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4671   if(!arr->isAllocated())
4672     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4673   _dt=field->getTime(_iteration,_order);
4674   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4675   if(!getOrCreateAndGetArray()->isAllocated())
4676     {
4677       allocNotFromFile(arr->getNumberOfTuples());
4678       return 0;
4679     }
4680   else
4681     {
4682       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4683       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4684       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4685       _nb_of_tuples_to_be_allocated=-3;
4686       return oldNbOfTuples;
4687     }
4688 }
4689
4690 /*!
4691  * Returns number of components in \a this field
4692  *  \return int - the number of components.
4693  */
4694 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4695 {
4696   return getOrCreateAndGetArray()->getNumberOfComponents();
4697 }
4698
4699 /*!
4700  * Change info on components in \a this.
4701  * \throw If size of \a infos is not equal to the number of components already in \a this.
4702  */
4703 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4704 {
4705   DataArray *arr=getOrCreateAndGetArray();
4706   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4707 }
4708
4709 /*!
4710  * Returns info on components of \a this field.
4711  *  \return const std::vector<std::string>& - a sequence of strings each being an
4712  *          information on _i_-th component.
4713  */
4714 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4715 {
4716   const DataArray *arr=getOrCreateAndGetArray();
4717   return arr->getInfoOnComponents();
4718 }
4719
4720 /*!
4721  * Returns a mutable info on components of \a this field.
4722  *  \return std::vector<std::string>& - a sequence of strings each being an
4723  *          information on _i_-th component.
4724  */
4725 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4726 {
4727   DataArray *arr=getOrCreateAndGetArray();
4728   return arr->getInfoOnComponents();
4729 }
4730
4731 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4732 {
4733   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4734     {
4735       const MEDFileFieldPerMesh *fpm(*it);
4736       if(!fpm)
4737         continue;
4738       if(fpm->presenceOfMultiDiscPerGeoType())
4739         return true;
4740     }
4741   return false;
4742 }
4743
4744 /*!
4745  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4746  *  \param [in] type - a spatial discretization of the new field.
4747  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4748  *  \param [in] mName - a name of the supporting mesh.
4749  *  \param [in] renumPol - specifies how to permute values of the result field according to
4750  *          the optional numbers of cells and nodes, if any. The valid values are
4751  *          - 0 - do not permute.
4752  *          - 1 - permute cells.
4753  *          - 2 - permute nodes.
4754  *          - 3 - permute cells and nodes.
4755  *
4756  *  \param [in] glob - the global data storing profiles and localization.
4757  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4758  *          caller is to delete this field using decrRef() as it is no more needed. 
4759  *  \throw If the MED file is not readable.
4760  *  \throw If there is no mesh named \a mName in the MED file.
4761  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4762  *  \throw If no field of \a this is lying on the mesh \a mName.
4763  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4764  */
4765 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4766 {
4767   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4768   if(mName.empty())
4769     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4770   else
4771     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4772   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4773 }
4774
4775 /*!
4776  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4777  *  \param [in] type - a spatial discretization of the new field.
4778  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4779  *  \param [in] renumPol - specifies how to permute values of the result field according to
4780  *          the optional numbers of cells and nodes, if any. The valid values are
4781  *          - 0 - do not permute.
4782  *          - 1 - permute cells.
4783  *          - 2 - permute nodes.
4784  *          - 3 - permute cells and nodes.
4785  *
4786  *  \param [in] glob - the global data storing profiles and localization.
4787  *  \param [in] mesh - the supporting mesh.
4788  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4789  *          caller is to delete this field using decrRef() as it is no more needed. 
4790  *  \throw If the MED file is not readable.
4791  *  \throw If no field of \a this is lying on \a mesh.
4792  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4793  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4794  */
4795 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4796 {
4797   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4798   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4799   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4800   if(meshDimRelToMax==1)
4801     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4802   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4803 }
4804
4805 /*!
4806  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4807  * given mesh. 
4808  *  \param [in] type - a spatial discretization of the new field.
4809  *  \param [in] mName - a name of the supporting mesh.
4810  *  \param [in] renumPol - specifies how to permute values of the result field according to
4811  *          the optional numbers of cells and nodes, if any. The valid values are
4812  *          - 0 - do not permute.
4813  *          - 1 - permute cells.
4814  *          - 2 - permute nodes.
4815  *          - 3 - permute cells and nodes.
4816  *
4817  *  \param [in] glob - the global data storing profiles and localization.
4818  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4819  *          caller is to delete this field using decrRef() as it is no more needed. 
4820  *  \throw If the MED file is not readable.
4821  *  \throw If there is no mesh named \a mName in the MED file.
4822  *  \throw If there are no mesh entities in the mesh.
4823  *  \throw If no field values of the given \a type are available.
4824  */
4825 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4826 {
4827   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4828   if(mName.empty())
4829     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4830   else
4831     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4832   int absDim=getDimension();
4833   int meshDimRelToMax=absDim-mm->getMeshDimension();
4834   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4835 }
4836
4837 /*!
4838  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4839  *  \param [in] type - a spatial discretization of the new field.
4840  *  \param [in] renumPol - specifies how to permute values of the result field according to
4841  *          the optional numbers of cells and nodes, if any. The valid values are
4842  *          - 0 - do not permute.
4843  *          - 1 - permute cells.
4844  *          - 2 - permute nodes.
4845  *          - 3 - permute cells and nodes.
4846  *
4847  *  \param [in] glob - the global data storing profiles and localization.
4848  *  \param [in] mesh - the supporting mesh.
4849  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4850  *         field according to \a renumPol.
4851  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4852  *         field according to \a renumPol.
4853  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4854  *          caller is to delete this field using decrRef() as it is no more needed. 
4855  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4856  *  \throw If no field of \a this is lying on \a mesh.
4857  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4858  */
4859 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
4860 {
4861   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4862   int meshId=getMeshIdFromMeshName(mesh->getName());
4863   bool isPfl=false;
4864   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4865   switch(renumPol)
4866   {
4867     case 0:
4868       {
4869         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4870         return ret.retn();
4871       }
4872     case 3:
4873     case 1:
4874       {
4875         if(isPfl)
4876           throw INTERP_KERNEL::Exception(msg1);
4877         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4878         if(cellRenum)
4879           {
4880             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4881               {
4882                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4883                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4884                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4885               }
4886             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4887             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4888             std::vector<DataArray *> arrOut2(1,arrOut);
4889             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4890             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4891             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4892           }
4893         if(renumPol==1)
4894           return ret.retn();
4895       }
4896     case 2:
4897       {
4898         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4899         if(isPfl)
4900           throw INTERP_KERNEL::Exception(msg1);
4901         if(nodeRenum)
4902           {
4903             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4904               {
4905                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4906                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4907                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4908               }
4909             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4910             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4911               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4912             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4913           }
4914         return ret.retn();
4915       }
4916     default:
4917       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4918   }
4919 }
4920
4921 /*!
4922  * Returns values and a profile of the field of a given type lying on a given support.
4923  *  \param [in] type - a spatial discretization of the field.
4924  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4925  *  \param [in] mesh - the supporting mesh.
4926  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4927  *          field of interest lies on. If the field lies on all entities of the given
4928  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4929  *          using decrRef() as it is no more needed.  
4930  *  \param [in] glob - the global data storing profiles and localization.
4931  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4932  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4933  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4934  *  \throw If no field of \a this is lying on \a mesh.
4935  *  \throw If no field values of the given \a type are available.
4936  */
4937 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4938 {
4939   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4940   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4941   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4942   ret->setName(nasc.getName().c_str());
4943   return ret.retn();
4944 }
4945
4946 //= MEDFileField1TSWithoutSDA
4947
4948 /*!
4949  * Throws if a given value is not a valid (non-extended) relative dimension.
4950  *  \param [in] meshDimRelToMax - the relative dimension value.
4951  *  \throw If \a meshDimRelToMax > 0.
4952  */
4953 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4954 {
4955   if(meshDimRelToMax>0)
4956     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4957 }
4958
4959 /*!
4960  * Checks if elements of a given mesh are in the order suitable for writing 
4961  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4962  * vector describing types of elements and their number.
4963  *  \param [in] mesh - the mesh to check.
4964  *  \return std::vector<int> - a vector holding for each element type (1) item of
4965  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4966  *          These values are in full-interlace mode.
4967  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4968  */
4969 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4970 {
4971   if(!mesh)
4972     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4973   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4974   int nbOfTypes=geoTypes.size();
4975   std::vector<int> code(3*nbOfTypes);
4976   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4977   arr1->alloc(nbOfTypes,1);
4978   int *arrPtr=arr1->getPointer();
4979   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4980   for(int i=0;i<nbOfTypes;i++,it++)
4981     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4982   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4983   const int *arrPtr2=arr2->getConstPointer();
4984   int i=0;
4985   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4986     {
4987       int pos=arrPtr2[i];
4988       int nbCells=mesh->getNumberOfCellsWithType(*it);
4989       code[3*pos]=(int)(*it);
4990       code[3*pos+1]=nbCells;
4991       code[3*pos+2]=-1;//no profiles
4992     }
4993   std::vector<const DataArrayInt *> idsPerType;//no profiles
4994   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4995   if(da)
4996     {
4997       da->decrRef();
4998       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4999     }
5000   return code;
5001 }
5002
5003 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5004 {
5005   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5006 }
5007
5008 /*!
5009  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5010  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5011  * item of every of returned sequences refers to the _i_-th part of \a this field.
5012  * Thus all sequences returned by this method are of the same length equal to number
5013  * of different types of supporting entities.<br>
5014  * A field part can include sub-parts with several different spatial discretizations,
5015  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
5016  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5017  * of a nested sequence corresponds to a type of spatial discretization.<br>
5018  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5019  * The overhead is due to selecting values into new instances of DataArrayDouble.
5020  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5021  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5022  *          not checked if \a mname == \c NULL).
5023  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5024  *          a field part is returned. 
5025  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5026  *          A field part can include sub-parts with several different spatial discretizations,
5027  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
5028  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5029  *          This sequence is of the same length as \a types. 
5030  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5031  *          discretization. A profile name can be empty.
5032  *          Length of this and of nested sequences is the same as that of \a typesF.
5033  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5034  *          discretization. A localization name can be empty.
5035  *          Length of this and of nested sequences is the same as that of \a typesF.
5036  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5037  *          per each type of spatial discretization within one mesh entity type.
5038  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5039  *          Length of this and of nested sequences is the same as that of \a typesF.
5040  *  \throw If no field is lying on \a mname.
5041  */
5042 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TSWithoutSDA::getFieldSplitedByType2(const std::string& 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
5043 {
5044   int meshId=0;
5045   if(!mname.empty())
5046     meshId=getMeshIdFromMeshName(mname);
5047   else
5048     if(_field_per_mesh.empty())
5049       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5050   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5051   int nbOfRet=ret0.size();
5052   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5053   for(int i=0;i<nbOfRet;i++)
5054     {
5055       const std::vector< std::pair<int,int> >& p=ret0[i];
5056       int nbOfRet1=p.size();
5057       ret[i].resize(nbOfRet1);
5058       for(int j=0;j<nbOfRet1;j++)
5059         {
5060           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
5061           ret[i][j]=tmp;
5062         }
5063     }
5064   return ret;
5065 }
5066
5067 /*!
5068  * Returns a pointer to the underground DataArrayDouble instance. So the
5069  * caller should not decrRef() it. This method allows for a direct access to the field
5070  * values. This method is quite unusable if there is more than a nodal field or a cell
5071  * field on single geometric cell type. 
5072  *  \return DataArrayDouble * - the pointer to the field values array.
5073  */
5074 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
5075 {
5076   const DataArrayDouble *ret=_arr;
5077   if(ret)
5078     return const_cast<DataArrayDouble *>(ret);
5079   else
5080     return 0;
5081 }
5082
5083 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5084 {
5085   return TYPE_STR;
5086 }
5087
5088 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5089 {
5090   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5091   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5092   ret->deepCpyLeavesFrom(*this);
5093   const DataArrayDouble *arr(_arr);
5094   if(arr)
5095     {
5096       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
5097       ret->setArray(arr2);
5098     }
5099   return ret.retn();
5100 }
5101
5102 /*!
5103  * Returns a pointer to the underground DataArrayDouble instance. So the
5104  * caller should not decrRef() it. This method allows for a direct access to the field
5105  * values. This method is quite unusable if there is more than a nodal field or a cell
5106  * field on single geometric cell type. 
5107  *  \return DataArrayDouble * - the pointer to the field values array.
5108  */
5109 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
5110 {
5111   return getUndergroundDataArrayDouble();
5112 }
5113
5114 /*!
5115  * Returns a pointer to the underground DataArrayDouble instance and a
5116  * sequence describing parameters of a support of each part of \a this field. The
5117  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5118  * direct access to the field values. This method is intended for the field lying on one
5119  * mesh only.
5120  *  \param [in,out] entries - the sequence describing parameters of a support of each
5121  *         part of \a this field. Each item of this sequence consists of two parts. The
5122  *         first part describes a type of mesh entity and an id of discretization of a
5123  *         current field part. The second part describes a range of values [begin,end)
5124  *         within the returned array relating to the current field part.
5125  *  \return DataArrayDouble * - the pointer to the field values array.
5126  *  \throw If the number of underlying meshes is not equal to 1.
5127  *  \throw If no field values are available.
5128  *  \sa getUndergroundDataArray()
5129  */
5130 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5131 {
5132   if(_field_per_mesh.size()!=1)
5133     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5134   if(_field_per_mesh[0]==0)
5135     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5136   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5137   return getUndergroundDataArrayDouble();
5138 }
5139
5140 /*!
5141  * Returns a pointer to the underground DataArrayDouble instance and a
5142  * sequence describing parameters of a support of each part of \a this field. The
5143  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5144  * direct access to the field values. This method is intended for the field lying on one
5145  * mesh only.
5146  *  \param [in,out] entries - the sequence describing parameters of a support of each
5147  *         part of \a this field. Each item of this sequence consists of two parts. The
5148  *         first part describes a type of mesh entity and an id of discretization of a
5149  *         current field part. The second part describes a range of values [begin,end)
5150  *         within the returned array relating to the current field part.
5151  *  \return DataArrayDouble * - the pointer to the field values array.
5152  *  \throw If the number of underlying meshes is not equal to 1.
5153  *  \throw If no field values are available.
5154  *  \sa getUndergroundDataArray()
5155  */
5156 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5157 {
5158   return getUndergroundDataArrayDoubleExt(entries);
5159 }
5160
5161 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5162 {
5163   DataArrayDouble *arr(getOrCreateAndGetArrayDouble());
5164   arr->setInfoAndChangeNbOfCompo(infos);
5165 }
5166
5167 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5168 {
5169 }
5170
5171 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5172 {
5173   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5174   ret->deepCpyLeavesFrom(*this);
5175   return ret.retn();
5176 }
5177
5178 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const
5179 {
5180   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5181   if((const DataArrayDouble *)_arr)
5182     ret->_arr=_arr->deepCpy();
5183   return ret.retn();
5184 }
5185
5186 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
5187 {
5188   if(!arr)
5189     {
5190       _nb_of_tuples_to_be_allocated=-1;
5191       _arr=0;
5192       return ;
5193     }
5194   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
5195   if(!arrC)
5196     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
5197   else
5198     _nb_of_tuples_to_be_allocated=-3;
5199   arrC->incrRef();
5200   _arr=arrC;
5201 }
5202
5203 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5204 {
5205   return DataArrayDouble::New();
5206 }
5207
5208 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
5209 {
5210   DataArrayDouble *ret=_arr;
5211   if(ret)
5212     return ret;
5213   _arr=DataArrayDouble::New();
5214   return _arr;
5215 }
5216
5217 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
5218 {
5219   return getOrCreateAndGetArrayDouble();
5220 }
5221
5222 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
5223 {
5224   const DataArrayDouble *ret=_arr;
5225   if(ret)
5226     return ret;
5227   DataArrayDouble *ret2=DataArrayDouble::New();
5228   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
5229   return ret2;
5230 }
5231
5232 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
5233 {
5234   return getOrCreateAndGetArrayDouble();
5235 }
5236
5237 //= MEDFileIntField1TSWithoutSDA
5238
5239 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5240 {
5241   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5242 }
5243
5244 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5245 {
5246 }
5247
5248 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5249                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5250 {
5251   DataArrayInt *arr(getOrCreateAndGetArrayInt());
5252   arr->setInfoAndChangeNbOfCompo(infos);
5253 }
5254
5255 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5256 {
5257   return TYPE_STR;
5258 }
5259
5260 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5261 {
5262   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5263   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5264   ret->deepCpyLeavesFrom(*this);
5265   const DataArrayInt *arr(_arr);
5266   if(arr)
5267     {
5268       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
5269       ret->setArray(arr2);
5270     }
5271   return ret.retn();
5272 }
5273
5274 /*!
5275  * Returns a pointer to the underground DataArrayInt instance. So the
5276  * caller should not decrRef() it. This method allows for a direct access to the field
5277  * values. This method is quite unusable if there is more than a nodal field or a cell
5278  * field on single geometric cell type. 
5279  *  \return DataArrayInt * - the pointer to the field values array.
5280  */
5281 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
5282 {
5283   return getUndergroundDataArrayInt();
5284 }
5285
5286 /*!
5287  * Returns a pointer to the underground DataArrayInt instance. So the
5288  * caller should not decrRef() it. This method allows for a direct access to the field
5289  * values. This method is quite unusable if there is more than a nodal field or a cell
5290  * field on single geometric cell type. 
5291  *  \return DataArrayInt * - the pointer to the field values array.
5292  */
5293 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5294 {
5295   const DataArrayInt *ret=_arr;
5296   if(ret)
5297     return const_cast<DataArrayInt *>(ret);
5298   else
5299     return 0;
5300 }
5301
5302 /*!
5303  * Returns a pointer to the underground DataArrayInt instance and a
5304  * sequence describing parameters of a support of each part of \a this field. The
5305  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5306  * direct access to the field values. This method is intended for the field lying on one
5307  * mesh only.
5308  *  \param [in,out] entries - the sequence describing parameters of a support of each
5309  *         part of \a this field. Each item of this sequence consists of two parts. The
5310  *         first part describes a type of mesh entity and an id of discretization of a
5311  *         current field part. The second part describes a range of values [begin,end)
5312  *         within the returned array relating to the current field part.
5313  *  \return DataArrayInt * - the pointer to the field values array.
5314  *  \throw If the number of underlying meshes is not equal to 1.
5315  *  \throw If no field values are available.
5316  *  \sa getUndergroundDataArray()
5317  */
5318 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5319 {
5320   return getUndergroundDataArrayIntExt(entries);
5321 }
5322
5323 /*!
5324  * Returns a pointer to the underground DataArrayInt instance and a
5325  * sequence describing parameters of a support of each part of \a this field. The
5326  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5327  * direct access to the field values. This method is intended for the field lying on one
5328  * mesh only.
5329  *  \param [in,out] entries - the sequence describing parameters of a support of each
5330  *         part of \a this field. Each item of this sequence consists of two parts. The
5331  *         first part describes a type of mesh entity and an id of discretization of a
5332  *         current field part. The second part describes a range of values [begin,end)
5333  *         within the returned array relating to the current field part.
5334  *  \return DataArrayInt * - the pointer to the field values array.
5335  *  \throw If the number of underlying meshes is not equal to 1.
5336  *  \throw If no field values are available.
5337  *  \sa getUndergroundDataArray()
5338  */
5339 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5340 {
5341   if(_field_per_mesh.size()!=1)
5342     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5343   if(_field_per_mesh[0]==0)
5344     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5345   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5346   return getUndergroundDataArrayInt();
5347 }
5348
5349 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5350 {
5351   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5352   ret->deepCpyLeavesFrom(*this);
5353   return ret.retn();
5354 }
5355
5356 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const
5357 {
5358   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5359   if((const DataArrayInt *)_arr)
5360     ret->_arr=_arr->deepCpy();
5361   return ret.retn();
5362 }
5363
5364 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5365 {
5366   if(!arr)
5367     {
5368       _nb_of_tuples_to_be_allocated=-1;
5369       _arr=0;
5370       return ;
5371     }
5372   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5373   if(!arrC)
5374     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5375   else
5376     _nb_of_tuples_to_be_allocated=-3;
5377   arrC->incrRef();
5378   _arr=arrC;
5379 }
5380
5381 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5382 {
5383   return DataArrayInt::New();
5384 }
5385
5386 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5387 {
5388   DataArrayInt *ret=_arr;
5389   if(ret)
5390     return ret;
5391   _arr=DataArrayInt::New();
5392   return _arr;
5393 }
5394
5395 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5396 {
5397   return getOrCreateAndGetArrayInt();
5398 }
5399
5400 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5401 {
5402   const DataArrayInt *ret=_arr;
5403   if(ret)
5404     return ret;
5405   DataArrayInt *ret2=DataArrayInt::New();
5406   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5407   return ret2;
5408 }
5409
5410 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5411 {
5412   return getOrCreateAndGetArrayInt();
5413 }
5414
5415 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5416 {
5417 }
5418
5419 //= MEDFileAnyTypeField1TS
5420
5421 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5422 {
5423   med_field_type typcha;
5424   //
5425   std::vector<std::string> infos;
5426   std::string dtunit,fieldName;
5427   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5428   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5429   switch(typcha)
5430   {
5431     case MED_FLOAT64:
5432       {
5433         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5434         break;
5435       }
5436     case MED_INT32:
5437       {
5438         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5439         break;
5440       }
5441     default:
5442       {
5443         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] !";
5444         throw INTERP_KERNEL::Exception(oss.str().c_str());
5445       }
5446   }
5447   ret->setDtUnit(dtunit.c_str());
5448   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5449   //
5450   med_int numdt,numit;
5451   med_float dt;
5452   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5453   ret->setTime(numdt,numit,dt);
5454   ret->_csit=1;
5455   if(loadAll)
5456     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5457   else
5458     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5459   return ret.retn();
5460 }
5461
5462 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5463 try:MEDFileFieldGlobsReal(fileName)
5464 {
5465   MEDFileUtilities::CheckFileForRead(fileName);
5466   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5467   _content=BuildContentFrom(fid,fileName,loadAll,ms);
5468   loadGlobals(fid);
5469 }
5470 catch(INTERP_KERNEL::Exception& e)
5471 {
5472     throw e;
5473 }
5474
5475 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5476 {
5477   med_field_type typcha;
5478   std::vector<std::string> infos;
5479   std::string dtunit;
5480   int iii=-1;
5481   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5482   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5483   switch(typcha)
5484   {
5485     case MED_FLOAT64:
5486       {
5487         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5488         break;
5489       }
5490     case MED_INT32:
5491       {
5492         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5493         break;
5494       }
5495     default:
5496       {
5497         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] !";
5498         throw INTERP_KERNEL::Exception(oss.str().c_str());
5499       }
5500   }
5501   ret->setDtUnit(dtunit.c_str());
5502   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5503   //
5504   if(nbSteps<1)
5505     {
5506       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5507       throw INTERP_KERNEL::Exception(oss.str().c_str());
5508     }
5509   //
5510   med_int numdt,numit;
5511   med_float dt;
5512   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5513   ret->setTime(numdt,numit,dt);
5514   ret->_csit=1;
5515   if(loadAll)
5516     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5517   else
5518     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5519   return ret.retn();
5520 }
5521
5522 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5523 try:MEDFileFieldGlobsReal(fileName)
5524 {
5525   MEDFileUtilities::CheckFileForRead(fileName);
5526   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5527   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
5528   loadGlobals(fid);
5529 }
5530 catch(INTERP_KERNEL::Exception& e)
5531 {
5532     throw e;
5533 }
5534
5535 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5536 {
5537   if(!c)
5538     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5539   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5540     {
5541       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5542       ret->setFileName(fileName);
5543       ret->_content=c; c->incrRef();
5544       return ret.retn();
5545     }
5546   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5547     {
5548       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5549       ret->setFileName(fileName);
5550       ret->_content=c; c->incrRef();
5551       return ret.retn();
5552     }
5553   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5554 }
5555
5556 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5557 {
5558   MEDFileUtilities::CheckFileForRead(fileName);
5559   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5560   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
5561   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5562   ret->loadGlobals(fid);
5563   return ret.retn();
5564 }
5565
5566 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5567 {
5568   MEDFileUtilities::CheckFileForRead(fileName);
5569   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5570   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
5571   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5572   ret->loadGlobals(fid);
5573   return ret.retn();
5574 }
5575
5576 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5577 {
5578   MEDFileUtilities::CheckFileForRead(fileName);
5579   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5580   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll,0);
5581   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5582   ret->loadGlobals(fid);
5583   return ret.retn();
5584 }
5585
5586 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5587 {
5588   med_field_type typcha;
5589   std::vector<std::string> infos;
5590   std::string dtunit;
5591   int iii=-1;
5592   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5593   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5594   switch(typcha)
5595   {
5596     case MED_FLOAT64:
5597       {
5598         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5599         break;
5600       }
5601     case MED_INT32:
5602       {
5603         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5604         break;
5605       }
5606     default:
5607       {
5608         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] !";
5609         throw INTERP_KERNEL::Exception(oss.str().c_str());
5610       }
5611   }
5612   ret->setDtUnit(dtunit.c_str());
5613   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5614   //
5615   bool found=false;
5616   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5617   for(int i=0;i<nbOfStep2 && !found;i++)
5618     {
5619       med_int numdt,numit;
5620       med_float dt;
5621       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5622       if(numdt==iteration && numit==order)
5623         {
5624           found=true;
5625           ret->_csit=i+1;
5626         }
5627       else
5628         dtits[i]=std::pair<int,int>(numdt,numit);
5629     }
5630   if(!found)
5631     {
5632       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5633       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5634         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5635       throw INTERP_KERNEL::Exception(oss.str().c_str());
5636     }
5637   if(loadAll)
5638     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5639   else
5640     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5641   return ret.retn();
5642 }
5643
5644 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5645 try:MEDFileFieldGlobsReal(fileName)
5646 {
5647   MEDFileUtilities::CheckFileForRead(fileName);
5648   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5649   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll,ms);
5650   loadGlobals(fid);
5651 }
5652 catch(INTERP_KERNEL::Exception& e)
5653 {
5654     throw e;
5655 }
5656
5657 /*!
5658  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5659  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5660  *
5661  * \warning this is a shallow copy constructor
5662  */
5663 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5664 {
5665   if(!shallowCopyOfContent)
5666     {
5667       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5668       otherPtr->incrRef();
5669       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5670     }
5671   else
5672     {
5673       _content=other.shallowCpy();
5674     }
5675 }
5676
5677 int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, const std::string& fileName, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5678 {
5679   if(checkFieldId)
5680     {
5681       int nbFields=MEDnField(fid);
5682       if(fieldIdCFormat>=nbFields)
5683         {
5684           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5685           throw INTERP_KERNEL::Exception(oss.str().c_str());
5686         }
5687     }
5688   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5689   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5690   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5691   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5692   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5693   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5694   med_bool localMesh;
5695   int nbOfStep;
5696   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5697   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5698   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5699   infos.clear(); infos.resize(ncomp);
5700   for(int j=0;j<ncomp;j++)
5701     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5702   return nbOfStep;
5703 }
5704
5705 /*!
5706  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5707  * 
5708  * \param [out]
5709  * \return in case of success the number of time steps available for the field with name \a fieldName.
5710  */
5711 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fileName, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5712 {
5713   int nbFields=MEDnField(fid);
5714   bool found=false;
5715   std::vector<std::string> fns(nbFields);
5716   int nbOfStep2=-1;
5717   for(int i=0;i<nbFields && !found;i++)
5718     {
5719       std::string tmp;
5720       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5721       fns[i]=tmp;
5722       found=(tmp==fieldName);
5723       if(found)
5724         posCFormat=i;
5725     }
5726   if(!found)
5727     {
5728       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5729       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5730         oss << "\"" << *it << "\" ";
5731       throw INTERP_KERNEL::Exception(oss.str().c_str());
5732     }
5733   return nbOfStep2;
5734 }
5735
5736 /*!
5737  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5738  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5739  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5740  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5741  * to keep a valid instance.
5742  * 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.
5743  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5744  * 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.
5745  *
5746  * \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.
5747  * \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.
5748  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5749  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5750  * \param [in] newLocName is the new localization name.
5751  * \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.
5752  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5753  */
5754 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5755 {
5756   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5757   std::string oldPflName=disc->getProfile();
5758   std::vector<std::string> vv=getPflsReallyUsedMulti();
5759   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5760   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5761     {
5762       disc->setProfile(newPflName);
5763       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5764       pfl->setName(newPflName);
5765     }
5766   else
5767     {
5768       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5769       throw INTERP_KERNEL::Exception(oss.str().c_str());
5770     }
5771 }
5772
5773 /*!
5774  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5775  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5776  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5777  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5778  * to keep a valid instance.
5779  * 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.
5780  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5781  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5782  * 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.
5783  *
5784  * \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.
5785  * \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.
5786  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5787  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5788  * \param [in] newLocName is the new localization name.
5789  * \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.
5790  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5791  */
5792 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5793 {
5794   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5795   std::string oldLocName=disc->getLocalization();
5796   std::vector<std::string> vv=getLocsReallyUsedMulti();
5797   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5798   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5799     {
5800       disc->setLocalization(newLocName);
5801       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5802       loc.setName(newLocName);
5803     }
5804   else
5805     {
5806       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5807       throw INTERP_KERNEL::Exception(oss.str().c_str());
5808     }
5809 }
5810
5811 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5812 {
5813   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5814   if(!ret)
5815     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5816   return ret;
5817 }
5818
5819 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5820 {
5821   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5822   if(!ret)
5823     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5824   return ret;
5825 }
5826
5827 /*!
5828  * Writes \a this field into a MED file specified by its name.
5829  *  \param [in] fileName - the MED file name.
5830  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5831  * - 2 - erase; an existing file is removed.
5832  * - 1 - append; same data should not be present in an existing file.
5833  * - 0 - overwrite; same data present in an existing file is overwritten.
5834  *  \throw If the field name is not set.
5835  *  \throw If no field data is set.
5836  *  \throw If \a mode == 1 and the same data is present in an existing file.
5837  */
5838 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5839 {
5840   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5841   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5842   writeLL(fid);
5843 }
5844
5845 /*!
5846  * This method alloc the arrays and load potentially huge arrays contained in this field.
5847  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5848  * This method can be also called to refresh or reinit values from a file.
5849  * 
5850  * \throw If the fileName is not set or points to a non readable MED file.
5851  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5852  */
5853 void MEDFileAnyTypeField1TS::loadArrays()
5854 {
5855   if(getFileName().empty())
5856     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5857   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5858   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5859 }
5860
5861 /*!
5862  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5863  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5864  * this method does not throw if \a this does not come from file read.
5865  * 
5866  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5867  */
5868 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5869 {
5870   if(!getFileName().empty())
5871     {
5872       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5873       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5874     }
5875 }
5876
5877 /*!
5878  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5879  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5880  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5881  * 
5882  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5883  */
5884 void MEDFileAnyTypeField1TS::unloadArrays()
5885 {
5886   contentNotNullBase()->unloadArrays();
5887 }
5888
5889 /*!
5890  * This method potentially releases big data arrays if \a this is coming from a file. If \a this has been built from scratch this method will have no effect.
5891  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5892  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5893  * 
5894  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5895  */
5896 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5897 {
5898   if(!getFileName().empty())
5899     contentNotNullBase()->unloadArrays();
5900 }
5901
5902 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5903 {
5904   int nbComp=getNumberOfComponents();
5905   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5906   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5907   for(int i=0;i<nbComp;i++)
5908     {
5909       std::string info=getInfo()[i];
5910       std::string c,u;
5911       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5912       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5913       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5914     }
5915   if(getName().empty())
5916     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5917   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
5918   writeGlobals(fid,*this);
5919   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5920 }
5921
5922 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5923 {
5924   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5925 }
5926
5927 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5928 {
5929   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5930   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5931   return ret;
5932 }
5933
5934 /*!
5935  * Returns a string describing \a this field. This string is outputted 
5936  * by \c print Python command.
5937  */
5938 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5939 {
5940   std::ostringstream oss;
5941   contentNotNullBase()->simpleRepr(0,oss,-1);
5942   simpleReprGlobs(oss);
5943   return oss.str();
5944 }
5945
5946 /*!
5947  * This method returns all profiles whose name is non empty used.
5948  * \b WARNING If profile is used several times it will be reported \b only \b once.
5949  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5950  */
5951 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5952 {
5953   return contentNotNullBase()->getPflsReallyUsed2();
5954 }
5955
5956 /*!
5957  * This method returns all localizations whose name is non empty used.
5958  * \b WARNING If localization is used several times it will be reported \b only \b once.
5959  */
5960 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5961 {
5962   return contentNotNullBase()->getLocsReallyUsed2();
5963 }
5964
5965 /*!
5966  * This method returns all profiles whose name is non empty used.
5967  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5968  */
5969 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5970 {
5971   return contentNotNullBase()->getPflsReallyUsedMulti2();
5972 }
5973
5974 /*!
5975  * This method returns all localizations whose name is non empty used.
5976  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5977  */
5978 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5979 {
5980   return contentNotNullBase()->getLocsReallyUsedMulti2();
5981 }
5982
5983 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5984 {
5985   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5986 }
5987
5988 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5989 {
5990   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5991 }
5992
5993 int MEDFileAnyTypeField1TS::getDimension() const
5994 {
5995   return contentNotNullBase()->getDimension();
5996 }
5997
5998 int MEDFileAnyTypeField1TS::getIteration() const
5999 {
6000   return contentNotNullBase()->getIteration();
6001 }
6002
6003 int MEDFileAnyTypeField1TS::getOrder() const
6004 {
6005   return contentNotNullBase()->getOrder();
6006 }
6007
6008 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6009 {
6010   return contentNotNullBase()->getTime(iteration,order);
6011 }
6012
6013 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6014 {
6015   contentNotNullBase()->setTime(iteration,order,val);
6016 }
6017
6018 std::string MEDFileAnyTypeField1TS::getName() const
6019 {
6020   return contentNotNullBase()->getName();
6021 }
6022
6023 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6024 {
6025   contentNotNullBase()->setName(name);
6026 }
6027
6028 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6029 {
6030   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6031 }
6032
6033 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6034 {
6035   return contentNotNullBase()->getDtUnit();
6036 }
6037
6038 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6039 {
6040   contentNotNullBase()->setDtUnit(dtUnit);
6041 }
6042
6043 std::string MEDFileAnyTypeField1TS::getMeshName() const
6044 {
6045   return contentNotNullBase()->getMeshName();
6046 }
6047
6048 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6049 {
6050   contentNotNullBase()->setMeshName(newMeshName);
6051 }
6052
6053 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6054 {
6055   return contentNotNullBase()->changeMeshNames(modifTab);
6056 }
6057
6058 int MEDFileAnyTypeField1TS::getMeshIteration() const
6059 {
6060   return contentNotNullBase()->getMeshIteration();
6061 }
6062
6063 int MEDFileAnyTypeField1TS::getMeshOrder() const
6064 {
6065   return contentNotNullBase()->getMeshOrder();
6066 }
6067
6068 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6069 {
6070   return contentNotNullBase()->getNumberOfComponents();
6071 }
6072
6073 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6074 {
6075   return contentNotNullBase()->isDealingTS(iteration,order);
6076 }
6077
6078 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6079 {
6080   return contentNotNullBase()->getDtIt();
6081 }
6082
6083 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6084 {
6085   contentNotNullBase()->fillIteration(p);
6086 }
6087
6088 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6089 {
6090   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6091 }
6092
6093 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6094 {
6095   contentNotNullBase()->setInfo(infos);
6096 }
6097
6098 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6099 {
6100   return contentNotNullBase()->getInfo();
6101 }
6102 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6103 {
6104   return contentNotNullBase()->getInfo();
6105 }
6106
6107 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6108 {
6109   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6110 }
6111
6112 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6113 {
6114   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6115 }
6116
6117 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6118 {
6119   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6120 }
6121
6122 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6123 {
6124   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6125 }
6126
6127 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6128 {
6129   return contentNotNullBase()->getTypesOfFieldAvailable();
6130 }
6131
6132 std::vector< std::vector<std::pair<int,int> > > MEDFileAnyTypeField1TS::getFieldSplitedByType(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6133                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6134 {
6135   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6136 }
6137
6138 /*!
6139  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6140  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6141  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6142  */
6143 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6144 {
6145   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6146   if(!content)
6147     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6148   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6149   std::size_t sz(contentsSplit.size());
6150   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6151   for(std::size_t i=0;i<sz;i++)
6152     {
6153       ret[i]=shallowCpy();
6154       ret[i]->_content=contentsSplit[i];
6155     }
6156   return ret;
6157 }
6158
6159 /*!
6160  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6161  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6162  */
6163 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6164 {
6165   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6166   if(!content)
6167     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6168   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6169   std::size_t sz(contentsSplit.size());
6170   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6171   for(std::size_t i=0;i<sz;i++)
6172     {
6173       ret[i]=shallowCpy();
6174       ret[i]->_content=contentsSplit[i];
6175     }
6176   return ret;
6177 }
6178
6179 /*!
6180  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6181  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6182  */
6183 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6184 {
6185   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6186   if(!content)
6187     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6188   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6189   std::size_t sz(contentsSplit.size());
6190   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6191   for(std::size_t i=0;i<sz;i++)
6192     {
6193       ret[i]=shallowCpy();
6194       ret[i]->_content=contentsSplit[i];
6195     }
6196   return ret;
6197 }
6198
6199 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const
6200 {
6201   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
6202   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6203     ret->_content=_content->deepCpy();
6204   ret->deepCpyGlobs(*this);
6205   return ret.retn();
6206 }
6207
6208 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6209 {
6210   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6211 }
6212
6213 //= MEDFileField1TS
6214
6215 /*!
6216  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6217  * the first field that has been read from a specified MED file.
6218  *  \param [in] fileName - the name of the MED file to read.
6219  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6220  *          is to delete this field using decrRef() as it is no more needed.
6221  *  \throw If reading the file fails.
6222  */
6223 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6224 {
6225   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,loadAll,0));
6226   ret->contentNotNull();
6227   return ret.retn();
6228 }
6229
6230 /*!
6231  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6232  * a given field that has been read from a specified MED file.
6233  *  \param [in] fileName - the name of the MED file to read.
6234  *  \param [in] fieldName - the name of the field to read.
6235  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6236  *          is to delete this field using decrRef() as it is no more needed.
6237  *  \throw If reading the file fails.
6238  *  \throw If there is no field named \a fieldName in the file.
6239  */
6240 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6241 {
6242   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,loadAll,0));
6243   ret->contentNotNull();
6244   return ret.retn();
6245 }
6246
6247 /*!
6248  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6249  * a given field that has been read from a specified MED file.
6250  *  \param [in] fileName - the name of the MED file to read.
6251  *  \param [in] fieldName - the name of the field to read.
6252  *  \param [in] iteration - the iteration number of a required time step.
6253  *  \param [in] order - the iteration order number of required time step.
6254  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6255  *          is to delete this field using decrRef() as it is no more needed.
6256  *  \throw If reading the file fails.
6257  *  \throw If there is no field named \a fieldName in the file.
6258  *  \throw If the required time step is missing from the file.
6259  */
6260 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6261 {
6262   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll,0));
6263   ret->contentNotNull();
6264   return ret.retn();
6265 }
6266
6267 /*!
6268  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6269  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6270  *
6271  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6272  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6273  * \warning this is a shallow copy constructor
6274  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6275  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6276  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6277  *          is to delete this field using decrRef() as it is no more needed.
6278  */
6279 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6280 {
6281   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
6282   ret->contentNotNull();
6283   return ret.retn();
6284 }
6285
6286 /*!
6287  * Returns a new empty instance of MEDFileField1TS.
6288  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6289  *          is to delete this field using decrRef() as it is no more needed.
6290  */
6291 MEDFileField1TS *MEDFileField1TS::New()
6292 {
6293   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
6294   ret->contentNotNull();
6295   return ret.retn();
6296 }
6297
6298 /*!
6299  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6300  * following the given input policy.
6301  *
6302  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6303  *                            By default (true) the globals are deeply copied.
6304  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6305  */
6306 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6307 {
6308   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
6309   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6310   if(content)
6311     {
6312       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6313       if(!contc)
6314         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6315       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6316       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6317     }
6318   else
6319     ret=MEDFileIntField1TS::New();
6320   if(isDeepCpyGlobs)
6321     ret->deepCpyGlobs(*this);
6322   else
6323     ret->shallowCpyGlobs(*this);
6324   return ret.retn();
6325 }
6326
6327 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6328 {
6329   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6330   if(!pt)
6331     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6332   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6333   if(!ret)
6334     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 !");
6335   return ret;
6336 }
6337
6338 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6339 {
6340   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6341   if(!pt)
6342     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6343   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6344   if(!ret)
6345     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 !");
6346   return ret;
6347 }
6348
6349 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6350 {
6351   if(!f)
6352     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6353   if(!((DataArray*)arr))
6354     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6355   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6356   if(!arrOutC)
6357     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6358   f->setArray(arrOutC);
6359 }
6360
6361 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6362 {
6363   if(!((DataArray*)arr))
6364     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6365   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6366   if(!arrOutC)
6367     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6368   arrOutC->incrRef();
6369   return arrOutC;
6370 }
6371
6372 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6373 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6374 {
6375 }
6376 catch(INTERP_KERNEL::Exception& e)
6377 { throw e; }
6378
6379 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6380 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6381 {
6382 }
6383 catch(INTERP_KERNEL::Exception& e)
6384 { throw e; }
6385
6386 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6387 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6388 {
6389 }
6390 catch(INTERP_KERNEL::Exception& e)
6391 { throw e; }
6392
6393 /*!
6394  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6395  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6396  *
6397  * \warning this is a shallow copy constructor
6398  */
6399 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6400 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6401 {
6402 }
6403 catch(INTERP_KERNEL::Exception& e)
6404 { throw e; }
6405
6406 MEDFileField1TS::MEDFileField1TS()
6407 {
6408   _content=new MEDFileField1TSWithoutSDA;
6409 }
6410
6411 /*!
6412  * Returns a new MEDCouplingFieldDouble of a given type lying on
6413  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6414  * has not been constructed via file reading, an exception is thrown.
6415  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6416  *  \param [in] type - a spatial discretization of interest.
6417  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6418  *  \param [in] renumPol - specifies how to permute values of the result field according to
6419  *          the optional numbers of cells and nodes, if any. The valid values are
6420  *          - 0 - do not permute.
6421  *          - 1 - permute cells.
6422  *          - 2 - permute nodes.
6423  *          - 3 - permute cells and nodes.
6424  *
6425  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6426  *          caller is to delete this field using decrRef() as it is no more needed. 
6427  *  \throw If \a this field has not been constructed via file reading.
6428  *  \throw If the MED file is not readable.
6429  *  \throw If there is no mesh in the MED file.
6430  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6431  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6432  *  \sa getFieldOnMeshAtLevel()
6433  */
6434 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6435 {
6436   if(getFileName().empty())
6437     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6438   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6439   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6440   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6441   return ret.retn();
6442 }
6443
6444 /*!
6445  * Returns a new MEDCouplingFieldDouble of a given type lying on
6446  * the top level cells of the first mesh in MED file. If \a this field 
6447  * has not been constructed via file reading, an exception is thrown.
6448  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6449  *  \param [in] type - a spatial discretization of interest.
6450  *  \param [in] renumPol - specifies how to permute values of the result field according to
6451  *          the optional numbers of cells and nodes, if any. The valid values are
6452  *          - 0 - do not permute.
6453  *          - 1 - permute cells.
6454  *          - 2 - permute nodes.
6455  *          - 3 - permute cells and nodes.
6456  *
6457  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6458  *          caller is to delete this field using decrRef() as it is no more needed. 
6459  *  \throw If \a this field has not been constructed via file reading.
6460  *  \throw If the MED file is not readable.
6461  *  \throw If there is no mesh in the MED file.
6462  *  \throw If no field values of the given \a type.
6463  *  \throw If no field values lying on the top level support.
6464  *  \sa getFieldAtLevel()
6465  */
6466 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6467 {
6468   if(getFileName().empty())
6469     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6470   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6471   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6472   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6473   return ret.retn();
6474 }
6475
6476 /*!
6477  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6478  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6479  *  \param [in] type - a spatial discretization of the new field.
6480  *  \param [in] mesh - the supporting mesh.
6481  *  \param [in] renumPol - specifies how to permute values of the result field according to
6482  *          the optional numbers of cells and nodes, if any. The valid values are
6483  *          - 0 - do not permute.
6484  *          - 1 - permute cells.
6485  *          - 2 - permute nodes.
6486  *          - 3 - permute cells and nodes.
6487  *
6488  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6489  *          caller is to delete this field using decrRef() as it is no more needed. 
6490  *  \throw If no field of \a this is lying on \a mesh.
6491  *  \throw If the mesh is empty.
6492  *  \throw If no field values of the given \a type are available.
6493  *  \sa getFieldAtLevel()
6494  *  \sa getFieldOnMeshAtLevel() 
6495  */
6496 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6497 {
6498   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6499   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6500   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6501   return ret.retn();
6502 }
6503
6504 /*!
6505  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6506  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6507  *  \param [in] type - a spatial discretization of interest.
6508  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6509  *  \param [in] mesh - the supporting mesh.
6510  *  \param [in] renumPol - specifies how to permute values of the result field according to
6511  *          the optional numbers of cells and nodes, if any. The valid values are
6512  *          - 0 - do not permute.
6513  *          - 1 - permute cells.
6514  *          - 2 - permute nodes.
6515  *          - 3 - permute cells and nodes.
6516  *
6517  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6518  *          caller is to delete this field using decrRef() as it is no more needed. 
6519  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6520  *  \throw If no field of \a this is lying on \a mesh.
6521  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6522  *  \sa getFieldAtLevel()
6523  *  \sa getFieldOnMeshAtLevel() 
6524  */
6525 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6526 {
6527   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6528   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6529   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6530   return ret.retn();
6531 }
6532
6533 /*!
6534  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6535  * This method is called "Old" because in MED3 norm a field has only one meshName
6536  * attached, so this method is for readers of MED2 files. If \a this field 
6537  * has not been constructed via file reading, an exception is thrown.
6538  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6539  *  \param [in] type - a spatial discretization of interest.
6540  *  \param [in] mName - a name of the supporting mesh.
6541  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6542  *  \param [in] renumPol - specifies how to permute values of the result field according to
6543  *          the optional numbers of cells and nodes, if any. The valid values are
6544  *          - 0 - do not permute.
6545  *          - 1 - permute cells.
6546  *          - 2 - permute nodes.
6547  *          - 3 - permute cells and nodes.
6548  *
6549  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6550  *          caller is to delete this field using decrRef() as it is no more needed. 
6551  *  \throw If the MED file is not readable.
6552  *  \throw If there is no mesh named \a mName in the MED file.
6553  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6554  *  \throw If \a this field has not been constructed via file reading.
6555  *  \throw If no field of \a this is lying on the mesh named \a mName.
6556  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6557  *  \sa getFieldAtLevel()
6558  */
6559 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6560 {
6561   if(getFileName().empty())
6562     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6563   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6564   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6565   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6566   return ret.retn();
6567 }
6568
6569 /*!
6570  * Returns values and a profile of the field of a given type lying on a given support.
6571  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6572  *  \param [in] type - a spatial discretization of the field.
6573  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6574  *  \param [in] mesh - the supporting mesh.
6575  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6576  *          field of interest lies on. If the field lies on all entities of the given
6577  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6578  *          using decrRef() as it is no more needed.  
6579  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6580  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6581  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6582  *  \throw If no field of \a this is lying on \a mesh.
6583  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6584  */
6585 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6586 {
6587   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6588   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6589 }
6590
6591 /*!
6592  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6593  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6594  * "Sort By Type"), if not, an exception is thrown. 
6595  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6596  *  \param [in] field - the field to add to \a this.
6597  *  \throw If the name of \a field is empty.
6598  *  \throw If the data array of \a field is not set.
6599  *  \throw If the data array is already allocated but has different number of components
6600  *         than \a field.
6601  *  \throw If the underlying mesh of \a field has no name.
6602  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6603  */
6604 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6605 {
6606   setFileName("");
6607   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6608 }
6609
6610 /*!
6611  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6612  * can be an aggregation of several MEDCouplingFieldDouble instances.
6613  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6614  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6615  * and \a profile.
6616  *
6617  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6618  * A new profile is added only if no equal profile is missing.
6619  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6620  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6621  *  \param [in] mesh - the supporting mesh of \a field.
6622  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6623  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6624  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6625  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6626  *  \throw If the data array of \a field is not set.
6627  *  \throw If the data array of \a this is already allocated but has different number of
6628  *         components than \a field.
6629  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6630  *  \sa setFieldNoProfileSBT()
6631  */
6632 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6633 {
6634   setFileName("");
6635   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6636 }
6637
6638 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6639 {
6640   return new MEDFileField1TS(*this);
6641 }
6642
6643 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6644 {
6645   return contentNotNull()->getUndergroundDataArrayDouble();
6646 }
6647
6648 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6649 {
6650   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6651 }
6652
6653 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6654                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6655 {
6656   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6657 }
6658
6659 //= MEDFileIntField1TS
6660
6661 MEDFileIntField1TS *MEDFileIntField1TS::New()
6662 {
6663   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6664   ret->contentNotNull();
6665   return ret.retn();
6666 }
6667
6668 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6669 {
6670   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6671   ret->contentNotNull();
6672   return ret.retn();
6673 }
6674
6675 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6676 {
6677   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6678   ret->contentNotNull();
6679   return ret.retn();
6680 }
6681
6682 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6683 {
6684   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6685   ret->contentNotNull();
6686   return ret.retn();
6687 }
6688
6689 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6690 {
6691   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6692   ret->contentNotNull();
6693   return ret.retn();
6694 }
6695
6696 MEDFileIntField1TS::MEDFileIntField1TS()
6697 {
6698   _content=new MEDFileIntField1TSWithoutSDA;
6699 }
6700
6701 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6702 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6703 {
6704 }
6705 catch(INTERP_KERNEL::Exception& e)
6706 { throw e; }
6707
6708 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6709 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6710 {
6711 }
6712 catch(INTERP_KERNEL::Exception& e)
6713 { throw e; }
6714
6715 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6716 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6717 {
6718 }
6719 catch(INTERP_KERNEL::Exception& e)
6720 { throw e; }
6721
6722 /*!
6723  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6724  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6725  *
6726  * \warning this is a shallow copy constructor
6727  */
6728 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6729 {
6730 }
6731
6732 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6733 {
6734   return new MEDFileIntField1TS(*this);
6735 }
6736
6737 /*!
6738  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6739  * following the given input policy.
6740  *
6741  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6742  *                            By default (true) the globals are deeply copied.
6743  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6744  */
6745 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6746 {
6747   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6748   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6749   if(content)
6750     {
6751       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6752       if(!contc)
6753         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6754       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6755       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6756     }
6757   else
6758     ret=MEDFileField1TS::New();
6759   if(isDeepCpyGlobs)
6760     ret->deepCpyGlobs(*this);
6761   else
6762     ret->shallowCpyGlobs(*this);
6763   return ret.retn();
6764 }
6765
6766 /*!
6767  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6768  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6769  * "Sort By Type"), if not, an exception is thrown. 
6770  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6771  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6772  *  \param [in] arrOfVals - the values of the field \a field used.
6773  *  \throw If the name of \a field is empty.
6774  *  \throw If the data array of \a field is not set.
6775  *  \throw If the data array is already allocated but has different number of components
6776  *         than \a field.
6777  *  \throw If the underlying mesh of \a field has no name.
6778  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6779  */
6780 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6781 {
6782   setFileName("");
6783   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6784 }
6785
6786 /*!
6787  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6788  * can be an aggregation of several MEDCouplingFieldDouble instances.
6789  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6790  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6791  * and \a profile.
6792  *
6793  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6794  * A new profile is added only if no equal profile is missing.
6795  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6796  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6797  *  \param [in] arrOfVals - the values of the field \a field used.
6798  *  \param [in] mesh - the supporting mesh of \a field.
6799  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6800  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6801  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6802  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6803  *  \throw If the data array of \a field is not set.
6804  *  \throw If the data array of \a this is already allocated but has different number of
6805  *         components than \a field.
6806  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6807  *  \sa setFieldNoProfileSBT()
6808  */
6809 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6810 {
6811   setFileName("");
6812   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6813 }
6814
6815 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6816 {
6817   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6818   if(!pt)
6819     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6820   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6821   if(!ret)
6822     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 !");
6823   return ret;
6824 }
6825
6826 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6827 {
6828   if(getFileName().empty())
6829     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6830   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6831   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6832   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6833   if(!arrOutC)
6834     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6835   arrOut=arrOutC;
6836   arrOut->incrRef();  // arrOut2 dies at the end of the func
6837   return ret.retn();
6838 }
6839
6840 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6841 {
6842   if(!((DataArray *)arr))
6843     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6844   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6845   if(!arrC)
6846     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6847   arrC->incrRef();
6848   return arrC;
6849 }
6850
6851 /*!
6852  * Returns a new MEDCouplingFieldDouble of a given type lying on
6853  * the top level cells of the first mesh in MED file. If \a this field 
6854  * has not been constructed via file reading, an exception is thrown.
6855  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6856  *  \param [in] type - a spatial discretization of interest.
6857  *  \param [out] arrOut - the DataArrayInt containing values of field.
6858  *  \param [in] renumPol - specifies how to permute values of the result field according to
6859  *          the optional numbers of cells and nodes, if any. The valid values are
6860  *          - 0 - do not permute.
6861  *          - 1 - permute cells.
6862  *          - 2 - permute nodes.
6863  *          - 3 - permute cells and nodes.
6864  *
6865  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6866  *          caller is to delete this field using decrRef() as it is no more needed. 
6867  *  \throw If \a this field has not been constructed via file reading.
6868  *  \throw If the MED file is not readable.
6869  *  \throw If there is no mesh in the MED file.
6870  *  \throw If no field values of the given \a type.
6871  *  \throw If no field values lying on the top level support.
6872  *  \sa getFieldAtLevel()
6873  */
6874 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6875 {
6876   if(getFileName().empty())
6877     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6878   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6879   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6880   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6881   return ret.retn();
6882 }
6883
6884 /*!
6885  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6886  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6887  *  \param [in] type - a spatial discretization of the new field.
6888  *  \param [in] mesh - the supporting mesh.
6889  *  \param [out] arrOut - the DataArrayInt containing values of field.
6890  *  \param [in] renumPol - specifies how to permute values of the result field according to
6891  *          the optional numbers of cells and nodes, if any. The valid values are
6892  *          - 0 - do not permute.
6893  *          - 1 - permute cells.
6894  *          - 2 - permute nodes.
6895  *          - 3 - permute cells and nodes.
6896  *
6897  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6898  *          caller is to delete this field using decrRef() as it is no more needed. 
6899  *  \throw If no field of \a this is lying on \a mesh.
6900  *  \throw If the mesh is empty.
6901  *  \throw If no field values of the given \a type are available.
6902  *  \sa getFieldAtLevel()
6903  *  \sa getFieldOnMeshAtLevel() 
6904  */
6905 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6906 {
6907   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6908   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6909   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6910   return ret.retn();
6911 }
6912
6913 /*!
6914  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6915  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6916  *  \param [in] type - a spatial discretization of interest.
6917  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6918  *  \param [out] arrOut - the DataArrayInt containing values of field.
6919  *  \param [in] mesh - the supporting mesh.
6920  *  \param [in] renumPol - specifies how to permute values of the result field according to
6921  *          the optional numbers of cells and nodes, if any. The valid values are
6922  *          - 0 - do not permute.
6923  *          - 1 - permute cells.
6924  *          - 2 - permute nodes.
6925  *          - 3 - permute cells and nodes.
6926  *
6927  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6928  *          caller is to delete this field using decrRef() as it is no more needed. 
6929  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6930  *  \throw If no field of \a this is lying on \a mesh.
6931  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6932  *  \sa getFieldAtLevel()
6933  *  \sa getFieldOnMeshAtLevel() 
6934  */
6935 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6936 {
6937   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6938   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6939   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6940   return ret.retn();
6941 }
6942
6943 /*!
6944  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6945  * This method is called "Old" because in MED3 norm a field has only one meshName
6946  * attached, so this method is for readers of MED2 files. If \a this field 
6947  * has not been constructed via file reading, an exception is thrown.
6948  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6949  *  \param [in] type - a spatial discretization of interest.
6950  *  \param [in] mName - a name of the supporting mesh.
6951  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6952  *  \param [out] arrOut - the DataArrayInt containing values of field.
6953  *  \param [in] renumPol - specifies how to permute values of the result field according to
6954  *          the optional numbers of cells and nodes, if any. The valid values are
6955  *          - 0 - do not permute.
6956  *          - 1 - permute cells.
6957  *          - 2 - permute nodes.
6958  *          - 3 - permute cells and nodes.
6959  *
6960  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6961  *          caller is to delete this field using decrRef() as it is no more needed. 
6962  *  \throw If the MED file is not readable.
6963  *  \throw If there is no mesh named \a mName in the MED file.
6964  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6965  *  \throw If \a this field has not been constructed via file reading.
6966  *  \throw If no field of \a this is lying on the mesh named \a mName.
6967  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6968  *  \sa getFieldAtLevel()
6969  */
6970 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6971 {
6972   if(getFileName().empty())
6973     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6974   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6975   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6976   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6977   return ret.retn();
6978 }
6979
6980 /*!
6981  * Returns values and a profile of the field of a given type lying on a given support.
6982  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6983  *  \param [in] type - a spatial discretization of the field.
6984  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6985  *  \param [in] mesh - the supporting mesh.
6986  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6987  *          field of interest lies on. If the field lies on all entities of the given
6988  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6989  *          using decrRef() as it is no more needed.  
6990  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6991  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6992  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6993  *  \throw If no field of \a this is lying on \a mesh.
6994  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6995  */
6996 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6997 {
6998   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6999   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7000 }
7001
7002 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7003 {
7004   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7005   if(!pt)
7006     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7007   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7008   if(!ret)
7009     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 !");
7010   return ret;
7011 }
7012
7013 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7014 {
7015   return contentNotNull()->getUndergroundDataArrayInt();
7016 }
7017
7018 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7019
7020 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7021 {
7022 }
7023
7024 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7025 {
7026 }
7027
7028 /*!
7029  * \param [in] fieldId field id in C mode
7030  */
7031 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7032 {
7033   med_field_type typcha;
7034   std::string dtunitOut;
7035   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
7036   setDtUnit(dtunitOut.c_str());
7037   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7038 }
7039
7040 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7041 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7042 {
7043   setDtUnit(dtunit.c_str());
7044   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7045 }
7046 catch(INTERP_KERNEL::Exception& e)
7047 {
7048     throw e;
7049 }
7050
7051 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7052 {
7053   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>));
7054   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7055     ret+=(*it).capacity();
7056   return ret;
7057 }
7058
7059 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7060 {
7061   std::vector<const BigMemoryObject *> ret;
7062   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7063     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7064   return ret;
7065 }
7066
7067 /*!
7068  * 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
7069  * NULL.
7070  */
7071 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7072 {
7073   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7074   ret->setInfo(_infos);
7075   int sz=(int)_time_steps.size();
7076   for(const int *id=startIds;id!=endIds;id++)
7077     {
7078       if(*id>=0 && *id<sz)
7079         {
7080           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7081           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7082           if(tse)
7083             {
7084               tse->incrRef();
7085               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7086             }
7087           ret->pushBackTimeStep(tse2);
7088         }
7089       else
7090         {
7091           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7092           oss << " ! Should be in [0," << sz << ") !";
7093           throw INTERP_KERNEL::Exception(oss.str().c_str());
7094         }
7095     }
7096   if(ret->getNumberOfTS()>0)
7097     ret->synchronizeNameScope();
7098   ret->copyNameScope(*this);
7099   return ret.retn();
7100 }
7101
7102 /*!
7103  * 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
7104  * NULL.
7105  */
7106 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7107 {
7108   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7109   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7110   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7111   ret->setInfo(_infos);
7112   int sz=(int)_time_steps.size();
7113   int j=bg;
7114   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7115     {
7116       if(j>=0 && j<sz)
7117         {
7118           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7119           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7120           if(tse)
7121             {
7122               tse->incrRef();
7123               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7124             }
7125           ret->pushBackTimeStep(tse2);
7126         }
7127       else
7128         {
7129           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7130           oss << " ! Should be in [0," << sz << ") !";
7131           throw INTERP_KERNEL::Exception(oss.str().c_str());
7132         }
7133     }
7134   if(ret->getNumberOfTS()>0)
7135     ret->synchronizeNameScope();
7136   ret->copyNameScope(*this);
7137   return ret.retn();
7138 }
7139
7140 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7141 {
7142   int id=0;
7143   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7144   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7145     {
7146       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7147       if(!cur)
7148         continue;
7149       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7150       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7151         ids->pushBackSilent(id);
7152     }
7153   return buildFromTimeStepIds(ids->begin(),ids->end());
7154 }
7155
7156 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7157 {
7158   int id=0;
7159   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7160   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7161     {
7162       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7163       if(!cur)
7164         continue;
7165       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7166       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7167         ids->pushBackSilent(id);
7168     }
7169   return buildFromTimeStepIds(ids->begin(),ids->end());
7170 }
7171
7172 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7173 {
7174   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7175     {
7176       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7177       if(!cur)
7178         continue;
7179       if(cur->presenceOfMultiDiscPerGeoType())
7180         return true;
7181     }
7182   return false;
7183 }
7184
7185 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7186 {
7187   return _infos;
7188 }
7189
7190 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7191 {
7192   _infos=info;
7193 }
7194
7195 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7196 {
7197   int ret=0;
7198   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7199     {
7200       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7201       if(pt->isDealingTS(iteration,order))
7202         return ret;
7203     }
7204   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7205   std::vector< std::pair<int,int> > vp=getIterations();
7206   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7207     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7208   throw INTERP_KERNEL::Exception(oss.str().c_str());
7209 }
7210
7211 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7212 {
7213   return *_time_steps[getTimeStepPos(iteration,order)];
7214 }
7215
7216 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7217 {
7218   return *_time_steps[getTimeStepPos(iteration,order)];
7219 }
7220
7221 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7222 {
7223   if(_time_steps.empty())
7224     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7225   return _time_steps[0]->getMeshName();
7226 }
7227
7228 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7229 {
7230   std::string oldName(getMeshName());
7231   std::vector< std::pair<std::string,std::string> > v(1);
7232   v[0].first=oldName; v[0].second=newMeshName;
7233   changeMeshNames(v);
7234 }
7235
7236 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7237 {
7238   bool ret=false;
7239   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7240     {
7241       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7242       if(cur)
7243         ret=cur->changeMeshNames(modifTab) || ret;
7244     }
7245   return ret;
7246 }
7247
7248 /*!
7249  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7250  */
7251 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7252 {
7253   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7254 }
7255
7256 /*!
7257  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7258  */
7259 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7260 {
7261   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7262 }
7263
7264 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7265                                                                        MEDFileFieldGlobsReal& glob)
7266 {
7267   bool ret=false;
7268   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7269     {
7270       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7271       if(f1ts)
7272         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7273     }
7274   return ret;
7275 }
7276
7277 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7278 {
7279   std::string startLine(bkOffset,' ');
7280   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7281   if(fmtsId>=0)
7282     oss << " (" << fmtsId << ")";
7283   oss << " has the following name: \"" << _name << "\"." << std::endl;
7284   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7285   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7286     {
7287       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7288     }
7289   int i=0;
7290   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7291     {
7292       std::string chapter(17,'0'+i);
7293       oss << startLine << chapter << std::endl;
7294       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7295       if(cur)
7296         cur->simpleRepr(bkOffset+2,oss,i);
7297       else
7298         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7299       oss << startLine << chapter << std::endl;
7300     }
7301 }
7302
7303 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7304 {
7305   std::size_t sz=_time_steps.size();
7306   std::vector< std::pair<int,int> > ret(sz);
7307   ret1.resize(sz);
7308   for(std::size_t i=0;i<sz;i++)
7309     {
7310       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7311       if(f1ts)
7312         {
7313           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7314         }
7315       else
7316         {
7317           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7318           throw INTERP_KERNEL::Exception(oss.str().c_str());
7319         }
7320     }
7321   return ret;
7322 }
7323
7324 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7325 {
7326   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7327   if(!tse2)
7328     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7329   checkCoherencyOfType(tse2);
7330   if(_time_steps.empty())
7331     {
7332       setName(tse2->getName().c_str());
7333       setInfo(tse2->getInfo());
7334     }
7335   checkThatComponentsMatch(tse2->getInfo());
7336   _time_steps.push_back(tse);
7337 }
7338
7339 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7340 {
7341   std::size_t nbOfCompo=_infos.size();
7342   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7343     {
7344       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7345       if(cur)
7346         {
7347           if((cur->getInfo()).size()!=nbOfCompo)
7348             {
7349               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7350               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7351               throw INTERP_KERNEL::Exception(oss.str().c_str());
7352             }
7353           cur->copyNameScope(*this);
7354         }
7355     }
7356 }
7357
7358 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7359 {
7360   _time_steps.resize(nbPdt);
7361   for(int i=0;i<nbPdt;i++)
7362     {
7363       std::vector< std::pair<int,int> > ts;
7364       med_int numdt=0,numo=0;
7365       med_int meshIt=0,meshOrder=0;
7366       med_float dt=0.0;
7367       MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder));
7368       switch(fieldTyp)
7369       {
7370         case MED_FLOAT64:
7371           {
7372             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7373             break;
7374           }
7375         case MED_INT32:
7376           {
7377             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7378             break;
7379           }
7380         default:
7381           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7382       }
7383       if(loadAll)
7384         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7385       else
7386         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7387     }
7388 }
7389
7390 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7391 {
7392   if(_time_steps.empty())
7393     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7394   checkThatNbOfCompoOfTSMatchThis();
7395   std::vector<std::string> infos(getInfo());
7396   int nbComp=infos.size();
7397   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7398   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7399   for(int i=0;i<nbComp;i++)
7400     {
7401       std::string info=infos[i];
7402       std::string c,u;
7403       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7404       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7405       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7406     }
7407   if(_name.empty())
7408     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7409   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7410   int nbOfTS=_time_steps.size();
7411   for(int i=0;i<nbOfTS;i++)
7412     _time_steps[i]->writeLL(fid,opts,*this);
7413 }
7414
7415 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7416 {
7417   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7418     {
7419       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7420       if(elt)
7421         elt->loadBigArraysRecursively(fid,nasc);
7422     }
7423 }
7424
7425 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7426 {
7427   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7428     {
7429       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7430       if(elt)
7431         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7432     }
7433 }
7434
7435 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7436 {
7437   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7438     {
7439       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7440       if(elt)
7441         elt->unloadArrays();
7442     }
7443 }
7444
7445 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7446 {
7447   return _time_steps.size();
7448 }
7449
7450 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7451 {
7452   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7453   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7454     {
7455       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7456       if(tmp)
7457         newTS.push_back(*it);
7458     }
7459   _time_steps=newTS;
7460 }
7461
7462 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7463 {
7464   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7465   int maxId=(int)_time_steps.size();
7466   int ii=0;
7467   std::set<int> idsToDel;
7468   for(const int *id=startIds;id!=endIds;id++,ii++)
7469     {
7470       if(*id>=0 && *id<maxId)
7471         {
7472           idsToDel.insert(*id);
7473         }
7474       else
7475         {
7476           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7477           throw INTERP_KERNEL::Exception(oss.str().c_str());
7478         }
7479     }
7480   for(int iii=0;iii<maxId;iii++)
7481     if(idsToDel.find(iii)==idsToDel.end())
7482       newTS.push_back(_time_steps[iii]);
7483   _time_steps=newTS;
7484 }
7485
7486 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7487 {
7488   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7489   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7490   if(nbOfEntriesToKill==0)
7491     return ;
7492   std::size_t sz=_time_steps.size();
7493   std::vector<bool> b(sz,true);
7494   int j=bg;
7495   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7496     b[j]=false;
7497   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7498   for(std::size_t i=0;i<sz;i++)
7499     if(b[i])
7500       newTS.push_back(_time_steps[i]);
7501   _time_steps=newTS;
7502 }
7503
7504 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7505 {
7506   int ret=0;
7507   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7508   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7509     {
7510       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7511       if(tmp)
7512         {
7513           int it2,ord;
7514           tmp->getTime(it2,ord);
7515           if(it2==iteration && order==ord)
7516             return ret;
7517           else
7518             oss << "(" << it2 << ","  << ord << "), ";
7519         }
7520     }
7521   throw INTERP_KERNEL::Exception(oss.str().c_str());
7522 }
7523
7524 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7525 {
7526   int ret=0;
7527   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7528   oss.precision(15);
7529   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7530     {
7531       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7532       if(tmp)
7533         {
7534           int it2,ord;
7535           double ti=tmp->getTime(it2,ord);
7536           if(fabs(time-ti)<eps)
7537             return ret;
7538           else
7539             oss << ti << ", ";
7540         }
7541     }
7542   throw INTERP_KERNEL::Exception(oss.str().c_str());
7543 }
7544
7545 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7546 {
7547   int lgth=_time_steps.size();
7548   std::vector< std::pair<int,int> > ret(lgth);
7549   for(int i=0;i<lgth;i++)
7550     _time_steps[i]->fillIteration(ret[i]);
7551   return ret;
7552 }
7553
7554 /*!
7555  * 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'
7556  * This method returns two things.
7557  * - The absolute dimension of 'this' in first parameter. 
7558  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7559  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7560  *
7561  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7562  * Only these 3 discretizations will be taken into account here.
7563  *
7564  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7565  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7566  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7567  *
7568  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7569  * 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'.
7570  * 
7571  * Let's consider the typical following case :
7572  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7573  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7574  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7575  *   TETRA4 and SEG2
7576  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7577  *
7578  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7579  * 
7580  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7581  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7582  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7583  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7584  */
7585 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7586 {
7587   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7588 }
7589
7590 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7591 {
7592   if(pos<0 || pos>=(int)_time_steps.size())
7593     {
7594       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7595       throw INTERP_KERNEL::Exception(oss.str().c_str());
7596     }
7597   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7598   if(item==0)
7599     {
7600       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7601       oss << "\nTry to use following method eraseEmptyTS !";
7602       throw INTERP_KERNEL::Exception(oss.str().c_str());
7603     }
7604   return item;
7605 }
7606
7607 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7608 {
7609   if(pos<0 || pos>=(int)_time_steps.size())
7610     {
7611       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7612       throw INTERP_KERNEL::Exception(oss.str().c_str());
7613     }
7614   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7615   if(item==0)
7616     {
7617       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7618       oss << "\nTry to use following method eraseEmptyTS !";
7619       throw INTERP_KERNEL::Exception(oss.str().c_str());
7620     }
7621   return item;
7622 }
7623
7624 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7625 {
7626   std::vector<std::string> ret;
7627   std::set<std::string> ret2;
7628   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7629     {
7630       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7631       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7632         if(ret2.find(*it2)==ret2.end())
7633           {
7634             ret.push_back(*it2);
7635             ret2.insert(*it2);
7636           }
7637     }
7638   return ret;
7639 }
7640
7641 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7642 {
7643   std::vector<std::string> ret;
7644   std::set<std::string> ret2;
7645   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7646     {
7647       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7648       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7649         if(ret2.find(*it2)==ret2.end())
7650           {
7651             ret.push_back(*it2);
7652             ret2.insert(*it2);
7653           }
7654     }
7655   return ret;
7656 }
7657
7658 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7659 {
7660   std::vector<std::string> ret;
7661   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7662     {
7663       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7664       ret.insert(ret.end(),tmp.begin(),tmp.end());
7665     }
7666   return ret;
7667 }
7668
7669 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7670 {
7671   std::vector<std::string> ret;
7672   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7673     {
7674       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7675       ret.insert(ret.end(),tmp.begin(),tmp.end());
7676     }
7677   return ret;
7678 }
7679
7680 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7681 {
7682   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7683     (*it)->changePflsRefsNamesGen2(mapOfModif);
7684 }
7685
7686 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7687 {
7688   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7689     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7690 }
7691
7692 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7693 {
7694   int lgth=_time_steps.size();
7695   std::vector< std::vector<TypeOfField> > ret(lgth);
7696   for(int i=0;i<lgth;i++)
7697     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7698   return ret;
7699 }
7700
7701 /*!
7702  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7703  */
7704 std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeFieldMultiTSWithoutSDA::getFieldSplitedByType(int iteration, int order, const std::string& 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
7705 {
7706   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7707 }
7708
7709 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const
7710 {
7711   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7712   std::size_t i=0;
7713   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7714     {
7715       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7716         ret->_time_steps[i]=(*it)->deepCpy();
7717     }
7718   return ret.retn();
7719 }
7720
7721 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7722 {
7723   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7724   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7725   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7726   for(std::size_t i=0;i<sz;i++)
7727     {
7728       ret[i]=shallowCpy();
7729       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7730     }
7731   for(std::size_t i=0;i<sz2;i++)
7732     {
7733       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7734       if(ret1.size()!=sz)
7735         {
7736           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7737           throw INTERP_KERNEL::Exception(oss.str().c_str());
7738         }
7739       ts[i]=ret1;
7740     }
7741   for(std::size_t i=0;i<sz;i++)
7742     for(std::size_t j=0;j<sz2;j++)
7743       ret[i]->_time_steps[j]=ts[j][i];
7744   return ret;
7745 }
7746
7747 /*!
7748  * This method splits into discretization each time steps in \a this.
7749  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7750  */
7751 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7752 {
7753   std::size_t sz(_time_steps.size());
7754   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7755   for(std::size_t i=0;i<sz;i++)
7756     {
7757       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7758       if(!timeStep)
7759         {
7760           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7761           throw INTERP_KERNEL::Exception(oss.str().c_str());
7762         }
7763       items[i]=timeStep->splitDiscretizations();  
7764     }
7765   //
7766   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7767   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7768   std::vector< TypeOfField > types;
7769   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7770     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7771       {
7772         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7773         if(ts.size()!=1)
7774           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7775         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7776         if(it2==types.end())
7777           types.push_back(ts[0]);
7778       }
7779   ret.resize(types.size()); ret2.resize(types.size());
7780   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7781     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7782       {
7783         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7784         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7785         ret2[pos].push_back(*it1);
7786       }
7787   for(std::size_t i=0;i<types.size();i++)
7788     {
7789       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7790       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7791         elt->pushBackTimeStep(*it1);//also updates infos in elt
7792       ret[i]=elt;
7793       elt->MEDFileFieldNameScope::operator=(*this);
7794     }
7795   return ret;
7796 }
7797
7798 /*!
7799  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7800  */
7801 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7802 {
7803   std::size_t sz(_time_steps.size());
7804   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7805   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7806   for(std::size_t i=0;i<sz;i++)
7807     {
7808       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7809       if(!timeStep)
7810         {
7811           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7812           throw INTERP_KERNEL::Exception(oss.str().c_str());
7813         }
7814       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7815       if(szOut==std::numeric_limits<std::size_t>::max())
7816         szOut=items[i].size();
7817       else
7818         if(items[i].size()!=szOut)
7819           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7820     }
7821   if(szOut==std::numeric_limits<std::size_t>::max())
7822     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7823   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7824   for(std::size_t i=0;i<szOut;i++)
7825     {
7826       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7827       for(std::size_t j=0;j<sz;j++)
7828         elt->pushBackTimeStep(items[j][i]);
7829       ret[i]=elt;
7830       elt->MEDFileFieldNameScope::operator=(*this);
7831     }
7832   return ret;
7833 }
7834
7835 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7836 {
7837   _name=field->getName();
7838   if(_name.empty())
7839     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7840   if(!arr)
7841     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7842   _infos=arr->getInfoOnComponents();
7843 }
7844
7845 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7846 {
7847   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7848   if(_name!=field->getName())
7849     {
7850       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7851       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7852       throw INTERP_KERNEL::Exception(oss.str().c_str());
7853     }
7854   if(!arr)
7855     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7856   checkThatComponentsMatch(arr->getInfoOnComponents());
7857 }
7858
7859 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7860 {
7861   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7862   if(getInfo().size()!=compos.size())
7863     {
7864       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7865       oss << " number of components of element to append (" << compos.size() << ") !";
7866       throw INTERP_KERNEL::Exception(oss.str().c_str());
7867     }
7868   if(_infos!=compos)
7869     {
7870       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7871       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7872       oss << " But compo in input fields are : ";
7873       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7874       oss << " !";
7875       throw INTERP_KERNEL::Exception(oss.str().c_str());
7876     }
7877 }
7878
7879 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7880 {
7881   std::size_t sz=_infos.size();
7882   int j=0;
7883   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7884     {
7885       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7886       if(elt)
7887         if(elt->getInfo().size()!=sz)
7888           {
7889             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7890             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7891             throw INTERP_KERNEL::Exception(oss.str().c_str());
7892           }
7893     }
7894 }
7895
7896 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7897 {
7898   if(!field)
7899     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7900   if(!_time_steps.empty())
7901     checkCoherencyOfTinyInfo(field,arr);
7902   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7903   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7904   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7905   copyTinyInfoFrom(field,arr);
7906   _time_steps.push_back(obj);
7907 }
7908
7909 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7910 {
7911   if(!field)
7912     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7913   if(!_time_steps.empty())
7914     checkCoherencyOfTinyInfo(field,arr);
7915   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7916   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7917   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7918   copyTinyInfoFrom(field,arr);
7919   _time_steps.push_back(obj);
7920 }
7921
7922 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts)
7923 {
7924   int sz=(int)_time_steps.size();
7925   if(i<0 || i>=sz)
7926     {
7927       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7928       throw INTERP_KERNEL::Exception(oss.str().c_str());
7929     }
7930   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7931   if(tsPtr)
7932     {
7933       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7934         {
7935           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7936           throw INTERP_KERNEL::Exception(oss.str().c_str());
7937         }
7938     }
7939   _time_steps[i]=ts;
7940 }
7941
7942 //= MEDFileFieldMultiTSWithoutSDA
7943
7944 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7945 {
7946   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
7947 }
7948
7949 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7950 {
7951 }
7952
7953 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7954 {
7955 }
7956
7957 /*!
7958  * \param [in] fieldId field id in C mode
7959  */
7960 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7961 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
7962 {
7963 }
7964 catch(INTERP_KERNEL::Exception& e)
7965 { throw e; }
7966
7967 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7968 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
7969 {
7970 }
7971 catch(INTERP_KERNEL::Exception& e)
7972 { throw e; }
7973
7974 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7975 {
7976   return new MEDFileField1TSWithoutSDA;
7977 }
7978
7979 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7980 {
7981   if(!f1ts)
7982     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7983   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7984   if(!f1tsC)
7985     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7986 }
7987
7988 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7989 {
7990   return MEDFileField1TSWithoutSDA::TYPE_STR;
7991 }
7992
7993 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7994 {
7995   return new MEDFileFieldMultiTSWithoutSDA(*this);
7996 }
7997
7998 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
7999 {
8000   return new MEDFileFieldMultiTSWithoutSDA;
8001 }
8002
8003 /*!
8004  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8005  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8006  */
8007 std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2(int iteration, int order, const std::string& 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
8008 {
8009   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8010   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8011   if(!myF1TSC)
8012     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8013   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8014 }
8015
8016 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8017 {
8018   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8019   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8020   int i=0;
8021   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8022     {
8023       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8024       if(eltToConv)
8025         {
8026           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8027           if(!eltToConvC)
8028             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8029           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8030           ret->setIteration(i,elt);
8031         }
8032     }
8033   return ret.retn();
8034 }
8035
8036 //= MEDFileAnyTypeFieldMultiTS
8037
8038 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8039 {
8040 }
8041
8042 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8043 try:MEDFileFieldGlobsReal(fileName)
8044 {
8045   MEDFileUtilities::CheckFileForRead(fileName);
8046   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8047   _content=BuildContentFrom(fid,fileName,loadAll,ms);
8048   loadGlobals(fid);
8049 }
8050 catch(INTERP_KERNEL::Exception& e)
8051 {
8052     throw e;
8053 }
8054
8055 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8056 {
8057   med_field_type typcha;
8058   std::vector<std::string> infos;
8059   std::string dtunit;
8060   int i=-1;
8061   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
8062   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8063   switch(typcha)
8064   {
8065     case MED_FLOAT64:
8066       {
8067         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8068         break;
8069       }
8070     case MED_INT32:
8071       {
8072         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8073         break;
8074       }
8075     default:
8076       {
8077         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] !";
8078         throw INTERP_KERNEL::Exception(oss.str().c_str());
8079       }
8080   }
8081   ret->setDtUnit(dtunit.c_str());
8082   return ret.retn();
8083 }
8084
8085 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8086 {
8087   med_field_type typcha;
8088   //
8089   std::vector<std::string> infos;
8090   std::string dtunit,fieldName;
8091   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
8092   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8093   switch(typcha)
8094   {
8095     case MED_FLOAT64:
8096       {
8097         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8098         break;
8099       }
8100     case MED_INT32:
8101       {
8102         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8103         break;
8104       }
8105     default:
8106       {
8107         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] !";
8108         throw INTERP_KERNEL::Exception(oss.str().c_str());
8109       }
8110   }
8111   ret->setDtUnit(dtunit.c_str());
8112   return ret.retn();
8113 }
8114
8115 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
8116 {
8117   if(!c)
8118     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8119   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8120     {
8121       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
8122       ret->setFileName(fileName);
8123       ret->_content=c;  c->incrRef();
8124       return ret.retn();
8125     }
8126   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8127     {
8128       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
8129       ret->setFileName(fileName);
8130       ret->_content=c;  c->incrRef();
8131       return ret.retn();
8132     }
8133   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8134 }
8135
8136 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8137 try:MEDFileFieldGlobsReal(fileName)
8138 {
8139   MEDFileUtilities::CheckFileForRead(fileName);
8140   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8141   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms,entities);
8142   loadGlobals(fid);
8143 }
8144 catch(INTERP_KERNEL::Exception& e)
8145 {
8146     throw e;
8147 }
8148
8149 //= MEDFileIntFieldMultiTSWithoutSDA
8150
8151 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8152 {
8153   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8154 }
8155
8156 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8157 {
8158 }
8159
8160 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8161 {
8162 }
8163
8164 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8165 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8166 {
8167 }
8168 catch(INTERP_KERNEL::Exception& e)
8169 { throw e; }
8170
8171 /*!
8172  * \param [in] fieldId field id in C mode
8173  */
8174 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8175 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8176 {
8177 }
8178 catch(INTERP_KERNEL::Exception& e)
8179 { throw e; }
8180
8181 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8182 {
8183   return new MEDFileIntField1TSWithoutSDA;
8184 }
8185
8186 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8187 {
8188   if(!f1ts)
8189     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8190   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8191   if(!f1tsC)
8192     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8193 }
8194
8195 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8196 {
8197   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8198 }
8199
8200 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8201 {
8202   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8203 }
8204
8205 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8206 {
8207   return new MEDFileIntFieldMultiTSWithoutSDA;
8208 }
8209
8210 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8211 {
8212   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8213   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8214   int i=0;
8215   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8216     {
8217       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8218       if(eltToConv)
8219         {
8220           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8221           if(!eltToConvC)
8222             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8223           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8224           ret->setIteration(i,elt);
8225         }
8226     }
8227   return ret.retn();
8228 }
8229
8230 //= MEDFileAnyTypeFieldMultiTS
8231
8232 /*!
8233  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8234  * that has been read from a specified MED file.
8235  *  \param [in] fileName - the name of the MED file to read.
8236  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8237  *          is to delete this field using decrRef() as it is no more needed.
8238  *  \throw If reading the file fails.
8239  */
8240 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8241 {
8242   MEDFileUtilities::CheckFileForRead(fileName);
8243   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8244   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
8245   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8246   ret->loadGlobals(fid);
8247   return ret.retn();
8248 }
8249
8250 /*!
8251  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8252  * that has been read from a specified MED file.
8253  *  \param [in] fileName - the name of the MED file to read.
8254  *  \param [in] fieldName - the name of the field to read.
8255  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8256  *          is to delete this field using decrRef() as it is no more needed.
8257  *  \throw If reading the file fails.
8258  *  \throw If there is no field named \a fieldName in the file.
8259  */
8260 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8261 {
8262   MEDFileUtilities::CheckFileForRead(fileName);
8263   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8264   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fileName,fieldName,loadAll,0,0));
8265   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8266   ret->loadGlobals(fid);
8267   return ret.retn();
8268 }
8269
8270 /*!
8271  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8272  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8273  *
8274  * \warning this is a shallow copy constructor
8275  */
8276 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8277 {
8278   if(!shallowCopyOfContent)
8279     {
8280       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8281       otherPtr->incrRef();
8282       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8283     }
8284   else
8285     {
8286       _content=other.shallowCpy();
8287     }
8288 }
8289
8290 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8291 {
8292   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8293   if(!ret)
8294     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8295   return ret;
8296 }
8297
8298 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8299 {
8300   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8301   if(!ret)
8302     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8303   return ret;
8304 }
8305
8306 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8307 {
8308   return contentNotNullBase()->getPflsReallyUsed2();
8309 }
8310
8311 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8312 {
8313   return contentNotNullBase()->getLocsReallyUsed2();
8314 }
8315
8316 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8317 {
8318   return contentNotNullBase()->getPflsReallyUsedMulti2();
8319 }
8320
8321 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8322 {
8323   return contentNotNullBase()->getLocsReallyUsedMulti2();
8324 }
8325
8326 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8327 {
8328   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8329 }
8330
8331 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8332 {
8333   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8334 }
8335
8336 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8337 {
8338   return contentNotNullBase()->getNumberOfTS();
8339 }
8340
8341 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8342 {
8343   contentNotNullBase()->eraseEmptyTS();
8344 }
8345
8346 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8347 {
8348   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8349 }
8350
8351 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8352 {
8353   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8354 }
8355
8356 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8357 {
8358   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8359   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8360   ret->_content=c;
8361   return ret.retn();
8362 }
8363
8364 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8365 {
8366   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8367   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8368   ret->_content=c;
8369   return ret.retn();
8370 }
8371
8372 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8373 {
8374   return contentNotNullBase()->getIterations();
8375 }
8376
8377 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8378 {
8379   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8380     pushBackTimeStep(*it);
8381 }
8382
8383 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8384 {
8385   if(!fmts)
8386     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8387   int nbOfTS(fmts->getNumberOfTS());
8388   for(int i=0;i<nbOfTS;i++)
8389     {
8390       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8391       pushBackTimeStep(elt);
8392     }
8393 }
8394
8395 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8396 {
8397   if(!f1ts)
8398     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8399   checkCoherencyOfType(f1ts);
8400   f1ts->incrRef();
8401   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8402   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8403   c->incrRef();
8404   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8405   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8406     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8407   _content->pushBackTimeStep(cSafe);
8408   appendGlobs(*f1ts,1e-12);
8409 }
8410
8411 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8412 {
8413   contentNotNullBase()->synchronizeNameScope();
8414 }
8415
8416 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8417 {
8418   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8419 }
8420
8421 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8422 {
8423   return contentNotNullBase()->getPosGivenTime(time,eps);
8424 }
8425
8426 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8427 {
8428   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8429 }
8430
8431 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8432 {
8433   return contentNotNullBase()->getTypesOfFieldAvailable();
8434 }
8435
8436 std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeFieldMultiTS::getFieldSplitedByType(int iteration, int order, const std::string& 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
8437 {
8438   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8439 }
8440
8441 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8442 {
8443   return contentNotNullBase()->getName();
8444 }
8445
8446 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8447 {
8448   contentNotNullBase()->setName(name);
8449 }
8450
8451 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8452 {
8453   return contentNotNullBase()->getDtUnit();
8454 }
8455
8456 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8457 {
8458   contentNotNullBase()->setDtUnit(dtUnit);
8459 }
8460
8461 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8462 {
8463   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8464 }
8465
8466 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8467 {
8468   return contentNotNullBase()->getTimeSteps(ret1);
8469 }
8470
8471 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8472 {
8473   return contentNotNullBase()->getMeshName();
8474 }
8475
8476 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8477 {
8478   contentNotNullBase()->setMeshName(newMeshName);
8479 }
8480
8481 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8482 {
8483   return contentNotNullBase()->changeMeshNames(modifTab);
8484 }
8485
8486 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8487 {
8488   return contentNotNullBase()->getInfo();
8489 }
8490
8491 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8492 {
8493   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8494 }
8495
8496 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8497 {
8498   return contentNotNullBase()->setInfo(info);
8499 }
8500
8501 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8502 {
8503   const std::vector<std::string> ret=getInfo();
8504   return (int)ret.size();
8505 }
8506
8507 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8508 {
8509   writeGlobals(fid,*this);
8510   contentNotNullBase()->writeLL(fid,*this);
8511 }
8512
8513 /*!
8514  * Writes \a this field into a MED file specified by its name.
8515  *  \param [in] fileName - the MED file name.
8516  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8517  * - 2 - erase; an existing file is removed.
8518  * - 1 - append; same data should not be present in an existing file.
8519  * - 0 - overwrite; same data present in an existing file is overwritten.
8520  *  \throw If the field name is not set.
8521  *  \throw If no field data is set.
8522  *  \throw If \a mode == 1 and the same data is present in an existing file.
8523  */
8524 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8525 {
8526   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8527   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8528   writeLL(fid);
8529 }
8530
8531 /*!
8532  * This method alloc the arrays and load potentially huge arrays contained in this field.
8533  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8534  * This method can be also called to refresh or reinit values from a file.
8535  * 
8536  * \throw If the fileName is not set or points to a non readable MED file.
8537  */
8538 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8539 {
8540   if(getFileName().empty())
8541     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8542   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8543   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8544 }
8545
8546 /*!
8547  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8548  * But once data loaded once, this method does nothing.
8549  * 
8550  * \throw If the fileName is not set or points to a non readable MED file.
8551  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8552  */
8553 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8554 {
8555   if(!getFileName().empty())
8556     {
8557       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8558       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8559     }
8560 }
8561
8562 /*!
8563  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8564  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8565  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8566  * 
8567  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8568  */
8569 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8570 {
8571   contentNotNullBase()->unloadArrays();
8572 }
8573
8574 /*!
8575  * This method potentially releases big data arrays if \a this is coming from a file. If \a this has been built from scratch this method will have no effect.
8576  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8577  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8578  * 
8579  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8580  */
8581 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8582 {
8583   if(!getFileName().empty())
8584     contentNotNullBase()->unloadArrays();
8585 }
8586
8587 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8588 {
8589   std::ostringstream oss;
8590   contentNotNullBase()->simpleRepr(0,oss,-1);
8591   simpleReprGlobs(oss);
8592   return oss.str();
8593 }
8594
8595 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8596 {
8597   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8598 }
8599
8600 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8601 {
8602   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8603   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8604   return ret;
8605 }
8606
8607 /*!
8608  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8609  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8610  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8611  */
8612 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8613 {
8614   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8615   if(!content)
8616     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8617   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8618   std::size_t sz(contentsSplit.size());
8619   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8620   for(std::size_t i=0;i<sz;i++)
8621     {
8622       ret[i]=shallowCpy();
8623       ret[i]->_content=contentsSplit[i];
8624     }
8625   return ret;
8626 }
8627
8628 /*!
8629  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8630  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8631  */
8632 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8633 {
8634   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8635   if(!content)
8636     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8637   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8638   std::size_t sz(contentsSplit.size());
8639   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8640   for(std::size_t i=0;i<sz;i++)
8641     {
8642       ret[i]=shallowCpy();
8643       ret[i]->_content=contentsSplit[i];
8644     }
8645   return ret;
8646 }
8647
8648 /*!
8649  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8650  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8651  */
8652 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8653 {
8654   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8655   if(!content)
8656     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8657   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8658   std::size_t sz(contentsSplit.size());
8659   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8660   for(std::size_t i=0;i<sz;i++)
8661     {
8662       ret[i]=shallowCpy();
8663       ret[i]->_content=contentsSplit[i];
8664     }
8665   return ret;
8666 }
8667
8668 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const
8669 {
8670   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8671   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8672     ret->_content=_content->deepCpy();
8673   ret->deepCpyGlobs(*this);
8674   return ret.retn();
8675 }
8676
8677 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8678 {
8679   return _content;
8680 }
8681
8682 /*!
8683  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8684  *  \param [in] iteration - the iteration number of a required time step.
8685  *  \param [in] order - the iteration order number of required time step.
8686  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8687  *          delete this field using decrRef() as it is no more needed.
8688  *  \throw If there is no required time step in \a this field.
8689  */
8690 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8691 {
8692   int pos=getPosOfTimeStep(iteration,order);
8693   return getTimeStepAtPos(pos);
8694 }
8695
8696 /*!
8697  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8698  *  \param [in] time - the time of the time step of interest.
8699  *  \param [in] eps - a precision used to compare time values.
8700  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8701  *          delete this field using decrRef() as it is no more needed.
8702  *  \throw If there is no required time step in \a this field.
8703  */
8704 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8705 {
8706   int pos=getPosGivenTime(time,eps);
8707   return getTimeStepAtPos(pos);
8708 }
8709
8710 /*!
8711  * 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.
8712  * The float64 value of time attached to the pair of integers are not considered here.
8713  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8714  *
8715  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8716  * \throw If there is a null pointer in \a vectFMTS.
8717  */
8718 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8719 {
8720   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8721   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8722   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8723   while(!lstFMTS.empty())
8724     {
8725       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8726       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8727       if(!curIt)
8728         throw INTERP_KERNEL::Exception(msg);
8729       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8730       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8731       elt.push_back(curIt); it=lstFMTS.erase(it);
8732       while(it!=lstFMTS.end())
8733         {
8734           curIt=*it;
8735           if(!curIt)
8736             throw INTERP_KERNEL::Exception(msg);
8737           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8738           if(refIts==curIts)
8739             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8740           else
8741             it++;
8742         }
8743       ret.push_back(elt);
8744     }
8745   return ret;
8746 }
8747
8748 /*!
8749  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8750  * All returned instances in a subvector can be safely loaded, rendered along time
8751  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8752  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8753  * 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).
8754  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8755  * 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.
8756  *
8757  * \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().
8758  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8759  * \param [out] fsc - A vector having same size than returned vector. It specifies the support comporator of the corresponding vector of MEDFileAnyTypeFieldMultiTS in returned vector of vector.
8760  * \return - A vector of vector of objects that contains the same pointers (objects) than thoose in \a vectFMTS except that there are organized differently. So pointers included in returned vector of vector should \b not been dealt by the caller.
8761  *
8762  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8763  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8764  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8765  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8766  * \throw If mesh is null.
8767  * \throw If an element in \a vectFMTS is null.
8768  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8769  */
8770 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& fsc)
8771 {
8772   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8773   if(!mesh)
8774     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8775   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8776   if(vectFMTS.empty())
8777     return ret;
8778   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8779   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8780   if(!frstElt)
8781     throw INTERP_KERNEL::Exception(msg);
8782   std::size_t i=0;
8783   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8784   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8785   for(;it!=vectFMTS.end();it++,i++)
8786     {
8787       if(!(*it))
8788         throw INTERP_KERNEL::Exception(msg);
8789       TypeOfField tof0,tof1;
8790       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8791         {
8792           if(tof1!=ON_NODES)
8793             vectFMTSNotNodes.push_back(*it);
8794           else
8795             vectFMTSNodes.push_back(*it);
8796         }
8797       else
8798         vectFMTSNotNodes.push_back(*it);
8799     }
8800   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8801   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8802   ret=retCell;
8803   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8804     {
8805       i=0;
8806       bool isFetched(false);
8807       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8808         {
8809           if((*it0).empty())
8810             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8811           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8812             { ret[i].push_back(*it2); isFetched=true; }
8813         }
8814       if(!isFetched)
8815         {
8816           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8817           MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8818           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8819         }
8820     }
8821   fsc=cmps;
8822   return ret;
8823 }
8824
8825 /*!
8826  * 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.
8827  * \param [out] cmps - same size than the returned vector.
8828  */
8829 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps)
8830 {
8831   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8832   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8833   while(!lstFMTS.empty())
8834     {
8835       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8836       MEDFileAnyTypeFieldMultiTS *ref(*it);
8837       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8838       elt.push_back(ref); it=lstFMTS.erase(it);
8839       MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8840       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8841       while(it!=lstFMTS.end())
8842         {
8843           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8844           if(cmp->isEqual(curIt))
8845             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8846           else
8847             it++;
8848         }
8849       ret.push_back(elt); cmps.push_back(cmp);
8850     }
8851   return ret;
8852 }
8853
8854 /*!
8855  * 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.
8856  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8857  *
8858  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8859  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8860  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8861  * \thorw If \a f0 and \a f1 do not have the same times steps.
8862  * \throw If mesh is null.
8863  * \throw If \a f0 or \a f1 is null.
8864  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8865  */
8866 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8867 {
8868   if(!mesh)
8869     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8870   if(!f0 || !f1)
8871     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8872   if(f0->getMeshName()!=mesh->getName())
8873     {
8874       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8875       throw INTERP_KERNEL::Exception(oss.str().c_str());
8876     }
8877   if(f1->getMeshName()!=mesh->getName())
8878     {
8879       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8880       throw INTERP_KERNEL::Exception(oss.str().c_str());
8881     }
8882   int nts=f0->getNumberOfTS();
8883   if(nts!=f1->getNumberOfTS())
8884     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8885   if(nts==0)
8886     return nts;
8887   for(int i=0;i<nts;i++)
8888     {
8889       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8890       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8891       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8892       if(tofs0.size()!=1 || tofs1.size()!=1)
8893         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8894       if(i!=0)
8895         {
8896           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8897             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8898         }
8899       else
8900         { tof0=tofs0[0]; tof1=tofs1[0]; }
8901       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8902         {
8903           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() << ") !";
8904           throw INTERP_KERNEL::Exception(oss.str().c_str());
8905         }
8906       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8907         {
8908           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() << ") !";
8909           throw INTERP_KERNEL::Exception(oss.str().c_str());
8910         }
8911       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8912         {
8913           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() << ") !";
8914           throw INTERP_KERNEL::Exception(oss.str().c_str());
8915         }
8916     }
8917   return nts;
8918 }
8919
8920 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8921 {
8922   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8923 }
8924
8925 //= MEDFileFieldMultiTS
8926
8927 /*!
8928  * Returns a new empty instance of MEDFileFieldMultiTS.
8929  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8930  *          is to delete this field using decrRef() as it is no more needed.
8931  */
8932 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8933 {
8934   return new MEDFileFieldMultiTS;
8935 }
8936
8937 /*!
8938  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8939  * that has been read from a specified MED file.
8940  *  \param [in] fileName - the name of the MED file to read.
8941  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8942  *          is to delete this field using decrRef() as it is no more needed.
8943  *  \throw If reading the file fails.
8944  */
8945 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8946 {
8947   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
8948   ret->contentNotNull();//to check that content type matches with \a this type.
8949   return ret.retn();
8950 }
8951
8952 /*!
8953  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8954  * that has been read from a specified MED file.
8955  *  \param [in] fileName - the name of the MED file to read.
8956  *  \param [in] fieldName - the name of the field to read.
8957  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8958  *          is to delete this field using decrRef() as it is no more needed.
8959  *  \throw If reading the file fails.
8960  *  \throw If there is no field named \a fieldName in the file.
8961  */
8962 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8963 {
8964   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
8965   ret->contentNotNull();//to check that content type matches with \a this type.
8966   return ret.retn();
8967 }
8968
8969 /*!
8970  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8971  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8972  *
8973  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8974  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8975  * \warning this is a shallow copy constructor
8976  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8977  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8978  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8979  *          is to delete this field using decrRef() as it is no more needed.
8980  */
8981 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8982 {
8983   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8984 }
8985
8986 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
8987 {
8988   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0,&entities));
8989   ret->contentNotNull();//to check that content type matches with \a this type.
8990   return ret.retn();
8991 }
8992
8993 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8994 {
8995   return new MEDFileFieldMultiTS(*this);
8996 }
8997
8998 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
8999 {
9000   if(!f1ts)
9001     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9002   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9003   if(!f1tsC)
9004     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9005 }
9006
9007 /*!
9008  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9009  * following the given input policy.
9010  *
9011  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9012  *                            By default (true) the globals are deeply copied.
9013  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9014  */
9015 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9016 {
9017   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
9018   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9019   if(content)
9020     {
9021       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9022       if(!contc)
9023         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9024       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9025       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
9026     }
9027   else
9028     ret=MEDFileIntFieldMultiTS::New();
9029   if(isDeepCpyGlobs)
9030     ret->deepCpyGlobs(*this);
9031   else
9032     ret->shallowCpyGlobs(*this);
9033   return ret.retn();
9034 }
9035
9036 /*!
9037  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9038  *  \param [in] pos - a time step id.
9039  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9040  *          delete this field using decrRef() as it is no more needed.
9041  *  \throw If \a pos is not a valid time step id.
9042  */
9043 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9044 {
9045   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9046   if(!item)
9047     {
9048       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9049       throw INTERP_KERNEL::Exception(oss.str().c_str());
9050     }
9051   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9052   if(itemC)
9053     {
9054       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9055       ret->shallowCpyGlobs(*this);
9056       return ret.retn();
9057     }
9058   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9059   throw INTERP_KERNEL::Exception(oss.str().c_str());
9060 }
9061
9062 /*!
9063  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9064  * mesh entities of a given dimension of the first mesh in MED file.
9065  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9066  *  \param [in] type - a spatial discretization of interest.
9067  *  \param [in] iteration - the iteration number of a required time step.
9068  *  \param [in] order - the iteration order number of required time step.
9069  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9070  *  \param [in] renumPol - specifies how to permute values of the result field according to
9071  *          the optional numbers of cells and nodes, if any. The valid values are
9072  *          - 0 - do not permute.
9073  *          - 1 - permute cells.
9074  *          - 2 - permute nodes.
9075  *          - 3 - permute cells and nodes.
9076  *
9077  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9078  *          caller is to delete this field using decrRef() as it is no more needed. 
9079  *  \throw If the MED file is not readable.
9080  *  \throw If there is no mesh in the MED file.
9081  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9082  *  \throw If no field values of the required parameters are available.
9083  */
9084 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9085 {
9086   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9087   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9088   if(!myF1TSC)
9089     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9090   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9091   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9092   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9093   return ret.retn();
9094 }
9095
9096 /*!
9097  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9098  * the top level cells of the first mesh in MED file.
9099  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9100  *  \param [in] type - a spatial discretization of interest.
9101  *  \param [in] iteration - the iteration number of a required time step.
9102  *  \param [in] order - the iteration order number of required time step.
9103  *  \param [in] renumPol - specifies how to permute values of the result field according to
9104  *          the optional numbers of cells and nodes, if any. The valid values are
9105  *          - 0 - do not permute.
9106  *          - 1 - permute cells.
9107  *          - 2 - permute nodes.
9108  *          - 3 - permute cells and nodes.
9109  *
9110  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9111  *          caller is to delete this field using decrRef() as it is no more needed. 
9112  *  \throw If the MED file is not readable.
9113  *  \throw If there is no mesh in the MED file.
9114  *  \throw If no field values of the required parameters are available.
9115  */
9116 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9117 {
9118   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9119   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9120   if(!myF1TSC)
9121     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9122   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9123   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9124   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9125   return ret.retn();
9126 }
9127
9128 /*!
9129  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9130  * a given support.
9131  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9132  *  \param [in] type - a spatial discretization of interest.
9133  *  \param [in] iteration - the iteration number of a required time step.
9134  *  \param [in] order - the iteration order number of required time step.
9135  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9136  *  \param [in] mesh - the supporting mesh.
9137  *  \param [in] renumPol - specifies how to permute values of the result field according to
9138  *          the optional numbers of cells and nodes, if any. The valid values are
9139  *          - 0 - do not permute.
9140  *          - 1 - permute cells.
9141  *          - 2 - permute nodes.
9142  *          - 3 - permute cells and nodes.
9143  *
9144  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9145  *          caller is to delete this field using decrRef() as it is no more needed. 
9146  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9147  *  \throw If no field of \a this is lying on \a mesh.
9148  *  \throw If no field values of the required parameters are available.
9149  */
9150 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9151 {
9152   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9153   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9154   if(!myF1TSC)
9155     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9156   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9157   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9158   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9159   return ret.retn();
9160 }
9161
9162 /*!
9163  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9164  * given support. 
9165  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9166  *  \param [in] type - a spatial discretization of the new field.
9167  *  \param [in] iteration - the iteration number of a required time step.
9168  *  \param [in] order - the iteration order number of required time step.
9169  *  \param [in] mesh - the supporting mesh.
9170  *  \param [in] renumPol - specifies how to permute values of the result field according to
9171  *          the optional numbers of cells and nodes, if any. The valid values are
9172  *          - 0 - do not permute.
9173  *          - 1 - permute cells.
9174  *          - 2 - permute nodes.
9175  *          - 3 - permute cells and nodes.
9176  *
9177  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9178  *          caller is to delete this field using decrRef() as it is no more needed. 
9179  *  \throw If no field of \a this is lying on \a mesh.
9180  *  \throw If no field values of the required parameters are available.
9181  */
9182 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9183 {
9184   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9185   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9186   if(!myF1TSC)
9187     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9188   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9189   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9190   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9191   return ret.retn();
9192 }
9193
9194 /*!
9195  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9196  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9197  * This method is useful for MED2 file format when field on different mesh was autorized.
9198  */
9199 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9200 {
9201   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9202   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9203   if(!myF1TSC)
9204     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9205   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9206   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9207   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9208   return ret.retn();
9209 }
9210
9211 /*!
9212  * Returns values and a profile of the field of a given type, of a given time step,
9213  * lying on a given support.
9214  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9215  *  \param [in] type - a spatial discretization of the field.
9216  *  \param [in] iteration - the iteration number of a required time step.
9217  *  \param [in] order - the iteration order number of required time step.
9218  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9219  *  \param [in] mesh - the supporting mesh.
9220  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9221  *          field of interest lies on. If the field lies on all entities of the given
9222  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9223  *          using decrRef() as it is no more needed.  
9224  *  \param [in] glob - the global data storing profiles and localization.
9225  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9226  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9227  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9228  *  \throw If no field of \a this is lying on \a mesh.
9229  *  \throw If no field values of the required parameters are available.
9230  */
9231 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9232 {
9233   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9234   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9235   if(!myF1TSC)
9236     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9237   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9238   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9239 }
9240
9241 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9242 {
9243   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9244   if(!pt)
9245     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9246   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9247   if(!ret)
9248     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 !");
9249   return ret;
9250 }
9251
9252 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9253 {
9254   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9255   if(!pt)
9256     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9257   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9258   if(!ret)
9259     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 !");
9260   return ret;
9261 }
9262
9263 /*!
9264  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9265  * the given field is checked if its elements are sorted suitable for writing to MED file
9266  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9267  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9268  *  \param [in] field - the field to add to \a this.
9269  *  \throw If the name of \a field is empty.
9270  *  \throw If the data array of \a field is not set.
9271  *  \throw If existing time steps have different name or number of components than \a field.
9272  *  \throw If the underlying mesh of \a field has no name.
9273  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9274  */
9275 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9276 {
9277   const DataArrayDouble *arr=0;
9278   if(field)
9279     arr=field->getArray();
9280   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9281 }
9282
9283 /*!
9284  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9285  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9286  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9287  * and \a profile.
9288  *
9289  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9290  * A new profile is added only if no equal profile is missing.
9291  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9292  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9293  *  \param [in] mesh - the supporting mesh of \a field.
9294  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9295  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9296  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9297  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9298  *  \throw If the data array of \a field is not set.
9299  *  \throw If the data array of \a this is already allocated but has different number of
9300  *         components than \a field.
9301  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9302  *  \sa setFieldNoProfileSBT()
9303  */
9304 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9305 {
9306   const DataArrayDouble *arr=0;
9307   if(field)
9308     arr=field->getArray();
9309   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9310 }
9311
9312 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9313 {
9314   _content=new MEDFileFieldMultiTSWithoutSDA;
9315 }
9316
9317 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9318 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9319 {
9320 }
9321 catch(INTERP_KERNEL::Exception& e)
9322 { throw e; }
9323
9324 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9325 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9326 {
9327 }
9328 catch(INTERP_KERNEL::Exception& e)
9329 { throw e; }
9330
9331 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9332 {
9333 }
9334
9335 std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTS::getFieldSplitedByType2(int iteration, int order, const std::string& 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
9336 {
9337   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9338 }
9339
9340 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9341 {
9342   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9343 }
9344
9345 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9346 {
9347   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9348 }
9349
9350 //= MEDFileAnyTypeFieldMultiTSIterator
9351
9352 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9353 {
9354   if(fmts)
9355     {
9356       fmts->incrRef();
9357       _nb_iter=fmts->getNumberOfTS();
9358     }
9359 }
9360
9361 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9362 {
9363 }
9364
9365 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9366 {
9367   if(_iter_id<_nb_iter)
9368     {
9369       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9370       if(fmts)
9371         return fmts->getTimeStepAtPos(_iter_id++);
9372       else
9373         return 0;
9374     }
9375   else
9376     return 0;
9377 }
9378
9379 //= MEDFileIntFieldMultiTS
9380
9381 /*!
9382  * Returns a new empty instance of MEDFileFieldMultiTS.
9383  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9384  *          is to delete this field using decrRef() as it is no more needed.
9385  */
9386 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9387 {
9388   return new MEDFileIntFieldMultiTS;
9389 }
9390
9391 /*!
9392  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9393  * that has been read from a specified MED file.
9394  *  \param [in] fileName - the name of the MED file to read.
9395  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9396  *          is to delete this field using decrRef() as it is no more needed.
9397  *  \throw If reading the file fails.
9398  */
9399 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9400 {
9401   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9402   ret->contentNotNull();//to check that content type matches with \a this type.
9403   return ret.retn();
9404 }
9405
9406 /*!
9407  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9408  * that has been read from a specified MED file.
9409  *  \param [in] fileName - the name of the MED file to read.
9410  *  \param [in] fieldName - the name of the field to read.
9411  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9412  *          is to delete this field using decrRef() as it is no more needed.
9413  *  \throw If reading the file fails.
9414  *  \throw If there is no field named \a fieldName in the file.
9415  */
9416 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9417 {
9418   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9419   ret->contentNotNull();//to check that content type matches with \a this type.
9420   return ret.retn();
9421 }
9422
9423 /*!
9424  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9425  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9426  *
9427  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9428  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9429  * \warning this is a shallow copy constructor
9430  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9431  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9432  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9433  *          is to delete this field using decrRef() as it is no more needed.
9434  */
9435 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9436 {
9437   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9438 }
9439
9440 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9441 {
9442   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0,&entities);
9443   ret->contentNotNull();//to check that content type matches with \a this type.
9444   return ret.retn();
9445 }
9446
9447 /*!
9448  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9449  * following the given input policy.
9450  *
9451  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9452  *                            By default (true) the globals are deeply copied.
9453  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9454  */
9455 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9456 {
9457   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
9458   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9459   if(content)
9460     {
9461       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9462       if(!contc)
9463         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9464       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9465       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9466     }
9467   else
9468     ret=MEDFileFieldMultiTS::New();
9469   if(isDeepCpyGlobs)
9470     ret->deepCpyGlobs(*this);
9471   else
9472     ret->shallowCpyGlobs(*this);
9473   return ret.retn();
9474 }
9475
9476 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9477 {
9478   return new MEDFileIntFieldMultiTS(*this);
9479 }
9480
9481 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9482 {
9483   if(!f1ts)
9484     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9485   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9486   if(!f1tsC)
9487     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9488 }
9489
9490 /*!
9491  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9492  * mesh entities of a given dimension of the first mesh in MED file.
9493  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9494  *  \param [in] type - a spatial discretization of interest.
9495  *  \param [in] iteration - the iteration number of a required time step.
9496  *  \param [in] order - the iteration order number of required time step.
9497  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9498  *  \param [out] arrOut - the DataArrayInt containing values of field.
9499  *  \param [in] renumPol - specifies how to permute values of the result field according to
9500  *          the optional numbers of cells and nodes, if any. The valid values are
9501  *          - 0 - do not permute.
9502  *          - 1 - permute cells.
9503  *          - 2 - permute nodes.
9504  *          - 3 - permute cells and nodes.
9505  *
9506  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9507  *          caller is to delete this field using decrRef() as it is no more needed. 
9508  *  \throw If the MED file is not readable.
9509  *  \throw If there is no mesh in the MED file.
9510  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9511  *  \throw If no field values of the required parameters are available.
9512  */
9513 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9514 {
9515   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9516   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9517   if(!myF1TSC)
9518     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9519   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9520   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9521   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9522   return ret.retn();
9523 }
9524
9525 /*!
9526  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9527  * the top level cells of the first mesh in MED file.
9528  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9529  *  \param [in] type - a spatial discretization of interest.
9530  *  \param [in] iteration - the iteration number of a required time step.
9531  *  \param [in] order - the iteration order number of required time step.
9532  *  \param [out] arrOut - the DataArrayInt containing values of field.
9533  *  \param [in] renumPol - specifies how to permute values of the result field according to
9534  *          the optional numbers of cells and nodes, if any. The valid values are
9535  *          - 0 - do not permute.
9536  *          - 1 - permute cells.
9537  *          - 2 - permute nodes.
9538  *          - 3 - permute cells and nodes.
9539  *
9540  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9541  *          caller is to delete this field using decrRef() as it is no more needed. 
9542  *  \throw If the MED file is not readable.
9543  *  \throw If there is no mesh in the MED file.
9544  *  \throw If no field values of the required parameters are available.
9545  */
9546 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9547 {
9548   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9549   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9550   if(!myF1TSC)
9551     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9552   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9553   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9554   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9555   return ret.retn();
9556 }
9557
9558 /*!
9559  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9560  * a given support.
9561  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9562  *  \param [in] type - a spatial discretization of interest.
9563  *  \param [in] iteration - the iteration number of a required time step.
9564  *  \param [in] order - the iteration order number of required time step.
9565  *  \param [out] arrOut - the DataArrayInt containing values of field.
9566  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9567  *  \param [in] mesh - the supporting mesh.
9568  *  \param [in] renumPol - specifies how to permute values of the result field according to
9569  *          the optional numbers of cells and nodes, if any. The valid values are
9570  *          - 0 - do not permute.
9571  *          - 1 - permute cells.
9572  *          - 2 - permute nodes.
9573  *          - 3 - permute cells and nodes.
9574  *
9575  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9576  *          caller is to delete this field using decrRef() as it is no more needed. 
9577  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9578  *  \throw If no field of \a this is lying on \a mesh.
9579  *  \throw If no field values of the required parameters are available.
9580  */
9581 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9582 {
9583   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9584   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9585   if(!myF1TSC)
9586     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9587   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9588   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9589   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9590   return ret.retn();
9591 }
9592
9593 /*!
9594  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9595  * given support. 
9596  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9597  *  \param [in] type - a spatial discretization of the new field.
9598  *  \param [in] iteration - the iteration number of a required time step.
9599  *  \param [in] order - the iteration order number of required time step.
9600  *  \param [in] mesh - the supporting mesh.
9601  *  \param [out] arrOut - the DataArrayInt containing values of field.
9602  *  \param [in] renumPol - specifies how to permute values of the result field according to
9603  *          the optional numbers of cells and nodes, if any. The valid values are
9604  *          - 0 - do not permute.
9605  *          - 1 - permute cells.
9606  *          - 2 - permute nodes.
9607  *          - 3 - permute cells and nodes.
9608  *
9609  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9610  *          caller is to delete this field using decrRef() as it is no more needed. 
9611  *  \throw If no field of \a this is lying on \a mesh.
9612  *  \throw If no field values of the required parameters are available.
9613  */
9614 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9615 {
9616   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9617   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9618   if(!myF1TSC)
9619     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9620   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9621   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9622   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9623   return ret.retn();
9624 }
9625
9626 /*!
9627  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9628  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9629  * This method is useful for MED2 file format when field on different mesh was autorized.
9630  */
9631 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9632 {
9633   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9634   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9635   if(!myF1TSC)
9636     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9637   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9638   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9639   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9640   return ret.retn();
9641 }
9642
9643 /*!
9644  * Returns values and a profile of the field of a given type, of a given time step,
9645  * lying on a given support.
9646  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9647  *  \param [in] type - a spatial discretization of the field.
9648  *  \param [in] iteration - the iteration number of a required time step.
9649  *  \param [in] order - the iteration order number of required time step.
9650  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9651  *  \param [in] mesh - the supporting mesh.
9652  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9653  *          field of interest lies on. If the field lies on all entities of the given
9654  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9655  *          using decrRef() as it is no more needed.  
9656  *  \param [in] glob - the global data storing profiles and localization.
9657  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9658  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9659  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9660  *  \throw If no field of \a this is lying on \a mesh.
9661  *  \throw If no field values of the required parameters are available.
9662  */
9663 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9664 {
9665   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9666   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9667   if(!myF1TSC)
9668     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9669   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9670   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9671 }
9672
9673 /*!
9674  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9675  *  \param [in] pos - a time step id.
9676  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9677  *          delete this field using decrRef() as it is no more needed.
9678  *  \throw If \a pos is not a valid time step id.
9679  */
9680 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9681 {
9682   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9683   if(!item)
9684     {
9685       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9686       throw INTERP_KERNEL::Exception(oss.str().c_str());
9687     }
9688   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9689   if(itemC)
9690     {
9691       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9692       ret->shallowCpyGlobs(*this);
9693       return ret.retn();
9694     }
9695   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9696   throw INTERP_KERNEL::Exception(oss.str().c_str());
9697 }
9698
9699 /*!
9700  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9701  * the given field is checked if its elements are sorted suitable for writing to MED file
9702  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9703  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9704  *  \param [in] field - the field to add to \a this.
9705  *  \throw If the name of \a field is empty.
9706  *  \throw If the data array of \a field is not set.
9707  *  \throw If existing time steps have different name or number of components than \a field.
9708  *  \throw If the underlying mesh of \a field has no name.
9709  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9710  */
9711 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9712 {
9713   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9714 }
9715
9716 /*!
9717  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9718  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9719  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9720  * and \a profile.
9721  *
9722  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9723  * A new profile is added only if no equal profile is missing.
9724  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9725  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9726  *  \param [in] arrOfVals - the values of the field \a field used.
9727  *  \param [in] mesh - the supporting mesh of \a field.
9728  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9729  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9730  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9731  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9732  *  \throw If the data array of \a field is not set.
9733  *  \throw If the data array of \a this is already allocated but has different number of
9734  *         components than \a field.
9735  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9736  *  \sa setFieldNoProfileSBT()
9737  */
9738 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9739 {
9740   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9741 }
9742
9743 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9744 {
9745   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9746   if(!pt)
9747     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9748   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9749   if(!ret)
9750     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 !");
9751   return ret;
9752 }
9753
9754 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9755 {
9756   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9757   if(!pt)
9758     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9759   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9760   if(!ret)
9761     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 !");
9762   return ret;
9763 }
9764
9765 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9766 {
9767   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9768 }
9769
9770 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9771 {
9772 }
9773
9774 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9775 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9776 {
9777 }
9778 catch(INTERP_KERNEL::Exception& e)
9779 { throw e; }
9780
9781 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9782 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9783 {
9784 }
9785 catch(INTERP_KERNEL::Exception& e)
9786 { throw e; }
9787
9788 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9789 {
9790   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9791 }
9792
9793 //= MEDFileFields
9794
9795 MEDFileFields *MEDFileFields::New()
9796 {
9797   return new MEDFileFields;
9798 }
9799
9800 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9801 {
9802   return new MEDFileFields(fileName,loadAll,0,0);
9803 }
9804
9805 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9806 {
9807   return new MEDFileFields(fileName,loadAll,ms,0);
9808 }
9809
9810 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9811 {
9812   return new MEDFileFields(fileName,loadAll,0,&entities);
9813 }
9814
9815 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9816 {
9817   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9818   ret+=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9819   return ret;
9820 }
9821
9822 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9823 {
9824   std::vector<const BigMemoryObject *> ret;
9825   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9826     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9827   return ret;
9828 }
9829
9830 MEDFileFields *MEDFileFields::deepCpy() const
9831 {
9832   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9833   std::size_t i=0;
9834   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9835     {
9836       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9837         ret->_fields[i]=(*it)->deepCpy();
9838     }
9839   ret->deepCpyGlobs(*this);
9840   return ret.retn();
9841 }
9842
9843 MEDFileFields *MEDFileFields::shallowCpy() const
9844 {
9845   return new MEDFileFields(*this);
9846 }
9847
9848 /*!
9849  * 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
9850  * 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.
9851  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9852  *
9853  * \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.
9854  * \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.
9855  * 
9856  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9857  */
9858 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9859 {
9860   std::set< std::pair<int,int> > s;
9861   bool firstShot=true;
9862   areThereSomeForgottenTS=false;
9863   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9864     {
9865       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9866         continue;
9867       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9868       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9869       if(firstShot)
9870         { s=s1; firstShot=false; }
9871       else
9872         {
9873           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9874           if(s!=s2)
9875             areThereSomeForgottenTS=true;
9876           s=s2;
9877         }
9878     }
9879   std::vector< std::pair<int,int> > ret;
9880   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9881   return ret;
9882 }
9883
9884 int MEDFileFields::getNumberOfFields() const
9885 {
9886   return _fields.size();
9887 }
9888
9889 std::vector<std::string> MEDFileFields::getFieldsNames() const
9890 {
9891   std::vector<std::string> ret(_fields.size());
9892   int i=0;
9893   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9894     {
9895       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9896       if(f)
9897         {
9898           ret[i]=f->getName();
9899         }
9900       else
9901         {
9902           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9903           throw INTERP_KERNEL::Exception(oss.str().c_str());
9904         }
9905     }
9906   return ret;
9907 }
9908
9909 std::vector<std::string> MEDFileFields::getMeshesNames() const
9910 {
9911   std::vector<std::string> ret;
9912   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9913     {
9914       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9915       if(cur)
9916         ret.push_back(cur->getMeshName());
9917     }
9918   return ret;
9919 }
9920
9921 std::string MEDFileFields::simpleRepr() const
9922 {
9923   std::ostringstream oss;
9924   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9925   simpleRepr(0,oss);
9926   return oss.str();
9927 }
9928
9929 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9930 {
9931   int nbOfFields=getNumberOfFields();
9932   std::string startLine(bkOffset,' ');
9933   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9934   int i=0;
9935   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9936     {
9937       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9938       if(cur)
9939         {
9940           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9941         }
9942       else
9943         {
9944           oss << startLine << "  - not defined !" << std::endl;
9945         }
9946     }
9947   i=0;
9948   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9949     {
9950       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9951       std::string chapter(17,'0'+i);
9952       oss << startLine << chapter << std::endl;
9953       if(cur)
9954         {
9955           cur->simpleRepr(bkOffset+2,oss,i);
9956         }
9957       else
9958         {
9959           oss << startLine << "  - not defined !" << std::endl;
9960         }
9961       oss << startLine << chapter << std::endl;
9962     }
9963   simpleReprGlobs(oss);
9964 }
9965
9966 MEDFileFields::MEDFileFields()
9967 {
9968 }
9969
9970 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9971 try:MEDFileFieldGlobsReal(fileName)
9972 {
9973   MEDFileUtilities::CheckFileForRead(fileName);
9974   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
9975   int nbFields(MEDnField(fid));
9976   _fields.resize(nbFields);
9977   med_field_type typcha;
9978   for(int i=0;i<nbFields;i++)
9979     {
9980       std::vector<std::string> infos;
9981       std::string fieldName,dtunit;
9982       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
9983       switch(typcha)
9984       {
9985         case MED_FLOAT64:
9986           {
9987             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9988             break;
9989           }
9990         case MED_INT32:
9991           {
9992             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9993             break;
9994           }
9995         default:
9996           {
9997             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] !";
9998             throw INTERP_KERNEL::Exception(oss.str().c_str());
9999           }
10000       }
10001     }
10002   loadAllGlobals(fid);
10003 }
10004 catch(INTERP_KERNEL::Exception& e)
10005 {
10006     throw e;
10007 }
10008
10009 void MEDFileFields::writeLL(med_idt fid) const
10010 {
10011   int i=0;
10012   writeGlobals(fid,*this);
10013   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10014     {
10015       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10016       if(!elt)
10017         {
10018           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10019           throw INTERP_KERNEL::Exception(oss.str().c_str());
10020         }
10021       elt->writeLL(fid,*this);
10022     }
10023 }
10024
10025 void MEDFileFields::write(const std::string& fileName, int mode) const
10026 {
10027   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
10028   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
10029   writeLL(fid);
10030 }
10031
10032 /*!
10033  * This method alloc the arrays and load potentially huge arrays contained in this field.
10034  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10035  * This method can be also called to refresh or reinit values from a file.
10036  * 
10037  * \throw If the fileName is not set or points to a non readable MED file.
10038  */
10039 void MEDFileFields::loadArrays()
10040 {
10041   if(getFileName().empty())
10042     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10043   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10044   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10045     {
10046       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10047       if(elt)
10048         elt->loadBigArraysRecursively(fid,*elt);
10049     }
10050 }
10051
10052 /*!
10053  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10054  * But once data loaded once, this method does nothing.
10055  * 
10056  * \throw If the fileName is not set or points to a non readable MED file.
10057  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10058  */
10059 void MEDFileFields::loadArraysIfNecessary()
10060 {
10061   if(!getFileName().empty())
10062     {
10063       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10064       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10065         {
10066           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10067           if(elt)
10068             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10069         }
10070     }
10071 }
10072
10073 /*!
10074  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10075  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10076  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10077  * 
10078  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10079  */
10080 void MEDFileFields::unloadArrays()
10081 {
10082   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10083     {
10084       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10085       if(elt)
10086         elt->unloadArrays();
10087     }
10088 }
10089
10090 /*!
10091  * This method potentially releases big data arrays if \a this is coming from a file. If \a this has been built from scratch this method will have no effect.
10092  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10093  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10094  * 
10095  * \sa MEDFileFields::loadArraysIfNecessary
10096  */
10097 void MEDFileFields::unloadArraysWithoutDataLoss()
10098 {
10099   if(!getFileName().empty())
10100     unloadArrays();
10101 }
10102
10103 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10104 {
10105   std::vector<std::string> ret;
10106   std::set<std::string> ret2;
10107   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10108     {
10109       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10110       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10111         if(ret2.find(*it2)==ret2.end())
10112           {
10113             ret.push_back(*it2);
10114             ret2.insert(*it2);
10115           }
10116     }
10117   return ret;
10118 }
10119
10120 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10121 {
10122   std::vector<std::string> ret;
10123   std::set<std::string> ret2;
10124   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10125     {
10126       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10127       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10128         if(ret2.find(*it2)==ret2.end())
10129           {
10130             ret.push_back(*it2);
10131             ret2.insert(*it2);
10132           }
10133     }
10134   return ret;
10135 }
10136
10137 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10138 {
10139   std::vector<std::string> ret;
10140   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10141     {
10142       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
10143       ret.insert(ret.end(),tmp.begin(),tmp.end());
10144     }
10145   return ret;
10146 }
10147
10148 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10149 {
10150   std::vector<std::string> ret;
10151   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10152     {
10153       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10154       ret.insert(ret.end(),tmp.begin(),tmp.end());
10155     }
10156   return ret;
10157 }
10158
10159 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10160 {
10161   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10162     (*it)->changePflsRefsNamesGen2(mapOfModif);
10163 }
10164
10165 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10166 {
10167   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10168     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10169 }
10170
10171 void MEDFileFields::resize(int newSize)
10172 {
10173   _fields.resize(newSize);
10174 }
10175
10176 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10177 {
10178   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10179     pushField(*it);
10180 }
10181
10182 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10183 {
10184   if(!field)
10185     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10186   _fields.push_back(field->getContent());
10187   appendGlobs(*field,1e-12);
10188 }
10189
10190 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10191 {
10192   if(!field)
10193     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10194   if(i>=(int)_fields.size())
10195     _fields.resize(i+1);
10196   _fields[i]=field->getContent();
10197   appendGlobs(*field,1e-12);
10198 }
10199
10200 void MEDFileFields::destroyFieldAtPos(int i)
10201 {
10202   destroyFieldsAtPos(&i,&i+1);
10203 }
10204
10205 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10206 {
10207   std::vector<bool> b(_fields.size(),true);
10208   for(const int *i=startIds;i!=endIds;i++)
10209     {
10210       if(*i<0 || *i>=(int)_fields.size())
10211         {
10212           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10213           throw INTERP_KERNEL::Exception(oss.str().c_str());
10214         }
10215       b[*i]=false;
10216     }
10217   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10218   std::size_t j=0;
10219   for(std::size_t i=0;i<_fields.size();i++)
10220     if(b[i])
10221       fields[j++]=_fields[i];
10222   _fields=fields;
10223 }
10224
10225 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10226 {
10227   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10228   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
10229   std::vector<bool> b(_fields.size(),true);
10230   int k=bg;
10231   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10232     {
10233       if(k<0 || k>=(int)_fields.size())
10234         {
10235           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10236           throw INTERP_KERNEL::Exception(oss.str().c_str());
10237         }
10238       b[k]=false;
10239     }
10240   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10241   std::size_t j=0;
10242   for(std::size_t i=0;i<_fields.size();i++)
10243     if(b[i])
10244       fields[j++]=_fields[i];
10245   _fields=fields;
10246 }
10247
10248 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10249 {
10250   bool ret=false;
10251   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10252     {
10253       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10254       if(cur)
10255         ret=cur->changeMeshNames(modifTab) || ret;
10256     }
10257   return ret;
10258 }
10259
10260 /*!
10261  * \param [in] meshName the name of the mesh that will be renumbered.
10262  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10263  *             This code corresponds to the distribution of types in the corresponding mesh.
10264  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10265  * \param [in] renumO2N the old to new renumber array.
10266  * \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 
10267  *         field in \a this.
10268  */
10269 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10270 {
10271   bool ret=false;
10272   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10273     {
10274       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10275       if(fmts)
10276         {
10277           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10278         }
10279     }
10280   return ret;
10281 }
10282
10283 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10284 {
10285   if(i<0 || i>=(int)_fields.size())
10286     {
10287       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10288       throw INTERP_KERNEL::Exception(oss.str().c_str());
10289     }
10290   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10291   if(!fmts)
10292     return 0;
10293   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
10294   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
10295   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
10296   if(fmtsC)
10297     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10298   else if(fmtsC2)
10299     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10300   else
10301     {
10302       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10303       throw INTERP_KERNEL::Exception(oss.str().c_str());
10304     }
10305   ret->shallowCpyGlobs(*this);
10306   return ret.retn();
10307 }
10308
10309 /*!
10310  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10311  * This method is accessible in python using __getitem__ with a list in input.
10312  * \return a new object that the caller should deal with.
10313  */
10314 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10315 {
10316   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
10317   std::size_t sz=std::distance(startIds,endIds);
10318   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10319   int j=0;
10320   for(const int *i=startIds;i!=endIds;i++,j++)
10321     {
10322       if(*i<0 || *i>=(int)_fields.size())
10323         {
10324           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10325           throw INTERP_KERNEL::Exception(oss.str().c_str());
10326         }
10327       fields[j]=_fields[*i];
10328     }
10329   ret->_fields=fields;
10330   return ret.retn();
10331 }
10332
10333 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10334 {
10335   return getFieldAtPos(getPosFromFieldName(fieldName));
10336 }
10337
10338 /*!
10339  * This method removes, if any, fields in \a this having no time steps.
10340  * If there is one or more than one such field in \a this true is returned and those fields will not be referenced anymore in \a this.
10341  * 
10342  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10343  */
10344 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10345 {
10346   std::vector<MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10347   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10348     {
10349       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10350       if(elt)
10351         {
10352           if(elt->getNumberOfTS()>0)
10353             newFields.push_back(*it);
10354         }
10355     }
10356   if(_fields.size()==newFields.size())
10357     return false;
10358   _fields=newFields;
10359   return true;
10360 }
10361
10362 /*!
10363  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10364  * This method can be seen as a filter applied on \a this, that returns an object containing
10365  * 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
10366  * shallow copied from \a this.
10367  * 
10368  * \param [in] meshName - the name of the mesh on w
10369  * \return a new object that the caller should deal with.
10370  */
10371 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10372 {
10373   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10374   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10375     {
10376       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10377       if(!cur)
10378         continue;
10379       if(cur->getMeshName()==meshName)
10380         {
10381           cur->incrRef();
10382           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10383           ret->_fields.push_back(cur2);
10384         }
10385     }
10386   ret->shallowCpyOnlyUsedGlobs(*this);
10387   return ret.retn();
10388 }
10389
10390 /*!
10391  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10392  * Input time steps are specified using a pair of integer (iteration, order).
10393  * 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,
10394  * but for each multitimestep only the time steps in \a timeSteps are kept.
10395  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10396  * 
10397  * The returned object points to shallow copy of elements in \a this.
10398  * 
10399  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10400  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10401  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10402  */
10403 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10404 {
10405   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10406   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10407     {
10408       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10409       if(!cur)
10410         continue;
10411       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10412       ret->_fields.push_back(elt);
10413     }
10414   ret->shallowCpyOnlyUsedGlobs(*this);
10415   return ret.retn();
10416 }
10417
10418 /*!
10419  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10420  */
10421 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10422 {
10423   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10424   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10425     {
10426       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10427       if(!cur)
10428         continue;
10429       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10430       if(elt->getNumberOfTS()!=0)
10431         ret->_fields.push_back(elt);
10432     }
10433   ret->shallowCpyOnlyUsedGlobs(*this);
10434   return ret.retn();
10435 }
10436
10437 MEDFileFieldsIterator *MEDFileFields::iterator()
10438 {
10439   return new MEDFileFieldsIterator(this);
10440 }
10441
10442 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10443 {
10444   std::string tmp(fieldName);
10445   std::vector<std::string> poss;
10446   for(std::size_t i=0;i<_fields.size();i++)
10447     {
10448       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10449       if(f)
10450         {
10451           std::string fname(f->getName());
10452           if(tmp==fname)
10453             return i;
10454           else
10455             poss.push_back(fname);
10456         }
10457     }
10458   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10459   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10460   oss << " !";
10461   throw INTERP_KERNEL::Exception(oss.str().c_str());
10462 }
10463
10464 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10465 {
10466   if(fs)
10467     {
10468       fs->incrRef();
10469       _nb_iter=fs->getNumberOfFields();
10470     }
10471 }
10472
10473 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10474 {
10475 }
10476
10477 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10478 {
10479   if(_iter_id<_nb_iter)
10480     {
10481       MEDFileFields *fs(_fs);
10482       if(fs)
10483         return fs->getFieldAtPos(_iter_id++);
10484       else
10485         return 0;
10486     }
10487   else
10488     return 0;
10489 }