Salome HOME
Initiating medtool
[modules/med.git] / src / medtool / 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 /// @endcond
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 /// @cond INTERNAL
2946 namespace ParaMEDMEMImpl
2947 {
2948   class LocFinder
2949   {
2950   public:
2951     LocFinder(const std::string& loc):_loc(loc) { }
2952     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2953   private:
2954     const std::string &_loc;
2955   };
2956
2957   class PflFinder
2958   {
2959   public:
2960     PflFinder(const std::string& pfl):_pfl(pfl) { }
2961     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2962   private:
2963     const std::string& _pfl;
2964   };
2965 }
2966 /// @endcond
2967
2968 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2969 {
2970   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2971   if(it==_locs.end())
2972     {
2973       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2974       for(it=_locs.begin();it!=_locs.end();it++)
2975         oss << "\"" << (*it)->getName() << "\", ";
2976       throw INTERP_KERNEL::Exception(oss.str().c_str());
2977     }
2978   return std::distance(_locs.begin(),it);
2979 }
2980
2981 /*!
2982  * The returned value is never null.
2983  */
2984 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2985 {
2986   std::string pflNameCpp(pflName);
2987   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2988   if(it==_pfls.end())
2989     {
2990       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2991       for(it=_pfls.begin();it!=_pfls.end();it++)
2992         oss << "\"" << (*it)->getName() << "\", ";
2993       throw INTERP_KERNEL::Exception(oss.str().c_str());
2994     }
2995   return *it;
2996 }
2997
2998 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2999 {
3000   if(pflId<0 || pflId>=(int)_pfls.size())
3001     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3002   return _pfls[pflId];
3003 }
3004
3005 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3006 {
3007   if(locId<0 || locId>=(int)_locs.size())
3008     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3009   return *_locs[locId];
3010 }
3011
3012 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3013 {
3014   return getLocalizationFromId(getLocalizationId(locName));
3015 }
3016
3017 /*!
3018  * The returned value is never null.
3019  */
3020 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3021 {
3022   std::string pflNameCpp(pflName);
3023   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
3024   if(it==_pfls.end())
3025     {
3026       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3027       for(it=_pfls.begin();it!=_pfls.end();it++)
3028         oss << "\"" << (*it)->getName() << "\", ";
3029       throw INTERP_KERNEL::Exception(oss.str().c_str());
3030     }
3031   return *it;
3032 }
3033
3034 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3035 {
3036   if(pflId<0 || pflId>=(int)_pfls.size())
3037     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3038   return _pfls[pflId];
3039 }
3040
3041 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3042 {
3043   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
3044   int i=0;
3045   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3046     {
3047       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3048         newPfls.push_back(*it);
3049     }
3050   _pfls=newPfls;
3051 }
3052
3053 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3054 {
3055   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
3056   int i=0;
3057   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3058     {
3059       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3060         newLocs.push_back(*it);
3061     }
3062   _locs=newLocs;
3063 }
3064
3065 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3066 {
3067   int sz=_pfls.size();
3068   std::vector<std::string> ret(sz);
3069   for(int i=0;i<sz;i++)
3070     ret[i]=_pfls[i]->getName();
3071   return ret;
3072 }
3073
3074 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3075 {
3076   int sz=_locs.size();
3077   std::vector<std::string> ret(sz);
3078   for(int i=0;i<sz;i++)
3079     ret[i]=_locs[i]->getName();
3080   return ret;
3081 }
3082
3083 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3084 {
3085   std::vector<std::string> v=getPfls();
3086   std::string s(pflName);
3087   return std::find(v.begin(),v.end(),s)!=v.end();
3088 }
3089
3090 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3091 {
3092   std::vector<std::string> v=getLocs();
3093   std::string s(locName);
3094   return std::find(v.begin(),v.end(),s)!=v.end();
3095 }
3096
3097 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3098 {
3099   std::map<int,std::vector<int> > m;
3100   int i=0;
3101   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3102     {
3103       const DataArrayInt *tmp=(*it);
3104       if(tmp)
3105         {
3106           m[tmp->getHashCode()].push_back(i);
3107         }
3108     }
3109   std::vector< std::vector<int> > ret;
3110   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3111     {
3112       if((*it2).second.size()>1)
3113         {
3114           std::vector<int> ret0;
3115           bool equalityOrNot=false;
3116           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3117             {
3118               std::vector<int>::const_iterator it4=it3; it4++;
3119               for(;it4!=(*it2).second.end();it4++)
3120                 {
3121                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3122                     {
3123                       if(!equalityOrNot)
3124                         ret0.push_back(*it3);
3125                       ret0.push_back(*it4);
3126                       equalityOrNot=true;
3127                     }
3128                 }
3129             }
3130           if(!ret0.empty())
3131             ret.push_back(ret0);
3132         }
3133     }
3134   return ret;
3135 }
3136
3137 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3138 {
3139   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3140 }
3141
3142 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3143 {
3144   std::string name(pfl->getName());
3145   if(name.empty())
3146     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3147   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3148     if(name==(*it)->getName())
3149       {
3150         if(!pfl->isEqual(*(*it)))
3151           {
3152             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3153             throw INTERP_KERNEL::Exception(oss.str().c_str());
3154           }
3155       }
3156   pfl->incrRef();
3157   _pfls.push_back(pfl);
3158 }
3159
3160 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)
3161 {
3162   std::string name(locName);
3163   if(name.empty())
3164     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3165   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3166   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3167     if((*it)->isName(locName))
3168       {
3169         if(!(*it)->isEqual(*obj,1e-12))
3170           {
3171             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3172             throw INTERP_KERNEL::Exception(oss.str().c_str());
3173           }
3174       }
3175   _locs.push_back(obj);
3176 }
3177
3178 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3179 {
3180   std::vector<std::string> names=getPfls();
3181   return CreateNewNameNotIn("NewPfl_",names);
3182 }
3183
3184 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3185 {
3186   std::vector<std::string> names=getLocs();
3187   return CreateNewNameNotIn("NewLoc_",names);
3188 }
3189
3190 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3191 {
3192   for(std::size_t sz=0;sz<100000;sz++)
3193     {
3194       std::ostringstream tryName;
3195       tryName << prefix << sz;
3196       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3197         return tryName.str();
3198     }
3199   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3200 }
3201
3202 /*!
3203  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3204  *  \param [in] fname - the file name.
3205  */
3206 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
3207 {
3208 }
3209
3210 /*!
3211  * Creates an empty MEDFileFieldGlobsReal.
3212  */
3213 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3214 {
3215 }
3216
3217 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3218 {
3219   return 0;
3220 }
3221
3222 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3223 {
3224   std::vector<const BigMemoryObject *> ret;
3225   ret.push_back((const MEDFileFieldGlobs *)_globals);
3226   return ret;
3227 }
3228
3229 /*!
3230  * Returns a string describing profiles and Gauss points held in \a this.
3231  *  \return std::string - the description string.
3232  */
3233 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3234 {
3235   const MEDFileFieldGlobs *glob=_globals;
3236   std::ostringstream oss2; oss2 << glob;
3237   std::string stars(oss2.str().length(),'*');
3238   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3239   if(glob)
3240     glob->simpleRepr(oss);
3241   else
3242     oss << "NO GLOBAL INFORMATION !\n";
3243 }
3244
3245 void MEDFileFieldGlobsReal::resetContent()
3246 {
3247   _globals=MEDFileFieldGlobs::New();
3248 }
3249
3250 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3251 {
3252 }
3253
3254 /*!
3255  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3256  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3257  */
3258 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3259 {
3260   _globals=other._globals;
3261 }
3262
3263 /*!
3264  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3265  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3266  */
3267 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3268 {
3269   const MEDFileFieldGlobs *otherg(other._globals);
3270   if(!otherg)
3271     return ;
3272   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3273 }
3274
3275 /*!
3276  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3277  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3278  */
3279 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3280 {
3281   const MEDFileFieldGlobs *otherg(other._globals);
3282   if(!otherg)
3283     return ;
3284   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3285 }
3286
3287 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3288 {
3289   _globals=other._globals;
3290   if((const MEDFileFieldGlobs *)_globals)
3291     _globals=other._globals->deepCpy();
3292 }
3293
3294 /*!
3295  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3296  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3297  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3298  *         \a this and \a other MEDFileFieldGlobsReal.
3299  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3300  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3301  */
3302 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3303 {
3304   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3305   if(thisGlobals==otherGlobals)
3306     return ;
3307   if(!thisGlobals)
3308     {
3309       _globals=other._globals;
3310       return ;
3311     }
3312   _globals->appendGlobs(*other._globals,eps);
3313 }
3314
3315 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3316 {
3317   checkGlobsPflsPartCoherency();
3318   checkGlobsLocsPartCoherency();
3319 }
3320
3321 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3322 {
3323   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3324 }
3325
3326 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3327 {
3328   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3329 }
3330
3331 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3332 {
3333   contentNotNull()->loadProfileInFile(fid,id,pflName);
3334 }
3335
3336 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3337 {
3338   contentNotNull()->loadProfileInFile(fid,id);
3339 }
3340
3341 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3342 {
3343   contentNotNull()->loadGlobals(fid,*this);
3344 }
3345
3346 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3347 {
3348   contentNotNull()->loadAllGlobals(fid);
3349 }
3350
3351 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3352 {
3353   contentNotNull()->writeGlobals(fid,opt);
3354 }
3355
3356 /*!
3357  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3358  * or getPflsReallyUsedMulti().
3359  *  \return std::vector<std::string> - a sequence of names of all profiles.
3360  */
3361 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3362 {
3363   return contentNotNull()->getPfls();
3364 }
3365
3366 /*!
3367  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3368  * or getLocsReallyUsedMulti().
3369  *  \return std::vector<std::string> - a sequence of names of all localizations.
3370  */
3371 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3372 {
3373   return contentNotNull()->getLocs();
3374 }
3375
3376 /*!
3377  * Checks if the profile with a given name exists.
3378  *  \param [in] pflName - the profile name of interest.
3379  *  \return bool - \c true if the profile named \a pflName exists.
3380  */
3381 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3382 {
3383   return contentNotNull()->existsPfl(pflName);
3384 }
3385
3386 /*!
3387  * Checks if the localization with a given name exists.
3388  *  \param [in] locName - the localization name of interest.
3389  *  \return bool - \c true if the localization named \a locName exists.
3390  */
3391 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3392 {
3393   return contentNotNull()->existsLoc(locName);
3394 }
3395
3396 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3397 {
3398   return contentNotNull()->createNewNameOfPfl();
3399 }
3400
3401 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3402 {
3403   return contentNotNull()->createNewNameOfLoc();
3404 }
3405
3406 /*!
3407  * Sets the name of a MED file.
3408  *  \param [inout] fileName - the file name.
3409  */
3410 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3411 {
3412   contentNotNull()->setFileName(fileName);
3413 }
3414
3415 /*!
3416  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3417  * in the same order.
3418  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3419  *          Each item of this sequence is a vector containing ids of equal profiles.
3420  */
3421 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3422 {
3423   return contentNotNull()->whichAreEqualProfiles();
3424 }
3425
3426 /*!
3427  * Finds equal localizations.
3428  *  \param [in] eps - a precision used to compare real values of the localizations.
3429  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3430  *          Each item of this sequence is a vector containing ids of equal localizations.
3431  */
3432 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3433 {
3434   return contentNotNull()->whichAreEqualLocs(eps);
3435 }
3436
3437 /*!
3438  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3439  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3440  *        this sequence is a pair whose 
3441  *        - the first item is a vector of profile names to replace by the second item,
3442  *        - the second item is a profile name to replace every profile name of the first item.
3443  */
3444 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3445 {
3446   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3447 }
3448
3449 /*!
3450  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3451  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3452  *        this sequence is a pair whose 
3453  *        - the first item is a vector of localization names to replace by the second item,
3454  *        - the second item is a localization name to replace every localization name of the first item.
3455  */
3456 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3457 {
3458   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3459 }
3460
3461 /*!
3462  * Replaces references to some profiles (a reference is a profile name) by references
3463  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3464  * them-selves accordingly. <br>
3465  * This method is a generalization of changePflName().
3466  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3467  *        this sequence is a pair whose 
3468  *        - the first item is a vector of profile names to replace by the second item,
3469  *        - the second item is a profile name to replace every profile of the first item.
3470  * \sa changePflsRefsNamesGen()
3471  * \sa changePflName()
3472  */
3473 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3474 {
3475   changePflsRefsNamesGen(mapOfModif);
3476   changePflsNamesInStruct(mapOfModif);
3477 }
3478
3479 /*!
3480  * Replaces references to some localizations (a reference is a localization name) by references
3481  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3482  * them-selves accordingly. <br>
3483  * This method is a generalization of changeLocName().
3484  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3485  *        this sequence is a pair whose 
3486  *        - the first item is a vector of localization names to replace by the second item,
3487  *        - the second item is a localization name to replace every localization of the first item.
3488  * \sa changeLocsRefsNamesGen()
3489  * \sa changeLocName()
3490  */
3491 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3492 {
3493   changeLocsRefsNamesGen(mapOfModif);
3494   changeLocsNamesInStruct(mapOfModif);
3495 }
3496
3497 /*!
3498  * Renames the profile having a given name and updates references to this profile.
3499  *  \param [in] oldName - the name of the profile to rename.
3500  *  \param [in] newName - a new name of the profile.
3501  * \sa changePflsNames().
3502  */
3503 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3504 {
3505   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3506   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3507   mapOfModif[0]=p;
3508   changePflsNames(mapOfModif);
3509 }
3510
3511 /*!
3512  * Renames the localization having a given name and updates references to this localization.
3513  *  \param [in] oldName - the name of the localization to rename.
3514  *  \param [in] newName - a new name of the localization.
3515  * \sa changeLocsNames().
3516  */
3517 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3518 {
3519   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3520   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3521   mapOfModif[0]=p;
3522   changeLocsNames(mapOfModif);
3523 }
3524
3525 /*!
3526  * Removes duplicated profiles. Returns a map used to update references to removed 
3527  * profiles via changePflsRefsNamesGen().
3528  * Equal profiles are found using whichAreEqualProfiles().
3529  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3530  *          a sequence describing the performed replacements of profiles. Each element of
3531  *          this sequence is a pair whose
3532  *          - the first item is a vector of profile names replaced by the second item,
3533  *          - the second item is a profile name replacing every profile of the first item.
3534  */
3535 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3536 {
3537   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3538   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3539   int i=0;
3540   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3541     {
3542       std::vector< std::string > tmp((*it).size());
3543       int j=0;
3544       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3545         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3546       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3547       ret[i]=p;
3548       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3549       killProfileIds(tmp2);
3550     }
3551   changePflsRefsNamesGen(ret);
3552   return ret;
3553 }
3554
3555 /*!
3556  * Removes duplicated localizations. Returns a map used to update references to removed 
3557  * localizations via changeLocsRefsNamesGen().
3558  * Equal localizations are found using whichAreEqualLocs().
3559  *  \param [in] eps - a precision used to compare real values of the localizations.
3560  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3561  *          a sequence describing the performed replacements of localizations. Each element of
3562  *          this sequence is a pair whose
3563  *          - the first item is a vector of localization names replaced by the second item,
3564  *          - the second item is a localization name replacing every localization of the first item.
3565  */
3566 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3567 {
3568   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3569   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3570   int i=0;
3571   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3572     {
3573       std::vector< std::string > tmp((*it).size());
3574       int j=0;
3575       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3576         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3577       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3578       ret[i]=p;
3579       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3580       killLocalizationIds(tmp2);
3581     }
3582   changeLocsRefsNamesGen(ret);
3583   return ret;
3584 }
3585
3586 /*!
3587  * Returns number of Gauss points per cell in a given localization.
3588  *  \param [in] locId - an id of the localization of interest.
3589  *  \return int - the number of the Gauss points per cell.
3590  */
3591 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3592 {
3593   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3594 }
3595
3596 /*!
3597  * Returns an id of a localization by its name.
3598  *  \param [in] loc - the localization name of interest.
3599  *  \return int - the id of the localization.
3600  *  \throw If there is no a localization named \a loc.
3601  */
3602 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3603 {
3604   return contentNotNull()->getLocalizationId(loc);
3605 }
3606
3607 /*!
3608  * Returns the name of the MED file.
3609  *  \return const std::string&  - the MED file name.
3610  */
3611 std::string MEDFileFieldGlobsReal::getFileName() const
3612 {
3613   return contentNotNull()->getFileName();
3614 }
3615
3616 /*!
3617  * Returns a localization object by its name.
3618  *  \param [in] locName - the name of the localization of interest.
3619  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3620  *  \throw If there is no a localization named \a locName.
3621  */
3622 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3623 {
3624   return contentNotNull()->getLocalization(locName);
3625 }
3626
3627 /*!
3628  * Returns a localization object by its id.
3629  *  \param [in] locId - the id of the localization of interest.
3630  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3631  *  \throw If there is no a localization with id \a locId.
3632  */
3633 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3634 {
3635   return contentNotNull()->getLocalizationFromId(locId);
3636 }
3637
3638 /*!
3639  * Returns a profile array by its name.
3640  *  \param [in] pflName - the name of the profile of interest.
3641  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3642  *  \throw If there is no a profile named \a pflName.
3643  */
3644 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3645 {
3646   return contentNotNull()->getProfile(pflName);
3647 }
3648
3649 /*!
3650  * Returns a profile array by its id.
3651  *  \param [in] pflId - the id of the profile of interest.
3652  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3653  *  \throw If there is no a profile with id \a pflId.
3654  */
3655 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3656 {
3657   return contentNotNull()->getProfileFromId(pflId);
3658 }
3659
3660 /*!
3661  * Returns a localization object, apt for modification, by its id.
3662  *  \param [in] locId - the id of the localization of interest.
3663  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3664  *          having the id \a locId.
3665  *  \throw If there is no a localization with id \a locId.
3666  */
3667 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3668 {
3669   return contentNotNull()->getLocalizationFromId(locId);
3670 }
3671
3672 /*!
3673  * Returns a localization object, apt for modification, by its name.
3674  *  \param [in] locName - the name of the localization of interest.
3675  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3676  *          having the name \a locName.
3677  *  \throw If there is no a localization named \a locName.
3678  */
3679 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3680 {
3681   return contentNotNull()->getLocalization(locName);
3682 }
3683
3684 /*!
3685  * Returns a profile array, apt for modification, by its name.
3686  *  \param [in] pflName - the name of the profile of interest.
3687  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3688  *  \throw If there is no a profile named \a pflName.
3689  */
3690 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3691 {
3692   return contentNotNull()->getProfile(pflName);
3693 }
3694
3695 /*!
3696  * Returns a profile array, apt for modification, by its id.
3697  *  \param [in] pflId - the id of the profile of interest.
3698  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3699  *  \throw If there is no a profile with id \a pflId.
3700  */
3701 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3702 {
3703   return contentNotNull()->getProfileFromId(pflId);
3704 }
3705
3706 /*!
3707  * Removes profiles given by their ids. No data is updated to track this removal.
3708  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3709  */
3710 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3711 {
3712   contentNotNull()->killProfileIds(pflIds);
3713 }
3714
3715 /*!
3716  * Removes localizations given by their ids. No data is updated to track this removal.
3717  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3718  */
3719 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3720 {
3721   contentNotNull()->killLocalizationIds(locIds);
3722 }
3723
3724 /*!
3725  * Stores a profile array.
3726  *  \param [in] pfl - the profile array to store.
3727  *  \throw If the name of \a pfl is empty.
3728  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3729  *         different ids.
3730  */
3731 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3732 {
3733   contentNotNull()->appendProfile(pfl);
3734 }
3735
3736 /*!
3737  * Adds a new localization of Gauss points.
3738  *  \param [in] locName - the name of the new localization.
3739  *  \param [in] geoType - a geometrical type of the reference cell.
3740  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3741  *         must be \c nbOfNodesPerCell * \c dimOfType.
3742  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3743  *         must be  _wg_.size() * \c dimOfType.
3744  *  \param [in] w - the weights of Gauss points.
3745  *  \throw If \a locName is empty.
3746  *  \throw If a localization with the name \a locName already exists but is
3747  *         different form the new one.
3748  */
3749 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)
3750 {
3751   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3752 }
3753
3754 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3755 {
3756   MEDFileFieldGlobs *g(_globals);
3757   if(!g)
3758     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3759   return g;
3760 }
3761
3762 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3763 {
3764   const MEDFileFieldGlobs *g(_globals);
3765   if(!g)
3766     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3767   return g;
3768 }
3769
3770 //= MEDFileFieldNameScope
3771
3772 MEDFileFieldNameScope::MEDFileFieldNameScope()
3773 {
3774 }
3775
3776 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3777 {
3778 }
3779
3780 /*!
3781  * Returns the name of \a this field.
3782  *  \return std::string - a string containing the field name.
3783  */
3784 std::string MEDFileFieldNameScope::getName() const
3785 {
3786   return _name;
3787 }
3788
3789 /*!
3790  * Sets name of \a this field
3791  *  \param [in] name - the new field name.
3792  */
3793 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3794 {
3795   _name=fieldName;
3796 }
3797
3798 std::string MEDFileFieldNameScope::getDtUnit() const
3799 {
3800   return _dt_unit;
3801 }
3802
3803 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3804 {
3805   _dt_unit=dtUnit;
3806 }
3807
3808 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3809 {
3810   _name=other._name;
3811   _dt_unit=other._dt_unit;
3812 }
3813
3814 //= MEDFileAnyTypeField1TSWithoutSDA
3815
3816 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3817 {
3818   _field_per_mesh.resize(other._field_per_mesh.size());
3819   std::size_t i=0;
3820   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3821     {
3822       if((const MEDFileFieldPerMesh *)*it)
3823         _field_per_mesh[i]=(*it)->deepCpy(this);
3824     }
3825 }
3826
3827 /*!
3828  * Prints a string describing \a this field into a stream. This string is outputted 
3829  * by \c print Python command.
3830  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3831  *  \param [in,out] oss - the out stream.
3832  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3833  *          info id printed, else, not.
3834  */
3835 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3836 {
3837   std::string startOfLine(bkOffset,' ');
3838   oss << startOfLine << "Field ";
3839   if(bkOffset==0)
3840     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3841   oss << "on one time Step ";
3842   if(f1tsId>=0)
3843     oss << "(" << f1tsId << ") ";
3844   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3845   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3846   const DataArray *arr=getUndergroundDataArray();
3847   if(arr)
3848     {
3849       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3850       if(f1tsId<0)
3851         {
3852           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3853           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3854             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3855         }
3856       if(arr->isAllocated())
3857         {
3858           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3859         }
3860       else
3861         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3862     }
3863   else
3864     {
3865       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3866     }
3867   oss << startOfLine << "----------------------" << std::endl;
3868   if(!_field_per_mesh.empty())
3869     {
3870       int i=0;
3871       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3872         {
3873           const MEDFileFieldPerMesh *cur=(*it2);
3874           if(cur)
3875             cur->simpleRepr(bkOffset,oss,i);
3876           else
3877             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3878         }
3879     }
3880   else
3881     {
3882       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3883     }
3884   oss << startOfLine << "----------------------" << std::endl;
3885 }
3886
3887 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3888 {
3889   const DataArray *arr(getUndergroundDataArray());
3890   if(!arr)
3891     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3892   int nbOfCompo=arr->getNumberOfComponents();
3893   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3894   for(int i=0;i<nbOfCompo;i++)
3895     {
3896       ret[i]=deepCpy();
3897       std::vector<int> v(1,i);
3898       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3899       ret[i]->setArray(arr2);
3900     }
3901   return ret;
3902 }
3903
3904 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)
3905 {
3906 }
3907
3908 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3909 {
3910 }
3911
3912 /*!
3913  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3914  * empty. Returns -1 if this in on nodes.
3915  *  \return int - the dimension of \a this.
3916  */
3917 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3918 {
3919   int ret=-2;
3920   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3921     (*it)->getDimension(ret);
3922   return ret;
3923 }
3924
3925 /*!
3926  * Returns the mesh name.
3927  *  \return std::string - a string holding the mesh name.
3928  *  \throw If \c _field_per_mesh.empty()
3929  */
3930 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3931 {
3932   if(_field_per_mesh.empty())
3933     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3934   return _field_per_mesh[0]->getMeshName();
3935 }
3936
3937 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3938 {
3939   std::string oldName(getMeshName());
3940   std::vector< std::pair<std::string,std::string> > v(1);
3941   v[0].first=oldName; v[0].second=newMeshName;
3942   changeMeshNames(v);
3943 }
3944
3945 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3946 {
3947   bool ret=false;
3948   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3949     {
3950       MEDFileFieldPerMesh *cur(*it);
3951       if(cur)
3952         ret=cur->changeMeshNames(modifTab) || ret;
3953     }
3954   return ret;
3955 }
3956
3957 /*!
3958  * Returns the number of iteration of the state of underlying mesh.
3959  *  \return int - the iteration number.
3960  *  \throw If \c _field_per_mesh.empty()
3961  */
3962 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3963 {
3964   if(_field_per_mesh.empty())
3965     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3966   return _field_per_mesh[0]->getMeshIteration();
3967 }
3968
3969 /*!
3970  * Returns the order number of iteration of the state of underlying mesh.
3971  *  \return int - the order number.
3972  *  \throw If \c _field_per_mesh.empty()
3973  */
3974 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3975 {
3976   if(_field_per_mesh.empty())
3977     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3978   return _field_per_mesh[0]->getMeshOrder();
3979 }
3980
3981 /*!
3982  * Checks if \a this field is tagged by a given iteration number and a given
3983  * iteration order number.
3984  *  \param [in] iteration - the iteration number of interest.
3985  *  \param [in] order - the iteration order number of interest.
3986  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3987  *          \a this->getOrder() == \a order.
3988  */
3989 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3990 {
3991   return iteration==_iteration && order==_order;
3992 }
3993
3994 /*!
3995  * Returns number of iteration and order number of iteration when
3996  * \a this field has been calculated.
3997  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3998  *          order number.
3999  */
4000 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4001 {
4002   std::pair<int,int> p;
4003   fillIteration(p);
4004   return p;
4005 }
4006
4007 /*!
4008  * Returns number of iteration and order number of iteration when
4009  * \a this field has been calculated.
4010  *  \param [in,out] p - a pair returning the iteration number and the iteration
4011  *          order number.
4012  */
4013 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4014 {
4015   p.first=_iteration;
4016   p.second=_order;
4017 }
4018
4019 /*!
4020  * Returns all types of spatial discretization of \a this field.
4021  *  \param [in,out] types - a sequence of types of \a this field.
4022  */
4023 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4024 {
4025   std::set<TypeOfField> types2;
4026   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4027     {
4028       (*it)->fillTypesOfFieldAvailable(types2);
4029     }
4030   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4031   std::copy(types2.begin(),types2.end(),bi);
4032 }
4033
4034 /*!
4035  * Returns all types of spatial discretization of \a this field.
4036  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4037  *          of \a this field.
4038  */
4039 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4040 {
4041   std::vector<TypeOfField> ret;
4042   fillTypesOfFieldAvailable(ret);
4043   return ret;
4044 }
4045
4046 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4047 {
4048   std::vector<std::string> ret;
4049   std::set<std::string> ret2;
4050   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4051     {
4052       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4053       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4054         if(ret2.find(*it2)==ret2.end())
4055           {
4056             ret.push_back(*it2);
4057             ret2.insert(*it2);
4058           }
4059     }
4060   return ret;
4061 }
4062
4063 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4064 {
4065   std::vector<std::string> ret;
4066   std::set<std::string> ret2;
4067   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4068     {
4069       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4070       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4071         if(ret2.find(*it2)==ret2.end())
4072           {
4073             ret.push_back(*it2);
4074             ret2.insert(*it2);
4075           }
4076     }
4077   return ret;
4078 }
4079
4080 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4081 {
4082   std::vector<std::string> ret;
4083   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4084     {
4085       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4086       ret.insert(ret.end(),tmp.begin(),tmp.end());
4087     }
4088   return ret;
4089 }
4090
4091 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4092 {
4093   std::vector<std::string> ret;
4094   std::set<std::string> ret2;
4095   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4096     {
4097       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4098       ret.insert(ret.end(),tmp.begin(),tmp.end());
4099     }
4100   return ret;
4101 }
4102
4103 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4104 {
4105   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4106     (*it)->changePflsRefsNamesGen(mapOfModif);
4107 }
4108
4109 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4110 {
4111   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4112     (*it)->changeLocsRefsNamesGen(mapOfModif);
4113 }
4114
4115 /*!
4116  * Returns all attributes of parts of \a this field lying on a given mesh.
4117  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4118  * item of every of returned sequences refers to the _i_-th part of \a this field.
4119  * Thus all sequences returned by this method are of the same length equal to number
4120  * of different types of supporting entities.<br>
4121  * A field part can include sub-parts with several different spatial discretizations,
4122  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4123  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4124  * of a nested sequence corresponds to a type of spatial discretization.<br>
4125  * This method allows for iteration over MEDFile DataStructure without any overhead.
4126  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4127  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4128  *          not checked if \a mname == \c NULL).
4129  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4130  *          a field part is returned. 
4131  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4132  *          This sequence is of the same length as \a types. 
4133  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4134  *          discretization. A profile name can be empty.
4135  *          Length of this and of nested sequences is the same as that of \a typesF.
4136  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4137  *          discretization. A localization name can be empty.
4138  *          Length of this and of nested sequences is the same as that of \a typesF.
4139  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4140  *          of ids of tuples within the data array, per each type of spatial
4141  *          discretization within one mesh entity type. 
4142  *          Length of this and of nested sequences is the same as that of \a typesF.
4143  *  \throw If no field is lying on \a mname.
4144  */
4145 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
4146 {
4147   int meshId=0;
4148   if(!mname.empty())
4149     meshId=getMeshIdFromMeshName(mname);
4150   else
4151     if(_field_per_mesh.empty())
4152       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4153   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4154 }
4155
4156 /*!
4157  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4158  * maximal absolute dimension and values returned via the out parameter \a levs are 
4159  * dimensions relative to the maximal absolute dimension. <br>
4160  * This method is designed for MEDFileField1TS instances that have a discretization
4161  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
4162  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
4163  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
4164  * Only these 3 discretizations will be taken into account here. If \a this is
4165  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4166  * This method is useful to make the link between the dimension of the underlying mesh
4167  * and the levels of \a this, because it is possible that the highest dimension of \a this
4168  * field is not equal to the dimension of the underlying mesh.
4169  * 
4170  * Let's consider the following case:
4171  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4172  * TETRA4, HEXA8, TRI3 and SEG2.
4173  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4174  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4175  *
4176  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4177  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4178  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4179  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4180  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4181  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4182  * For example<br>
4183  * to retrieve the highest level of
4184  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4185  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4186  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4187  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4188  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4189  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4190  *          not checked if \a mname == \c NULL).
4191  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4192  *          absolute one. They are in decreasing order. This sequence is cleared before
4193  *          filling it in.
4194  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4195  *  \throw If no field is lying on \a mname.
4196  */
4197 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4198 {
4199   levs.clear();
4200   int meshId=getMeshIdFromMeshName(mname);
4201   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4202   std::vector< std::vector<TypeOfField> > typesF;
4203   std::vector< std::vector<std::string> > pfls, locs;
4204   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4205   if(types.empty())
4206     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4207   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4208   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4209     return -1;
4210   st.erase(INTERP_KERNEL::NORM_ERROR);
4211   std::set<int> ret1;
4212   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4213     {
4214       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4215       ret1.insert((int)cm.getDimension());
4216     }
4217   int ret=*std::max_element(ret1.begin(),ret1.end());
4218   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4219   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4220   return ret;
4221 }
4222
4223 /*!
4224  * \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.
4225  * \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.
4226  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4227  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4228  */
4229 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4230 {
4231   int mid=getMeshIdFromMeshName(mName);
4232   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4233 }
4234
4235 /*!
4236  * \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.
4237  * \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.
4238  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4239  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4240  */
4241 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4242 {
4243   int mid=getMeshIdFromMeshName(mName);
4244   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4245 }
4246
4247 /*!
4248  * \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.
4249  */
4250 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4251 {
4252   if(_field_per_mesh.empty())
4253     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4254   if(mName.empty())
4255     return 0;
4256   std::string mName2(mName);
4257   int ret=0;
4258   std::vector<std::string> msg;
4259   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4260     if(mName2==(*it)->getMeshName())
4261       return ret;
4262     else
4263       msg.push_back((*it)->getMeshName());
4264   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4265   oss << "Possible meshes are : ";
4266   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4267     oss << "\"" << (*it2) << "\" ";
4268   throw INTERP_KERNEL::Exception(oss.str().c_str());
4269 }
4270
4271 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4272 {
4273   if(!mesh)
4274     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4275   std::string tmp(mesh->getName());
4276   if(tmp.empty())
4277     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4278   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4279   int i=0;
4280   for(;it!=_field_per_mesh.end();it++,i++)
4281     {
4282       if((*it)->getMeshName()==tmp)
4283         return i;
4284     }
4285   int sz=_field_per_mesh.size();
4286   _field_per_mesh.resize(sz+1);
4287   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4288   return sz;
4289 }
4290
4291 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4292                                                                    MEDFileFieldGlobsReal& glob)
4293 {
4294   bool ret=false;
4295   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4296     {
4297       MEDFileFieldPerMesh *fpm(*it);
4298       if(fpm)
4299         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4300     }
4301   return ret;
4302 }
4303
4304 /*!
4305  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4306  * splitting that leads to single spatial discretization of this.
4307  *
4308  * \sa splitMultiDiscrPerGeoTypes
4309  */
4310 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4311 {
4312   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4313   std::vector< std::vector<TypeOfField> > typesF;
4314   std::vector< std::vector<std::string> > pfls,locs;
4315   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4316   std::set<TypeOfField> allEnt;
4317   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4318     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4319       allEnt.insert(*it2);
4320   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4321   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4322   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4323     {
4324       std::vector< std::pair<int,int> > its;
4325       ret[i]=shallowCpy();
4326       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4327       ret[i]->updateData(newLgth,its);
4328     }
4329   return ret;
4330 }
4331
4332 /*!
4333  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4334  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4335  *
4336  * \sa splitDiscretizations
4337  */
4338 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4339 {
4340   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4341   std::vector< std::vector<TypeOfField> > typesF;
4342   std::vector< std::vector<std::string> > pfls,locs;
4343   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4344   std::set<TypeOfField> allEnt;
4345   std::size_t nbOfMDPGT(0),ii(0);
4346   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4347     {
4348       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4349       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4350         allEnt.insert(*it2);
4351     }
4352   if(allEnt.size()!=1)
4353     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4354   if(nbOfMDPGT==0)
4355     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4356   if(nbOfMDPGT==1)
4357     {
4358       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4359       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4360       return ret0;
4361     }
4362   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4363   for(std::size_t i=0;i<nbOfMDPGT;i++)
4364     {
4365       std::vector< std::pair<int,int> > its;
4366       ret[i]=shallowCpy();
4367       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4368       ret[i]->updateData(newLgth,its);
4369     }
4370   return ret;
4371 }
4372
4373 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4374 {
4375   int globalCounter(0);
4376   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4377     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4378   return globalCounter;
4379 }
4380
4381 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4382 {
4383   int globalCounter(0);
4384   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4385     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4386   return globalCounter;
4387 }
4388
4389 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4390 {
4391   if(_nb_of_tuples_to_be_allocated>=0)
4392     {
4393       _nb_of_tuples_to_be_allocated=newLgth;
4394       const DataArray *oldArr(getUndergroundDataArray());
4395       if(oldArr)
4396         {
4397           MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4398           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4399           setArray(newArr);
4400           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4401         }
4402       return ;
4403     }
4404   if(_nb_of_tuples_to_be_allocated==-1)
4405     return ;
4406   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4407     {
4408       const DataArray *oldArr(getUndergroundDataArray());
4409       if(!oldArr || !oldArr->isAllocated())
4410         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4411       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4412       newArr->alloc(newLgth,getNumberOfComponents());
4413       if(oldArr)
4414         newArr->copyStringInfoFrom(*oldArr);
4415       int pos=0;
4416       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4417         {
4418           if((*it).second<(*it).first)
4419             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4420           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4421           pos+=(*it).second-(*it).first;
4422         }
4423       setArray(newArr);
4424       return ;
4425     }
4426   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4427 }
4428
4429 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4430 {
4431   if(_field_per_mesh.empty())
4432     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4433   if(_field_per_mesh.size()>1)
4434     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4435   _field_per_mesh[0]->copyOptionsFrom(opts);
4436   _field_per_mesh[0]->writeLL(fid,nasc);
4437 }
4438
4439 /*!
4440  * 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.
4441  * If false is returned the memory allocation is not required.
4442  */
4443 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4444 {
4445   if(_nb_of_tuples_to_be_allocated>=0)
4446     {
4447       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4448       _nb_of_tuples_to_be_allocated=-2;
4449       return true;
4450     }
4451   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4452     return false;
4453   if(_nb_of_tuples_to_be_allocated==-1)
4454     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4455   if(_nb_of_tuples_to_be_allocated<-3)
4456     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4457   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4458 }
4459
4460 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4461 {
4462   med_int numdt,numit;
4463   med_float dt;
4464   med_int nmesh;
4465   med_bool localMesh;
4466   med_int meshnumdt,meshnumit;
4467   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4468   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4469   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4470   if(_iteration!=numdt || _order!=numit)
4471     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4472   _field_per_mesh.resize(nmesh);
4473   //
4474   MEDFileMesh *mm(0);
4475   if(ms)
4476     {
4477       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4478       mm=ms->getMeshWithName(meshNameCpp);
4479     }
4480   //
4481   for(int i=0;i<nmesh;i++)
4482     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4483   _nb_of_tuples_to_be_allocated=0;
4484   for(int i=0;i<nmesh;i++)
4485     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4486 }
4487
4488 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4489 {
4490   allocIfNecessaryTheArrayToReceiveDataFromFile();
4491   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4492     (*it)->loadBigArraysRecursively(fid,nasc);
4493 }
4494
4495 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4496 {
4497   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4498     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4499       (*it)->loadBigArraysRecursively(fid,nasc);
4500 }
4501
4502 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4503 {
4504   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4505   loadBigArraysRecursively(fid,nasc);
4506 }
4507
4508 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4509 {
4510   DataArray *thisArr(getUndergroundDataArray());
4511   if(thisArr && thisArr->isAllocated())
4512     {
4513       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4514       thisArr->desallocate();
4515     }
4516 }
4517
4518 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4519 {
4520   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4521 }
4522
4523 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4524 {
4525   std::vector<const BigMemoryObject *> ret;
4526   if(getUndergroundDataArray())
4527     ret.push_back(getUndergroundDataArray());
4528   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4529     ret.push_back((const MEDFileFieldPerMesh *)*it);
4530   return ret;
4531 }
4532
4533 /*!
4534  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4535  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4536  * "Sort By Type"), if not, an exception is thrown. 
4537  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4538  *  \param [in] arr - the array of values.
4539  *  \param [in,out] glob - the global data where profiles and localization present in
4540  *          \a field, if any, are added.
4541  *  \throw If the name of \a field is empty.
4542  *  \throw If the data array of \a field is not set.
4543  *  \throw If \a this->_arr is already allocated but has different number of components
4544  *         than \a field.
4545  *  \throw If the underlying mesh of \a field has no name.
4546  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4547  */
4548 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4549 {
4550   const MEDCouplingMesh *mesh=field->getMesh();
4551   //
4552   TypeOfField type=field->getTypeOfField();
4553   std::vector<DataArrayInt *> dummy;
4554   int start=copyTinyInfoFrom(field,arr);
4555   int pos=addNewEntryIfNecessary(mesh);
4556   if(type!=ON_NODES)
4557     {
4558       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4559       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4560     }
4561   else
4562     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4563 }
4564
4565 /*!
4566  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4567  * of a given mesh are used as the support of the given field (a real support is not used). 
4568  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4569  * Order of underlying mesh entities of the given field specified by \a profile parameter
4570  * is not prescribed; this method permutes field values to have them sorted by element
4571  * type as required for writing to MED file. A new profile is added only if no equal
4572  * profile is missing. 
4573  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4574  *  \param [in] arrOfVals - the values of the field \a field used.
4575  *  \param [in] mesh - the supporting mesh of \a field.
4576  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4577  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4578  *  \param [in,out] glob - the global data where profiles and localization present in
4579  *          \a field, if any, are added.
4580  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4581  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4582  *  \throw If the data array of \a field is not set.
4583  *  \throw If \a this->_arr is already allocated but has different number of components
4584  *         than \a field.
4585  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4586  *  \sa setFieldNoProfileSBT()
4587  */
4588 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4589 {
4590   if(!field)
4591     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4592   if(!arrOfVals || !arrOfVals->isAllocated())
4593     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4594   TypeOfField type=field->getTypeOfField();
4595   std::vector<DataArrayInt *> idsInPflPerType;
4596   std::vector<DataArrayInt *> idsPerType;
4597   std::vector<int> code,code2;
4598   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4599   if(type!=ON_NODES)
4600     {
4601       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4602       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4603       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4604       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4605       // start of check
4606       MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2=field->clone(false);
4607       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4608       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4609         {
4610           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4611           throw INTERP_KERNEL::Exception(oss.str().c_str());
4612         }
4613       // end of check
4614       int start=copyTinyInfoFrom(field,arrOfVals);
4615       code2=m->getDistributionOfTypes();
4616       //
4617       int pos=addNewEntryIfNecessary(m);
4618       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4619     }
4620   else
4621     {
4622       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4623         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4624       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4625       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4626       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4627       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4628         {
4629           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4630           throw INTERP_KERNEL::Exception(oss.str().c_str());
4631         }
4632       int start=copyTinyInfoFrom(field,arrOfVals);
4633       int pos=addNewEntryIfNecessary(m);
4634       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4635     }
4636 }
4637
4638 /*!
4639  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4640  */
4641 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4642 {
4643   if(_nb_of_tuples_to_be_allocated>=0)
4644     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 !");
4645   DataArray *arr(getOrCreateAndGetArray());
4646   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4647   _nb_of_tuples_to_be_allocated=-3;
4648 }
4649
4650 /*!
4651  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4652  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4653  * larger by the size of \a field. Returns an id of the first not filled
4654  * tuple of \a this->_arr.
4655  *  \param [in] field - the field to copy the info on components and the name from.
4656  *  \return int - the id of first not initialized tuple of \a this->_arr.
4657  *  \throw If the name of \a field is empty.
4658  *  \throw If the data array of \a field is not set.
4659  *  \throw If \a this->_arr is already allocated but has different number of components
4660  *         than \a field.
4661  */
4662 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4663 {
4664   if(!field)
4665     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4666   std::string name(field->getName());
4667   setName(name.c_str());
4668   setDtUnit(field->getTimeUnit());
4669   if(name.empty())
4670     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4671   if(!arr)
4672     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4673   if(!arr->isAllocated())
4674     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4675   _dt=field->getTime(_iteration,_order);
4676   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4677   if(!getOrCreateAndGetArray()->isAllocated())
4678     {
4679       allocNotFromFile(arr->getNumberOfTuples());
4680       return 0;
4681     }
4682   else
4683     {
4684       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4685       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4686       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4687       _nb_of_tuples_to_be_allocated=-3;
4688       return oldNbOfTuples;
4689     }
4690 }
4691
4692 /*!
4693  * Returns number of components in \a this field
4694  *  \return int - the number of components.
4695  */
4696 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4697 {
4698   return getOrCreateAndGetArray()->getNumberOfComponents();
4699 }
4700
4701 /*!
4702  * Change info on components in \a this.
4703  * \throw If size of \a infos is not equal to the number of components already in \a this.
4704  */
4705 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4706 {
4707   DataArray *arr=getOrCreateAndGetArray();
4708   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4709 }
4710
4711 /*!
4712  * Returns info on components of \a this field.
4713  *  \return const std::vector<std::string>& - a sequence of strings each being an
4714  *          information on _i_-th component.
4715  */
4716 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4717 {
4718   const DataArray *arr=getOrCreateAndGetArray();
4719   return arr->getInfoOnComponents();
4720 }
4721
4722 /*!
4723  * Returns a mutable info on components of \a this field.
4724  *  \return std::vector<std::string>& - a sequence of strings each being an
4725  *          information on _i_-th component.
4726  */
4727 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4728 {
4729   DataArray *arr=getOrCreateAndGetArray();
4730   return arr->getInfoOnComponents();
4731 }
4732
4733 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4734 {
4735   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4736     {
4737       const MEDFileFieldPerMesh *fpm(*it);
4738       if(!fpm)
4739         continue;
4740       if(fpm->presenceOfMultiDiscPerGeoType())
4741         return true;
4742     }
4743   return false;
4744 }
4745
4746 /*!
4747  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4748  *  \param [in] type - a spatial discretization of the new field.
4749  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4750  *  \param [in] mName - a name of the supporting mesh.
4751  *  \param [in] renumPol - specifies how to permute values of the result field according to
4752  *          the optional numbers of cells and nodes, if any. The valid values are
4753  *          - 0 - do not permute.
4754  *          - 1 - permute cells.
4755  *          - 2 - permute nodes.
4756  *          - 3 - permute cells and nodes.
4757  *
4758  *  \param [in] glob - the global data storing profiles and localization.
4759  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4760  *          caller is to delete this field using decrRef() as it is no more needed. 
4761  *  \throw If the MED file is not readable.
4762  *  \throw If there is no mesh named \a mName in the MED file.
4763  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4764  *  \throw If no field of \a this is lying on the mesh \a mName.
4765  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4766  */
4767 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4768 {
4769   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4770   if(mName.empty())
4771     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4772   else
4773     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4774   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4775 }
4776
4777 /*!
4778  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4779  *  \param [in] type - a spatial discretization of the new field.
4780  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4781  *  \param [in] renumPol - specifies how to permute values of the result field according to
4782  *          the optional numbers of cells and nodes, if any. The valid values are
4783  *          - 0 - do not permute.
4784  *          - 1 - permute cells.
4785  *          - 2 - permute nodes.
4786  *          - 3 - permute cells and nodes.
4787  *
4788  *  \param [in] glob - the global data storing profiles and localization.
4789  *  \param [in] mesh - the supporting mesh.
4790  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4791  *          caller is to delete this field using decrRef() as it is no more needed. 
4792  *  \throw If the MED file is not readable.
4793  *  \throw If no field of \a this is lying on \a mesh.
4794  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4795  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4796  */
4797 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4798 {
4799   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4800   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4801   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4802   if(meshDimRelToMax==1)
4803     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4804   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4805 }
4806
4807 /*!
4808  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4809  * given mesh. 
4810  *  \param [in] type - a spatial discretization of the new field.
4811  *  \param [in] mName - a name of the supporting mesh.
4812  *  \param [in] renumPol - specifies how to permute values of the result field according to
4813  *          the optional numbers of cells and nodes, if any. The valid values are
4814  *          - 0 - do not permute.
4815  *          - 1 - permute cells.
4816  *          - 2 - permute nodes.
4817  *          - 3 - permute cells and nodes.
4818  *
4819  *  \param [in] glob - the global data storing profiles and localization.
4820  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4821  *          caller is to delete this field using decrRef() as it is no more needed. 
4822  *  \throw If the MED file is not readable.
4823  *  \throw If there is no mesh named \a mName in the MED file.
4824  *  \throw If there are no mesh entities in the mesh.
4825  *  \throw If no field values of the given \a type are available.
4826  */
4827 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4828 {
4829   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4830   if(mName.empty())
4831     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4832   else
4833     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4834   int absDim=getDimension();
4835   int meshDimRelToMax=absDim-mm->getMeshDimension();
4836   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4837 }
4838
4839 /*!
4840  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4841  *  \param [in] type - a spatial discretization of the new field.
4842  *  \param [in] renumPol - specifies how to permute values of the result field according to
4843  *          the optional numbers of cells and nodes, if any. The valid values are
4844  *          - 0 - do not permute.
4845  *          - 1 - permute cells.
4846  *          - 2 - permute nodes.
4847  *          - 3 - permute cells and nodes.
4848  *
4849  *  \param [in] glob - the global data storing profiles and localization.
4850  *  \param [in] mesh - the supporting mesh.
4851  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4852  *         field according to \a renumPol.
4853  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4854  *         field according to \a renumPol.
4855  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4856  *          caller is to delete this field using decrRef() as it is no more needed. 
4857  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4858  *  \throw If no field of \a this is lying on \a mesh.
4859  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4860  */
4861 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
4862 {
4863   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4864   int meshId=getMeshIdFromMeshName(mesh->getName());
4865   bool isPfl=false;
4866   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4867   switch(renumPol)
4868   {
4869     case 0:
4870       {
4871         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4872         return ret.retn();
4873       }
4874     case 3:
4875     case 1:
4876       {
4877         if(isPfl)
4878           throw INTERP_KERNEL::Exception(msg1);
4879         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4880         if(cellRenum)
4881           {
4882             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4883               {
4884                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4885                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4886                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4887               }
4888             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4889             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4890             std::vector<DataArray *> arrOut2(1,arrOut);
4891             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4892             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4893             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4894           }
4895         if(renumPol==1)
4896           return ret.retn();
4897       }
4898     case 2:
4899       {
4900         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4901         if(isPfl)
4902           throw INTERP_KERNEL::Exception(msg1);
4903         if(nodeRenum)
4904           {
4905             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4906               {
4907                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4908                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4909                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4910               }
4911             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4912             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4913               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4914             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4915           }
4916         return ret.retn();
4917       }
4918     default:
4919       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4920   }
4921 }
4922
4923 /*!
4924  * Returns values and a profile of the field of a given type lying on a given support.
4925  *  \param [in] type - a spatial discretization of the field.
4926  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4927  *  \param [in] mesh - the supporting mesh.
4928  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4929  *          field of interest lies on. If the field lies on all entities of the given
4930  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4931  *          using decrRef() as it is no more needed.  
4932  *  \param [in] glob - the global data storing profiles and localization.
4933  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4934  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4935  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4936  *  \throw If no field of \a this is lying on \a mesh.
4937  *  \throw If no field values of the given \a type are available.
4938  */
4939 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4940 {
4941   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4942   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4943   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4944   ret->setName(nasc.getName().c_str());
4945   return ret.retn();
4946 }
4947
4948 //= MEDFileField1TSWithoutSDA
4949
4950 /*!
4951  * Throws if a given value is not a valid (non-extended) relative dimension.
4952  *  \param [in] meshDimRelToMax - the relative dimension value.
4953  *  \throw If \a meshDimRelToMax > 0.
4954  */
4955 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4956 {
4957   if(meshDimRelToMax>0)
4958     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4959 }
4960
4961 /*!
4962  * Checks if elements of a given mesh are in the order suitable for writing 
4963  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4964  * vector describing types of elements and their number.
4965  *  \param [in] mesh - the mesh to check.
4966  *  \return std::vector<int> - a vector holding for each element type (1) item of
4967  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4968  *          These values are in full-interlace mode.
4969  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4970  */
4971 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4972 {
4973   if(!mesh)
4974     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4975   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4976   int nbOfTypes=geoTypes.size();
4977   std::vector<int> code(3*nbOfTypes);
4978   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4979   arr1->alloc(nbOfTypes,1);
4980   int *arrPtr=arr1->getPointer();
4981   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4982   for(int i=0;i<nbOfTypes;i++,it++)
4983     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4984   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4985   const int *arrPtr2=arr2->getConstPointer();
4986   int i=0;
4987   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4988     {
4989       int pos=arrPtr2[i];
4990       int nbCells=mesh->getNumberOfCellsWithType(*it);
4991       code[3*pos]=(int)(*it);
4992       code[3*pos+1]=nbCells;
4993       code[3*pos+2]=-1;//no profiles
4994     }
4995   std::vector<const DataArrayInt *> idsPerType;//no profiles
4996   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4997   if(da)
4998     {
4999       da->decrRef();
5000       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5001     }
5002   return code;
5003 }
5004
5005 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5006 {
5007   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5008 }
5009
5010 /*!
5011  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5012  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5013  * item of every of returned sequences refers to the _i_-th part of \a this field.
5014  * Thus all sequences returned by this method are of the same length equal to number
5015  * of different types of supporting entities.<br>
5016  * A field part can include sub-parts with several different spatial discretizations,
5017  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
5018  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5019  * of a nested sequence corresponds to a type of spatial discretization.<br>
5020  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5021  * The overhead is due to selecting values into new instances of DataArrayDouble.
5022  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5023  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5024  *          not checked if \a mname == \c NULL).
5025  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5026  *          a field part is returned. 
5027  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5028  *          A field part can include sub-parts with several different spatial discretizations,
5029  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
5030  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5031  *          This sequence is of the same length as \a types. 
5032  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5033  *          discretization. A profile name can be empty.
5034  *          Length of this and of nested sequences is the same as that of \a typesF.
5035  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5036  *          discretization. A localization name can be empty.
5037  *          Length of this and of nested sequences is the same as that of \a typesF.
5038  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5039  *          per each type of spatial discretization within one mesh entity type.
5040  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5041  *          Length of this and of nested sequences is the same as that of \a typesF.
5042  *  \throw If no field is lying on \a mname.
5043  */
5044 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
5045 {
5046   int meshId=0;
5047   if(!mname.empty())
5048     meshId=getMeshIdFromMeshName(mname);
5049   else
5050     if(_field_per_mesh.empty())
5051       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5052   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5053   int nbOfRet=ret0.size();
5054   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5055   for(int i=0;i<nbOfRet;i++)
5056     {
5057       const std::vector< std::pair<int,int> >& p=ret0[i];
5058       int nbOfRet1=p.size();
5059       ret[i].resize(nbOfRet1);
5060       for(int j=0;j<nbOfRet1;j++)
5061         {
5062           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
5063           ret[i][j]=tmp;
5064         }
5065     }
5066   return ret;
5067 }
5068
5069 /*!
5070  * Returns a pointer to the underground DataArrayDouble instance. So the
5071  * caller should not decrRef() it. This method allows for a direct access to the field
5072  * values. This method is quite unusable if there is more than a nodal field or a cell
5073  * field on single geometric cell type. 
5074  *  \return DataArrayDouble * - the pointer to the field values array.
5075  */
5076 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
5077 {
5078   const DataArrayDouble *ret=_arr;
5079   if(ret)
5080     return const_cast<DataArrayDouble *>(ret);
5081   else
5082     return 0;
5083 }
5084
5085 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5086 {
5087   return TYPE_STR;
5088 }
5089
5090 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5091 {
5092   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5093   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5094   ret->deepCpyLeavesFrom(*this);
5095   const DataArrayDouble *arr(_arr);
5096   if(arr)
5097     {
5098       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
5099       ret->setArray(arr2);
5100     }
5101   return ret.retn();
5102 }
5103
5104 /*!
5105  * Returns a pointer to the underground DataArrayDouble instance. So the
5106  * caller should not decrRef() it. This method allows for a direct access to the field
5107  * values. This method is quite unusable if there is more than a nodal field or a cell
5108  * field on single geometric cell type. 
5109  *  \return DataArrayDouble * - the pointer to the field values array.
5110  */
5111 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
5112 {
5113   return getUndergroundDataArrayDouble();
5114 }
5115
5116 /*!
5117  * Returns a pointer to the underground DataArrayDouble instance and a
5118  * sequence describing parameters of a support of each part of \a this field. The
5119  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5120  * direct access to the field values. This method is intended for the field lying on one
5121  * mesh only.
5122  *  \param [in,out] entries - the sequence describing parameters of a support of each
5123  *         part of \a this field. Each item of this sequence consists of two parts. The
5124  *         first part describes a type of mesh entity and an id of discretization of a
5125  *         current field part. The second part describes a range of values [begin,end)
5126  *         within the returned array relating to the current field part.
5127  *  \return DataArrayDouble * - the pointer to the field values array.
5128  *  \throw If the number of underlying meshes is not equal to 1.
5129  *  \throw If no field values are available.
5130  *  \sa getUndergroundDataArray()
5131  */
5132 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5133 {
5134   if(_field_per_mesh.size()!=1)
5135     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5136   if(_field_per_mesh[0]==0)
5137     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5138   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5139   return getUndergroundDataArrayDouble();
5140 }
5141
5142 /*!
5143  * Returns a pointer to the underground DataArrayDouble instance and a
5144  * sequence describing parameters of a support of each part of \a this field. The
5145  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5146  * direct access to the field values. This method is intended for the field lying on one
5147  * mesh only.
5148  *  \param [in,out] entries - the sequence describing parameters of a support of each
5149  *         part of \a this field. Each item of this sequence consists of two parts. The
5150  *         first part describes a type of mesh entity and an id of discretization of a
5151  *         current field part. The second part describes a range of values [begin,end)
5152  *         within the returned array relating to the current field part.
5153  *  \return DataArrayDouble * - the pointer to the field values array.
5154  *  \throw If the number of underlying meshes is not equal to 1.
5155  *  \throw If no field values are available.
5156  *  \sa getUndergroundDataArray()
5157  */
5158 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5159 {
5160   return getUndergroundDataArrayDoubleExt(entries);
5161 }
5162
5163 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5164 {
5165   DataArrayDouble *arr(getOrCreateAndGetArrayDouble());
5166   arr->setInfoAndChangeNbOfCompo(infos);
5167 }
5168
5169 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5170 {
5171 }
5172
5173 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5174 {
5175   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5176   ret->deepCpyLeavesFrom(*this);
5177   return ret.retn();
5178 }
5179
5180 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const
5181 {
5182   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5183   if((const DataArrayDouble *)_arr)
5184     ret->_arr=_arr->deepCpy();
5185   return ret.retn();
5186 }
5187
5188 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
5189 {
5190   if(!arr)
5191     {
5192       _nb_of_tuples_to_be_allocated=-1;
5193       _arr=0;
5194       return ;
5195     }
5196   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
5197   if(!arrC)
5198     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
5199   else
5200     _nb_of_tuples_to_be_allocated=-3;
5201   arrC->incrRef();
5202   _arr=arrC;
5203 }
5204
5205 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5206 {
5207   return DataArrayDouble::New();
5208 }
5209
5210 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
5211 {
5212   DataArrayDouble *ret=_arr;
5213   if(ret)
5214     return ret;
5215   _arr=DataArrayDouble::New();
5216   return _arr;
5217 }
5218
5219 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
5220 {
5221   return getOrCreateAndGetArrayDouble();
5222 }
5223
5224 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
5225 {
5226   const DataArrayDouble *ret=_arr;
5227   if(ret)
5228     return ret;
5229   DataArrayDouble *ret2=DataArrayDouble::New();
5230   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
5231   return ret2;
5232 }
5233
5234 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
5235 {
5236   return getOrCreateAndGetArrayDouble();
5237 }
5238
5239 //= MEDFileIntField1TSWithoutSDA
5240
5241 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5242 {
5243   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5244 }
5245
5246 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5247 {
5248 }
5249
5250 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5251                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5252 {
5253   DataArrayInt *arr(getOrCreateAndGetArrayInt());
5254   arr->setInfoAndChangeNbOfCompo(infos);
5255 }
5256
5257 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5258 {
5259   return TYPE_STR;
5260 }
5261
5262 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5263 {
5264   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5265   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5266   ret->deepCpyLeavesFrom(*this);
5267   const DataArrayInt *arr(_arr);
5268   if(arr)
5269     {
5270       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
5271       ret->setArray(arr2);
5272     }
5273   return ret.retn();
5274 }
5275
5276 /*!
5277  * Returns a pointer to the underground DataArrayInt instance. So the
5278  * caller should not decrRef() it. This method allows for a direct access to the field
5279  * values. This method is quite unusable if there is more than a nodal field or a cell
5280  * field on single geometric cell type. 
5281  *  \return DataArrayInt * - the pointer to the field values array.
5282  */
5283 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
5284 {
5285   return getUndergroundDataArrayInt();
5286 }
5287
5288 /*!
5289  * Returns a pointer to the underground DataArrayInt instance. So the
5290  * caller should not decrRef() it. This method allows for a direct access to the field
5291  * values. This method is quite unusable if there is more than a nodal field or a cell
5292  * field on single geometric cell type. 
5293  *  \return DataArrayInt * - the pointer to the field values array.
5294  */
5295 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5296 {
5297   const DataArrayInt *ret=_arr;
5298   if(ret)
5299     return const_cast<DataArrayInt *>(ret);
5300   else
5301     return 0;
5302 }
5303
5304 /*!
5305  * Returns a pointer to the underground DataArrayInt instance and a
5306  * sequence describing parameters of a support of each part of \a this field. The
5307  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5308  * direct access to the field values. This method is intended for the field lying on one
5309  * mesh only.
5310  *  \param [in,out] entries - the sequence describing parameters of a support of each
5311  *         part of \a this field. Each item of this sequence consists of two parts. The
5312  *         first part describes a type of mesh entity and an id of discretization of a
5313  *         current field part. The second part describes a range of values [begin,end)
5314  *         within the returned array relating to the current field part.
5315  *  \return DataArrayInt * - the pointer to the field values array.
5316  *  \throw If the number of underlying meshes is not equal to 1.
5317  *  \throw If no field values are available.
5318  *  \sa getUndergroundDataArray()
5319  */
5320 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5321 {
5322   return getUndergroundDataArrayIntExt(entries);
5323 }
5324
5325 /*!
5326  * Returns a pointer to the underground DataArrayInt instance and a
5327  * sequence describing parameters of a support of each part of \a this field. The
5328  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5329  * direct access to the field values. This method is intended for the field lying on one
5330  * mesh only.
5331  *  \param [in,out] entries - the sequence describing parameters of a support of each
5332  *         part of \a this field. Each item of this sequence consists of two parts. The
5333  *         first part describes a type of mesh entity and an id of discretization of a
5334  *         current field part. The second part describes a range of values [begin,end)
5335  *         within the returned array relating to the current field part.
5336  *  \return DataArrayInt * - the pointer to the field values array.
5337  *  \throw If the number of underlying meshes is not equal to 1.
5338  *  \throw If no field values are available.
5339  *  \sa getUndergroundDataArray()
5340  */
5341 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5342 {
5343   if(_field_per_mesh.size()!=1)
5344     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5345   if(_field_per_mesh[0]==0)
5346     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5347   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5348   return getUndergroundDataArrayInt();
5349 }
5350
5351 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5352 {
5353   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5354   ret->deepCpyLeavesFrom(*this);
5355   return ret.retn();
5356 }
5357
5358 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const
5359 {
5360   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5361   if((const DataArrayInt *)_arr)
5362     ret->_arr=_arr->deepCpy();
5363   return ret.retn();
5364 }
5365
5366 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5367 {
5368   if(!arr)
5369     {
5370       _nb_of_tuples_to_be_allocated=-1;
5371       _arr=0;
5372       return ;
5373     }
5374   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5375   if(!arrC)
5376     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5377   else
5378     _nb_of_tuples_to_be_allocated=-3;
5379   arrC->incrRef();
5380   _arr=arrC;
5381 }
5382
5383 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5384 {
5385   return DataArrayInt::New();
5386 }
5387
5388 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5389 {
5390   DataArrayInt *ret=_arr;
5391   if(ret)
5392     return ret;
5393   _arr=DataArrayInt::New();
5394   return _arr;
5395 }
5396
5397 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5398 {
5399   return getOrCreateAndGetArrayInt();
5400 }
5401
5402 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5403 {
5404   const DataArrayInt *ret=_arr;
5405   if(ret)
5406     return ret;
5407   DataArrayInt *ret2=DataArrayInt::New();
5408   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5409   return ret2;
5410 }
5411
5412 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5413 {
5414   return getOrCreateAndGetArrayInt();
5415 }
5416
5417 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5418 {
5419 }
5420
5421 //= MEDFileAnyTypeField1TS
5422
5423 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5424 {
5425   med_field_type typcha;
5426   //
5427   std::vector<std::string> infos;
5428   std::string dtunit,fieldName;
5429   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5430   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5431   switch(typcha)
5432   {
5433     case MED_FLOAT64:
5434       {
5435         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5436         break;
5437       }
5438     case MED_INT32:
5439       {
5440         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5441         break;
5442       }
5443     default:
5444       {
5445         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] !";
5446         throw INTERP_KERNEL::Exception(oss.str().c_str());
5447       }
5448   }
5449   ret->setDtUnit(dtunit.c_str());
5450   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5451   //
5452   med_int numdt,numit;
5453   med_float dt;
5454   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5455   ret->setTime(numdt,numit,dt);
5456   ret->_csit=1;
5457   if(loadAll)
5458     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5459   else
5460     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5461   return ret.retn();
5462 }
5463
5464 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5465 try:MEDFileFieldGlobsReal(fileName)
5466 {
5467   MEDFileUtilities::CheckFileForRead(fileName);
5468   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5469   _content=BuildContentFrom(fid,fileName,loadAll,ms);
5470   loadGlobals(fid);
5471 }
5472 catch(INTERP_KERNEL::Exception& e)
5473 {
5474     throw e;
5475 }
5476
5477 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5478 {
5479   med_field_type typcha;
5480   std::vector<std::string> infos;
5481   std::string dtunit;
5482   int iii=-1;
5483   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5484   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5485   switch(typcha)
5486   {
5487     case MED_FLOAT64:
5488       {
5489         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5490         break;
5491       }
5492     case MED_INT32:
5493       {
5494         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5495         break;
5496       }
5497     default:
5498       {
5499         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] !";
5500         throw INTERP_KERNEL::Exception(oss.str().c_str());
5501       }
5502   }
5503   ret->setDtUnit(dtunit.c_str());
5504   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5505   //
5506   if(nbSteps<1)
5507     {
5508       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5509       throw INTERP_KERNEL::Exception(oss.str().c_str());
5510     }
5511   //
5512   med_int numdt,numit;
5513   med_float dt;
5514   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5515   ret->setTime(numdt,numit,dt);
5516   ret->_csit=1;
5517   if(loadAll)
5518     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5519   else
5520     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5521   return ret.retn();
5522 }
5523
5524 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5525 try:MEDFileFieldGlobsReal(fileName)
5526 {
5527   MEDFileUtilities::CheckFileForRead(fileName);
5528   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5529   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
5530   loadGlobals(fid);
5531 }
5532 catch(INTERP_KERNEL::Exception& e)
5533 {
5534     throw e;
5535 }
5536
5537 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5538 {
5539   if(!c)
5540     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5541   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5542     {
5543       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5544       ret->setFileName(fileName);
5545       ret->_content=c; c->incrRef();
5546       return ret.retn();
5547     }
5548   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5549     {
5550       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5551       ret->setFileName(fileName);
5552       ret->_content=c; c->incrRef();
5553       return ret.retn();
5554     }
5555   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5556 }
5557
5558 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5559 {
5560   MEDFileUtilities::CheckFileForRead(fileName);
5561   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5562   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
5563   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5564   ret->loadGlobals(fid);
5565   return ret.retn();
5566 }
5567
5568 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5569 {
5570   MEDFileUtilities::CheckFileForRead(fileName);
5571   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5572   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
5573   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5574   ret->loadGlobals(fid);
5575   return ret.retn();
5576 }
5577
5578 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5579 {
5580   MEDFileUtilities::CheckFileForRead(fileName);
5581   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5582   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll,0);
5583   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5584   ret->loadGlobals(fid);
5585   return ret.retn();
5586 }
5587
5588 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5589 {
5590   med_field_type typcha;
5591   std::vector<std::string> infos;
5592   std::string dtunit;
5593   int iii=-1;
5594   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5595   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5596   switch(typcha)
5597   {
5598     case MED_FLOAT64:
5599       {
5600         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5601         break;
5602       }
5603     case MED_INT32:
5604       {
5605         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5606         break;
5607       }
5608     default:
5609       {
5610         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] !";
5611         throw INTERP_KERNEL::Exception(oss.str().c_str());
5612       }
5613   }
5614   ret->setDtUnit(dtunit.c_str());
5615   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5616   //
5617   bool found=false;
5618   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5619   for(int i=0;i<nbOfStep2 && !found;i++)
5620     {
5621       med_int numdt,numit;
5622       med_float dt;
5623       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5624       if(numdt==iteration && numit==order)
5625         {
5626           found=true;
5627           ret->_csit=i+1;
5628         }
5629       else
5630         dtits[i]=std::pair<int,int>(numdt,numit);
5631     }
5632   if(!found)
5633     {
5634       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5635       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5636         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5637       throw INTERP_KERNEL::Exception(oss.str().c_str());
5638     }
5639   if(loadAll)
5640     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5641   else
5642     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5643   return ret.retn();
5644 }
5645
5646 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5647 try:MEDFileFieldGlobsReal(fileName)
5648 {
5649   MEDFileUtilities::CheckFileForRead(fileName);
5650   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5651   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll,ms);
5652   loadGlobals(fid);
5653 }
5654 catch(INTERP_KERNEL::Exception& e)
5655 {
5656     throw e;
5657 }
5658
5659 /*!
5660  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5661  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5662  *
5663  * \warning this is a shallow copy constructor
5664  */
5665 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5666 {
5667   if(!shallowCopyOfContent)
5668     {
5669       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5670       otherPtr->incrRef();
5671       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5672     }
5673   else
5674     {
5675       _content=other.shallowCpy();
5676     }
5677 }
5678
5679 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)
5680 {
5681   if(checkFieldId)
5682     {
5683       int nbFields=MEDnField(fid);
5684       if(fieldIdCFormat>=nbFields)
5685         {
5686           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5687           throw INTERP_KERNEL::Exception(oss.str().c_str());
5688         }
5689     }
5690   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5691   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5692   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5693   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5694   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5695   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5696   med_bool localMesh;
5697   int nbOfStep;
5698   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5699   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5700   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5701   infos.clear(); infos.resize(ncomp);
5702   for(int j=0;j<ncomp;j++)
5703     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5704   return nbOfStep;
5705 }
5706
5707 /*!
5708  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5709  * 
5710  * \param [out]
5711  * \return in case of success the number of time steps available for the field with name \a fieldName.
5712  */
5713 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)
5714 {
5715   int nbFields=MEDnField(fid);
5716   bool found=false;
5717   std::vector<std::string> fns(nbFields);
5718   int nbOfStep2=-1;
5719   for(int i=0;i<nbFields && !found;i++)
5720     {
5721       std::string tmp;
5722       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5723       fns[i]=tmp;
5724       found=(tmp==fieldName);
5725       if(found)
5726         posCFormat=i;
5727     }
5728   if(!found)
5729     {
5730       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5731       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5732         oss << "\"" << *it << "\" ";
5733       throw INTERP_KERNEL::Exception(oss.str().c_str());
5734     }
5735   return nbOfStep2;
5736 }
5737
5738 /*!
5739  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5740  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5741  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5742  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5743  * to keep a valid instance.
5744  * 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.
5745  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5746  * 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.
5747  *
5748  * \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.
5749  * \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.
5750  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5751  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5752  * \param [in] newLocName is the new localization name.
5753  * \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.
5754  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5755  */
5756 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5757 {
5758   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5759   std::string oldPflName=disc->getProfile();
5760   std::vector<std::string> vv=getPflsReallyUsedMulti();
5761   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5762   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5763     {
5764       disc->setProfile(newPflName);
5765       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5766       pfl->setName(newPflName);
5767     }
5768   else
5769     {
5770       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5771       throw INTERP_KERNEL::Exception(oss.str().c_str());
5772     }
5773 }
5774
5775 /*!
5776  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5777  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5778  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5779  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5780  * to keep a valid instance.
5781  * 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.
5782  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5783  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5784  * 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.
5785  *
5786  * \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.
5787  * \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.
5788  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5789  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5790  * \param [in] newLocName is the new localization name.
5791  * \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.
5792  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5793  */
5794 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5795 {
5796   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5797   std::string oldLocName=disc->getLocalization();
5798   std::vector<std::string> vv=getLocsReallyUsedMulti();
5799   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5800   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5801     {
5802       disc->setLocalization(newLocName);
5803       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5804       loc.setName(newLocName);
5805     }
5806   else
5807     {
5808       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5809       throw INTERP_KERNEL::Exception(oss.str().c_str());
5810     }
5811 }
5812
5813 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5814 {
5815   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5816   if(!ret)
5817     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5818   return ret;
5819 }
5820
5821 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5822 {
5823   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5824   if(!ret)
5825     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5826   return ret;
5827 }
5828
5829 /*!
5830  * Writes \a this field into a MED file specified by its name.
5831  *  \param [in] fileName - the MED file name.
5832  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5833  * - 2 - erase; an existing file is removed.
5834  * - 1 - append; same data should not be present in an existing file.
5835  * - 0 - overwrite; same data present in an existing file is overwritten.
5836  *  \throw If the field name is not set.
5837  *  \throw If no field data is set.
5838  *  \throw If \a mode == 1 and the same data is present in an existing file.
5839  */
5840 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5841 {
5842   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5843   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5844   writeLL(fid);
5845 }
5846
5847 /*!
5848  * This method alloc the arrays and load potentially huge arrays contained in this field.
5849  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5850  * This method can be also called to refresh or reinit values from a file.
5851  * 
5852  * \throw If the fileName is not set or points to a non readable MED file.
5853  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5854  */
5855 void MEDFileAnyTypeField1TS::loadArrays()
5856 {
5857   if(getFileName().empty())
5858     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5859   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5860   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5861 }
5862
5863 /*!
5864  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5865  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5866  * this method does not throw if \a this does not come from file read.
5867  * 
5868  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5869  */
5870 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5871 {
5872   if(!getFileName().empty())
5873     {
5874       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5875       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5876     }
5877 }
5878
5879 /*!
5880  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5881  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5882  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5883  * 
5884  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5885  */
5886 void MEDFileAnyTypeField1TS::unloadArrays()
5887 {
5888   contentNotNullBase()->unloadArrays();
5889 }
5890
5891 /*!
5892  * 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.
5893  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5894  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5895  * 
5896  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5897  */
5898 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5899 {
5900   if(!getFileName().empty())
5901     contentNotNullBase()->unloadArrays();
5902 }
5903
5904 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5905 {
5906   int nbComp=getNumberOfComponents();
5907   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5908   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5909   for(int i=0;i<nbComp;i++)
5910     {
5911       std::string info=getInfo()[i];
5912       std::string c,u;
5913       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5914       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5915       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5916     }
5917   if(getName().empty())
5918     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5919   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
5920   writeGlobals(fid,*this);
5921   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5922 }
5923
5924 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5925 {
5926   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5927 }
5928
5929 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5930 {
5931   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5932   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5933   return ret;
5934 }
5935
5936 /*!
5937  * Returns a string describing \a this field. This string is outputted 
5938  * by \c print Python command.
5939  */
5940 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5941 {
5942   std::ostringstream oss;
5943   contentNotNullBase()->simpleRepr(0,oss,-1);
5944   simpleReprGlobs(oss);
5945   return oss.str();
5946 }
5947
5948 /*!
5949  * This method returns all profiles whose name is non empty used.
5950  * \b WARNING If profile is used several times it will be reported \b only \b once.
5951  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5952  */
5953 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5954 {
5955   return contentNotNullBase()->getPflsReallyUsed2();
5956 }
5957
5958 /*!
5959  * This method returns all localizations whose name is non empty used.
5960  * \b WARNING If localization is used several times it will be reported \b only \b once.
5961  */
5962 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5963 {
5964   return contentNotNullBase()->getLocsReallyUsed2();
5965 }
5966
5967 /*!
5968  * This method returns all profiles whose name is non empty used.
5969  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5970  */
5971 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5972 {
5973   return contentNotNullBase()->getPflsReallyUsedMulti2();
5974 }
5975
5976 /*!
5977  * This method returns all localizations whose name is non empty used.
5978  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5979  */
5980 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5981 {
5982   return contentNotNullBase()->getLocsReallyUsedMulti2();
5983 }
5984
5985 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5986 {
5987   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5988 }
5989
5990 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5991 {
5992   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5993 }
5994
5995 int MEDFileAnyTypeField1TS::getDimension() const
5996 {
5997   return contentNotNullBase()->getDimension();
5998 }
5999
6000 int MEDFileAnyTypeField1TS::getIteration() const
6001 {
6002   return contentNotNullBase()->getIteration();
6003 }
6004
6005 int MEDFileAnyTypeField1TS::getOrder() const
6006 {
6007   return contentNotNullBase()->getOrder();
6008 }
6009
6010 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6011 {
6012   return contentNotNullBase()->getTime(iteration,order);
6013 }
6014
6015 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6016 {
6017   contentNotNullBase()->setTime(iteration,order,val);
6018 }
6019
6020 std::string MEDFileAnyTypeField1TS::getName() const
6021 {
6022   return contentNotNullBase()->getName();
6023 }
6024
6025 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6026 {
6027   contentNotNullBase()->setName(name);
6028 }
6029
6030 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6031 {
6032   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6033 }
6034
6035 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6036 {
6037   return contentNotNullBase()->getDtUnit();
6038 }
6039
6040 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6041 {
6042   contentNotNullBase()->setDtUnit(dtUnit);
6043 }
6044
6045 std::string MEDFileAnyTypeField1TS::getMeshName() const
6046 {
6047   return contentNotNullBase()->getMeshName();
6048 }
6049
6050 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6051 {
6052   contentNotNullBase()->setMeshName(newMeshName);
6053 }
6054
6055 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6056 {
6057   return contentNotNullBase()->changeMeshNames(modifTab);
6058 }
6059
6060 int MEDFileAnyTypeField1TS::getMeshIteration() const
6061 {
6062   return contentNotNullBase()->getMeshIteration();
6063 }
6064
6065 int MEDFileAnyTypeField1TS::getMeshOrder() const
6066 {
6067   return contentNotNullBase()->getMeshOrder();
6068 }
6069
6070 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6071 {
6072   return contentNotNullBase()->getNumberOfComponents();
6073 }
6074
6075 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6076 {
6077   return contentNotNullBase()->isDealingTS(iteration,order);
6078 }
6079
6080 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6081 {
6082   return contentNotNullBase()->getDtIt();
6083 }
6084
6085 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6086 {
6087   contentNotNullBase()->fillIteration(p);
6088 }
6089
6090 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6091 {
6092   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6093 }
6094
6095 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6096 {
6097   contentNotNullBase()->setInfo(infos);
6098 }
6099
6100 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6101 {
6102   return contentNotNullBase()->getInfo();
6103 }
6104 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6105 {
6106   return contentNotNullBase()->getInfo();
6107 }
6108
6109 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6110 {
6111   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6112 }
6113
6114 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6115 {
6116   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6117 }
6118
6119 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6120 {
6121   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6122 }
6123
6124 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6125 {
6126   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6127 }
6128
6129 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6130 {
6131   return contentNotNullBase()->getTypesOfFieldAvailable();
6132 }
6133
6134 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,
6135                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6136 {
6137   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6138 }
6139
6140 /*!
6141  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6142  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6143  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6144  */
6145 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6146 {
6147   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6148   if(!content)
6149     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6150   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6151   std::size_t sz(contentsSplit.size());
6152   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6153   for(std::size_t i=0;i<sz;i++)
6154     {
6155       ret[i]=shallowCpy();
6156       ret[i]->_content=contentsSplit[i];
6157     }
6158   return ret;
6159 }
6160
6161 /*!
6162  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6163  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6164  */
6165 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6166 {
6167   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6168   if(!content)
6169     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6170   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6171   std::size_t sz(contentsSplit.size());
6172   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6173   for(std::size_t i=0;i<sz;i++)
6174     {
6175       ret[i]=shallowCpy();
6176       ret[i]->_content=contentsSplit[i];
6177     }
6178   return ret;
6179 }
6180
6181 /*!
6182  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6183  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6184  */
6185 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6186 {
6187   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6188   if(!content)
6189     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6190   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6191   std::size_t sz(contentsSplit.size());
6192   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6193   for(std::size_t i=0;i<sz;i++)
6194     {
6195       ret[i]=shallowCpy();
6196       ret[i]->_content=contentsSplit[i];
6197     }
6198   return ret;
6199 }
6200
6201 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const
6202 {
6203   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
6204   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6205     ret->_content=_content->deepCpy();
6206   ret->deepCpyGlobs(*this);
6207   return ret.retn();
6208 }
6209
6210 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6211 {
6212   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6213 }
6214
6215 //= MEDFileField1TS
6216
6217 /*!
6218  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6219  * the first field that has been read from a specified MED file.
6220  *  \param [in] fileName - the name of the MED file to read.
6221  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6222  *          is to delete this field using decrRef() as it is no more needed.
6223  *  \throw If reading the file fails.
6224  */
6225 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6226 {
6227   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,loadAll,0));
6228   ret->contentNotNull();
6229   return ret.retn();
6230 }
6231
6232 /*!
6233  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6234  * a given field that has been read from a specified MED file.
6235  *  \param [in] fileName - the name of the MED file to read.
6236  *  \param [in] fieldName - the name of the field to read.
6237  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6238  *          is to delete this field using decrRef() as it is no more needed.
6239  *  \throw If reading the file fails.
6240  *  \throw If there is no field named \a fieldName in the file.
6241  */
6242 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6243 {
6244   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,loadAll,0));
6245   ret->contentNotNull();
6246   return ret.retn();
6247 }
6248
6249 /*!
6250  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6251  * a given field that has been read from a specified MED file.
6252  *  \param [in] fileName - the name of the MED file to read.
6253  *  \param [in] fieldName - the name of the field to read.
6254  *  \param [in] iteration - the iteration number of a required time step.
6255  *  \param [in] order - the iteration order number of required time step.
6256  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6257  *          is to delete this field using decrRef() as it is no more needed.
6258  *  \throw If reading the file fails.
6259  *  \throw If there is no field named \a fieldName in the file.
6260  *  \throw If the required time step is missing from the file.
6261  */
6262 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6263 {
6264   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll,0));
6265   ret->contentNotNull();
6266   return ret.retn();
6267 }
6268
6269 /*!
6270  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6271  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6272  *
6273  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6274  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6275  * \warning this is a shallow copy constructor
6276  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6277  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6278  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6279  *          is to delete this field using decrRef() as it is no more needed.
6280  */
6281 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6282 {
6283   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
6284   ret->contentNotNull();
6285   return ret.retn();
6286 }
6287
6288 /*!
6289  * Returns a new empty instance of MEDFileField1TS.
6290  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6291  *          is to delete this field using decrRef() as it is no more needed.
6292  */
6293 MEDFileField1TS *MEDFileField1TS::New()
6294 {
6295   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
6296   ret->contentNotNull();
6297   return ret.retn();
6298 }
6299
6300 /*!
6301  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6302  * following the given input policy.
6303  *
6304  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6305  *                            By default (true) the globals are deeply copied.
6306  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6307  */
6308 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6309 {
6310   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
6311   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6312   if(content)
6313     {
6314       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6315       if(!contc)
6316         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6317       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6318       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6319     }
6320   else
6321     ret=MEDFileIntField1TS::New();
6322   if(isDeepCpyGlobs)
6323     ret->deepCpyGlobs(*this);
6324   else
6325     ret->shallowCpyGlobs(*this);
6326   return ret.retn();
6327 }
6328
6329 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6330 {
6331   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6332   if(!pt)
6333     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6334   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6335   if(!ret)
6336     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 !");
6337   return ret;
6338 }
6339
6340 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6341 {
6342   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6343   if(!pt)
6344     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6345   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6346   if(!ret)
6347     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 !");
6348   return ret;
6349 }
6350
6351 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6352 {
6353   if(!f)
6354     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6355   if(!((DataArray*)arr))
6356     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6357   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6358   if(!arrOutC)
6359     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6360   f->setArray(arrOutC);
6361 }
6362
6363 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6364 {
6365   if(!((DataArray*)arr))
6366     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6367   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6368   if(!arrOutC)
6369     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6370   arrOutC->incrRef();
6371   return arrOutC;
6372 }
6373
6374 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6375 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6376 {
6377 }
6378 catch(INTERP_KERNEL::Exception& e)
6379 { throw e; }
6380
6381 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6382 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6383 {
6384 }
6385 catch(INTERP_KERNEL::Exception& e)
6386 { throw e; }
6387
6388 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6389 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6390 {
6391 }
6392 catch(INTERP_KERNEL::Exception& e)
6393 { throw e; }
6394
6395 /*!
6396  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6397  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6398  *
6399  * \warning this is a shallow copy constructor
6400  */
6401 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6402 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6403 {
6404 }
6405 catch(INTERP_KERNEL::Exception& e)
6406 { throw e; }
6407
6408 MEDFileField1TS::MEDFileField1TS()
6409 {
6410   _content=new MEDFileField1TSWithoutSDA;
6411 }
6412
6413 /*!
6414  * Returns a new MEDCouplingFieldDouble of a given type lying on
6415  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6416  * has not been constructed via file reading, an exception is thrown.
6417  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6418  *  \param [in] type - a spatial discretization of interest.
6419  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6420  *  \param [in] renumPol - specifies how to permute values of the result field according to
6421  *          the optional numbers of cells and nodes, if any. The valid values are
6422  *          - 0 - do not permute.
6423  *          - 1 - permute cells.
6424  *          - 2 - permute nodes.
6425  *          - 3 - permute cells and nodes.
6426  *
6427  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6428  *          caller is to delete this field using decrRef() as it is no more needed. 
6429  *  \throw If \a this field has not been constructed via file reading.
6430  *  \throw If the MED file is not readable.
6431  *  \throw If there is no mesh in the MED file.
6432  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6433  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6434  *  \sa getFieldOnMeshAtLevel()
6435  */
6436 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6437 {
6438   if(getFileName().empty())
6439     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6440   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6441   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6442   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6443   return ret.retn();
6444 }
6445
6446 /*!
6447  * Returns a new MEDCouplingFieldDouble of a given type lying on
6448  * the top level cells of the first mesh in MED file. If \a this field 
6449  * has not been constructed via file reading, an exception is thrown.
6450  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6451  *  \param [in] type - a spatial discretization of interest.
6452  *  \param [in] renumPol - specifies how to permute values of the result field according to
6453  *          the optional numbers of cells and nodes, if any. The valid values are
6454  *          - 0 - do not permute.
6455  *          - 1 - permute cells.
6456  *          - 2 - permute nodes.
6457  *          - 3 - permute cells and nodes.
6458  *
6459  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6460  *          caller is to delete this field using decrRef() as it is no more needed. 
6461  *  \throw If \a this field has not been constructed via file reading.
6462  *  \throw If the MED file is not readable.
6463  *  \throw If there is no mesh in the MED file.
6464  *  \throw If no field values of the given \a type.
6465  *  \throw If no field values lying on the top level support.
6466  *  \sa getFieldAtLevel()
6467  */
6468 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6469 {
6470   if(getFileName().empty())
6471     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6472   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6473   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6474   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6475   return ret.retn();
6476 }
6477
6478 /*!
6479  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6480  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6481  *  \param [in] type - a spatial discretization of the new field.
6482  *  \param [in] mesh - the supporting mesh.
6483  *  \param [in] renumPol - specifies how to permute values of the result field according to
6484  *          the optional numbers of cells and nodes, if any. The valid values are
6485  *          - 0 - do not permute.
6486  *          - 1 - permute cells.
6487  *          - 2 - permute nodes.
6488  *          - 3 - permute cells and nodes.
6489  *
6490  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6491  *          caller is to delete this field using decrRef() as it is no more needed. 
6492  *  \throw If no field of \a this is lying on \a mesh.
6493  *  \throw If the mesh is empty.
6494  *  \throw If no field values of the given \a type are available.
6495  *  \sa getFieldAtLevel()
6496  *  \sa getFieldOnMeshAtLevel() 
6497  */
6498 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6499 {
6500   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6501   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6502   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6503   return ret.retn();
6504 }
6505
6506 /*!
6507  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6508  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6509  *  \param [in] type - a spatial discretization of interest.
6510  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6511  *  \param [in] mesh - the supporting mesh.
6512  *  \param [in] renumPol - specifies how to permute values of the result field according to
6513  *          the optional numbers of cells and nodes, if any. The valid values are
6514  *          - 0 - do not permute.
6515  *          - 1 - permute cells.
6516  *          - 2 - permute nodes.
6517  *          - 3 - permute cells and nodes.
6518  *
6519  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6520  *          caller is to delete this field using decrRef() as it is no more needed. 
6521  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6522  *  \throw If no field of \a this is lying on \a mesh.
6523  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6524  *  \sa getFieldAtLevel()
6525  *  \sa getFieldOnMeshAtLevel() 
6526  */
6527 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6528 {
6529   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6530   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6531   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6532   return ret.retn();
6533 }
6534
6535 /*!
6536  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6537  * This method is called "Old" because in MED3 norm a field has only one meshName
6538  * attached, so this method is for readers of MED2 files. If \a this field 
6539  * has not been constructed via file reading, an exception is thrown.
6540  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6541  *  \param [in] type - a spatial discretization of interest.
6542  *  \param [in] mName - a name of the supporting mesh.
6543  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6544  *  \param [in] renumPol - specifies how to permute values of the result field according to
6545  *          the optional numbers of cells and nodes, if any. The valid values are
6546  *          - 0 - do not permute.
6547  *          - 1 - permute cells.
6548  *          - 2 - permute nodes.
6549  *          - 3 - permute cells and nodes.
6550  *
6551  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6552  *          caller is to delete this field using decrRef() as it is no more needed. 
6553  *  \throw If the MED file is not readable.
6554  *  \throw If there is no mesh named \a mName in the MED file.
6555  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6556  *  \throw If \a this field has not been constructed via file reading.
6557  *  \throw If no field of \a this is lying on the mesh named \a mName.
6558  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6559  *  \sa getFieldAtLevel()
6560  */
6561 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6562 {
6563   if(getFileName().empty())
6564     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6565   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6566   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6567   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6568   return ret.retn();
6569 }
6570
6571 /*!
6572  * Returns values and a profile of the field of a given type lying on a given support.
6573  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6574  *  \param [in] type - a spatial discretization of the field.
6575  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6576  *  \param [in] mesh - the supporting mesh.
6577  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6578  *          field of interest lies on. If the field lies on all entities of the given
6579  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6580  *          using decrRef() as it is no more needed.  
6581  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6582  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6583  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6584  *  \throw If no field of \a this is lying on \a mesh.
6585  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6586  */
6587 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6588 {
6589   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6590   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6591 }
6592
6593 /*!
6594  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6595  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6596  * "Sort By Type"), if not, an exception is thrown. 
6597  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6598  *  \param [in] field - the field to add to \a this.
6599  *  \throw If the name of \a field is empty.
6600  *  \throw If the data array of \a field is not set.
6601  *  \throw If the data array is already allocated but has different number of components
6602  *         than \a field.
6603  *  \throw If the underlying mesh of \a field has no name.
6604  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6605  */
6606 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6607 {
6608   setFileName("");
6609   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6610 }
6611
6612 /*!
6613  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6614  * can be an aggregation of several MEDCouplingFieldDouble instances.
6615  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6616  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6617  * and \a profile.
6618  *
6619  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6620  * A new profile is added only if no equal profile is missing.
6621  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6622  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6623  *  \param [in] mesh - the supporting mesh of \a field.
6624  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6625  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6626  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6627  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6628  *  \throw If the data array of \a field is not set.
6629  *  \throw If the data array of \a this is already allocated but has different number of
6630  *         components than \a field.
6631  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6632  *  \sa setFieldNoProfileSBT()
6633  */
6634 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6635 {
6636   setFileName("");
6637   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6638 }
6639
6640 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6641 {
6642   return new MEDFileField1TS(*this);
6643 }
6644
6645 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6646 {
6647   return contentNotNull()->getUndergroundDataArrayDouble();
6648 }
6649
6650 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6651 {
6652   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6653 }
6654
6655 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6656                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6657 {
6658   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6659 }
6660
6661 //= MEDFileIntField1TS
6662
6663 MEDFileIntField1TS *MEDFileIntField1TS::New()
6664 {
6665   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6666   ret->contentNotNull();
6667   return ret.retn();
6668 }
6669
6670 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6671 {
6672   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6673   ret->contentNotNull();
6674   return ret.retn();
6675 }
6676
6677 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6678 {
6679   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6680   ret->contentNotNull();
6681   return ret.retn();
6682 }
6683
6684 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6685 {
6686   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6687   ret->contentNotNull();
6688   return ret.retn();
6689 }
6690
6691 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6692 {
6693   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6694   ret->contentNotNull();
6695   return ret.retn();
6696 }
6697
6698 MEDFileIntField1TS::MEDFileIntField1TS()
6699 {
6700   _content=new MEDFileIntField1TSWithoutSDA;
6701 }
6702
6703 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6704 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6705 {
6706 }
6707 catch(INTERP_KERNEL::Exception& e)
6708 { throw e; }
6709
6710 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6711 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6712 {
6713 }
6714 catch(INTERP_KERNEL::Exception& e)
6715 { throw e; }
6716
6717 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6718 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6719 {
6720 }
6721 catch(INTERP_KERNEL::Exception& e)
6722 { throw e; }
6723
6724 /*!
6725  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6726  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6727  *
6728  * \warning this is a shallow copy constructor
6729  */
6730 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6731 {
6732 }
6733
6734 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6735 {
6736   return new MEDFileIntField1TS(*this);
6737 }
6738
6739 /*!
6740  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6741  * following the given input policy.
6742  *
6743  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6744  *                            By default (true) the globals are deeply copied.
6745  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6746  */
6747 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6748 {
6749   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6750   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6751   if(content)
6752     {
6753       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6754       if(!contc)
6755         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6756       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6757       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6758     }
6759   else
6760     ret=MEDFileField1TS::New();
6761   if(isDeepCpyGlobs)
6762     ret->deepCpyGlobs(*this);
6763   else
6764     ret->shallowCpyGlobs(*this);
6765   return ret.retn();
6766 }
6767
6768 /*!
6769  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6770  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6771  * "Sort By Type"), if not, an exception is thrown. 
6772  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6773  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6774  *  \param [in] arrOfVals - the values of the field \a field used.
6775  *  \throw If the name of \a field is empty.
6776  *  \throw If the data array of \a field is not set.
6777  *  \throw If the data array is already allocated but has different number of components
6778  *         than \a field.
6779  *  \throw If the underlying mesh of \a field has no name.
6780  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6781  */
6782 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6783 {
6784   setFileName("");
6785   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6786 }
6787
6788 /*!
6789  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6790  * can be an aggregation of several MEDCouplingFieldDouble instances.
6791  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6792  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6793  * and \a profile.
6794  *
6795  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6796  * A new profile is added only if no equal profile is missing.
6797  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6798  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6799  *  \param [in] arrOfVals - the values of the field \a field used.
6800  *  \param [in] mesh - the supporting mesh of \a field.
6801  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6802  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6803  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6804  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6805  *  \throw If the data array of \a field is not set.
6806  *  \throw If the data array of \a this is already allocated but has different number of
6807  *         components than \a field.
6808  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6809  *  \sa setFieldNoProfileSBT()
6810  */
6811 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6812 {
6813   setFileName("");
6814   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6815 }
6816
6817 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6818 {
6819   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6820   if(!pt)
6821     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6822   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6823   if(!ret)
6824     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 !");
6825   return ret;
6826 }
6827
6828 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6829 {
6830   if(getFileName().empty())
6831     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6832   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6833   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6834   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6835   if(!arrOutC)
6836     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6837   arrOut=arrOutC;
6838   arrOut->incrRef();  // arrOut2 dies at the end of the func
6839   return ret.retn();
6840 }
6841
6842 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6843 {
6844   if(!((DataArray *)arr))
6845     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6846   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6847   if(!arrC)
6848     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6849   arrC->incrRef();
6850   return arrC;
6851 }
6852
6853 /*!
6854  * Returns a new MEDCouplingFieldDouble of a given type lying on
6855  * the top level cells of the first mesh in MED file. If \a this field 
6856  * has not been constructed via file reading, an exception is thrown.
6857  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6858  *  \param [in] type - a spatial discretization of interest.
6859  *  \param [out] arrOut - the DataArrayInt containing values of field.
6860  *  \param [in] renumPol - specifies how to permute values of the result field according to
6861  *          the optional numbers of cells and nodes, if any. The valid values are
6862  *          - 0 - do not permute.
6863  *          - 1 - permute cells.
6864  *          - 2 - permute nodes.
6865  *          - 3 - permute cells and nodes.
6866  *
6867  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6868  *          caller is to delete this field using decrRef() as it is no more needed. 
6869  *  \throw If \a this field has not been constructed via file reading.
6870  *  \throw If the MED file is not readable.
6871  *  \throw If there is no mesh in the MED file.
6872  *  \throw If no field values of the given \a type.
6873  *  \throw If no field values lying on the top level support.
6874  *  \sa getFieldAtLevel()
6875  */
6876 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6877 {
6878   if(getFileName().empty())
6879     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6880   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6881   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6882   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6883   return ret.retn();
6884 }
6885
6886 /*!
6887  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6888  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6889  *  \param [in] type - a spatial discretization of the new field.
6890  *  \param [in] mesh - the supporting mesh.
6891  *  \param [out] arrOut - the DataArrayInt containing values of field.
6892  *  \param [in] renumPol - specifies how to permute values of the result field according to
6893  *          the optional numbers of cells and nodes, if any. The valid values are
6894  *          - 0 - do not permute.
6895  *          - 1 - permute cells.
6896  *          - 2 - permute nodes.
6897  *          - 3 - permute cells and nodes.
6898  *
6899  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6900  *          caller is to delete this field using decrRef() as it is no more needed. 
6901  *  \throw If no field of \a this is lying on \a mesh.
6902  *  \throw If the mesh is empty.
6903  *  \throw If no field values of the given \a type are available.
6904  *  \sa getFieldAtLevel()
6905  *  \sa getFieldOnMeshAtLevel() 
6906  */
6907 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6908 {
6909   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6910   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6911   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6912   return ret.retn();
6913 }
6914
6915 /*!
6916  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6917  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6918  *  \param [in] type - a spatial discretization of interest.
6919  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6920  *  \param [out] arrOut - the DataArrayInt containing values of field.
6921  *  \param [in] mesh - the supporting mesh.
6922  *  \param [in] renumPol - specifies how to permute values of the result field according to
6923  *          the optional numbers of cells and nodes, if any. The valid values are
6924  *          - 0 - do not permute.
6925  *          - 1 - permute cells.
6926  *          - 2 - permute nodes.
6927  *          - 3 - permute cells and nodes.
6928  *
6929  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6930  *          caller is to delete this field using decrRef() as it is no more needed. 
6931  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6932  *  \throw If no field of \a this is lying on \a mesh.
6933  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6934  *  \sa getFieldAtLevel()
6935  *  \sa getFieldOnMeshAtLevel() 
6936  */
6937 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6938 {
6939   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6940   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6941   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6942   return ret.retn();
6943 }
6944
6945 /*!
6946  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6947  * This method is called "Old" because in MED3 norm a field has only one meshName
6948  * attached, so this method is for readers of MED2 files. If \a this field 
6949  * has not been constructed via file reading, an exception is thrown.
6950  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6951  *  \param [in] type - a spatial discretization of interest.
6952  *  \param [in] mName - a name of the supporting mesh.
6953  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6954  *  \param [out] arrOut - the DataArrayInt containing values of field.
6955  *  \param [in] renumPol - specifies how to permute values of the result field according to
6956  *          the optional numbers of cells and nodes, if any. The valid values are
6957  *          - 0 - do not permute.
6958  *          - 1 - permute cells.
6959  *          - 2 - permute nodes.
6960  *          - 3 - permute cells and nodes.
6961  *
6962  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6963  *          caller is to delete this field using decrRef() as it is no more needed. 
6964  *  \throw If the MED file is not readable.
6965  *  \throw If there is no mesh named \a mName in the MED file.
6966  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6967  *  \throw If \a this field has not been constructed via file reading.
6968  *  \throw If no field of \a this is lying on the mesh named \a mName.
6969  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6970  *  \sa getFieldAtLevel()
6971  */
6972 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6973 {
6974   if(getFileName().empty())
6975     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6976   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6977   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6978   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6979   return ret.retn();
6980 }
6981
6982 /*!
6983  * Returns values and a profile of the field of a given type lying on a given support.
6984  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6985  *  \param [in] type - a spatial discretization of the field.
6986  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6987  *  \param [in] mesh - the supporting mesh.
6988  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6989  *          field of interest lies on. If the field lies on all entities of the given
6990  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6991  *          using decrRef() as it is no more needed.  
6992  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6993  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6994  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6995  *  \throw If no field of \a this is lying on \a mesh.
6996  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6997  */
6998 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6999 {
7000   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7001   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7002 }
7003
7004 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7005 {
7006   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7007   if(!pt)
7008     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7009   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7010   if(!ret)
7011     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 !");
7012   return ret;
7013 }
7014
7015 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7016 {
7017   return contentNotNull()->getUndergroundDataArrayInt();
7018 }
7019
7020 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7021
7022 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7023 {
7024 }
7025
7026 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7027 {
7028 }
7029
7030 /*!
7031  * \param [in] fieldId field id in C mode
7032  */
7033 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7034 {
7035   med_field_type typcha;
7036   std::string dtunitOut;
7037   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
7038   setDtUnit(dtunitOut.c_str());
7039   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7040 }
7041
7042 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)
7043 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7044 {
7045   setDtUnit(dtunit.c_str());
7046   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7047 }
7048 catch(INTERP_KERNEL::Exception& e)
7049 {
7050     throw e;
7051 }
7052
7053 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7054 {
7055   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>));
7056   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7057     ret+=(*it).capacity();
7058   return ret;
7059 }
7060
7061 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7062 {
7063   std::vector<const BigMemoryObject *> ret;
7064   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7065     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7066   return ret;
7067 }
7068
7069 /*!
7070  * 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
7071  * NULL.
7072  */
7073 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7074 {
7075   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7076   ret->setInfo(_infos);
7077   int sz=(int)_time_steps.size();
7078   for(const int *id=startIds;id!=endIds;id++)
7079     {
7080       if(*id>=0 && *id<sz)
7081         {
7082           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7083           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7084           if(tse)
7085             {
7086               tse->incrRef();
7087               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7088             }
7089           ret->pushBackTimeStep(tse2);
7090         }
7091       else
7092         {
7093           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7094           oss << " ! Should be in [0," << sz << ") !";
7095           throw INTERP_KERNEL::Exception(oss.str().c_str());
7096         }
7097     }
7098   if(ret->getNumberOfTS()>0)
7099     ret->synchronizeNameScope();
7100   ret->copyNameScope(*this);
7101   return ret.retn();
7102 }
7103
7104 /*!
7105  * 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
7106  * NULL.
7107  */
7108 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7109 {
7110   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7111   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7112   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7113   ret->setInfo(_infos);
7114   int sz=(int)_time_steps.size();
7115   int j=bg;
7116   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7117     {
7118       if(j>=0 && j<sz)
7119         {
7120           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7121           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7122           if(tse)
7123             {
7124               tse->incrRef();
7125               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7126             }
7127           ret->pushBackTimeStep(tse2);
7128         }
7129       else
7130         {
7131           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7132           oss << " ! Should be in [0," << sz << ") !";
7133           throw INTERP_KERNEL::Exception(oss.str().c_str());
7134         }
7135     }
7136   if(ret->getNumberOfTS()>0)
7137     ret->synchronizeNameScope();
7138   ret->copyNameScope(*this);
7139   return ret.retn();
7140 }
7141
7142 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7143 {
7144   int id=0;
7145   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7146   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7147     {
7148       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7149       if(!cur)
7150         continue;
7151       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7152       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7153         ids->pushBackSilent(id);
7154     }
7155   return buildFromTimeStepIds(ids->begin(),ids->end());
7156 }
7157
7158 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7159 {
7160   int id=0;
7161   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7162   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7163     {
7164       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7165       if(!cur)
7166         continue;
7167       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7168       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7169         ids->pushBackSilent(id);
7170     }
7171   return buildFromTimeStepIds(ids->begin(),ids->end());
7172 }
7173
7174 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7175 {
7176   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7177     {
7178       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7179       if(!cur)
7180         continue;
7181       if(cur->presenceOfMultiDiscPerGeoType())
7182         return true;
7183     }
7184   return false;
7185 }
7186
7187 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7188 {
7189   return _infos;
7190 }
7191
7192 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7193 {
7194   _infos=info;
7195 }
7196
7197 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7198 {
7199   int ret=0;
7200   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7201     {
7202       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7203       if(pt->isDealingTS(iteration,order))
7204         return ret;
7205     }
7206   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7207   std::vector< std::pair<int,int> > vp=getIterations();
7208   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7209     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7210   throw INTERP_KERNEL::Exception(oss.str().c_str());
7211 }
7212
7213 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7214 {
7215   return *_time_steps[getTimeStepPos(iteration,order)];
7216 }
7217
7218 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7219 {
7220   return *_time_steps[getTimeStepPos(iteration,order)];
7221 }
7222
7223 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7224 {
7225   if(_time_steps.empty())
7226     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7227   return _time_steps[0]->getMeshName();
7228 }
7229
7230 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7231 {
7232   std::string oldName(getMeshName());
7233   std::vector< std::pair<std::string,std::string> > v(1);
7234   v[0].first=oldName; v[0].second=newMeshName;
7235   changeMeshNames(v);
7236 }
7237
7238 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7239 {
7240   bool ret=false;
7241   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7242     {
7243       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7244       if(cur)
7245         ret=cur->changeMeshNames(modifTab) || ret;
7246     }
7247   return ret;
7248 }
7249
7250 /*!
7251  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7252  */
7253 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7254 {
7255   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7256 }
7257
7258 /*!
7259  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7260  */
7261 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7262 {
7263   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7264 }
7265
7266 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7267                                                                        MEDFileFieldGlobsReal& glob)
7268 {
7269   bool ret=false;
7270   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7271     {
7272       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7273       if(f1ts)
7274         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7275     }
7276   return ret;
7277 }
7278
7279 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7280 {
7281   std::string startLine(bkOffset,' ');
7282   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7283   if(fmtsId>=0)
7284     oss << " (" << fmtsId << ")";
7285   oss << " has the following name: \"" << _name << "\"." << std::endl;
7286   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7287   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7288     {
7289       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7290     }
7291   int i=0;
7292   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7293     {
7294       std::string chapter(17,'0'+i);
7295       oss << startLine << chapter << std::endl;
7296       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7297       if(cur)
7298         cur->simpleRepr(bkOffset+2,oss,i);
7299       else
7300         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7301       oss << startLine << chapter << std::endl;
7302     }
7303 }
7304
7305 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7306 {
7307   std::size_t sz=_time_steps.size();
7308   std::vector< std::pair<int,int> > ret(sz);
7309   ret1.resize(sz);
7310   for(std::size_t i=0;i<sz;i++)
7311     {
7312       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7313       if(f1ts)
7314         {
7315           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7316         }
7317       else
7318         {
7319           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7320           throw INTERP_KERNEL::Exception(oss.str().c_str());
7321         }
7322     }
7323   return ret;
7324 }
7325
7326 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7327 {
7328   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7329   if(!tse2)
7330     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7331   checkCoherencyOfType(tse2);
7332   if(_time_steps.empty())
7333     {
7334       setName(tse2->getName().c_str());
7335       setInfo(tse2->getInfo());
7336     }
7337   checkThatComponentsMatch(tse2->getInfo());
7338   _time_steps.push_back(tse);
7339 }
7340
7341 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7342 {
7343   std::size_t nbOfCompo=_infos.size();
7344   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7345     {
7346       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7347       if(cur)
7348         {
7349           if((cur->getInfo()).size()!=nbOfCompo)
7350             {
7351               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7352               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7353               throw INTERP_KERNEL::Exception(oss.str().c_str());
7354             }
7355           cur->copyNameScope(*this);
7356         }
7357     }
7358 }
7359
7360 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)
7361 {
7362   _time_steps.resize(nbPdt);
7363   for(int i=0;i<nbPdt;i++)
7364     {
7365       std::vector< std::pair<int,int> > ts;
7366       med_int numdt=0,numo=0;
7367       med_int meshIt=0,meshOrder=0;
7368       med_float dt=0.0;
7369       MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder));
7370       switch(fieldTyp)
7371       {
7372         case MED_FLOAT64:
7373           {
7374             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7375             break;
7376           }
7377         case MED_INT32:
7378           {
7379             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7380             break;
7381           }
7382         default:
7383           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7384       }
7385       if(loadAll)
7386         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7387       else
7388         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7389     }
7390 }
7391
7392 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7393 {
7394   if(_time_steps.empty())
7395     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7396   checkThatNbOfCompoOfTSMatchThis();
7397   std::vector<std::string> infos(getInfo());
7398   int nbComp=infos.size();
7399   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7400   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7401   for(int i=0;i<nbComp;i++)
7402     {
7403       std::string info=infos[i];
7404       std::string c,u;
7405       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7406       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7407       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7408     }
7409   if(_name.empty())
7410     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7411   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7412   int nbOfTS=_time_steps.size();
7413   for(int i=0;i<nbOfTS;i++)
7414     _time_steps[i]->writeLL(fid,opts,*this);
7415 }
7416
7417 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7418 {
7419   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7420     {
7421       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7422       if(elt)
7423         elt->loadBigArraysRecursively(fid,nasc);
7424     }
7425 }
7426
7427 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7428 {
7429   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7430     {
7431       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7432       if(elt)
7433         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7434     }
7435 }
7436
7437 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7438 {
7439   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7440     {
7441       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7442       if(elt)
7443         elt->unloadArrays();
7444     }
7445 }
7446
7447 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7448 {
7449   return _time_steps.size();
7450 }
7451
7452 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7453 {
7454   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7455   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7456     {
7457       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7458       if(tmp)
7459         newTS.push_back(*it);
7460     }
7461   _time_steps=newTS;
7462 }
7463
7464 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7465 {
7466   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7467   int maxId=(int)_time_steps.size();
7468   int ii=0;
7469   std::set<int> idsToDel;
7470   for(const int *id=startIds;id!=endIds;id++,ii++)
7471     {
7472       if(*id>=0 && *id<maxId)
7473         {
7474           idsToDel.insert(*id);
7475         }
7476       else
7477         {
7478           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7479           throw INTERP_KERNEL::Exception(oss.str().c_str());
7480         }
7481     }
7482   for(int iii=0;iii<maxId;iii++)
7483     if(idsToDel.find(iii)==idsToDel.end())
7484       newTS.push_back(_time_steps[iii]);
7485   _time_steps=newTS;
7486 }
7487
7488 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7489 {
7490   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7491   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7492   if(nbOfEntriesToKill==0)
7493     return ;
7494   std::size_t sz=_time_steps.size();
7495   std::vector<bool> b(sz,true);
7496   int j=bg;
7497   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7498     b[j]=false;
7499   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7500   for(std::size_t i=0;i<sz;i++)
7501     if(b[i])
7502       newTS.push_back(_time_steps[i]);
7503   _time_steps=newTS;
7504 }
7505
7506 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7507 {
7508   int ret=0;
7509   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7510   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7511     {
7512       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7513       if(tmp)
7514         {
7515           int it2,ord;
7516           tmp->getTime(it2,ord);
7517           if(it2==iteration && order==ord)
7518             return ret;
7519           else
7520             oss << "(" << it2 << ","  << ord << "), ";
7521         }
7522     }
7523   throw INTERP_KERNEL::Exception(oss.str().c_str());
7524 }
7525
7526 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7527 {
7528   int ret=0;
7529   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7530   oss.precision(15);
7531   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7532     {
7533       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7534       if(tmp)
7535         {
7536           int it2,ord;
7537           double ti=tmp->getTime(it2,ord);
7538           if(fabs(time-ti)<eps)
7539             return ret;
7540           else
7541             oss << ti << ", ";
7542         }
7543     }
7544   throw INTERP_KERNEL::Exception(oss.str().c_str());
7545 }
7546
7547 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7548 {
7549   int lgth=_time_steps.size();
7550   std::vector< std::pair<int,int> > ret(lgth);
7551   for(int i=0;i<lgth;i++)
7552     _time_steps[i]->fillIteration(ret[i]);
7553   return ret;
7554 }
7555
7556 /*!
7557  * 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'
7558  * This method returns two things.
7559  * - The absolute dimension of 'this' in first parameter. 
7560  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7561  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7562  *
7563  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7564  * Only these 3 discretizations will be taken into account here.
7565  *
7566  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7567  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7568  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7569  *
7570  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7571  * 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'.
7572  * 
7573  * Let's consider the typical following case :
7574  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7575  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7576  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7577  *   TETRA4 and SEG2
7578  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7579  *
7580  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7581  * 
7582  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7583  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7584  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7585  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7586  */
7587 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7588 {
7589   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7590 }
7591
7592 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7593 {
7594   if(pos<0 || pos>=(int)_time_steps.size())
7595     {
7596       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7597       throw INTERP_KERNEL::Exception(oss.str().c_str());
7598     }
7599   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7600   if(item==0)
7601     {
7602       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7603       oss << "\nTry to use following method eraseEmptyTS !";
7604       throw INTERP_KERNEL::Exception(oss.str().c_str());
7605     }
7606   return item;
7607 }
7608
7609 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7610 {
7611   if(pos<0 || pos>=(int)_time_steps.size())
7612     {
7613       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7614       throw INTERP_KERNEL::Exception(oss.str().c_str());
7615     }
7616   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7617   if(item==0)
7618     {
7619       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7620       oss << "\nTry to use following method eraseEmptyTS !";
7621       throw INTERP_KERNEL::Exception(oss.str().c_str());
7622     }
7623   return item;
7624 }
7625
7626 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7627 {
7628   std::vector<std::string> ret;
7629   std::set<std::string> ret2;
7630   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7631     {
7632       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7633       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7634         if(ret2.find(*it2)==ret2.end())
7635           {
7636             ret.push_back(*it2);
7637             ret2.insert(*it2);
7638           }
7639     }
7640   return ret;
7641 }
7642
7643 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7644 {
7645   std::vector<std::string> ret;
7646   std::set<std::string> ret2;
7647   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7648     {
7649       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7650       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7651         if(ret2.find(*it2)==ret2.end())
7652           {
7653             ret.push_back(*it2);
7654             ret2.insert(*it2);
7655           }
7656     }
7657   return ret;
7658 }
7659
7660 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7661 {
7662   std::vector<std::string> ret;
7663   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7664     {
7665       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7666       ret.insert(ret.end(),tmp.begin(),tmp.end());
7667     }
7668   return ret;
7669 }
7670
7671 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7672 {
7673   std::vector<std::string> ret;
7674   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7675     {
7676       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7677       ret.insert(ret.end(),tmp.begin(),tmp.end());
7678     }
7679   return ret;
7680 }
7681
7682 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7683 {
7684   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7685     (*it)->changePflsRefsNamesGen2(mapOfModif);
7686 }
7687
7688 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7689 {
7690   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7691     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7692 }
7693
7694 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7695 {
7696   int lgth=_time_steps.size();
7697   std::vector< std::vector<TypeOfField> > ret(lgth);
7698   for(int i=0;i<lgth;i++)
7699     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7700   return ret;
7701 }
7702
7703 /*!
7704  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7705  */
7706 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
7707 {
7708   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7709 }
7710
7711 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const
7712 {
7713   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7714   std::size_t i=0;
7715   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7716     {
7717       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7718         ret->_time_steps[i]=(*it)->deepCpy();
7719     }
7720   return ret.retn();
7721 }
7722
7723 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7724 {
7725   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7726   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7727   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7728   for(std::size_t i=0;i<sz;i++)
7729     {
7730       ret[i]=shallowCpy();
7731       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7732     }
7733   for(std::size_t i=0;i<sz2;i++)
7734     {
7735       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7736       if(ret1.size()!=sz)
7737         {
7738           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7739           throw INTERP_KERNEL::Exception(oss.str().c_str());
7740         }
7741       ts[i]=ret1;
7742     }
7743   for(std::size_t i=0;i<sz;i++)
7744     for(std::size_t j=0;j<sz2;j++)
7745       ret[i]->_time_steps[j]=ts[j][i];
7746   return ret;
7747 }
7748
7749 /*!
7750  * This method splits into discretization each time steps in \a this.
7751  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7752  */
7753 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7754 {
7755   std::size_t sz(_time_steps.size());
7756   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7757   for(std::size_t i=0;i<sz;i++)
7758     {
7759       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7760       if(!timeStep)
7761         {
7762           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7763           throw INTERP_KERNEL::Exception(oss.str().c_str());
7764         }
7765       items[i]=timeStep->splitDiscretizations();  
7766     }
7767   //
7768   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7769   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7770   std::vector< TypeOfField > types;
7771   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7772     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7773       {
7774         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7775         if(ts.size()!=1)
7776           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7777         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7778         if(it2==types.end())
7779           types.push_back(ts[0]);
7780       }
7781   ret.resize(types.size()); ret2.resize(types.size());
7782   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7783     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7784       {
7785         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7786         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7787         ret2[pos].push_back(*it1);
7788       }
7789   for(std::size_t i=0;i<types.size();i++)
7790     {
7791       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7792       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7793         elt->pushBackTimeStep(*it1);//also updates infos in elt
7794       ret[i]=elt;
7795       elt->MEDFileFieldNameScope::operator=(*this);
7796     }
7797   return ret;
7798 }
7799
7800 /*!
7801  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7802  */
7803 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7804 {
7805   std::size_t sz(_time_steps.size());
7806   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7807   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7808   for(std::size_t i=0;i<sz;i++)
7809     {
7810       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7811       if(!timeStep)
7812         {
7813           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7814           throw INTERP_KERNEL::Exception(oss.str().c_str());
7815         }
7816       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7817       if(szOut==std::numeric_limits<std::size_t>::max())
7818         szOut=items[i].size();
7819       else
7820         if(items[i].size()!=szOut)
7821           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7822     }
7823   if(szOut==std::numeric_limits<std::size_t>::max())
7824     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7825   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7826   for(std::size_t i=0;i<szOut;i++)
7827     {
7828       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7829       for(std::size_t j=0;j<sz;j++)
7830         elt->pushBackTimeStep(items[j][i]);
7831       ret[i]=elt;
7832       elt->MEDFileFieldNameScope::operator=(*this);
7833     }
7834   return ret;
7835 }
7836
7837 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7838 {
7839   _name=field->getName();
7840   if(_name.empty())
7841     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7842   if(!arr)
7843     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7844   _infos=arr->getInfoOnComponents();
7845 }
7846
7847 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7848 {
7849   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7850   if(_name!=field->getName())
7851     {
7852       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7853       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7854       throw INTERP_KERNEL::Exception(oss.str().c_str());
7855     }
7856   if(!arr)
7857     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7858   checkThatComponentsMatch(arr->getInfoOnComponents());
7859 }
7860
7861 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7862 {
7863   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7864   if(getInfo().size()!=compos.size())
7865     {
7866       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7867       oss << " number of components of element to append (" << compos.size() << ") !";
7868       throw INTERP_KERNEL::Exception(oss.str().c_str());
7869     }
7870   if(_infos!=compos)
7871     {
7872       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7873       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7874       oss << " But compo in input fields are : ";
7875       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7876       oss << " !";
7877       throw INTERP_KERNEL::Exception(oss.str().c_str());
7878     }
7879 }
7880
7881 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7882 {
7883   std::size_t sz=_infos.size();
7884   int j=0;
7885   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7886     {
7887       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7888       if(elt)
7889         if(elt->getInfo().size()!=sz)
7890           {
7891             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7892             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7893             throw INTERP_KERNEL::Exception(oss.str().c_str());
7894           }
7895     }
7896 }
7897
7898 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7899 {
7900   if(!field)
7901     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7902   if(!_time_steps.empty())
7903     checkCoherencyOfTinyInfo(field,arr);
7904   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7905   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7906   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7907   copyTinyInfoFrom(field,arr);
7908   _time_steps.push_back(obj);
7909 }
7910
7911 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7912 {
7913   if(!field)
7914     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7915   if(!_time_steps.empty())
7916     checkCoherencyOfTinyInfo(field,arr);
7917   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7918   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7919   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7920   copyTinyInfoFrom(field,arr);
7921   _time_steps.push_back(obj);
7922 }
7923
7924 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts)
7925 {
7926   int sz=(int)_time_steps.size();
7927   if(i<0 || i>=sz)
7928     {
7929       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7930       throw INTERP_KERNEL::Exception(oss.str().c_str());
7931     }
7932   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7933   if(tsPtr)
7934     {
7935       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7936         {
7937           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7938           throw INTERP_KERNEL::Exception(oss.str().c_str());
7939         }
7940     }
7941   _time_steps[i]=ts;
7942 }
7943
7944 //= MEDFileFieldMultiTSWithoutSDA
7945
7946 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)
7947 {
7948   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
7949 }
7950
7951 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7952 {
7953 }
7954
7955 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7956 {
7957 }
7958
7959 /*!
7960  * \param [in] fieldId field id in C mode
7961  */
7962 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7963 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
7964 {
7965 }
7966 catch(INTERP_KERNEL::Exception& e)
7967 { throw e; }
7968
7969 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)
7970 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
7971 {
7972 }
7973 catch(INTERP_KERNEL::Exception& e)
7974 { throw e; }
7975
7976 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7977 {
7978   return new MEDFileField1TSWithoutSDA;
7979 }
7980
7981 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7982 {
7983   if(!f1ts)
7984     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7985   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7986   if(!f1tsC)
7987     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7988 }
7989
7990 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7991 {
7992   return MEDFileField1TSWithoutSDA::TYPE_STR;
7993 }
7994
7995 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7996 {
7997   return new MEDFileFieldMultiTSWithoutSDA(*this);
7998 }
7999
8000 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8001 {
8002   return new MEDFileFieldMultiTSWithoutSDA;
8003 }
8004
8005 /*!
8006  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8007  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8008  */
8009 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
8010 {
8011   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8012   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8013   if(!myF1TSC)
8014     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8015   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8016 }
8017
8018 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8019 {
8020   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8021   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8022   int i=0;
8023   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8024     {
8025       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8026       if(eltToConv)
8027         {
8028           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8029           if(!eltToConvC)
8030             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8031           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8032           ret->setIteration(i,elt);
8033         }
8034     }
8035   return ret.retn();
8036 }
8037
8038 //= MEDFileAnyTypeFieldMultiTS
8039
8040 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8041 {
8042 }
8043
8044 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8045 try:MEDFileFieldGlobsReal(fileName)
8046 {
8047   MEDFileUtilities::CheckFileForRead(fileName);
8048   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8049   _content=BuildContentFrom(fid,fileName,loadAll,ms);
8050   loadGlobals(fid);
8051 }
8052 catch(INTERP_KERNEL::Exception& e)
8053 {
8054     throw e;
8055 }
8056
8057 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)
8058 {
8059   med_field_type typcha;
8060   std::vector<std::string> infos;
8061   std::string dtunit;
8062   int i=-1;
8063   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
8064   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8065   switch(typcha)
8066   {
8067     case MED_FLOAT64:
8068       {
8069         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8070         break;
8071       }
8072     case MED_INT32:
8073       {
8074         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8075         break;
8076       }
8077     default:
8078       {
8079         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] !";
8080         throw INTERP_KERNEL::Exception(oss.str().c_str());
8081       }
8082   }
8083   ret->setDtUnit(dtunit.c_str());
8084   return ret.retn();
8085 }
8086
8087 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8088 {
8089   med_field_type typcha;
8090   //
8091   std::vector<std::string> infos;
8092   std::string dtunit,fieldName;
8093   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
8094   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8095   switch(typcha)
8096   {
8097     case MED_FLOAT64:
8098       {
8099         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8100         break;
8101       }
8102     case MED_INT32:
8103       {
8104         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8105         break;
8106       }
8107     default:
8108       {
8109         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] !";
8110         throw INTERP_KERNEL::Exception(oss.str().c_str());
8111       }
8112   }
8113   ret->setDtUnit(dtunit.c_str());
8114   return ret.retn();
8115 }
8116
8117 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
8118 {
8119   if(!c)
8120     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8121   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8122     {
8123       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
8124       ret->setFileName(fileName);
8125       ret->_content=c;  c->incrRef();
8126       return ret.retn();
8127     }
8128   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8129     {
8130       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
8131       ret->setFileName(fileName);
8132       ret->_content=c;  c->incrRef();
8133       return ret.retn();
8134     }
8135   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8136 }
8137
8138 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)
8139 try:MEDFileFieldGlobsReal(fileName)
8140 {
8141   MEDFileUtilities::CheckFileForRead(fileName);
8142   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8143   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms,entities);
8144   loadGlobals(fid);
8145 }
8146 catch(INTERP_KERNEL::Exception& e)
8147 {
8148     throw e;
8149 }
8150
8151 //= MEDFileIntFieldMultiTSWithoutSDA
8152
8153 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)
8154 {
8155   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8156 }
8157
8158 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8159 {
8160 }
8161
8162 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8163 {
8164 }
8165
8166 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)
8167 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8168 {
8169 }
8170 catch(INTERP_KERNEL::Exception& e)
8171 { throw e; }
8172
8173 /*!
8174  * \param [in] fieldId field id in C mode
8175  */
8176 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8177 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8178 {
8179 }
8180 catch(INTERP_KERNEL::Exception& e)
8181 { throw e; }
8182
8183 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8184 {
8185   return new MEDFileIntField1TSWithoutSDA;
8186 }
8187
8188 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8189 {
8190   if(!f1ts)
8191     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8192   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8193   if(!f1tsC)
8194     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8195 }
8196
8197 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8198 {
8199   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8200 }
8201
8202 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8203 {
8204   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8205 }
8206
8207 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8208 {
8209   return new MEDFileIntFieldMultiTSWithoutSDA;
8210 }
8211
8212 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8213 {
8214   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8215   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8216   int i=0;
8217   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8218     {
8219       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8220       if(eltToConv)
8221         {
8222           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8223           if(!eltToConvC)
8224             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8225           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8226           ret->setIteration(i,elt);
8227         }
8228     }
8229   return ret.retn();
8230 }
8231
8232 //= MEDFileAnyTypeFieldMultiTS
8233
8234 /*!
8235  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8236  * that has been read from a specified MED file.
8237  *  \param [in] fileName - the name of the MED file to read.
8238  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8239  *          is to delete this field using decrRef() as it is no more needed.
8240  *  \throw If reading the file fails.
8241  */
8242 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8243 {
8244   MEDFileUtilities::CheckFileForRead(fileName);
8245   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8246   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
8247   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8248   ret->loadGlobals(fid);
8249   return ret.retn();
8250 }
8251
8252 /*!
8253  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8254  * that has been read from a specified MED file.
8255  *  \param [in] fileName - the name of the MED file to read.
8256  *  \param [in] fieldName - the name of the field to read.
8257  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8258  *          is to delete this field using decrRef() as it is no more needed.
8259  *  \throw If reading the file fails.
8260  *  \throw If there is no field named \a fieldName in the file.
8261  */
8262 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8263 {
8264   MEDFileUtilities::CheckFileForRead(fileName);
8265   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8266   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fileName,fieldName,loadAll,0,0));
8267   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8268   ret->loadGlobals(fid);
8269   return ret.retn();
8270 }
8271
8272 /*!
8273  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8274  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8275  *
8276  * \warning this is a shallow copy constructor
8277  */
8278 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8279 {
8280   if(!shallowCopyOfContent)
8281     {
8282       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8283       otherPtr->incrRef();
8284       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8285     }
8286   else
8287     {
8288       _content=other.shallowCpy();
8289     }
8290 }
8291
8292 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8293 {
8294   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8295   if(!ret)
8296     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8297   return ret;
8298 }
8299
8300 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8301 {
8302   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8303   if(!ret)
8304     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8305   return ret;
8306 }
8307
8308 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8309 {
8310   return contentNotNullBase()->getPflsReallyUsed2();
8311 }
8312
8313 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8314 {
8315   return contentNotNullBase()->getLocsReallyUsed2();
8316 }
8317
8318 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8319 {
8320   return contentNotNullBase()->getPflsReallyUsedMulti2();
8321 }
8322
8323 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8324 {
8325   return contentNotNullBase()->getLocsReallyUsedMulti2();
8326 }
8327
8328 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8329 {
8330   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8331 }
8332
8333 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8334 {
8335   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8336 }
8337
8338 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8339 {
8340   return contentNotNullBase()->getNumberOfTS();
8341 }
8342
8343 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8344 {
8345   contentNotNullBase()->eraseEmptyTS();
8346 }
8347
8348 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8349 {
8350   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8351 }
8352
8353 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8354 {
8355   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8356 }
8357
8358 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8359 {
8360   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8361   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8362   ret->_content=c;
8363   return ret.retn();
8364 }
8365
8366 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8367 {
8368   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8369   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8370   ret->_content=c;
8371   return ret.retn();
8372 }
8373
8374 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8375 {
8376   return contentNotNullBase()->getIterations();
8377 }
8378
8379 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8380 {
8381   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8382     pushBackTimeStep(*it);
8383 }
8384
8385 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8386 {
8387   if(!fmts)
8388     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8389   int nbOfTS(fmts->getNumberOfTS());
8390   for(int i=0;i<nbOfTS;i++)
8391     {
8392       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8393       pushBackTimeStep(elt);
8394     }
8395 }
8396
8397 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8398 {
8399   if(!f1ts)
8400     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8401   checkCoherencyOfType(f1ts);
8402   f1ts->incrRef();
8403   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8404   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8405   c->incrRef();
8406   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8407   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8408     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8409   _content->pushBackTimeStep(cSafe);
8410   appendGlobs(*f1ts,1e-12);
8411 }
8412
8413 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8414 {
8415   contentNotNullBase()->synchronizeNameScope();
8416 }
8417
8418 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8419 {
8420   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8421 }
8422
8423 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8424 {
8425   return contentNotNullBase()->getPosGivenTime(time,eps);
8426 }
8427
8428 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8429 {
8430   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8431 }
8432
8433 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8434 {
8435   return contentNotNullBase()->getTypesOfFieldAvailable();
8436 }
8437
8438 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
8439 {
8440   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8441 }
8442
8443 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8444 {
8445   return contentNotNullBase()->getName();
8446 }
8447
8448 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8449 {
8450   contentNotNullBase()->setName(name);
8451 }
8452
8453 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8454 {
8455   return contentNotNullBase()->getDtUnit();
8456 }
8457
8458 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8459 {
8460   contentNotNullBase()->setDtUnit(dtUnit);
8461 }
8462
8463 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8464 {
8465   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8466 }
8467
8468 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8469 {
8470   return contentNotNullBase()->getTimeSteps(ret1);
8471 }
8472
8473 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8474 {
8475   return contentNotNullBase()->getMeshName();
8476 }
8477
8478 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8479 {
8480   contentNotNullBase()->setMeshName(newMeshName);
8481 }
8482
8483 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8484 {
8485   return contentNotNullBase()->changeMeshNames(modifTab);
8486 }
8487
8488 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8489 {
8490   return contentNotNullBase()->getInfo();
8491 }
8492
8493 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8494 {
8495   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8496 }
8497
8498 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8499 {
8500   return contentNotNullBase()->setInfo(info);
8501 }
8502
8503 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8504 {
8505   const std::vector<std::string> ret=getInfo();
8506   return (int)ret.size();
8507 }
8508
8509 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8510 {
8511   writeGlobals(fid,*this);
8512   contentNotNullBase()->writeLL(fid,*this);
8513 }
8514
8515 /*!
8516  * Writes \a this field into a MED file specified by its name.
8517  *  \param [in] fileName - the MED file name.
8518  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8519  * - 2 - erase; an existing file is removed.
8520  * - 1 - append; same data should not be present in an existing file.
8521  * - 0 - overwrite; same data present in an existing file is overwritten.
8522  *  \throw If the field name is not set.
8523  *  \throw If no field data is set.
8524  *  \throw If \a mode == 1 and the same data is present in an existing file.
8525  */
8526 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8527 {
8528   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8529   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8530   writeLL(fid);
8531 }
8532
8533 /*!
8534  * This method alloc the arrays and load potentially huge arrays contained in this field.
8535  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8536  * This method can be also called to refresh or reinit values from a file.
8537  * 
8538  * \throw If the fileName is not set or points to a non readable MED file.
8539  */
8540 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8541 {
8542   if(getFileName().empty())
8543     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8544   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8545   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8546 }
8547
8548 /*!
8549  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8550  * But once data loaded once, this method does nothing.
8551  * 
8552  * \throw If the fileName is not set or points to a non readable MED file.
8553  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8554  */
8555 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8556 {
8557   if(!getFileName().empty())
8558     {
8559       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8560       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8561     }
8562 }
8563
8564 /*!
8565  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8566  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8567  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8568  * 
8569  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8570  */
8571 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8572 {
8573   contentNotNullBase()->unloadArrays();
8574 }
8575
8576 /*!
8577  * 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.
8578  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8579  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8580  * 
8581  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8582  */
8583 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8584 {
8585   if(!getFileName().empty())
8586     contentNotNullBase()->unloadArrays();
8587 }
8588
8589 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8590 {
8591   std::ostringstream oss;
8592   contentNotNullBase()->simpleRepr(0,oss,-1);
8593   simpleReprGlobs(oss);
8594   return oss.str();
8595 }
8596
8597 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8598 {
8599   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8600 }
8601
8602 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8603 {
8604   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8605   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8606   return ret;
8607 }
8608
8609 /*!
8610  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8611  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8612  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8613  */
8614 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8615 {
8616   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8617   if(!content)
8618     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8619   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8620   std::size_t sz(contentsSplit.size());
8621   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8622   for(std::size_t i=0;i<sz;i++)
8623     {
8624       ret[i]=shallowCpy();
8625       ret[i]->_content=contentsSplit[i];
8626     }
8627   return ret;
8628 }
8629
8630 /*!
8631  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8632  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8633  */
8634 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8635 {
8636   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8637   if(!content)
8638     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8639   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8640   std::size_t sz(contentsSplit.size());
8641   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8642   for(std::size_t i=0;i<sz;i++)
8643     {
8644       ret[i]=shallowCpy();
8645       ret[i]->_content=contentsSplit[i];
8646     }
8647   return ret;
8648 }
8649
8650 /*!
8651  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8652  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8653  */
8654 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8655 {
8656   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8657   if(!content)
8658     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8659   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8660   std::size_t sz(contentsSplit.size());
8661   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8662   for(std::size_t i=0;i<sz;i++)
8663     {
8664       ret[i]=shallowCpy();
8665       ret[i]->_content=contentsSplit[i];
8666     }
8667   return ret;
8668 }
8669
8670 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const
8671 {
8672   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8673   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8674     ret->_content=_content->deepCpy();
8675   ret->deepCpyGlobs(*this);
8676   return ret.retn();
8677 }
8678
8679 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8680 {
8681   return _content;
8682 }
8683
8684 /*!
8685  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8686  *  \param [in] iteration - the iteration number of a required time step.
8687  *  \param [in] order - the iteration order number of required time step.
8688  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8689  *          delete this field using decrRef() as it is no more needed.
8690  *  \throw If there is no required time step in \a this field.
8691  */
8692 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8693 {
8694   int pos=getPosOfTimeStep(iteration,order);
8695   return getTimeStepAtPos(pos);
8696 }
8697
8698 /*!
8699  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8700  *  \param [in] time - the time of the time step of interest.
8701  *  \param [in] eps - a precision used to compare time values.
8702  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8703  *          delete this field using decrRef() as it is no more needed.
8704  *  \throw If there is no required time step in \a this field.
8705  */
8706 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8707 {
8708   int pos=getPosGivenTime(time,eps);
8709   return getTimeStepAtPos(pos);
8710 }
8711
8712 /*!
8713  * 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.
8714  * The float64 value of time attached to the pair of integers are not considered here.
8715  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8716  *
8717  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8718  * \throw If there is a null pointer in \a vectFMTS.
8719  */
8720 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8721 {
8722   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8723   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8724   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8725   while(!lstFMTS.empty())
8726     {
8727       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8728       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8729       if(!curIt)
8730         throw INTERP_KERNEL::Exception(msg);
8731       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8732       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8733       elt.push_back(curIt); it=lstFMTS.erase(it);
8734       while(it!=lstFMTS.end())
8735         {
8736           curIt=*it;
8737           if(!curIt)
8738             throw INTERP_KERNEL::Exception(msg);
8739           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8740           if(refIts==curIts)
8741             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8742           else
8743             it++;
8744         }
8745       ret.push_back(elt);
8746     }
8747   return ret;
8748 }
8749
8750 /*!
8751  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8752  * All returned instances in a subvector can be safely loaded, rendered along time
8753  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8754  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8755  * 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).
8756  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8757  * 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.
8758  *
8759  * \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().
8760  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8761  * \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.
8762  * \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.
8763  *
8764  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8765  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8766  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8767  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8768  * \throw If mesh is null.
8769  * \throw If an element in \a vectFMTS is null.
8770  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8771  */
8772 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& fsc)
8773 {
8774   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8775   if(!mesh)
8776     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8777   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8778   if(vectFMTS.empty())
8779     return ret;
8780   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8781   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8782   if(!frstElt)
8783     throw INTERP_KERNEL::Exception(msg);
8784   std::size_t i=0;
8785   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8786   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8787   for(;it!=vectFMTS.end();it++,i++)
8788     {
8789       if(!(*it))
8790         throw INTERP_KERNEL::Exception(msg);
8791       TypeOfField tof0,tof1;
8792       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8793         {
8794           if(tof1!=ON_NODES)
8795             vectFMTSNotNodes.push_back(*it);
8796           else
8797             vectFMTSNodes.push_back(*it);
8798         }
8799       else
8800         vectFMTSNotNodes.push_back(*it);
8801     }
8802   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8803   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8804   ret=retCell;
8805   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8806     {
8807       i=0;
8808       bool isFetched(false);
8809       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8810         {
8811           if((*it0).empty())
8812             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8813           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8814             { ret[i].push_back(*it2); isFetched=true; }
8815         }
8816       if(!isFetched)
8817         {
8818           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8819           MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8820           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8821         }
8822     }
8823   fsc=cmps;
8824   return ret;
8825 }
8826
8827 /*!
8828  * 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.
8829  * \param [out] cmps - same size than the returned vector.
8830  */
8831 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps)
8832 {
8833   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8834   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8835   while(!lstFMTS.empty())
8836     {
8837       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8838       MEDFileAnyTypeFieldMultiTS *ref(*it);
8839       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8840       elt.push_back(ref); it=lstFMTS.erase(it);
8841       MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8842       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8843       while(it!=lstFMTS.end())
8844         {
8845           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8846           if(cmp->isEqual(curIt))
8847             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8848           else
8849             it++;
8850         }
8851       ret.push_back(elt); cmps.push_back(cmp);
8852     }
8853   return ret;
8854 }
8855
8856 /*!
8857  * 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.
8858  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8859  *
8860  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8861  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8862  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8863  * \thorw If \a f0 and \a f1 do not have the same times steps.
8864  * \throw If mesh is null.
8865  * \throw If \a f0 or \a f1 is null.
8866  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8867  */
8868 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8869 {
8870   if(!mesh)
8871     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8872   if(!f0 || !f1)
8873     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8874   if(f0->getMeshName()!=mesh->getName())
8875     {
8876       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8877       throw INTERP_KERNEL::Exception(oss.str().c_str());
8878     }
8879   if(f1->getMeshName()!=mesh->getName())
8880     {
8881       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8882       throw INTERP_KERNEL::Exception(oss.str().c_str());
8883     }
8884   int nts=f0->getNumberOfTS();
8885   if(nts!=f1->getNumberOfTS())
8886     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8887   if(nts==0)
8888     return nts;
8889   for(int i=0;i<nts;i++)
8890     {
8891       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8892       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8893       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8894       if(tofs0.size()!=1 || tofs1.size()!=1)
8895         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8896       if(i!=0)
8897         {
8898           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8899             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8900         }
8901       else
8902         { tof0=tofs0[0]; tof1=tofs1[0]; }
8903       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8904         {
8905           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() << ") !";
8906           throw INTERP_KERNEL::Exception(oss.str().c_str());
8907         }
8908       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8909         {
8910           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() << ") !";
8911           throw INTERP_KERNEL::Exception(oss.str().c_str());
8912         }
8913       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8914         {
8915           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() << ") !";
8916           throw INTERP_KERNEL::Exception(oss.str().c_str());
8917         }
8918     }
8919   return nts;
8920 }
8921
8922 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8923 {
8924   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8925 }
8926
8927 //= MEDFileFieldMultiTS
8928
8929 /*!
8930  * Returns a new empty instance of MEDFileFieldMultiTS.
8931  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8932  *          is to delete this field using decrRef() as it is no more needed.
8933  */
8934 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8935 {
8936   return new MEDFileFieldMultiTS;
8937 }
8938
8939 /*!
8940  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8941  * that has been read from a specified MED file.
8942  *  \param [in] fileName - the name of the MED file to read.
8943  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8944  *          is to delete this field using decrRef() as it is no more needed.
8945  *  \throw If reading the file fails.
8946  */
8947 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8948 {
8949   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
8950   ret->contentNotNull();//to check that content type matches with \a this type.
8951   return ret.retn();
8952 }
8953
8954 /*!
8955  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8956  * that has been read from a specified MED file.
8957  *  \param [in] fileName - the name of the MED file to read.
8958  *  \param [in] fieldName - the name of the field to read.
8959  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8960  *          is to delete this field using decrRef() as it is no more needed.
8961  *  \throw If reading the file fails.
8962  *  \throw If there is no field named \a fieldName in the file.
8963  */
8964 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8965 {
8966   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
8967   ret->contentNotNull();//to check that content type matches with \a this type.
8968   return ret.retn();
8969 }
8970
8971 /*!
8972  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8973  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8974  *
8975  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8976  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8977  * \warning this is a shallow copy constructor
8978  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8979  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8980  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8981  *          is to delete this field using decrRef() as it is no more needed.
8982  */
8983 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8984 {
8985   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8986 }
8987
8988 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
8989 {
8990   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0,&entities));
8991   ret->contentNotNull();//to check that content type matches with \a this type.
8992   return ret.retn();
8993 }
8994
8995 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8996 {
8997   return new MEDFileFieldMultiTS(*this);
8998 }
8999
9000 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9001 {
9002   if(!f1ts)
9003     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9004   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9005   if(!f1tsC)
9006     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9007 }
9008
9009 /*!
9010  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9011  * following the given input policy.
9012  *
9013  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9014  *                            By default (true) the globals are deeply copied.
9015  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9016  */
9017 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9018 {
9019   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
9020   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9021   if(content)
9022     {
9023       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9024       if(!contc)
9025         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9026       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9027       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
9028     }
9029   else
9030     ret=MEDFileIntFieldMultiTS::New();
9031   if(isDeepCpyGlobs)
9032     ret->deepCpyGlobs(*this);
9033   else
9034     ret->shallowCpyGlobs(*this);
9035   return ret.retn();
9036 }
9037
9038 /*!
9039  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9040  *  \param [in] pos - a time step id.
9041  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9042  *          delete this field using decrRef() as it is no more needed.
9043  *  \throw If \a pos is not a valid time step id.
9044  */
9045 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9046 {
9047   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9048   if(!item)
9049     {
9050       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9051       throw INTERP_KERNEL::Exception(oss.str().c_str());
9052     }
9053   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9054   if(itemC)
9055     {
9056       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9057       ret->shallowCpyGlobs(*this);
9058       return ret.retn();
9059     }
9060   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9061   throw INTERP_KERNEL::Exception(oss.str().c_str());
9062 }
9063
9064 /*!
9065  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9066  * mesh entities of a given dimension of the first mesh in MED file.
9067  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9068  *  \param [in] type - a spatial discretization of interest.
9069  *  \param [in] iteration - the iteration number of a required time step.
9070  *  \param [in] order - the iteration order number of required time step.
9071  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9072  *  \param [in] renumPol - specifies how to permute values of the result field according to
9073  *          the optional numbers of cells and nodes, if any. The valid values are
9074  *          - 0 - do not permute.
9075  *          - 1 - permute cells.
9076  *          - 2 - permute nodes.
9077  *          - 3 - permute cells and nodes.
9078  *
9079  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9080  *          caller is to delete this field using decrRef() as it is no more needed. 
9081  *  \throw If the MED file is not readable.
9082  *  \throw If there is no mesh in the MED file.
9083  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9084  *  \throw If no field values of the required parameters are available.
9085  */
9086 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9087 {
9088   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9089   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9090   if(!myF1TSC)
9091     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9092   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9093   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9094   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9095   return ret.retn();
9096 }
9097
9098 /*!
9099  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9100  * the top level cells of the first mesh in MED file.
9101  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9102  *  \param [in] type - a spatial discretization of interest.
9103  *  \param [in] iteration - the iteration number of a required time step.
9104  *  \param [in] order - the iteration order number of required time step.
9105  *  \param [in] renumPol - specifies how to permute values of the result field according to
9106  *          the optional numbers of cells and nodes, if any. The valid values are
9107  *          - 0 - do not permute.
9108  *          - 1 - permute cells.
9109  *          - 2 - permute nodes.
9110  *          - 3 - permute cells and nodes.
9111  *
9112  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9113  *          caller is to delete this field using decrRef() as it is no more needed. 
9114  *  \throw If the MED file is not readable.
9115  *  \throw If there is no mesh in the MED file.
9116  *  \throw If no field values of the required parameters are available.
9117  */
9118 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9119 {
9120   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9121   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9122   if(!myF1TSC)
9123     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9124   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9125   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9126   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9127   return ret.retn();
9128 }
9129
9130 /*!
9131  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9132  * a given support.
9133  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9134  *  \param [in] type - a spatial discretization of interest.
9135  *  \param [in] iteration - the iteration number of a required time step.
9136  *  \param [in] order - the iteration order number of required time step.
9137  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9138  *  \param [in] mesh - the supporting mesh.
9139  *  \param [in] renumPol - specifies how to permute values of the result field according to
9140  *          the optional numbers of cells and nodes, if any. The valid values are
9141  *          - 0 - do not permute.
9142  *          - 1 - permute cells.
9143  *          - 2 - permute nodes.
9144  *          - 3 - permute cells and nodes.
9145  *
9146  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9147  *          caller is to delete this field using decrRef() as it is no more needed. 
9148  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9149  *  \throw If no field of \a this is lying on \a mesh.
9150  *  \throw If no field values of the required parameters are available.
9151  */
9152 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9153 {
9154   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9155   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9156   if(!myF1TSC)
9157     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9158   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9159   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9160   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9161   return ret.retn();
9162 }
9163
9164 /*!
9165  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9166  * given support. 
9167  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9168  *  \param [in] type - a spatial discretization of the new field.
9169  *  \param [in] iteration - the iteration number of a required time step.
9170  *  \param [in] order - the iteration order number of required time step.
9171  *  \param [in] mesh - the supporting mesh.
9172  *  \param [in] renumPol - specifies how to permute values of the result field according to
9173  *          the optional numbers of cells and nodes, if any. The valid values are
9174  *          - 0 - do not permute.
9175  *          - 1 - permute cells.
9176  *          - 2 - permute nodes.
9177  *          - 3 - permute cells and nodes.
9178  *
9179  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9180  *          caller is to delete this field using decrRef() as it is no more needed. 
9181  *  \throw If no field of \a this is lying on \a mesh.
9182  *  \throw If no field values of the required parameters are available.
9183  */
9184 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9185 {
9186   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9187   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9188   if(!myF1TSC)
9189     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9190   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9191   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9192   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9193   return ret.retn();
9194 }
9195
9196 /*!
9197  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9198  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9199  * This method is useful for MED2 file format when field on different mesh was autorized.
9200  */
9201 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9202 {
9203   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9204   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9205   if(!myF1TSC)
9206     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9207   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9208   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9209   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9210   return ret.retn();
9211 }
9212
9213 /*!
9214  * Returns values and a profile of the field of a given type, of a given time step,
9215  * lying on a given support.
9216  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9217  *  \param [in] type - a spatial discretization of the field.
9218  *  \param [in] iteration - the iteration number of a required time step.
9219  *  \param [in] order - the iteration order number of required time step.
9220  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9221  *  \param [in] mesh - the supporting mesh.
9222  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9223  *          field of interest lies on. If the field lies on all entities of the given
9224  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9225  *          using decrRef() as it is no more needed.  
9226  *  \param [in] glob - the global data storing profiles and localization.
9227  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9228  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9229  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9230  *  \throw If no field of \a this is lying on \a mesh.
9231  *  \throw If no field values of the required parameters are available.
9232  */
9233 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9234 {
9235   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9236   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9237   if(!myF1TSC)
9238     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9239   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9240   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9241 }
9242
9243 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9244 {
9245   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9246   if(!pt)
9247     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9248   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9249   if(!ret)
9250     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 !");
9251   return ret;
9252 }
9253
9254 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9255 {
9256   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9257   if(!pt)
9258     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9259   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9260   if(!ret)
9261     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 !");
9262   return ret;
9263 }
9264
9265 /*!
9266  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9267  * the given field is checked if its elements are sorted suitable for writing to MED file
9268  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9269  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9270  *  \param [in] field - the field to add to \a this.
9271  *  \throw If the name of \a field is empty.
9272  *  \throw If the data array of \a field is not set.
9273  *  \throw If existing time steps have different name or number of components than \a field.
9274  *  \throw If the underlying mesh of \a field has no name.
9275  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9276  */
9277 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9278 {
9279   const DataArrayDouble *arr=0;
9280   if(field)
9281     arr=field->getArray();
9282   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9283 }
9284
9285 /*!
9286  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9287  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9288  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9289  * and \a profile.
9290  *
9291  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9292  * A new profile is added only if no equal profile is missing.
9293  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9294  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9295  *  \param [in] mesh - the supporting mesh of \a field.
9296  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9297  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9298  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9299  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9300  *  \throw If the data array of \a field is not set.
9301  *  \throw If the data array of \a this is already allocated but has different number of
9302  *         components than \a field.
9303  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9304  *  \sa setFieldNoProfileSBT()
9305  */
9306 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9307 {
9308   const DataArrayDouble *arr=0;
9309   if(field)
9310     arr=field->getArray();
9311   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9312 }
9313
9314 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9315 {
9316   _content=new MEDFileFieldMultiTSWithoutSDA;
9317 }
9318
9319 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9320 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9321 {
9322 }
9323 catch(INTERP_KERNEL::Exception& e)
9324 { throw e; }
9325
9326 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)
9327 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9328 {
9329 }
9330 catch(INTERP_KERNEL::Exception& e)
9331 { throw e; }
9332
9333 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9334 {
9335 }
9336
9337 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
9338 {
9339   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9340 }
9341
9342 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9343 {
9344   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9345 }
9346
9347 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9348 {
9349   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9350 }
9351
9352 //= MEDFileAnyTypeFieldMultiTSIterator
9353
9354 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9355 {
9356   if(fmts)
9357     {
9358       fmts->incrRef();
9359       _nb_iter=fmts->getNumberOfTS();
9360     }
9361 }
9362
9363 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9364 {
9365 }
9366
9367 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9368 {
9369   if(_iter_id<_nb_iter)
9370     {
9371       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9372       if(fmts)
9373         return fmts->getTimeStepAtPos(_iter_id++);
9374       else
9375         return 0;
9376     }
9377   else
9378     return 0;
9379 }
9380
9381 //= MEDFileIntFieldMultiTS
9382
9383 /*!
9384  * Returns a new empty instance of MEDFileFieldMultiTS.
9385  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9386  *          is to delete this field using decrRef() as it is no more needed.
9387  */
9388 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9389 {
9390   return new MEDFileIntFieldMultiTS;
9391 }
9392
9393 /*!
9394  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9395  * that has been read from a specified MED file.
9396  *  \param [in] fileName - the name of the MED file to read.
9397  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9398  *          is to delete this field using decrRef() as it is no more needed.
9399  *  \throw If reading the file fails.
9400  */
9401 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9402 {
9403   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9404   ret->contentNotNull();//to check that content type matches with \a this type.
9405   return ret.retn();
9406 }
9407
9408 /*!
9409  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9410  * that has been read from a specified MED file.
9411  *  \param [in] fileName - the name of the MED file to read.
9412  *  \param [in] fieldName - the name of the field to read.
9413  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9414  *          is to delete this field using decrRef() as it is no more needed.
9415  *  \throw If reading the file fails.
9416  *  \throw If there is no field named \a fieldName in the file.
9417  */
9418 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9419 {
9420   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9421   ret->contentNotNull();//to check that content type matches with \a this type.
9422   return ret.retn();
9423 }
9424
9425 /*!
9426  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9427  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9428  *
9429  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9430  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9431  * \warning this is a shallow copy constructor
9432  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9433  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9434  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9435  *          is to delete this field using decrRef() as it is no more needed.
9436  */
9437 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9438 {
9439   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9440 }
9441
9442 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9443 {
9444   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0,&entities);
9445   ret->contentNotNull();//to check that content type matches with \a this type.
9446   return ret.retn();
9447 }
9448
9449 /*!
9450  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9451  * following the given input policy.
9452  *
9453  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9454  *                            By default (true) the globals are deeply copied.
9455  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9456  */
9457 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9458 {
9459   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
9460   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9461   if(content)
9462     {
9463       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9464       if(!contc)
9465         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9466       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9467       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9468     }
9469   else
9470     ret=MEDFileFieldMultiTS::New();
9471   if(isDeepCpyGlobs)
9472     ret->deepCpyGlobs(*this);
9473   else
9474     ret->shallowCpyGlobs(*this);
9475   return ret.retn();
9476 }
9477
9478 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9479 {
9480   return new MEDFileIntFieldMultiTS(*this);
9481 }
9482
9483 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9484 {
9485   if(!f1ts)
9486     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9487   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9488   if(!f1tsC)
9489     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9490 }
9491
9492 /*!
9493  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9494  * mesh entities of a given dimension of the first mesh in MED file.
9495  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9496  *  \param [in] type - a spatial discretization of interest.
9497  *  \param [in] iteration - the iteration number of a required time step.
9498  *  \param [in] order - the iteration order number of required time step.
9499  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9500  *  \param [out] arrOut - the DataArrayInt containing values of field.
9501  *  \param [in] renumPol - specifies how to permute values of the result field according to
9502  *          the optional numbers of cells and nodes, if any. The valid values are
9503  *          - 0 - do not permute.
9504  *          - 1 - permute cells.
9505  *          - 2 - permute nodes.
9506  *          - 3 - permute cells and nodes.
9507  *
9508  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9509  *          caller is to delete this field using decrRef() as it is no more needed. 
9510  *  \throw If the MED file is not readable.
9511  *  \throw If there is no mesh in the MED file.
9512  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9513  *  \throw If no field values of the required parameters are available.
9514  */
9515 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9516 {
9517   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9518   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9519   if(!myF1TSC)
9520     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9521   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9522   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9523   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9524   return ret.retn();
9525 }
9526
9527 /*!
9528  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9529  * the top level cells of the first mesh in MED file.
9530  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9531  *  \param [in] type - a spatial discretization of interest.
9532  *  \param [in] iteration - the iteration number of a required time step.
9533  *  \param [in] order - the iteration order number of required time step.
9534  *  \param [out] arrOut - the DataArrayInt containing values of field.
9535  *  \param [in] renumPol - specifies how to permute values of the result field according to
9536  *          the optional numbers of cells and nodes, if any. The valid values are
9537  *          - 0 - do not permute.
9538  *          - 1 - permute cells.
9539  *          - 2 - permute nodes.
9540  *          - 3 - permute cells and nodes.
9541  *
9542  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9543  *          caller is to delete this field using decrRef() as it is no more needed. 
9544  *  \throw If the MED file is not readable.
9545  *  \throw If there is no mesh in the MED file.
9546  *  \throw If no field values of the required parameters are available.
9547  */
9548 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9549 {
9550   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9551   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9552   if(!myF1TSC)
9553     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9554   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9555   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9556   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9557   return ret.retn();
9558 }
9559
9560 /*!
9561  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9562  * a given support.
9563  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9564  *  \param [in] type - a spatial discretization of interest.
9565  *  \param [in] iteration - the iteration number of a required time step.
9566  *  \param [in] order - the iteration order number of required time step.
9567  *  \param [out] arrOut - the DataArrayInt containing values of field.
9568  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9569  *  \param [in] mesh - the supporting mesh.
9570  *  \param [in] renumPol - specifies how to permute values of the result field according to
9571  *          the optional numbers of cells and nodes, if any. The valid values are
9572  *          - 0 - do not permute.
9573  *          - 1 - permute cells.
9574  *          - 2 - permute nodes.
9575  *          - 3 - permute cells and nodes.
9576  *
9577  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9578  *          caller is to delete this field using decrRef() as it is no more needed. 
9579  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9580  *  \throw If no field of \a this is lying on \a mesh.
9581  *  \throw If no field values of the required parameters are available.
9582  */
9583 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9584 {
9585   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9586   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9587   if(!myF1TSC)
9588     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9589   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9590   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9591   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9592   return ret.retn();
9593 }
9594
9595 /*!
9596  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9597  * given support. 
9598  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9599  *  \param [in] type - a spatial discretization of the new field.
9600  *  \param [in] iteration - the iteration number of a required time step.
9601  *  \param [in] order - the iteration order number of required time step.
9602  *  \param [in] mesh - the supporting mesh.
9603  *  \param [out] arrOut - the DataArrayInt containing values of field.
9604  *  \param [in] renumPol - specifies how to permute values of the result field according to
9605  *          the optional numbers of cells and nodes, if any. The valid values are
9606  *          - 0 - do not permute.
9607  *          - 1 - permute cells.
9608  *          - 2 - permute nodes.
9609  *          - 3 - permute cells and nodes.
9610  *
9611  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9612  *          caller is to delete this field using decrRef() as it is no more needed. 
9613  *  \throw If no field of \a this is lying on \a mesh.
9614  *  \throw If no field values of the required parameters are available.
9615  */
9616 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9617 {
9618   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9619   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9620   if(!myF1TSC)
9621     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9622   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9623   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9624   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9625   return ret.retn();
9626 }
9627
9628 /*!
9629  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9630  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9631  * This method is useful for MED2 file format when field on different mesh was autorized.
9632  */
9633 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9634 {
9635   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9636   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9637   if(!myF1TSC)
9638     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9639   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9640   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9641   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9642   return ret.retn();
9643 }
9644
9645 /*!
9646  * Returns values and a profile of the field of a given type, of a given time step,
9647  * lying on a given support.
9648  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9649  *  \param [in] type - a spatial discretization of the field.
9650  *  \param [in] iteration - the iteration number of a required time step.
9651  *  \param [in] order - the iteration order number of required time step.
9652  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9653  *  \param [in] mesh - the supporting mesh.
9654  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9655  *          field of interest lies on. If the field lies on all entities of the given
9656  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9657  *          using decrRef() as it is no more needed.  
9658  *  \param [in] glob - the global data storing profiles and localization.
9659  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9660  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9661  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9662  *  \throw If no field of \a this is lying on \a mesh.
9663  *  \throw If no field values of the required parameters are available.
9664  */
9665 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9666 {
9667   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9668   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9669   if(!myF1TSC)
9670     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9671   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9672   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9673 }
9674
9675 /*!
9676  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9677  *  \param [in] pos - a time step id.
9678  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9679  *          delete this field using decrRef() as it is no more needed.
9680  *  \throw If \a pos is not a valid time step id.
9681  */
9682 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9683 {
9684   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9685   if(!item)
9686     {
9687       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9688       throw INTERP_KERNEL::Exception(oss.str().c_str());
9689     }
9690   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9691   if(itemC)
9692     {
9693       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9694       ret->shallowCpyGlobs(*this);
9695       return ret.retn();
9696     }
9697   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9698   throw INTERP_KERNEL::Exception(oss.str().c_str());
9699 }
9700
9701 /*!
9702  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9703  * the given field is checked if its elements are sorted suitable for writing to MED file
9704  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9705  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9706  *  \param [in] field - the field to add to \a this.
9707  *  \throw If the name of \a field is empty.
9708  *  \throw If the data array of \a field is not set.
9709  *  \throw If existing time steps have different name or number of components than \a field.
9710  *  \throw If the underlying mesh of \a field has no name.
9711  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9712  */
9713 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9714 {
9715   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9716 }
9717
9718 /*!
9719  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9720  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9721  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9722  * and \a profile.
9723  *
9724  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9725  * A new profile is added only if no equal profile is missing.
9726  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9727  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9728  *  \param [in] arrOfVals - the values of the field \a field used.
9729  *  \param [in] mesh - the supporting mesh of \a field.
9730  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9731  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9732  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9733  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9734  *  \throw If the data array of \a field is not set.
9735  *  \throw If the data array of \a this is already allocated but has different number of
9736  *         components than \a field.
9737  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9738  *  \sa setFieldNoProfileSBT()
9739  */
9740 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9741 {
9742   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9743 }
9744
9745 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9746 {
9747   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9748   if(!pt)
9749     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9750   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9751   if(!ret)
9752     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 !");
9753   return ret;
9754 }
9755
9756 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9757 {
9758   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9759   if(!pt)
9760     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9761   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9762   if(!ret)
9763     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 !");
9764   return ret;
9765 }
9766
9767 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9768 {
9769   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9770 }
9771
9772 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9773 {
9774 }
9775
9776 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9777 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9778 {
9779 }
9780 catch(INTERP_KERNEL::Exception& e)
9781 { throw e; }
9782
9783 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)
9784 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9785 {
9786 }
9787 catch(INTERP_KERNEL::Exception& e)
9788 { throw e; }
9789
9790 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9791 {
9792   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9793 }
9794
9795 //= MEDFileFields
9796
9797 MEDFileFields *MEDFileFields::New()
9798 {
9799   return new MEDFileFields;
9800 }
9801
9802 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9803 {
9804   return new MEDFileFields(fileName,loadAll,0,0);
9805 }
9806
9807 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9808 {
9809   return new MEDFileFields(fileName,loadAll,ms,0);
9810 }
9811
9812 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9813 {
9814   return new MEDFileFields(fileName,loadAll,0,&entities);
9815 }
9816
9817 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9818 {
9819   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9820   ret+=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9821   return ret;
9822 }
9823
9824 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9825 {
9826   std::vector<const BigMemoryObject *> ret;
9827   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9828     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9829   return ret;
9830 }
9831
9832 MEDFileFields *MEDFileFields::deepCpy() const
9833 {
9834   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9835   std::size_t i=0;
9836   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9837     {
9838       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9839         ret->_fields[i]=(*it)->deepCpy();
9840     }
9841   ret->deepCpyGlobs(*this);
9842   return ret.retn();
9843 }
9844
9845 MEDFileFields *MEDFileFields::shallowCpy() const
9846 {
9847   return new MEDFileFields(*this);
9848 }
9849
9850 /*!
9851  * 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
9852  * 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.
9853  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9854  *
9855  * \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.
9856  * \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.
9857  * 
9858  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9859  */
9860 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9861 {
9862   std::set< std::pair<int,int> > s;
9863   bool firstShot=true;
9864   areThereSomeForgottenTS=false;
9865   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9866     {
9867       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9868         continue;
9869       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9870       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9871       if(firstShot)
9872         { s=s1; firstShot=false; }
9873       else
9874         {
9875           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9876           if(s!=s2)
9877             areThereSomeForgottenTS=true;
9878           s=s2;
9879         }
9880     }
9881   std::vector< std::pair<int,int> > ret;
9882   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9883   return ret;
9884 }
9885
9886 int MEDFileFields::getNumberOfFields() const
9887 {
9888   return _fields.size();
9889 }
9890
9891 std::vector<std::string> MEDFileFields::getFieldsNames() const
9892 {
9893   std::vector<std::string> ret(_fields.size());
9894   int i=0;
9895   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9896     {
9897       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9898       if(f)
9899         {
9900           ret[i]=f->getName();
9901         }
9902       else
9903         {
9904           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9905           throw INTERP_KERNEL::Exception(oss.str().c_str());
9906         }
9907     }
9908   return ret;
9909 }
9910
9911 std::vector<std::string> MEDFileFields::getMeshesNames() const
9912 {
9913   std::vector<std::string> ret;
9914   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9915     {
9916       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9917       if(cur)
9918         ret.push_back(cur->getMeshName());
9919     }
9920   return ret;
9921 }
9922
9923 std::string MEDFileFields::simpleRepr() const
9924 {
9925   std::ostringstream oss;
9926   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9927   simpleRepr(0,oss);
9928   return oss.str();
9929 }
9930
9931 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9932 {
9933   int nbOfFields=getNumberOfFields();
9934   std::string startLine(bkOffset,' ');
9935   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9936   int i=0;
9937   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9938     {
9939       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9940       if(cur)
9941         {
9942           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9943         }
9944       else
9945         {
9946           oss << startLine << "  - not defined !" << std::endl;
9947         }
9948     }
9949   i=0;
9950   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9951     {
9952       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9953       std::string chapter(17,'0'+i);
9954       oss << startLine << chapter << std::endl;
9955       if(cur)
9956         {
9957           cur->simpleRepr(bkOffset+2,oss,i);
9958         }
9959       else
9960         {
9961           oss << startLine << "  - not defined !" << std::endl;
9962         }
9963       oss << startLine << chapter << std::endl;
9964     }
9965   simpleReprGlobs(oss);
9966 }
9967
9968 MEDFileFields::MEDFileFields()
9969 {
9970 }
9971
9972 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9973 try:MEDFileFieldGlobsReal(fileName)
9974 {
9975   MEDFileUtilities::CheckFileForRead(fileName);
9976   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
9977   int nbFields(MEDnField(fid));
9978   _fields.resize(nbFields);
9979   med_field_type typcha;
9980   for(int i=0;i<nbFields;i++)
9981     {
9982       std::vector<std::string> infos;
9983       std::string fieldName,dtunit;
9984       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
9985       switch(typcha)
9986       {
9987         case MED_FLOAT64:
9988           {
9989             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9990             break;
9991           }
9992         case MED_INT32:
9993           {
9994             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9995             break;
9996           }
9997         default:
9998           {
9999             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] !";
10000             throw INTERP_KERNEL::Exception(oss.str().c_str());
10001           }
10002       }
10003     }
10004   loadAllGlobals(fid);
10005 }
10006 catch(INTERP_KERNEL::Exception& e)
10007 {
10008     throw e;
10009 }
10010
10011 void MEDFileFields::writeLL(med_idt fid) const
10012 {
10013   int i=0;
10014   writeGlobals(fid,*this);
10015   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10016     {
10017       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10018       if(!elt)
10019         {
10020           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10021           throw INTERP_KERNEL::Exception(oss.str().c_str());
10022         }
10023       elt->writeLL(fid,*this);
10024     }
10025 }
10026
10027 void MEDFileFields::write(const std::string& fileName, int mode) const
10028 {
10029   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
10030   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
10031   writeLL(fid);
10032 }
10033
10034 /*!
10035  * This method alloc the arrays and load potentially huge arrays contained in this field.
10036  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10037  * This method can be also called to refresh or reinit values from a file.
10038  * 
10039  * \throw If the fileName is not set or points to a non readable MED file.
10040  */
10041 void MEDFileFields::loadArrays()
10042 {
10043   if(getFileName().empty())
10044     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10045   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10046   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10047     {
10048       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10049       if(elt)
10050         elt->loadBigArraysRecursively(fid,*elt);
10051     }
10052 }
10053
10054 /*!
10055  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10056  * But once data loaded once, this method does nothing.
10057  * 
10058  * \throw If the fileName is not set or points to a non readable MED file.
10059  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10060  */
10061 void MEDFileFields::loadArraysIfNecessary()
10062 {
10063   if(!getFileName().empty())
10064     {
10065       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10066       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10067         {
10068           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10069           if(elt)
10070             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10071         }
10072     }
10073 }
10074
10075 /*!
10076  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10077  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10078  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10079  * 
10080  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10081  */
10082 void MEDFileFields::unloadArrays()
10083 {
10084   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10085     {
10086       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10087       if(elt)
10088         elt->unloadArrays();
10089     }
10090 }
10091
10092 /*!
10093  * 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.
10094  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10095  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10096  * 
10097  * \sa MEDFileFields::loadArraysIfNecessary
10098  */
10099 void MEDFileFields::unloadArraysWithoutDataLoss()
10100 {
10101   if(!getFileName().empty())
10102     unloadArrays();
10103 }
10104
10105 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10106 {
10107   std::vector<std::string> ret;
10108   std::set<std::string> ret2;
10109   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10110     {
10111       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10112       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10113         if(ret2.find(*it2)==ret2.end())
10114           {
10115             ret.push_back(*it2);
10116             ret2.insert(*it2);
10117           }
10118     }
10119   return ret;
10120 }
10121
10122 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10123 {
10124   std::vector<std::string> ret;
10125   std::set<std::string> ret2;
10126   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10127     {
10128       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10129       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10130         if(ret2.find(*it2)==ret2.end())
10131           {
10132             ret.push_back(*it2);
10133             ret2.insert(*it2);
10134           }
10135     }
10136   return ret;
10137 }
10138
10139 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10140 {
10141   std::vector<std::string> ret;
10142   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10143     {
10144       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
10145       ret.insert(ret.end(),tmp.begin(),tmp.end());
10146     }
10147   return ret;
10148 }
10149
10150 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10151 {
10152   std::vector<std::string> ret;
10153   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10154     {
10155       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10156       ret.insert(ret.end(),tmp.begin(),tmp.end());
10157     }
10158   return ret;
10159 }
10160
10161 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10162 {
10163   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10164     (*it)->changePflsRefsNamesGen2(mapOfModif);
10165 }
10166
10167 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10168 {
10169   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10170     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10171 }
10172
10173 void MEDFileFields::resize(int newSize)
10174 {
10175   _fields.resize(newSize);
10176 }
10177
10178 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10179 {
10180   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10181     pushField(*it);
10182 }
10183
10184 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10185 {
10186   if(!field)
10187     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10188   _fields.push_back(field->getContent());
10189   appendGlobs(*field,1e-12);
10190 }
10191
10192 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10193 {
10194   if(!field)
10195     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10196   if(i>=(int)_fields.size())
10197     _fields.resize(i+1);
10198   _fields[i]=field->getContent();
10199   appendGlobs(*field,1e-12);
10200 }
10201
10202 void MEDFileFields::destroyFieldAtPos(int i)
10203 {
10204   destroyFieldsAtPos(&i,&i+1);
10205 }
10206
10207 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10208 {
10209   std::vector<bool> b(_fields.size(),true);
10210   for(const int *i=startIds;i!=endIds;i++)
10211     {
10212       if(*i<0 || *i>=(int)_fields.size())
10213         {
10214           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10215           throw INTERP_KERNEL::Exception(oss.str().c_str());
10216         }
10217       b[*i]=false;
10218     }
10219   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10220   std::size_t j=0;
10221   for(std::size_t i=0;i<_fields.size();i++)
10222     if(b[i])
10223       fields[j++]=_fields[i];
10224   _fields=fields;
10225 }
10226
10227 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10228 {
10229   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10230   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
10231   std::vector<bool> b(_fields.size(),true);
10232   int k=bg;
10233   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10234     {
10235       if(k<0 || k>=(int)_fields.size())
10236         {
10237           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10238           throw INTERP_KERNEL::Exception(oss.str().c_str());
10239         }
10240       b[k]=false;
10241     }
10242   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10243   std::size_t j=0;
10244   for(std::size_t i=0;i<_fields.size();i++)
10245     if(b[i])
10246       fields[j++]=_fields[i];
10247   _fields=fields;
10248 }
10249
10250 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10251 {
10252   bool ret=false;
10253   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10254     {
10255       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10256       if(cur)
10257         ret=cur->changeMeshNames(modifTab) || ret;
10258     }
10259   return ret;
10260 }
10261
10262 /*!
10263  * \param [in] meshName the name of the mesh that will be renumbered.
10264  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10265  *             This code corresponds to the distribution of types in the corresponding mesh.
10266  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10267  * \param [in] renumO2N the old to new renumber array.
10268  * \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 
10269  *         field in \a this.
10270  */
10271 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10272 {
10273   bool ret=false;
10274   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10275     {
10276       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10277       if(fmts)
10278         {
10279           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10280         }
10281     }
10282   return ret;
10283 }
10284
10285 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10286 {
10287   if(i<0 || i>=(int)_fields.size())
10288     {
10289       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10290       throw INTERP_KERNEL::Exception(oss.str().c_str());
10291     }
10292   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10293   if(!fmts)
10294     return 0;
10295   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
10296   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
10297   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
10298   if(fmtsC)
10299     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10300   else if(fmtsC2)
10301     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10302   else
10303     {
10304       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10305       throw INTERP_KERNEL::Exception(oss.str().c_str());
10306     }
10307   ret->shallowCpyGlobs(*this);
10308   return ret.retn();
10309 }
10310
10311 /*!
10312  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10313  * This method is accessible in python using __getitem__ with a list in input.
10314  * \return a new object that the caller should deal with.
10315  */
10316 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10317 {
10318   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
10319   std::size_t sz=std::distance(startIds,endIds);
10320   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10321   int j=0;
10322   for(const int *i=startIds;i!=endIds;i++,j++)
10323     {
10324       if(*i<0 || *i>=(int)_fields.size())
10325         {
10326           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10327           throw INTERP_KERNEL::Exception(oss.str().c_str());
10328         }
10329       fields[j]=_fields[*i];
10330     }
10331   ret->_fields=fields;
10332   return ret.retn();
10333 }
10334
10335 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10336 {
10337   return getFieldAtPos(getPosFromFieldName(fieldName));
10338 }
10339
10340 /*!
10341  * This method removes, if any, fields in \a this having no time steps.
10342  * 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.
10343  * 
10344  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10345  */
10346 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10347 {
10348   std::vector<MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10349   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10350     {
10351       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10352       if(elt)
10353         {
10354           if(elt->getNumberOfTS()>0)
10355             newFields.push_back(*it);
10356         }
10357     }
10358   if(_fields.size()==newFields.size())
10359     return false;
10360   _fields=newFields;
10361   return true;
10362 }
10363
10364 /*!
10365  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10366  * This method can be seen as a filter applied on \a this, that returns an object containing
10367  * 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
10368  * shallow copied from \a this.
10369  * 
10370  * \param [in] meshName - the name of the mesh on w
10371  * \return a new object that the caller should deal with.
10372  */
10373 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10374 {
10375   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10376   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10377     {
10378       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10379       if(!cur)
10380         continue;
10381       if(cur->getMeshName()==meshName)
10382         {
10383           cur->incrRef();
10384           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10385           ret->_fields.push_back(cur2);
10386         }
10387     }
10388   ret->shallowCpyOnlyUsedGlobs(*this);
10389   return ret.retn();
10390 }
10391
10392 /*!
10393  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10394  * Input time steps are specified using a pair of integer (iteration, order).
10395  * 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,
10396  * but for each multitimestep only the time steps in \a timeSteps are kept.
10397  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10398  * 
10399  * The returned object points to shallow copy of elements in \a this.
10400  * 
10401  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10402  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10403  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10404  */
10405 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10406 {
10407   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10408   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10409     {
10410       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10411       if(!cur)
10412         continue;
10413       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10414       ret->_fields.push_back(elt);
10415     }
10416   ret->shallowCpyOnlyUsedGlobs(*this);
10417   return ret.retn();
10418 }
10419
10420 /*!
10421  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10422  */
10423 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10424 {
10425   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10426   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10427     {
10428       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10429       if(!cur)
10430         continue;
10431       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10432       if(elt->getNumberOfTS()!=0)
10433         ret->_fields.push_back(elt);
10434     }
10435   ret->shallowCpyOnlyUsedGlobs(*this);
10436   return ret.retn();
10437 }
10438
10439 MEDFileFieldsIterator *MEDFileFields::iterator()
10440 {
10441   return new MEDFileFieldsIterator(this);
10442 }
10443
10444 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10445 {
10446   std::string tmp(fieldName);
10447   std::vector<std::string> poss;
10448   for(std::size_t i=0;i<_fields.size();i++)
10449     {
10450       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10451       if(f)
10452         {
10453           std::string fname(f->getName());
10454           if(tmp==fname)
10455             return i;
10456           else
10457             poss.push_back(fname);
10458         }
10459     }
10460   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10461   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10462   oss << " !";
10463   throw INTERP_KERNEL::Exception(oss.str().c_str());
10464 }
10465
10466 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10467 {
10468   if(fs)
10469     {
10470       fs->incrRef();
10471       _nb_iter=fs->getNumberOfFields();
10472     }
10473 }
10474
10475 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10476 {
10477 }
10478
10479 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10480 {
10481   if(_iter_id<_nb_iter)
10482     {
10483       MEDFileFields *fs(_fs);
10484       if(fs)
10485         return fs->getFieldAtPos(_iter_id++);
10486       else
10487         return 0;
10488     }
10489   else
10490     return 0;
10491 }