Salome HOME
4c082e21fafee6122636ba411146996bebf97233
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2014  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 "MEDFileFieldOverView.hxx"
26
27 #include "MEDCouplingFieldDouble.hxx"
28 #include "MEDCouplingFieldDiscretization.hxx"
29
30 #include "InterpKernelAutoPtr.hxx"
31 #include "CellModel.hxx"
32
33 #include <algorithm>
34 #include <iterator>
35
36 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
37 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
38 extern med_geometry_type typmainoeud[1];
39 extern med_geometry_type typmai3[34];
40
41 using namespace ParaMEDMEM;
42
43 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
44 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
45
46 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
47 {
48   return new MEDFileFieldLoc(fid,locName);
49 }
50
51 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
52 {
53   return new MEDFileFieldLoc(fid,id);
54 }
55
56 MEDFileFieldLoc *MEDFileFieldLoc::New(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
57 {
58   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
59 }
60
61 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
62 {
63   med_geometry_type geotype;
64   med_geometry_type sectiongeotype;
65   int nsectionmeshcell;
66   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
67   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
68   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
69   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
70   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
71   _nb_node_per_cell=cm.getNumberOfNodes();
72   _ref_coo.resize(_dim*_nb_node_per_cell);
73   _gs_coo.resize(_dim*_nb_gauss_pt);
74   _w.resize(_nb_gauss_pt);
75   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
76 }
77
78 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
79 {
80   med_geometry_type geotype;
81   med_geometry_type sectiongeotype;
82   int nsectionmeshcell;
83   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
84   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
85   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
86   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
87   _name=locName;
88   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
89   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
90   _nb_node_per_cell=cm.getNumberOfNodes();
91   _ref_coo.resize(_dim*_nb_node_per_cell);
92   _gs_coo.resize(_dim*_nb_gauss_pt);
93   _w.resize(_nb_gauss_pt);
94   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
95 }
96
97 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
98                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_geo_type(geoType),_ref_coo(refCoo),_gs_coo(gsCoo),
99                                      _w(w)
100 {
101   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
102   _dim=cm.getDimension();
103   _nb_node_per_cell=cm.getNumberOfNodes();
104   _nb_gauss_pt=_w.size();
105 }
106
107 MEDFileFieldLoc *MEDFileFieldLoc::deepCpy() const
108 {
109   return new MEDFileFieldLoc(*this);
110 }
111
112 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
113 {
114   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
115 }
116
117 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
118 {
119   return std::vector<const BigMemoryObject *>();
120 }
121
122 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
123 {
124   static const char OFF7[]="\n    ";
125   oss << "\"" << _name << "\"" << OFF7;
126   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
127   oss << "Dimension=" << _dim << OFF7;
128   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
129   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
130   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
131   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
132   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
133 }
134
135 void MEDFileFieldLoc::setName(const std::string& name)
136 {
137   _name=name;
138 }
139
140 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
141 {
142   if(_name!=other._name)
143     return false;
144   if(_dim!=other._dim)
145     return false;
146   if(_nb_gauss_pt!=other._nb_gauss_pt)
147     return false;
148   if(_nb_node_per_cell!=other._nb_node_per_cell)
149     return false;
150   if(_geo_type!=other._geo_type)
151     return false;
152   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
153     return false;
154   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
155     return false;
156   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
157     return false;
158
159   return true;
160 }
161
162 void MEDFileFieldLoc::writeLL(med_idt fid) const
163 {
164   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);
165 }
166
167 std::string MEDFileFieldLoc::repr() const
168 {
169   std::ostringstream oss; oss.precision(15);
170   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
171   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
172   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
173   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
174   oss << "\n  - Ref coords are : ";
175   int sz=_ref_coo.size();
176   if(sz%_dim==0)
177     {
178       int nbOfTuples=sz/_dim;
179       for(int i=0;i<nbOfTuples;i++)
180         {
181           oss << "(";
182           for(int j=0;j<_dim;j++)
183             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
184           oss << ") ";
185         }
186     }
187   else
188     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
189   oss << "\n  - Gauss coords in reference element : ";
190   sz=_gs_coo.size();
191   if(sz%_dim==0)
192     {
193       int nbOfTuples=sz/_dim;
194       for(int i=0;i<nbOfTuples;i++)
195         {
196           oss << "(";
197           for(int j=0;j<_dim;j++)
198             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
199           oss << ") ";
200         }
201     }
202   else
203     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
204   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
205   return oss.str();
206 }
207
208 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
209 {
210   _type=field->getTypeOfField();
211   _start=start;
212   switch(_type)
213   {
214     case ON_CELLS:
215       {
216         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,offset,offset+nbOfCells,1);
217         _end=_start+nbOfCells;
218         _nval=nbOfCells;
219         break;
220       }
221     case ON_GAUSS_NE:
222       {
223         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
224         const int *arrPtr=arr->getConstPointer();
225         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
226         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
227         _nval=nbOfCells;
228         break;
229       }
230     case ON_GAUSS_PT:
231       {
232         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
233         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
234         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
235         if(!disc2)
236           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
237         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
238         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
239         const int *dai2Ptr=dai2->getConstPointer();
240         int nbi=gsLoc.getWeights().size();
241         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=dai->selectByTupleId2(offset,offset+nbOfCells,1);
242         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
243         const int *da3Ptr=da3->getConstPointer();
244         if(da3->getNumberOfTuples()!=nbOfCells)
245           {//profile : for gauss even in NoProfile !!!
246             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
247             _profile=oss.str();
248             da3->setName(_profile.c_str());
249             glob.appendProfile(da3);
250           }
251         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=DataArrayInt::New();
252         _nval=da3->getNbOfElems();
253         da4->alloc(_nval*nbi,1);
254         int *da4Ptr=da4->getPointer();
255         for(int i=0;i<_nval;i++)
256           {
257             int ref=dai2Ptr[offset+da3Ptr[i]];
258             for(int j=0;j<nbi;j++)
259               *da4Ptr++=ref+j;
260           }
261         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
262         _localization=oss2.str();
263         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
264         _end=_start+_nval*nbi;
265         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
266         break;
267       }
268     default:
269       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
270   }
271   start=_end;
272 }
273
274 /*!
275  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
276  * \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).
277  * \param [in] multiTypePfl is the end user profile specified in high level API
278  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
279  * \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.
280  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
281  * \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.
282  */
283 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)
284 {
285   _profile.clear();
286   _type=field->getTypeOfField();
287   std::string pflName(multiTypePfl->getName());
288   std::ostringstream oss; oss << pflName;
289   if(_type!=ON_NODES)
290     {
291       if(!isPflAlone)
292         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
293     }
294   else
295     { oss << "_NODE"; }
296   if(locIds)
297     {
298       if(pflName.empty())
299         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
300       if(_type!=ON_GAUSS_PT)
301         {
302           locIds->setName(oss.str().c_str());
303           glob.appendProfile(locIds);
304           _profile=oss.str();
305         }
306     }
307   _start=start;
308   switch(_type)
309   {
310     case ON_NODES:
311       {
312         _nval=idsInPfl->getNumberOfTuples();
313         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,arrr->getNumberOfTuples(),1);
314         _end=_start+_nval;
315         break;
316       }
317     case ON_CELLS:
318       {
319         _nval=idsInPfl->getNumberOfTuples();
320         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
321         _end=_start+_nval;
322         break;
323       }
324     case ON_GAUSS_NE:
325       {
326         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
327         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr->deltaShiftIndex();
328         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
329         arr3->computeOffsets2();
330         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
331         int trueNval=tmp->getNumberOfTuples();
332         _nval=idsInPfl->getNumberOfTuples();
333         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
334         _end=_start+trueNval;
335         break;
336       }
337     case ON_GAUSS_PT:
338       {
339         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
340         if(!disc2)
341           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
342         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
343         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
344         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
345         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
346         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
347         //
348         MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
349         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
350         //
351         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New();
352         int trueNval=0;
353         for(const int *pt=da4->begin();pt!=da4->end();pt++)
354           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
355         tmp->alloc(trueNval,1);
356         int *tmpPtr=tmp->getPointer();
357         for(const int *pt=da4->begin();pt!=da4->end();pt++)
358           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
359             *tmpPtr++=j;
360         //
361         _nval=da4->getNumberOfTuples();
362         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
363         _end=_start+trueNval;
364         oss << "_loc_" << _loc_id;
365         if(locIds)
366           {
367             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
368             da5->setName(oss.str().c_str());
369             glob.appendProfile(da5);
370             _profile=oss.str();
371           }
372         else
373           {
374             if(da3->getNumberOfTuples()!=nbOfEltsInWholeMesh || !da3->isIdentity())
375               {
376                 da3->setName(oss.str().c_str());
377                 glob.appendProfile(da3);
378                 _profile=oss.str();
379               }
380           }
381         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
382         _localization=oss2.str();
383         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
384         break;
385       }
386     default:
387       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
388   }
389   start=_end;
390 }
391
392 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
393 {
394   _start=start;
395   _nval=arrr->getNumberOfTuples();
396   getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,_nval,1);
397   _end=_start+_nval;
398   start=_end;
399 }
400
401 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
402 {
403   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
404 }
405
406 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
407 {
408   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
409 }
410
411 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
412 {
413   return new MEDFileFieldPerMeshPerTypePerDisc(other);
414 }
415
416 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
417 {
418   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
419 }
420
421 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
422 {
423   std::vector<const BigMemoryObject *> ret(1);
424   ret[0]=(const PartDefinition*)_pd;
425   return ret;
426 }
427
428 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const
429 {
430   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
431   ret->_father=father;
432   return ret.retn();
433 }
434
435 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
436 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
437 {
438   if(pd)
439     pd->incrRef();
440 }
441 catch(INTERP_KERNEL::Exception& e)
442 {
443     throw e;
444 }
445
446 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
447 {
448 }
449
450 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)
451 {
452 }
453
454 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
455     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
456 {
457 }
458
459 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)
460 {
461   const PartDefinition *pd(_pd);
462   if(!pd)
463     {
464       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
465       int nbi,tmp1;
466       med_int nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
467       if(_end-_start!=nbValsInFile*nbi)
468         {
469           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 !";
470           throw INTERP_KERNEL::Exception(oss.str().c_str());
471         }
472       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr);
473     }
474   else
475     {
476       if(!_profile.empty())
477         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
478       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
479       if(spd)
480         {
481           int profilesize,nbi,start,stop,step;
482           spd->getSlice(start,stop,step);
483           INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
484           int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
485           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
486           med_filter filter=MED_FILTER_INIT;
487           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
488                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
489                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
490                                    /*lastblocksize=useless because count=1*/0,&filter);
491           MEDfieldValueAdvancedRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr);
492           MEDfilterClose(&filter);
493           return ;
494         }
495       else
496         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
497     }
498 }
499
500 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
501 {
502   return _father;
503 }
504
505 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
506 {
507   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
508   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
509   std::string fieldName(nasc.getName()),meshName(getMeshName());
510   int iteration(getIteration()),order(getOrder());
511   TypeOfField type(getType());
512   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
513   int profilesize,nbi;
514   med_geometry_type mgeoti;
515   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
516   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
517   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
518   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
519   const PartDefinition *pd(_pd);
520   if(!pd)
521     {
522       _nval=zeNVal;
523     }
524   else
525     {
526       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
527       if(!spd)
528         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : Part def only implemented for split one !");
529       if(!_profile.empty())
530         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
531       int start1,stop1,step1;
532       spd->getSlice(start1,stop1,step1);
533       _nval=DataArray::GetNumberOfItemGivenBES(start1,stop1,step1,"MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively");
534     }
535   _start=start;
536   _end=start+_nval*nbi;
537   start=_end;
538   if(type==ON_CELLS && !_localization.empty())
539     {
540       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
541         setType(ON_GAUSS_PT);
542       else
543         {
544           setType(ON_GAUSS_NE);
545           _localization.clear();
546         }
547     }
548 }
549
550 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
551 {
552   std::string fieldName(nasc.getName()),meshName(getMeshName());
553   int iteration(getIteration()),order(getOrder());
554   TypeOfField type(getType());
555   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
556   med_geometry_type mgeoti;
557   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
558   if(_start>_end)
559     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
560   if(_start==_end)
561     return ;
562   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
563   if(_start<0 || _start>=arr->getNumberOfTuples())
564     {
565       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
566       throw INTERP_KERNEL::Exception(oss.str().c_str());
567     }
568   if(_end<0 || _end>arr->getNumberOfTuples())
569     {
570       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
571       throw INTERP_KERNEL::Exception(oss.str().c_str());
572     }
573   int nbOfCompo(arr->getNumberOfComponents());
574   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
575   if(arrD)
576     {
577       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
578       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
579       return ;
580     }
581   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
582   if(arrI)
583     {
584       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
585       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
586       return ;
587     }
588   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
589 }
590
591 /*!
592  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
593  */
594 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
595 {
596   int delta=_end-_start;
597   _start=newValueOfStart;
598   _end=_start+delta;
599 }
600
601 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
602 {
603   return _father->getIteration();
604 }
605
606 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
607 {
608   return _father->getOrder();
609 }
610
611 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
612 {
613   return _father->getTime();
614 }
615
616 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
617 {
618   return _father->getMeshName();
619 }
620
621 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
622 {
623   const char startLine[]="    ## ";
624   std::string startLine2(bkOffset,' ');
625   startLine2+=startLine;
626   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
627   oss << startLine2 << "Localization #" << id << "." << std::endl;
628   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
629   delete tmp;
630   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
631   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
632   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
633 }
634
635 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
636 {
637   return _type;
638 }
639
640 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
641 {
642   types.insert(_type);
643 }
644
645 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
646 {
647   _type=newType;
648 }
649
650 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
651 {
652   return _father->getGeoType();
653 }
654
655 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
656 {
657   return _father->getNumberOfComponents();
658 }
659
660 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
661 {
662   return _end-_start;
663 }
664
665 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
666 {
667   return _father->getOrCreateAndGetArray();
668 }
669
670 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
671 {
672   const MEDFileFieldPerMeshPerType *fath=_father;
673   return fath->getOrCreateAndGetArray();
674 }
675
676 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
677 {
678   return _father->getInfo();
679 }
680
681 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
682 {
683   return _profile;
684 }
685
686 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
687 {
688   _profile=newPflName;
689 }
690
691 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
692 {
693   return _localization;
694 }
695
696 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
697 {
698   _localization=newLocName;
699 }
700
701 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
702 {
703   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
704     {
705       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
706         {
707           _profile=(*it2).second;
708           return;
709         }
710     }
711 }
712
713 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
714 {
715   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
716     {
717       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
718         {
719           _localization=(*it2).second;
720           return;
721         }
722     }
723 }
724
725 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
726 {
727   if(type!=_type)
728     return ;
729   dads.push_back(std::pair<int,int>(_start,_end));
730   geoTypes.push_back(getGeoType());
731   if(_profile.empty())
732     pfls.push_back(0);
733   else
734     {
735       pfls.push_back(glob->getProfile(_profile.c_str()));
736     }
737   if(_localization.empty())
738     locs.push_back(-1);
739   else
740     {
741       locs.push_back(glob->getLocalizationId(_localization.c_str()));
742     }
743 }
744
745 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
746 {
747   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));
748   startEntryId++;
749 }
750
751 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
752 {
753   TypeOfField type=getType();
754   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
755   med_geometry_type mgeoti;
756   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
757   const DataArray *arr=getOrCreateAndGetArray();
758   if(!arr)
759     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
760   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
761   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
762   const unsigned char *locToWrite=0;
763   if(arrD)
764     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
765   else if(arrI)
766     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
767   else
768     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
769   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
770                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
771                              locToWrite);
772 }
773
774 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
775 {
776   type=_type;
777   pfl=_profile;
778   loc=_localization;
779   dad.first=_start; dad.second=_end;
780 }
781
782 /*!
783  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
784  *             This code corresponds to the distribution of types in the corresponding mesh.
785  * \param [out] ptToFill memory zone where the output will be stored.
786  * \return the size of data pushed into output param \a ptToFill
787  */
788 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
789 {
790   _loc_id=offset;
791   std::ostringstream oss;
792   std::size_t nbOfType=codeOfMesh.size()/3;
793   int found=-1;
794   for(std::size_t i=0;i<nbOfType && found==-1;i++)
795     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
796       found=(int)i;
797   if(found==-1)
798     {
799       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
800       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
801       throw INTERP_KERNEL::Exception(oss.str().c_str());
802     }
803   int *work=ptToFill;
804   if(_profile.empty())
805     {
806       if(_nval!=codeOfMesh[3*found+1])
807         {
808           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
809           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
810           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
811           throw INTERP_KERNEL::Exception(oss.str().c_str());
812         }
813       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
814         *work++=ii;
815     }
816   else
817     {
818       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
819       if(pfl->getNumberOfTuples()!=_nval)
820         {
821           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
822           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
823           oss << _nval;
824           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
825           throw INTERP_KERNEL::Exception(oss.str().c_str());
826         }
827       int offset2=codeOfMesh[3*found+2];
828       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
829         {
830           if(*pflId<codeOfMesh[3*found+1])
831             *work++=offset2+*pflId;
832         }
833     }
834   return _nval;
835 }
836
837 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
838 {
839   for(int i=_start;i<_end;i++)
840     *ptToFill++=i;
841   return _end-_start;
842 }
843
844 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
845 {
846   switch(type)
847   {
848     case ON_CELLS:
849       return -2;
850     case ON_GAUSS_NE:
851       return -1;
852     case ON_GAUSS_PT:
853       return locId;
854     default:
855       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
856   }
857 }
858
859 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
860 {
861   int id=0;
862   std::map<std::pair<std::string,TypeOfField>,int> m;
863   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
864   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
865     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
866       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
867   ret.resize(id);
868   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
869     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
870   return ret;
871 }
872
873 /*!
874  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
875  * 
876  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
877  * \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.
878  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
879  * \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)
880  * \param [in,out] glob if necessary by the method, new profiles can be added to it
881  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
882  * \param [out] result All new entries will be appended on it.
883  * \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 !)
884  */
885 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
886                                                        const DataArrayInt *explicitIdsInMesh,
887                                                        const std::vector<int>& newCode,
888                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
889                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
890 {
891   if(entriesOnSameDisc.empty())
892     return false;
893   TypeOfField type=entriesOnSameDisc[0]->getType();
894   int szEntities=0,szTuples=0;
895   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
896     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
897   int nbi=szTuples/szEntities;
898   if(szTuples%szEntities!=0)
899     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
900   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
901   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
902   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
903   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
904   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
905   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
906   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
907   int id=0;
908   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
909     {
910       int startOfEltIdOfChunk=(*it)->_start;
911       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
912       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
913       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
914       //
915       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
916       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
917       //
918       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
919       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
920     }
921   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
922   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
923   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
924   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
925   //
926   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
927   //
928   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
929   arrPart->renumberInPlace(renumTupleIds->begin());
930   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
931   bool ret=false;
932   const int *idIt=diffVals->begin();
933   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
934   int offset2=0;
935   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
936     {
937       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
938       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
939       int nbEntityElts=subIds->getNumberOfTuples();
940       bool ret2;
941       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
942           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
943                                       offset+offset2,
944                                       li,glob,ret2);
945       ret=ret || ret2;
946       result.push_back(eltToAdd);
947       offset2+=nbEntityElts*nbi;
948     }
949   ret=ret || li.empty();
950   return ret;
951 }
952
953 /*!
954  * \param [in] typeF type of field of new chunk
955  * \param [in] geoType the geometric type of the chunk
956  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
957  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
958  * \param [in] nbi number of integration points
959  * \param [in] offset The offset in the **global array of data**.
960  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
961  *                 to the new chunk to create.
962  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
963  * \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
964  *              and corresponding entry erased from \a entriesOnSameDisc.
965  * \return a newly allocated chunk
966  */
967 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
968                                                                                                   bool isPfl, int nbi, int offset,
969                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
970                                                                                                   MEDFileFieldGlobsReal& glob,
971                                                                                                   bool &notInExisting)
972 {
973   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
974   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
975   for(;it!=entriesOnSameDisc.end();it++)
976     {
977       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
978         {
979           if(!isPfl)
980             {
981               if((*it)->_profile.empty())
982                 break;
983               else
984                 if(!(*it)->_profile.empty())
985                   {
986                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
987                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
988                       break;
989                   }
990             }
991         }
992     }
993   if(it==entriesOnSameDisc.end())
994     {
995       notInExisting=true;
996       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
997       ret->_type=typeF;
998       ret->_loc_id=(int)geoType;
999       ret->_nval=nbMeshEntities;
1000       ret->_start=offset;
1001       ret->_end=ret->_start+ret->_nval*nbi;
1002       if(isPfl)
1003         {
1004           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1005           glob.appendProfile(idsOfMeshElt);
1006           ret->_profile=idsOfMeshElt->getName();
1007         }
1008       //tony treatment of localization
1009       return ret;
1010     }
1011   else
1012     {
1013       notInExisting=false;
1014       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1015       ret->_loc_id=(int)geoType;
1016       ret->setNewStart(offset);
1017       entriesOnSameDisc.erase(it);
1018       return ret;
1019     }
1020
1021 }
1022
1023 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1024 {
1025   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1026 }
1027
1028 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1029 {
1030   return new MEDFileFieldPerMeshPerType(fath,geoType);
1031 }
1032
1033 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
1034 {
1035   return _field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
1036 }
1037
1038 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
1039 {
1040   std::vector<const BigMemoryObject *> ret;
1041   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1042     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1043   return ret;
1044 }
1045
1046 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const
1047 {
1048   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1049   ret->_father=father;
1050   std::size_t i=0;
1051   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1052     {
1053       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1054         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
1055     }
1056   return ret.retn();
1057 }
1058
1059 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1060 {
1061   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1062   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1063     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1064 }
1065
1066 /*!
1067  * This method is the most general one. No optimization is done here.
1068  * \param [in] multiTypePfl is the end user profile specified in high level API
1069  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1070  * \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.
1071  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1072  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1073  * \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.
1074  */
1075 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)
1076 {
1077   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1078   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1079     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1080 }
1081
1082 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1083 {
1084   _field_pm_pt_pd.resize(1);
1085   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1086   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1087 }
1088
1089 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1090 {
1091   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1092   if(!arr || !arr->isAllocated())
1093     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1094   _field_pm_pt_pd.resize(1);
1095   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1096   _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.
1097 }
1098
1099 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1100 {
1101   TypeOfField type=field->getTypeOfField();
1102   if(type!=ON_GAUSS_PT)
1103     {
1104       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1105       int sz=_field_pm_pt_pd.size();
1106       bool found=false;
1107       for(int j=0;j<sz && !found;j++)
1108         {
1109           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1110             {
1111               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1112               found=true;
1113             }
1114         }
1115       if(!found)
1116         {
1117           _field_pm_pt_pd.resize(sz+1);
1118           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1119         }
1120       std::vector<int> ret(1,(int)sz);
1121       return ret;
1122     }
1123   else
1124     {
1125       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1126       int sz2=ret2.size();
1127       std::vector<int> ret3(sz2);
1128       int k=0;
1129       for(int i=0;i<sz2;i++)
1130         {
1131           int sz=_field_pm_pt_pd.size();
1132           int locIdToFind=ret2[i];
1133           bool found=false;
1134           for(int j=0;j<sz && !found;j++)
1135             {
1136               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1137                 {
1138                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1139                   ret3[k++]=j;
1140                   found=true;
1141                 }
1142             }
1143           if(!found)
1144             {
1145               _field_pm_pt_pd.resize(sz+1);
1146               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1147               ret3[k++]=sz;
1148             }
1149         }
1150       return ret3;
1151     }
1152 }
1153
1154 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1155 {
1156   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1157   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1158   if(!disc2)
1159     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1160   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1161   if(!da)
1162     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1163   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1164   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1165   if(retTmp->presenceOfValue(-1))
1166     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1167   std::vector<int> ret(retTmp->begin(),retTmp->end());
1168   return ret;
1169 }
1170
1171 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1172 {
1173   TypeOfField type=field->getTypeOfField();
1174   if(type!=ON_GAUSS_PT)
1175     {
1176       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1177       int sz=_field_pm_pt_pd.size();
1178       bool found=false;
1179       for(int j=0;j<sz && !found;j++)
1180         {
1181           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1182             {
1183               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1184               found=true;
1185             }
1186         }
1187       if(!found)
1188         {
1189           _field_pm_pt_pd.resize(sz+1);
1190           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1191         }
1192       std::vector<int> ret(1,0);
1193       return ret;
1194     }
1195   else
1196     {
1197       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1198       int sz2=ret2.size();
1199       std::vector<int> ret3(sz2);
1200       int k=0;
1201       for(int i=0;i<sz2;i++)
1202         {
1203           int sz=_field_pm_pt_pd.size();
1204           int locIdToFind=ret2[i];
1205           bool found=false;
1206           for(int j=0;j<sz && !found;j++)
1207             {
1208               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1209                 {
1210                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1211                   ret3[k++]=j;
1212                   found=true;
1213                 }
1214             }
1215           if(!found)
1216             {
1217               _field_pm_pt_pd.resize(sz+1);
1218               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1219               ret3[k++]=sz;
1220             }
1221         }
1222       return ret3;
1223     }
1224 }
1225
1226 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1227 {
1228   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1229   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1230   if(!disc2)
1231     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1232   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1233   if(!da)
1234     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1235   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1236   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1237   if(retTmp->presenceOfValue(-1))
1238     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1239   std::vector<int> ret(retTmp->begin(),retTmp->end());
1240   return ret;
1241 }
1242
1243 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1244 {
1245   return _father;
1246 }
1247
1248 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1249 {
1250   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1251   int curDim=(int)cm.getDimension();
1252   dim=std::max(dim,curDim);
1253 }
1254
1255 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1256 {
1257   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1258     {
1259       (*it)->fillTypesOfFieldAvailable(types);
1260     }
1261 }
1262
1263 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
1264 {
1265   int sz=_field_pm_pt_pd.size();
1266   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1267   for(int i=0;i<sz;i++)
1268     {
1269       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1270     }
1271 }
1272
1273 int MEDFileFieldPerMeshPerType::getIteration() const
1274 {
1275   return _father->getIteration();
1276 }
1277
1278 int MEDFileFieldPerMeshPerType::getOrder() const
1279 {
1280   return _father->getOrder();
1281 }
1282
1283 double MEDFileFieldPerMeshPerType::getTime() const
1284 {
1285   return _father->getTime();
1286 }
1287
1288 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1289 {
1290   return _father->getMeshName();
1291 }
1292
1293 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1294 {
1295   const char startLine[]="  ## ";
1296   std::string startLine2(bkOffset,' ');
1297   std::string startLine3(startLine2);
1298   startLine3+=startLine;
1299   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1300     {
1301       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1302       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1303     }
1304   else
1305     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1306   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1307   int i=0;
1308   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1309     {
1310       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1311       if(cur)
1312         cur->simpleRepr(bkOffset,oss,i);
1313       else
1314         {
1315           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1316         }
1317     }
1318 }
1319
1320 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1321 {
1322   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1323     {
1324       globalSz+=(*it)->getNumberOfTuples();
1325     }
1326   nbOfEntries+=(int)_field_pm_pt_pd.size();
1327 }
1328
1329 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1330 {
1331   return _geo_type;
1332 }
1333
1334
1335 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1336 {
1337   return _father->getNumberOfComponents();
1338 }
1339
1340 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1341 {
1342   return _father->getOrCreateAndGetArray();
1343 }
1344
1345 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1346 {
1347   const MEDFileFieldPerMesh *fath=_father;
1348   return fath->getOrCreateAndGetArray();
1349 }
1350
1351 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1352 {
1353   return _father->getInfo();
1354 }
1355
1356 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1357 {
1358   std::vector<std::string> ret;
1359   std::set<std::string> ret2;
1360   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1361     {
1362       std::string tmp=(*it1)->getProfile();
1363       if(!tmp.empty())
1364         if(ret2.find(tmp)==ret2.end())
1365           {
1366             ret.push_back(tmp);
1367             ret2.insert(tmp);
1368           }
1369     }
1370   return ret;
1371 }
1372
1373 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1374 {
1375   std::vector<std::string> ret;
1376   std::set<std::string> ret2;
1377   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1378     {
1379       std::string tmp=(*it1)->getLocalization();
1380       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1381         if(ret2.find(tmp)==ret2.end())
1382           {
1383             ret.push_back(tmp);
1384             ret2.insert(tmp);
1385           }
1386     }
1387   return ret;
1388 }
1389
1390 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1391 {
1392   std::vector<std::string> ret;
1393   std::set<std::string> ret2;
1394   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1395     {
1396       std::string tmp=(*it1)->getProfile();
1397       if(!tmp.empty())
1398         ret.push_back(tmp);
1399     }
1400   return ret;
1401 }
1402
1403 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1404 {
1405   std::vector<std::string> ret;
1406   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1407     {
1408       std::string tmp=(*it1)->getLocalization();
1409       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1410         ret.push_back(tmp);
1411     }
1412   return ret;
1413 }
1414
1415 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1416 {
1417   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1418     (*it1)->changePflsRefsNamesGen(mapOfModif);
1419 }
1420
1421 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1422 {
1423   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1424     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1425 }
1426
1427 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1428 {
1429   if(_field_pm_pt_pd.empty())
1430     {
1431       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1432       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1433       throw INTERP_KERNEL::Exception(oss.str().c_str());
1434     }
1435   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1436     return _field_pm_pt_pd[locId];
1437   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1438   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1439   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1440   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1441   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1442 }
1443
1444 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1445 {
1446   if(_field_pm_pt_pd.empty())
1447     {
1448       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1449       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1450       throw INTERP_KERNEL::Exception(oss.str().c_str());
1451     }
1452   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1453     return _field_pm_pt_pd[locId];
1454   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1455   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1456   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1457   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1458   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1459 }
1460
1461 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
1462 {
1463   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1464     {
1465       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1466       if(meshDim!=(int)cm.getDimension())
1467         return ;
1468     }
1469   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1470     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1471 }
1472
1473 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1474 {
1475   int i=0;
1476   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1477     {
1478       (*it)->fillValues(i,startEntryId,entries);
1479     }
1480 }
1481
1482 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1483 {
1484   _field_pm_pt_pd=leaves;
1485   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1486     (*it)->setFather(this);
1487 }
1488
1489 /*!
1490  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1491  *  \param [out] its - list of pair (start,stop) kept
1492  *  \return bool - false if the type of field \a tof is not contained in \a this.
1493  */
1494 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1495 {
1496   bool ret=false;
1497   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1498   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1499     if((*it)->getType()==tof)
1500       {
1501         newPmPtPd.push_back(*it);
1502         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1503         (*it)->setNewStart(globalNum);
1504         globalNum=(*it)->getEnd();
1505         its.push_back(bgEnd);
1506         ret=true;
1507       }
1508   if(ret)
1509     _field_pm_pt_pd=newPmPtPd;
1510   return ret;
1511 }
1512
1513 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1514 {
1515 }
1516
1517 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType)
1518 {
1519   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1520   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1521   med_geometry_type mgeoti;
1522   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1523   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1524   _field_pm_pt_pd.resize(nbProfiles);
1525   for(int i=0;i<nbProfiles;i++)
1526     {
1527       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1528     }
1529   if(type==ON_CELLS)
1530     {
1531       int nbProfiles2=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName);
1532       for(int i=0;i<nbProfiles2;i++)
1533         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1534     }
1535 }
1536
1537 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1538 {
1539   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1540     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1541 }
1542
1543 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1544 {
1545   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1546     (*it)->loadBigArray(fid,nasc);
1547 }
1548
1549 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1550 {
1551   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1552     {
1553       (*it)->copyOptionsFrom(*this);
1554       (*it)->writeLL(fid,nasc);
1555     }
1556 }
1557
1558 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1559 {
1560   switch(ikType)
1561   {
1562     case ON_CELLS:
1563       medfGeoType=typmai3[(int)ikGeoType];
1564       return MED_CELL;
1565     case ON_NODES:
1566       medfGeoType=MED_NONE;
1567       return MED_NODE;
1568     case ON_GAUSS_NE:
1569       medfGeoType=typmai3[(int)ikGeoType];
1570       return MED_NODE_ELEMENT;
1571     case ON_GAUSS_PT:
1572       medfGeoType=typmai3[(int)ikGeoType];
1573       return MED_CELL;
1574     default:
1575       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1576   }
1577   return MED_UNDEF_ENTITY_TYPE;
1578 }
1579
1580 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm)
1581 {
1582   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm);
1583 }
1584
1585 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1586 {
1587   return new MEDFileFieldPerMesh(fath,mesh);
1588 }
1589
1590 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1591 {
1592   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1593 }
1594
1595 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1596 {
1597   std::vector<const BigMemoryObject *> ret;
1598   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1599     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1600   return ret;
1601 }
1602
1603 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1604 {
1605   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1606   ret->_father=father;
1607   std::size_t i=0;
1608   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1609     {
1610       if((const MEDFileFieldPerMeshPerType *)*it)
1611         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1612     }
1613   return ret.retn();
1614 }
1615
1616 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1617 {
1618   std::string startLine(bkOffset,' ');
1619   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1620   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1621   int i=0;
1622   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1623     {
1624       const MEDFileFieldPerMeshPerType *cur=*it;
1625       if(cur)
1626         cur->simpleRepr(bkOffset,oss,i);
1627       else
1628         {
1629           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1630         }
1631     }
1632 }
1633
1634 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1635 {
1636   _mesh_name=mesh->getName();
1637   mesh->getTime(_mesh_iteration,_mesh_order);
1638 }
1639
1640 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1641 {
1642   int nbOfTypes=code.size()/3;
1643   int offset=0;
1644   for(int i=0;i<nbOfTypes;i++)
1645     {
1646       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1647       int nbOfCells=code[3*i+1];
1648       int pos=addNewEntryIfNecessary(type);
1649       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1650       offset+=nbOfCells;
1651     }
1652 }
1653
1654 /*!
1655  * This method is the most general one. No optimization is done here.
1656  * \param [in] multiTypePfl is the end user profile specified in high level API
1657  * \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].
1658  * \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.
1659  * \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.
1660  * \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.
1661  * \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.
1662  */
1663 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)
1664 {
1665   int nbOfTypes(code.size()/3);
1666   for(int i=0;i<nbOfTypes;i++)
1667     {
1668       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1669       int pos=addNewEntryIfNecessary(type);
1670       DataArrayInt *pfl=0;
1671       if(code[3*i+2]!=-1)
1672         pfl=idsPerType[code[3*i+2]];
1673       int nbOfTupes2=code2.size()/3;
1674       int found=0;
1675       for(;found<nbOfTupes2;found++)
1676         if(code[3*i]==code2[3*found])
1677           break;
1678       if(found==nbOfTupes2)
1679         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1680       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1681     }
1682 }
1683
1684 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1685 {
1686   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1687   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1688 }
1689
1690 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1691 {
1692   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1693   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1694 }
1695
1696 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1697 {
1698   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1699     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1700 }
1701
1702 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1703 {
1704   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1705     (*it)->loadBigArraysRecursively(fid,nasc);
1706 }
1707
1708 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1709 {
1710   int nbOfTypes=_field_pm_pt.size();
1711   for(int i=0;i<nbOfTypes;i++)
1712     {
1713       _field_pm_pt[i]->copyOptionsFrom(*this);
1714       _field_pm_pt[i]->writeLL(fid,nasc);
1715     }
1716 }
1717
1718 void MEDFileFieldPerMesh::getDimension(int& dim) const
1719 {
1720   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1721     (*it)->getDimension(dim);
1722 }
1723
1724 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1725 {
1726   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1727     (*it)->fillTypesOfFieldAvailable(types);
1728 }
1729
1730 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
1731 {
1732   int sz=_field_pm_pt.size();
1733   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1734   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1735   for(int i=0;i<sz;i++)
1736     {
1737       types[i]=_field_pm_pt[i]->getGeoType();
1738       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1739     }
1740   return ret;
1741 }
1742
1743 double MEDFileFieldPerMesh::getTime() const
1744 {
1745   int tmp1,tmp2;
1746   return _father->getTime(tmp1,tmp2);
1747 }
1748
1749 int MEDFileFieldPerMesh::getIteration() const
1750 {
1751   return _father->getIteration();
1752 }
1753
1754 int MEDFileFieldPerMesh::getOrder() const
1755 {
1756   return _father->getOrder();
1757 }
1758
1759 int MEDFileFieldPerMesh::getNumberOfComponents() const
1760 {
1761   return _father->getNumberOfComponents();
1762 }
1763
1764 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1765 {
1766   if(!_father)
1767     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1768   return _father->getOrCreateAndGetArray();
1769 }
1770
1771 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1772 {
1773   if(!_father)
1774     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1775   return _father->getOrCreateAndGetArray();
1776 }
1777
1778 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1779 {
1780   return _father->getInfo();
1781 }
1782
1783 /*!
1784  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1785  * 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.
1786  * It returns 2 output vectors :
1787  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1788  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1789  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1790  */
1791 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)
1792 {
1793   int notNullPflsSz=0;
1794   int nbOfArrs=geoTypes.size();
1795   for(int i=0;i<nbOfArrs;i++)
1796     if(pfls[i])
1797       notNullPflsSz++;
1798   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1799   int nbOfDiffGeoTypes=geoTypes3.size();
1800   code.resize(3*nbOfDiffGeoTypes);
1801   notNullPfls.resize(notNullPflsSz);
1802   notNullPflsSz=0;
1803   int j=0;
1804   for(int i=0;i<nbOfDiffGeoTypes;i++)
1805     {
1806       int startZone=j;
1807       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1808       std::vector<const DataArrayInt *> notNullTmp;
1809       if(pfls[j])
1810         notNullTmp.push_back(pfls[j]);
1811       j++;
1812       for(;j<nbOfArrs;j++)
1813         if(geoTypes[j]==refType)
1814           {
1815             if(pfls[j])
1816               notNullTmp.push_back(pfls[j]);
1817           }
1818         else
1819           break;
1820       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1821       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1822       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1823       code[3*i]=(int)refType;
1824       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1825       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1826       if(notNullTmp.empty())
1827         code[3*i+2]=-1;
1828       else
1829         {
1830           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1831           code[3*i+2]=notNullPflsSz++;
1832         }
1833     }
1834 }
1835
1836 /*!
1837  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1838  */
1839 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)
1840 {
1841   int sz=dads.size();
1842   int ret=0;
1843   for(int i=0;i<sz;i++)
1844     {
1845       if(locs[i]==-1)
1846         {
1847           if(type!=ON_GAUSS_NE)
1848             ret+=dads[i].second-dads[i].first;
1849           else
1850             {
1851               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1852               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1853             }
1854         }
1855       else
1856         {
1857           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1858           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1859         }
1860     }
1861   return ret;
1862 }
1863
1864 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1865 {
1866   std::vector<std::string> ret;
1867   std::set<std::string> ret2;
1868   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1869     {
1870       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1871       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1872         if(ret2.find(*it2)==ret2.end())
1873           {
1874             ret.push_back(*it2);
1875             ret2.insert(*it2);
1876           }
1877     }
1878   return ret;
1879 }
1880
1881 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1882 {
1883   std::vector<std::string> ret;
1884   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1885     {
1886       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1887       ret.insert(ret.end(),tmp.begin(),tmp.end());
1888     }
1889   return ret;
1890 }
1891
1892 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1893 {
1894   std::vector<std::string> ret;
1895   std::set<std::string> ret2;
1896   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1897     {
1898       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1899       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1900         if(ret2.find(*it2)==ret2.end())
1901           {
1902             ret.push_back(*it2);
1903             ret2.insert(*it2);
1904           }
1905     }
1906   return ret;
1907 }
1908
1909 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1910 {
1911   std::vector<std::string> ret;
1912   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1913     {
1914       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1915       ret.insert(ret.end(),tmp.begin(),tmp.end());
1916     }
1917   return ret;
1918 }
1919
1920 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1921 {
1922   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1923     {
1924       if((*it).first==_mesh_name)
1925         {
1926           _mesh_name=(*it).second;
1927           return true;
1928         }
1929     }
1930   return false;
1931 }
1932
1933 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1934                                                       MEDFileFieldGlobsReal& glob)
1935 {
1936   if(_mesh_name!=meshName)
1937     return false;
1938   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1939   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1940   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1941   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1942   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1943   getUndergroundDataArrayExt(entries);
1944   DataArray *arr0=getOrCreateAndGetArray();//tony
1945   if(!arr0)
1946     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
1947   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
1948   if(!arr0)
1949     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
1950   int sz=0;
1951   if(!arr)
1952     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1953   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1954     {
1955       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1956         {
1957           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1958           sz+=(*it).second.second-(*it).second.first;
1959         }
1960       else
1961         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1962     }
1963   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1964   ////////////////////
1965   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1966   int *workI2=explicitIdsOldInMesh->getPointer();
1967   int sz1=0,sz2=0,sid=1;
1968   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1969   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1970   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1971     {
1972       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1973       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1974       int *workI=explicitIdsOldInArr->getPointer();
1975       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1976         {
1977           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1978           (*itL2)->setLocId(sz2);
1979           (*itL2)->_tmp_work1=(*itL2)->getStart();
1980           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1981         }
1982       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1983     }
1984   explicitIdsOldInMesh->reAlloc(sz2);
1985   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1986   ////////////////////
1987   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1988   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1989   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1990   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1991     {
1992       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1993       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1994       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1995     }
1996   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1997   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1998   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
1999     {
2000       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2001       int newStart=elt->getLocId();
2002       elt->setLocId((*it)->getGeoType());
2003       elt->setNewStart(newStart);
2004       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2005       entriesKeptNew.push_back(elt);
2006       entriesKeptNew2.push_back(elt);
2007     }
2008   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2009   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2010   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2011   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2012   bool ret=false;
2013   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2014     {
2015       sid=0;
2016       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2017         {
2018           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2019           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2020           }*/
2021       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2022                                                             glob,arr2,otherEntriesNew) || ret;
2023     }
2024   if(!ret)
2025     return false;
2026   // Assign new dispatching
2027   assignNewLeaves(otherEntriesNew);
2028   arr->cpyFrom(*arr2);
2029   return true;
2030 }
2031
2032 /*!
2033  * \param [in,out] globalNum a global numbering counter for the renumbering.
2034  * \param [out] its - list of pair (start,stop) kept
2035  */
2036 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2037 {
2038   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
2039   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2040     {
2041       std::vector< std::pair<int,int> > its2;
2042       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2043         {
2044           ret.push_back(*it);
2045           its.insert(its.end(),its2.begin(),its2.end());
2046         }
2047     }
2048   _field_pm_pt=ret;
2049 }
2050
2051 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2052 {
2053   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2054   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2055     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2056   //
2057   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2058   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2059   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2060   for(;it1!=types.end();it1++,it2++)
2061     {
2062       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2063       elt->setLeaves((*it1).second);
2064       *it2=elt;
2065     }
2066   _field_pm_pt=fieldPmPt;
2067 }
2068
2069 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2070 {
2071   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2072     (*it)->changePflsRefsNamesGen(mapOfModif);
2073 }
2074
2075 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2076 {
2077   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2078     (*it)->changeLocsRefsNamesGen(mapOfModif);
2079 }
2080
2081 /*!
2082  * \param [in] mesh is the whole mesh
2083  */
2084 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2085 {
2086   if(_field_pm_pt.empty())
2087     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2088   //
2089   std::vector< std::pair<int,int> > dads;
2090   std::vector<const DataArrayInt *> pfls;
2091   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2092   std::vector<int> locs,code;
2093   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2094   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2095     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2096   // Sort by types
2097   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2098   if(code.empty())
2099     {
2100       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2101       throw INTERP_KERNEL::Exception(oss.str().c_str());
2102     }
2103   //
2104   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2105   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2106   if(type!=ON_NODES)
2107     {
2108       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2109       if(!arr)
2110         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2111       else
2112         {
2113           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2114           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2115         }
2116     }
2117   else
2118     {
2119       if(code.size()!=3)
2120         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2121       int nb=code[1];
2122       if(code[2]==-1)
2123         {
2124           if(nb!=mesh->getNumberOfNodes())
2125             {
2126               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2127               oss << " nodes in mesh !";
2128               throw INTERP_KERNEL::Exception(oss.str().c_str());
2129             }
2130           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2131         }
2132       else
2133         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2134     }
2135 }
2136
2137 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2138 {
2139   if(_field_pm_pt.empty())
2140     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2141   //
2142   std::vector<std::pair<int,int> > dads;
2143   std::vector<const DataArrayInt *> pfls;
2144   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2145   std::vector<int> locs,code;
2146   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2147   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2148     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2149   // Sort by types
2150   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2151   if(code.empty())
2152     {
2153       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2154       throw INTERP_KERNEL::Exception(oss.str().c_str());
2155     }
2156   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2157   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2158   if(type!=ON_NODES)
2159     {
2160       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2161       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2162     }
2163   else
2164     {
2165       if(code.size()!=3)
2166         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2167       int nb=code[1];
2168       if(code[2]==-1)
2169         {
2170           if(nb!=mesh->getNumberOfNodes())
2171             {
2172               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2173               oss << " nodes in mesh !";
2174               throw INTERP_KERNEL::Exception(oss.str().c_str());
2175             }
2176         }
2177       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2178     }
2179   //
2180   return 0;
2181 }
2182
2183 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2184 {
2185   int globalSz=0;
2186   int nbOfEntries=0;
2187   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2188     {
2189       (*it)->getSizes(globalSz,nbOfEntries);
2190     }
2191   entries.resize(nbOfEntries);
2192   nbOfEntries=0;
2193   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2194     {
2195       (*it)->fillValues(nbOfEntries,entries);
2196     }
2197 }
2198
2199 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2200 {
2201   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2202     {
2203       if((*it)->getGeoType()==typ)
2204         return (*it)->getLeafGivenLocId(locId);
2205     }
2206   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2207   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2208   oss << "Possiblities are : ";
2209   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2210     {
2211       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2212       oss << "\"" << cm2.getRepr() << "\", ";
2213     }
2214   throw INTERP_KERNEL::Exception(oss.str().c_str());
2215 }
2216
2217 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2218 {
2219   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2220     {
2221       if((*it)->getGeoType()==typ)
2222         return (*it)->getLeafGivenLocId(locId);
2223     }
2224   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2225   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2226   oss << "Possiblities are : ";
2227   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2228     {
2229       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2230       oss << "\"" << cm2.getRepr() << "\", ";
2231     }
2232   throw INTERP_KERNEL::Exception(oss.str().c_str());
2233 }
2234
2235 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2236 {
2237   int i=0;
2238   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2239   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2240   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2241     {
2242       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2243       if(type==curType)
2244         return i;
2245       else
2246         {
2247           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2248           if(pos>pos2)
2249             it2=it+1;
2250         }
2251     }
2252   int ret=std::distance(_field_pm_pt.begin(),it2);
2253   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2254   return ret;
2255 }
2256
2257 /*!
2258  * 'dads' and 'locs' input parameters have the same number of elements
2259  * \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
2260  */
2261 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2262                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2263                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2264 {
2265   isPfl=false;
2266   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2267   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2268   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2269   const std::vector<std::string>& infos=getInfo();
2270   da->setInfoOnComponents(infos);
2271   da->setName("");
2272   if(type==ON_GAUSS_PT)
2273     {
2274       int offset=0;
2275       int nbOfArrs=dads.size();
2276       for(int i=0;i<nbOfArrs;i++)
2277         {
2278           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2279           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2280           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2281           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2282           di->alloc(nbOfElems,1);
2283           di->iota(offset);
2284           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2285           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2286           offset+=nbOfElems;
2287         }
2288     }
2289   arrOut=da;
2290   return ret.retn();
2291 }
2292
2293 /*!
2294  * 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.
2295  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2296  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2297  * The order of cells in the returned field is those imposed by the profile.
2298  * \param [in] mesh is the global mesh.
2299  */
2300 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2301                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2302                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2303                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2304 {
2305   if(da->isIdentity())
2306     {
2307       int nbOfTuples=da->getNumberOfTuples();
2308       if(nbOfTuples==mesh->getNumberOfCells())
2309         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2310     }
2311   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2312   m2->setName(mesh->getName().c_str());
2313   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2314   isPfl=true;
2315   return ret.retn();
2316 }
2317
2318 /*!
2319  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2320  */
2321 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2322                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2323                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2324 {
2325   if(da->isIdentity())
2326     {
2327       int nbOfTuples=da->getNumberOfTuples();
2328       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2329         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2330     }
2331   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2332   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2333   if(meshu)
2334     {
2335       if(meshu->getNodalConnectivity()==0)
2336         {
2337           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2338           int nb=da->getNbOfElems();
2339           const int *ptr=da->getConstPointer();
2340           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2341           meshuc->allocateCells(nb);
2342           for(int i=0;i<nb;i++)
2343             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2344           meshuc->finishInsertingCells();
2345           ret->setMesh(meshuc);
2346           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2347           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2348           disc->checkCoherencyBetween(meshuc,arrOut);
2349           return ret.retn();
2350         }
2351     }
2352   //
2353   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2354   isPfl=true;
2355   DataArrayInt *arr2=0;
2356   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2357   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2358   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2359   int nnodes=mesh2->getNumberOfNodes();
2360   if(nnodes==(int)da->getNbOfElems())
2361     {
2362       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2363       arrOut->renumberInPlace(da3->getConstPointer());
2364       mesh2->setName(mesh->getName().c_str());
2365       ret->setMesh(mesh2);
2366       return ret.retn();
2367     }
2368   else
2369     {
2370       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 !!!";
2371       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2372       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2373       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2374       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2375       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2376       throw INTERP_KERNEL::Exception(oss.str().c_str());
2377     }
2378   return 0;
2379 }
2380
2381 /*!
2382  * This method is the most light method of field retrieving.
2383  */
2384 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2385 {
2386   if(!pflIn)
2387     {
2388       pflOut=DataArrayInt::New();
2389       pflOut->alloc(nbOfElems,1);
2390       pflOut->iota(0);
2391     }
2392   else
2393     {
2394       pflOut=const_cast<DataArrayInt*>(pflIn);
2395       pflOut->incrRef();
2396     }
2397   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2398   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2399   const std::vector<std::string>& infos=getInfo();
2400   int nbOfComp=infos.size();
2401   for(int i=0;i<nbOfComp;i++)
2402     da->setInfoOnComponent(i,infos[i].c_str());
2403   safePfl->incrRef();
2404   return da.retn();
2405 }
2406
2407 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2408     _father(fath)
2409 {
2410   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2411   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2412   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2413   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2414   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2415     {
2416       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[i],meshCsit+1,meshName,pflName,locName));
2417       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2418       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],meshCsit+1,meshName,pflName,locName));
2419       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2420       if(nbProfile>0 || nbProfile2>0)
2421         {
2422           const PartDefinition *pd(0);
2423           if(mmu)
2424             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[i]),typmai2[i]);
2425           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i],nasc,pd));
2426           if(nbProfile>0)
2427             _mesh_name=name0;
2428           else
2429             _mesh_name=name1;
2430         }
2431     }
2432   int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName);
2433   if(nbProfile>0)
2434     {
2435       const PartDefinition *pd(0);
2436       if(mmu)
2437         pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2438       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2439       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2440     }
2441 }
2442
2443 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2444 {
2445   copyTinyInfoFrom(mesh);
2446 }
2447
2448 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2449 {
2450   if(id>=(int)_pfls.size())
2451     _pfls.resize(id+1);
2452   _pfls[id]=DataArrayInt::New();
2453   int lgth=MEDprofileSizeByName(fid,pflName.c_str());
2454   _pfls[id]->setName(pflName);
2455   _pfls[id]->alloc(lgth,1);
2456   MEDprofileRd(fid,pflName.c_str(),_pfls[id]->getPointer());
2457   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2458 }
2459
2460 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2461 {
2462   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2463   int sz;
2464   MEDprofileInfo(fid,i+1,pflName,&sz);
2465   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2466   if(i>=(int)_pfls.size())
2467     _pfls.resize(i+1);
2468   _pfls[i]=DataArrayInt::New();
2469   _pfls[i]->alloc(sz,1);
2470   _pfls[i]->setName(pflCpp.c_str());
2471   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2472   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2473 }
2474
2475 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2476 {
2477   int nbOfPfls=_pfls.size();
2478   for(int i=0;i<nbOfPfls;i++)
2479     {
2480       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2481       cpy->applyLin(1,1,0);
2482       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2483       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2484       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2485     }
2486   //
2487   int nbOfLocs=_locs.size();
2488   for(int i=0;i<nbOfLocs;i++)
2489     _locs[i]->writeLL(fid);
2490 }
2491
2492 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2493 {
2494   std::vector<std::string> pfls=getPfls();
2495   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2496     {
2497       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2498       if(it2==pfls.end())
2499         {
2500           _pfls.push_back(*it);
2501         }
2502       else
2503         {
2504           int id=std::distance(pfls.begin(),it2);
2505           if(!(*it)->isEqual(*_pfls[id]))
2506             {
2507               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2508               throw INTERP_KERNEL::Exception(oss.str().c_str());
2509             }
2510         }
2511     }
2512   std::vector<std::string> locs=getLocs();
2513   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2514     {
2515       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2516       if(it2==locs.end())
2517         {
2518           _locs.push_back(*it);
2519         }
2520       else
2521         {
2522           int id=std::distance(locs.begin(),it2);
2523           if(!(*it)->isEqual(*_locs[id],eps))
2524             {
2525               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2526               throw INTERP_KERNEL::Exception(oss.str().c_str());
2527             }
2528         }
2529     }
2530 }
2531
2532 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2533 {
2534   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2535     getProfile((*it).c_str());
2536 }
2537
2538 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2539 {
2540   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2541     getLocalization((*it).c_str());
2542 }
2543
2544 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2545 {
2546   std::vector<std::string> profiles=real.getPflsReallyUsed();
2547   int sz=profiles.size();
2548   _pfls.resize(sz);
2549   for(int i=0;i<sz;i++)
2550     loadProfileInFile(fid,i,profiles[i].c_str());
2551   //
2552   std::vector<std::string> locs=real.getLocsReallyUsed();
2553   sz=locs.size();
2554   _locs.resize(sz);
2555   for(int i=0;i<sz;i++)
2556     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2557 }
2558
2559 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2560 {
2561   int nProfil=MEDnProfile(fid);
2562   for(int i=0;i<nProfil;i++)
2563     loadProfileInFile(fid,i);
2564   int sz=MEDnLocalization(fid);
2565   _locs.resize(sz);
2566   for(int i=0;i<sz;i++)
2567     {
2568       _locs[i]=MEDFileFieldLoc::New(fid,i);
2569     }
2570 }
2571
2572 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2573 {
2574   return new MEDFileFieldGlobs(fname);
2575 }
2576
2577 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2578 {
2579   return new MEDFileFieldGlobs;
2580 }
2581
2582 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2583 {
2584   return _file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2585 }
2586
2587 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2588 {
2589   std::vector<const BigMemoryObject *> ret;
2590   for(std::vector< MEDCouplingAutoRefCountObjectPtr< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2591     ret.push_back((const DataArrayInt *)*it);
2592   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2593     ret.push_back((const MEDFileFieldLoc *)*it);
2594   return ret;
2595 }
2596
2597 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const
2598 {
2599   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2600   std::size_t i=0;
2601   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2602     {
2603       if((const DataArrayInt *)*it)
2604         ret->_pfls[i]=(*it)->deepCpy();
2605     }
2606   i=0;
2607   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2608     {
2609       if((const MEDFileFieldLoc*)*it)
2610         ret->_locs[i]=(*it)->deepCpy();
2611     }
2612   return ret.retn();
2613 }
2614
2615 /*!
2616  * \throw if a profile in \a pfls in not in \a this.
2617  * \throw if a localization in \a locs in not in \a this.
2618  * \sa MEDFileFieldGlobs::deepCpyPart
2619  */
2620 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2621 {
2622   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2623   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2624     {
2625       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2626       if(!pfl)
2627         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2628       pfl->incrRef();
2629       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2630       ret->_pfls.push_back(pfl2);
2631     }
2632   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2633     {
2634       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2635       if(!loc)
2636         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2637       loc->incrRef();
2638       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2639       ret->_locs.push_back(loc2);
2640     }
2641   ret->setFileName(getFileName());
2642   return ret.retn();
2643 }
2644
2645 /*!
2646  * \throw if a profile in \a pfls in not in \a this.
2647  * \throw if a localization in \a locs in not in \a this.
2648  * \sa MEDFileFieldGlobs::shallowCpyPart
2649  */
2650 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2651 {
2652   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2653   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2654     {
2655       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2656       if(!pfl)
2657         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2658       ret->_pfls.push_back(pfl->deepCpy());
2659     }
2660   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2661     {
2662       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2663       if(!loc)
2664         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2665       ret->_locs.push_back(loc->deepCpy());
2666     }
2667   ret->setFileName(getFileName());
2668   return ret.retn();
2669 }
2670
2671 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2672 {
2673 }
2674
2675 MEDFileFieldGlobs::MEDFileFieldGlobs()
2676 {
2677 }
2678
2679 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2680 {
2681 }
2682
2683 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2684 {
2685   oss << "Profiles :\n";
2686   std::size_t n=_pfls.size();
2687   for(std::size_t i=0;i<n;i++)
2688     {
2689       oss << "  - #" << i << " ";
2690       const DataArrayInt *pfl=_pfls[i];
2691       if(pfl)
2692         oss << "\"" << pfl->getName() << "\"\n";
2693       else
2694         oss << "EMPTY !\n";
2695     }
2696   n=_locs.size();
2697   oss << "Localizations :\n";
2698   for(std::size_t i=0;i<n;i++)
2699     {
2700       oss << "  - #" << i << " ";
2701       const MEDFileFieldLoc *loc=_locs[i];
2702       if(loc)
2703         loc->simpleRepr(oss);
2704       else
2705         oss<< "EMPTY !\n";
2706     }
2707 }
2708
2709 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2710 {
2711   _file_name=fileName;
2712 }
2713
2714 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2715 {
2716   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2717     {
2718       DataArrayInt *elt(*it);
2719       if(elt)
2720         {
2721           std::string name(elt->getName());
2722           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2723             {
2724               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2725                 {
2726                   elt->setName((*it2).second.c_str());
2727                   return;
2728                 }
2729             }
2730         }
2731     }
2732 }
2733
2734 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2735 {
2736   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2737     {
2738       MEDFileFieldLoc *elt(*it);
2739       if(elt)
2740         {
2741           std::string name(elt->getName());
2742           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2743             {
2744               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2745                 {
2746                   elt->setName((*it2).second.c_str());
2747                   return;
2748                 }
2749             }
2750         }
2751     }
2752 }
2753
2754 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2755 {
2756   if(locId<0 || locId>=(int)_locs.size())
2757     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2758   return _locs[locId]->getNbOfGaussPtPerCell();
2759 }
2760
2761 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2762 {
2763   return getLocalizationFromId(getLocalizationId(locName));
2764 }
2765
2766 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2767 {
2768   if(locId<0 || locId>=(int)_locs.size())
2769     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2770   return *_locs[locId];
2771 }
2772
2773 namespace ParaMEDMEMImpl
2774 {
2775   class LocFinder
2776   {
2777   public:
2778     LocFinder(const std::string& loc):_loc(loc) { }
2779     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2780   private:
2781     const std::string &_loc;
2782   };
2783
2784   class PflFinder
2785   {
2786   public:
2787     PflFinder(const std::string& pfl):_pfl(pfl) { }
2788     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2789   private:
2790     const std::string& _pfl;
2791   };
2792 }
2793
2794 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2795 {
2796   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2797   if(it==_locs.end())
2798     {
2799       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2800       for(it=_locs.begin();it!=_locs.end();it++)
2801         oss << "\"" << (*it)->getName() << "\", ";
2802       throw INTERP_KERNEL::Exception(oss.str().c_str());
2803     }
2804   return std::distance(_locs.begin(),it);
2805 }
2806
2807 /*!
2808  * The returned value is never null.
2809  */
2810 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2811 {
2812   std::string pflNameCpp(pflName);
2813   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2814   if(it==_pfls.end())
2815     {
2816       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2817       for(it=_pfls.begin();it!=_pfls.end();it++)
2818         oss << "\"" << (*it)->getName() << "\", ";
2819       throw INTERP_KERNEL::Exception(oss.str().c_str());
2820     }
2821   return *it;
2822 }
2823
2824 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2825 {
2826   if(pflId<0 || pflId>=(int)_pfls.size())
2827     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2828   return _pfls[pflId];
2829 }
2830
2831 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
2832 {
2833   if(locId<0 || locId>=(int)_locs.size())
2834     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2835   return *_locs[locId];
2836 }
2837
2838 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
2839 {
2840   return getLocalizationFromId(getLocalizationId(locName));
2841 }
2842
2843 /*!
2844  * The returned value is never null.
2845  */
2846 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
2847 {
2848   std::string pflNameCpp(pflName);
2849   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2850   if(it==_pfls.end())
2851     {
2852       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2853       for(it=_pfls.begin();it!=_pfls.end();it++)
2854         oss << "\"" << (*it)->getName() << "\", ";
2855       throw INTERP_KERNEL::Exception(oss.str().c_str());
2856     }
2857   return *it;
2858 }
2859
2860 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
2861 {
2862   if(pflId<0 || pflId>=(int)_pfls.size())
2863     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2864   return _pfls[pflId];
2865 }
2866
2867 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
2868 {
2869   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2870   int i=0;
2871   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2872     {
2873       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2874         newPfls.push_back(*it);
2875     }
2876   _pfls=newPfls;
2877 }
2878
2879 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
2880 {
2881   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2882   int i=0;
2883   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2884     {
2885       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2886         newLocs.push_back(*it);
2887     }
2888   _locs=newLocs;
2889 }
2890
2891 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2892 {
2893   int sz=_pfls.size();
2894   std::vector<std::string> ret(sz);
2895   for(int i=0;i<sz;i++)
2896     ret[i]=_pfls[i]->getName();
2897   return ret;
2898 }
2899
2900 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2901 {
2902   int sz=_locs.size();
2903   std::vector<std::string> ret(sz);
2904   for(int i=0;i<sz;i++)
2905     ret[i]=_locs[i]->getName();
2906   return ret;
2907 }
2908
2909 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
2910 {
2911   std::vector<std::string> v=getPfls();
2912   std::string s(pflName);
2913   return std::find(v.begin(),v.end(),s)!=v.end();
2914 }
2915
2916 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
2917 {
2918   std::vector<std::string> v=getLocs();
2919   std::string s(locName);
2920   return std::find(v.begin(),v.end(),s)!=v.end();
2921 }
2922
2923 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2924 {
2925   std::map<int,std::vector<int> > m;
2926   int i=0;
2927   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2928     {
2929       const DataArrayInt *tmp=(*it);
2930       if(tmp)
2931         {
2932           m[tmp->getHashCode()].push_back(i);
2933         }
2934     }
2935   std::vector< std::vector<int> > ret;
2936   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2937     {
2938       if((*it2).second.size()>1)
2939         {
2940           std::vector<int> ret0;
2941           bool equalityOrNot=false;
2942           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2943             {
2944               std::vector<int>::const_iterator it4=it3; it4++;
2945               for(;it4!=(*it2).second.end();it4++)
2946                 {
2947                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2948                     {
2949                       if(!equalityOrNot)
2950                         ret0.push_back(*it3);
2951                       ret0.push_back(*it4);
2952                       equalityOrNot=true;
2953                     }
2954                 }
2955             }
2956           if(!ret0.empty())
2957             ret.push_back(ret0);
2958         }
2959     }
2960   return ret;
2961 }
2962
2963 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2964 {
2965   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2966 }
2967
2968 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
2969 {
2970   std::string name(pfl->getName());
2971   if(name.empty())
2972     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2973   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2974     if(name==(*it)->getName())
2975       {
2976         if(!pfl->isEqual(*(*it)))
2977           {
2978             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2979             throw INTERP_KERNEL::Exception(oss.str().c_str());
2980           }
2981       }
2982   pfl->incrRef();
2983   _pfls.push_back(pfl);
2984 }
2985
2986 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)
2987 {
2988   std::string name(locName);
2989   if(name.empty())
2990     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2991   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2992   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2993     if((*it)->isName(locName))
2994       {
2995         if(!(*it)->isEqual(*obj,1e-12))
2996           {
2997             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
2998             throw INTERP_KERNEL::Exception(oss.str().c_str());
2999           }
3000       }
3001   _locs.push_back(obj);
3002 }
3003
3004 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3005 {
3006   std::vector<std::string> names=getPfls();
3007   return CreateNewNameNotIn("NewPfl_",names);
3008 }
3009
3010 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3011 {
3012   std::vector<std::string> names=getLocs();
3013   return CreateNewNameNotIn("NewLoc_",names);
3014 }
3015
3016 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3017 {
3018   for(std::size_t sz=0;sz<100000;sz++)
3019     {
3020       std::ostringstream tryName;
3021       tryName << prefix << sz;
3022       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3023         return tryName.str();
3024     }
3025   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3026 }
3027
3028 /*!
3029  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3030  *  \param [in] fname - the file name.
3031  */
3032 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
3033 {
3034 }
3035
3036 /*!
3037  * Creates an empty MEDFileFieldGlobsReal.
3038  */
3039 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3040 {
3041 }
3042
3043 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3044 {
3045   return 0;
3046 }
3047
3048 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3049 {
3050   std::vector<const BigMemoryObject *> ret;
3051   ret.push_back((const MEDFileFieldGlobs *)_globals);
3052   return ret;
3053 }
3054
3055 /*!
3056  * Returns a string describing profiles and Gauss points held in \a this.
3057  *  \return std::string - the description string.
3058  */
3059 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3060 {
3061   const MEDFileFieldGlobs *glob=_globals;
3062   std::ostringstream oss2; oss2 << glob;
3063   std::string stars(oss2.str().length(),'*');
3064   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3065   if(glob)
3066     glob->simpleRepr(oss);
3067   else
3068     oss << "NO GLOBAL INFORMATION !\n";
3069 }
3070
3071 void MEDFileFieldGlobsReal::resetContent()
3072 {
3073   _globals=MEDFileFieldGlobs::New();
3074 }
3075
3076 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3077 {
3078 }
3079
3080 /*!
3081  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3082  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3083  */
3084 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3085 {
3086   _globals=other._globals;
3087 }
3088
3089 /*!
3090  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3091  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3092  */
3093 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3094 {
3095   const MEDFileFieldGlobs *otherg(other._globals);
3096   if(!otherg)
3097     return ;
3098   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3099 }
3100
3101 /*!
3102  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3103  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3104  */
3105 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3106 {
3107   const MEDFileFieldGlobs *otherg(other._globals);
3108   if(!otherg)
3109     return ;
3110   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3111 }
3112
3113 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3114 {
3115   _globals=other._globals;
3116   if((const MEDFileFieldGlobs *)_globals)
3117     _globals=other._globals->deepCpy();
3118 }
3119
3120 /*!
3121  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3122  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3123  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3124  *         \a this and \a other MEDFileFieldGlobsReal.
3125  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3126  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3127  */
3128 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3129 {
3130   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3131   if(thisGlobals==otherGlobals)
3132     return ;
3133   if(!thisGlobals)
3134     {
3135       _globals=other._globals;
3136       return ;
3137     }
3138   _globals->appendGlobs(*other._globals,eps);
3139 }
3140
3141 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3142 {
3143   checkGlobsPflsPartCoherency();
3144   checkGlobsLocsPartCoherency();
3145 }
3146
3147 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3148 {
3149   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3150 }
3151
3152 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3153 {
3154   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3155 }
3156
3157 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3158 {
3159   contentNotNull()->loadProfileInFile(fid,id,pflName);
3160 }
3161
3162 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3163 {
3164   contentNotNull()->loadProfileInFile(fid,id);
3165 }
3166
3167 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3168 {
3169   contentNotNull()->loadGlobals(fid,*this);
3170 }
3171
3172 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3173 {
3174   contentNotNull()->loadAllGlobals(fid);
3175 }
3176
3177 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3178 {
3179   contentNotNull()->writeGlobals(fid,opt);
3180 }
3181
3182 /*!
3183  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3184  * or getPflsReallyUsedMulti().
3185  *  \return std::vector<std::string> - a sequence of names of all profiles.
3186  */
3187 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3188 {
3189   return contentNotNull()->getPfls();
3190 }
3191
3192 /*!
3193  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3194  * or getLocsReallyUsedMulti().
3195  *  \return std::vector<std::string> - a sequence of names of all localizations.
3196  */
3197 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3198 {
3199   return contentNotNull()->getLocs();
3200 }
3201
3202 /*!
3203  * Checks if the profile with a given name exists.
3204  *  \param [in] pflName - the profile name of interest.
3205  *  \return bool - \c true if the profile named \a pflName exists.
3206  */
3207 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3208 {
3209   return contentNotNull()->existsPfl(pflName);
3210 }
3211
3212 /*!
3213  * Checks if the localization with a given name exists.
3214  *  \param [in] locName - the localization name of interest.
3215  *  \return bool - \c true if the localization named \a locName exists.
3216  */
3217 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3218 {
3219   return contentNotNull()->existsLoc(locName);
3220 }
3221
3222 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3223 {
3224   return contentNotNull()->createNewNameOfPfl();
3225 }
3226
3227 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3228 {
3229   return contentNotNull()->createNewNameOfLoc();
3230 }
3231
3232 /*!
3233  * Sets the name of a MED file.
3234  *  \param [inout] fileName - the file name.
3235  */
3236 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3237 {
3238   contentNotNull()->setFileName(fileName);
3239 }
3240
3241 /*!
3242  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3243  * in the same order.
3244  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3245  *          Each item of this sequence is a vector containing ids of equal profiles.
3246  */
3247 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3248 {
3249   return contentNotNull()->whichAreEqualProfiles();
3250 }
3251
3252 /*!
3253  * Finds equal localizations.
3254  *  \param [in] eps - a precision used to compare real values of the localizations.
3255  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3256  *          Each item of this sequence is a vector containing ids of equal localizations.
3257  */
3258 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3259 {
3260   return contentNotNull()->whichAreEqualLocs(eps);
3261 }
3262
3263 /*!
3264  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3265  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3266  *        this sequence is a pair whose 
3267  *        - the first item is a vector of profile names to replace by the second item,
3268  *        - the second item is a profile name to replace every profile name of the first item.
3269  */
3270 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3271 {
3272   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3273 }
3274
3275 /*!
3276  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3277  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3278  *        this sequence is a pair whose 
3279  *        - the first item is a vector of localization names to replace by the second item,
3280  *        - the second item is a localization name to replace every localization name of the first item.
3281  */
3282 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3283 {
3284   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3285 }
3286
3287 /*!
3288  * Replaces references to some profiles (a reference is a profile name) by references
3289  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3290  * them-selves accordingly. <br>
3291  * This method is a generalization of changePflName().
3292  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3293  *        this sequence is a pair whose 
3294  *        - the first item is a vector of profile names to replace by the second item,
3295  *        - the second item is a profile name to replace every profile of the first item.
3296  * \sa changePflsRefsNamesGen()
3297  * \sa changePflName()
3298  */
3299 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3300 {
3301   changePflsRefsNamesGen(mapOfModif);
3302   changePflsNamesInStruct(mapOfModif);
3303 }
3304
3305 /*!
3306  * Replaces references to some localizations (a reference is a localization name) by references
3307  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3308  * them-selves accordingly. <br>
3309  * This method is a generalization of changeLocName().
3310  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3311  *        this sequence is a pair whose 
3312  *        - the first item is a vector of localization names to replace by the second item,
3313  *        - the second item is a localization name to replace every localization of the first item.
3314  * \sa changeLocsRefsNamesGen()
3315  * \sa changeLocName()
3316  */
3317 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3318 {
3319   changeLocsRefsNamesGen(mapOfModif);
3320   changeLocsNamesInStruct(mapOfModif);
3321 }
3322
3323 /*!
3324  * Renames the profile having a given name and updates references to this profile.
3325  *  \param [in] oldName - the name of the profile to rename.
3326  *  \param [in] newName - a new name of the profile.
3327  * \sa changePflsNames().
3328  */
3329 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3330 {
3331   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3332   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3333   mapOfModif[0]=p;
3334   changePflsNames(mapOfModif);
3335 }
3336
3337 /*!
3338  * Renames the localization having a given name and updates references to this localization.
3339  *  \param [in] oldName - the name of the localization to rename.
3340  *  \param [in] newName - a new name of the localization.
3341  * \sa changeLocsNames().
3342  */
3343 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3344 {
3345   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3346   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3347   mapOfModif[0]=p;
3348   changeLocsNames(mapOfModif);
3349 }
3350
3351 /*!
3352  * Removes duplicated profiles. Returns a map used to update references to removed 
3353  * profiles via changePflsRefsNamesGen().
3354  * Equal profiles are found using whichAreEqualProfiles().
3355  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3356  *          a sequence describing the performed replacements of profiles. Each element of
3357  *          this sequence is a pair whose
3358  *          - the first item is a vector of profile names replaced by the second item,
3359  *          - the second item is a profile name replacing every profile of the first item.
3360  */
3361 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3362 {
3363   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3364   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3365   int i=0;
3366   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3367     {
3368       std::vector< std::string > tmp((*it).size());
3369       int j=0;
3370       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3371         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3372       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3373       ret[i]=p;
3374       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3375       killProfileIds(tmp2);
3376     }
3377   changePflsRefsNamesGen(ret);
3378   return ret;
3379 }
3380
3381 /*!
3382  * Removes duplicated localizations. Returns a map used to update references to removed 
3383  * localizations via changeLocsRefsNamesGen().
3384  * Equal localizations are found using whichAreEqualLocs().
3385  *  \param [in] eps - a precision used to compare real values of the localizations.
3386  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3387  *          a sequence describing the performed replacements of localizations. Each element of
3388  *          this sequence is a pair whose
3389  *          - the first item is a vector of localization names replaced by the second item,
3390  *          - the second item is a localization name replacing every localization of the first item.
3391  */
3392 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3393 {
3394   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3395   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3396   int i=0;
3397   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3398     {
3399       std::vector< std::string > tmp((*it).size());
3400       int j=0;
3401       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3402         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3403       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3404       ret[i]=p;
3405       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3406       killLocalizationIds(tmp2);
3407     }
3408   changeLocsRefsNamesGen(ret);
3409   return ret;
3410 }
3411
3412 /*!
3413  * Returns number of Gauss points per cell in a given localization.
3414  *  \param [in] locId - an id of the localization of interest.
3415  *  \return int - the number of the Gauss points per cell.
3416  */
3417 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3418 {
3419   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3420 }
3421
3422 /*!
3423  * Returns an id of a localization by its name.
3424  *  \param [in] loc - the localization name of interest.
3425  *  \return int - the id of the localization.
3426  *  \throw If there is no a localization named \a loc.
3427  */
3428 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3429 {
3430   return contentNotNull()->getLocalizationId(loc);
3431 }
3432
3433 /*!
3434  * Returns the name of the MED file.
3435  *  \return const std::string&  - the MED file name.
3436  */
3437 std::string MEDFileFieldGlobsReal::getFileName() const
3438 {
3439   return contentNotNull()->getFileName();
3440 }
3441
3442 /*!
3443  * Returns a localization object by its name.
3444  *  \param [in] locName - the name of the localization of interest.
3445  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3446  *  \throw If there is no a localization named \a locName.
3447  */
3448 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3449 {
3450   return contentNotNull()->getLocalization(locName);
3451 }
3452
3453 /*!
3454  * Returns a localization object by its id.
3455  *  \param [in] locId - the id of the localization of interest.
3456  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3457  *  \throw If there is no a localization with id \a locId.
3458  */
3459 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3460 {
3461   return contentNotNull()->getLocalizationFromId(locId);
3462 }
3463
3464 /*!
3465  * Returns a profile array by its name.
3466  *  \param [in] pflName - the name of the profile of interest.
3467  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3468  *  \throw If there is no a profile named \a pflName.
3469  */
3470 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3471 {
3472   return contentNotNull()->getProfile(pflName);
3473 }
3474
3475 /*!
3476  * Returns a profile array by its id.
3477  *  \param [in] pflId - the id of the profile of interest.
3478  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3479  *  \throw If there is no a profile with id \a pflId.
3480  */
3481 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3482 {
3483   return contentNotNull()->getProfileFromId(pflId);
3484 }
3485
3486 /*!
3487  * Returns a localization object, apt for modification, by its id.
3488  *  \param [in] locId - the id of the localization of interest.
3489  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3490  *          having the id \a locId.
3491  *  \throw If there is no a localization with id \a locId.
3492  */
3493 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3494 {
3495   return contentNotNull()->getLocalizationFromId(locId);
3496 }
3497
3498 /*!
3499  * Returns a localization object, apt for modification, by its name.
3500  *  \param [in] locName - the name of the localization of interest.
3501  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3502  *          having the name \a locName.
3503  *  \throw If there is no a localization named \a locName.
3504  */
3505 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3506 {
3507   return contentNotNull()->getLocalization(locName);
3508 }
3509
3510 /*!
3511  * Returns a profile array, apt for modification, by its name.
3512  *  \param [in] pflName - the name of the profile of interest.
3513  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3514  *  \throw If there is no a profile named \a pflName.
3515  */
3516 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3517 {
3518   return contentNotNull()->getProfile(pflName);
3519 }
3520
3521 /*!
3522  * Returns a profile array, apt for modification, by its id.
3523  *  \param [in] pflId - the id of the profile of interest.
3524  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3525  *  \throw If there is no a profile with id \a pflId.
3526  */
3527 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3528 {
3529   return contentNotNull()->getProfileFromId(pflId);
3530 }
3531
3532 /*!
3533  * Removes profiles given by their ids. No data is updated to track this removal.
3534  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3535  */
3536 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3537 {
3538   contentNotNull()->killProfileIds(pflIds);
3539 }
3540
3541 /*!
3542  * Removes localizations given by their ids. No data is updated to track this removal.
3543  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3544  */
3545 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3546 {
3547   contentNotNull()->killLocalizationIds(locIds);
3548 }
3549
3550 /*!
3551  * Stores a profile array.
3552  *  \param [in] pfl - the profile array to store.
3553  *  \throw If the name of \a pfl is empty.
3554  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3555  *         different ids.
3556  */
3557 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3558 {
3559   contentNotNull()->appendProfile(pfl);
3560 }
3561
3562 /*!
3563  * Adds a new localization of Gauss points.
3564  *  \param [in] locName - the name of the new localization.
3565  *  \param [in] geoType - a geometrical type of the reference cell.
3566  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3567  *         must be \c nbOfNodesPerCell * \c dimOfType.
3568  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3569  *         must be  _wg_.size() * \c dimOfType.
3570  *  \param [in] w - the weights of Gauss points.
3571  *  \throw If \a locName is empty.
3572  *  \throw If a localization with the name \a locName already exists but is
3573  *         different form the new one.
3574  */
3575 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)
3576 {
3577   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3578 }
3579
3580 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3581 {
3582   MEDFileFieldGlobs *g(_globals);
3583   if(!g)
3584     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3585   return g;
3586 }
3587
3588 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3589 {
3590   const MEDFileFieldGlobs *g(_globals);
3591   if(!g)
3592     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3593   return g;
3594 }
3595
3596 //= MEDFileFieldNameScope
3597
3598 MEDFileFieldNameScope::MEDFileFieldNameScope()
3599 {
3600 }
3601
3602 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3603 {
3604 }
3605
3606 /*!
3607  * Returns the name of \a this field.
3608  *  \return std::string - a string containing the field name.
3609  */
3610 std::string MEDFileFieldNameScope::getName() const
3611 {
3612   return _name;
3613 }
3614
3615 /*!
3616  * Sets name of \a this field
3617  *  \param [in] name - the new field name.
3618  */
3619 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3620 {
3621   _name=fieldName;
3622 }
3623
3624 std::string MEDFileFieldNameScope::getDtUnit() const
3625 {
3626   return _dt_unit;
3627 }
3628
3629 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3630 {
3631   _dt_unit=dtUnit;
3632 }
3633
3634 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3635 {
3636   _name=other._name;
3637   _dt_unit=other._dt_unit;
3638 }
3639
3640 //= MEDFileAnyTypeField1TSWithoutSDA
3641
3642 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3643 {
3644   _field_per_mesh.resize(other._field_per_mesh.size());
3645   std::size_t i=0;
3646   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3647     {
3648       if((const MEDFileFieldPerMesh *)*it)
3649         _field_per_mesh[i]=(*it)->deepCpy(this);
3650     }
3651 }
3652
3653 /*!
3654  * Prints a string describing \a this field into a stream. This string is outputted 
3655  * by \c print Python command.
3656  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3657  *  \param [in,out] oss - the out stream.
3658  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3659  *          info id printed, else, not.
3660  */
3661 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3662 {
3663   std::string startOfLine(bkOffset,' ');
3664   oss << startOfLine << "Field ";
3665   if(bkOffset==0)
3666     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3667   oss << "on one time Step ";
3668   if(f1tsId>=0)
3669     oss << "(" << f1tsId << ") ";
3670   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3671   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3672   const DataArray *arr=getUndergroundDataArray();
3673   if(arr)
3674     {
3675       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3676       if(f1tsId<0)
3677         {
3678           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3679           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3680             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3681         }
3682       if(arr->isAllocated())
3683         {
3684           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3685         }
3686       else
3687         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3688     }
3689   else
3690     {
3691       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3692     }
3693   oss << startOfLine << "----------------------" << std::endl;
3694   if(!_field_per_mesh.empty())
3695     {
3696       int i=0;
3697       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3698         {
3699           const MEDFileFieldPerMesh *cur=(*it2);
3700           if(cur)
3701             cur->simpleRepr(bkOffset,oss,i);
3702           else
3703             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3704         }
3705     }
3706   else
3707     {
3708       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3709     }
3710   oss << startOfLine << "----------------------" << std::endl;
3711 }
3712
3713 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3714 {
3715   const DataArray *arr(getUndergroundDataArray());
3716   if(!arr)
3717     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3718   int nbOfCompo=arr->getNumberOfComponents();
3719   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3720   for(int i=0;i<nbOfCompo;i++)
3721     {
3722       ret[i]=deepCpy();
3723       std::vector<int> v(1,i);
3724       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3725       ret[i]->setArray(arr2);
3726     }
3727   return ret;
3728 }
3729
3730 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)
3731 {
3732 }
3733
3734 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3735 {
3736 }
3737
3738 /*!
3739  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3740  * empty. Returns -1 if this in on nodes.
3741  *  \return int - the dimension of \a this.
3742  */
3743 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3744 {
3745   int ret=-2;
3746   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3747     (*it)->getDimension(ret);
3748   return ret;
3749 }
3750
3751 /*!
3752  * Returns the mesh name.
3753  *  \return std::string - a string holding the mesh name.
3754  *  \throw If \c _field_per_mesh.empty()
3755  */
3756 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3757 {
3758   if(_field_per_mesh.empty())
3759     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3760   return _field_per_mesh[0]->getMeshName();
3761 }
3762
3763 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3764 {
3765   std::string oldName(getMeshName());
3766   std::vector< std::pair<std::string,std::string> > v(1);
3767   v[0].first=oldName; v[0].second=newMeshName;
3768   changeMeshNames(v);
3769 }
3770
3771 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3772 {
3773   bool ret=false;
3774   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3775     {
3776       MEDFileFieldPerMesh *cur(*it);
3777       if(cur)
3778         ret=cur->changeMeshNames(modifTab) || ret;
3779     }
3780   return ret;
3781 }
3782
3783 /*!
3784  * Returns the number of iteration of the state of underlying mesh.
3785  *  \return int - the iteration number.
3786  *  \throw If \c _field_per_mesh.empty()
3787  */
3788 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3789 {
3790   if(_field_per_mesh.empty())
3791     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3792   return _field_per_mesh[0]->getMeshIteration();
3793 }
3794
3795 /*!
3796  * Returns the order number of iteration of the state of underlying mesh.
3797  *  \return int - the order number.
3798  *  \throw If \c _field_per_mesh.empty()
3799  */
3800 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3801 {
3802   if(_field_per_mesh.empty())
3803     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3804   return _field_per_mesh[0]->getMeshOrder();
3805 }
3806
3807 /*!
3808  * Checks if \a this field is tagged by a given iteration number and a given
3809  * iteration order number.
3810  *  \param [in] iteration - the iteration number of interest.
3811  *  \param [in] order - the iteration order number of interest.
3812  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3813  *          \a this->getOrder() == \a order.
3814  */
3815 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3816 {
3817   return iteration==_iteration && order==_order;
3818 }
3819
3820 /*!
3821  * Returns number of iteration and order number of iteration when
3822  * \a this field has been calculated.
3823  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3824  *          order number.
3825  */
3826 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3827 {
3828   std::pair<int,int> p;
3829   fillIteration(p);
3830   return p;
3831 }
3832
3833 /*!
3834  * Returns number of iteration and order number of iteration when
3835  * \a this field has been calculated.
3836  *  \param [in,out] p - a pair returning the iteration number and the iteration
3837  *          order number.
3838  */
3839 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3840 {
3841   p.first=_iteration;
3842   p.second=_order;
3843 }
3844
3845 /*!
3846  * Returns all types of spatial discretization of \a this field.
3847  *  \param [in,out] types - a sequence of types of \a this field.
3848  */
3849 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
3850 {
3851   std::set<TypeOfField> types2;
3852   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3853     {
3854       (*it)->fillTypesOfFieldAvailable(types2);
3855     }
3856   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3857   std::copy(types2.begin(),types2.end(),bi);
3858 }
3859
3860 /*!
3861  * Returns all types of spatial discretization of \a this field.
3862  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3863  *          of \a this field.
3864  */
3865 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
3866 {
3867   std::vector<TypeOfField> ret;
3868   fillTypesOfFieldAvailable(ret);
3869   return ret;
3870 }
3871
3872 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3873 {
3874   std::vector<std::string> ret;
3875   std::set<std::string> ret2;
3876   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3877     {
3878       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3879       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3880         if(ret2.find(*it2)==ret2.end())
3881           {
3882             ret.push_back(*it2);
3883             ret2.insert(*it2);
3884           }
3885     }
3886   return ret;
3887 }
3888
3889 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3890 {
3891   std::vector<std::string> ret;
3892   std::set<std::string> ret2;
3893   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3894     {
3895       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3896       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3897         if(ret2.find(*it2)==ret2.end())
3898           {
3899             ret.push_back(*it2);
3900             ret2.insert(*it2);
3901           }
3902     }
3903   return ret;
3904 }
3905
3906 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3907 {
3908   std::vector<std::string> ret;
3909   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3910     {
3911       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3912       ret.insert(ret.end(),tmp.begin(),tmp.end());
3913     }
3914   return ret;
3915 }
3916
3917 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3918 {
3919   std::vector<std::string> ret;
3920   std::set<std::string> ret2;
3921   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3922     {
3923       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3924       ret.insert(ret.end(),tmp.begin(),tmp.end());
3925     }
3926   return ret;
3927 }
3928
3929 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3930 {
3931   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3932     (*it)->changePflsRefsNamesGen(mapOfModif);
3933 }
3934
3935 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3936 {
3937   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3938     (*it)->changeLocsRefsNamesGen(mapOfModif);
3939 }
3940
3941 /*!
3942  * Returns all attributes of parts of \a this field lying on a given mesh.
3943  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3944  * item of every of returned sequences refers to the _i_-th part of \a this field.
3945  * Thus all sequences returned by this method are of the same length equal to number
3946  * of different types of supporting entities.<br>
3947  * A field part can include sub-parts with several different spatial discretizations,
3948  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3949  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3950  * of a nested sequence corresponds to a type of spatial discretization.<br>
3951  * This method allows for iteration over MEDFile DataStructure without any overhead.
3952  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3953  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3954  *          not checked if \a mname == \c NULL).
3955  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3956  *          a field part is returned. 
3957  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3958  *          This sequence is of the same length as \a types. 
3959  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3960  *          discretization. A profile name can be empty.
3961  *          Length of this and of nested sequences is the same as that of \a typesF.
3962  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3963  *          discretization. A localization name can be empty.
3964  *          Length of this and of nested sequences is the same as that of \a typesF.
3965  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3966  *          of ids of tuples within the data array, per each type of spatial
3967  *          discretization within one mesh entity type. 
3968  *          Length of this and of nested sequences is the same as that of \a typesF.
3969  *  \throw If no field is lying on \a mname.
3970  */
3971 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
3972 {
3973   int meshId=0;
3974   if(!mname.empty())
3975     meshId=getMeshIdFromMeshName(mname);
3976   else
3977     if(_field_per_mesh.empty())
3978       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3979   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3980 }
3981
3982 /*!
3983  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
3984  * maximal absolute dimension and values returned via the out parameter \a levs are 
3985  * dimensions relative to the maximal absolute dimension. <br>
3986  * This method is designed for MEDFileField1TS instances that have a discretization
3987  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
3988  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
3989  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
3990  * Only these 3 discretizations will be taken into account here. If \a this is
3991  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
3992  * This method is useful to make the link between the dimension of the underlying mesh
3993  * and the levels of \a this, because it is possible that the highest dimension of \a this
3994  * field is not equal to the dimension of the underlying mesh.
3995  * 
3996  * Let's consider the following case:
3997  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
3998  * TETRA4, HEXA8, TRI3 and SEG2.
3999  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4000  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4001  *
4002  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4003  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4004  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4005  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4006  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4007  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4008  * For example<br>
4009  * to retrieve the highest level of
4010  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4011  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4012  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4013  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4014  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4015  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4016  *          not checked if \a mname == \c NULL).
4017  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4018  *          absolute one. They are in decreasing order. This sequence is cleared before
4019  *          filling it in.
4020  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4021  *  \throw If no field is lying on \a mname.
4022  */
4023 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4024 {
4025   levs.clear();
4026   int meshId=getMeshIdFromMeshName(mname);
4027   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4028   std::vector< std::vector<TypeOfField> > typesF;
4029   std::vector< std::vector<std::string> > pfls, locs;
4030   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4031   if(types.empty())
4032     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4033   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4034   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4035     return -1;
4036   st.erase(INTERP_KERNEL::NORM_ERROR);
4037   std::set<int> ret1;
4038   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4039     {
4040       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4041       ret1.insert((int)cm.getDimension());
4042     }
4043   int ret=*std::max_element(ret1.begin(),ret1.end());
4044   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4045   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4046   return ret;
4047 }
4048
4049 /*!
4050  * \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.
4051  * \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.
4052  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4053  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4054  */
4055 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4056 {
4057   int mid=getMeshIdFromMeshName(mName);
4058   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4059 }
4060
4061 /*!
4062  * \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.
4063  * \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.
4064  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4065  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4066  */
4067 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4068 {
4069   int mid=getMeshIdFromMeshName(mName);
4070   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4071 }
4072
4073 /*!
4074  * \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.
4075  */
4076 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4077 {
4078   if(_field_per_mesh.empty())
4079     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4080   if(mName.empty())
4081     return 0;
4082   std::string mName2(mName);
4083   int ret=0;
4084   std::vector<std::string> msg;
4085   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4086     if(mName2==(*it)->getMeshName())
4087       return ret;
4088     else
4089       msg.push_back((*it)->getMeshName());
4090   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4091   oss << "Possible meshes are : ";
4092   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4093     oss << "\"" << (*it2) << "\" ";
4094   throw INTERP_KERNEL::Exception(oss.str().c_str());
4095 }
4096
4097 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4098 {
4099   if(!mesh)
4100     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4101   std::string tmp(mesh->getName());
4102   if(tmp.empty())
4103     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4104   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4105   int i=0;
4106   for(;it!=_field_per_mesh.end();it++,i++)
4107     {
4108       if((*it)->getMeshName()==tmp)
4109         return i;
4110     }
4111   int sz=_field_per_mesh.size();
4112   _field_per_mesh.resize(sz+1);
4113   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4114   return sz;
4115 }
4116
4117 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4118                                                                    MEDFileFieldGlobsReal& glob)
4119 {
4120   bool ret=false;
4121   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4122     {
4123       MEDFileFieldPerMesh *fpm(*it);
4124       if(fpm)
4125         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4126     }
4127   return ret;
4128 }
4129
4130 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4131 {
4132   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4133   std::vector< std::vector<TypeOfField> > typesF;
4134   std::vector< std::vector<std::string> > pfls,locs;
4135   std::vector< std::vector<std::pair<int,int> > > bgEnd=getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs);
4136   std::set<TypeOfField> allEnt;
4137   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4138     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4139       allEnt.insert(*it2);
4140   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4141   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4142   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4143     {
4144       std::vector< std::pair<int,int> > its;
4145       ret[i]=shallowCpy();
4146       int newLgth=ret[i]->keepOnlySpatialDiscretization(*it3,its);
4147       ret[i]->updateData(newLgth,its);
4148     }
4149   return ret;
4150 }
4151
4152 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4153 {
4154   int globalCounter=0;
4155   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4156     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4157   return globalCounter;
4158 }
4159
4160 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4161 {
4162   if(_nb_of_tuples_to_be_allocated>=0)
4163     {
4164       _nb_of_tuples_to_be_allocated=newLgth;
4165       const DataArray *oldArr(getUndergroundDataArray());
4166       if(oldArr)
4167         {
4168           MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4169           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4170           setArray(newArr);
4171           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4172         }
4173       return ;
4174     }
4175   if(_nb_of_tuples_to_be_allocated==-1)
4176     return ;
4177   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4178     {
4179       const DataArray *oldArr(getUndergroundDataArray());
4180       if(!oldArr || !oldArr->isAllocated())
4181         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4182       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4183       newArr->alloc(newLgth,getNumberOfComponents());
4184       if(oldArr)
4185         newArr->copyStringInfoFrom(*oldArr);
4186       int pos=0;
4187       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4188         {
4189           if((*it).second<(*it).first)
4190             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4191           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4192           pos+=(*it).second-(*it).first;
4193         }
4194       setArray(newArr);
4195       return ;
4196     }
4197   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4198 }
4199
4200 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4201 {
4202   if(_field_per_mesh.empty())
4203     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4204   if(_field_per_mesh.size()>1)
4205     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4206   _field_per_mesh[0]->copyOptionsFrom(opts);
4207   _field_per_mesh[0]->writeLL(fid,nasc);
4208 }
4209
4210 /*!
4211  * 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.
4212  * If false is returned the memory allocation is not required.
4213  */
4214 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4215 {
4216   if(_nb_of_tuples_to_be_allocated>=0)
4217     {
4218       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4219       _nb_of_tuples_to_be_allocated=-2;
4220       return true;
4221     }
4222   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4223     return false;
4224   if(_nb_of_tuples_to_be_allocated==-1)
4225     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4226   if(_nb_of_tuples_to_be_allocated<-3)
4227     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4228   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4229 }
4230
4231 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms)
4232 {
4233   med_int numdt,numit;
4234   med_float dt;
4235   med_int nmesh;
4236   med_bool localMesh;
4237   med_int meshnumdt,meshnumit;
4238   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4239   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4240   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4241   if(_iteration!=numdt || _order!=numit)
4242     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4243   _field_per_mesh.resize(nmesh);
4244   //
4245   MEDFileMesh *mm(0);
4246   if(ms)
4247     {
4248       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4249       mm=ms->getMeshWithName(meshNameCpp);
4250     }
4251   //
4252   for(int i=0;i<nmesh;i++)
4253     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm);
4254   _nb_of_tuples_to_be_allocated=0;
4255   for(int i=0;i<nmesh;i++)
4256     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4257 }
4258
4259 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4260 {
4261   allocIfNecessaryTheArrayToReceiveDataFromFile();
4262   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4263     (*it)->loadBigArraysRecursively(fid,nasc);
4264 }
4265
4266 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4267 {
4268   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4269     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4270       (*it)->loadBigArraysRecursively(fid,nasc);
4271 }
4272
4273 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms)
4274 {
4275   loadOnlyStructureOfDataRecursively(fid,nasc,ms);
4276   loadBigArraysRecursively(fid,nasc);
4277 }
4278
4279 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4280 {
4281   DataArray *thisArr(getUndergroundDataArray());
4282   if(thisArr && thisArr->isAllocated())
4283     {
4284       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4285       thisArr->desallocate();
4286     }
4287 }
4288
4289 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4290 {
4291   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4292 }
4293
4294 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4295 {
4296   std::vector<const BigMemoryObject *> ret;
4297   if(getUndergroundDataArray())
4298     ret.push_back(getUndergroundDataArray());
4299   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4300     ret.push_back((const MEDFileFieldPerMesh *)*it);
4301   return ret;
4302 }
4303
4304 /*!
4305  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4306  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4307  * "Sort By Type"), if not, an exception is thrown. 
4308  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4309  *  \param [in] arr - the array of values.
4310  *  \param [in,out] glob - the global data where profiles and localization present in
4311  *          \a field, if any, are added.
4312  *  \throw If the name of \a field is empty.
4313  *  \throw If the data array of \a field is not set.
4314  *  \throw If \a this->_arr is already allocated but has different number of components
4315  *         than \a field.
4316  *  \throw If the underlying mesh of \a field has no name.
4317  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4318  */
4319 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4320 {
4321   const MEDCouplingMesh *mesh=field->getMesh();
4322   //
4323   TypeOfField type=field->getTypeOfField();
4324   std::vector<DataArrayInt *> dummy;
4325   int start=copyTinyInfoFrom(field,arr);
4326   int pos=addNewEntryIfNecessary(mesh);
4327   if(type!=ON_NODES)
4328     {
4329       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4330       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4331     }
4332   else
4333     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4334 }
4335
4336 /*!
4337  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4338  * of a given mesh are used as the support of the given field (a real support is not used). 
4339  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4340  * Order of underlying mesh entities of the given field specified by \a profile parameter
4341  * is not prescribed; this method permutes field values to have them sorted by element
4342  * type as required for writing to MED file. A new profile is added only if no equal
4343  * profile is missing. 
4344  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4345  *  \param [in] arrOfVals - the values of the field \a field used.
4346  *  \param [in] mesh - the supporting mesh of \a field.
4347  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4348  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4349  *  \param [in,out] glob - the global data where profiles and localization present in
4350  *          \a field, if any, are added.
4351  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4352  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4353  *  \throw If the data array of \a field is not set.
4354  *  \throw If \a this->_arr is already allocated but has different number of components
4355  *         than \a field.
4356  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4357  *  \sa setFieldNoProfileSBT()
4358  */
4359 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4360 {
4361   if(!field)
4362     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4363   if(!arrOfVals || !arrOfVals->isAllocated())
4364     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4365   TypeOfField type=field->getTypeOfField();
4366   std::vector<DataArrayInt *> idsInPflPerType;
4367   std::vector<DataArrayInt *> idsPerType;
4368   std::vector<int> code,code2;
4369   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4370   if(type!=ON_NODES)
4371     {
4372       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4373       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4374       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4375       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4376       // start of check
4377       MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2=field->clone(false);
4378       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4379       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4380         {
4381           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4382           throw INTERP_KERNEL::Exception(oss.str().c_str());
4383         }
4384       // end of check
4385       int start=copyTinyInfoFrom(field,arrOfVals);
4386       code2=m->getDistributionOfTypes();
4387       //
4388       int pos=addNewEntryIfNecessary(m);
4389       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4390     }
4391   else
4392     {
4393       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4394         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4395       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4396       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4397       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4398       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4399         {
4400           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4401           throw INTERP_KERNEL::Exception(oss.str().c_str());
4402         }
4403       int start=copyTinyInfoFrom(field,arrOfVals);
4404       int pos=addNewEntryIfNecessary(m);
4405       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4406     }
4407 }
4408
4409 /*!
4410  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4411  */
4412 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4413 {
4414   if(_nb_of_tuples_to_be_allocated>=0)
4415     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 !");
4416   DataArray *arr(getOrCreateAndGetArray());
4417   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4418   _nb_of_tuples_to_be_allocated=-3;
4419 }
4420
4421 /*!
4422  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4423  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4424  * larger by the size of \a field. Returns an id of the first not filled
4425  * tuple of \a this->_arr.
4426  *  \param [in] field - the field to copy the info on components and the name from.
4427  *  \return int - the id of first not initialized tuple of \a this->_arr.
4428  *  \throw If the name of \a field is empty.
4429  *  \throw If the data array of \a field is not set.
4430  *  \throw If \a this->_arr is already allocated but has different number of components
4431  *         than \a field.
4432  */
4433 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4434 {
4435   if(!field)
4436     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4437   std::string name(field->getName());
4438   setName(name.c_str());
4439   setDtUnit(field->getTimeUnit());
4440   if(name.empty())
4441     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4442   if(!arr)
4443     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4444   if(!arr->isAllocated())
4445     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4446   _dt=field->getTime(_iteration,_order);
4447   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4448   if(!getOrCreateAndGetArray()->isAllocated())
4449     {
4450       allocNotFromFile(arr->getNumberOfTuples());
4451       return 0;
4452     }
4453   else
4454     {
4455       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4456       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4457       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4458       _nb_of_tuples_to_be_allocated=-3;
4459       return oldNbOfTuples;
4460     }
4461 }
4462
4463 /*!
4464  * Returns number of components in \a this field
4465  *  \return int - the number of components.
4466  */
4467 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4468 {
4469   return getOrCreateAndGetArray()->getNumberOfComponents();
4470 }
4471
4472 /*!
4473  * Change info on components in \a this.
4474  * \throw If size of \a infos is not equal to the number of components already in \a this.
4475  */
4476 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4477 {
4478   DataArray *arr=getOrCreateAndGetArray();
4479   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4480 }
4481
4482 /*!
4483  * Returns info on components of \a this field.
4484  *  \return const std::vector<std::string>& - a sequence of strings each being an
4485  *          information on _i_-th component.
4486  */
4487 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4488 {
4489   const DataArray *arr=getOrCreateAndGetArray();
4490   return arr->getInfoOnComponents();
4491 }
4492
4493 /*!
4494  * Returns a mutable info on components of \a this field.
4495  *  \return std::vector<std::string>& - a sequence of strings each being an
4496  *          information on _i_-th component.
4497  */
4498 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4499 {
4500   DataArray *arr=getOrCreateAndGetArray();
4501   return arr->getInfoOnComponents();
4502 }
4503
4504 /*!
4505  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4506  *  \param [in] type - a spatial discretization of the new field.
4507  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4508  *  \param [in] mName - a name of the supporting mesh.
4509  *  \param [in] renumPol - specifies how to permute values of the result field according to
4510  *          the optional numbers of cells and nodes, if any. The valid values are
4511  *          - 0 - do not permute.
4512  *          - 1 - permute cells.
4513  *          - 2 - permute nodes.
4514  *          - 3 - permute cells and nodes.
4515  *
4516  *  \param [in] glob - the global data storing profiles and localization.
4517  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4518  *          caller is to delete this field using decrRef() as it is no more needed. 
4519  *  \throw If the MED file is not readable.
4520  *  \throw If there is no mesh named \a mName in the MED file.
4521  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4522  *  \throw If no field of \a this is lying on the mesh \a mName.
4523  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4524  */
4525 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4526 {
4527   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4528   if(mName.empty())
4529     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4530   else
4531     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4532   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4533 }
4534
4535 /*!
4536  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4537  *  \param [in] type - a spatial discretization of the new field.
4538  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4539  *  \param [in] renumPol - specifies how to permute values of the result field according to
4540  *          the optional numbers of cells and nodes, if any. The valid values are
4541  *          - 0 - do not permute.
4542  *          - 1 - permute cells.
4543  *          - 2 - permute nodes.
4544  *          - 3 - permute cells and nodes.
4545  *
4546  *  \param [in] glob - the global data storing profiles and localization.
4547  *  \param [in] mesh - the supporting mesh.
4548  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4549  *          caller is to delete this field using decrRef() as it is no more needed. 
4550  *  \throw If the MED file is not readable.
4551  *  \throw If no field of \a this is lying on \a mesh.
4552  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4553  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4554  */
4555 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4556 {
4557   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4558   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4559   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4560   if(meshDimRelToMax==1)
4561     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4562   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4563 }
4564
4565 /*!
4566  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4567  * given mesh. 
4568  *  \param [in] type - a spatial discretization of the new field.
4569  *  \param [in] mName - a name of the supporting mesh.
4570  *  \param [in] renumPol - specifies how to permute values of the result field according to
4571  *          the optional numbers of cells and nodes, if any. The valid values are
4572  *          - 0 - do not permute.
4573  *          - 1 - permute cells.
4574  *          - 2 - permute nodes.
4575  *          - 3 - permute cells and nodes.
4576  *
4577  *  \param [in] glob - the global data storing profiles and localization.
4578  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4579  *          caller is to delete this field using decrRef() as it is no more needed. 
4580  *  \throw If the MED file is not readable.
4581  *  \throw If there is no mesh named \a mName in the MED file.
4582  *  \throw If there are no mesh entities in the mesh.
4583  *  \throw If no field values of the given \a type are available.
4584  */
4585 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4586 {
4587   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4588   if(mName.empty())
4589     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4590   else
4591     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4592   int absDim=getDimension();
4593   int meshDimRelToMax=absDim-mm->getMeshDimension();
4594   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4595 }
4596
4597 /*!
4598  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4599  *  \param [in] type - a spatial discretization of the new field.
4600  *  \param [in] renumPol - specifies how to permute values of the result field according to
4601  *          the optional numbers of cells and nodes, if any. The valid values are
4602  *          - 0 - do not permute.
4603  *          - 1 - permute cells.
4604  *          - 2 - permute nodes.
4605  *          - 3 - permute cells and nodes.
4606  *
4607  *  \param [in] glob - the global data storing profiles and localization.
4608  *  \param [in] mesh - the supporting mesh.
4609  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4610  *         field according to \a renumPol.
4611  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4612  *         field according to \a renumPol.
4613  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4614  *          caller is to delete this field using decrRef() as it is no more needed. 
4615  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4616  *  \throw If no field of \a this is lying on \a mesh.
4617  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4618  */
4619 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
4620 {
4621   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4622   int meshId=getMeshIdFromMeshName(mesh->getName());
4623   bool isPfl=false;
4624   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4625   switch(renumPol)
4626   {
4627     case 0:
4628       {
4629         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4630         return ret.retn();
4631       }
4632     case 3:
4633     case 1:
4634       {
4635         if(isPfl)
4636           throw INTERP_KERNEL::Exception(msg1);
4637         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4638         if(cellRenum)
4639           {
4640             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4641               {
4642                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4643                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4644                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4645               }
4646             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4647             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4648             std::vector<DataArray *> arrOut2(1,arrOut);
4649             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4650             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4651             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4652           }
4653         if(renumPol==1)
4654           return ret.retn();
4655       }
4656     case 2:
4657       {
4658         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4659         if(isPfl)
4660           throw INTERP_KERNEL::Exception(msg1);
4661         if(nodeRenum)
4662           {
4663             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4664               {
4665                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4666                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4667                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4668               }
4669             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4670             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4671               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4672             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4673           }
4674         return ret.retn();
4675       }
4676     default:
4677       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4678   }
4679 }
4680
4681 /*!
4682  * Returns values and a profile of the field of a given type lying on a given support.
4683  *  \param [in] type - a spatial discretization of the field.
4684  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4685  *  \param [in] mesh - the supporting mesh.
4686  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4687  *          field of interest lies on. If the field lies on all entities of the given
4688  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4689  *          using decrRef() as it is no more needed.  
4690  *  \param [in] glob - the global data storing profiles and localization.
4691  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4692  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4693  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4694  *  \throw If no field of \a this is lying on \a mesh.
4695  *  \throw If no field values of the given \a type are available.
4696  */
4697 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4698 {
4699   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4700   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4701   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4702   ret->setName(nasc.getName().c_str());
4703   return ret.retn();
4704 }
4705
4706 //= MEDFileField1TSWithoutSDA
4707
4708 /*!
4709  * Throws if a given value is not a valid (non-extended) relative dimension.
4710  *  \param [in] meshDimRelToMax - the relative dimension value.
4711  *  \throw If \a meshDimRelToMax > 0.
4712  */
4713 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4714 {
4715   if(meshDimRelToMax>0)
4716     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4717 }
4718
4719 /*!
4720  * Checks if elements of a given mesh are in the order suitable for writing 
4721  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4722  * vector describing types of elements and their number.
4723  *  \param [in] mesh - the mesh to check.
4724  *  \return std::vector<int> - a vector holding for each element type (1) item of
4725  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4726  *          These values are in full-interlace mode.
4727  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4728  */
4729 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4730 {
4731   if(!mesh)
4732     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4733   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4734   int nbOfTypes=geoTypes.size();
4735   std::vector<int> code(3*nbOfTypes);
4736   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4737   arr1->alloc(nbOfTypes,1);
4738   int *arrPtr=arr1->getPointer();
4739   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4740   for(int i=0;i<nbOfTypes;i++,it++)
4741     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4742   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4743   const int *arrPtr2=arr2->getConstPointer();
4744   int i=0;
4745   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4746     {
4747       int pos=arrPtr2[i];
4748       int nbCells=mesh->getNumberOfCellsWithType(*it);
4749       code[3*pos]=(int)(*it);
4750       code[3*pos+1]=nbCells;
4751       code[3*pos+2]=-1;//no profiles
4752     }
4753   std::vector<const DataArrayInt *> idsPerType;//no profiles
4754   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4755   if(da)
4756     {
4757       da->decrRef();
4758       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4759     }
4760   return code;
4761 }
4762
4763 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4764 {
4765   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4766 }
4767
4768 /*!
4769  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4770  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4771  * item of every of returned sequences refers to the _i_-th part of \a this field.
4772  * Thus all sequences returned by this method are of the same length equal to number
4773  * of different types of supporting entities.<br>
4774  * A field part can include sub-parts with several different spatial discretizations,
4775  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4776  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4777  * of a nested sequence corresponds to a type of spatial discretization.<br>
4778  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4779  * The overhead is due to selecting values into new instances of DataArrayDouble.
4780  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4781  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4782  *          not checked if \a mname == \c NULL).
4783  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4784  *          a field part is returned. 
4785  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4786  *          A field part can include sub-parts with several different spatial discretizations,
4787  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4788  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4789  *          This sequence is of the same length as \a types. 
4790  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4791  *          discretization. A profile name can be empty.
4792  *          Length of this and of nested sequences is the same as that of \a typesF.
4793  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4794  *          discretization. A localization name can be empty.
4795  *          Length of this and of nested sequences is the same as that of \a typesF.
4796  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4797  *          per each type of spatial discretization within one mesh entity type.
4798  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4799  *          Length of this and of nested sequences is the same as that of \a typesF.
4800  *  \throw If no field is lying on \a mname.
4801  */
4802 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
4803 {
4804   int meshId=0;
4805   if(!mname.empty())
4806     meshId=getMeshIdFromMeshName(mname);
4807   else
4808     if(_field_per_mesh.empty())
4809       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4810   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4811   int nbOfRet=ret0.size();
4812   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4813   for(int i=0;i<nbOfRet;i++)
4814     {
4815       const std::vector< std::pair<int,int> >& p=ret0[i];
4816       int nbOfRet1=p.size();
4817       ret[i].resize(nbOfRet1);
4818       for(int j=0;j<nbOfRet1;j++)
4819         {
4820           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4821           ret[i][j]=tmp;
4822         }
4823     }
4824   return ret;
4825 }
4826
4827 /*!
4828  * Returns a pointer to the underground DataArrayDouble instance. So the
4829  * caller should not decrRef() it. This method allows for a direct access to the field
4830  * values. This method is quite unusable if there is more than a nodal field or a cell
4831  * field on single geometric cell type. 
4832  *  \return DataArrayDouble * - the pointer to the field values array.
4833  */
4834 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
4835 {
4836   const DataArrayDouble *ret=_arr;
4837   if(ret)
4838     return const_cast<DataArrayDouble *>(ret);
4839   else
4840     return 0;
4841 }
4842
4843 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
4844 {
4845   return TYPE_STR;
4846 }
4847
4848 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
4849 {
4850   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
4851   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4852   ret->deepCpyLeavesFrom(*this);
4853   const DataArrayDouble *arr(_arr);
4854   if(arr)
4855     {
4856       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
4857       ret->setArray(arr2);
4858     }
4859   return ret.retn();
4860 }
4861
4862 /*!
4863  * Returns a pointer to the underground DataArrayDouble instance. So the
4864  * caller should not decrRef() it. This method allows for a direct access to the field
4865  * values. This method is quite unusable if there is more than a nodal field or a cell
4866  * field on single geometric cell type. 
4867  *  \return DataArrayDouble * - the pointer to the field values array.
4868  */
4869 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
4870 {
4871   return getUndergroundDataArrayDouble();
4872 }
4873
4874 /*!
4875  * Returns a pointer to the underground DataArrayDouble instance and a
4876  * sequence describing parameters of a support of each part of \a this field. The
4877  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4878  * direct access to the field values. This method is intended for the field lying on one
4879  * mesh only.
4880  *  \param [in,out] entries - the sequence describing parameters of a support of each
4881  *         part of \a this field. Each item of this sequence consists of two parts. The
4882  *         first part describes a type of mesh entity and an id of discretization of a
4883  *         current field part. The second part describes a range of values [begin,end)
4884  *         within the returned array relating to the current field part.
4885  *  \return DataArrayDouble * - the pointer to the field values array.
4886  *  \throw If the number of underlying meshes is not equal to 1.
4887  *  \throw If no field values are available.
4888  *  \sa getUndergroundDataArray()
4889  */
4890 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4891 {
4892   if(_field_per_mesh.size()!=1)
4893     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4894   if(_field_per_mesh[0]==0)
4895     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4896   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4897   return getUndergroundDataArrayDouble();
4898 }
4899
4900 /*!
4901  * Returns a pointer to the underground DataArrayDouble instance and a
4902  * sequence describing parameters of a support of each part of \a this field. The
4903  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4904  * direct access to the field values. This method is intended for the field lying on one
4905  * mesh only.
4906  *  \param [in,out] entries - the sequence describing parameters of a support of each
4907  *         part of \a this field. Each item of this sequence consists of two parts. The
4908  *         first part describes a type of mesh entity and an id of discretization of a
4909  *         current field part. The second part describes a range of values [begin,end)
4910  *         within the returned array relating to the current field part.
4911  *  \return DataArrayDouble * - the pointer to the field values array.
4912  *  \throw If the number of underlying meshes is not equal to 1.
4913  *  \throw If no field values are available.
4914  *  \sa getUndergroundDataArray()
4915  */
4916 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4917 {
4918   return getUndergroundDataArrayDoubleExt(entries);
4919 }
4920
4921 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4922 {
4923   DataArrayDouble *arr(getOrCreateAndGetArrayDouble());
4924   arr->setInfoAndChangeNbOfCompo(infos);
4925 }
4926
4927 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4928 {
4929 }
4930
4931 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
4932 {
4933   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
4934   ret->deepCpyLeavesFrom(*this);
4935   return ret.retn();
4936 }
4937
4938 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const
4939 {
4940   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
4941   if((const DataArrayDouble *)_arr)
4942     ret->_arr=_arr->deepCpy();
4943   return ret.retn();
4944 }
4945
4946 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
4947 {
4948   if(!arr)
4949     {
4950       _nb_of_tuples_to_be_allocated=-1;
4951       _arr=0;
4952       return ;
4953     }
4954   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
4955   if(!arrC)
4956     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
4957   else
4958     _nb_of_tuples_to_be_allocated=-3;
4959   arrC->incrRef();
4960   _arr=arrC;
4961 }
4962
4963 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4964 {
4965   return DataArrayDouble::New();
4966 }
4967
4968 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
4969 {
4970   DataArrayDouble *ret=_arr;
4971   if(ret)
4972     return ret;
4973   _arr=DataArrayDouble::New();
4974   return _arr;
4975 }
4976
4977 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
4978 {
4979   return getOrCreateAndGetArrayDouble();
4980 }
4981
4982 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
4983 {
4984   const DataArrayDouble *ret=_arr;
4985   if(ret)
4986     return ret;
4987   DataArrayDouble *ret2=DataArrayDouble::New();
4988   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
4989   return ret2;
4990 }
4991
4992 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
4993 {
4994   return getOrCreateAndGetArrayDouble();
4995 }
4996
4997 //= MEDFileIntField1TSWithoutSDA
4998
4999 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5000 {
5001   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5002 }
5003
5004 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5005 {
5006 }
5007
5008 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5009                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5010 {
5011   DataArrayInt *arr(getOrCreateAndGetArrayInt());
5012   arr->setInfoAndChangeNbOfCompo(infos);
5013 }
5014
5015 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5016 {
5017   return TYPE_STR;
5018 }
5019
5020 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5021 {
5022   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5023   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5024   ret->deepCpyLeavesFrom(*this);
5025   const DataArrayInt *arr(_arr);
5026   if(arr)
5027     {
5028       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
5029       ret->setArray(arr2);
5030     }
5031   return ret.retn();
5032 }
5033
5034 /*!
5035  * Returns a pointer to the underground DataArrayInt instance. So the
5036  * caller should not decrRef() it. This method allows for a direct access to the field
5037  * values. This method is quite unusable if there is more than a nodal field or a cell
5038  * field on single geometric cell type. 
5039  *  \return DataArrayInt * - the pointer to the field values array.
5040  */
5041 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
5042 {
5043   return getUndergroundDataArrayInt();
5044 }
5045
5046 /*!
5047  * Returns a pointer to the underground DataArrayInt instance. So the
5048  * caller should not decrRef() it. This method allows for a direct access to the field
5049  * values. This method is quite unusable if there is more than a nodal field or a cell
5050  * field on single geometric cell type. 
5051  *  \return DataArrayInt * - the pointer to the field values array.
5052  */
5053 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5054 {
5055   const DataArrayInt *ret=_arr;
5056   if(ret)
5057     return const_cast<DataArrayInt *>(ret);
5058   else
5059     return 0;
5060 }
5061
5062 /*!
5063  * Returns a pointer to the underground DataArrayInt instance and a
5064  * sequence describing parameters of a support of each part of \a this field. The
5065  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5066  * direct access to the field values. This method is intended for the field lying on one
5067  * mesh only.
5068  *  \param [in,out] entries - the sequence describing parameters of a support of each
5069  *         part of \a this field. Each item of this sequence consists of two parts. The
5070  *         first part describes a type of mesh entity and an id of discretization of a
5071  *         current field part. The second part describes a range of values [begin,end)
5072  *         within the returned array relating to the current field part.
5073  *  \return DataArrayInt * - the pointer to the field values array.
5074  *  \throw If the number of underlying meshes is not equal to 1.
5075  *  \throw If no field values are available.
5076  *  \sa getUndergroundDataArray()
5077  */
5078 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5079 {
5080   return getUndergroundDataArrayIntExt(entries);
5081 }
5082
5083 /*!
5084  * Returns a pointer to the underground DataArrayInt instance and a
5085  * sequence describing parameters of a support of each part of \a this field. The
5086  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5087  * direct access to the field values. This method is intended for the field lying on one
5088  * mesh only.
5089  *  \param [in,out] entries - the sequence describing parameters of a support of each
5090  *         part of \a this field. Each item of this sequence consists of two parts. The
5091  *         first part describes a type of mesh entity and an id of discretization of a
5092  *         current field part. The second part describes a range of values [begin,end)
5093  *         within the returned array relating to the current field part.
5094  *  \return DataArrayInt * - the pointer to the field values array.
5095  *  \throw If the number of underlying meshes is not equal to 1.
5096  *  \throw If no field values are available.
5097  *  \sa getUndergroundDataArray()
5098  */
5099 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5100 {
5101   if(_field_per_mesh.size()!=1)
5102     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5103   if(_field_per_mesh[0]==0)
5104     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5105   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5106   return getUndergroundDataArrayInt();
5107 }
5108
5109 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5110 {
5111   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5112   ret->deepCpyLeavesFrom(*this);
5113   return ret.retn();
5114 }
5115
5116 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const
5117 {
5118   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5119   if((const DataArrayInt *)_arr)
5120     ret->_arr=_arr->deepCpy();
5121   return ret.retn();
5122 }
5123
5124 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5125 {
5126   if(!arr)
5127     {
5128       _nb_of_tuples_to_be_allocated=-1;
5129       _arr=0;
5130       return ;
5131     }
5132   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5133   if(!arrC)
5134     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5135   else
5136     _nb_of_tuples_to_be_allocated=-3;
5137   arrC->incrRef();
5138   _arr=arrC;
5139 }
5140
5141 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5142 {
5143   return DataArrayInt::New();
5144 }
5145
5146 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5147 {
5148   DataArrayInt *ret=_arr;
5149   if(ret)
5150     return ret;
5151   _arr=DataArrayInt::New();
5152   return _arr;
5153 }
5154
5155 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5156 {
5157   return getOrCreateAndGetArrayInt();
5158 }
5159
5160 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5161 {
5162   const DataArrayInt *ret=_arr;
5163   if(ret)
5164     return ret;
5165   DataArrayInt *ret2=DataArrayInt::New();
5166   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5167   return ret2;
5168 }
5169
5170 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5171 {
5172   return getOrCreateAndGetArrayInt();
5173 }
5174
5175 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5176 {
5177 }
5178
5179 //= MEDFileAnyTypeField1TS
5180
5181 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5182 {
5183   med_field_type typcha;
5184   //
5185   std::vector<std::string> infos;
5186   std::string dtunit,fieldName;
5187   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5188   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5189   switch(typcha)
5190   {
5191     case MED_FLOAT64:
5192       {
5193         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5194         break;
5195       }
5196     case MED_INT32:
5197       {
5198         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5199         break;
5200       }
5201     default:
5202       {
5203         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] !";
5204         throw INTERP_KERNEL::Exception(oss.str().c_str());
5205       }
5206   }
5207   ret->setDtUnit(dtunit.c_str());
5208   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5209   //
5210   med_int numdt,numit;
5211   med_float dt;
5212   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5213   ret->setTime(numdt,numit,dt);
5214   ret->_csit=1;
5215   if(loadAll)
5216     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5217   else
5218     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5219   return ret.retn();
5220 }
5221
5222 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5223 try:MEDFileFieldGlobsReal(fileName)
5224 {
5225   MEDFileUtilities::CheckFileForRead(fileName);
5226   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5227   _content=BuildContentFrom(fid,fileName,loadAll,ms);
5228   loadGlobals(fid);
5229 }
5230 catch(INTERP_KERNEL::Exception& e)
5231 {
5232     throw e;
5233 }
5234
5235 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5236 {
5237   med_field_type typcha;
5238   std::vector<std::string> infos;
5239   std::string dtunit;
5240   int iii=-1;
5241   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5242   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5243   switch(typcha)
5244   {
5245     case MED_FLOAT64:
5246       {
5247         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5248         break;
5249       }
5250     case MED_INT32:
5251       {
5252         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5253         break;
5254       }
5255     default:
5256       {
5257         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] !";
5258         throw INTERP_KERNEL::Exception(oss.str().c_str());
5259       }
5260   }
5261   ret->setDtUnit(dtunit.c_str());
5262   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5263   //
5264   if(nbSteps<1)
5265     {
5266       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5267       throw INTERP_KERNEL::Exception(oss.str().c_str());
5268     }
5269   //
5270   med_int numdt,numit;
5271   med_float dt;
5272   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5273   ret->setTime(numdt,numit,dt);
5274   ret->_csit=1;
5275   if(loadAll)
5276     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5277   else
5278     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5279   return ret.retn();
5280 }
5281
5282 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5283 try:MEDFileFieldGlobsReal(fileName)
5284 {
5285   MEDFileUtilities::CheckFileForRead(fileName);
5286   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5287   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
5288   loadGlobals(fid);
5289 }
5290 catch(INTERP_KERNEL::Exception& e)
5291 {
5292     throw e;
5293 }
5294
5295 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5296 {
5297   if(!c)
5298     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5299   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5300     {
5301       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5302       ret->setFileName(fileName);
5303       ret->_content=c; c->incrRef();
5304       return ret.retn();
5305     }
5306   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5307     {
5308       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5309       ret->setFileName(fileName);
5310       ret->_content=c; c->incrRef();
5311       return ret.retn();
5312     }
5313   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5314 }
5315
5316 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5317 {
5318   MEDFileUtilities::CheckFileForRead(fileName);
5319   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5320   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
5321   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5322   ret->loadGlobals(fid);
5323   return ret.retn();
5324 }
5325
5326 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5327 {
5328   MEDFileUtilities::CheckFileForRead(fileName);
5329   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5330   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
5331   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5332   ret->loadGlobals(fid);
5333   return ret.retn();
5334 }
5335
5336 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5337 {
5338   MEDFileUtilities::CheckFileForRead(fileName);
5339   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5340   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll,0);
5341   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5342   ret->loadGlobals(fid);
5343   return ret.retn();
5344 }
5345
5346 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5347 {
5348   med_field_type typcha;
5349   std::vector<std::string> infos;
5350   std::string dtunit;
5351   int iii=-1;
5352   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5353   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5354   switch(typcha)
5355   {
5356     case MED_FLOAT64:
5357       {
5358         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5359         break;
5360       }
5361     case MED_INT32:
5362       {
5363         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5364         break;
5365       }
5366     default:
5367       {
5368         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] !";
5369         throw INTERP_KERNEL::Exception(oss.str().c_str());
5370       }
5371   }
5372   ret->setDtUnit(dtunit.c_str());
5373   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5374   //
5375   bool found=false;
5376   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5377   for(int i=0;i<nbOfStep2 && !found;i++)
5378     {
5379       med_int numdt,numit;
5380       med_float dt;
5381       MEDfieldComputingStepInfo(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt);
5382       if(numdt==iteration && numit==order)
5383         {
5384           found=true;
5385           ret->_csit=i+1;
5386         }
5387       else
5388         dtits[i]=std::pair<int,int>(numdt,numit);
5389     }
5390   if(!found)
5391     {
5392       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5393       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5394         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5395       throw INTERP_KERNEL::Exception(oss.str().c_str());
5396     }
5397   if(loadAll)
5398     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5399   else
5400     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5401   return ret.retn();
5402 }
5403
5404 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5405 try:MEDFileFieldGlobsReal(fileName)
5406 {
5407   MEDFileUtilities::CheckFileForRead(fileName);
5408   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5409   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll,ms);
5410   loadGlobals(fid);
5411 }
5412 catch(INTERP_KERNEL::Exception& e)
5413 {
5414     throw e;
5415 }
5416
5417 /*!
5418  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5419  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5420  *
5421  * \warning this is a shallow copy constructor
5422  */
5423 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5424 {
5425   if(!shallowCopyOfContent)
5426     {
5427       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5428       otherPtr->incrRef();
5429       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5430     }
5431   else
5432     {
5433       _content=other.shallowCpy();
5434     }
5435 }
5436
5437 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)
5438 {
5439   if(checkFieldId)
5440     {
5441       int nbFields=MEDnField(fid);
5442       if(fieldIdCFormat>=nbFields)
5443         {
5444           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5445           throw INTERP_KERNEL::Exception(oss.str().c_str());
5446         }
5447     }
5448   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5449   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5450   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5451   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5452   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5453   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5454   med_bool localMesh;
5455   int nbOfStep;
5456   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5457   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5458   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5459   infos.clear(); infos.resize(ncomp);
5460   for(int j=0;j<ncomp;j++)
5461     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5462   return nbOfStep;
5463 }
5464
5465 /*!
5466  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5467  * 
5468  * \param [out]
5469  * \return in case of success the number of time steps available for the field with name \a fieldName.
5470  */
5471 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)
5472 {
5473   int nbFields=MEDnField(fid);
5474   bool found=false;
5475   std::vector<std::string> fns(nbFields);
5476   int nbOfStep2=-1;
5477   for(int i=0;i<nbFields && !found;i++)
5478     {
5479       std::string tmp;
5480       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5481       fns[i]=tmp;
5482       found=(tmp==fieldName);
5483       if(found)
5484         posCFormat=i;
5485     }
5486   if(!found)
5487     {
5488       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5489       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5490         oss << "\"" << *it << "\" ";
5491       throw INTERP_KERNEL::Exception(oss.str().c_str());
5492     }
5493   return nbOfStep2;
5494 }
5495
5496 /*!
5497  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5498  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5499  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5500  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5501  * to keep a valid instance.
5502  * 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.
5503  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5504  * 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.
5505  *
5506  * \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.
5507  * \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.
5508  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5509  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5510  * \param [in] newLocName is the new localization name.
5511  * \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.
5512  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5513  */
5514 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5515 {
5516   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5517   std::string oldPflName=disc->getProfile();
5518   std::vector<std::string> vv=getPflsReallyUsedMulti();
5519   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5520   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5521     {
5522       disc->setProfile(newPflName);
5523       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5524       pfl->setName(newPflName);
5525     }
5526   else
5527     {
5528       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5529       throw INTERP_KERNEL::Exception(oss.str().c_str());
5530     }
5531 }
5532
5533 /*!
5534  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5535  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5536  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5537  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5538  * to keep a valid instance.
5539  * 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.
5540  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5541  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5542  * 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.
5543  *
5544  * \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.
5545  * \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.
5546  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5547  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5548  * \param [in] newLocName is the new localization name.
5549  * \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.
5550  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5551  */
5552 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5553 {
5554   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5555   std::string oldLocName=disc->getLocalization();
5556   std::vector<std::string> vv=getLocsReallyUsedMulti();
5557   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5558   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5559     {
5560       disc->setLocalization(newLocName);
5561       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5562       loc.setName(newLocName);
5563     }
5564   else
5565     {
5566       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5567       throw INTERP_KERNEL::Exception(oss.str().c_str());
5568     }
5569 }
5570
5571 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5572 {
5573   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5574   if(!ret)
5575     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5576   return ret;
5577 }
5578
5579 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5580 {
5581   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5582   if(!ret)
5583     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5584   return ret;
5585 }
5586
5587 /*!
5588  * Writes \a this field into a MED file specified by its name.
5589  *  \param [in] fileName - the MED file name.
5590  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5591  * - 2 - erase; an existing file is removed.
5592  * - 1 - append; same data should not be present in an existing file.
5593  * - 0 - overwrite; same data present in an existing file is overwritten.
5594  *  \throw If the field name is not set.
5595  *  \throw If no field data is set.
5596  *  \throw If \a mode == 1 and the same data is present in an existing file.
5597  */
5598 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5599 {
5600   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5601   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5602   writeLL(fid);
5603 }
5604
5605 /*!
5606  * This method alloc the arrays and load potentially huge arrays contained in this field.
5607  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5608  * This method can be also called to refresh or reinit values from a file.
5609  * 
5610  * \throw If the fileName is not set or points to a non readable MED file.
5611  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5612  */
5613 void MEDFileAnyTypeField1TS::loadArrays()
5614 {
5615   if(getFileName().empty())
5616     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5617   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5618   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5619 }
5620
5621 /*!
5622  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5623  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5624  * this method does not throw if \a this does not come from file read.
5625  * 
5626  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5627  */
5628 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5629 {
5630   if(!getFileName().empty())
5631     {
5632       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5633       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5634     }
5635 }
5636
5637 /*!
5638  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5639  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5640  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5641  * 
5642  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5643  */
5644 void MEDFileAnyTypeField1TS::unloadArrays()
5645 {
5646   contentNotNullBase()->unloadArrays();
5647 }
5648
5649 /*!
5650  * 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.
5651  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5652  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5653  * 
5654  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5655  */
5656 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5657 {
5658   if(!getFileName().empty())
5659     contentNotNullBase()->unloadArrays();
5660 }
5661
5662 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5663 {
5664   int nbComp=getNumberOfComponents();
5665   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5666   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5667   for(int i=0;i<nbComp;i++)
5668     {
5669       std::string info=getInfo()[i];
5670       std::string c,u;
5671       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5672       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5673       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5674     }
5675   if(getName().empty())
5676     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5677   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5678   writeGlobals(fid,*this);
5679   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5680 }
5681
5682 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5683 {
5684   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5685 }
5686
5687 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5688 {
5689   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5690   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5691   return ret;
5692 }
5693
5694 /*!
5695  * Returns a string describing \a this field. This string is outputted 
5696  * by \c print Python command.
5697  */
5698 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5699 {
5700   std::ostringstream oss;
5701   contentNotNullBase()->simpleRepr(0,oss,-1);
5702   simpleReprGlobs(oss);
5703   return oss.str();
5704 }
5705
5706 /*!
5707  * This method returns all profiles whose name is non empty used.
5708  * \b WARNING If profile is used several times it will be reported \b only \b once.
5709  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5710  */
5711 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5712 {
5713   return contentNotNullBase()->getPflsReallyUsed2();
5714 }
5715
5716 /*!
5717  * This method returns all localizations whose name is non empty used.
5718  * \b WARNING If localization is used several times it will be reported \b only \b once.
5719  */
5720 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5721 {
5722   return contentNotNullBase()->getLocsReallyUsed2();
5723 }
5724
5725 /*!
5726  * This method returns all profiles whose name is non empty used.
5727  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5728  */
5729 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5730 {
5731   return contentNotNullBase()->getPflsReallyUsedMulti2();
5732 }
5733
5734 /*!
5735  * This method returns all localizations whose name is non empty used.
5736  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5737  */
5738 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5739 {
5740   return contentNotNullBase()->getLocsReallyUsedMulti2();
5741 }
5742
5743 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5744 {
5745   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5746 }
5747
5748 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5749 {
5750   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5751 }
5752
5753 int MEDFileAnyTypeField1TS::getDimension() const
5754 {
5755   return contentNotNullBase()->getDimension();
5756 }
5757
5758 int MEDFileAnyTypeField1TS::getIteration() const
5759 {
5760   return contentNotNullBase()->getIteration();
5761 }
5762
5763 int MEDFileAnyTypeField1TS::getOrder() const
5764 {
5765   return contentNotNullBase()->getOrder();
5766 }
5767
5768 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5769 {
5770   return contentNotNullBase()->getTime(iteration,order);
5771 }
5772
5773 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5774 {
5775   contentNotNullBase()->setTime(iteration,order,val);
5776 }
5777
5778 std::string MEDFileAnyTypeField1TS::getName() const
5779 {
5780   return contentNotNullBase()->getName();
5781 }
5782
5783 void MEDFileAnyTypeField1TS::setName(const std::string& name)
5784 {
5785   contentNotNullBase()->setName(name);
5786 }
5787
5788 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5789 {
5790   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5791 }
5792
5793 std::string MEDFileAnyTypeField1TS::getDtUnit() const
5794 {
5795   return contentNotNullBase()->getDtUnit();
5796 }
5797
5798 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
5799 {
5800   contentNotNullBase()->setDtUnit(dtUnit);
5801 }
5802
5803 std::string MEDFileAnyTypeField1TS::getMeshName() const
5804 {
5805   return contentNotNullBase()->getMeshName();
5806 }
5807
5808 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
5809 {
5810   contentNotNullBase()->setMeshName(newMeshName);
5811 }
5812
5813 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
5814 {
5815   return contentNotNullBase()->changeMeshNames(modifTab);
5816 }
5817
5818 int MEDFileAnyTypeField1TS::getMeshIteration() const
5819 {
5820   return contentNotNullBase()->getMeshIteration();
5821 }
5822
5823 int MEDFileAnyTypeField1TS::getMeshOrder() const
5824 {
5825   return contentNotNullBase()->getMeshOrder();
5826 }
5827
5828 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5829 {
5830   return contentNotNullBase()->getNumberOfComponents();
5831 }
5832
5833 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5834 {
5835   return contentNotNullBase()->isDealingTS(iteration,order);
5836 }
5837
5838 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5839 {
5840   return contentNotNullBase()->getDtIt();
5841 }
5842
5843 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5844 {
5845   contentNotNullBase()->fillIteration(p);
5846 }
5847
5848 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
5849 {
5850   contentNotNullBase()->fillTypesOfFieldAvailable(types);
5851 }
5852
5853 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
5854 {
5855   contentNotNullBase()->setInfo(infos);
5856 }
5857
5858 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
5859 {
5860   return contentNotNullBase()->getInfo();
5861 }
5862 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
5863 {
5864   return contentNotNullBase()->getInfo();
5865 }
5866
5867 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
5868 {
5869   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5870 }
5871
5872 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
5873 {
5874   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5875 }
5876
5877 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
5878 {
5879   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
5880 }
5881
5882 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
5883 {
5884   return contentNotNullBase()->getTypesOfFieldAvailable();
5885 }
5886
5887 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,
5888                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
5889 {
5890   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5891 }
5892
5893 /*!
5894  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
5895  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5896  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
5897  */
5898 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
5899 {
5900   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5901   if(!content)
5902     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
5903   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
5904   std::size_t sz(contentsSplit.size());
5905   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5906   for(std::size_t i=0;i<sz;i++)
5907     {
5908       ret[i]=shallowCpy();
5909       ret[i]->_content=contentsSplit[i];
5910     }
5911   return ret;
5912 }
5913
5914 /*!
5915  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
5916  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5917  */
5918 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
5919 {
5920   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5921   if(!content)
5922     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
5923   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitDiscretizations();
5924   std::size_t sz(contentsSplit.size());
5925   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5926   for(std::size_t i=0;i<sz;i++)
5927     {
5928       ret[i]=shallowCpy();
5929       ret[i]->_content=contentsSplit[i];
5930     }
5931   return ret;
5932 }
5933
5934 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const
5935 {
5936   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
5937   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5938     ret->_content=_content->deepCpy();
5939   ret->deepCpyGlobs(*this);
5940   return ret.retn();
5941 }
5942
5943 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
5944 {
5945   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
5946 }
5947
5948 //= MEDFileField1TS
5949
5950 /*!
5951  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5952  * the first field that has been read from a specified MED file.
5953  *  \param [in] fileName - the name of the MED file to read.
5954  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5955  *          is to delete this field using decrRef() as it is no more needed.
5956  *  \throw If reading the file fails.
5957  */
5958 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
5959 {
5960   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,loadAll,0));
5961   ret->contentNotNull();
5962   return ret.retn();
5963 }
5964
5965 /*!
5966  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5967  * a given field that has been read from a specified MED file.
5968  *  \param [in] fileName - the name of the MED file to read.
5969  *  \param [in] fieldName - the name of the field to read.
5970  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5971  *          is to delete this field using decrRef() as it is no more needed.
5972  *  \throw If reading the file fails.
5973  *  \throw If there is no field named \a fieldName in the file.
5974  */
5975 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5976 {
5977   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,loadAll,0));
5978   ret->contentNotNull();
5979   return ret.retn();
5980 }
5981
5982 /*!
5983  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
5984  * a given field that has been read from a specified MED file.
5985  *  \param [in] fileName - the name of the MED file to read.
5986  *  \param [in] fieldName - the name of the field to read.
5987  *  \param [in] iteration - the iteration number of a required time step.
5988  *  \param [in] order - the iteration order number of required time step.
5989  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5990  *          is to delete this field using decrRef() as it is no more needed.
5991  *  \throw If reading the file fails.
5992  *  \throw If there is no field named \a fieldName in the file.
5993  *  \throw If the required time step is missing from the file.
5994  */
5995 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5996 {
5997   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll,0));
5998   ret->contentNotNull();
5999   return ret.retn();
6000 }
6001
6002 /*!
6003  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6004  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6005  *
6006  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6007  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6008  * \warning this is a shallow copy constructor
6009  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6010  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6011  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6012  *          is to delete this field using decrRef() as it is no more needed.
6013  */
6014 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6015 {
6016   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
6017   ret->contentNotNull();
6018   return ret.retn();
6019 }
6020
6021 /*!
6022  * Returns a new empty instance of MEDFileField1TS.
6023  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6024  *          is to delete this field using decrRef() as it is no more needed.
6025  */
6026 MEDFileField1TS *MEDFileField1TS::New()
6027 {
6028   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
6029   ret->contentNotNull();
6030   return ret.retn();
6031 }
6032
6033 /*!
6034  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6035  * following the given input policy.
6036  *
6037  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6038  *                            By default (true) the globals are deeply copied.
6039  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6040  */
6041 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6042 {
6043   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
6044   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6045   if(content)
6046     {
6047       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6048       if(!contc)
6049         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6050       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6051       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6052     }
6053   else
6054     ret=MEDFileIntField1TS::New();
6055   if(isDeepCpyGlobs)
6056     ret->deepCpyGlobs(*this);
6057   else
6058     ret->shallowCpyGlobs(*this);
6059   return ret.retn();
6060 }
6061
6062 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6063 {
6064   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6065   if(!pt)
6066     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6067   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6068   if(!ret)
6069     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 !");
6070   return ret;
6071 }
6072
6073 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6074 {
6075   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6076   if(!pt)
6077     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6078   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6079   if(!ret)
6080     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 !");
6081   return ret;
6082 }
6083
6084 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6085 {
6086   if(!f)
6087     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6088   if(!((DataArray*)arr))
6089     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6090   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6091   if(!arrOutC)
6092     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6093   f->setArray(arrOutC);
6094 }
6095
6096 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6097 {
6098   if(!((DataArray*)arr))
6099     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6100   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6101   if(!arrOutC)
6102     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6103   arrOutC->incrRef();
6104   return arrOutC;
6105 }
6106
6107 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6108 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6109 {
6110 }
6111 catch(INTERP_KERNEL::Exception& e)
6112 { throw e; }
6113
6114 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6115 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6116 {
6117 }
6118 catch(INTERP_KERNEL::Exception& e)
6119 { throw e; }
6120
6121 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6122 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6123 {
6124 }
6125 catch(INTERP_KERNEL::Exception& e)
6126 { throw e; }
6127
6128 /*!
6129  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6130  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6131  *
6132  * \warning this is a shallow copy constructor
6133  */
6134 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6135 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6136 {
6137 }
6138 catch(INTERP_KERNEL::Exception& e)
6139 { throw e; }
6140
6141 MEDFileField1TS::MEDFileField1TS()
6142 {
6143   _content=new MEDFileField1TSWithoutSDA;
6144 }
6145
6146 /*!
6147  * Returns a new MEDCouplingFieldDouble of a given type lying on
6148  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6149  * has not been constructed via file reading, an exception is thrown.
6150  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6151  *  \param [in] type - a spatial discretization of interest.
6152  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6153  *  \param [in] renumPol - specifies how to permute values of the result field according to
6154  *          the optional numbers of cells and nodes, if any. The valid values are
6155  *          - 0 - do not permute.
6156  *          - 1 - permute cells.
6157  *          - 2 - permute nodes.
6158  *          - 3 - permute cells and nodes.
6159  *
6160  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6161  *          caller is to delete this field using decrRef() as it is no more needed. 
6162  *  \throw If \a this field has not been constructed via file reading.
6163  *  \throw If the MED file is not readable.
6164  *  \throw If there is no mesh in the MED file.
6165  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6166  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6167  *  \sa getFieldOnMeshAtLevel()
6168  */
6169 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6170 {
6171   if(getFileName().empty())
6172     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6173   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6174   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6175   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6176   return ret.retn();
6177 }
6178
6179 /*!
6180  * Returns a new MEDCouplingFieldDouble of a given type lying on
6181  * the top level cells of the first mesh in MED file. If \a this field 
6182  * has not been constructed via file reading, an exception is thrown.
6183  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6184  *  \param [in] type - a spatial discretization of interest.
6185  *  \param [in] renumPol - specifies how to permute values of the result field according to
6186  *          the optional numbers of cells and nodes, if any. The valid values are
6187  *          - 0 - do not permute.
6188  *          - 1 - permute cells.
6189  *          - 2 - permute nodes.
6190  *          - 3 - permute cells and nodes.
6191  *
6192  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6193  *          caller is to delete this field using decrRef() as it is no more needed. 
6194  *  \throw If \a this field has not been constructed via file reading.
6195  *  \throw If the MED file is not readable.
6196  *  \throw If there is no mesh in the MED file.
6197  *  \throw If no field values of the given \a type.
6198  *  \throw If no field values lying on the top level support.
6199  *  \sa getFieldAtLevel()
6200  */
6201 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6202 {
6203   if(getFileName().empty())
6204     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6205   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6206   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6207   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6208   return ret.retn();
6209 }
6210
6211 /*!
6212  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6213  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6214  *  \param [in] type - a spatial discretization of the new field.
6215  *  \param [in] mesh - the supporting mesh.
6216  *  \param [in] renumPol - specifies how to permute values of the result field according to
6217  *          the optional numbers of cells and nodes, if any. The valid values are
6218  *          - 0 - do not permute.
6219  *          - 1 - permute cells.
6220  *          - 2 - permute nodes.
6221  *          - 3 - permute cells and nodes.
6222  *
6223  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6224  *          caller is to delete this field using decrRef() as it is no more needed. 
6225  *  \throw If no field of \a this is lying on \a mesh.
6226  *  \throw If the mesh is empty.
6227  *  \throw If no field values of the given \a type are available.
6228  *  \sa getFieldAtLevel()
6229  *  \sa getFieldOnMeshAtLevel() 
6230  */
6231 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6232 {
6233   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6234   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6235   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6236   return ret.retn();
6237 }
6238
6239 /*!
6240  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6241  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6242  *  \param [in] type - a spatial discretization of interest.
6243  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6244  *  \param [in] mesh - the supporting mesh.
6245  *  \param [in] renumPol - specifies how to permute values of the result field according to
6246  *          the optional numbers of cells and nodes, if any. The valid values are
6247  *          - 0 - do not permute.
6248  *          - 1 - permute cells.
6249  *          - 2 - permute nodes.
6250  *          - 3 - permute cells and nodes.
6251  *
6252  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6253  *          caller is to delete this field using decrRef() as it is no more needed. 
6254  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6255  *  \throw If no field of \a this is lying on \a mesh.
6256  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6257  *  \sa getFieldAtLevel()
6258  *  \sa getFieldOnMeshAtLevel() 
6259  */
6260 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6261 {
6262   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6263   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6264   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6265   return ret.retn();
6266 }
6267
6268 /*!
6269  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6270  * This method is called "Old" because in MED3 norm a field has only one meshName
6271  * attached, so this method is for readers of MED2 files. If \a this field 
6272  * has not been constructed via file reading, an exception is thrown.
6273  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6274  *  \param [in] type - a spatial discretization of interest.
6275  *  \param [in] mName - a name of the supporting mesh.
6276  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6277  *  \param [in] renumPol - specifies how to permute values of the result field according to
6278  *          the optional numbers of cells and nodes, if any. The valid values are
6279  *          - 0 - do not permute.
6280  *          - 1 - permute cells.
6281  *          - 2 - permute nodes.
6282  *          - 3 - permute cells and nodes.
6283  *
6284  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6285  *          caller is to delete this field using decrRef() as it is no more needed. 
6286  *  \throw If the MED file is not readable.
6287  *  \throw If there is no mesh named \a mName in the MED file.
6288  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6289  *  \throw If \a this field has not been constructed via file reading.
6290  *  \throw If no field of \a this is lying on the mesh named \a mName.
6291  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6292  *  \sa getFieldAtLevel()
6293  */
6294 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6295 {
6296   if(getFileName().empty())
6297     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6298   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6299   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6300   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6301   return ret.retn();
6302 }
6303
6304 /*!
6305  * Returns values and a profile of the field of a given type lying on a given support.
6306  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6307  *  \param [in] type - a spatial discretization of the field.
6308  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6309  *  \param [in] mesh - the supporting mesh.
6310  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6311  *          field of interest lies on. If the field lies on all entities of the given
6312  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6313  *          using decrRef() as it is no more needed.  
6314  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6315  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6316  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6317  *  \throw If no field of \a this is lying on \a mesh.
6318  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6319  */
6320 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6321 {
6322   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6323   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6324 }
6325
6326 /*!
6327  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6328  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6329  * "Sort By Type"), if not, an exception is thrown. 
6330  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6331  *  \param [in] field - the field to add to \a this.
6332  *  \throw If the name of \a field is empty.
6333  *  \throw If the data array of \a field is not set.
6334  *  \throw If the data array is already allocated but has different number of components
6335  *         than \a field.
6336  *  \throw If the underlying mesh of \a field has no name.
6337  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6338  */
6339 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6340 {
6341   setFileName("");
6342   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6343 }
6344
6345 /*!
6346  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6347  * can be an aggregation of several MEDCouplingFieldDouble instances.
6348  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6349  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6350  * and \a profile.
6351  *
6352  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6353  * A new profile is added only if no equal profile is missing.
6354  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6355  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6356  *  \param [in] mesh - the supporting mesh of \a field.
6357  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6358  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6359  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6360  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6361  *  \throw If the data array of \a field is not set.
6362  *  \throw If the data array of \a this is already allocated but has different number of
6363  *         components than \a field.
6364  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6365  *  \sa setFieldNoProfileSBT()
6366  */
6367 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6368 {
6369   setFileName("");
6370   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6371 }
6372
6373 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6374 {
6375   return new MEDFileField1TS(*this);
6376 }
6377
6378 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6379 {
6380   return contentNotNull()->getUndergroundDataArrayDouble();
6381 }
6382
6383 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6384 {
6385   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6386 }
6387
6388 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6389                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6390 {
6391   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6392 }
6393
6394 //= MEDFileIntField1TS
6395
6396 MEDFileIntField1TS *MEDFileIntField1TS::New()
6397 {
6398   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6399   ret->contentNotNull();
6400   return ret.retn();
6401 }
6402
6403 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6404 {
6405   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6406   ret->contentNotNull();
6407   return ret.retn();
6408 }
6409
6410 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6411 {
6412   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6413   ret->contentNotNull();
6414   return ret.retn();
6415 }
6416
6417 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6418 {
6419   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6420   ret->contentNotNull();
6421   return ret.retn();
6422 }
6423
6424 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6425 {
6426   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6427   ret->contentNotNull();
6428   return ret.retn();
6429 }
6430
6431 MEDFileIntField1TS::MEDFileIntField1TS()
6432 {
6433   _content=new MEDFileIntField1TSWithoutSDA;
6434 }
6435
6436 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6437 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6438 {
6439 }
6440 catch(INTERP_KERNEL::Exception& e)
6441 { throw e; }
6442
6443 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6444 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6445 {
6446 }
6447 catch(INTERP_KERNEL::Exception& e)
6448 { throw e; }
6449
6450 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6451 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6452 {
6453 }
6454 catch(INTERP_KERNEL::Exception& e)
6455 { throw e; }
6456
6457 /*!
6458  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6459  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6460  *
6461  * \warning this is a shallow copy constructor
6462  */
6463 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6464 {
6465 }
6466
6467 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6468 {
6469   return new MEDFileIntField1TS(*this);
6470 }
6471
6472 /*!
6473  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6474  * following the given input policy.
6475  *
6476  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6477  *                            By default (true) the globals are deeply copied.
6478  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6479  */
6480 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6481 {
6482   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6483   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6484   if(content)
6485     {
6486       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6487       if(!contc)
6488         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6489       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6490       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6491     }
6492   else
6493     ret=MEDFileField1TS::New();
6494   if(isDeepCpyGlobs)
6495     ret->deepCpyGlobs(*this);
6496   else
6497     ret->shallowCpyGlobs(*this);
6498   return ret.retn();
6499 }
6500
6501 /*!
6502  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6503  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6504  * "Sort By Type"), if not, an exception is thrown. 
6505  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6506  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6507  *  \param [in] arrOfVals - the values of the field \a field used.
6508  *  \throw If the name of \a field is empty.
6509  *  \throw If the data array of \a field is not set.
6510  *  \throw If the data array is already allocated but has different number of components
6511  *         than \a field.
6512  *  \throw If the underlying mesh of \a field has no name.
6513  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6514  */
6515 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6516 {
6517   setFileName("");
6518   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6519 }
6520
6521 /*!
6522  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6523  * can be an aggregation of several MEDCouplingFieldDouble instances.
6524  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6525  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6526  * and \a profile.
6527  *
6528  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6529  * A new profile is added only if no equal profile is missing.
6530  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6531  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6532  *  \param [in] arrOfVals - the values of the field \a field used.
6533  *  \param [in] mesh - the supporting mesh of \a field.
6534  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6535  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6536  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6537  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6538  *  \throw If the data array of \a field is not set.
6539  *  \throw If the data array of \a this is already allocated but has different number of
6540  *         components than \a field.
6541  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6542  *  \sa setFieldNoProfileSBT()
6543  */
6544 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6545 {
6546   setFileName("");
6547   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6548 }
6549
6550 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6551 {
6552   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6553   if(!pt)
6554     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6555   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6556   if(!ret)
6557     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 !");
6558   return ret;
6559 }
6560
6561 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6562 {
6563   if(getFileName().empty())
6564     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6565   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6566   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6567   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6568   if(!arrOutC)
6569     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6570   arrOut=arrOutC;
6571   return ret.retn();
6572 }
6573
6574 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6575 {
6576   if(!((DataArray *)arr))
6577     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6578   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6579   if(!arrC)
6580     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6581   arrC->incrRef();
6582   return arrC;
6583 }
6584
6585 /*!
6586  * Returns a new MEDCouplingFieldDouble of a given type lying on
6587  * the top level cells of the first mesh in MED file. If \a this field 
6588  * has not been constructed via file reading, an exception is thrown.
6589  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6590  *  \param [in] type - a spatial discretization of interest.
6591  *  \param [out] arrOut - the DataArrayInt containing values of field.
6592  *  \param [in] renumPol - specifies how to permute values of the result field according to
6593  *          the optional numbers of cells and nodes, if any. The valid values are
6594  *          - 0 - do not permute.
6595  *          - 1 - permute cells.
6596  *          - 2 - permute nodes.
6597  *          - 3 - permute cells and nodes.
6598  *
6599  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6600  *          caller is to delete this field using decrRef() as it is no more needed. 
6601  *  \throw If \a this field has not been constructed via file reading.
6602  *  \throw If the MED file is not readable.
6603  *  \throw If there is no mesh in the MED file.
6604  *  \throw If no field values of the given \a type.
6605  *  \throw If no field values lying on the top level support.
6606  *  \sa getFieldAtLevel()
6607  */
6608 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6609 {
6610   if(getFileName().empty())
6611     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6612   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6613   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6614   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6615   return ret.retn();
6616 }
6617
6618 /*!
6619  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6620  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6621  *  \param [in] type - a spatial discretization of the new field.
6622  *  \param [in] mesh - the supporting mesh.
6623  *  \param [out] arrOut - the DataArrayInt containing values of field.
6624  *  \param [in] renumPol - specifies how to permute values of the result field according to
6625  *          the optional numbers of cells and nodes, if any. The valid values are
6626  *          - 0 - do not permute.
6627  *          - 1 - permute cells.
6628  *          - 2 - permute nodes.
6629  *          - 3 - permute cells and nodes.
6630  *
6631  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6632  *          caller is to delete this field using decrRef() as it is no more needed. 
6633  *  \throw If no field of \a this is lying on \a mesh.
6634  *  \throw If the mesh is empty.
6635  *  \throw If no field values of the given \a type are available.
6636  *  \sa getFieldAtLevel()
6637  *  \sa getFieldOnMeshAtLevel() 
6638  */
6639 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6640 {
6641   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6642   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6643   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6644   return ret.retn();
6645 }
6646
6647 /*!
6648  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6649  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6650  *  \param [in] type - a spatial discretization of interest.
6651  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6652  *  \param [out] arrOut - the DataArrayInt containing values of field.
6653  *  \param [in] mesh - the supporting mesh.
6654  *  \param [in] renumPol - specifies how to permute values of the result field according to
6655  *          the optional numbers of cells and nodes, if any. The valid values are
6656  *          - 0 - do not permute.
6657  *          - 1 - permute cells.
6658  *          - 2 - permute nodes.
6659  *          - 3 - permute cells and nodes.
6660  *
6661  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6662  *          caller is to delete this field using decrRef() as it is no more needed. 
6663  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6664  *  \throw If no field of \a this is lying on \a mesh.
6665  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6666  *  \sa getFieldAtLevel()
6667  *  \sa getFieldOnMeshAtLevel() 
6668  */
6669 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6670 {
6671   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6672   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6673   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6674   return ret.retn();
6675 }
6676
6677 /*!
6678  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6679  * This method is called "Old" because in MED3 norm a field has only one meshName
6680  * attached, so this method is for readers of MED2 files. If \a this field 
6681  * has not been constructed via file reading, an exception is thrown.
6682  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6683  *  \param [in] type - a spatial discretization of interest.
6684  *  \param [in] mName - a name of the supporting mesh.
6685  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6686  *  \param [out] arrOut - the DataArrayInt containing values of field.
6687  *  \param [in] renumPol - specifies how to permute values of the result field according to
6688  *          the optional numbers of cells and nodes, if any. The valid values are
6689  *          - 0 - do not permute.
6690  *          - 1 - permute cells.
6691  *          - 2 - permute nodes.
6692  *          - 3 - permute cells and nodes.
6693  *
6694  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6695  *          caller is to delete this field using decrRef() as it is no more needed. 
6696  *  \throw If the MED file is not readable.
6697  *  \throw If there is no mesh named \a mName in the MED file.
6698  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6699  *  \throw If \a this field has not been constructed via file reading.
6700  *  \throw If no field of \a this is lying on the mesh named \a mName.
6701  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6702  *  \sa getFieldAtLevel()
6703  */
6704 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6705 {
6706   if(getFileName().empty())
6707     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6708   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6709   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6710   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6711   return ret.retn();
6712 }
6713
6714 /*!
6715  * Returns values and a profile of the field of a given type lying on a given support.
6716  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6717  *  \param [in] type - a spatial discretization of the field.
6718  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6719  *  \param [in] mesh - the supporting mesh.
6720  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6721  *          field of interest lies on. If the field lies on all entities of the given
6722  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6723  *          using decrRef() as it is no more needed.  
6724  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6725  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6726  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6727  *  \throw If no field of \a this is lying on \a mesh.
6728  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6729  */
6730 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6731 {
6732   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6733   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6734 }
6735
6736 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
6737 {
6738   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6739   if(!pt)
6740     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6741   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6742   if(!ret)
6743     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 !");
6744   return ret;
6745 }
6746
6747 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
6748 {
6749   return contentNotNull()->getUndergroundDataArrayInt();
6750 }
6751
6752 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6753
6754 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6755 {
6756 }
6757
6758 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
6759 {
6760 }
6761
6762 /*!
6763  * \param [in] fieldId field id in C mode
6764  */
6765 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
6766 {
6767   med_field_type typcha;
6768   std::string dtunitOut;
6769   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6770   setDtUnit(dtunitOut.c_str());
6771   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms);
6772 }
6773
6774 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)
6775 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6776 {
6777   setDtUnit(dtunit.c_str());
6778   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms);
6779 }
6780 catch(INTERP_KERNEL::Exception& e)
6781 {
6782     throw e;
6783 }
6784
6785 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
6786 {
6787   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>));
6788   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6789     ret+=(*it).capacity();
6790   return ret;
6791 }
6792
6793 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
6794 {
6795   std::vector<const BigMemoryObject *> ret;
6796   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6797     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
6798   return ret;
6799 }
6800
6801 /*!
6802  * 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
6803  * NULL.
6804  */
6805 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
6806 {
6807   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6808   ret->setInfo(_infos);
6809   int sz=(int)_time_steps.size();
6810   for(const int *id=startIds;id!=endIds;id++)
6811     {
6812       if(*id>=0 && *id<sz)
6813         {
6814           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6815           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6816           if(tse)
6817             {
6818               tse->incrRef();
6819               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6820             }
6821           ret->pushBackTimeStep(tse2);
6822         }
6823       else
6824         {
6825           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6826           oss << " ! Should be in [0," << sz << ") !";
6827           throw INTERP_KERNEL::Exception(oss.str().c_str());
6828         }
6829     }
6830   if(ret->getNumberOfTS()>0)
6831     ret->synchronizeNameScope();
6832   ret->copyNameScope(*this);
6833   return ret.retn();
6834 }
6835
6836 /*!
6837  * 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
6838  * NULL.
6839  */
6840 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
6841 {
6842   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6843   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6844   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6845   ret->setInfo(_infos);
6846   int sz=(int)_time_steps.size();
6847   int j=bg;
6848   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
6849     {
6850       if(j>=0 && j<sz)
6851         {
6852           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
6853           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6854           if(tse)
6855             {
6856               tse->incrRef();
6857               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6858             }
6859           ret->pushBackTimeStep(tse2);
6860         }
6861       else
6862         {
6863           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
6864           oss << " ! Should be in [0," << sz << ") !";
6865           throw INTERP_KERNEL::Exception(oss.str().c_str());
6866         }
6867     }
6868   if(ret->getNumberOfTS()>0)
6869     ret->synchronizeNameScope();
6870   ret->copyNameScope(*this);
6871   return ret.retn();
6872 }
6873
6874 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6875 {
6876   int id=0;
6877   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6878   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6879     {
6880       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6881       if(!cur)
6882         continue;
6883       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6884       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
6885         ids->pushBackSilent(id);
6886     }
6887   return buildFromTimeStepIds(ids->begin(),ids->end());
6888 }
6889
6890 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6891 {
6892   int id=0;
6893   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6894   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6895     {
6896       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6897       if(!cur)
6898         continue;
6899       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6900       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
6901         ids->pushBackSilent(id);
6902     }
6903   return buildFromTimeStepIds(ids->begin(),ids->end());
6904 }
6905
6906 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
6907 {
6908   return _infos;
6909 }
6910
6911 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
6912 {
6913   _infos=info;
6914 }
6915
6916 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
6917 {
6918   int ret=0;
6919   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6920     {
6921       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
6922       if(pt->isDealingTS(iteration,order))
6923         return ret;
6924     }
6925   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
6926   std::vector< std::pair<int,int> > vp=getIterations();
6927   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
6928     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
6929   throw INTERP_KERNEL::Exception(oss.str().c_str());
6930 }
6931
6932 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
6933 {
6934   return *_time_steps[getTimeStepPos(iteration,order)];
6935 }
6936
6937 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
6938 {
6939   return *_time_steps[getTimeStepPos(iteration,order)];
6940 }
6941
6942 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
6943 {
6944   if(_time_steps.empty())
6945     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
6946   return _time_steps[0]->getMeshName();
6947 }
6948
6949 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
6950 {
6951   std::string oldName(getMeshName());
6952   std::vector< std::pair<std::string,std::string> > v(1);
6953   v[0].first=oldName; v[0].second=newMeshName;
6954   changeMeshNames(v);
6955 }
6956
6957 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6958 {
6959   bool ret=false;
6960   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6961     {
6962       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6963       if(cur)
6964         ret=cur->changeMeshNames(modifTab) || ret;
6965     }
6966   return ret;
6967 }
6968
6969 /*!
6970  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
6971  */
6972 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
6973 {
6974   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
6975 }
6976
6977 /*!
6978  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
6979  */
6980 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6981 {
6982   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
6983 }
6984
6985 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
6986                                                                        MEDFileFieldGlobsReal& glob)
6987 {
6988   bool ret=false;
6989   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6990     {
6991       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
6992       if(f1ts)
6993         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
6994     }
6995   return ret;
6996 }
6997
6998 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
6999 {
7000   std::string startLine(bkOffset,' ');
7001   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7002   if(fmtsId>=0)
7003     oss << " (" << fmtsId << ")";
7004   oss << " has the following name: \"" << _name << "\"." << std::endl;
7005   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7006   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7007     {
7008       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7009     }
7010   int i=0;
7011   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7012     {
7013       std::string chapter(17,'0'+i);
7014       oss << startLine << chapter << std::endl;
7015       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7016       if(cur)
7017         cur->simpleRepr(bkOffset+2,oss,i);
7018       else
7019         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7020       oss << startLine << chapter << std::endl;
7021     }
7022 }
7023
7024 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7025 {
7026   std::size_t sz=_time_steps.size();
7027   std::vector< std::pair<int,int> > ret(sz);
7028   ret1.resize(sz);
7029   for(std::size_t i=0;i<sz;i++)
7030     {
7031       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7032       if(f1ts)
7033         {
7034           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7035         }
7036       else
7037         {
7038           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7039           throw INTERP_KERNEL::Exception(oss.str().c_str());
7040         }
7041     }
7042   return ret;
7043 }
7044
7045 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7046 {
7047   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7048   if(!tse2)
7049     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7050   checkCoherencyOfType(tse2);
7051   if(_time_steps.empty())
7052     {
7053       setName(tse2->getName().c_str());
7054       setInfo(tse2->getInfo());
7055     }
7056   checkThatComponentsMatch(tse2->getInfo());
7057   _time_steps.push_back(tse);
7058 }
7059
7060 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7061 {
7062   std::size_t nbOfCompo=_infos.size();
7063   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7064     {
7065       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7066       if(cur)
7067         {
7068           if((cur->getInfo()).size()!=nbOfCompo)
7069             {
7070               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7071               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7072               throw INTERP_KERNEL::Exception(oss.str().c_str());
7073             }
7074           cur->copyNameScope(*this);
7075         }
7076     }
7077 }
7078
7079 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms)
7080 {
7081   _time_steps.resize(nbPdt);
7082   for(int i=0;i<nbPdt;i++)
7083     {
7084       std::vector< std::pair<int,int> > ts;
7085       med_int numdt=0,numo=0;
7086       med_int meshIt=0,meshOrder=0;
7087       med_float dt=0.0;
7088       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
7089       switch(fieldTyp)
7090       {
7091         case MED_FLOAT64:
7092           {
7093             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7094             break;
7095           }
7096         case MED_INT32:
7097           {
7098             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7099             break;
7100           }
7101         default:
7102           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7103       }
7104       if(loadAll)
7105         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms);
7106       else
7107         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms);
7108     }
7109 }
7110
7111 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7112 {
7113   if(_time_steps.empty())
7114     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7115   checkThatNbOfCompoOfTSMatchThis();
7116   std::vector<std::string> infos(getInfo());
7117   int nbComp=infos.size();
7118   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7119   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7120   for(int i=0;i<nbComp;i++)
7121     {
7122       std::string info=infos[i];
7123       std::string c,u;
7124       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7125       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7126       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7127     }
7128   if(_name.empty())
7129     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7130   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
7131   int nbOfTS=_time_steps.size();
7132   for(int i=0;i<nbOfTS;i++)
7133     _time_steps[i]->writeLL(fid,opts,*this);
7134 }
7135
7136 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7137 {
7138   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7139     {
7140       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7141       if(elt)
7142         elt->loadBigArraysRecursively(fid,nasc);
7143     }
7144 }
7145
7146 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7147 {
7148   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7149     {
7150       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7151       if(elt)
7152         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7153     }
7154 }
7155
7156 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7157 {
7158   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7159     {
7160       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7161       if(elt)
7162         elt->unloadArrays();
7163     }
7164 }
7165
7166 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7167 {
7168   return _time_steps.size();
7169 }
7170
7171 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7172 {
7173   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7174   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7175     {
7176       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7177       if(tmp)
7178         newTS.push_back(*it);
7179     }
7180   _time_steps=newTS;
7181 }
7182
7183 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7184 {
7185   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7186   int maxId=(int)_time_steps.size();
7187   int ii=0;
7188   std::set<int> idsToDel;
7189   for(const int *id=startIds;id!=endIds;id++,ii++)
7190     {
7191       if(*id>=0 && *id<maxId)
7192         {
7193           idsToDel.insert(*id);
7194         }
7195       else
7196         {
7197           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7198           throw INTERP_KERNEL::Exception(oss.str().c_str());
7199         }
7200     }
7201   for(int iii=0;iii<maxId;iii++)
7202     if(idsToDel.find(iii)==idsToDel.end())
7203       newTS.push_back(_time_steps[iii]);
7204   _time_steps=newTS;
7205 }
7206
7207 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7208 {
7209   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7210   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7211   if(nbOfEntriesToKill==0)
7212     return ;
7213   std::size_t sz=_time_steps.size();
7214   std::vector<bool> b(sz,true);
7215   int j=bg;
7216   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7217     b[j]=false;
7218   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7219   for(std::size_t i=0;i<sz;i++)
7220     if(b[i])
7221       newTS.push_back(_time_steps[i]);
7222   _time_steps=newTS;
7223 }
7224
7225 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7226 {
7227   int ret=0;
7228   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7229   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7230     {
7231       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7232       if(tmp)
7233         {
7234           int it2,ord;
7235           tmp->getTime(it2,ord);
7236           if(it2==iteration && order==ord)
7237             return ret;
7238           else
7239             oss << "(" << it2 << ","  << ord << "), ";
7240         }
7241     }
7242   throw INTERP_KERNEL::Exception(oss.str().c_str());
7243 }
7244
7245 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7246 {
7247   int ret=0;
7248   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7249   oss.precision(15);
7250   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7251     {
7252       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7253       if(tmp)
7254         {
7255           int it2,ord;
7256           double ti=tmp->getTime(it2,ord);
7257           if(fabs(time-ti)<eps)
7258             return ret;
7259           else
7260             oss << ti << ", ";
7261         }
7262     }
7263   throw INTERP_KERNEL::Exception(oss.str().c_str());
7264 }
7265
7266 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7267 {
7268   int lgth=_time_steps.size();
7269   std::vector< std::pair<int,int> > ret(lgth);
7270   for(int i=0;i<lgth;i++)
7271     _time_steps[i]->fillIteration(ret[i]);
7272   return ret;
7273 }
7274
7275 /*!
7276  * 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'
7277  * This method returns two things.
7278  * - The absolute dimension of 'this' in first parameter. 
7279  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7280  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7281  *
7282  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7283  * Only these 3 discretizations will be taken into account here.
7284  *
7285  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7286  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7287  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7288  *
7289  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7290  * 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'.
7291  * 
7292  * Let's consider the typical following case :
7293  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7294  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7295  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7296  *   TETRA4 and SEG2
7297  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7298  *
7299  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7300  * 
7301  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7302  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7303  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7304  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7305  */
7306 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7307 {
7308   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7309 }
7310
7311 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7312 {
7313   if(pos<0 || pos>=(int)_time_steps.size())
7314     {
7315       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7316       throw INTERP_KERNEL::Exception(oss.str().c_str());
7317     }
7318   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7319   if(item==0)
7320     {
7321       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7322       oss << "\nTry to use following method eraseEmptyTS !";
7323       throw INTERP_KERNEL::Exception(oss.str().c_str());
7324     }
7325   return item;
7326 }
7327
7328 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7329 {
7330   if(pos<0 || pos>=(int)_time_steps.size())
7331     {
7332       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7333       throw INTERP_KERNEL::Exception(oss.str().c_str());
7334     }
7335   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7336   if(item==0)
7337     {
7338       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7339       oss << "\nTry to use following method eraseEmptyTS !";
7340       throw INTERP_KERNEL::Exception(oss.str().c_str());
7341     }
7342   return item;
7343 }
7344
7345 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7346 {
7347   std::vector<std::string> ret;
7348   std::set<std::string> ret2;
7349   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7350     {
7351       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7352       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7353         if(ret2.find(*it2)==ret2.end())
7354           {
7355             ret.push_back(*it2);
7356             ret2.insert(*it2);
7357           }
7358     }
7359   return ret;
7360 }
7361
7362 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7363 {
7364   std::vector<std::string> ret;
7365   std::set<std::string> ret2;
7366   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7367     {
7368       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7369       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7370         if(ret2.find(*it2)==ret2.end())
7371           {
7372             ret.push_back(*it2);
7373             ret2.insert(*it2);
7374           }
7375     }
7376   return ret;
7377 }
7378
7379 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7380 {
7381   std::vector<std::string> ret;
7382   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7383     {
7384       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7385       ret.insert(ret.end(),tmp.begin(),tmp.end());
7386     }
7387   return ret;
7388 }
7389
7390 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7391 {
7392   std::vector<std::string> ret;
7393   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7394     {
7395       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7396       ret.insert(ret.end(),tmp.begin(),tmp.end());
7397     }
7398   return ret;
7399 }
7400
7401 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7402 {
7403   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7404     (*it)->changePflsRefsNamesGen2(mapOfModif);
7405 }
7406
7407 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7408 {
7409   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7410     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7411 }
7412
7413 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7414 {
7415   int lgth=_time_steps.size();
7416   std::vector< std::vector<TypeOfField> > ret(lgth);
7417   for(int i=0;i<lgth;i++)
7418     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7419   return ret;
7420 }
7421
7422 /*!
7423  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7424  */
7425 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
7426 {
7427   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7428 }
7429
7430 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const
7431 {
7432   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7433   std::size_t i=0;
7434   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7435     {
7436       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7437         ret->_time_steps[i]=(*it)->deepCpy();
7438     }
7439   return ret.retn();
7440 }
7441
7442 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7443 {
7444   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7445   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7446   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7447   for(std::size_t i=0;i<sz;i++)
7448     {
7449       ret[i]=shallowCpy();
7450       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7451     }
7452   for(std::size_t i=0;i<sz2;i++)
7453     {
7454       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7455       if(ret1.size()!=sz)
7456         {
7457           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7458           throw INTERP_KERNEL::Exception(oss.str().c_str());
7459         }
7460       ts[i]=ret1;
7461     }
7462   for(std::size_t i=0;i<sz;i++)
7463     for(std::size_t j=0;j<sz2;j++)
7464       ret[i]->_time_steps[j]=ts[j][i];
7465   return ret;
7466 }
7467
7468 /*!
7469  * This method splits into discretization each time steps in \a this.
7470  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7471  */
7472 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7473 {
7474   std::size_t sz(_time_steps.size());
7475   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7476   for(std::size_t i=0;i<sz;i++)
7477     {
7478       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7479       if(!timeStep)
7480         {
7481           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7482           throw INTERP_KERNEL::Exception(oss.str().c_str());
7483         }
7484       items[i]=timeStep->splitDiscretizations();  
7485     }
7486   //
7487   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7488   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7489   std::vector< TypeOfField > types;
7490   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7491     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7492       {
7493         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7494         if(ts.size()!=1)
7495           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7496         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7497         if(it2==types.end())
7498           types.push_back(ts[0]);
7499       }
7500   ret.resize(types.size()); ret2.resize(types.size());
7501   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7502     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7503       {
7504         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7505         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7506         ret2[pos].push_back(*it1);
7507       }
7508   for(std::size_t i=0;i<types.size();i++)
7509     {
7510       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=createNew();
7511       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7512         elt->pushBackTimeStep(*it1);//also updates infos in elt
7513       ret[i]=elt;
7514       elt->MEDFileFieldNameScope::operator=(*this);
7515     }
7516   return ret;
7517 }
7518
7519 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7520 {
7521   _name=field->getName();
7522   if(_name.empty())
7523     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7524   if(!arr)
7525     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7526   _infos=arr->getInfoOnComponents();
7527 }
7528
7529 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7530 {
7531   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7532   if(_name!=field->getName())
7533     {
7534       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7535       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7536       throw INTERP_KERNEL::Exception(oss.str().c_str());
7537     }
7538   if(!arr)
7539     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7540   checkThatComponentsMatch(arr->getInfoOnComponents());
7541 }
7542
7543 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7544 {
7545   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7546   if(getInfo().size()!=compos.size())
7547     {
7548       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7549       oss << " number of components of element to append (" << compos.size() << ") !";
7550       throw INTERP_KERNEL::Exception(oss.str().c_str());
7551     }
7552   if(_infos!=compos)
7553     {
7554       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7555       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7556       oss << " But compo in input fields are : ";
7557       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7558       oss << " !";
7559       throw INTERP_KERNEL::Exception(oss.str().c_str());
7560     }
7561 }
7562
7563 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7564 {
7565   std::size_t sz=_infos.size();
7566   int j=0;
7567   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7568     {
7569       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7570       if(elt)
7571         if(elt->getInfo().size()!=sz)
7572           {
7573             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7574             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7575             throw INTERP_KERNEL::Exception(oss.str().c_str());
7576           }
7577     }
7578 }
7579
7580 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7581 {
7582   if(!field)
7583     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7584   if(!_time_steps.empty())
7585     checkCoherencyOfTinyInfo(field,arr);
7586   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7587   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7588   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7589   copyTinyInfoFrom(field,arr);
7590   _time_steps.push_back(obj);
7591 }
7592
7593 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7594 {
7595   if(!field)
7596     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7597   if(!_time_steps.empty())
7598     checkCoherencyOfTinyInfo(field,arr);
7599   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7600   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7601   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7602   copyTinyInfoFrom(field,arr);
7603   _time_steps.push_back(obj);
7604 }
7605
7606 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts)
7607 {
7608   int sz=(int)_time_steps.size();
7609   if(i<0 || i>=sz)
7610     {
7611       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7612       throw INTERP_KERNEL::Exception(oss.str().c_str());
7613     }
7614   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7615   if(tsPtr)
7616     {
7617       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7618         {
7619           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7620           throw INTERP_KERNEL::Exception(oss.str().c_str());
7621         }
7622     }
7623   _time_steps[i]=ts;
7624 }
7625
7626 //= MEDFileFieldMultiTSWithoutSDA
7627
7628 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)
7629 {
7630   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms);
7631 }
7632
7633 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7634 {
7635 }
7636
7637 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7638 {
7639 }
7640
7641 /*!
7642  * \param [in] fieldId field id in C mode
7643  */
7644 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
7645 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms)
7646 {
7647 }
7648 catch(INTERP_KERNEL::Exception& e)
7649 { throw e; }
7650
7651 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)
7652 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms)
7653 {
7654 }
7655 catch(INTERP_KERNEL::Exception& e)
7656 { throw e; }
7657
7658 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7659 {
7660   return new MEDFileField1TSWithoutSDA;
7661 }
7662
7663 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7664 {
7665   if(!f1ts)
7666     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7667   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7668   if(!f1tsC)
7669     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7670 }
7671
7672 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7673 {
7674   return MEDFileField1TSWithoutSDA::TYPE_STR;
7675 }
7676
7677 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7678 {
7679   return new MEDFileFieldMultiTSWithoutSDA(*this);
7680 }
7681
7682 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
7683 {
7684   return new MEDFileFieldMultiTSWithoutSDA;
7685 }
7686
7687 /*!
7688  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7689  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7690  */
7691 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
7692 {
7693   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7694   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7695   if(!myF1TSC)
7696     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7697   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7698 }
7699
7700 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
7701 {
7702   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7703   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7704   int i=0;
7705   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7706     {
7707       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7708       if(eltToConv)
7709         {
7710           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7711           if(!eltToConvC)
7712             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7713           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7714           ret->setIteration(i,elt);
7715         }
7716     }
7717   return ret.retn();
7718 }
7719
7720 //= MEDFileAnyTypeFieldMultiTS
7721
7722 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7723 {
7724 }
7725
7726 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
7727 try:MEDFileFieldGlobsReal(fileName)
7728 {
7729   MEDFileUtilities::CheckFileForRead(fileName);
7730   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7731   _content=BuildContentFrom(fid,fileName,loadAll,ms);
7732   loadGlobals(fid);
7733 }
7734 catch(INTERP_KERNEL::Exception& e)
7735 {
7736     throw e;
7737 }
7738
7739 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7740 {
7741   med_field_type typcha;
7742   std::vector<std::string> infos;
7743   std::string dtunit;
7744   int i=-1;
7745   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7746   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7747   switch(typcha)
7748   {
7749     case MED_FLOAT64:
7750       {
7751         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms);
7752         break;
7753       }
7754     case MED_INT32:
7755       {
7756         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms);
7757         break;
7758       }
7759     default:
7760       {
7761         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] !";
7762         throw INTERP_KERNEL::Exception(oss.str().c_str());
7763       }
7764   }
7765   ret->setDtUnit(dtunit.c_str());
7766   return ret.retn();
7767 }
7768
7769 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
7770 {
7771   med_field_type typcha;
7772   //
7773   std::vector<std::string> infos;
7774   std::string dtunit,fieldName;
7775   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
7776   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7777   switch(typcha)
7778   {
7779     case MED_FLOAT64:
7780       {
7781         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms);
7782         break;
7783       }
7784     case MED_INT32:
7785       {
7786         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms);
7787         break;
7788       }
7789     default:
7790       {
7791         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] !";
7792         throw INTERP_KERNEL::Exception(oss.str().c_str());
7793       }
7794   }
7795   ret->setDtUnit(dtunit.c_str());
7796   return ret.retn();
7797 }
7798
7799 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
7800 {
7801   if(!c)
7802     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
7803   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
7804     {
7805       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
7806       ret->setFileName(fileName);
7807       ret->_content=c;  c->incrRef();
7808       return ret.retn();
7809     }
7810   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
7811     {
7812       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
7813       ret->setFileName(fileName);
7814       ret->_content=c;  c->incrRef();
7815       return ret.retn();
7816     }
7817   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
7818 }
7819
7820 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7821 try:MEDFileFieldGlobsReal(fileName)
7822 {
7823   MEDFileUtilities::CheckFileForRead(fileName);
7824   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7825   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
7826   loadGlobals(fid);
7827 }
7828 catch(INTERP_KERNEL::Exception& e)
7829 {
7830     throw e;
7831 }
7832
7833 //= MEDFileIntFieldMultiTSWithoutSDA
7834
7835 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)
7836 {
7837   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms);
7838 }
7839
7840 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
7841 {
7842 }
7843
7844 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7845 {
7846 }
7847
7848 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)
7849 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms)
7850 {
7851 }
7852 catch(INTERP_KERNEL::Exception& e)
7853 { throw e; }
7854
7855 /*!
7856  * \param [in] fieldId field id in C mode
7857  */
7858 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
7859 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms)
7860 {
7861 }
7862 catch(INTERP_KERNEL::Exception& e)
7863 { throw e; }
7864
7865 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7866 {
7867   return new MEDFileIntField1TSWithoutSDA;
7868 }
7869
7870 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7871 {
7872   if(!f1ts)
7873     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7874   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
7875   if(!f1tsC)
7876     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
7877 }
7878
7879 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
7880 {
7881   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
7882 }
7883
7884 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
7885 {
7886   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
7887 }
7888
7889 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
7890 {
7891   return new MEDFileIntFieldMultiTSWithoutSDA;
7892 }
7893
7894 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
7895 {
7896   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
7897   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7898   int i=0;
7899   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7900     {
7901       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7902       if(eltToConv)
7903         {
7904           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
7905           if(!eltToConvC)
7906             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
7907           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
7908           ret->setIteration(i,elt);
7909         }
7910     }
7911   return ret.retn();
7912 }
7913
7914 //= MEDFileAnyTypeFieldMultiTS
7915
7916 /*!
7917  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
7918  * that has been read from a specified MED file.
7919  *  \param [in] fileName - the name of the MED file to read.
7920  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7921  *          is to delete this field using decrRef() as it is no more needed.
7922  *  \throw If reading the file fails.
7923  */
7924 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
7925 {
7926   MEDFileUtilities::CheckFileForRead(fileName);
7927   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7928   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
7929   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7930   ret->loadGlobals(fid);
7931   return ret.retn();
7932 }
7933
7934 /*!
7935  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
7936  * that has been read from a specified MED file.
7937  *  \param [in] fileName - the name of the MED file to read.
7938  *  \param [in] fieldName - the name of the field to read.
7939  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7940  *          is to delete this field using decrRef() as it is no more needed.
7941  *  \throw If reading the file fails.
7942  *  \throw If there is no field named \a fieldName in the file.
7943  */
7944 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
7945 {
7946   MEDFileUtilities::CheckFileForRead(fileName);
7947   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7948   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
7949   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7950   ret->loadGlobals(fid);
7951   return ret.retn();
7952 }
7953
7954 /*!
7955  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7956  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7957  *
7958  * \warning this is a shallow copy constructor
7959  */
7960 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7961 {
7962   if(!shallowCopyOfContent)
7963     {
7964       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
7965       otherPtr->incrRef();
7966       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
7967     }
7968   else
7969     {
7970       _content=other.shallowCpy();
7971     }
7972 }
7973
7974 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
7975 {
7976   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7977   if(!ret)
7978     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
7979   return ret;
7980 }
7981
7982 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
7983 {
7984   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7985   if(!ret)
7986     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
7987   return ret;
7988 }
7989
7990 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
7991 {
7992   return contentNotNullBase()->getPflsReallyUsed2();
7993 }
7994
7995 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
7996 {
7997   return contentNotNullBase()->getLocsReallyUsed2();
7998 }
7999
8000 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8001 {
8002   return contentNotNullBase()->getPflsReallyUsedMulti2();
8003 }
8004
8005 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8006 {
8007   return contentNotNullBase()->getLocsReallyUsedMulti2();
8008 }
8009
8010 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8011 {
8012   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8013 }
8014
8015 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8016 {
8017   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8018 }
8019
8020 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8021 {
8022   return contentNotNullBase()->getNumberOfTS();
8023 }
8024
8025 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8026 {
8027   contentNotNullBase()->eraseEmptyTS();
8028 }
8029
8030 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8031 {
8032   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8033 }
8034
8035 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8036 {
8037   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8038 }
8039
8040 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8041 {
8042   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8043   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8044   ret->_content=c;
8045   return ret.retn();
8046 }
8047
8048 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8049 {
8050   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8051   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8052   ret->_content=c;
8053   return ret.retn();
8054 }
8055
8056 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8057 {
8058   return contentNotNullBase()->getIterations();
8059 }
8060
8061 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8062 {
8063   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8064     pushBackTimeStep(*it);
8065 }
8066
8067 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8068 {
8069   if(!f1ts)
8070     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8071   checkCoherencyOfType(f1ts);
8072   f1ts->incrRef();
8073   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8074   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8075   c->incrRef();
8076   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8077   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8078     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8079   _content->pushBackTimeStep(cSafe);
8080   appendGlobs(*f1ts,1e-12);
8081 }
8082
8083 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8084 {
8085   contentNotNullBase()->synchronizeNameScope();
8086 }
8087
8088 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8089 {
8090   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8091 }
8092
8093 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8094 {
8095   return contentNotNullBase()->getPosGivenTime(time,eps);
8096 }
8097
8098 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8099 {
8100   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8101 }
8102
8103 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8104 {
8105   return contentNotNullBase()->getTypesOfFieldAvailable();
8106 }
8107
8108 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
8109 {
8110   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8111 }
8112
8113 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8114 {
8115   return contentNotNullBase()->getName();
8116 }
8117
8118 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8119 {
8120   contentNotNullBase()->setName(name);
8121 }
8122
8123 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8124 {
8125   return contentNotNullBase()->getDtUnit();
8126 }
8127
8128 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8129 {
8130   contentNotNullBase()->setDtUnit(dtUnit);
8131 }
8132
8133 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8134 {
8135   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8136 }
8137
8138 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8139 {
8140   return contentNotNullBase()->getTimeSteps(ret1);
8141 }
8142
8143 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8144 {
8145   return contentNotNullBase()->getMeshName();
8146 }
8147
8148 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8149 {
8150   contentNotNullBase()->setMeshName(newMeshName);
8151 }
8152
8153 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8154 {
8155   return contentNotNullBase()->changeMeshNames(modifTab);
8156 }
8157
8158 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8159 {
8160   return contentNotNullBase()->getInfo();
8161 }
8162
8163 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8164 {
8165   return contentNotNullBase()->setInfo(info);
8166 }
8167
8168 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8169 {
8170   const std::vector<std::string> ret=getInfo();
8171   return (int)ret.size();
8172 }
8173
8174 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8175 {
8176   writeGlobals(fid,*this);
8177   contentNotNullBase()->writeLL(fid,*this);
8178 }
8179
8180 /*!
8181  * Writes \a this field into a MED file specified by its name.
8182  *  \param [in] fileName - the MED file name.
8183  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8184  * - 2 - erase; an existing file is removed.
8185  * - 1 - append; same data should not be present in an existing file.
8186  * - 0 - overwrite; same data present in an existing file is overwritten.
8187  *  \throw If the field name is not set.
8188  *  \throw If no field data is set.
8189  *  \throw If \a mode == 1 and the same data is present in an existing file.
8190  */
8191 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8192 {
8193   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8194   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8195   writeLL(fid);
8196 }
8197
8198 /*!
8199  * This method alloc the arrays and load potentially huge arrays contained in this field.
8200  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8201  * This method can be also called to refresh or reinit values from a file.
8202  * 
8203  * \throw If the fileName is not set or points to a non readable MED file.
8204  */
8205 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8206 {
8207   if(getFileName().empty())
8208     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8209   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8210   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8211 }
8212
8213 /*!
8214  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8215  * But once data loaded once, this method does nothing.
8216  * 
8217  * \throw If the fileName is not set or points to a non readable MED file.
8218  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8219  */
8220 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8221 {
8222   if(!getFileName().empty())
8223     {
8224       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8225       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8226     }
8227 }
8228
8229 /*!
8230  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8231  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8232  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8233  * 
8234  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8235  */
8236 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8237 {
8238   contentNotNullBase()->unloadArrays();
8239 }
8240
8241 /*!
8242  * 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.
8243  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8244  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8245  * 
8246  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8247  */
8248 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8249 {
8250   if(!getFileName().empty())
8251     contentNotNullBase()->unloadArrays();
8252 }
8253
8254 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8255 {
8256   std::ostringstream oss;
8257   contentNotNullBase()->simpleRepr(0,oss,-1);
8258   simpleReprGlobs(oss);
8259   return oss.str();
8260 }
8261
8262 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8263 {
8264   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8265 }
8266
8267 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8268 {
8269   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8270   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8271   return ret;
8272 }
8273
8274 /*!
8275  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8276  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8277  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8278  */
8279 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8280 {
8281   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8282   if(!content)
8283     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8284   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8285   std::size_t sz(contentsSplit.size());
8286   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8287   for(std::size_t i=0;i<sz;i++)
8288     {
8289       ret[i]=shallowCpy();
8290       ret[i]->_content=contentsSplit[i];
8291     }
8292   return ret;
8293 }
8294
8295 /*!
8296  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8297  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8298  */
8299 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8300 {
8301   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8302   if(!content)
8303     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8304   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitDiscretizations();
8305   std::size_t sz(contentsSplit.size());
8306   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8307   for(std::size_t i=0;i<sz;i++)
8308     {
8309       ret[i]=shallowCpy();
8310       ret[i]->_content=contentsSplit[i];
8311     }
8312   return ret;
8313 }
8314
8315 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const
8316 {
8317   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8318   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8319     ret->_content=_content->deepCpy();
8320   ret->deepCpyGlobs(*this);
8321   return ret.retn();
8322 }
8323
8324 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8325 {
8326   return _content;
8327 }
8328
8329 /*!
8330  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8331  *  \param [in] iteration - the iteration number of a required time step.
8332  *  \param [in] order - the iteration order number of required time step.
8333  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8334  *          delete this field using decrRef() as it is no more needed.
8335  *  \throw If there is no required time step in \a this field.
8336  */
8337 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8338 {
8339   int pos=getPosOfTimeStep(iteration,order);
8340   return getTimeStepAtPos(pos);
8341 }
8342
8343 /*!
8344  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8345  *  \param [in] time - the time of the time step of interest.
8346  *  \param [in] eps - a precision used to compare time values.
8347  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8348  *          delete this field using decrRef() as it is no more needed.
8349  *  \throw If there is no required time step in \a this field.
8350  */
8351 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8352 {
8353   int pos=getPosGivenTime(time,eps);
8354   return getTimeStepAtPos(pos);
8355 }
8356
8357 /*!
8358  * 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.
8359  * The float64 value of time attached to the pair of integers are not considered here.
8360  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8361  *
8362  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8363  * \throw If there is a null pointer in \a vectFMTS.
8364  */
8365 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8366 {
8367   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8368   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8369   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8370   while(!lstFMTS.empty())
8371     {
8372       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8373       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8374       if(!curIt)
8375         throw INTERP_KERNEL::Exception(msg);
8376       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8377       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8378       elt.push_back(curIt); it=lstFMTS.erase(it);
8379       while(it!=lstFMTS.end())
8380         {
8381           curIt=*it;
8382           if(!curIt)
8383             throw INTERP_KERNEL::Exception(msg);
8384           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8385           if(refIts==curIts)
8386             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8387           else
8388             it++;
8389         }
8390       ret.push_back(elt);
8391     }
8392   return ret;
8393 }
8394
8395 /*!
8396  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8397  * All returned instances in a subvector can be safely loaded, rendered along time
8398  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8399  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8400  * 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).
8401  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8402  * 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.
8403  *
8404  * \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().
8405  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8406  * \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.
8407  * \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.
8408  *
8409  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8410  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8411  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8412  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8413  * \throw If mesh is null.
8414  * \throw If an element in \a vectFMTS is null.
8415  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8416  */
8417 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& fsc)
8418 {
8419   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8420   if(!mesh)
8421     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8422   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8423   if(vectFMTS.empty())
8424     return ret;
8425   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8426   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8427   if(!frstElt)
8428     throw INTERP_KERNEL::Exception(msg);
8429   std::size_t i=0;
8430   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8431   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8432   for(;it!=vectFMTS.end();it++,i++)
8433     {
8434       if(!(*it))
8435         throw INTERP_KERNEL::Exception(msg);
8436       TypeOfField tof0,tof1;
8437       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8438         {
8439           if(tof1!=ON_NODES)
8440             vectFMTSNotNodes.push_back(*it);
8441           else
8442             vectFMTSNodes.push_back(*it);
8443         }
8444       else
8445         vectFMTSNotNodes.push_back(*it);
8446     }
8447   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8448   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8449   ret=retCell;
8450   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8451     {
8452       i=0;
8453       bool isFetched(false);
8454       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8455         {
8456           if((*it0).empty())
8457             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8458           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8459             { ret[i].push_back(*it2); isFetched=true; }
8460         }
8461       if(!isFetched)
8462         {
8463           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8464           MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8465           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8466         }
8467     }
8468   fsc=cmps;
8469   return ret;
8470 }
8471
8472 /*!
8473  * 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.
8474  * \param [out] cmps - same size than the returned vector.
8475  */
8476 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps)
8477 {
8478   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8479   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8480   while(!lstFMTS.empty())
8481     {
8482       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8483       MEDFileAnyTypeFieldMultiTS *ref(*it);
8484       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8485       elt.push_back(ref); it=lstFMTS.erase(it);
8486       MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8487       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8488       while(it!=lstFMTS.end())
8489         {
8490           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8491           if(cmp->isEqual(curIt))
8492             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8493           else
8494             it++;
8495         }
8496       ret.push_back(elt); cmps.push_back(cmp);
8497     }
8498   return ret;
8499 }
8500
8501 /*!
8502  * 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.
8503  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8504  *
8505  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8506  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8507  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8508  * \thorw If \a f0 and \a f1 do not have the same times steps.
8509  * \throw If mesh is null.
8510  * \throw If \a f0 or \a f1 is null.
8511  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8512  */
8513 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8514 {
8515   if(!mesh)
8516     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8517   if(!f0 || !f1)
8518     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8519   if(f0->getMeshName()!=mesh->getName())
8520     {
8521       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8522       throw INTERP_KERNEL::Exception(oss.str().c_str());
8523     }
8524   if(f1->getMeshName()!=mesh->getName())
8525     {
8526       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8527       throw INTERP_KERNEL::Exception(oss.str().c_str());
8528     }
8529   int nts=f0->getNumberOfTS();
8530   if(nts!=f1->getNumberOfTS())
8531     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8532   if(nts==0)
8533     return nts;
8534   for(int i=0;i<nts;i++)
8535     {
8536       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8537       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8538       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8539       if(tofs0.size()!=1 || tofs1.size()!=1)
8540         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8541       if(i!=0)
8542         {
8543           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8544             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8545         }
8546       else
8547         { tof0=tofs0[0]; tof1=tofs1[0]; }
8548       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8549         {
8550           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() << ") !";
8551           throw INTERP_KERNEL::Exception(oss.str().c_str());
8552         }
8553       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8554         {
8555           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() << ") !";
8556           throw INTERP_KERNEL::Exception(oss.str().c_str());
8557         }
8558       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8559         {
8560           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() << ") !";
8561           throw INTERP_KERNEL::Exception(oss.str().c_str());
8562         }
8563     }
8564   return nts;
8565 }
8566
8567 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8568 {
8569   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8570 }
8571
8572 //= MEDFileFieldMultiTS
8573
8574 /*!
8575  * Returns a new empty instance of MEDFileFieldMultiTS.
8576  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8577  *          is to delete this field using decrRef() as it is no more needed.
8578  */
8579 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8580 {
8581   return new MEDFileFieldMultiTS;
8582 }
8583
8584 /*!
8585  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8586  * that has been read from a specified MED file.
8587  *  \param [in] fileName - the name of the MED file to read.
8588  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8589  *          is to delete this field using decrRef() as it is no more needed.
8590  *  \throw If reading the file fails.
8591  */
8592 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8593 {
8594   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
8595   ret->contentNotNull();//to check that content type matches with \a this type.
8596   return ret.retn();
8597 }
8598
8599 /*!
8600  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8601  * that has been read from a specified MED file.
8602  *  \param [in] fileName - the name of the MED file to read.
8603  *  \param [in] fieldName - the name of the field to read.
8604  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8605  *          is to delete this field using decrRef() as it is no more needed.
8606  *  \throw If reading the file fails.
8607  *  \throw If there is no field named \a fieldName in the file.
8608  */
8609 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8610 {
8611   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
8612   ret->contentNotNull();//to check that content type matches with \a this type.
8613   return ret.retn();
8614 }
8615
8616 /*!
8617  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8618  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8619  *
8620  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8621  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8622  * \warning this is a shallow copy constructor
8623  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8624  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8625  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8626  *          is to delete this field using decrRef() as it is no more needed.
8627  */
8628 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8629 {
8630   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8631 }
8632
8633 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8634 {
8635   return new MEDFileFieldMultiTS(*this);
8636 }
8637
8638 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
8639 {
8640   if(!f1ts)
8641     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8642   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8643   if(!f1tsC)
8644     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8645 }
8646
8647 /*!
8648  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8649  * following the given input policy.
8650  *
8651  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8652  *                            By default (true) the globals are deeply copied.
8653  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8654  */
8655 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
8656 {
8657   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
8658   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8659   if(content)
8660     {
8661       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8662       if(!contc)
8663         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8664       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8665       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
8666     }
8667   else
8668     ret=MEDFileIntFieldMultiTS::New();
8669   if(isDeepCpyGlobs)
8670     ret->deepCpyGlobs(*this);
8671   else
8672     ret->shallowCpyGlobs(*this);
8673   return ret.retn();
8674 }
8675
8676 /*!
8677  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
8678  *  \param [in] pos - a time step id.
8679  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8680  *          delete this field using decrRef() as it is no more needed.
8681  *  \throw If \a pos is not a valid time step id.
8682  */
8683 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
8684 {
8685   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8686   if(!item)
8687     {
8688       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8689       throw INTERP_KERNEL::Exception(oss.str().c_str());
8690     }
8691   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
8692   if(itemC)
8693     {
8694       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
8695       ret->shallowCpyGlobs(*this);
8696       return ret.retn();
8697     }
8698   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
8699   throw INTERP_KERNEL::Exception(oss.str().c_str());
8700 }
8701
8702 /*!
8703  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8704  * mesh entities of a given dimension of the first mesh in MED file.
8705  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8706  *  \param [in] type - a spatial discretization of interest.
8707  *  \param [in] iteration - the iteration number of a required time step.
8708  *  \param [in] order - the iteration order number of required time step.
8709  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8710  *  \param [in] renumPol - specifies how to permute values of the result field according to
8711  *          the optional numbers of cells and nodes, if any. The valid values are
8712  *          - 0 - do not permute.
8713  *          - 1 - permute cells.
8714  *          - 2 - permute nodes.
8715  *          - 3 - permute cells and nodes.
8716  *
8717  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8718  *          caller is to delete this field using decrRef() as it is no more needed. 
8719  *  \throw If the MED file is not readable.
8720  *  \throw If there is no mesh in the MED file.
8721  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8722  *  \throw If no field values of the required parameters are available.
8723  */
8724 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
8725 {
8726   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8727   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8728   if(!myF1TSC)
8729     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
8730   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8731   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8732   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8733   return ret.retn();
8734 }
8735
8736 /*!
8737  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8738  * the top level cells of the first mesh in MED file.
8739  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8740  *  \param [in] type - a spatial discretization of interest.
8741  *  \param [in] iteration - the iteration number of a required time step.
8742  *  \param [in] order - the iteration order number of required time step.
8743  *  \param [in] renumPol - specifies how to permute values of the result field according to
8744  *          the optional numbers of cells and nodes, if any. The valid values are
8745  *          - 0 - do not permute.
8746  *          - 1 - permute cells.
8747  *          - 2 - permute nodes.
8748  *          - 3 - permute cells and nodes.
8749  *
8750  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8751  *          caller is to delete this field using decrRef() as it is no more needed. 
8752  *  \throw If the MED file is not readable.
8753  *  \throw If there is no mesh in the MED file.
8754  *  \throw If no field values of the required parameters are available.
8755  */
8756 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
8757 {
8758   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8759   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8760   if(!myF1TSC)
8761     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
8762   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8763   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8764   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8765   return ret.retn();
8766 }
8767
8768 /*!
8769  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8770  * a given support.
8771  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8772  *  \param [in] type - a spatial discretization of interest.
8773  *  \param [in] iteration - the iteration number of a required time step.
8774  *  \param [in] order - the iteration order number of required time step.
8775  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8776  *  \param [in] mesh - the supporting mesh.
8777  *  \param [in] renumPol - specifies how to permute values of the result field according to
8778  *          the optional numbers of cells and nodes, if any. The valid values are
8779  *          - 0 - do not permute.
8780  *          - 1 - permute cells.
8781  *          - 2 - permute nodes.
8782  *          - 3 - permute cells and nodes.
8783  *
8784  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8785  *          caller is to delete this field using decrRef() as it is no more needed. 
8786  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8787  *  \throw If no field of \a this is lying on \a mesh.
8788  *  \throw If no field values of the required parameters are available.
8789  */
8790 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
8791 {
8792   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8793   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8794   if(!myF1TSC)
8795     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8796   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8797   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
8798   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8799   return ret.retn();
8800 }
8801
8802 /*!
8803  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8804  * given support. 
8805  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8806  *  \param [in] type - a spatial discretization of the new field.
8807  *  \param [in] iteration - the iteration number of a required time step.
8808  *  \param [in] order - the iteration order number of required time step.
8809  *  \param [in] mesh - the supporting mesh.
8810  *  \param [in] renumPol - specifies how to permute values of the result field according to
8811  *          the optional numbers of cells and nodes, if any. The valid values are
8812  *          - 0 - do not permute.
8813  *          - 1 - permute cells.
8814  *          - 2 - permute nodes.
8815  *          - 3 - permute cells and nodes.
8816  *
8817  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8818  *          caller is to delete this field using decrRef() as it is no more needed. 
8819  *  \throw If no field of \a this is lying on \a mesh.
8820  *  \throw If no field values of the required parameters are available.
8821  */
8822 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
8823 {
8824   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8825   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8826   if(!myF1TSC)
8827     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8828   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8829   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
8830   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8831   return ret.retn();
8832 }
8833
8834 /*!
8835  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
8836  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8837  * This method is useful for MED2 file format when field on different mesh was autorized.
8838  */
8839 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
8840 {
8841   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8842   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8843   if(!myF1TSC)
8844     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
8845   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8846   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
8847   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8848   return ret.retn();
8849 }
8850
8851 /*!
8852  * Returns values and a profile of the field of a given type, of a given time step,
8853  * lying on a given support.
8854  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8855  *  \param [in] type - a spatial discretization of the field.
8856  *  \param [in] iteration - the iteration number of a required time step.
8857  *  \param [in] order - the iteration order number of required time step.
8858  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8859  *  \param [in] mesh - the supporting mesh.
8860  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8861  *          field of interest lies on. If the field lies on all entities of the given
8862  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8863  *          using decrRef() as it is no more needed.  
8864  *  \param [in] glob - the global data storing profiles and localization.
8865  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
8866  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8867  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8868  *  \throw If no field of \a this is lying on \a mesh.
8869  *  \throw If no field values of the required parameters are available.
8870  */
8871 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
8872 {
8873   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8874   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8875   if(!myF1TSC)
8876     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
8877   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8878   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
8879 }
8880
8881 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
8882 {
8883   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8884   if(!pt)
8885     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
8886   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
8887   if(!ret)
8888     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 !");
8889   return ret;
8890 }
8891
8892 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
8893 {
8894   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8895   if(!pt)
8896     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
8897   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
8898   if(!ret)
8899     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 !");
8900   return ret;
8901 }
8902
8903 /*!
8904  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8905  * the given field is checked if its elements are sorted suitable for writing to MED file
8906  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8907  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8908  *  \param [in] field - the field to add to \a this.
8909  *  \throw If the name of \a field is empty.
8910  *  \throw If the data array of \a field is not set.
8911  *  \throw If existing time steps have different name or number of components than \a field.
8912  *  \throw If the underlying mesh of \a field has no name.
8913  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8914  */
8915 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
8916 {
8917   const DataArrayDouble *arr=0;
8918   if(field)
8919     arr=field->getArray();
8920   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
8921 }
8922
8923 /*!
8924  * Adds a MEDCouplingFieldDouble to \a this as another time step.
8925  * The mesh support of input parameter \a field is ignored here, it can be NULL.
8926  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
8927  * and \a profile.
8928  *
8929  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
8930  * A new profile is added only if no equal profile is missing.
8931  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8932  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
8933  *  \param [in] mesh - the supporting mesh of \a field.
8934  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
8935  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8936  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8937  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8938  *  \throw If the data array of \a field is not set.
8939  *  \throw If the data array of \a this is already allocated but has different number of
8940  *         components than \a field.
8941  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8942  *  \sa setFieldNoProfileSBT()
8943  */
8944 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
8945 {
8946   const DataArrayDouble *arr=0;
8947   if(field)
8948     arr=field->getArray();
8949   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
8950 }
8951
8952 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
8953 {
8954   _content=new MEDFileFieldMultiTSWithoutSDA;
8955 }
8956
8957 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8958 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
8959 {
8960 }
8961 catch(INTERP_KERNEL::Exception& e)
8962 { throw e; }
8963
8964 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
8965 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms)
8966 {
8967 }
8968 catch(INTERP_KERNEL::Exception& e)
8969 { throw e; }
8970
8971 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8972 {
8973 }
8974
8975 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
8976 {
8977   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
8978 }
8979
8980 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
8981 {
8982   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8983 }
8984
8985 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
8986 {
8987   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
8988 }
8989
8990 //= MEDFileAnyTypeFieldMultiTSIterator
8991
8992 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
8993 {
8994   if(fmts)
8995     {
8996       fmts->incrRef();
8997       _nb_iter=fmts->getNumberOfTS();
8998     }
8999 }
9000
9001 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9002 {
9003 }
9004
9005 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9006 {
9007   if(_iter_id<_nb_iter)
9008     {
9009       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9010       if(fmts)
9011         return fmts->getTimeStepAtPos(_iter_id++);
9012       else
9013         return 0;
9014     }
9015   else
9016     return 0;
9017 }
9018
9019 //= MEDFileIntFieldMultiTS
9020
9021 /*!
9022  * Returns a new empty instance of MEDFileFieldMultiTS.
9023  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9024  *          is to delete this field using decrRef() as it is no more needed.
9025  */
9026 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9027 {
9028   return new MEDFileIntFieldMultiTS;
9029 }
9030
9031 /*!
9032  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9033  * that has been read from a specified MED file.
9034  *  \param [in] fileName - the name of the MED file to read.
9035  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9036  *          is to delete this field using decrRef() as it is no more needed.
9037  *  \throw If reading the file fails.
9038  */
9039 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9040 {
9041   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9042   ret->contentNotNull();//to check that content type matches with \a this type.
9043   return ret.retn();
9044 }
9045
9046 /*!
9047  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9048  * that has been read from a specified MED file.
9049  *  \param [in] fileName - the name of the MED file to read.
9050  *  \param [in] fieldName - the name of the field to read.
9051  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9052  *          is to delete this field using decrRef() as it is no more needed.
9053  *  \throw If reading the file fails.
9054  *  \throw If there is no field named \a fieldName in the file.
9055  */
9056 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9057 {
9058   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9059   ret->contentNotNull();//to check that content type matches with \a this type.
9060   return ret.retn();
9061 }
9062
9063 /*!
9064  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9065  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9066  *
9067  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9068  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9069  * \warning this is a shallow copy constructor
9070  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9071  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9072  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9073  *          is to delete this field using decrRef() as it is no more needed.
9074  */
9075 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9076 {
9077   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9078 }
9079
9080 /*!
9081  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9082  * following the given input policy.
9083  *
9084  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9085  *                            By default (true) the globals are deeply copied.
9086  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9087  */
9088 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9089 {
9090   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
9091   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9092   if(content)
9093     {
9094       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9095       if(!contc)
9096         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9097       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9098       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9099     }
9100   else
9101     ret=MEDFileFieldMultiTS::New();
9102   if(isDeepCpyGlobs)
9103     ret->deepCpyGlobs(*this);
9104   else
9105     ret->shallowCpyGlobs(*this);
9106   return ret.retn();
9107 }
9108
9109 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9110 {
9111   return new MEDFileIntFieldMultiTS(*this);
9112 }
9113
9114 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9115 {
9116   if(!f1ts)
9117     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9118   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9119   if(!f1tsC)
9120     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9121 }
9122
9123 /*!
9124  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9125  * mesh entities of a given dimension of the first mesh in MED file.
9126  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9127  *  \param [in] type - a spatial discretization of interest.
9128  *  \param [in] iteration - the iteration number of a required time step.
9129  *  \param [in] order - the iteration order number of required time step.
9130  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9131  *  \param [out] arrOut - the DataArrayInt containing values of field.
9132  *  \param [in] renumPol - specifies how to permute values of the result field according to
9133  *          the optional numbers of cells and nodes, if any. The valid values are
9134  *          - 0 - do not permute.
9135  *          - 1 - permute cells.
9136  *          - 2 - permute nodes.
9137  *          - 3 - permute cells and nodes.
9138  *
9139  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9140  *          caller is to delete this field using decrRef() as it is no more needed. 
9141  *  \throw If the MED file is not readable.
9142  *  \throw If there is no mesh in the MED file.
9143  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9144  *  \throw If no field values of the required parameters are available.
9145  */
9146 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9147 {
9148   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9149   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9150   if(!myF1TSC)
9151     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9152   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9153   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9154   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9155   return ret.retn();
9156 }
9157
9158 /*!
9159  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9160  * the top level cells of the first mesh in MED file.
9161  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9162  *  \param [in] type - a spatial discretization of interest.
9163  *  \param [in] iteration - the iteration number of a required time step.
9164  *  \param [in] order - the iteration order number of required time step.
9165  *  \param [out] arrOut - the DataArrayInt containing values of field.
9166  *  \param [in] renumPol - specifies how to permute values of the result field according to
9167  *          the optional numbers of cells and nodes, if any. The valid values are
9168  *          - 0 - do not permute.
9169  *          - 1 - permute cells.
9170  *          - 2 - permute nodes.
9171  *          - 3 - permute cells and nodes.
9172  *
9173  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9174  *          caller is to delete this field using decrRef() as it is no more needed. 
9175  *  \throw If the MED file is not readable.
9176  *  \throw If there is no mesh in the MED file.
9177  *  \throw If no field values of the required parameters are available.
9178  */
9179 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9180 {
9181   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9182   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9183   if(!myF1TSC)
9184     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9185   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9186   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9187   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9188   return ret.retn();
9189 }
9190
9191 /*!
9192  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9193  * a given support.
9194  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9195  *  \param [in] type - a spatial discretization of interest.
9196  *  \param [in] iteration - the iteration number of a required time step.
9197  *  \param [in] order - the iteration order number of required time step.
9198  *  \param [out] arrOut - the DataArrayInt containing values of field.
9199  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9200  *  \param [in] mesh - the supporting mesh.
9201  *  \param [in] renumPol - specifies how to permute values of the result field according to
9202  *          the optional numbers of cells and nodes, if any. The valid values are
9203  *          - 0 - do not permute.
9204  *          - 1 - permute cells.
9205  *          - 2 - permute nodes.
9206  *          - 3 - permute cells and nodes.
9207  *
9208  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9209  *          caller is to delete this field using decrRef() as it is no more needed. 
9210  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9211  *  \throw If no field of \a this is lying on \a mesh.
9212  *  \throw If no field values of the required parameters are available.
9213  */
9214 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9215 {
9216   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9217   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9218   if(!myF1TSC)
9219     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9220   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9221   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9222   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9223   return ret.retn();
9224 }
9225
9226 /*!
9227  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9228  * given support. 
9229  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9230  *  \param [in] type - a spatial discretization of the new field.
9231  *  \param [in] iteration - the iteration number of a required time step.
9232  *  \param [in] order - the iteration order number of required time step.
9233  *  \param [in] mesh - the supporting mesh.
9234  *  \param [out] arrOut - the DataArrayInt containing values of field.
9235  *  \param [in] renumPol - specifies how to permute values of the result field according to
9236  *          the optional numbers of cells and nodes, if any. The valid values are
9237  *          - 0 - do not permute.
9238  *          - 1 - permute cells.
9239  *          - 2 - permute nodes.
9240  *          - 3 - permute cells and nodes.
9241  *
9242  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9243  *          caller is to delete this field using decrRef() as it is no more needed. 
9244  *  \throw If no field of \a this is lying on \a mesh.
9245  *  \throw If no field values of the required parameters are available.
9246  */
9247 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9248 {
9249   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9250   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9251   if(!myF1TSC)
9252     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9253   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9254   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9255   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9256   return ret.retn();
9257 }
9258
9259 /*!
9260  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9261  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9262  * This method is useful for MED2 file format when field on different mesh was autorized.
9263  */
9264 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9265 {
9266   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9267   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9268   if(!myF1TSC)
9269     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9270   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9271   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9272   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9273   return ret.retn();
9274 }
9275
9276 /*!
9277  * Returns values and a profile of the field of a given type, of a given time step,
9278  * lying on a given support.
9279  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9280  *  \param [in] type - a spatial discretization of the field.
9281  *  \param [in] iteration - the iteration number of a required time step.
9282  *  \param [in] order - the iteration order number of required time step.
9283  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9284  *  \param [in] mesh - the supporting mesh.
9285  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9286  *          field of interest lies on. If the field lies on all entities of the given
9287  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9288  *          using decrRef() as it is no more needed.  
9289  *  \param [in] glob - the global data storing profiles and localization.
9290  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9291  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9292  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9293  *  \throw If no field of \a this is lying on \a mesh.
9294  *  \throw If no field values of the required parameters are available.
9295  */
9296 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9297 {
9298   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9299   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9300   if(!myF1TSC)
9301     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9302   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9303   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9304 }
9305
9306 /*!
9307  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9308  *  \param [in] pos - a time step id.
9309  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9310  *          delete this field using decrRef() as it is no more needed.
9311  *  \throw If \a pos is not a valid time step id.
9312  */
9313 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9314 {
9315   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9316   if(!item)
9317     {
9318       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9319       throw INTERP_KERNEL::Exception(oss.str().c_str());
9320     }
9321   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9322   if(itemC)
9323     {
9324       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9325       ret->shallowCpyGlobs(*this);
9326       return ret.retn();
9327     }
9328   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9329   throw INTERP_KERNEL::Exception(oss.str().c_str());
9330 }
9331
9332 /*!
9333  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9334  * the given field is checked if its elements are sorted suitable for writing to MED file
9335  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9336  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9337  *  \param [in] field - the field to add to \a this.
9338  *  \throw If the name of \a field is empty.
9339  *  \throw If the data array of \a field is not set.
9340  *  \throw If existing time steps have different name or number of components than \a field.
9341  *  \throw If the underlying mesh of \a field has no name.
9342  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9343  */
9344 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9345 {
9346   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9347 }
9348
9349 /*!
9350  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9351  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9352  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9353  * and \a profile.
9354  *
9355  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9356  * A new profile is added only if no equal profile is missing.
9357  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9358  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9359  *  \param [in] arrOfVals - the values of the field \a field used.
9360  *  \param [in] mesh - the supporting mesh of \a field.
9361  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9362  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9363  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9364  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9365  *  \throw If the data array of \a field is not set.
9366  *  \throw If the data array of \a this is already allocated but has different number of
9367  *         components than \a field.
9368  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9369  *  \sa setFieldNoProfileSBT()
9370  */
9371 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9372 {
9373   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9374 }
9375
9376 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9377 {
9378   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9379   if(!pt)
9380     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9381   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9382   if(!ret)
9383     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 !");
9384   return ret;
9385 }
9386
9387 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9388 {
9389   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9390   if(!pt)
9391     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9392   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9393   if(!ret)
9394     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 !");
9395   return ret;
9396 }
9397
9398 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9399 {
9400   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9401 }
9402
9403 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9404 {
9405 }
9406
9407 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9408 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9409 {
9410 }
9411 catch(INTERP_KERNEL::Exception& e)
9412 { throw e; }
9413
9414 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
9415 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms)
9416 {
9417 }
9418 catch(INTERP_KERNEL::Exception& e)
9419 { throw e; }
9420
9421 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9422 {
9423   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9424 }
9425
9426 //= MEDFileFields
9427
9428 MEDFileFields *MEDFileFields::New()
9429 {
9430   return new MEDFileFields;
9431 }
9432
9433 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9434 {
9435   return new MEDFileFields(fileName,loadAll,0);
9436 }
9437
9438 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9439 {
9440   return new MEDFileFields(fileName,loadAll,ms);
9441 }
9442
9443 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9444 {
9445   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9446   ret+=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9447   return ret;
9448 }
9449
9450 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9451 {
9452   std::vector<const BigMemoryObject *> ret;
9453   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9454     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9455   return ret;
9456 }
9457
9458 MEDFileFields *MEDFileFields::deepCpy() const
9459 {
9460   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9461   std::size_t i=0;
9462   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9463     {
9464       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9465         ret->_fields[i]=(*it)->deepCpy();
9466     }
9467   ret->deepCpyGlobs(*this);
9468   return ret.retn();
9469 }
9470
9471 MEDFileFields *MEDFileFields::shallowCpy() const
9472 {
9473   return new MEDFileFields(*this);
9474 }
9475
9476 /*!
9477  * 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
9478  * 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.
9479  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9480  *
9481  * \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.
9482  * \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.
9483  * 
9484  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9485  */
9486 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9487 {
9488   std::set< std::pair<int,int> > s;
9489   bool firstShot=true;
9490   areThereSomeForgottenTS=false;
9491   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9492     {
9493       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9494         continue;
9495       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9496       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9497       if(firstShot)
9498         { s=s1; firstShot=false; }
9499       else
9500         {
9501           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9502           if(s!=s2)
9503             areThereSomeForgottenTS=true;
9504           s=s2;
9505         }
9506     }
9507   std::vector< std::pair<int,int> > ret;
9508   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9509   return ret;
9510 }
9511
9512 int MEDFileFields::getNumberOfFields() const
9513 {
9514   return _fields.size();
9515 }
9516
9517 std::vector<std::string> MEDFileFields::getFieldsNames() const
9518 {
9519   std::vector<std::string> ret(_fields.size());
9520   int i=0;
9521   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9522     {
9523       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9524       if(f)
9525         {
9526           ret[i]=f->getName();
9527         }
9528       else
9529         {
9530           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9531           throw INTERP_KERNEL::Exception(oss.str().c_str());
9532         }
9533     }
9534   return ret;
9535 }
9536
9537 std::vector<std::string> MEDFileFields::getMeshesNames() const
9538 {
9539   std::vector<std::string> ret;
9540   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9541     {
9542       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9543       if(cur)
9544         ret.push_back(cur->getMeshName());
9545     }
9546   return ret;
9547 }
9548
9549 std::string MEDFileFields::simpleRepr() const
9550 {
9551   std::ostringstream oss;
9552   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9553   simpleRepr(0,oss);
9554   return oss.str();
9555 }
9556
9557 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9558 {
9559   int nbOfFields=getNumberOfFields();
9560   std::string startLine(bkOffset,' ');
9561   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9562   int i=0;
9563   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9564     {
9565       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9566       if(cur)
9567         {
9568           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9569         }
9570       else
9571         {
9572           oss << startLine << "  - not defined !" << std::endl;
9573         }
9574     }
9575   i=0;
9576   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9577     {
9578       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9579       std::string chapter(17,'0'+i);
9580       oss << startLine << chapter << std::endl;
9581       if(cur)
9582         {
9583           cur->simpleRepr(bkOffset+2,oss,i);
9584         }
9585       else
9586         {
9587           oss << startLine << "  - not defined !" << std::endl;
9588         }
9589       oss << startLine << chapter << std::endl;
9590     }
9591   simpleReprGlobs(oss);
9592 }
9593
9594 MEDFileFields::MEDFileFields()
9595 {
9596 }
9597
9598 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9599 try:MEDFileFieldGlobsReal(fileName)
9600 {
9601   MEDFileUtilities::CheckFileForRead(fileName);
9602   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
9603   int nbFields(MEDnField(fid));
9604   _fields.resize(nbFields);
9605   med_field_type typcha;
9606   for(int i=0;i<nbFields;i++)
9607     {
9608       std::vector<std::string> infos;
9609       std::string fieldName,dtunit;
9610       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
9611       switch(typcha)
9612       {
9613         case MED_FLOAT64:
9614           {
9615             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms);
9616             break;
9617           }
9618         case MED_INT32:
9619           {
9620             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms);
9621             break;
9622           }
9623         default:
9624           {
9625             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] !";
9626             throw INTERP_KERNEL::Exception(oss.str().c_str());
9627           }
9628       }
9629     }
9630   loadAllGlobals(fid);
9631 }
9632 catch(INTERP_KERNEL::Exception& e)
9633 {
9634     throw e;
9635 }
9636
9637 void MEDFileFields::writeLL(med_idt fid) const
9638 {
9639   int i=0;
9640   writeGlobals(fid,*this);
9641   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9642     {
9643       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9644       if(!elt)
9645         {
9646           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9647           throw INTERP_KERNEL::Exception(oss.str().c_str());
9648         }
9649       elt->writeLL(fid,*this);
9650     }
9651 }
9652
9653 void MEDFileFields::write(const std::string& fileName, int mode) const
9654 {
9655   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
9656   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
9657   writeLL(fid);
9658 }
9659
9660 /*!
9661  * This method alloc the arrays and load potentially huge arrays contained in this field.
9662  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9663  * This method can be also called to refresh or reinit values from a file.
9664  * 
9665  * \throw If the fileName is not set or points to a non readable MED file.
9666  */
9667 void MEDFileFields::loadArrays()
9668 {
9669   if(getFileName().empty())
9670     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
9671   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9672   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9673     {
9674       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9675       if(elt)
9676         elt->loadBigArraysRecursively(fid,*elt);
9677     }
9678 }
9679
9680 /*!
9681  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9682  * But once data loaded once, this method does nothing.
9683  * 
9684  * \throw If the fileName is not set or points to a non readable MED file.
9685  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
9686  */
9687 void MEDFileFields::loadArraysIfNecessary()
9688 {
9689   if(!getFileName().empty())
9690     {
9691       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9692       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9693         {
9694           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9695           if(elt)
9696             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9697         }
9698     }
9699 }
9700
9701 /*!
9702  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9703  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9704  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
9705  * 
9706  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
9707  */
9708 void MEDFileFields::unloadArrays()
9709 {
9710   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9711     {
9712       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9713       if(elt)
9714         elt->unloadArrays();
9715     }
9716 }
9717
9718 /*!
9719  * 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.
9720  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
9721  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9722  * 
9723  * \sa MEDFileFields::loadArraysIfNecessary
9724  */
9725 void MEDFileFields::unloadArraysWithoutDataLoss()
9726 {
9727   if(!getFileName().empty())
9728     unloadArrays();
9729 }
9730
9731 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9732 {
9733   std::vector<std::string> ret;
9734   std::set<std::string> ret2;
9735   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9736     {
9737       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9738       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9739         if(ret2.find(*it2)==ret2.end())
9740           {
9741             ret.push_back(*it2);
9742             ret2.insert(*it2);
9743           }
9744     }
9745   return ret;
9746 }
9747
9748 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9749 {
9750   std::vector<std::string> ret;
9751   std::set<std::string> ret2;
9752   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9753     {
9754       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9755       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9756         if(ret2.find(*it2)==ret2.end())
9757           {
9758             ret.push_back(*it2);
9759             ret2.insert(*it2);
9760           }
9761     }
9762   return ret;
9763 }
9764
9765 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
9766 {
9767   std::vector<std::string> ret;
9768   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9769     {
9770       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
9771       ret.insert(ret.end(),tmp.begin(),tmp.end());
9772     }
9773   return ret;
9774 }
9775
9776 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
9777 {
9778   std::vector<std::string> ret;
9779   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9780     {
9781       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9782       ret.insert(ret.end(),tmp.begin(),tmp.end());
9783     }
9784   return ret;
9785 }
9786
9787 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9788 {
9789   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9790     (*it)->changePflsRefsNamesGen2(mapOfModif);
9791 }
9792
9793 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9794 {
9795   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9796     (*it)->changeLocsRefsNamesGen2(mapOfModif);
9797 }
9798
9799 void MEDFileFields::resize(int newSize)
9800 {
9801   _fields.resize(newSize);
9802 }
9803
9804 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
9805 {
9806   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
9807     pushField(*it);
9808 }
9809
9810 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
9811 {
9812   if(!field)
9813     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
9814   _fields.push_back(field->getContent());
9815   appendGlobs(*field,1e-12);
9816 }
9817
9818 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
9819 {
9820   if(!field)
9821     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9822   if(i>=(int)_fields.size())
9823     _fields.resize(i+1);
9824   _fields[i]=field->getContent();
9825   appendGlobs(*field,1e-12);
9826 }
9827
9828 void MEDFileFields::destroyFieldAtPos(int i)
9829 {
9830   destroyFieldsAtPos(&i,&i+1);
9831 }
9832
9833 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
9834 {
9835   std::vector<bool> b(_fields.size(),true);
9836   for(const int *i=startIds;i!=endIds;i++)
9837     {
9838       if(*i<0 || *i>=(int)_fields.size())
9839         {
9840           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9841           throw INTERP_KERNEL::Exception(oss.str().c_str());
9842         }
9843       b[*i]=false;
9844     }
9845   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9846   std::size_t j=0;
9847   for(std::size_t i=0;i<_fields.size();i++)
9848     if(b[i])
9849       fields[j++]=_fields[i];
9850   _fields=fields;
9851 }
9852
9853 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
9854 {
9855   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9856   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
9857   std::vector<bool> b(_fields.size(),true);
9858   int k=bg;
9859   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9860     {
9861       if(k<0 || k>=(int)_fields.size())
9862         {
9863           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9864           throw INTERP_KERNEL::Exception(oss.str().c_str());
9865         }
9866       b[k]=false;
9867     }
9868   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9869   std::size_t j=0;
9870   for(std::size_t i=0;i<_fields.size();i++)
9871     if(b[i])
9872       fields[j++]=_fields[i];
9873   _fields=fields;
9874 }
9875
9876 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9877 {
9878   bool ret=false;
9879   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9880     {
9881       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9882       if(cur)
9883         ret=cur->changeMeshNames(modifTab) || ret;
9884     }
9885   return ret;
9886 }
9887
9888 /*!
9889  * \param [in] meshName the name of the mesh that will be renumbered.
9890  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9891  *             This code corresponds to the distribution of types in the corresponding mesh.
9892  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9893  * \param [in] renumO2N the old to new renumber array.
9894  * \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 
9895  *         field in \a this.
9896  */
9897 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
9898 {
9899   bool ret=false;
9900   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9901     {
9902       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9903       if(fmts)
9904         {
9905           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9906         }
9907     }
9908   return ret;
9909 }
9910
9911 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
9912 {
9913   if(i<0 || i>=(int)_fields.size())
9914     {
9915       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9916       throw INTERP_KERNEL::Exception(oss.str().c_str());
9917     }
9918   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9919   if(!fmts)
9920     return 0;
9921   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
9922   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
9923   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
9924   if(fmtsC)
9925     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9926   else if(fmtsC2)
9927     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9928   else
9929     {
9930       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
9931       throw INTERP_KERNEL::Exception(oss.str().c_str());
9932     }
9933   ret->shallowCpyGlobs(*this);
9934   return ret.retn();
9935 }
9936
9937 /*!
9938  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9939  * This method is accessible in python using __getitem__ with a list in input.
9940  * \return a new object that the caller should deal with.
9941  */
9942 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
9943 {
9944   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9945   std::size_t sz=std::distance(startIds,endIds);
9946   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9947   int j=0;
9948   for(const int *i=startIds;i!=endIds;i++,j++)
9949     {
9950       if(*i<0 || *i>=(int)_fields.size())
9951         {
9952           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9953           throw INTERP_KERNEL::Exception(oss.str().c_str());
9954         }
9955       fields[j]=_fields[*i];
9956     }
9957   ret->_fields=fields;
9958   return ret.retn();
9959 }
9960
9961 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
9962 {
9963   return getFieldAtPos(getPosFromFieldName(fieldName));
9964 }
9965
9966 /*!
9967  * This method removes, if any, fields in \a this having no time steps.
9968  * 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.
9969  * 
9970  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
9971  */
9972 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
9973 {
9974   std::vector<MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
9975   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9976     {
9977       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9978       if(elt)
9979         {
9980           if(elt->getNumberOfTS()>0)
9981             newFields.push_back(*it);
9982         }
9983     }
9984   if(_fields.size()==newFields.size())
9985     return false;
9986   _fields=newFields;
9987   return true;
9988 }
9989
9990 /*!
9991  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9992  * This method can be seen as a filter applied on \a this, that returns an object containing
9993  * 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
9994  * shallow copied from \a this.
9995  * 
9996  * \param [in] meshName - the name of the mesh on w
9997  * \return a new object that the caller should deal with.
9998  */
9999 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10000 {
10001   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10002   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10003     {
10004       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10005       if(!cur)
10006         continue;
10007       if(cur->getMeshName()==meshName)
10008         {
10009           cur->incrRef();
10010           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10011           ret->_fields.push_back(cur2);
10012         }
10013     }
10014   ret->shallowCpyOnlyUsedGlobs(*this);
10015   return ret.retn();
10016 }
10017
10018 /*!
10019  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10020  * Input time steps are specified using a pair of integer (iteration, order).
10021  * 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,
10022  * but for each multitimestep only the time steps in \a timeSteps are kept.
10023  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10024  * 
10025  * The returned object points to shallow copy of elements in \a this.
10026  * 
10027  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10028  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10029  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10030  */
10031 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10032 {
10033   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10034   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10035     {
10036       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10037       if(!cur)
10038         continue;
10039       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10040       ret->_fields.push_back(elt);
10041     }
10042   ret->shallowCpyOnlyUsedGlobs(*this);
10043   return ret.retn();
10044 }
10045
10046 /*!
10047  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10048  */
10049 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10050 {
10051   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10052   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10053     {
10054       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10055       if(!cur)
10056         continue;
10057       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10058       if(elt->getNumberOfTS()!=0)
10059         ret->_fields.push_back(elt);
10060     }
10061   ret->shallowCpyOnlyUsedGlobs(*this);
10062   return ret.retn();
10063 }
10064
10065 MEDFileFieldsIterator *MEDFileFields::iterator()
10066 {
10067   return new MEDFileFieldsIterator(this);
10068 }
10069
10070 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10071 {
10072   std::string tmp(fieldName);
10073   std::vector<std::string> poss;
10074   for(std::size_t i=0;i<_fields.size();i++)
10075     {
10076       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10077       if(f)
10078         {
10079           std::string fname(f->getName());
10080           if(tmp==fname)
10081             return i;
10082           else
10083             poss.push_back(fname);
10084         }
10085     }
10086   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10087   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10088   oss << " !";
10089   throw INTERP_KERNEL::Exception(oss.str().c_str());
10090 }
10091
10092 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10093 {
10094   if(fs)
10095     {
10096       fs->incrRef();
10097       _nb_iter=fs->getNumberOfFields();
10098     }
10099 }
10100
10101 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10102 {
10103 }
10104
10105 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10106 {
10107   if(_iter_id<_nb_iter)
10108     {
10109       MEDFileFields *fs(_fs);
10110       if(fs)
10111         return fs->getFieldAtPos(_iter_id++);
10112       else
10113         return 0;
10114     }
10115   else
10116     return 0;
10117 }