Salome HOME
99a4f1d02708f091d052cac81e8280db41147a01
[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 start,stop,step;
532       spd->getSlice(start,stop,step);
533       _nval=DataArray::GetNumberOfItemGivenBES(start,stop,step,"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   med_int tmp1,nbi;
574   int nbOfCompo(arr->getNumberOfComponents());
575   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
576   if(arrD)
577     {
578       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
579       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
580       return ;
581     }
582   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
583   if(arrI)
584     {
585       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
586       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
587       return ;
588     }
589   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
590 }
591
592 /*!
593  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
594  */
595 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
596 {
597   int delta=_end-_start;
598   _start=newValueOfStart;
599   _end=_start+delta;
600 }
601
602 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
603 {
604   return _father->getIteration();
605 }
606
607 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
608 {
609   return _father->getOrder();
610 }
611
612 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
613 {
614   return _father->getTime();
615 }
616
617 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
618 {
619   return _father->getMeshName();
620 }
621
622 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
623 {
624   const char startLine[]="    ## ";
625   std::string startLine2(bkOffset,' ');
626   startLine2+=startLine;
627   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
628   oss << startLine2 << "Localization #" << id << "." << std::endl;
629   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
630   delete tmp;
631   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
632   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
633   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
634 }
635
636 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
637 {
638   return _type;
639 }
640
641 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
642 {
643   types.insert(_type);
644 }
645
646 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
647 {
648   _type=newType;
649 }
650
651 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
652 {
653   return _father->getGeoType();
654 }
655
656 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
657 {
658   return _father->getNumberOfComponents();
659 }
660
661 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
662 {
663   return _end-_start;
664 }
665
666 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
667 {
668   return _father->getOrCreateAndGetArray();
669 }
670
671 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
672 {
673   const MEDFileFieldPerMeshPerType *fath=_father;
674   return fath->getOrCreateAndGetArray();
675 }
676
677 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
678 {
679   return _father->getInfo();
680 }
681
682 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
683 {
684   return _profile;
685 }
686
687 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
688 {
689   _profile=newPflName;
690 }
691
692 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
693 {
694   return _localization;
695 }
696
697 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
698 {
699   _localization=newLocName;
700 }
701
702 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
703 {
704   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
705     {
706       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
707         {
708           _profile=(*it2).second;
709           return;
710         }
711     }
712 }
713
714 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
715 {
716   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
717     {
718       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
719         {
720           _localization=(*it2).second;
721           return;
722         }
723     }
724 }
725
726 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
727 {
728   if(type!=_type)
729     return ;
730   dads.push_back(std::pair<int,int>(_start,_end));
731   geoTypes.push_back(getGeoType());
732   if(_profile.empty())
733     pfls.push_back(0);
734   else
735     {
736       pfls.push_back(glob->getProfile(_profile.c_str()));
737     }
738   if(_localization.empty())
739     locs.push_back(-1);
740   else
741     {
742       locs.push_back(glob->getLocalizationId(_localization.c_str()));
743     }
744 }
745
746 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
747 {
748   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));
749   startEntryId++;
750 }
751
752 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
753 {
754   TypeOfField type=getType();
755   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
756   med_geometry_type mgeoti;
757   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
758   const DataArray *arr=getOrCreateAndGetArray();
759   if(!arr)
760     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
761   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
762   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
763   const unsigned char *locToWrite=0;
764   if(arrD)
765     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
766   else if(arrI)
767     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
768   else
769     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
770   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
771                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
772                              locToWrite);
773 }
774
775 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
776 {
777   type=_type;
778   pfl=_profile;
779   loc=_localization;
780   dad.first=_start; dad.second=_end;
781 }
782
783 /*!
784  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
785  *             This code corresponds to the distribution of types in the corresponding mesh.
786  * \param [out] ptToFill memory zone where the output will be stored.
787  * \return the size of data pushed into output param \a ptToFill
788  */
789 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
790 {
791   _loc_id=offset;
792   std::ostringstream oss;
793   std::size_t nbOfType=codeOfMesh.size()/3;
794   int found=-1;
795   for(std::size_t i=0;i<nbOfType && found==-1;i++)
796     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
797       found=(int)i;
798   if(found==-1)
799     {
800       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
801       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
802       throw INTERP_KERNEL::Exception(oss.str().c_str());
803     }
804   int *work=ptToFill;
805   if(_profile.empty())
806     {
807       if(_nval!=codeOfMesh[3*found+1])
808         {
809           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
810           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
811           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
812           throw INTERP_KERNEL::Exception(oss.str().c_str());
813         }
814       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
815         *work++=ii;
816     }
817   else
818     {
819       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
820       if(pfl->getNumberOfTuples()!=_nval)
821         {
822           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
823           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
824           oss << _nval;
825           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
826           throw INTERP_KERNEL::Exception(oss.str().c_str());
827         }
828       int offset2=codeOfMesh[3*found+2];
829       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
830         {
831           if(*pflId<codeOfMesh[3*found+1])
832             *work++=offset2+*pflId;
833         }
834     }
835   return _nval;
836 }
837
838 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
839 {
840   for(int i=_start;i<_end;i++)
841     *ptToFill++=i;
842   return _end-_start;
843 }
844
845 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
846 {
847   switch(type)
848   {
849     case ON_CELLS:
850       return -2;
851     case ON_GAUSS_NE:
852       return -1;
853     case ON_GAUSS_PT:
854       return locId;
855     default:
856       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
857   }
858 }
859
860 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
861 {
862   int id=0;
863   std::map<std::pair<std::string,TypeOfField>,int> m;
864   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
865   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
866     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
867       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
868   ret.resize(id);
869   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
870     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
871   return ret;
872 }
873
874 /*!
875  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
876  * 
877  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
878  * \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.
879  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
880  * \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)
881  * \param [in,out] glob if necessary by the method, new profiles can be added to it
882  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
883  * \param [out] result All new entries will be appended on it.
884  * \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 !)
885  */
886 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
887                                                        const DataArrayInt *explicitIdsInMesh,
888                                                        const std::vector<int>& newCode,
889                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
890                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
891 {
892   if(entriesOnSameDisc.empty())
893     return false;
894   TypeOfField type=entriesOnSameDisc[0]->getType();
895   int szEntities=0,szTuples=0;
896   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
897     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
898   int nbi=szTuples/szEntities;
899   if(szTuples%szEntities!=0)
900     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
901   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
902   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
903   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
904   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
905   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
906   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
907   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
908   int id=0;
909   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
910     {
911       int startOfEltIdOfChunk=(*it)->_start;
912       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
913       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
914       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
915       //
916       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
917       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
918       //
919       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
920       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
921     }
922   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
923   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
924   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
925   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
926   //
927   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
928   //
929   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
930   arrPart->renumberInPlace(renumTupleIds->begin());
931   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
932   bool ret=false;
933   const int *idIt=diffVals->begin();
934   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
935   int offset2=0;
936   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
937     {
938       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
939       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
940       int nbEntityElts=subIds->getNumberOfTuples();
941       bool ret2;
942       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
943           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
944                                       offset+offset2,
945                                       li,glob,ret2);
946       ret=ret || ret2;
947       result.push_back(eltToAdd);
948       offset2+=nbEntityElts*nbi;
949     }
950   ret=ret || li.empty();
951   return ret;
952 }
953
954 /*!
955  * \param [in] typeF type of field of new chunk
956  * \param [in] geoType the geometric type of the chunk
957  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
958  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
959  * \param [in] nbi number of integration points
960  * \param [in] offset The offset in the **global array of data**.
961  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
962  *                 to the new chunk to create.
963  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
964  * \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
965  *              and corresponding entry erased from \a entriesOnSameDisc.
966  * \return a newly allocated chunk
967  */
968 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
969                                                                                                   bool isPfl, int nbi, int offset,
970                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
971                                                                                                   MEDFileFieldGlobsReal& glob,
972                                                                                                   bool &notInExisting)
973 {
974   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
975   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
976   for(;it!=entriesOnSameDisc.end();it++)
977     {
978       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
979         {
980           if(!isPfl)
981             {
982               if((*it)->_profile.empty())
983                 break;
984               else
985                 if(!(*it)->_profile.empty())
986                   {
987                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
988                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
989                       break;
990                   }
991             }
992         }
993     }
994   if(it==entriesOnSameDisc.end())
995     {
996       notInExisting=true;
997       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
998       ret->_type=typeF;
999       ret->_loc_id=(int)geoType;
1000       ret->_nval=nbMeshEntities;
1001       ret->_start=offset;
1002       ret->_end=ret->_start+ret->_nval*nbi;
1003       if(isPfl)
1004         {
1005           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1006           glob.appendProfile(idsOfMeshElt);
1007           ret->_profile=idsOfMeshElt->getName();
1008         }
1009       //tony treatment of localization
1010       return ret;
1011     }
1012   else
1013     {
1014       notInExisting=false;
1015       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1016       ret->_loc_id=(int)geoType;
1017       ret->setNewStart(offset);
1018       entriesOnSameDisc.erase(it);
1019       return ret;
1020     }
1021
1022 }
1023
1024 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1025 {
1026   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1027 }
1028
1029 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1030 {
1031   return new MEDFileFieldPerMeshPerType(fath,geoType);
1032 }
1033
1034 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
1035 {
1036   return _field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
1037 }
1038
1039 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
1040 {
1041   std::vector<const BigMemoryObject *> ret;
1042   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1043     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1044   return ret;
1045 }
1046
1047 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const
1048 {
1049   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1050   ret->_father=father;
1051   std::size_t i=0;
1052   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1053     {
1054       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1055         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
1056     }
1057   return ret.retn();
1058 }
1059
1060 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1061 {
1062   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1063   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1064     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1065 }
1066
1067 /*!
1068  * This method is the most general one. No optimization is done here.
1069  * \param [in] multiTypePfl is the end user profile specified in high level API
1070  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1071  * \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.
1072  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1073  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1074  * \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.
1075  */
1076 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)
1077 {
1078   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1079   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1080     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1081 }
1082
1083 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1084 {
1085   _field_pm_pt_pd.resize(1);
1086   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1087   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1088 }
1089
1090 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1091 {
1092   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1093   if(!arr || !arr->isAllocated())
1094     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1095   _field_pm_pt_pd.resize(1);
1096   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1097   _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.
1098 }
1099
1100 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1101 {
1102   TypeOfField type=field->getTypeOfField();
1103   if(type!=ON_GAUSS_PT)
1104     {
1105       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1106       int sz=_field_pm_pt_pd.size();
1107       bool found=false;
1108       for(int j=0;j<sz && !found;j++)
1109         {
1110           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1111             {
1112               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1113               found=true;
1114             }
1115         }
1116       if(!found)
1117         {
1118           _field_pm_pt_pd.resize(sz+1);
1119           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1120         }
1121       std::vector<int> ret(1,(int)sz);
1122       return ret;
1123     }
1124   else
1125     {
1126       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1127       int sz2=ret2.size();
1128       std::vector<int> ret3(sz2);
1129       int k=0;
1130       for(int i=0;i<sz2;i++)
1131         {
1132           int sz=_field_pm_pt_pd.size();
1133           int locIdToFind=ret2[i];
1134           bool found=false;
1135           for(int j=0;j<sz && !found;j++)
1136             {
1137               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1138                 {
1139                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1140                   ret3[k++]=j;
1141                   found=true;
1142                 }
1143             }
1144           if(!found)
1145             {
1146               _field_pm_pt_pd.resize(sz+1);
1147               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1148               ret3[k++]=sz;
1149             }
1150         }
1151       return ret3;
1152     }
1153 }
1154
1155 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1156 {
1157   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1158   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1159   if(!disc2)
1160     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1161   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1162   if(!da)
1163     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1164   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1165   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1166   if(retTmp->presenceOfValue(-1))
1167     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1168   std::vector<int> ret(retTmp->begin(),retTmp->end());
1169   return ret;
1170 }
1171
1172 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1173 {
1174   TypeOfField type=field->getTypeOfField();
1175   if(type!=ON_GAUSS_PT)
1176     {
1177       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1178       int sz=_field_pm_pt_pd.size();
1179       bool found=false;
1180       for(int j=0;j<sz && !found;j++)
1181         {
1182           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1183             {
1184               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1185               found=true;
1186             }
1187         }
1188       if(!found)
1189         {
1190           _field_pm_pt_pd.resize(sz+1);
1191           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1192         }
1193       std::vector<int> ret(1,0);
1194       return ret;
1195     }
1196   else
1197     {
1198       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1199       int sz2=ret2.size();
1200       std::vector<int> ret3(sz2);
1201       int k=0;
1202       for(int i=0;i<sz2;i++)
1203         {
1204           int sz=_field_pm_pt_pd.size();
1205           int locIdToFind=ret2[i];
1206           bool found=false;
1207           for(int j=0;j<sz && !found;j++)
1208             {
1209               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1210                 {
1211                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1212                   ret3[k++]=j;
1213                   found=true;
1214                 }
1215             }
1216           if(!found)
1217             {
1218               _field_pm_pt_pd.resize(sz+1);
1219               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1220               ret3[k++]=sz;
1221             }
1222         }
1223       return ret3;
1224     }
1225 }
1226
1227 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1228 {
1229   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1230   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1231   if(!disc2)
1232     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1233   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1234   if(!da)
1235     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1236   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1237   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1238   if(retTmp->presenceOfValue(-1))
1239     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1240   std::vector<int> ret(retTmp->begin(),retTmp->end());
1241   return ret;
1242 }
1243
1244 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1245 {
1246   return _father;
1247 }
1248
1249 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1250 {
1251   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1252   int curDim=(int)cm.getDimension();
1253   dim=std::max(dim,curDim);
1254 }
1255
1256 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1257 {
1258   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1259     {
1260       (*it)->fillTypesOfFieldAvailable(types);
1261     }
1262 }
1263
1264 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
1265 {
1266   int sz=_field_pm_pt_pd.size();
1267   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1268   for(int i=0;i<sz;i++)
1269     {
1270       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1271     }
1272 }
1273
1274 int MEDFileFieldPerMeshPerType::getIteration() const
1275 {
1276   return _father->getIteration();
1277 }
1278
1279 int MEDFileFieldPerMeshPerType::getOrder() const
1280 {
1281   return _father->getOrder();
1282 }
1283
1284 double MEDFileFieldPerMeshPerType::getTime() const
1285 {
1286   return _father->getTime();
1287 }
1288
1289 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1290 {
1291   return _father->getMeshName();
1292 }
1293
1294 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1295 {
1296   const char startLine[]="  ## ";
1297   std::string startLine2(bkOffset,' ');
1298   std::string startLine3(startLine2);
1299   startLine3+=startLine;
1300   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1301     {
1302       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1303       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1304     }
1305   else
1306     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1307   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1308   int i=0;
1309   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1310     {
1311       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1312       if(cur)
1313         cur->simpleRepr(bkOffset,oss,i);
1314       else
1315         {
1316           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1317         }
1318     }
1319 }
1320
1321 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1322 {
1323   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1324     {
1325       globalSz+=(*it)->getNumberOfTuples();
1326     }
1327   nbOfEntries+=(int)_field_pm_pt_pd.size();
1328 }
1329
1330 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1331 {
1332   return _geo_type;
1333 }
1334
1335
1336 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1337 {
1338   return _father->getNumberOfComponents();
1339 }
1340
1341 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1342 {
1343   return _father->getOrCreateAndGetArray();
1344 }
1345
1346 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1347 {
1348   const MEDFileFieldPerMesh *fath=_father;
1349   return fath->getOrCreateAndGetArray();
1350 }
1351
1352 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1353 {
1354   return _father->getInfo();
1355 }
1356
1357 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1358 {
1359   std::vector<std::string> ret;
1360   std::set<std::string> ret2;
1361   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1362     {
1363       std::string tmp=(*it1)->getProfile();
1364       if(!tmp.empty())
1365         if(ret2.find(tmp)==ret2.end())
1366           {
1367             ret.push_back(tmp);
1368             ret2.insert(tmp);
1369           }
1370     }
1371   return ret;
1372 }
1373
1374 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1375 {
1376   std::vector<std::string> ret;
1377   std::set<std::string> ret2;
1378   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1379     {
1380       std::string tmp=(*it1)->getLocalization();
1381       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1382         if(ret2.find(tmp)==ret2.end())
1383           {
1384             ret.push_back(tmp);
1385             ret2.insert(tmp);
1386           }
1387     }
1388   return ret;
1389 }
1390
1391 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1392 {
1393   std::vector<std::string> ret;
1394   std::set<std::string> ret2;
1395   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1396     {
1397       std::string tmp=(*it1)->getProfile();
1398       if(!tmp.empty())
1399         ret.push_back(tmp);
1400     }
1401   return ret;
1402 }
1403
1404 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1405 {
1406   std::vector<std::string> ret;
1407   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1408     {
1409       std::string tmp=(*it1)->getLocalization();
1410       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1411         ret.push_back(tmp);
1412     }
1413   return ret;
1414 }
1415
1416 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1417 {
1418   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1419     (*it1)->changePflsRefsNamesGen(mapOfModif);
1420 }
1421
1422 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1423 {
1424   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1425     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1426 }
1427
1428 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1429 {
1430   if(_field_pm_pt_pd.empty())
1431     {
1432       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1433       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1434       throw INTERP_KERNEL::Exception(oss.str().c_str());
1435     }
1436   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1437     return _field_pm_pt_pd[locId];
1438   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1439   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1440   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1441   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1442   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1443 }
1444
1445 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1446 {
1447   if(_field_pm_pt_pd.empty())
1448     {
1449       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1450       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1451       throw INTERP_KERNEL::Exception(oss.str().c_str());
1452     }
1453   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1454     return _field_pm_pt_pd[locId];
1455   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1456   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1457   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1458   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1459   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1460 }
1461
1462 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
1463 {
1464   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1465     {
1466       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1467       if(meshDim!=(int)cm.getDimension())
1468         return ;
1469     }
1470   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1471     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1472 }
1473
1474 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1475 {
1476   int i=0;
1477   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1478     {
1479       (*it)->fillValues(i,startEntryId,entries);
1480     }
1481 }
1482
1483 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1484 {
1485   _field_pm_pt_pd=leaves;
1486   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1487     (*it)->setFather(this);
1488 }
1489
1490 /*!
1491  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1492  *  \param [out] its - list of pair (start,stop) kept
1493  *  \return bool - false if the type of field \a tof is not contained in \a this.
1494  */
1495 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1496 {
1497   bool ret=false;
1498   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1499   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1500     if((*it)->getType()==tof)
1501       {
1502         newPmPtPd.push_back(*it);
1503         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1504         (*it)->setNewStart(globalNum);
1505         globalNum=(*it)->getEnd();
1506         its.push_back(bgEnd);
1507         ret=true;
1508       }
1509   if(ret)
1510     _field_pm_pt_pd=newPmPtPd;
1511   return ret;
1512 }
1513
1514 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1515 {
1516 }
1517
1518 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType)
1519 {
1520   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1521   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1522   med_geometry_type mgeoti;
1523   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1524   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1525   _field_pm_pt_pd.resize(nbProfiles);
1526   for(int i=0;i<nbProfiles;i++)
1527     {
1528       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1529     }
1530   if(type==ON_CELLS)
1531     {
1532       int nbProfiles2=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName);
1533       for(int i=0;i<nbProfiles2;i++)
1534         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1535     }
1536 }
1537
1538 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1539 {
1540   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1541     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1542 }
1543
1544 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1545 {
1546   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1547     (*it)->loadBigArray(fid,nasc);
1548 }
1549
1550 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1551 {
1552   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1553     {
1554       (*it)->copyOptionsFrom(*this);
1555       (*it)->writeLL(fid,nasc);
1556     }
1557 }
1558
1559 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1560 {
1561   switch(ikType)
1562   {
1563     case ON_CELLS:
1564       medfGeoType=typmai3[(int)ikGeoType];
1565       return MED_CELL;
1566     case ON_NODES:
1567       medfGeoType=MED_NONE;
1568       return MED_NODE;
1569     case ON_GAUSS_NE:
1570       medfGeoType=typmai3[(int)ikGeoType];
1571       return MED_NODE_ELEMENT;
1572     case ON_GAUSS_PT:
1573       medfGeoType=typmai3[(int)ikGeoType];
1574       return MED_CELL;
1575     default:
1576       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1577   }
1578   return MED_UNDEF_ENTITY_TYPE;
1579 }
1580
1581 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm)
1582 {
1583   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm);
1584 }
1585
1586 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1587 {
1588   return new MEDFileFieldPerMesh(fath,mesh);
1589 }
1590
1591 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1592 {
1593   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1594 }
1595
1596 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1597 {
1598   std::vector<const BigMemoryObject *> ret;
1599   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1600     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1601   return ret;
1602 }
1603
1604 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1605 {
1606   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1607   ret->_father=father;
1608   std::size_t i=0;
1609   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1610     {
1611       if((const MEDFileFieldPerMeshPerType *)*it)
1612         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1613     }
1614   return ret.retn();
1615 }
1616
1617 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1618 {
1619   std::string startLine(bkOffset,' ');
1620   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1621   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1622   int i=0;
1623   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1624     {
1625       const MEDFileFieldPerMeshPerType *cur=*it;
1626       if(cur)
1627         cur->simpleRepr(bkOffset,oss,i);
1628       else
1629         {
1630           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1631         }
1632     }
1633 }
1634
1635 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1636 {
1637   _mesh_name=mesh->getName();
1638   mesh->getTime(_mesh_iteration,_mesh_order);
1639 }
1640
1641 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1642 {
1643   int nbOfTypes=code.size()/3;
1644   int offset=0;
1645   for(int i=0;i<nbOfTypes;i++)
1646     {
1647       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1648       int nbOfCells=code[3*i+1];
1649       int pos=addNewEntryIfNecessary(type);
1650       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1651       offset+=nbOfCells;
1652     }
1653 }
1654
1655 /*!
1656  * This method is the most general one. No optimization is done here.
1657  * \param [in] multiTypePfl is the end user profile specified in high level API
1658  * \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].
1659  * \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.
1660  * \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.
1661  * \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.
1662  * \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.
1663  */
1664 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)
1665 {
1666   int nbOfTypes(code.size()/3);
1667   for(int i=0;i<nbOfTypes;i++)
1668     {
1669       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1670       int pos=addNewEntryIfNecessary(type);
1671       DataArrayInt *pfl=0;
1672       if(code[3*i+2]!=-1)
1673         pfl=idsPerType[code[3*i+2]];
1674       int nbOfTupes2=code2.size()/3;
1675       int found=0;
1676       for(;found<nbOfTupes2;found++)
1677         if(code[3*i]==code2[3*found])
1678           break;
1679       if(found==nbOfTupes2)
1680         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1681       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1682     }
1683 }
1684
1685 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1686 {
1687   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1688   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1689 }
1690
1691 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1692 {
1693   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1694   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1695 }
1696
1697 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1698 {
1699   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1700     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1701 }
1702
1703 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1704 {
1705   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1706     (*it)->loadBigArraysRecursively(fid,nasc);
1707 }
1708
1709 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1710 {
1711   int nbOfTypes=_field_pm_pt.size();
1712   for(int i=0;i<nbOfTypes;i++)
1713     {
1714       _field_pm_pt[i]->copyOptionsFrom(*this);
1715       _field_pm_pt[i]->writeLL(fid,nasc);
1716     }
1717 }
1718
1719 void MEDFileFieldPerMesh::getDimension(int& dim) const
1720 {
1721   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1722     (*it)->getDimension(dim);
1723 }
1724
1725 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1726 {
1727   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1728     (*it)->fillTypesOfFieldAvailable(types);
1729 }
1730
1731 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
1732 {
1733   int sz=_field_pm_pt.size();
1734   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1735   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1736   for(int i=0;i<sz;i++)
1737     {
1738       types[i]=_field_pm_pt[i]->getGeoType();
1739       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1740     }
1741   return ret;
1742 }
1743
1744 double MEDFileFieldPerMesh::getTime() const
1745 {
1746   int tmp1,tmp2;
1747   return _father->getTime(tmp1,tmp2);
1748 }
1749
1750 int MEDFileFieldPerMesh::getIteration() const
1751 {
1752   return _father->getIteration();
1753 }
1754
1755 int MEDFileFieldPerMesh::getOrder() const
1756 {
1757   return _father->getOrder();
1758 }
1759
1760 int MEDFileFieldPerMesh::getNumberOfComponents() const
1761 {
1762   return _father->getNumberOfComponents();
1763 }
1764
1765 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1766 {
1767   if(!_father)
1768     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1769   return _father->getOrCreateAndGetArray();
1770 }
1771
1772 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1773 {
1774   if(!_father)
1775     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1776   return _father->getOrCreateAndGetArray();
1777 }
1778
1779 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1780 {
1781   return _father->getInfo();
1782 }
1783
1784 /*!
1785  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1786  * 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.
1787  * It returns 2 output vectors :
1788  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1789  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1790  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1791  */
1792 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)
1793 {
1794   int notNullPflsSz=0;
1795   int nbOfArrs=geoTypes.size();
1796   for(int i=0;i<nbOfArrs;i++)
1797     if(pfls[i])
1798       notNullPflsSz++;
1799   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1800   int nbOfDiffGeoTypes=geoTypes3.size();
1801   code.resize(3*nbOfDiffGeoTypes);
1802   notNullPfls.resize(notNullPflsSz);
1803   notNullPflsSz=0;
1804   int j=0;
1805   for(int i=0;i<nbOfDiffGeoTypes;i++)
1806     {
1807       int startZone=j;
1808       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1809       std::vector<const DataArrayInt *> notNullTmp;
1810       if(pfls[j])
1811         notNullTmp.push_back(pfls[j]);
1812       j++;
1813       for(;j<nbOfArrs;j++)
1814         if(geoTypes[j]==refType)
1815           {
1816             if(pfls[j])
1817               notNullTmp.push_back(pfls[j]);
1818           }
1819         else
1820           break;
1821       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1822       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1823       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1824       code[3*i]=(int)refType;
1825       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1826       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1827       if(notNullTmp.empty())
1828         code[3*i+2]=-1;
1829       else
1830         {
1831           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1832           code[3*i+2]=notNullPflsSz++;
1833         }
1834     }
1835 }
1836
1837 /*!
1838  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1839  */
1840 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)
1841 {
1842   int sz=dads.size();
1843   int ret=0;
1844   for(int i=0;i<sz;i++)
1845     {
1846       if(locs[i]==-1)
1847         {
1848           if(type!=ON_GAUSS_NE)
1849             ret+=dads[i].second-dads[i].first;
1850           else
1851             {
1852               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1853               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1854             }
1855         }
1856       else
1857         {
1858           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1859           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1860         }
1861     }
1862   return ret;
1863 }
1864
1865 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1866 {
1867   std::vector<std::string> ret;
1868   std::set<std::string> ret2;
1869   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1870     {
1871       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1872       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1873         if(ret2.find(*it2)==ret2.end())
1874           {
1875             ret.push_back(*it2);
1876             ret2.insert(*it2);
1877           }
1878     }
1879   return ret;
1880 }
1881
1882 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1883 {
1884   std::vector<std::string> ret;
1885   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1886     {
1887       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1888       ret.insert(ret.end(),tmp.begin(),tmp.end());
1889     }
1890   return ret;
1891 }
1892
1893 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1894 {
1895   std::vector<std::string> ret;
1896   std::set<std::string> ret2;
1897   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1898     {
1899       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1900       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1901         if(ret2.find(*it2)==ret2.end())
1902           {
1903             ret.push_back(*it2);
1904             ret2.insert(*it2);
1905           }
1906     }
1907   return ret;
1908 }
1909
1910 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1911 {
1912   std::vector<std::string> ret;
1913   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1914     {
1915       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1916       ret.insert(ret.end(),tmp.begin(),tmp.end());
1917     }
1918   return ret;
1919 }
1920
1921 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1922 {
1923   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1924     {
1925       if((*it).first==_mesh_name)
1926         {
1927           _mesh_name=(*it).second;
1928           return true;
1929         }
1930     }
1931   return false;
1932 }
1933
1934 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1935                                                       MEDFileFieldGlobsReal& glob)
1936 {
1937   if(_mesh_name!=meshName)
1938     return false;
1939   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1940   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1941   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1942   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1943   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1944   getUndergroundDataArrayExt(entries);
1945   DataArray *arr0=getOrCreateAndGetArray();//tony
1946   if(!arr0)
1947     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
1948   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
1949   if(!arr0)
1950     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
1951   int sz=0;
1952   if(!arr)
1953     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1954   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1955     {
1956       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1957         {
1958           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1959           sz+=(*it).second.second-(*it).second.first;
1960         }
1961       else
1962         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1963     }
1964   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1965   ////////////////////
1966   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1967   int *workI2=explicitIdsOldInMesh->getPointer();
1968   int sz1=0,sz2=0,sid=1;
1969   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1970   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1971   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1972     {
1973       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1974       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1975       int *workI=explicitIdsOldInArr->getPointer();
1976       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1977         {
1978           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1979           (*itL2)->setLocId(sz2);
1980           (*itL2)->_tmp_work1=(*itL2)->getStart();
1981           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1982         }
1983       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1984     }
1985   explicitIdsOldInMesh->reAlloc(sz2);
1986   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1987   ////////////////////
1988   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1989   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1990   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1991   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1992     {
1993       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1994       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1995       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1996     }
1997   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1998   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1999   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2000     {
2001       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2002       int newStart=elt->getLocId();
2003       elt->setLocId((*it)->getGeoType());
2004       elt->setNewStart(newStart);
2005       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2006       entriesKeptNew.push_back(elt);
2007       entriesKeptNew2.push_back(elt);
2008     }
2009   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2010   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2011   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2012   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2013   bool ret=false;
2014   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2015     {
2016       sid=0;
2017       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2018         {
2019           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2020           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2021           }*/
2022       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2023                                                             glob,arr2,otherEntriesNew) || ret;
2024     }
2025   if(!ret)
2026     return false;
2027   // Assign new dispatching
2028   assignNewLeaves(otherEntriesNew);
2029   arr->cpyFrom(*arr2);
2030   return true;
2031 }
2032
2033 /*!
2034  * \param [in,out] globalNum a global numbering counter for the renumbering.
2035  * \param [out] its - list of pair (start,stop) kept
2036  */
2037 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2038 {
2039   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
2040   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2041     {
2042       std::vector< std::pair<int,int> > its2;
2043       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2044         {
2045           ret.push_back(*it);
2046           its.insert(its.end(),its2.begin(),its2.end());
2047         }
2048     }
2049   _field_pm_pt=ret;
2050 }
2051
2052 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2053 {
2054   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2055   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2056     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2057   //
2058   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2059   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2060   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2061   for(;it1!=types.end();it1++,it2++)
2062     {
2063       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2064       elt->setLeaves((*it1).second);
2065       *it2=elt;
2066     }
2067   _field_pm_pt=fieldPmPt;
2068 }
2069
2070 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2071 {
2072   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2073     (*it)->changePflsRefsNamesGen(mapOfModif);
2074 }
2075
2076 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2077 {
2078   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2079     (*it)->changeLocsRefsNamesGen(mapOfModif);
2080 }
2081
2082 /*!
2083  * \param [in] mesh is the whole mesh
2084  */
2085 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2086 {
2087   if(_field_pm_pt.empty())
2088     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2089   //
2090   std::vector< std::pair<int,int> > dads;
2091   std::vector<const DataArrayInt *> pfls;
2092   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2093   std::vector<int> locs,code;
2094   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2095   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2096     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2097   // Sort by types
2098   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2099   if(code.empty())
2100     {
2101       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2102       throw INTERP_KERNEL::Exception(oss.str().c_str());
2103     }
2104   //
2105   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2106   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2107   if(type!=ON_NODES)
2108     {
2109       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2110       if(!arr)
2111         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2112       else
2113         {
2114           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2115           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2116         }
2117     }
2118   else
2119     {
2120       if(code.size()!=3)
2121         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2122       int nb=code[1];
2123       if(code[2]==-1)
2124         {
2125           if(nb!=mesh->getNumberOfNodes())
2126             {
2127               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2128               oss << " nodes in mesh !";
2129               throw INTERP_KERNEL::Exception(oss.str().c_str());
2130             }
2131           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2132         }
2133       else
2134         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2135     }
2136 }
2137
2138 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2139 {
2140   if(_field_pm_pt.empty())
2141     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2142   //
2143   std::vector<std::pair<int,int> > dads;
2144   std::vector<const DataArrayInt *> pfls;
2145   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2146   std::vector<int> locs,code;
2147   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2148   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2149     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2150   // Sort by types
2151   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2152   if(code.empty())
2153     {
2154       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2155       throw INTERP_KERNEL::Exception(oss.str().c_str());
2156     }
2157   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2158   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2159   if(type!=ON_NODES)
2160     {
2161       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2162       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2163     }
2164   else
2165     {
2166       if(code.size()!=3)
2167         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2168       int nb=code[1];
2169       if(code[2]==-1)
2170         {
2171           if(nb!=mesh->getNumberOfNodes())
2172             {
2173               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2174               oss << " nodes in mesh !";
2175               throw INTERP_KERNEL::Exception(oss.str().c_str());
2176             }
2177         }
2178       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2179     }
2180   //
2181   return 0;
2182 }
2183
2184 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2185 {
2186   int globalSz=0;
2187   int nbOfEntries=0;
2188   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2189     {
2190       (*it)->getSizes(globalSz,nbOfEntries);
2191     }
2192   entries.resize(nbOfEntries);
2193   nbOfEntries=0;
2194   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2195     {
2196       (*it)->fillValues(nbOfEntries,entries);
2197     }
2198 }
2199
2200 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2201 {
2202   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2203     {
2204       if((*it)->getGeoType()==typ)
2205         return (*it)->getLeafGivenLocId(locId);
2206     }
2207   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2208   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2209   oss << "Possiblities are : ";
2210   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2211     {
2212       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2213       oss << "\"" << cm2.getRepr() << "\", ";
2214     }
2215   throw INTERP_KERNEL::Exception(oss.str().c_str());
2216 }
2217
2218 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2219 {
2220   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2221     {
2222       if((*it)->getGeoType()==typ)
2223         return (*it)->getLeafGivenLocId(locId);
2224     }
2225   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2226   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2227   oss << "Possiblities are : ";
2228   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2229     {
2230       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2231       oss << "\"" << cm2.getRepr() << "\", ";
2232     }
2233   throw INTERP_KERNEL::Exception(oss.str().c_str());
2234 }
2235
2236 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2237 {
2238   int i=0;
2239   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2240   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2241   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2242     {
2243       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2244       if(type==curType)
2245         return i;
2246       else
2247         {
2248           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2249           if(pos>pos2)
2250             it2=it+1;
2251         }
2252     }
2253   int ret=std::distance(_field_pm_pt.begin(),it2);
2254   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2255   return ret;
2256 }
2257
2258 /*!
2259  * 'dads' and 'locs' input parameters have the same number of elements
2260  * \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
2261  */
2262 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2263                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2264                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2265 {
2266   isPfl=false;
2267   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2268   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2269   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2270   const std::vector<std::string>& infos=getInfo();
2271   da->setInfoOnComponents(infos);
2272   da->setName("");
2273   if(type==ON_GAUSS_PT)
2274     {
2275       int offset=0;
2276       int nbOfArrs=dads.size();
2277       for(int i=0;i<nbOfArrs;i++)
2278         {
2279           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2280           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2281           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2282           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2283           di->alloc(nbOfElems,1);
2284           di->iota(offset);
2285           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2286           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2287           offset+=nbOfElems;
2288         }
2289     }
2290   arrOut=da;
2291   return ret.retn();
2292 }
2293
2294 /*!
2295  * 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.
2296  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2297  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2298  * The order of cells in the returned field is those imposed by the profile.
2299  * \param [in] mesh is the global mesh.
2300  */
2301 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2302                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2303                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2304                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2305 {
2306   if(da->isIdentity())
2307     {
2308       int nbOfTuples=da->getNumberOfTuples();
2309       if(nbOfTuples==mesh->getNumberOfCells())
2310         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2311     }
2312   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2313   m2->setName(mesh->getName().c_str());
2314   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2315   isPfl=true;
2316   return ret.retn();
2317 }
2318
2319 /*!
2320  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2321  */
2322 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2323                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2324                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2325 {
2326   if(da->isIdentity())
2327     {
2328       int nbOfTuples=da->getNumberOfTuples();
2329       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2330         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2331     }
2332   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2333   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2334   if(meshu)
2335     {
2336       if(meshu->getNodalConnectivity()==0)
2337         {
2338           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2339           int nb=da->getNbOfElems();
2340           const int *ptr=da->getConstPointer();
2341           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2342           meshuc->allocateCells(nb);
2343           for(int i=0;i<nb;i++)
2344             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2345           meshuc->finishInsertingCells();
2346           ret->setMesh(meshuc);
2347           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2348           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2349           disc->checkCoherencyBetween(meshuc,arrOut);
2350           return ret.retn();
2351         }
2352     }
2353   //
2354   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2355   isPfl=true;
2356   DataArrayInt *arr2=0;
2357   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2358   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2359   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2360   int nnodes=mesh2->getNumberOfNodes();
2361   if(nnodes==(int)da->getNbOfElems())
2362     {
2363       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2364       arrOut->renumberInPlace(da3->getConstPointer());
2365       mesh2->setName(mesh->getName().c_str());
2366       ret->setMesh(mesh2);
2367       return ret.retn();
2368     }
2369   else
2370     {
2371       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 !!!";
2372       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2373       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2374       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2375       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2376       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2377       throw INTERP_KERNEL::Exception(oss.str().c_str());
2378     }
2379   return 0;
2380 }
2381
2382 /*!
2383  * This method is the most light method of field retrieving.
2384  */
2385 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2386 {
2387   if(!pflIn)
2388     {
2389       pflOut=DataArrayInt::New();
2390       pflOut->alloc(nbOfElems,1);
2391       pflOut->iota(0);
2392     }
2393   else
2394     {
2395       pflOut=const_cast<DataArrayInt*>(pflIn);
2396       pflOut->incrRef();
2397     }
2398   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2399   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2400   const std::vector<std::string>& infos=getInfo();
2401   int nbOfComp=infos.size();
2402   for(int i=0;i<nbOfComp;i++)
2403     da->setInfoOnComponent(i,infos[i].c_str());
2404   safePfl->incrRef();
2405   return da.retn();
2406 }
2407
2408 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),
2409     _father(fath)
2410 {
2411   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2412   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2413   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2414   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2415   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2416     {
2417       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[i],meshCsit+1,meshName,pflName,locName));
2418       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2419       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],meshCsit+1,meshName,pflName,locName));
2420       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2421       if(nbProfile>0 || nbProfile2>0)
2422         {
2423           const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2424           const PartDefinition *pd(0);
2425           if(mmu)
2426             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[i]),typmai2[i]);
2427           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i],nasc,pd));
2428           if(nbProfile>0)
2429             _mesh_name=name0;
2430           else
2431             _mesh_name=name1;
2432         }
2433     }
2434   int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName);
2435   if(nbProfile>0)
2436     {
2437       const PartDefinition *pd(0);
2438       if(mmu)
2439         pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2440       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2441       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2442     }
2443 }
2444
2445 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2446 {
2447   copyTinyInfoFrom(mesh);
2448 }
2449
2450 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2451 {
2452   if(id>=(int)_pfls.size())
2453     _pfls.resize(id+1);
2454   _pfls[id]=DataArrayInt::New();
2455   int lgth=MEDprofileSizeByName(fid,pflName.c_str());
2456   _pfls[id]->setName(pflName);
2457   _pfls[id]->alloc(lgth,1);
2458   MEDprofileRd(fid,pflName.c_str(),_pfls[id]->getPointer());
2459   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2460 }
2461
2462 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2463 {
2464   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2465   int sz;
2466   MEDprofileInfo(fid,i+1,pflName,&sz);
2467   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2468   if(i>=(int)_pfls.size())
2469     _pfls.resize(i+1);
2470   _pfls[i]=DataArrayInt::New();
2471   _pfls[i]->alloc(sz,1);
2472   _pfls[i]->setName(pflCpp.c_str());
2473   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2474   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2475 }
2476
2477 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2478 {
2479   int nbOfPfls=_pfls.size();
2480   for(int i=0;i<nbOfPfls;i++)
2481     {
2482       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2483       cpy->applyLin(1,1,0);
2484       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2485       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2486       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2487     }
2488   //
2489   int nbOfLocs=_locs.size();
2490   for(int i=0;i<nbOfLocs;i++)
2491     _locs[i]->writeLL(fid);
2492 }
2493
2494 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2495 {
2496   std::vector<std::string> pfls=getPfls();
2497   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2498     {
2499       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2500       if(it2==pfls.end())
2501         {
2502           _pfls.push_back(*it);
2503         }
2504       else
2505         {
2506           int id=std::distance(pfls.begin(),it2);
2507           if(!(*it)->isEqual(*_pfls[id]))
2508             {
2509               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2510               throw INTERP_KERNEL::Exception(oss.str().c_str());
2511             }
2512         }
2513     }
2514   std::vector<std::string> locs=getLocs();
2515   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2516     {
2517       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2518       if(it2==locs.end())
2519         {
2520           _locs.push_back(*it);
2521         }
2522       else
2523         {
2524           int id=std::distance(locs.begin(),it2);
2525           if(!(*it)->isEqual(*_locs[id],eps))
2526             {
2527               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2528               throw INTERP_KERNEL::Exception(oss.str().c_str());
2529             }
2530         }
2531     }
2532 }
2533
2534 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2535 {
2536   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2537     getProfile((*it).c_str());
2538 }
2539
2540 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2541 {
2542   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2543     getLocalization((*it).c_str());
2544 }
2545
2546 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2547 {
2548   std::vector<std::string> profiles=real.getPflsReallyUsed();
2549   int sz=profiles.size();
2550   _pfls.resize(sz);
2551   for(int i=0;i<sz;i++)
2552     loadProfileInFile(fid,i,profiles[i].c_str());
2553   //
2554   std::vector<std::string> locs=real.getLocsReallyUsed();
2555   sz=locs.size();
2556   _locs.resize(sz);
2557   for(int i=0;i<sz;i++)
2558     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2559 }
2560
2561 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2562 {
2563   int nProfil=MEDnProfile(fid);
2564   for(int i=0;i<nProfil;i++)
2565     loadProfileInFile(fid,i);
2566   int sz=MEDnLocalization(fid);
2567   _locs.resize(sz);
2568   for(int i=0;i<sz;i++)
2569     {
2570       _locs[i]=MEDFileFieldLoc::New(fid,i);
2571     }
2572 }
2573
2574 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2575 {
2576   return new MEDFileFieldGlobs(fname);
2577 }
2578
2579 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2580 {
2581   return new MEDFileFieldGlobs;
2582 }
2583
2584 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2585 {
2586   return _file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2587 }
2588
2589 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2590 {
2591   std::vector<const BigMemoryObject *> ret;
2592   for(std::vector< MEDCouplingAutoRefCountObjectPtr< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2593     ret.push_back((const DataArrayInt *)*it);
2594   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2595     ret.push_back((const MEDFileFieldLoc *)*it);
2596   return ret;
2597 }
2598
2599 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const
2600 {
2601   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2602   std::size_t i=0;
2603   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2604     {
2605       if((const DataArrayInt *)*it)
2606         ret->_pfls[i]=(*it)->deepCpy();
2607     }
2608   i=0;
2609   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2610     {
2611       if((const MEDFileFieldLoc*)*it)
2612         ret->_locs[i]=(*it)->deepCpy();
2613     }
2614   return ret.retn();
2615 }
2616
2617 /*!
2618  * \throw if a profile in \a pfls in not in \a this.
2619  * \throw if a localization in \a locs in not in \a this.
2620  * \sa MEDFileFieldGlobs::deepCpyPart
2621  */
2622 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2623 {
2624   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2625   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2626     {
2627       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2628       if(!pfl)
2629         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2630       pfl->incrRef();
2631       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2632       ret->_pfls.push_back(pfl2);
2633     }
2634   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2635     {
2636       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2637       if(!loc)
2638         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2639       loc->incrRef();
2640       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2641       ret->_locs.push_back(loc2);
2642     }
2643   ret->setFileName(getFileName());
2644   return ret.retn();
2645 }
2646
2647 /*!
2648  * \throw if a profile in \a pfls in not in \a this.
2649  * \throw if a localization in \a locs in not in \a this.
2650  * \sa MEDFileFieldGlobs::shallowCpyPart
2651  */
2652 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2653 {
2654   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2655   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2656     {
2657       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2658       if(!pfl)
2659         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2660       ret->_pfls.push_back(pfl->deepCpy());
2661     }
2662   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2663     {
2664       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2665       if(!loc)
2666         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2667       ret->_locs.push_back(loc->deepCpy());
2668     }
2669   ret->setFileName(getFileName());
2670   return ret.retn();
2671 }
2672
2673 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2674 {
2675 }
2676
2677 MEDFileFieldGlobs::MEDFileFieldGlobs()
2678 {
2679 }
2680
2681 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2682 {
2683 }
2684
2685 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2686 {
2687   oss << "Profiles :\n";
2688   std::size_t n=_pfls.size();
2689   for(std::size_t i=0;i<n;i++)
2690     {
2691       oss << "  - #" << i << " ";
2692       const DataArrayInt *pfl=_pfls[i];
2693       if(pfl)
2694         oss << "\"" << pfl->getName() << "\"\n";
2695       else
2696         oss << "EMPTY !\n";
2697     }
2698   n=_locs.size();
2699   oss << "Localizations :\n";
2700   for(std::size_t i=0;i<n;i++)
2701     {
2702       oss << "  - #" << i << " ";
2703       const MEDFileFieldLoc *loc=_locs[i];
2704       if(loc)
2705         loc->simpleRepr(oss);
2706       else
2707         oss<< "EMPTY !\n";
2708     }
2709 }
2710
2711 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2712 {
2713   _file_name=fileName;
2714 }
2715
2716 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2717 {
2718   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2719     {
2720       DataArrayInt *elt(*it);
2721       if(elt)
2722         {
2723           std::string name(elt->getName());
2724           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2725             {
2726               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2727                 {
2728                   elt->setName((*it2).second.c_str());
2729                   return;
2730                 }
2731             }
2732         }
2733     }
2734 }
2735
2736 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2737 {
2738   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2739     {
2740       MEDFileFieldLoc *elt(*it);
2741       if(elt)
2742         {
2743           std::string name(elt->getName());
2744           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2745             {
2746               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2747                 {
2748                   elt->setName((*it2).second.c_str());
2749                   return;
2750                 }
2751             }
2752         }
2753     }
2754 }
2755
2756 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2757 {
2758   if(locId<0 || locId>=(int)_locs.size())
2759     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2760   return _locs[locId]->getNbOfGaussPtPerCell();
2761 }
2762
2763 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2764 {
2765   return getLocalizationFromId(getLocalizationId(locName));
2766 }
2767
2768 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2769 {
2770   if(locId<0 || locId>=(int)_locs.size())
2771     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2772   return *_locs[locId];
2773 }
2774
2775 namespace ParaMEDMEMImpl
2776 {
2777   class LocFinder
2778   {
2779   public:
2780     LocFinder(const std::string& loc):_loc(loc) { }
2781     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2782   private:
2783     const std::string &_loc;
2784   };
2785
2786   class PflFinder
2787   {
2788   public:
2789     PflFinder(const std::string& pfl):_pfl(pfl) { }
2790     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2791   private:
2792     const std::string& _pfl;
2793   };
2794 }
2795
2796 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2797 {
2798   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2799   if(it==_locs.end())
2800     {
2801       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2802       for(it=_locs.begin();it!=_locs.end();it++)
2803         oss << "\"" << (*it)->getName() << "\", ";
2804       throw INTERP_KERNEL::Exception(oss.str().c_str());
2805     }
2806   return std::distance(_locs.begin(),it);
2807 }
2808
2809 /*!
2810  * The returned value is never null.
2811  */
2812 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2813 {
2814   std::string pflNameCpp(pflName);
2815   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2816   if(it==_pfls.end())
2817     {
2818       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2819       for(it=_pfls.begin();it!=_pfls.end();it++)
2820         oss << "\"" << (*it)->getName() << "\", ";
2821       throw INTERP_KERNEL::Exception(oss.str().c_str());
2822     }
2823   return *it;
2824 }
2825
2826 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2827 {
2828   if(pflId<0 || pflId>=(int)_pfls.size())
2829     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2830   return _pfls[pflId];
2831 }
2832
2833 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
2834 {
2835   if(locId<0 || locId>=(int)_locs.size())
2836     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2837   return *_locs[locId];
2838 }
2839
2840 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
2841 {
2842   return getLocalizationFromId(getLocalizationId(locName));
2843 }
2844
2845 /*!
2846  * The returned value is never null.
2847  */
2848 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
2849 {
2850   std::string pflNameCpp(pflName);
2851   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2852   if(it==_pfls.end())
2853     {
2854       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2855       for(it=_pfls.begin();it!=_pfls.end();it++)
2856         oss << "\"" << (*it)->getName() << "\", ";
2857       throw INTERP_KERNEL::Exception(oss.str().c_str());
2858     }
2859   return *it;
2860 }
2861
2862 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
2863 {
2864   if(pflId<0 || pflId>=(int)_pfls.size())
2865     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2866   return _pfls[pflId];
2867 }
2868
2869 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
2870 {
2871   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2872   int i=0;
2873   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2874     {
2875       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2876         newPfls.push_back(*it);
2877     }
2878   _pfls=newPfls;
2879 }
2880
2881 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
2882 {
2883   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2884   int i=0;
2885   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2886     {
2887       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2888         newLocs.push_back(*it);
2889     }
2890   _locs=newLocs;
2891 }
2892
2893 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2894 {
2895   int sz=_pfls.size();
2896   std::vector<std::string> ret(sz);
2897   for(int i=0;i<sz;i++)
2898     ret[i]=_pfls[i]->getName();
2899   return ret;
2900 }
2901
2902 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2903 {
2904   int sz=_locs.size();
2905   std::vector<std::string> ret(sz);
2906   for(int i=0;i<sz;i++)
2907     ret[i]=_locs[i]->getName();
2908   return ret;
2909 }
2910
2911 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
2912 {
2913   std::vector<std::string> v=getPfls();
2914   std::string s(pflName);
2915   return std::find(v.begin(),v.end(),s)!=v.end();
2916 }
2917
2918 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
2919 {
2920   std::vector<std::string> v=getLocs();
2921   std::string s(locName);
2922   return std::find(v.begin(),v.end(),s)!=v.end();
2923 }
2924
2925 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2926 {
2927   std::map<int,std::vector<int> > m;
2928   int i=0;
2929   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2930     {
2931       const DataArrayInt *tmp=(*it);
2932       if(tmp)
2933         {
2934           m[tmp->getHashCode()].push_back(i);
2935         }
2936     }
2937   std::vector< std::vector<int> > ret;
2938   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2939     {
2940       if((*it2).second.size()>1)
2941         {
2942           std::vector<int> ret0;
2943           bool equalityOrNot=false;
2944           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2945             {
2946               std::vector<int>::const_iterator it4=it3; it4++;
2947               for(;it4!=(*it2).second.end();it4++)
2948                 {
2949                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2950                     {
2951                       if(!equalityOrNot)
2952                         ret0.push_back(*it3);
2953                       ret0.push_back(*it4);
2954                       equalityOrNot=true;
2955                     }
2956                 }
2957             }
2958           if(!ret0.empty())
2959             ret.push_back(ret0);
2960         }
2961     }
2962   return ret;
2963 }
2964
2965 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2966 {
2967   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2968 }
2969
2970 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
2971 {
2972   std::string name(pfl->getName());
2973   if(name.empty())
2974     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2975   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2976     if(name==(*it)->getName())
2977       {
2978         if(!pfl->isEqual(*(*it)))
2979           {
2980             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2981             throw INTERP_KERNEL::Exception(oss.str().c_str());
2982           }
2983       }
2984   pfl->incrRef();
2985   _pfls.push_back(pfl);
2986 }
2987
2988 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)
2989 {
2990   std::string name(locName);
2991   if(name.empty())
2992     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2993   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2994   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2995     if((*it)->isName(locName))
2996       {
2997         if(!(*it)->isEqual(*obj,1e-12))
2998           {
2999             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3000             throw INTERP_KERNEL::Exception(oss.str().c_str());
3001           }
3002       }
3003   _locs.push_back(obj);
3004 }
3005
3006 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3007 {
3008   std::vector<std::string> names=getPfls();
3009   return CreateNewNameNotIn("NewPfl_",names);
3010 }
3011
3012 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3013 {
3014   std::vector<std::string> names=getLocs();
3015   return CreateNewNameNotIn("NewLoc_",names);
3016 }
3017
3018 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3019 {
3020   for(std::size_t sz=0;sz<100000;sz++)
3021     {
3022       std::ostringstream tryName;
3023       tryName << prefix << sz;
3024       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3025         return tryName.str();
3026     }
3027   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3028 }
3029
3030 /*!
3031  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3032  *  \param [in] fname - the file name.
3033  */
3034 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
3035 {
3036 }
3037
3038 /*!
3039  * Creates an empty MEDFileFieldGlobsReal.
3040  */
3041 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3042 {
3043 }
3044
3045 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3046 {
3047   return 0;
3048 }
3049
3050 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3051 {
3052   std::vector<const BigMemoryObject *> ret;
3053   ret.push_back((const MEDFileFieldGlobs *)_globals);
3054   return ret;
3055 }
3056
3057 /*!
3058  * Returns a string describing profiles and Gauss points held in \a this.
3059  *  \return std::string - the description string.
3060  */
3061 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3062 {
3063   const MEDFileFieldGlobs *glob=_globals;
3064   std::ostringstream oss2; oss2 << glob;
3065   std::string stars(oss2.str().length(),'*');
3066   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3067   if(glob)
3068     glob->simpleRepr(oss);
3069   else
3070     oss << "NO GLOBAL INFORMATION !\n";
3071 }
3072
3073 void MEDFileFieldGlobsReal::resetContent()
3074 {
3075   _globals=MEDFileFieldGlobs::New();
3076 }
3077
3078 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3079 {
3080 }
3081
3082 /*!
3083  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3084  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3085  */
3086 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3087 {
3088   _globals=other._globals;
3089 }
3090
3091 /*!
3092  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3093  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3094  */
3095 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3096 {
3097   const MEDFileFieldGlobs *otherg(other._globals);
3098   if(!otherg)
3099     return ;
3100   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3101 }
3102
3103 /*!
3104  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3105  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3106  */
3107 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3108 {
3109   const MEDFileFieldGlobs *otherg(other._globals);
3110   if(!otherg)
3111     return ;
3112   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3113 }
3114
3115 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3116 {
3117   _globals=other._globals;
3118   if((const MEDFileFieldGlobs *)_globals)
3119     _globals=other._globals->deepCpy();
3120 }
3121
3122 /*!
3123  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3124  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3125  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3126  *         \a this and \a other MEDFileFieldGlobsReal.
3127  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3128  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3129  */
3130 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3131 {
3132   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3133   if(thisGlobals==otherGlobals)
3134     return ;
3135   if(!thisGlobals)
3136     {
3137       _globals=other._globals;
3138       return ;
3139     }
3140   _globals->appendGlobs(*other._globals,eps);
3141 }
3142
3143 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3144 {
3145   checkGlobsPflsPartCoherency();
3146   checkGlobsLocsPartCoherency();
3147 }
3148
3149 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3150 {
3151   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3152 }
3153
3154 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3155 {
3156   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3157 }
3158
3159 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3160 {
3161   contentNotNull()->loadProfileInFile(fid,id,pflName);
3162 }
3163
3164 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3165 {
3166   contentNotNull()->loadProfileInFile(fid,id);
3167 }
3168
3169 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3170 {
3171   contentNotNull()->loadGlobals(fid,*this);
3172 }
3173
3174 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3175 {
3176   contentNotNull()->loadAllGlobals(fid);
3177 }
3178
3179 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3180 {
3181   contentNotNull()->writeGlobals(fid,opt);
3182 }
3183
3184 /*!
3185  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3186  * or getPflsReallyUsedMulti().
3187  *  \return std::vector<std::string> - a sequence of names of all profiles.
3188  */
3189 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3190 {
3191   return contentNotNull()->getPfls();
3192 }
3193
3194 /*!
3195  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3196  * or getLocsReallyUsedMulti().
3197  *  \return std::vector<std::string> - a sequence of names of all localizations.
3198  */
3199 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3200 {
3201   return contentNotNull()->getLocs();
3202 }
3203
3204 /*!
3205  * Checks if the profile with a given name exists.
3206  *  \param [in] pflName - the profile name of interest.
3207  *  \return bool - \c true if the profile named \a pflName exists.
3208  */
3209 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3210 {
3211   return contentNotNull()->existsPfl(pflName);
3212 }
3213
3214 /*!
3215  * Checks if the localization with a given name exists.
3216  *  \param [in] locName - the localization name of interest.
3217  *  \return bool - \c true if the localization named \a locName exists.
3218  */
3219 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3220 {
3221   return contentNotNull()->existsLoc(locName);
3222 }
3223
3224 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3225 {
3226   return contentNotNull()->createNewNameOfPfl();
3227 }
3228
3229 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3230 {
3231   return contentNotNull()->createNewNameOfLoc();
3232 }
3233
3234 /*!
3235  * Sets the name of a MED file.
3236  *  \param [inout] fileName - the file name.
3237  */
3238 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3239 {
3240   contentNotNull()->setFileName(fileName);
3241 }
3242
3243 /*!
3244  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3245  * in the same order.
3246  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3247  *          Each item of this sequence is a vector containing ids of equal profiles.
3248  */
3249 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3250 {
3251   return contentNotNull()->whichAreEqualProfiles();
3252 }
3253
3254 /*!
3255  * Finds equal localizations.
3256  *  \param [in] eps - a precision used to compare real values of the localizations.
3257  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3258  *          Each item of this sequence is a vector containing ids of equal localizations.
3259  */
3260 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3261 {
3262   return contentNotNull()->whichAreEqualLocs(eps);
3263 }
3264
3265 /*!
3266  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3267  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3268  *        this sequence is a pair whose 
3269  *        - the first item is a vector of profile names to replace by the second item,
3270  *        - the second item is a profile name to replace every profile name of the first item.
3271  */
3272 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3273 {
3274   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3275 }
3276
3277 /*!
3278  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3279  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3280  *        this sequence is a pair whose 
3281  *        - the first item is a vector of localization names to replace by the second item,
3282  *        - the second item is a localization name to replace every localization name of the first item.
3283  */
3284 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3285 {
3286   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3287 }
3288
3289 /*!
3290  * Replaces references to some profiles (a reference is a profile name) by references
3291  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3292  * them-selves accordingly. <br>
3293  * This method is a generalization of changePflName().
3294  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3295  *        this sequence is a pair whose 
3296  *        - the first item is a vector of profile names to replace by the second item,
3297  *        - the second item is a profile name to replace every profile of the first item.
3298  * \sa changePflsRefsNamesGen()
3299  * \sa changePflName()
3300  */
3301 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3302 {
3303   changePflsRefsNamesGen(mapOfModif);
3304   changePflsNamesInStruct(mapOfModif);
3305 }
3306
3307 /*!
3308  * Replaces references to some localizations (a reference is a localization name) by references
3309  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3310  * them-selves accordingly. <br>
3311  * This method is a generalization of changeLocName().
3312  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3313  *        this sequence is a pair whose 
3314  *        - the first item is a vector of localization names to replace by the second item,
3315  *        - the second item is a localization name to replace every localization of the first item.
3316  * \sa changeLocsRefsNamesGen()
3317  * \sa changeLocName()
3318  */
3319 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3320 {
3321   changeLocsRefsNamesGen(mapOfModif);
3322   changeLocsNamesInStruct(mapOfModif);
3323 }
3324
3325 /*!
3326  * Renames the profile having a given name and updates references to this profile.
3327  *  \param [in] oldName - the name of the profile to rename.
3328  *  \param [in] newName - a new name of the profile.
3329  * \sa changePflsNames().
3330  */
3331 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3332 {
3333   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3334   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3335   mapOfModif[0]=p;
3336   changePflsNames(mapOfModif);
3337 }
3338
3339 /*!
3340  * Renames the localization having a given name and updates references to this localization.
3341  *  \param [in] oldName - the name of the localization to rename.
3342  *  \param [in] newName - a new name of the localization.
3343  * \sa changeLocsNames().
3344  */
3345 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3346 {
3347   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3348   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3349   mapOfModif[0]=p;
3350   changeLocsNames(mapOfModif);
3351 }
3352
3353 /*!
3354  * Removes duplicated profiles. Returns a map used to update references to removed 
3355  * profiles via changePflsRefsNamesGen().
3356  * Equal profiles are found using whichAreEqualProfiles().
3357  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3358  *          a sequence describing the performed replacements of profiles. Each element of
3359  *          this sequence is a pair whose
3360  *          - the first item is a vector of profile names replaced by the second item,
3361  *          - the second item is a profile name replacing every profile of the first item.
3362  */
3363 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3364 {
3365   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3366   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3367   int i=0;
3368   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3369     {
3370       std::vector< std::string > tmp((*it).size());
3371       int j=0;
3372       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3373         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3374       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3375       ret[i]=p;
3376       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3377       killProfileIds(tmp2);
3378     }
3379   changePflsRefsNamesGen(ret);
3380   return ret;
3381 }
3382
3383 /*!
3384  * Removes duplicated localizations. Returns a map used to update references to removed 
3385  * localizations via changeLocsRefsNamesGen().
3386  * Equal localizations are found using whichAreEqualLocs().
3387  *  \param [in] eps - a precision used to compare real values of the localizations.
3388  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3389  *          a sequence describing the performed replacements of localizations. Each element of
3390  *          this sequence is a pair whose
3391  *          - the first item is a vector of localization names replaced by the second item,
3392  *          - the second item is a localization name replacing every localization of the first item.
3393  */
3394 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3395 {
3396   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3397   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3398   int i=0;
3399   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3400     {
3401       std::vector< std::string > tmp((*it).size());
3402       int j=0;
3403       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3404         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3405       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3406       ret[i]=p;
3407       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3408       killLocalizationIds(tmp2);
3409     }
3410   changeLocsRefsNamesGen(ret);
3411   return ret;
3412 }
3413
3414 /*!
3415  * Returns number of Gauss points per cell in a given localization.
3416  *  \param [in] locId - an id of the localization of interest.
3417  *  \return int - the number of the Gauss points per cell.
3418  */
3419 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3420 {
3421   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3422 }
3423
3424 /*!
3425  * Returns an id of a localization by its name.
3426  *  \param [in] loc - the localization name of interest.
3427  *  \return int - the id of the localization.
3428  *  \throw If there is no a localization named \a loc.
3429  */
3430 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3431 {
3432   return contentNotNull()->getLocalizationId(loc);
3433 }
3434
3435 /*!
3436  * Returns the name of the MED file.
3437  *  \return const std::string&  - the MED file name.
3438  */
3439 std::string MEDFileFieldGlobsReal::getFileName() const
3440 {
3441   return contentNotNull()->getFileName();
3442 }
3443
3444 /*!
3445  * Returns a localization object by its name.
3446  *  \param [in] locName - the name of the localization of interest.
3447  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3448  *  \throw If there is no a localization named \a locName.
3449  */
3450 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3451 {
3452   return contentNotNull()->getLocalization(locName);
3453 }
3454
3455 /*!
3456  * Returns a localization object by its id.
3457  *  \param [in] locId - the id of the localization of interest.
3458  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3459  *  \throw If there is no a localization with id \a locId.
3460  */
3461 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3462 {
3463   return contentNotNull()->getLocalizationFromId(locId);
3464 }
3465
3466 /*!
3467  * Returns a profile array by its name.
3468  *  \param [in] pflName - the name of the profile of interest.
3469  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3470  *  \throw If there is no a profile named \a pflName.
3471  */
3472 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3473 {
3474   return contentNotNull()->getProfile(pflName);
3475 }
3476
3477 /*!
3478  * Returns a profile array by its id.
3479  *  \param [in] pflId - the id of the profile of interest.
3480  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3481  *  \throw If there is no a profile with id \a pflId.
3482  */
3483 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3484 {
3485   return contentNotNull()->getProfileFromId(pflId);
3486 }
3487
3488 /*!
3489  * Returns a localization object, apt for modification, by its id.
3490  *  \param [in] locId - the id of the localization of interest.
3491  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3492  *          having the id \a locId.
3493  *  \throw If there is no a localization with id \a locId.
3494  */
3495 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3496 {
3497   return contentNotNull()->getLocalizationFromId(locId);
3498 }
3499
3500 /*!
3501  * Returns a localization object, apt for modification, by its name.
3502  *  \param [in] locName - the name of the localization of interest.
3503  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3504  *          having the name \a locName.
3505  *  \throw If there is no a localization named \a locName.
3506  */
3507 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3508 {
3509   return contentNotNull()->getLocalization(locName);
3510 }
3511
3512 /*!
3513  * Returns a profile array, apt for modification, by its name.
3514  *  \param [in] pflName - the name of the profile of interest.
3515  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3516  *  \throw If there is no a profile named \a pflName.
3517  */
3518 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3519 {
3520   return contentNotNull()->getProfile(pflName);
3521 }
3522
3523 /*!
3524  * Returns a profile array, apt for modification, by its id.
3525  *  \param [in] pflId - the id of the profile of interest.
3526  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3527  *  \throw If there is no a profile with id \a pflId.
3528  */
3529 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3530 {
3531   return contentNotNull()->getProfileFromId(pflId);
3532 }
3533
3534 /*!
3535  * Removes profiles given by their ids. No data is updated to track this removal.
3536  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3537  */
3538 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3539 {
3540   contentNotNull()->killProfileIds(pflIds);
3541 }
3542
3543 /*!
3544  * Removes localizations given by their ids. No data is updated to track this removal.
3545  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3546  */
3547 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3548 {
3549   contentNotNull()->killLocalizationIds(locIds);
3550 }
3551
3552 /*!
3553  * Stores a profile array.
3554  *  \param [in] pfl - the profile array to store.
3555  *  \throw If the name of \a pfl is empty.
3556  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3557  *         different ids.
3558  */
3559 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3560 {
3561   contentNotNull()->appendProfile(pfl);
3562 }
3563
3564 /*!
3565  * Adds a new localization of Gauss points.
3566  *  \param [in] locName - the name of the new localization.
3567  *  \param [in] geoType - a geometrical type of the reference cell.
3568  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3569  *         must be \c nbOfNodesPerCell * \c dimOfType.
3570  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3571  *         must be  _wg_.size() * \c dimOfType.
3572  *  \param [in] w - the weights of Gauss points.
3573  *  \throw If \a locName is empty.
3574  *  \throw If a localization with the name \a locName already exists but is
3575  *         different form the new one.
3576  */
3577 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)
3578 {
3579   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3580 }
3581
3582 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3583 {
3584   MEDFileFieldGlobs *g(_globals);
3585   if(!g)
3586     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3587   return g;
3588 }
3589
3590 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3591 {
3592   const MEDFileFieldGlobs *g(_globals);
3593   if(!g)
3594     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3595   return g;
3596 }
3597
3598 //= MEDFileFieldNameScope
3599
3600 MEDFileFieldNameScope::MEDFileFieldNameScope()
3601 {
3602 }
3603
3604 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3605 {
3606 }
3607
3608 /*!
3609  * Returns the name of \a this field.
3610  *  \return std::string - a string containing the field name.
3611  */
3612 std::string MEDFileFieldNameScope::getName() const
3613 {
3614   return _name;
3615 }
3616
3617 /*!
3618  * Sets name of \a this field
3619  *  \param [in] name - the new field name.
3620  */
3621 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3622 {
3623   _name=fieldName;
3624 }
3625
3626 std::string MEDFileFieldNameScope::getDtUnit() const
3627 {
3628   return _dt_unit;
3629 }
3630
3631 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3632 {
3633   _dt_unit=dtUnit;
3634 }
3635
3636 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3637 {
3638   _name=other._name;
3639   _dt_unit=other._dt_unit;
3640 }
3641
3642 //= MEDFileAnyTypeField1TSWithoutSDA
3643
3644 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3645 {
3646   _field_per_mesh.resize(other._field_per_mesh.size());
3647   std::size_t i=0;
3648   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3649     {
3650       if((const MEDFileFieldPerMesh *)*it)
3651         _field_per_mesh[i]=(*it)->deepCpy(this);
3652     }
3653 }
3654
3655 /*!
3656  * Prints a string describing \a this field into a stream. This string is outputted 
3657  * by \c print Python command.
3658  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3659  *  \param [in,out] oss - the out stream.
3660  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3661  *          info id printed, else, not.
3662  */
3663 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3664 {
3665   std::string startOfLine(bkOffset,' ');
3666   oss << startOfLine << "Field ";
3667   if(bkOffset==0)
3668     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3669   oss << "on one time Step ";
3670   if(f1tsId>=0)
3671     oss << "(" << f1tsId << ") ";
3672   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3673   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3674   const DataArray *arr=getUndergroundDataArray();
3675   if(arr)
3676     {
3677       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3678       if(f1tsId<0)
3679         {
3680           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3681           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3682             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3683         }
3684       if(arr->isAllocated())
3685         {
3686           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3687         }
3688       else
3689         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3690     }
3691   else
3692     {
3693       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3694     }
3695   oss << startOfLine << "----------------------" << std::endl;
3696   if(!_field_per_mesh.empty())
3697     {
3698       int i=0;
3699       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3700         {
3701           const MEDFileFieldPerMesh *cur=(*it2);
3702           if(cur)
3703             cur->simpleRepr(bkOffset,oss,i);
3704           else
3705             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3706         }
3707     }
3708   else
3709     {
3710       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3711     }
3712   oss << startOfLine << "----------------------" << std::endl;
3713 }
3714
3715 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3716 {
3717   const DataArray *arr(getUndergroundDataArray());
3718   if(!arr)
3719     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3720   int nbOfCompo=arr->getNumberOfComponents();
3721   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3722   for(int i=0;i<nbOfCompo;i++)
3723     {
3724       ret[i]=deepCpy();
3725       std::vector<int> v(1,i);
3726       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3727       ret[i]->setArray(arr2);
3728     }
3729   return ret;
3730 }
3731
3732 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)
3733 {
3734 }
3735
3736 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3737 {
3738 }
3739
3740 /*!
3741  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3742  * empty. Returns -1 if this in on nodes.
3743  *  \return int - the dimension of \a this.
3744  */
3745 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3746 {
3747   int ret=-2;
3748   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3749     (*it)->getDimension(ret);
3750   return ret;
3751 }
3752
3753 /*!
3754  * Returns the mesh name.
3755  *  \return std::string - a string holding the mesh name.
3756  *  \throw If \c _field_per_mesh.empty()
3757  */
3758 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3759 {
3760   if(_field_per_mesh.empty())
3761     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3762   return _field_per_mesh[0]->getMeshName();
3763 }
3764
3765 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3766 {
3767   std::string oldName(getMeshName());
3768   std::vector< std::pair<std::string,std::string> > v(1);
3769   v[0].first=oldName; v[0].second=newMeshName;
3770   changeMeshNames(v);
3771 }
3772
3773 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3774 {
3775   bool ret=false;
3776   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3777     {
3778       MEDFileFieldPerMesh *cur(*it);
3779       if(cur)
3780         ret=cur->changeMeshNames(modifTab) || ret;
3781     }
3782   return ret;
3783 }
3784
3785 /*!
3786  * Returns the number of iteration of the state of underlying mesh.
3787  *  \return int - the iteration number.
3788  *  \throw If \c _field_per_mesh.empty()
3789  */
3790 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3791 {
3792   if(_field_per_mesh.empty())
3793     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3794   return _field_per_mesh[0]->getMeshIteration();
3795 }
3796
3797 /*!
3798  * Returns the order number of iteration of the state of underlying mesh.
3799  *  \return int - the order number.
3800  *  \throw If \c _field_per_mesh.empty()
3801  */
3802 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3803 {
3804   if(_field_per_mesh.empty())
3805     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3806   return _field_per_mesh[0]->getMeshOrder();
3807 }
3808
3809 /*!
3810  * Checks if \a this field is tagged by a given iteration number and a given
3811  * iteration order number.
3812  *  \param [in] iteration - the iteration number of interest.
3813  *  \param [in] order - the iteration order number of interest.
3814  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3815  *          \a this->getOrder() == \a order.
3816  */
3817 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3818 {
3819   return iteration==_iteration && order==_order;
3820 }
3821
3822 /*!
3823  * Returns number of iteration and order number of iteration when
3824  * \a this field has been calculated.
3825  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3826  *          order number.
3827  */
3828 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3829 {
3830   std::pair<int,int> p;
3831   fillIteration(p);
3832   return p;
3833 }
3834
3835 /*!
3836  * Returns number of iteration and order number of iteration when
3837  * \a this field has been calculated.
3838  *  \param [in,out] p - a pair returning the iteration number and the iteration
3839  *          order number.
3840  */
3841 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3842 {
3843   p.first=_iteration;
3844   p.second=_order;
3845 }
3846
3847 /*!
3848  * Returns all types of spatial discretization of \a this field.
3849  *  \param [in,out] types - a sequence of types of \a this field.
3850  */
3851 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
3852 {
3853   std::set<TypeOfField> types2;
3854   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3855     {
3856       (*it)->fillTypesOfFieldAvailable(types2);
3857     }
3858   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3859   std::copy(types2.begin(),types2.end(),bi);
3860 }
3861
3862 /*!
3863  * Returns all types of spatial discretization of \a this field.
3864  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3865  *          of \a this field.
3866  */
3867 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
3868 {
3869   std::vector<TypeOfField> ret;
3870   fillTypesOfFieldAvailable(ret);
3871   return ret;
3872 }
3873
3874 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3875 {
3876   std::vector<std::string> ret;
3877   std::set<std::string> ret2;
3878   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3879     {
3880       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3881       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3882         if(ret2.find(*it2)==ret2.end())
3883           {
3884             ret.push_back(*it2);
3885             ret2.insert(*it2);
3886           }
3887     }
3888   return ret;
3889 }
3890
3891 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3892 {
3893   std::vector<std::string> ret;
3894   std::set<std::string> ret2;
3895   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3896     {
3897       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3898       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3899         if(ret2.find(*it2)==ret2.end())
3900           {
3901             ret.push_back(*it2);
3902             ret2.insert(*it2);
3903           }
3904     }
3905   return ret;
3906 }
3907
3908 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3909 {
3910   std::vector<std::string> ret;
3911   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3912     {
3913       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3914       ret.insert(ret.end(),tmp.begin(),tmp.end());
3915     }
3916   return ret;
3917 }
3918
3919 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3920 {
3921   std::vector<std::string> ret;
3922   std::set<std::string> ret2;
3923   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3924     {
3925       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3926       ret.insert(ret.end(),tmp.begin(),tmp.end());
3927     }
3928   return ret;
3929 }
3930
3931 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3932 {
3933   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3934     (*it)->changePflsRefsNamesGen(mapOfModif);
3935 }
3936
3937 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3938 {
3939   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3940     (*it)->changeLocsRefsNamesGen(mapOfModif);
3941 }
3942
3943 /*!
3944  * Returns all attributes of parts of \a this field lying on a given mesh.
3945  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3946  * item of every of returned sequences refers to the _i_-th part of \a this field.
3947  * Thus all sequences returned by this method are of the same length equal to number
3948  * of different types of supporting entities.<br>
3949  * A field part can include sub-parts with several different spatial discretizations,
3950  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3951  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3952  * of a nested sequence corresponds to a type of spatial discretization.<br>
3953  * This method allows for iteration over MEDFile DataStructure without any overhead.
3954  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3955  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3956  *          not checked if \a mname == \c NULL).
3957  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3958  *          a field part is returned. 
3959  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3960  *          This sequence is of the same length as \a types. 
3961  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3962  *          discretization. A profile name can be empty.
3963  *          Length of this and of nested sequences is the same as that of \a typesF.
3964  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3965  *          discretization. A localization name can be empty.
3966  *          Length of this and of nested sequences is the same as that of \a typesF.
3967  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3968  *          of ids of tuples within the data array, per each type of spatial
3969  *          discretization within one mesh entity type. 
3970  *          Length of this and of nested sequences is the same as that of \a typesF.
3971  *  \throw If no field is lying on \a mname.
3972  */
3973 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
3974 {
3975   int meshId=0;
3976   if(!mname.empty())
3977     meshId=getMeshIdFromMeshName(mname);
3978   else
3979     if(_field_per_mesh.empty())
3980       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3981   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3982 }
3983
3984 /*!
3985  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
3986  * maximal absolute dimension and values returned via the out parameter \a levs are 
3987  * dimensions relative to the maximal absolute dimension. <br>
3988  * This method is designed for MEDFileField1TS instances that have a discretization
3989  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
3990  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
3991  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
3992  * Only these 3 discretizations will be taken into account here. If \a this is
3993  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
3994  * This method is useful to make the link between the dimension of the underlying mesh
3995  * and the levels of \a this, because it is possible that the highest dimension of \a this
3996  * field is not equal to the dimension of the underlying mesh.
3997  * 
3998  * Let's consider the following case:
3999  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4000  * TETRA4, HEXA8, TRI3 and SEG2.
4001  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4002  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4003  *
4004  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4005  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4006  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4007  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4008  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4009  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4010  * For example<br>
4011  * to retrieve the highest level of
4012  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4013  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4014  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4015  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4016  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4017  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4018  *          not checked if \a mname == \c NULL).
4019  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4020  *          absolute one. They are in decreasing order. This sequence is cleared before
4021  *          filling it in.
4022  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4023  *  \throw If no field is lying on \a mname.
4024  */
4025 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4026 {
4027   levs.clear();
4028   int meshId=getMeshIdFromMeshName(mname);
4029   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4030   std::vector< std::vector<TypeOfField> > typesF;
4031   std::vector< std::vector<std::string> > pfls, locs;
4032   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4033   if(types.empty())
4034     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4035   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4036   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4037     return -1;
4038   st.erase(INTERP_KERNEL::NORM_ERROR);
4039   std::set<int> ret1;
4040   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4041     {
4042       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4043       ret1.insert((int)cm.getDimension());
4044     }
4045   int ret=*std::max_element(ret1.begin(),ret1.end());
4046   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4047   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4048   return ret;
4049 }
4050
4051 /*!
4052  * \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.
4053  * \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.
4054  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4055  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4056  */
4057 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4058 {
4059   int mid=getMeshIdFromMeshName(mName);
4060   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4061 }
4062
4063 /*!
4064  * \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.
4065  * \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.
4066  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4067  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4068  */
4069 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4070 {
4071   int mid=getMeshIdFromMeshName(mName);
4072   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4073 }
4074
4075 /*!
4076  * \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.
4077  */
4078 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4079 {
4080   if(_field_per_mesh.empty())
4081     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4082   if(mName.empty())
4083     return 0;
4084   std::string mName2(mName);
4085   int ret=0;
4086   std::vector<std::string> msg;
4087   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4088     if(mName2==(*it)->getMeshName())
4089       return ret;
4090     else
4091       msg.push_back((*it)->getMeshName());
4092   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4093   oss << "Possible meshes are : ";
4094   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4095     oss << "\"" << (*it2) << "\" ";
4096   throw INTERP_KERNEL::Exception(oss.str().c_str());
4097 }
4098
4099 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4100 {
4101   if(!mesh)
4102     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4103   std::string tmp(mesh->getName());
4104   if(tmp.empty())
4105     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4106   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4107   int i=0;
4108   for(;it!=_field_per_mesh.end();it++,i++)
4109     {
4110       if((*it)->getMeshName()==tmp)
4111         return i;
4112     }
4113   int sz=_field_per_mesh.size();
4114   _field_per_mesh.resize(sz+1);
4115   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4116   return sz;
4117 }
4118
4119 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4120                                                                    MEDFileFieldGlobsReal& glob)
4121 {
4122   bool ret=false;
4123   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4124     {
4125       MEDFileFieldPerMesh *fpm(*it);
4126       if(fpm)
4127         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4128     }
4129   return ret;
4130 }
4131
4132 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4133 {
4134   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4135   std::vector< std::vector<TypeOfField> > typesF;
4136   std::vector< std::vector<std::string> > pfls,locs;
4137   std::vector< std::vector<std::pair<int,int> > > bgEnd=getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs);
4138   std::set<TypeOfField> allEnt;
4139   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4140     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4141       allEnt.insert(*it2);
4142   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4143   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4144   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4145     {
4146       std::vector< std::pair<int,int> > its;
4147       ret[i]=shallowCpy();
4148       int newLgth=ret[i]->keepOnlySpatialDiscretization(*it3,its);
4149       ret[i]->updateData(newLgth,its);
4150     }
4151   return ret;
4152 }
4153
4154 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4155 {
4156   int globalCounter=0;
4157   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4158     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4159   return globalCounter;
4160 }
4161
4162 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4163 {
4164   if(_nb_of_tuples_to_be_allocated>=0)
4165     {
4166       _nb_of_tuples_to_be_allocated=newLgth;
4167       const DataArray *oldArr(getUndergroundDataArray());
4168       if(oldArr)
4169         {
4170           MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4171           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4172           setArray(newArr);
4173           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4174         }
4175       return ;
4176     }
4177   if(_nb_of_tuples_to_be_allocated==-1)
4178     return ;
4179   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4180     {
4181       const DataArray *oldArr(getUndergroundDataArray());
4182       if(!oldArr || !oldArr->isAllocated())
4183         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4184       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4185       newArr->alloc(newLgth,getNumberOfComponents());
4186       if(oldArr)
4187         newArr->copyStringInfoFrom(*oldArr);
4188       int pos=0;
4189       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4190         {
4191           if((*it).second<(*it).first)
4192             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4193           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4194           pos+=(*it).second-(*it).first;
4195         }
4196       setArray(newArr);
4197       return ;
4198     }
4199   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4200 }
4201
4202 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4203 {
4204   if(_field_per_mesh.empty())
4205     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4206   if(_field_per_mesh.size()>1)
4207     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4208   _field_per_mesh[0]->copyOptionsFrom(opts);
4209   _field_per_mesh[0]->writeLL(fid,nasc);
4210 }
4211
4212 /*!
4213  * 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.
4214  * If false is returned the memory allocation is not required.
4215  */
4216 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4217 {
4218   if(_nb_of_tuples_to_be_allocated>=0)
4219     {
4220       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4221       _nb_of_tuples_to_be_allocated=-2;
4222       return true;
4223     }
4224   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4225     return false;
4226   if(_nb_of_tuples_to_be_allocated==-1)
4227     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4228   if(_nb_of_tuples_to_be_allocated<-3)
4229     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4230   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4231 }
4232
4233 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms)
4234 {
4235   med_int numdt,numit;
4236   med_float dt;
4237   med_int nmesh;
4238   med_bool localMesh;
4239   med_int meshnumdt,meshnumit;
4240   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4241   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4242   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4243   if(_iteration!=numdt || _order!=numit)
4244     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4245   _field_per_mesh.resize(nmesh);
4246   //
4247   MEDFileMesh *mm(0);
4248   if(ms)
4249     {
4250       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4251       mm=ms->getMeshWithName(meshNameCpp);
4252     }
4253   //
4254   for(int i=0;i<nmesh;i++)
4255     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm);
4256   _nb_of_tuples_to_be_allocated=0;
4257   for(int i=0;i<nmesh;i++)
4258     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4259 }
4260
4261 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4262 {
4263   allocIfNecessaryTheArrayToReceiveDataFromFile();
4264   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4265     (*it)->loadBigArraysRecursively(fid,nasc);
4266 }
4267
4268 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4269 {
4270   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4271     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4272       (*it)->loadBigArraysRecursively(fid,nasc);
4273 }
4274
4275 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms)
4276 {
4277   loadOnlyStructureOfDataRecursively(fid,nasc,ms);
4278   loadBigArraysRecursively(fid,nasc);
4279 }
4280
4281 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4282 {
4283   DataArray *thisArr(getUndergroundDataArray());
4284   if(thisArr && thisArr->isAllocated())
4285     {
4286       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4287       thisArr->desallocate();
4288     }
4289 }
4290
4291 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4292 {
4293   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4294 }
4295
4296 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4297 {
4298   std::vector<const BigMemoryObject *> ret;
4299   if(getUndergroundDataArray())
4300     ret.push_back(getUndergroundDataArray());
4301   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4302     ret.push_back((const MEDFileFieldPerMesh *)*it);
4303   return ret;
4304 }
4305
4306 /*!
4307  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4308  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4309  * "Sort By Type"), if not, an exception is thrown. 
4310  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4311  *  \param [in] arr - the array of values.
4312  *  \param [in,out] glob - the global data where profiles and localization present in
4313  *          \a field, if any, are added.
4314  *  \throw If the name of \a field is empty.
4315  *  \throw If the data array of \a field is not set.
4316  *  \throw If \a this->_arr is already allocated but has different number of components
4317  *         than \a field.
4318  *  \throw If the underlying mesh of \a field has no name.
4319  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4320  */
4321 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4322 {
4323   const MEDCouplingMesh *mesh=field->getMesh();
4324   //
4325   TypeOfField type=field->getTypeOfField();
4326   std::vector<DataArrayInt *> dummy;
4327   int start=copyTinyInfoFrom(field,arr);
4328   int pos=addNewEntryIfNecessary(mesh);
4329   if(type!=ON_NODES)
4330     {
4331       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4332       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4333     }
4334   else
4335     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4336 }
4337
4338 /*!
4339  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4340  * of a given mesh are used as the support of the given field (a real support is not used). 
4341  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4342  * Order of underlying mesh entities of the given field specified by \a profile parameter
4343  * is not prescribed; this method permutes field values to have them sorted by element
4344  * type as required for writing to MED file. A new profile is added only if no equal
4345  * profile is missing. 
4346  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4347  *  \param [in] arrOfVals - the values of the field \a field used.
4348  *  \param [in] mesh - the supporting mesh of \a field.
4349  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4350  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4351  *  \param [in,out] glob - the global data where profiles and localization present in
4352  *          \a field, if any, are added.
4353  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4354  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4355  *  \throw If the data array of \a field is not set.
4356  *  \throw If \a this->_arr is already allocated but has different number of components
4357  *         than \a field.
4358  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4359  *  \sa setFieldNoProfileSBT()
4360  */
4361 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4362 {
4363   if(!field)
4364     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4365   if(!arrOfVals || !arrOfVals->isAllocated())
4366     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4367   TypeOfField type=field->getTypeOfField();
4368   std::vector<DataArrayInt *> idsInPflPerType;
4369   std::vector<DataArrayInt *> idsPerType;
4370   std::vector<int> code,code2;
4371   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4372   if(type!=ON_NODES)
4373     {
4374       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4375       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4376       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4377       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4378       // start of check
4379       MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2=field->clone(false);
4380       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4381       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4382         {
4383           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4384           throw INTERP_KERNEL::Exception(oss.str().c_str());
4385         }
4386       // end of check
4387       int start=copyTinyInfoFrom(field,arrOfVals);
4388       code2=m->getDistributionOfTypes();
4389       //
4390       int pos=addNewEntryIfNecessary(m);
4391       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4392     }
4393   else
4394     {
4395       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4396         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4397       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4398       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4399       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4400       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4401         {
4402           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4403           throw INTERP_KERNEL::Exception(oss.str().c_str());
4404         }
4405       int start=copyTinyInfoFrom(field,arrOfVals);
4406       int pos=addNewEntryIfNecessary(m);
4407       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4408     }
4409 }
4410
4411 /*!
4412  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4413  */
4414 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4415 {
4416   if(_nb_of_tuples_to_be_allocated>=0)
4417     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 !");
4418   DataArray *arr(getOrCreateAndGetArray());
4419   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4420   _nb_of_tuples_to_be_allocated=-3;
4421 }
4422
4423 /*!
4424  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4425  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4426  * larger by the size of \a field. Returns an id of the first not filled
4427  * tuple of \a this->_arr.
4428  *  \param [in] field - the field to copy the info on components and the name from.
4429  *  \return int - the id of first not initialized tuple of \a this->_arr.
4430  *  \throw If the name of \a field is empty.
4431  *  \throw If the data array of \a field is not set.
4432  *  \throw If \a this->_arr is already allocated but has different number of components
4433  *         than \a field.
4434  */
4435 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4436 {
4437   if(!field)
4438     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4439   std::string name(field->getName());
4440   setName(name.c_str());
4441   setDtUnit(field->getTimeUnit());
4442   if(name.empty())
4443     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4444   if(!arr)
4445     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4446   if(!arr->isAllocated())
4447     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4448   _dt=field->getTime(_iteration,_order);
4449   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4450   if(!getOrCreateAndGetArray()->isAllocated())
4451     {
4452       allocNotFromFile(arr->getNumberOfTuples());
4453       return 0;
4454     }
4455   else
4456     {
4457       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4458       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4459       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4460       _nb_of_tuples_to_be_allocated=-3;
4461       return oldNbOfTuples;
4462     }
4463 }
4464
4465 /*!
4466  * Returns number of components in \a this field
4467  *  \return int - the number of components.
4468  */
4469 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4470 {
4471   return getOrCreateAndGetArray()->getNumberOfComponents();
4472 }
4473
4474 /*!
4475  * Change info on components in \a this.
4476  * \throw If size of \a infos is not equal to the number of components already in \a this.
4477  */
4478 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4479 {
4480   DataArray *arr=getOrCreateAndGetArray();
4481   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4482 }
4483
4484 /*!
4485  * Returns info on components of \a this field.
4486  *  \return const std::vector<std::string>& - a sequence of strings each being an
4487  *          information on _i_-th component.
4488  */
4489 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4490 {
4491   const DataArray *arr=getOrCreateAndGetArray();
4492   return arr->getInfoOnComponents();
4493 }
4494
4495 /*!
4496  * Returns a mutable info on components of \a this field.
4497  *  \return std::vector<std::string>& - a sequence of strings each being an
4498  *          information on _i_-th component.
4499  */
4500 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4501 {
4502   DataArray *arr=getOrCreateAndGetArray();
4503   return arr->getInfoOnComponents();
4504 }
4505
4506 /*!
4507  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4508  *  \param [in] type - a spatial discretization of the new field.
4509  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4510  *  \param [in] mName - a name of the supporting mesh.
4511  *  \param [in] renumPol - specifies how to permute values of the result field according to
4512  *          the optional numbers of cells and nodes, if any. The valid values are
4513  *          - 0 - do not permute.
4514  *          - 1 - permute cells.
4515  *          - 2 - permute nodes.
4516  *          - 3 - permute cells and nodes.
4517  *
4518  *  \param [in] glob - the global data storing profiles and localization.
4519  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4520  *          caller is to delete this field using decrRef() as it is no more needed. 
4521  *  \throw If the MED file is not readable.
4522  *  \throw If there is no mesh named \a mName in the MED file.
4523  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4524  *  \throw If no field of \a this is lying on the mesh \a mName.
4525  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4526  */
4527 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4528 {
4529   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4530   if(mName.empty())
4531     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4532   else
4533     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4534   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4535 }
4536
4537 /*!
4538  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4539  *  \param [in] type - a spatial discretization of the new field.
4540  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4541  *  \param [in] renumPol - specifies how to permute values of the result field according to
4542  *          the optional numbers of cells and nodes, if any. The valid values are
4543  *          - 0 - do not permute.
4544  *          - 1 - permute cells.
4545  *          - 2 - permute nodes.
4546  *          - 3 - permute cells and nodes.
4547  *
4548  *  \param [in] glob - the global data storing profiles and localization.
4549  *  \param [in] mesh - the supporting mesh.
4550  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4551  *          caller is to delete this field using decrRef() as it is no more needed. 
4552  *  \throw If the MED file is not readable.
4553  *  \throw If no field of \a this is lying on \a mesh.
4554  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4555  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4556  */
4557 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4558 {
4559   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4560   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4561   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4562   if(meshDimRelToMax==1)
4563     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4564   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4565 }
4566
4567 /*!
4568  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4569  * given mesh. 
4570  *  \param [in] type - a spatial discretization of the new field.
4571  *  \param [in] mName - a name of the supporting mesh.
4572  *  \param [in] renumPol - specifies how to permute values of the result field according to
4573  *          the optional numbers of cells and nodes, if any. The valid values are
4574  *          - 0 - do not permute.
4575  *          - 1 - permute cells.
4576  *          - 2 - permute nodes.
4577  *          - 3 - permute cells and nodes.
4578  *
4579  *  \param [in] glob - the global data storing profiles and localization.
4580  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4581  *          caller is to delete this field using decrRef() as it is no more needed. 
4582  *  \throw If the MED file is not readable.
4583  *  \throw If there is no mesh named \a mName in the MED file.
4584  *  \throw If there are no mesh entities in the mesh.
4585  *  \throw If no field values of the given \a type are available.
4586  */
4587 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4588 {
4589   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4590   if(mName.empty())
4591     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4592   else
4593     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4594   int absDim=getDimension();
4595   int meshDimRelToMax=absDim-mm->getMeshDimension();
4596   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4597 }
4598
4599 /*!
4600  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4601  *  \param [in] type - a spatial discretization of the new field.
4602  *  \param [in] renumPol - specifies how to permute values of the result field according to
4603  *          the optional numbers of cells and nodes, if any. The valid values are
4604  *          - 0 - do not permute.
4605  *          - 1 - permute cells.
4606  *          - 2 - permute nodes.
4607  *          - 3 - permute cells and nodes.
4608  *
4609  *  \param [in] glob - the global data storing profiles and localization.
4610  *  \param [in] mesh - the supporting mesh.
4611  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4612  *         field according to \a renumPol.
4613  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4614  *         field according to \a renumPol.
4615  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4616  *          caller is to delete this field using decrRef() as it is no more needed. 
4617  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4618  *  \throw If no field of \a this is lying on \a mesh.
4619  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4620  */
4621 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
4622 {
4623   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4624   int meshId=getMeshIdFromMeshName(mesh->getName());
4625   bool isPfl=false;
4626   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4627   switch(renumPol)
4628   {
4629     case 0:
4630       {
4631         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4632         return ret.retn();
4633       }
4634     case 3:
4635     case 1:
4636       {
4637         if(isPfl)
4638           throw INTERP_KERNEL::Exception(msg1);
4639         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4640         if(cellRenum)
4641           {
4642             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4643               {
4644                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4645                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4646                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4647               }
4648             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4649             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4650             std::vector<DataArray *> arrOut2(1,arrOut);
4651             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4652             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4653             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4654           }
4655         if(renumPol==1)
4656           return ret.retn();
4657       }
4658     case 2:
4659       {
4660         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4661         if(isPfl)
4662           throw INTERP_KERNEL::Exception(msg1);
4663         if(nodeRenum)
4664           {
4665             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4666               {
4667                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4668                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4669                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4670               }
4671             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4672             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4673               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4674             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4675           }
4676         return ret.retn();
4677       }
4678     default:
4679       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4680   }
4681 }
4682
4683 /*!
4684  * Returns values and a profile of the field of a given type lying on a given support.
4685  *  \param [in] type - a spatial discretization of the field.
4686  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4687  *  \param [in] mesh - the supporting mesh.
4688  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4689  *          field of interest lies on. If the field lies on all entities of the given
4690  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4691  *          using decrRef() as it is no more needed.  
4692  *  \param [in] glob - the global data storing profiles and localization.
4693  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4694  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4695  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4696  *  \throw If no field of \a this is lying on \a mesh.
4697  *  \throw If no field values of the given \a type are available.
4698  */
4699 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4700 {
4701   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4702   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4703   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4704   ret->setName(nasc.getName().c_str());
4705   return ret.retn();
4706 }
4707
4708 //= MEDFileField1TSWithoutSDA
4709
4710 /*!
4711  * Throws if a given value is not a valid (non-extended) relative dimension.
4712  *  \param [in] meshDimRelToMax - the relative dimension value.
4713  *  \throw If \a meshDimRelToMax > 0.
4714  */
4715 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4716 {
4717   if(meshDimRelToMax>0)
4718     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4719 }
4720
4721 /*!
4722  * Checks if elements of a given mesh are in the order suitable for writing 
4723  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4724  * vector describing types of elements and their number.
4725  *  \param [in] mesh - the mesh to check.
4726  *  \return std::vector<int> - a vector holding for each element type (1) item of
4727  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4728  *          These values are in full-interlace mode.
4729  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4730  */
4731 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4732 {
4733   if(!mesh)
4734     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4735   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4736   int nbOfTypes=geoTypes.size();
4737   std::vector<int> code(3*nbOfTypes);
4738   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4739   arr1->alloc(nbOfTypes,1);
4740   int *arrPtr=arr1->getPointer();
4741   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4742   for(int i=0;i<nbOfTypes;i++,it++)
4743     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4744   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4745   const int *arrPtr2=arr2->getConstPointer();
4746   int i=0;
4747   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4748     {
4749       int pos=arrPtr2[i];
4750       int nbCells=mesh->getNumberOfCellsWithType(*it);
4751       code[3*pos]=(int)(*it);
4752       code[3*pos+1]=nbCells;
4753       code[3*pos+2]=-1;//no profiles
4754     }
4755   std::vector<const DataArrayInt *> idsPerType;//no profiles
4756   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4757   if(da)
4758     {
4759       da->decrRef();
4760       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4761     }
4762   return code;
4763 }
4764
4765 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4766 {
4767   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4768 }
4769
4770 /*!
4771  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4772  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4773  * item of every of returned sequences refers to the _i_-th part of \a this field.
4774  * Thus all sequences returned by this method are of the same length equal to number
4775  * of different types of supporting entities.<br>
4776  * A field part can include sub-parts with several different spatial discretizations,
4777  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4778  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4779  * of a nested sequence corresponds to a type of spatial discretization.<br>
4780  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4781  * The overhead is due to selecting values into new instances of DataArrayDouble.
4782  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4783  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4784  *          not checked if \a mname == \c NULL).
4785  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4786  *          a field part is returned. 
4787  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4788  *          A field part can include sub-parts with several different spatial discretizations,
4789  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4790  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4791  *          This sequence is of the same length as \a types. 
4792  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4793  *          discretization. A profile name can be empty.
4794  *          Length of this and of nested sequences is the same as that of \a typesF.
4795  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4796  *          discretization. A localization name can be empty.
4797  *          Length of this and of nested sequences is the same as that of \a typesF.
4798  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4799  *          per each type of spatial discretization within one mesh entity type.
4800  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4801  *          Length of this and of nested sequences is the same as that of \a typesF.
4802  *  \throw If no field is lying on \a mname.
4803  */
4804 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
4805 {
4806   int meshId=0;
4807   if(!mname.empty())
4808     meshId=getMeshIdFromMeshName(mname);
4809   else
4810     if(_field_per_mesh.empty())
4811       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4812   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4813   int nbOfRet=ret0.size();
4814   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4815   for(int i=0;i<nbOfRet;i++)
4816     {
4817       const std::vector< std::pair<int,int> >& p=ret0[i];
4818       int nbOfRet1=p.size();
4819       ret[i].resize(nbOfRet1);
4820       for(int j=0;j<nbOfRet1;j++)
4821         {
4822           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4823           ret[i][j]=tmp;
4824         }
4825     }
4826   return ret;
4827 }
4828
4829 /*!
4830  * Returns a pointer to the underground DataArrayDouble instance. So the
4831  * caller should not decrRef() it. This method allows for a direct access to the field
4832  * values. This method is quite unusable if there is more than a nodal field or a cell
4833  * field on single geometric cell type. 
4834  *  \return DataArrayDouble * - the pointer to the field values array.
4835  */
4836 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
4837 {
4838   const DataArrayDouble *ret=_arr;
4839   if(ret)
4840     return const_cast<DataArrayDouble *>(ret);
4841   else
4842     return 0;
4843 }
4844
4845 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
4846 {
4847   return TYPE_STR;
4848 }
4849
4850 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
4851 {
4852   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
4853   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4854   ret->deepCpyLeavesFrom(*this);
4855   const DataArrayDouble *arr(_arr);
4856   if(arr)
4857     {
4858       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
4859       ret->setArray(arr2);
4860     }
4861   return ret.retn();
4862 }
4863
4864 /*!
4865  * Returns a pointer to the underground DataArrayDouble instance. So the
4866  * caller should not decrRef() it. This method allows for a direct access to the field
4867  * values. This method is quite unusable if there is more than a nodal field or a cell
4868  * field on single geometric cell type. 
4869  *  \return DataArrayDouble * - the pointer to the field values array.
4870  */
4871 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
4872 {
4873   return getUndergroundDataArrayDouble();
4874 }
4875
4876 /*!
4877  * Returns a pointer to the underground DataArrayDouble instance and a
4878  * sequence describing parameters of a support of each part of \a this field. The
4879  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4880  * direct access to the field values. This method is intended for the field lying on one
4881  * mesh only.
4882  *  \param [in,out] entries - the sequence describing parameters of a support of each
4883  *         part of \a this field. Each item of this sequence consists of two parts. The
4884  *         first part describes a type of mesh entity and an id of discretization of a
4885  *         current field part. The second part describes a range of values [begin,end)
4886  *         within the returned array relating to the current field part.
4887  *  \return DataArrayDouble * - the pointer to the field values array.
4888  *  \throw If the number of underlying meshes is not equal to 1.
4889  *  \throw If no field values are available.
4890  *  \sa getUndergroundDataArray()
4891  */
4892 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4893 {
4894   if(_field_per_mesh.size()!=1)
4895     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4896   if(_field_per_mesh[0]==0)
4897     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4898   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4899   return getUndergroundDataArrayDouble();
4900 }
4901
4902 /*!
4903  * Returns a pointer to the underground DataArrayDouble instance and a
4904  * sequence describing parameters of a support of each part of \a this field. The
4905  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4906  * direct access to the field values. This method is intended for the field lying on one
4907  * mesh only.
4908  *  \param [in,out] entries - the sequence describing parameters of a support of each
4909  *         part of \a this field. Each item of this sequence consists of two parts. The
4910  *         first part describes a type of mesh entity and an id of discretization of a
4911  *         current field part. The second part describes a range of values [begin,end)
4912  *         within the returned array relating to the current field part.
4913  *  \return DataArrayDouble * - the pointer to the field values array.
4914  *  \throw If the number of underlying meshes is not equal to 1.
4915  *  \throw If no field values are available.
4916  *  \sa getUndergroundDataArray()
4917  */
4918 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4919 {
4920   return getUndergroundDataArrayDoubleExt(entries);
4921 }
4922
4923 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4924 {
4925   DataArrayDouble *arr(getOrCreateAndGetArrayDouble());
4926   arr->setInfoAndChangeNbOfCompo(infos);
4927 }
4928
4929 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4930 {
4931 }
4932
4933 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
4934 {
4935   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
4936   ret->deepCpyLeavesFrom(*this);
4937   return ret.retn();
4938 }
4939
4940 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const
4941 {
4942   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
4943   if((const DataArrayDouble *)_arr)
4944     ret->_arr=_arr->deepCpy();
4945   return ret.retn();
4946 }
4947
4948 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
4949 {
4950   if(!arr)
4951     {
4952       _nb_of_tuples_to_be_allocated=-1;
4953       _arr=0;
4954       return ;
4955     }
4956   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
4957   if(!arrC)
4958     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
4959   else
4960     _nb_of_tuples_to_be_allocated=-3;
4961   arrC->incrRef();
4962   _arr=arrC;
4963 }
4964
4965 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4966 {
4967   return DataArrayDouble::New();
4968 }
4969
4970 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
4971 {
4972   DataArrayDouble *ret=_arr;
4973   if(ret)
4974     return ret;
4975   _arr=DataArrayDouble::New();
4976   return _arr;
4977 }
4978
4979 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
4980 {
4981   return getOrCreateAndGetArrayDouble();
4982 }
4983
4984 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
4985 {
4986   const DataArrayDouble *ret=_arr;
4987   if(ret)
4988     return ret;
4989   DataArrayDouble *ret2=DataArrayDouble::New();
4990   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
4991   return ret2;
4992 }
4993
4994 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
4995 {
4996   return getOrCreateAndGetArrayDouble();
4997 }
4998
4999 //= MEDFileIntField1TSWithoutSDA
5000
5001 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5002 {
5003   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5004 }
5005
5006 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5007 {
5008 }
5009
5010 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5011                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5012 {
5013   DataArrayInt *arr(getOrCreateAndGetArrayInt());
5014   arr->setInfoAndChangeNbOfCompo(infos);
5015 }
5016
5017 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5018 {
5019   return TYPE_STR;
5020 }
5021
5022 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5023 {
5024   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5025   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5026   ret->deepCpyLeavesFrom(*this);
5027   const DataArrayInt *arr(_arr);
5028   if(arr)
5029     {
5030       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
5031       ret->setArray(arr2);
5032     }
5033   return ret.retn();
5034 }
5035
5036 /*!
5037  * Returns a pointer to the underground DataArrayInt instance. So the
5038  * caller should not decrRef() it. This method allows for a direct access to the field
5039  * values. This method is quite unusable if there is more than a nodal field or a cell
5040  * field on single geometric cell type. 
5041  *  \return DataArrayInt * - the pointer to the field values array.
5042  */
5043 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
5044 {
5045   return getUndergroundDataArrayInt();
5046 }
5047
5048 /*!
5049  * Returns a pointer to the underground DataArrayInt instance. So the
5050  * caller should not decrRef() it. This method allows for a direct access to the field
5051  * values. This method is quite unusable if there is more than a nodal field or a cell
5052  * field on single geometric cell type. 
5053  *  \return DataArrayInt * - the pointer to the field values array.
5054  */
5055 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5056 {
5057   const DataArrayInt *ret=_arr;
5058   if(ret)
5059     return const_cast<DataArrayInt *>(ret);
5060   else
5061     return 0;
5062 }
5063
5064 /*!
5065  * Returns a pointer to the underground DataArrayInt instance and a
5066  * sequence describing parameters of a support of each part of \a this field. The
5067  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5068  * direct access to the field values. This method is intended for the field lying on one
5069  * mesh only.
5070  *  \param [in,out] entries - the sequence describing parameters of a support of each
5071  *         part of \a this field. Each item of this sequence consists of two parts. The
5072  *         first part describes a type of mesh entity and an id of discretization of a
5073  *         current field part. The second part describes a range of values [begin,end)
5074  *         within the returned array relating to the current field part.
5075  *  \return DataArrayInt * - the pointer to the field values array.
5076  *  \throw If the number of underlying meshes is not equal to 1.
5077  *  \throw If no field values are available.
5078  *  \sa getUndergroundDataArray()
5079  */
5080 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5081 {
5082   return getUndergroundDataArrayIntExt(entries);
5083 }
5084
5085 /*!
5086  * Returns a pointer to the underground DataArrayInt instance and a
5087  * sequence describing parameters of a support of each part of \a this field. The
5088  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5089  * direct access to the field values. This method is intended for the field lying on one
5090  * mesh only.
5091  *  \param [in,out] entries - the sequence describing parameters of a support of each
5092  *         part of \a this field. Each item of this sequence consists of two parts. The
5093  *         first part describes a type of mesh entity and an id of discretization of a
5094  *         current field part. The second part describes a range of values [begin,end)
5095  *         within the returned array relating to the current field part.
5096  *  \return DataArrayInt * - the pointer to the field values array.
5097  *  \throw If the number of underlying meshes is not equal to 1.
5098  *  \throw If no field values are available.
5099  *  \sa getUndergroundDataArray()
5100  */
5101 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5102 {
5103   if(_field_per_mesh.size()!=1)
5104     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5105   if(_field_per_mesh[0]==0)
5106     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5107   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5108   return getUndergroundDataArrayInt();
5109 }
5110
5111 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5112 {
5113   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5114   ret->deepCpyLeavesFrom(*this);
5115   return ret.retn();
5116 }
5117
5118 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const
5119 {
5120   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5121   if((const DataArrayInt *)_arr)
5122     ret->_arr=_arr->deepCpy();
5123   return ret.retn();
5124 }
5125
5126 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5127 {
5128   if(!arr)
5129     {
5130       _nb_of_tuples_to_be_allocated=-1;
5131       _arr=0;
5132       return ;
5133     }
5134   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5135   if(!arrC)
5136     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5137   else
5138     _nb_of_tuples_to_be_allocated=-3;
5139   arrC->incrRef();
5140   _arr=arrC;
5141 }
5142
5143 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5144 {
5145   return DataArrayInt::New();
5146 }
5147
5148 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5149 {
5150   DataArrayInt *ret=_arr;
5151   if(ret)
5152     return ret;
5153   _arr=DataArrayInt::New();
5154   return _arr;
5155 }
5156
5157 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5158 {
5159   return getOrCreateAndGetArrayInt();
5160 }
5161
5162 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5163 {
5164   const DataArrayInt *ret=_arr;
5165   if(ret)
5166     return ret;
5167   DataArrayInt *ret2=DataArrayInt::New();
5168   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5169   return ret2;
5170 }
5171
5172 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5173 {
5174   return getOrCreateAndGetArrayInt();
5175 }
5176
5177 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5178 {
5179 }
5180
5181 //= MEDFileAnyTypeField1TS
5182
5183 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5184 {
5185   med_field_type typcha;
5186   //
5187   std::vector<std::string> infos;
5188   std::string dtunit,fieldName;
5189   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5190   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5191   switch(typcha)
5192   {
5193     case MED_FLOAT64:
5194       {
5195         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5196         break;
5197       }
5198     case MED_INT32:
5199       {
5200         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5201         break;
5202       }
5203     default:
5204       {
5205         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] !";
5206         throw INTERP_KERNEL::Exception(oss.str().c_str());
5207       }
5208   }
5209   ret->setDtUnit(dtunit.c_str());
5210   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5211   //
5212   med_int numdt,numit;
5213   med_float dt;
5214   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5215   ret->setTime(numdt,numit,dt);
5216   ret->_csit=1;
5217   if(loadAll)
5218     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5219   else
5220     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5221   return ret.retn();
5222 }
5223
5224 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5225 try:MEDFileFieldGlobsReal(fileName)
5226 {
5227   MEDFileUtilities::CheckFileForRead(fileName);
5228   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5229   _content=BuildContentFrom(fid,fileName,loadAll,ms);
5230   loadGlobals(fid);
5231 }
5232 catch(INTERP_KERNEL::Exception& e)
5233 {
5234     throw e;
5235 }
5236
5237 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5238 {
5239   med_field_type typcha;
5240   std::vector<std::string> infos;
5241   std::string dtunit;
5242   int iii=-1;
5243   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5244   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5245   switch(typcha)
5246   {
5247     case MED_FLOAT64:
5248       {
5249         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5250         break;
5251       }
5252     case MED_INT32:
5253       {
5254         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5255         break;
5256       }
5257     default:
5258       {
5259         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] !";
5260         throw INTERP_KERNEL::Exception(oss.str().c_str());
5261       }
5262   }
5263   ret->setDtUnit(dtunit.c_str());
5264   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5265   //
5266   if(nbSteps<1)
5267     {
5268       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5269       throw INTERP_KERNEL::Exception(oss.str().c_str());
5270     }
5271   //
5272   med_int numdt,numit;
5273   med_float dt;
5274   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5275   ret->setTime(numdt,numit,dt);
5276   ret->_csit=1;
5277   if(loadAll)
5278     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5279   else
5280     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5281   return ret.retn();
5282 }
5283
5284 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5285 try:MEDFileFieldGlobsReal(fileName)
5286 {
5287   MEDFileUtilities::CheckFileForRead(fileName);
5288   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5289   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
5290   loadGlobals(fid);
5291 }
5292 catch(INTERP_KERNEL::Exception& e)
5293 {
5294     throw e;
5295 }
5296
5297 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5298 {
5299   if(!c)
5300     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5301   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5302     {
5303       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5304       ret->setFileName(fileName);
5305       ret->_content=c; c->incrRef();
5306       return ret.retn();
5307     }
5308   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5309     {
5310       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5311       ret->setFileName(fileName);
5312       ret->_content=c; c->incrRef();
5313       return ret.retn();
5314     }
5315   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5316 }
5317
5318 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5319 {
5320   MEDFileUtilities::CheckFileForRead(fileName);
5321   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5322   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
5323   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5324   ret->loadGlobals(fid);
5325   return ret.retn();
5326 }
5327
5328 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5329 {
5330   MEDFileUtilities::CheckFileForRead(fileName);
5331   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5332   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
5333   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5334   ret->loadGlobals(fid);
5335   return ret.retn();
5336 }
5337
5338 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5339 {
5340   MEDFileUtilities::CheckFileForRead(fileName);
5341   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5342   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll,0);
5343   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5344   ret->loadGlobals(fid);
5345   return ret.retn();
5346 }
5347
5348 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5349 {
5350   med_field_type typcha;
5351   std::vector<std::string> infos;
5352   std::string dtunit;
5353   int iii=-1;
5354   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5355   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5356   switch(typcha)
5357   {
5358     case MED_FLOAT64:
5359       {
5360         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5361         break;
5362       }
5363     case MED_INT32:
5364       {
5365         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5366         break;
5367       }
5368     default:
5369       {
5370         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] !";
5371         throw INTERP_KERNEL::Exception(oss.str().c_str());
5372       }
5373   }
5374   ret->setDtUnit(dtunit.c_str());
5375   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5376   //
5377   bool found=false;
5378   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5379   for(int i=0;i<nbOfStep2 && !found;i++)
5380     {
5381       med_int numdt,numit;
5382       med_float dt;
5383       MEDfieldComputingStepInfo(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt);
5384       if(numdt==iteration && numit==order)
5385         {
5386           found=true;
5387           ret->_csit=i+1;
5388         }
5389       else
5390         dtits[i]=std::pair<int,int>(numdt,numit);
5391     }
5392   if(!found)
5393     {
5394       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5395       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5396         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5397       throw INTERP_KERNEL::Exception(oss.str().c_str());
5398     }
5399   if(loadAll)
5400     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5401   else
5402     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5403   return ret.retn();
5404 }
5405
5406 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5407 try:MEDFileFieldGlobsReal(fileName)
5408 {
5409   MEDFileUtilities::CheckFileForRead(fileName);
5410   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5411   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll,ms);
5412   loadGlobals(fid);
5413 }
5414 catch(INTERP_KERNEL::Exception& e)
5415 {
5416     throw e;
5417 }
5418
5419 /*!
5420  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5421  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5422  *
5423  * \warning this is a shallow copy constructor
5424  */
5425 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5426 {
5427   if(!shallowCopyOfContent)
5428     {
5429       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5430       otherPtr->incrRef();
5431       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5432     }
5433   else
5434     {
5435       _content=other.shallowCpy();
5436     }
5437 }
5438
5439 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)
5440 {
5441   if(checkFieldId)
5442     {
5443       int nbFields=MEDnField(fid);
5444       if(fieldIdCFormat>=nbFields)
5445         {
5446           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5447           throw INTERP_KERNEL::Exception(oss.str().c_str());
5448         }
5449     }
5450   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5451   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5452   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5453   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5454   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5455   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5456   med_bool localMesh;
5457   int nbOfStep;
5458   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5459   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5460   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5461   infos.clear(); infos.resize(ncomp);
5462   for(int j=0;j<ncomp;j++)
5463     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5464   return nbOfStep;
5465 }
5466
5467 /*!
5468  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5469  * 
5470  * \param [out]
5471  * \return in case of success the number of time steps available for the field with name \a fieldName.
5472  */
5473 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)
5474 {
5475   int nbFields=MEDnField(fid);
5476   bool found=false;
5477   std::vector<std::string> fns(nbFields);
5478   int nbOfStep2=-1;
5479   for(int i=0;i<nbFields && !found;i++)
5480     {
5481       std::string tmp;
5482       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5483       fns[i]=tmp;
5484       found=(tmp==fieldName);
5485       if(found)
5486         posCFormat=i;
5487     }
5488   if(!found)
5489     {
5490       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5491       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5492         oss << "\"" << *it << "\" ";
5493       throw INTERP_KERNEL::Exception(oss.str().c_str());
5494     }
5495   return nbOfStep2;
5496 }
5497
5498 /*!
5499  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5500  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5501  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5502  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5503  * to keep a valid instance.
5504  * 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.
5505  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5506  * 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.
5507  *
5508  * \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.
5509  * \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.
5510  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5511  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5512  * \param [in] newLocName is the new localization name.
5513  * \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.
5514  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5515  */
5516 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5517 {
5518   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5519   std::string oldPflName=disc->getProfile();
5520   std::vector<std::string> vv=getPflsReallyUsedMulti();
5521   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5522   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5523     {
5524       disc->setProfile(newPflName);
5525       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5526       pfl->setName(newPflName);
5527     }
5528   else
5529     {
5530       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5531       throw INTERP_KERNEL::Exception(oss.str().c_str());
5532     }
5533 }
5534
5535 /*!
5536  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5537  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5538  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5539  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5540  * to keep a valid instance.
5541  * 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.
5542  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5543  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5544  * 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.
5545  *
5546  * \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.
5547  * \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.
5548  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5549  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5550  * \param [in] newLocName is the new localization name.
5551  * \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.
5552  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5553  */
5554 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5555 {
5556   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5557   std::string oldLocName=disc->getLocalization();
5558   std::vector<std::string> vv=getLocsReallyUsedMulti();
5559   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5560   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5561     {
5562       disc->setLocalization(newLocName);
5563       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5564       loc.setName(newLocName);
5565     }
5566   else
5567     {
5568       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5569       throw INTERP_KERNEL::Exception(oss.str().c_str());
5570     }
5571 }
5572
5573 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5574 {
5575   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5576   if(!ret)
5577     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5578   return ret;
5579 }
5580
5581 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5582 {
5583   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5584   if(!ret)
5585     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5586   return ret;
5587 }
5588
5589 /*!
5590  * Writes \a this field into a MED file specified by its name.
5591  *  \param [in] fileName - the MED file name.
5592  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5593  * - 2 - erase; an existing file is removed.
5594  * - 1 - append; same data should not be present in an existing file.
5595  * - 0 - overwrite; same data present in an existing file is overwritten.
5596  *  \throw If the field name is not set.
5597  *  \throw If no field data is set.
5598  *  \throw If \a mode == 1 and the same data is present in an existing file.
5599  */
5600 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5601 {
5602   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5603   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5604   writeLL(fid);
5605 }
5606
5607 /*!
5608  * This method alloc the arrays and load potentially huge arrays contained in this field.
5609  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5610  * This method can be also called to refresh or reinit values from a file.
5611  * 
5612  * \throw If the fileName is not set or points to a non readable MED file.
5613  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5614  */
5615 void MEDFileAnyTypeField1TS::loadArrays()
5616 {
5617   if(getFileName().empty())
5618     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5619   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5620   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5621 }
5622
5623 /*!
5624  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5625  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5626  * this method does not throw if \a this does not come from file read.
5627  * 
5628  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5629  */
5630 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5631 {
5632   if(!getFileName().empty())
5633     {
5634       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5635       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5636     }
5637 }
5638
5639 /*!
5640  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5641  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5642  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5643  * 
5644  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5645  */
5646 void MEDFileAnyTypeField1TS::unloadArrays()
5647 {
5648   contentNotNullBase()->unloadArrays();
5649 }
5650
5651 /*!
5652  * 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.
5653  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5654  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5655  * 
5656  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5657  */
5658 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5659 {
5660   if(!getFileName().empty())
5661     contentNotNullBase()->unloadArrays();
5662 }
5663
5664 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5665 {
5666   int nbComp=getNumberOfComponents();
5667   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5668   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5669   for(int i=0;i<nbComp;i++)
5670     {
5671       std::string info=getInfo()[i];
5672       std::string c,u;
5673       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5674       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5675       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5676     }
5677   if(getName().empty())
5678     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5679   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5680   writeGlobals(fid,*this);
5681   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5682 }
5683
5684 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5685 {
5686   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5687 }
5688
5689 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5690 {
5691   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5692   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5693   return ret;
5694 }
5695
5696 /*!
5697  * Returns a string describing \a this field. This string is outputted 
5698  * by \c print Python command.
5699  */
5700 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5701 {
5702   std::ostringstream oss;
5703   contentNotNullBase()->simpleRepr(0,oss,-1);
5704   simpleReprGlobs(oss);
5705   return oss.str();
5706 }
5707
5708 /*!
5709  * This method returns all profiles whose name is non empty used.
5710  * \b WARNING If profile is used several times it will be reported \b only \b once.
5711  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5712  */
5713 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5714 {
5715   return contentNotNullBase()->getPflsReallyUsed2();
5716 }
5717
5718 /*!
5719  * This method returns all localizations whose name is non empty used.
5720  * \b WARNING If localization is used several times it will be reported \b only \b once.
5721  */
5722 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5723 {
5724   return contentNotNullBase()->getLocsReallyUsed2();
5725 }
5726
5727 /*!
5728  * This method returns all profiles whose name is non empty used.
5729  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5730  */
5731 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5732 {
5733   return contentNotNullBase()->getPflsReallyUsedMulti2();
5734 }
5735
5736 /*!
5737  * This method returns all localizations whose name is non empty used.
5738  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5739  */
5740 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5741 {
5742   return contentNotNullBase()->getLocsReallyUsedMulti2();
5743 }
5744
5745 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5746 {
5747   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5748 }
5749
5750 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5751 {
5752   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5753 }
5754
5755 int MEDFileAnyTypeField1TS::getDimension() const
5756 {
5757   return contentNotNullBase()->getDimension();
5758 }
5759
5760 int MEDFileAnyTypeField1TS::getIteration() const
5761 {
5762   return contentNotNullBase()->getIteration();
5763 }
5764
5765 int MEDFileAnyTypeField1TS::getOrder() const
5766 {
5767   return contentNotNullBase()->getOrder();
5768 }
5769
5770 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5771 {
5772   return contentNotNullBase()->getTime(iteration,order);
5773 }
5774
5775 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5776 {
5777   contentNotNullBase()->setTime(iteration,order,val);
5778 }
5779
5780 std::string MEDFileAnyTypeField1TS::getName() const
5781 {
5782   return contentNotNullBase()->getName();
5783 }
5784
5785 void MEDFileAnyTypeField1TS::setName(const std::string& name)
5786 {
5787   contentNotNullBase()->setName(name);
5788 }
5789
5790 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5791 {
5792   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5793 }
5794
5795 std::string MEDFileAnyTypeField1TS::getDtUnit() const
5796 {
5797   return contentNotNullBase()->getDtUnit();
5798 }
5799
5800 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
5801 {
5802   contentNotNullBase()->setDtUnit(dtUnit);
5803 }
5804
5805 std::string MEDFileAnyTypeField1TS::getMeshName() const
5806 {
5807   return contentNotNullBase()->getMeshName();
5808 }
5809
5810 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
5811 {
5812   contentNotNullBase()->setMeshName(newMeshName);
5813 }
5814
5815 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
5816 {
5817   return contentNotNullBase()->changeMeshNames(modifTab);
5818 }
5819
5820 int MEDFileAnyTypeField1TS::getMeshIteration() const
5821 {
5822   return contentNotNullBase()->getMeshIteration();
5823 }
5824
5825 int MEDFileAnyTypeField1TS::getMeshOrder() const
5826 {
5827   return contentNotNullBase()->getMeshOrder();
5828 }
5829
5830 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5831 {
5832   return contentNotNullBase()->getNumberOfComponents();
5833 }
5834
5835 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5836 {
5837   return contentNotNullBase()->isDealingTS(iteration,order);
5838 }
5839
5840 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5841 {
5842   return contentNotNullBase()->getDtIt();
5843 }
5844
5845 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5846 {
5847   contentNotNullBase()->fillIteration(p);
5848 }
5849
5850 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
5851 {
5852   contentNotNullBase()->fillTypesOfFieldAvailable(types);
5853 }
5854
5855 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
5856 {
5857   contentNotNullBase()->setInfo(infos);
5858 }
5859
5860 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
5861 {
5862   return contentNotNullBase()->getInfo();
5863 }
5864 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
5865 {
5866   return contentNotNullBase()->getInfo();
5867 }
5868
5869 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
5870 {
5871   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5872 }
5873
5874 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
5875 {
5876   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5877 }
5878
5879 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
5880 {
5881   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
5882 }
5883
5884 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
5885 {
5886   return contentNotNullBase()->getTypesOfFieldAvailable();
5887 }
5888
5889 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,
5890                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
5891 {
5892   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5893 }
5894
5895 /*!
5896  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
5897  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5898  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
5899  */
5900 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
5901 {
5902   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5903   if(!content)
5904     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
5905   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
5906   std::size_t sz(contentsSplit.size());
5907   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5908   for(std::size_t i=0;i<sz;i++)
5909     {
5910       ret[i]=shallowCpy();
5911       ret[i]->_content=contentsSplit[i];
5912     }
5913   return ret;
5914 }
5915
5916 /*!
5917  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
5918  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5919  */
5920 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
5921 {
5922   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5923   if(!content)
5924     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
5925   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitDiscretizations();
5926   std::size_t sz(contentsSplit.size());
5927   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5928   for(std::size_t i=0;i<sz;i++)
5929     {
5930       ret[i]=shallowCpy();
5931       ret[i]->_content=contentsSplit[i];
5932     }
5933   return ret;
5934 }
5935
5936 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const
5937 {
5938   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
5939   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5940     ret->_content=_content->deepCpy();
5941   ret->deepCpyGlobs(*this);
5942   return ret.retn();
5943 }
5944
5945 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
5946 {
5947   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
5948 }
5949
5950 //= MEDFileField1TS
5951
5952 /*!
5953  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5954  * the first field that has been read from a specified MED file.
5955  *  \param [in] fileName - the name of the MED file to read.
5956  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5957  *          is to delete this field using decrRef() as it is no more needed.
5958  *  \throw If reading the file fails.
5959  */
5960 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
5961 {
5962   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,loadAll,0));
5963   ret->contentNotNull();
5964   return ret.retn();
5965 }
5966
5967 /*!
5968  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5969  * a given field that has been read from a specified MED file.
5970  *  \param [in] fileName - the name of the MED file to read.
5971  *  \param [in] fieldName - the name of the field to read.
5972  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5973  *          is to delete this field using decrRef() as it is no more needed.
5974  *  \throw If reading the file fails.
5975  *  \throw If there is no field named \a fieldName in the file.
5976  */
5977 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5978 {
5979   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,loadAll,0));
5980   ret->contentNotNull();
5981   return ret.retn();
5982 }
5983
5984 /*!
5985  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
5986  * a given field that has been read from a specified MED file.
5987  *  \param [in] fileName - the name of the MED file to read.
5988  *  \param [in] fieldName - the name of the field to read.
5989  *  \param [in] iteration - the iteration number of a required time step.
5990  *  \param [in] order - the iteration order number of required time step.
5991  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5992  *          is to delete this field using decrRef() as it is no more needed.
5993  *  \throw If reading the file fails.
5994  *  \throw If there is no field named \a fieldName in the file.
5995  *  \throw If the required time step is missing from the file.
5996  */
5997 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5998 {
5999   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll,0));
6000   ret->contentNotNull();
6001   return ret.retn();
6002 }
6003
6004 /*!
6005  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6006  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6007  *
6008  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6009  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6010  * \warning this is a shallow copy constructor
6011  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6012  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6013  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6014  *          is to delete this field using decrRef() as it is no more needed.
6015  */
6016 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6017 {
6018   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
6019   ret->contentNotNull();
6020   return ret.retn();
6021 }
6022
6023 /*!
6024  * Returns a new empty instance of MEDFileField1TS.
6025  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6026  *          is to delete this field using decrRef() as it is no more needed.
6027  */
6028 MEDFileField1TS *MEDFileField1TS::New()
6029 {
6030   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
6031   ret->contentNotNull();
6032   return ret.retn();
6033 }
6034
6035 /*!
6036  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6037  * following the given input policy.
6038  *
6039  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6040  *                            By default (true) the globals are deeply copied.
6041  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6042  */
6043 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6044 {
6045   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
6046   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6047   if(content)
6048     {
6049       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6050       if(!contc)
6051         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6052       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6053       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6054     }
6055   else
6056     ret=MEDFileIntField1TS::New();
6057   if(isDeepCpyGlobs)
6058     ret->deepCpyGlobs(*this);
6059   else
6060     ret->shallowCpyGlobs(*this);
6061   return ret.retn();
6062 }
6063
6064 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6065 {
6066   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6067   if(!pt)
6068     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6069   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6070   if(!ret)
6071     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 !");
6072   return ret;
6073 }
6074
6075 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6076 {
6077   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6078   if(!pt)
6079     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6080   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6081   if(!ret)
6082     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 !");
6083   return ret;
6084 }
6085
6086 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6087 {
6088   if(!f)
6089     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6090   if(!((DataArray*)arr))
6091     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6092   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6093   if(!arrOutC)
6094     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6095   f->setArray(arrOutC);
6096 }
6097
6098 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6099 {
6100   if(!((DataArray*)arr))
6101     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6102   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6103   if(!arrOutC)
6104     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6105   arrOutC->incrRef();
6106   return arrOutC;
6107 }
6108
6109 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6110 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6111 {
6112 }
6113 catch(INTERP_KERNEL::Exception& e)
6114 { throw e; }
6115
6116 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6117 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6118 {
6119 }
6120 catch(INTERP_KERNEL::Exception& e)
6121 { throw e; }
6122
6123 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6124 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6125 {
6126 }
6127 catch(INTERP_KERNEL::Exception& e)
6128 { throw e; }
6129
6130 /*!
6131  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6132  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6133  *
6134  * \warning this is a shallow copy constructor
6135  */
6136 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6137 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6138 {
6139 }
6140 catch(INTERP_KERNEL::Exception& e)
6141 { throw e; }
6142
6143 MEDFileField1TS::MEDFileField1TS()
6144 {
6145   _content=new MEDFileField1TSWithoutSDA;
6146 }
6147
6148 /*!
6149  * Returns a new MEDCouplingFieldDouble of a given type lying on
6150  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6151  * has not been constructed via file reading, an exception is thrown.
6152  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6153  *  \param [in] type - a spatial discretization of interest.
6154  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6155  *  \param [in] renumPol - specifies how to permute values of the result field according to
6156  *          the optional numbers of cells and nodes, if any. The valid values are
6157  *          - 0 - do not permute.
6158  *          - 1 - permute cells.
6159  *          - 2 - permute nodes.
6160  *          - 3 - permute cells and nodes.
6161  *
6162  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6163  *          caller is to delete this field using decrRef() as it is no more needed. 
6164  *  \throw If \a this field has not been constructed via file reading.
6165  *  \throw If the MED file is not readable.
6166  *  \throw If there is no mesh in the MED file.
6167  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6168  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6169  *  \sa getFieldOnMeshAtLevel()
6170  */
6171 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6172 {
6173   if(getFileName().empty())
6174     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6175   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6176   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6177   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6178   return ret.retn();
6179 }
6180
6181 /*!
6182  * Returns a new MEDCouplingFieldDouble of a given type lying on
6183  * the top level cells of the first mesh in MED file. If \a this field 
6184  * has not been constructed via file reading, an exception is thrown.
6185  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6186  *  \param [in] type - a spatial discretization of interest.
6187  *  \param [in] renumPol - specifies how to permute values of the result field according to
6188  *          the optional numbers of cells and nodes, if any. The valid values are
6189  *          - 0 - do not permute.
6190  *          - 1 - permute cells.
6191  *          - 2 - permute nodes.
6192  *          - 3 - permute cells and nodes.
6193  *
6194  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6195  *          caller is to delete this field using decrRef() as it is no more needed. 
6196  *  \throw If \a this field has not been constructed via file reading.
6197  *  \throw If the MED file is not readable.
6198  *  \throw If there is no mesh in the MED file.
6199  *  \throw If no field values of the given \a type.
6200  *  \throw If no field values lying on the top level support.
6201  *  \sa getFieldAtLevel()
6202  */
6203 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6204 {
6205   if(getFileName().empty())
6206     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6207   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6208   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6209   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6210   return ret.retn();
6211 }
6212
6213 /*!
6214  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6215  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6216  *  \param [in] type - a spatial discretization of the new field.
6217  *  \param [in] mesh - the supporting mesh.
6218  *  \param [in] renumPol - specifies how to permute values of the result field according to
6219  *          the optional numbers of cells and nodes, if any. The valid values are
6220  *          - 0 - do not permute.
6221  *          - 1 - permute cells.
6222  *          - 2 - permute nodes.
6223  *          - 3 - permute cells and nodes.
6224  *
6225  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6226  *          caller is to delete this field using decrRef() as it is no more needed. 
6227  *  \throw If no field of \a this is lying on \a mesh.
6228  *  \throw If the mesh is empty.
6229  *  \throw If no field values of the given \a type are available.
6230  *  \sa getFieldAtLevel()
6231  *  \sa getFieldOnMeshAtLevel() 
6232  */
6233 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6234 {
6235   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6236   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6237   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6238   return ret.retn();
6239 }
6240
6241 /*!
6242  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6243  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6244  *  \param [in] type - a spatial discretization of interest.
6245  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6246  *  \param [in] mesh - the supporting mesh.
6247  *  \param [in] renumPol - specifies how to permute values of the result field according to
6248  *          the optional numbers of cells and nodes, if any. The valid values are
6249  *          - 0 - do not permute.
6250  *          - 1 - permute cells.
6251  *          - 2 - permute nodes.
6252  *          - 3 - permute cells and nodes.
6253  *
6254  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6255  *          caller is to delete this field using decrRef() as it is no more needed. 
6256  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6257  *  \throw If no field of \a this is lying on \a mesh.
6258  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6259  *  \sa getFieldAtLevel()
6260  *  \sa getFieldOnMeshAtLevel() 
6261  */
6262 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6263 {
6264   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6265   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6266   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6267   return ret.retn();
6268 }
6269
6270 /*!
6271  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6272  * This method is called "Old" because in MED3 norm a field has only one meshName
6273  * attached, so this method is for readers of MED2 files. If \a this field 
6274  * has not been constructed via file reading, an exception is thrown.
6275  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6276  *  \param [in] type - a spatial discretization of interest.
6277  *  \param [in] mName - a name of the supporting mesh.
6278  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6279  *  \param [in] renumPol - specifies how to permute values of the result field according to
6280  *          the optional numbers of cells and nodes, if any. The valid values are
6281  *          - 0 - do not permute.
6282  *          - 1 - permute cells.
6283  *          - 2 - permute nodes.
6284  *          - 3 - permute cells and nodes.
6285  *
6286  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6287  *          caller is to delete this field using decrRef() as it is no more needed. 
6288  *  \throw If the MED file is not readable.
6289  *  \throw If there is no mesh named \a mName in the MED file.
6290  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6291  *  \throw If \a this field has not been constructed via file reading.
6292  *  \throw If no field of \a this is lying on the mesh named \a mName.
6293  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6294  *  \sa getFieldAtLevel()
6295  */
6296 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6297 {
6298   if(getFileName().empty())
6299     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6300   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6301   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6302   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6303   return ret.retn();
6304 }
6305
6306 /*!
6307  * Returns values and a profile of the field of a given type lying on a given support.
6308  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6309  *  \param [in] type - a spatial discretization of the field.
6310  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6311  *  \param [in] mesh - the supporting mesh.
6312  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6313  *          field of interest lies on. If the field lies on all entities of the given
6314  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6315  *          using decrRef() as it is no more needed.  
6316  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6317  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6318  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6319  *  \throw If no field of \a this is lying on \a mesh.
6320  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6321  */
6322 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6323 {
6324   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6325   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6326 }
6327
6328 /*!
6329  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6330  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6331  * "Sort By Type"), if not, an exception is thrown. 
6332  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6333  *  \param [in] field - the field to add to \a this.
6334  *  \throw If the name of \a field is empty.
6335  *  \throw If the data array of \a field is not set.
6336  *  \throw If the data array is already allocated but has different number of components
6337  *         than \a field.
6338  *  \throw If the underlying mesh of \a field has no name.
6339  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6340  */
6341 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6342 {
6343   setFileName("");
6344   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6345 }
6346
6347 /*!
6348  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6349  * can be an aggregation of several MEDCouplingFieldDouble instances.
6350  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6351  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6352  * and \a profile.
6353  *
6354  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6355  * A new profile is added only if no equal profile is missing.
6356  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6357  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6358  *  \param [in] mesh - the supporting mesh of \a field.
6359  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6360  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6361  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6362  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6363  *  \throw If the data array of \a field is not set.
6364  *  \throw If the data array of \a this is already allocated but has different number of
6365  *         components than \a field.
6366  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6367  *  \sa setFieldNoProfileSBT()
6368  */
6369 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6370 {
6371   setFileName("");
6372   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6373 }
6374
6375 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6376 {
6377   return new MEDFileField1TS(*this);
6378 }
6379
6380 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6381 {
6382   return contentNotNull()->getUndergroundDataArrayDouble();
6383 }
6384
6385 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6386 {
6387   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6388 }
6389
6390 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6391                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6392 {
6393   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6394 }
6395
6396 //= MEDFileIntField1TS
6397
6398 MEDFileIntField1TS *MEDFileIntField1TS::New()
6399 {
6400   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6401   ret->contentNotNull();
6402   return ret.retn();
6403 }
6404
6405 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6406 {
6407   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6408   ret->contentNotNull();
6409   return ret.retn();
6410 }
6411
6412 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6413 {
6414   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6415   ret->contentNotNull();
6416   return ret.retn();
6417 }
6418
6419 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6420 {
6421   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6422   ret->contentNotNull();
6423   return ret.retn();
6424 }
6425
6426 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6427 {
6428   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6429   ret->contentNotNull();
6430   return ret.retn();
6431 }
6432
6433 MEDFileIntField1TS::MEDFileIntField1TS()
6434 {
6435   _content=new MEDFileIntField1TSWithoutSDA;
6436 }
6437
6438 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6439 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6440 {
6441 }
6442 catch(INTERP_KERNEL::Exception& e)
6443 { throw e; }
6444
6445 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6446 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6447 {
6448 }
6449 catch(INTERP_KERNEL::Exception& e)
6450 { throw e; }
6451
6452 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6453 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6454 {
6455 }
6456 catch(INTERP_KERNEL::Exception& e)
6457 { throw e; }
6458
6459 /*!
6460  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6461  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6462  *
6463  * \warning this is a shallow copy constructor
6464  */
6465 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6466 {
6467 }
6468
6469 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6470 {
6471   return new MEDFileIntField1TS(*this);
6472 }
6473
6474 /*!
6475  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6476  * following the given input policy.
6477  *
6478  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6479  *                            By default (true) the globals are deeply copied.
6480  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6481  */
6482 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6483 {
6484   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6485   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6486   if(content)
6487     {
6488       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6489       if(!contc)
6490         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6491       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6492       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6493     }
6494   else
6495     ret=MEDFileField1TS::New();
6496   if(isDeepCpyGlobs)
6497     ret->deepCpyGlobs(*this);
6498   else
6499     ret->shallowCpyGlobs(*this);
6500   return ret.retn();
6501 }
6502
6503 /*!
6504  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6505  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6506  * "Sort By Type"), if not, an exception is thrown. 
6507  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6508  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6509  *  \param [in] arrOfVals - the values of the field \a field used.
6510  *  \throw If the name of \a field is empty.
6511  *  \throw If the data array of \a field is not set.
6512  *  \throw If the data array is already allocated but has different number of components
6513  *         than \a field.
6514  *  \throw If the underlying mesh of \a field has no name.
6515  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6516  */
6517 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6518 {
6519   setFileName("");
6520   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6521 }
6522
6523 /*!
6524  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6525  * can be an aggregation of several MEDCouplingFieldDouble instances.
6526  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6527  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6528  * and \a profile.
6529  *
6530  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6531  * A new profile is added only if no equal profile is missing.
6532  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6533  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6534  *  \param [in] arrOfVals - the values of the field \a field used.
6535  *  \param [in] mesh - the supporting mesh of \a field.
6536  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6537  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6538  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6539  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6540  *  \throw If the data array of \a field is not set.
6541  *  \throw If the data array of \a this is already allocated but has different number of
6542  *         components than \a field.
6543  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6544  *  \sa setFieldNoProfileSBT()
6545  */
6546 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6547 {
6548   setFileName("");
6549   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6550 }
6551
6552 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6553 {
6554   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6555   if(!pt)
6556     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6557   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6558   if(!ret)
6559     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 !");
6560   return ret;
6561 }
6562
6563 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6564 {
6565   if(getFileName().empty())
6566     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6567   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6568   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6569   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6570   if(!arrOutC)
6571     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6572   arrOut=arrOutC;
6573   return ret.retn();
6574 }
6575
6576 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6577 {
6578   if(!((DataArray *)arr))
6579     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6580   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6581   if(!arrC)
6582     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6583   arrC->incrRef();
6584   return arrC;
6585 }
6586
6587 /*!
6588  * Returns a new MEDCouplingFieldDouble of a given type lying on
6589  * the top level cells of the first mesh in MED file. If \a this field 
6590  * has not been constructed via file reading, an exception is thrown.
6591  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6592  *  \param [in] type - a spatial discretization of interest.
6593  *  \param [out] arrOut - the DataArrayInt containing values of field.
6594  *  \param [in] renumPol - specifies how to permute values of the result field according to
6595  *          the optional numbers of cells and nodes, if any. The valid values are
6596  *          - 0 - do not permute.
6597  *          - 1 - permute cells.
6598  *          - 2 - permute nodes.
6599  *          - 3 - permute cells and nodes.
6600  *
6601  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6602  *          caller is to delete this field using decrRef() as it is no more needed. 
6603  *  \throw If \a this field has not been constructed via file reading.
6604  *  \throw If the MED file is not readable.
6605  *  \throw If there is no mesh in the MED file.
6606  *  \throw If no field values of the given \a type.
6607  *  \throw If no field values lying on the top level support.
6608  *  \sa getFieldAtLevel()
6609  */
6610 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6611 {
6612   if(getFileName().empty())
6613     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6614   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6615   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6616   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6617   return ret.retn();
6618 }
6619
6620 /*!
6621  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6622  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6623  *  \param [in] type - a spatial discretization of the new field.
6624  *  \param [in] mesh - the supporting mesh.
6625  *  \param [out] arrOut - the DataArrayInt containing values of field.
6626  *  \param [in] renumPol - specifies how to permute values of the result field according to
6627  *          the optional numbers of cells and nodes, if any. The valid values are
6628  *          - 0 - do not permute.
6629  *          - 1 - permute cells.
6630  *          - 2 - permute nodes.
6631  *          - 3 - permute cells and nodes.
6632  *
6633  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6634  *          caller is to delete this field using decrRef() as it is no more needed. 
6635  *  \throw If no field of \a this is lying on \a mesh.
6636  *  \throw If the mesh is empty.
6637  *  \throw If no field values of the given \a type are available.
6638  *  \sa getFieldAtLevel()
6639  *  \sa getFieldOnMeshAtLevel() 
6640  */
6641 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6642 {
6643   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6644   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6645   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6646   return ret.retn();
6647 }
6648
6649 /*!
6650  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6651  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6652  *  \param [in] type - a spatial discretization of interest.
6653  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6654  *  \param [out] arrOut - the DataArrayInt containing values of field.
6655  *  \param [in] mesh - the supporting mesh.
6656  *  \param [in] renumPol - specifies how to permute values of the result field according to
6657  *          the optional numbers of cells and nodes, if any. The valid values are
6658  *          - 0 - do not permute.
6659  *          - 1 - permute cells.
6660  *          - 2 - permute nodes.
6661  *          - 3 - permute cells and nodes.
6662  *
6663  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6664  *          caller is to delete this field using decrRef() as it is no more needed. 
6665  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6666  *  \throw If no field of \a this is lying on \a mesh.
6667  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6668  *  \sa getFieldAtLevel()
6669  *  \sa getFieldOnMeshAtLevel() 
6670  */
6671 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6672 {
6673   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6674   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6675   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6676   return ret.retn();
6677 }
6678
6679 /*!
6680  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6681  * This method is called "Old" because in MED3 norm a field has only one meshName
6682  * attached, so this method is for readers of MED2 files. If \a this field 
6683  * has not been constructed via file reading, an exception is thrown.
6684  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6685  *  \param [in] type - a spatial discretization of interest.
6686  *  \param [in] mName - a name of the supporting mesh.
6687  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6688  *  \param [out] arrOut - the DataArrayInt containing values of field.
6689  *  \param [in] renumPol - specifies how to permute values of the result field according to
6690  *          the optional numbers of cells and nodes, if any. The valid values are
6691  *          - 0 - do not permute.
6692  *          - 1 - permute cells.
6693  *          - 2 - permute nodes.
6694  *          - 3 - permute cells and nodes.
6695  *
6696  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6697  *          caller is to delete this field using decrRef() as it is no more needed. 
6698  *  \throw If the MED file is not readable.
6699  *  \throw If there is no mesh named \a mName in the MED file.
6700  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6701  *  \throw If \a this field has not been constructed via file reading.
6702  *  \throw If no field of \a this is lying on the mesh named \a mName.
6703  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6704  *  \sa getFieldAtLevel()
6705  */
6706 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6707 {
6708   if(getFileName().empty())
6709     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6710   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6711   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6712   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6713   return ret.retn();
6714 }
6715
6716 /*!
6717  * Returns values and a profile of the field of a given type lying on a given support.
6718  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6719  *  \param [in] type - a spatial discretization of the field.
6720  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6721  *  \param [in] mesh - the supporting mesh.
6722  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6723  *          field of interest lies on. If the field lies on all entities of the given
6724  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6725  *          using decrRef() as it is no more needed.  
6726  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6727  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6728  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6729  *  \throw If no field of \a this is lying on \a mesh.
6730  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6731  */
6732 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6733 {
6734   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6735   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6736 }
6737
6738 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
6739 {
6740   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6741   if(!pt)
6742     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6743   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6744   if(!ret)
6745     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 !");
6746   return ret;
6747 }
6748
6749 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
6750 {
6751   return contentNotNull()->getUndergroundDataArrayInt();
6752 }
6753
6754 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6755
6756 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6757 {
6758 }
6759
6760 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
6761 {
6762 }
6763
6764 /*!
6765  * \param [in] fieldId field id in C mode
6766  */
6767 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
6768 {
6769   med_field_type typcha;
6770   std::string dtunitOut;
6771   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6772   setDtUnit(dtunitOut.c_str());
6773   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms);
6774 }
6775
6776 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)
6777 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6778 {
6779   setDtUnit(dtunit.c_str());
6780   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms);
6781 }
6782 catch(INTERP_KERNEL::Exception& e)
6783 {
6784     throw e;
6785 }
6786
6787 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
6788 {
6789   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>));
6790   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6791     ret+=(*it).capacity();
6792   return ret;
6793 }
6794
6795 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
6796 {
6797   std::vector<const BigMemoryObject *> ret;
6798   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6799     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
6800   return ret;
6801 }
6802
6803 /*!
6804  * 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
6805  * NULL.
6806  */
6807 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
6808 {
6809   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6810   ret->setInfo(_infos);
6811   int sz=(int)_time_steps.size();
6812   for(const int *id=startIds;id!=endIds;id++)
6813     {
6814       if(*id>=0 && *id<sz)
6815         {
6816           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6817           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6818           if(tse)
6819             {
6820               tse->incrRef();
6821               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6822             }
6823           ret->pushBackTimeStep(tse2);
6824         }
6825       else
6826         {
6827           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6828           oss << " ! Should be in [0," << sz << ") !";
6829           throw INTERP_KERNEL::Exception(oss.str().c_str());
6830         }
6831     }
6832   if(ret->getNumberOfTS()>0)
6833     ret->synchronizeNameScope();
6834   ret->copyNameScope(*this);
6835   return ret.retn();
6836 }
6837
6838 /*!
6839  * 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
6840  * NULL.
6841  */
6842 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
6843 {
6844   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6845   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6846   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6847   ret->setInfo(_infos);
6848   int sz=(int)_time_steps.size();
6849   int j=bg;
6850   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
6851     {
6852       if(j>=0 && j<sz)
6853         {
6854           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
6855           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6856           if(tse)
6857             {
6858               tse->incrRef();
6859               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6860             }
6861           ret->pushBackTimeStep(tse2);
6862         }
6863       else
6864         {
6865           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
6866           oss << " ! Should be in [0," << sz << ") !";
6867           throw INTERP_KERNEL::Exception(oss.str().c_str());
6868         }
6869     }
6870   if(ret->getNumberOfTS()>0)
6871     ret->synchronizeNameScope();
6872   ret->copyNameScope(*this);
6873   return ret.retn();
6874 }
6875
6876 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6877 {
6878   int id=0;
6879   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6880   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6881     {
6882       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6883       if(!cur)
6884         continue;
6885       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6886       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
6887         ids->pushBackSilent(id);
6888     }
6889   return buildFromTimeStepIds(ids->begin(),ids->end());
6890 }
6891
6892 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6893 {
6894   int id=0;
6895   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6896   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6897     {
6898       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6899       if(!cur)
6900         continue;
6901       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6902       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
6903         ids->pushBackSilent(id);
6904     }
6905   return buildFromTimeStepIds(ids->begin(),ids->end());
6906 }
6907
6908 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
6909 {
6910   return _infos;
6911 }
6912
6913 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
6914 {
6915   _infos=info;
6916 }
6917
6918 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
6919 {
6920   int ret=0;
6921   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6922     {
6923       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
6924       if(pt->isDealingTS(iteration,order))
6925         return ret;
6926     }
6927   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
6928   std::vector< std::pair<int,int> > vp=getIterations();
6929   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
6930     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
6931   throw INTERP_KERNEL::Exception(oss.str().c_str());
6932 }
6933
6934 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
6935 {
6936   return *_time_steps[getTimeStepPos(iteration,order)];
6937 }
6938
6939 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
6940 {
6941   return *_time_steps[getTimeStepPos(iteration,order)];
6942 }
6943
6944 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
6945 {
6946   if(_time_steps.empty())
6947     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
6948   return _time_steps[0]->getMeshName();
6949 }
6950
6951 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
6952 {
6953   std::string oldName(getMeshName());
6954   std::vector< std::pair<std::string,std::string> > v(1);
6955   v[0].first=oldName; v[0].second=newMeshName;
6956   changeMeshNames(v);
6957 }
6958
6959 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6960 {
6961   bool ret=false;
6962   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6963     {
6964       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6965       if(cur)
6966         ret=cur->changeMeshNames(modifTab) || ret;
6967     }
6968   return ret;
6969 }
6970
6971 /*!
6972  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
6973  */
6974 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
6975 {
6976   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
6977 }
6978
6979 /*!
6980  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
6981  */
6982 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6983 {
6984   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
6985 }
6986
6987 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
6988                                                                        MEDFileFieldGlobsReal& glob)
6989 {
6990   bool ret=false;
6991   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6992     {
6993       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
6994       if(f1ts)
6995         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
6996     }
6997   return ret;
6998 }
6999
7000 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7001 {
7002   std::string startLine(bkOffset,' ');
7003   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7004   if(fmtsId>=0)
7005     oss << " (" << fmtsId << ")";
7006   oss << " has the following name: \"" << _name << "\"." << std::endl;
7007   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7008   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7009     {
7010       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7011     }
7012   int i=0;
7013   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7014     {
7015       std::string chapter(17,'0'+i);
7016       oss << startLine << chapter << std::endl;
7017       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7018       if(cur)
7019         cur->simpleRepr(bkOffset+2,oss,i);
7020       else
7021         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7022       oss << startLine << chapter << std::endl;
7023     }
7024 }
7025
7026 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7027 {
7028   std::size_t sz=_time_steps.size();
7029   std::vector< std::pair<int,int> > ret(sz);
7030   ret1.resize(sz);
7031   for(std::size_t i=0;i<sz;i++)
7032     {
7033       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7034       if(f1ts)
7035         {
7036           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7037         }
7038       else
7039         {
7040           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7041           throw INTERP_KERNEL::Exception(oss.str().c_str());
7042         }
7043     }
7044   return ret;
7045 }
7046
7047 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7048 {
7049   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7050   if(!tse2)
7051     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7052   checkCoherencyOfType(tse2);
7053   if(_time_steps.empty())
7054     {
7055       setName(tse2->getName().c_str());
7056       setInfo(tse2->getInfo());
7057     }
7058   checkThatComponentsMatch(tse2->getInfo());
7059   _time_steps.push_back(tse);
7060 }
7061
7062 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7063 {
7064   std::size_t nbOfCompo=_infos.size();
7065   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7066     {
7067       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7068       if(cur)
7069         {
7070           if((cur->getInfo()).size()!=nbOfCompo)
7071             {
7072               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7073               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7074               throw INTERP_KERNEL::Exception(oss.str().c_str());
7075             }
7076           cur->copyNameScope(*this);
7077         }
7078     }
7079 }
7080
7081 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms)
7082 {
7083   _time_steps.resize(nbPdt);
7084   for(int i=0;i<nbPdt;i++)
7085     {
7086       std::vector< std::pair<int,int> > ts;
7087       med_int numdt=0,numo=0;
7088       med_int meshIt=0,meshOrder=0;
7089       med_float dt=0.0;
7090       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
7091       switch(fieldTyp)
7092       {
7093         case MED_FLOAT64:
7094           {
7095             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7096             break;
7097           }
7098         case MED_INT32:
7099           {
7100             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7101             break;
7102           }
7103         default:
7104           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7105       }
7106       if(loadAll)
7107         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms);
7108       else
7109         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms);
7110     }
7111 }
7112
7113 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7114 {
7115   if(_time_steps.empty())
7116     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7117   checkThatNbOfCompoOfTSMatchThis();
7118   std::vector<std::string> infos(getInfo());
7119   int nbComp=infos.size();
7120   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7121   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7122   for(int i=0;i<nbComp;i++)
7123     {
7124       std::string info=infos[i];
7125       std::string c,u;
7126       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7127       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7128       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7129     }
7130   if(_name.empty())
7131     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7132   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
7133   int nbOfTS=_time_steps.size();
7134   for(int i=0;i<nbOfTS;i++)
7135     _time_steps[i]->writeLL(fid,opts,*this);
7136 }
7137
7138 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7139 {
7140   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7141     {
7142       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7143       if(elt)
7144         elt->loadBigArraysRecursively(fid,nasc);
7145     }
7146 }
7147
7148 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7149 {
7150   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7151     {
7152       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7153       if(elt)
7154         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7155     }
7156 }
7157
7158 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7159 {
7160   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7161     {
7162       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7163       if(elt)
7164         elt->unloadArrays();
7165     }
7166 }
7167
7168 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7169 {
7170   return _time_steps.size();
7171 }
7172
7173 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7174 {
7175   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7176   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7177     {
7178       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7179       if(tmp)
7180         newTS.push_back(*it);
7181     }
7182   _time_steps=newTS;
7183 }
7184
7185 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7186 {
7187   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7188   int maxId=(int)_time_steps.size();
7189   int ii=0;
7190   std::set<int> idsToDel;
7191   for(const int *id=startIds;id!=endIds;id++,ii++)
7192     {
7193       if(*id>=0 && *id<maxId)
7194         {
7195           idsToDel.insert(*id);
7196         }
7197       else
7198         {
7199           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7200           throw INTERP_KERNEL::Exception(oss.str().c_str());
7201         }
7202     }
7203   for(int iii=0;iii<maxId;iii++)
7204     if(idsToDel.find(iii)==idsToDel.end())
7205       newTS.push_back(_time_steps[iii]);
7206   _time_steps=newTS;
7207 }
7208
7209 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7210 {
7211   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7212   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7213   if(nbOfEntriesToKill==0)
7214     return ;
7215   std::size_t sz=_time_steps.size();
7216   std::vector<bool> b(sz,true);
7217   int j=bg;
7218   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7219     b[j]=false;
7220   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7221   for(std::size_t i=0;i<sz;i++)
7222     if(b[i])
7223       newTS.push_back(_time_steps[i]);
7224   _time_steps=newTS;
7225 }
7226
7227 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7228 {
7229   int ret=0;
7230   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7231   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7232     {
7233       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7234       if(tmp)
7235         {
7236           int it2,ord;
7237           tmp->getTime(it2,ord);
7238           if(it2==iteration && order==ord)
7239             return ret;
7240           else
7241             oss << "(" << it2 << ","  << ord << "), ";
7242         }
7243     }
7244   throw INTERP_KERNEL::Exception(oss.str().c_str());
7245 }
7246
7247 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7248 {
7249   int ret=0;
7250   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7251   oss.precision(15);
7252   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7253     {
7254       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7255       if(tmp)
7256         {
7257           int it2,ord;
7258           double ti=tmp->getTime(it2,ord);
7259           if(fabs(time-ti)<eps)
7260             return ret;
7261           else
7262             oss << ti << ", ";
7263         }
7264     }
7265   throw INTERP_KERNEL::Exception(oss.str().c_str());
7266 }
7267
7268 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7269 {
7270   int lgth=_time_steps.size();
7271   std::vector< std::pair<int,int> > ret(lgth);
7272   for(int i=0;i<lgth;i++)
7273     _time_steps[i]->fillIteration(ret[i]);
7274   return ret;
7275 }
7276
7277 /*!
7278  * 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'
7279  * This method returns two things.
7280  * - The absolute dimension of 'this' in first parameter. 
7281  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7282  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7283  *
7284  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7285  * Only these 3 discretizations will be taken into account here.
7286  *
7287  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7288  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7289  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7290  *
7291  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7292  * 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'.
7293  * 
7294  * Let's consider the typical following case :
7295  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7296  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7297  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7298  *   TETRA4 and SEG2
7299  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7300  *
7301  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7302  * 
7303  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7304  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7305  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7306  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7307  */
7308 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7309 {
7310   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7311 }
7312
7313 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7314 {
7315   if(pos<0 || pos>=(int)_time_steps.size())
7316     {
7317       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7318       throw INTERP_KERNEL::Exception(oss.str().c_str());
7319     }
7320   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7321   if(item==0)
7322     {
7323       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7324       oss << "\nTry to use following method eraseEmptyTS !";
7325       throw INTERP_KERNEL::Exception(oss.str().c_str());
7326     }
7327   return item;
7328 }
7329
7330 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7331 {
7332   if(pos<0 || pos>=(int)_time_steps.size())
7333     {
7334       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7335       throw INTERP_KERNEL::Exception(oss.str().c_str());
7336     }
7337   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7338   if(item==0)
7339     {
7340       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7341       oss << "\nTry to use following method eraseEmptyTS !";
7342       throw INTERP_KERNEL::Exception(oss.str().c_str());
7343     }
7344   return item;
7345 }
7346
7347 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7348 {
7349   std::vector<std::string> ret;
7350   std::set<std::string> ret2;
7351   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7352     {
7353       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7354       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7355         if(ret2.find(*it2)==ret2.end())
7356           {
7357             ret.push_back(*it2);
7358             ret2.insert(*it2);
7359           }
7360     }
7361   return ret;
7362 }
7363
7364 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7365 {
7366   std::vector<std::string> ret;
7367   std::set<std::string> ret2;
7368   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7369     {
7370       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7371       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7372         if(ret2.find(*it2)==ret2.end())
7373           {
7374             ret.push_back(*it2);
7375             ret2.insert(*it2);
7376           }
7377     }
7378   return ret;
7379 }
7380
7381 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7382 {
7383   std::vector<std::string> ret;
7384   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7385     {
7386       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7387       ret.insert(ret.end(),tmp.begin(),tmp.end());
7388     }
7389   return ret;
7390 }
7391
7392 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7393 {
7394   std::vector<std::string> ret;
7395   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7396     {
7397       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7398       ret.insert(ret.end(),tmp.begin(),tmp.end());
7399     }
7400   return ret;
7401 }
7402
7403 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7404 {
7405   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7406     (*it)->changePflsRefsNamesGen2(mapOfModif);
7407 }
7408
7409 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7410 {
7411   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7412     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7413 }
7414
7415 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7416 {
7417   int lgth=_time_steps.size();
7418   std::vector< std::vector<TypeOfField> > ret(lgth);
7419   for(int i=0;i<lgth;i++)
7420     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7421   return ret;
7422 }
7423
7424 /*!
7425  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7426  */
7427 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
7428 {
7429   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7430 }
7431
7432 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const
7433 {
7434   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7435   std::size_t i=0;
7436   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7437     {
7438       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7439         ret->_time_steps[i]=(*it)->deepCpy();
7440     }
7441   return ret.retn();
7442 }
7443
7444 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7445 {
7446   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7447   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7448   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7449   for(std::size_t i=0;i<sz;i++)
7450     {
7451       ret[i]=shallowCpy();
7452       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7453     }
7454   for(std::size_t i=0;i<sz2;i++)
7455     {
7456       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7457       if(ret1.size()!=sz)
7458         {
7459           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7460           throw INTERP_KERNEL::Exception(oss.str().c_str());
7461         }
7462       ts[i]=ret1;
7463     }
7464   for(std::size_t i=0;i<sz;i++)
7465     for(std::size_t j=0;j<sz2;j++)
7466       ret[i]->_time_steps[j]=ts[j][i];
7467   return ret;
7468 }
7469
7470 /*!
7471  * This method splits into discretization each time steps in \a this.
7472  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7473  */
7474 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7475 {
7476   std::size_t sz(_time_steps.size());
7477   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7478   for(std::size_t i=0;i<sz;i++)
7479     {
7480       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7481       if(!timeStep)
7482         {
7483           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7484           throw INTERP_KERNEL::Exception(oss.str().c_str());
7485         }
7486       items[i]=timeStep->splitDiscretizations();  
7487     }
7488   //
7489   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7490   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7491   std::vector< TypeOfField > types;
7492   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7493     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7494       {
7495         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7496         if(ts.size()!=1)
7497           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7498         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7499         if(it2==types.end())
7500           types.push_back(ts[0]);
7501       }
7502   ret.resize(types.size()); ret2.resize(types.size());
7503   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7504     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7505       {
7506         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7507         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7508         ret2[pos].push_back(*it1);
7509       }
7510   for(std::size_t i=0;i<types.size();i++)
7511     {
7512       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=createNew();
7513       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7514         elt->pushBackTimeStep(*it1);//also updates infos in elt
7515       ret[i]=elt;
7516       elt->MEDFileFieldNameScope::operator=(*this);
7517     }
7518   return ret;
7519 }
7520
7521 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7522 {
7523   _name=field->getName();
7524   if(_name.empty())
7525     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7526   if(!arr)
7527     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7528   _infos=arr->getInfoOnComponents();
7529 }
7530
7531 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7532 {
7533   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7534   if(_name!=field->getName())
7535     {
7536       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7537       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7538       throw INTERP_KERNEL::Exception(oss.str().c_str());
7539     }
7540   if(!arr)
7541     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7542   checkThatComponentsMatch(arr->getInfoOnComponents());
7543 }
7544
7545 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7546 {
7547   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7548   if(getInfo().size()!=compos.size())
7549     {
7550       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7551       oss << " number of components of element to append (" << compos.size() << ") !";
7552       throw INTERP_KERNEL::Exception(oss.str().c_str());
7553     }
7554   if(_infos!=compos)
7555     {
7556       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7557       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7558       oss << " But compo in input fields are : ";
7559       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7560       oss << " !";
7561       throw INTERP_KERNEL::Exception(oss.str().c_str());
7562     }
7563 }
7564
7565 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7566 {
7567   std::size_t sz=_infos.size();
7568   int j=0;
7569   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7570     {
7571       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7572       if(elt)
7573         if(elt->getInfo().size()!=sz)
7574           {
7575             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7576             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7577             throw INTERP_KERNEL::Exception(oss.str().c_str());
7578           }
7579     }
7580 }
7581
7582 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7583 {
7584   if(!field)
7585     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7586   if(!_time_steps.empty())
7587     checkCoherencyOfTinyInfo(field,arr);
7588   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7589   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7590   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7591   copyTinyInfoFrom(field,arr);
7592   _time_steps.push_back(obj);
7593 }
7594
7595 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7596 {
7597   if(!field)
7598     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7599   if(!_time_steps.empty())
7600     checkCoherencyOfTinyInfo(field,arr);
7601   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7602   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7603   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7604   copyTinyInfoFrom(field,arr);
7605   _time_steps.push_back(obj);
7606 }
7607
7608 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts)
7609 {
7610   int sz=(int)_time_steps.size();
7611   if(i<0 || i>=sz)
7612     {
7613       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7614       throw INTERP_KERNEL::Exception(oss.str().c_str());
7615     }
7616   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7617   if(tsPtr)
7618     {
7619       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7620         {
7621           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7622           throw INTERP_KERNEL::Exception(oss.str().c_str());
7623         }
7624     }
7625   _time_steps[i]=ts;
7626 }
7627
7628 //= MEDFileFieldMultiTSWithoutSDA
7629
7630 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)
7631 {
7632   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms);
7633 }
7634
7635 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7636 {
7637 }
7638
7639 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7640 {
7641 }
7642
7643 /*!
7644  * \param [in] fieldId field id in C mode
7645  */
7646 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
7647 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms)
7648 {
7649 }
7650 catch(INTERP_KERNEL::Exception& e)
7651 { throw e; }
7652
7653 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)
7654 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms)
7655 {
7656 }
7657 catch(INTERP_KERNEL::Exception& e)
7658 { throw e; }
7659
7660 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7661 {
7662   return new MEDFileField1TSWithoutSDA;
7663 }
7664
7665 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7666 {
7667   if(!f1ts)
7668     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7669   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7670   if(!f1tsC)
7671     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7672 }
7673
7674 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7675 {
7676   return MEDFileField1TSWithoutSDA::TYPE_STR;
7677 }
7678
7679 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7680 {
7681   return new MEDFileFieldMultiTSWithoutSDA(*this);
7682 }
7683
7684 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
7685 {
7686   return new MEDFileFieldMultiTSWithoutSDA;
7687 }
7688
7689 /*!
7690  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7691  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7692  */
7693 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
7694 {
7695   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7696   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7697   if(!myF1TSC)
7698     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7699   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7700 }
7701
7702 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
7703 {
7704   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7705   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7706   int i=0;
7707   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7708     {
7709       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7710       if(eltToConv)
7711         {
7712           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7713           if(!eltToConvC)
7714             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7715           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7716           ret->setIteration(i,elt);
7717         }
7718     }
7719   return ret.retn();
7720 }
7721
7722 //= MEDFileAnyTypeFieldMultiTS
7723
7724 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7725 {
7726 }
7727
7728 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
7729 try:MEDFileFieldGlobsReal(fileName)
7730 {
7731   MEDFileUtilities::CheckFileForRead(fileName);
7732   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7733   _content=BuildContentFrom(fid,fileName,loadAll,ms);
7734   loadGlobals(fid);
7735 }
7736 catch(INTERP_KERNEL::Exception& e)
7737 {
7738     throw e;
7739 }
7740
7741 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7742 {
7743   med_field_type typcha;
7744   std::vector<std::string> infos;
7745   std::string dtunit;
7746   int i=-1;
7747   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7748   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7749   switch(typcha)
7750   {
7751     case MED_FLOAT64:
7752       {
7753         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms);
7754         break;
7755       }
7756     case MED_INT32:
7757       {
7758         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms);
7759         break;
7760       }
7761     default:
7762       {
7763         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] !";
7764         throw INTERP_KERNEL::Exception(oss.str().c_str());
7765       }
7766   }
7767   ret->setDtUnit(dtunit.c_str());
7768   return ret.retn();
7769 }
7770
7771 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
7772 {
7773   med_field_type typcha;
7774   //
7775   std::vector<std::string> infos;
7776   std::string dtunit,fieldName;
7777   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
7778   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7779   switch(typcha)
7780   {
7781     case MED_FLOAT64:
7782       {
7783         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms);
7784         break;
7785       }
7786     case MED_INT32:
7787       {
7788         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms);
7789         break;
7790       }
7791     default:
7792       {
7793         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] !";
7794         throw INTERP_KERNEL::Exception(oss.str().c_str());
7795       }
7796   }
7797   ret->setDtUnit(dtunit.c_str());
7798   return ret.retn();
7799 }
7800
7801 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
7802 {
7803   if(!c)
7804     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
7805   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
7806     {
7807       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
7808       ret->setFileName(fileName);
7809       ret->_content=c;  c->incrRef();
7810       return ret.retn();
7811     }
7812   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
7813     {
7814       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
7815       ret->setFileName(fileName);
7816       ret->_content=c;  c->incrRef();
7817       return ret.retn();
7818     }
7819   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
7820 }
7821
7822 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7823 try:MEDFileFieldGlobsReal(fileName)
7824 {
7825   MEDFileUtilities::CheckFileForRead(fileName);
7826   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7827   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
7828   loadGlobals(fid);
7829 }
7830 catch(INTERP_KERNEL::Exception& e)
7831 {
7832     throw e;
7833 }
7834
7835 //= MEDFileIntFieldMultiTSWithoutSDA
7836
7837 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)
7838 {
7839   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms);
7840 }
7841
7842 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
7843 {
7844 }
7845
7846 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7847 {
7848 }
7849
7850 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)
7851 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms)
7852 {
7853 }
7854 catch(INTERP_KERNEL::Exception& e)
7855 { throw e; }
7856
7857 /*!
7858  * \param [in] fieldId field id in C mode
7859  */
7860 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
7861 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms)
7862 {
7863 }
7864 catch(INTERP_KERNEL::Exception& e)
7865 { throw e; }
7866
7867 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7868 {
7869   return new MEDFileIntField1TSWithoutSDA;
7870 }
7871
7872 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7873 {
7874   if(!f1ts)
7875     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7876   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
7877   if(!f1tsC)
7878     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
7879 }
7880
7881 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
7882 {
7883   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
7884 }
7885
7886 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
7887 {
7888   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
7889 }
7890
7891 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
7892 {
7893   return new MEDFileIntFieldMultiTSWithoutSDA;
7894 }
7895
7896 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
7897 {
7898   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
7899   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7900   int i=0;
7901   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7902     {
7903       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7904       if(eltToConv)
7905         {
7906           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
7907           if(!eltToConvC)
7908             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
7909           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
7910           ret->setIteration(i,elt);
7911         }
7912     }
7913   return ret.retn();
7914 }
7915
7916 //= MEDFileAnyTypeFieldMultiTS
7917
7918 /*!
7919  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
7920  * that has been read from a specified MED file.
7921  *  \param [in] fileName - the name of the MED file to read.
7922  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7923  *          is to delete this field using decrRef() as it is no more needed.
7924  *  \throw If reading the file fails.
7925  */
7926 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
7927 {
7928   MEDFileUtilities::CheckFileForRead(fileName);
7929   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7930   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
7931   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7932   ret->loadGlobals(fid);
7933   return ret.retn();
7934 }
7935
7936 /*!
7937  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
7938  * that has been read from a specified MED file.
7939  *  \param [in] fileName - the name of the MED file to read.
7940  *  \param [in] fieldName - the name of the field to read.
7941  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7942  *          is to delete this field using decrRef() as it is no more needed.
7943  *  \throw If reading the file fails.
7944  *  \throw If there is no field named \a fieldName in the file.
7945  */
7946 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
7947 {
7948   MEDFileUtilities::CheckFileForRead(fileName);
7949   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7950   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
7951   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7952   ret->loadGlobals(fid);
7953   return ret.retn();
7954 }
7955
7956 /*!
7957  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7958  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7959  *
7960  * \warning this is a shallow copy constructor
7961  */
7962 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7963 {
7964   if(!shallowCopyOfContent)
7965     {
7966       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
7967       otherPtr->incrRef();
7968       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
7969     }
7970   else
7971     {
7972       _content=other.shallowCpy();
7973     }
7974 }
7975
7976 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
7977 {
7978   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7979   if(!ret)
7980     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
7981   return ret;
7982 }
7983
7984 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
7985 {
7986   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7987   if(!ret)
7988     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
7989   return ret;
7990 }
7991
7992 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
7993 {
7994   return contentNotNullBase()->getPflsReallyUsed2();
7995 }
7996
7997 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
7998 {
7999   return contentNotNullBase()->getLocsReallyUsed2();
8000 }
8001
8002 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8003 {
8004   return contentNotNullBase()->getPflsReallyUsedMulti2();
8005 }
8006
8007 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8008 {
8009   return contentNotNullBase()->getLocsReallyUsedMulti2();
8010 }
8011
8012 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8013 {
8014   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8015 }
8016
8017 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8018 {
8019   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8020 }
8021
8022 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8023 {
8024   return contentNotNullBase()->getNumberOfTS();
8025 }
8026
8027 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8028 {
8029   contentNotNullBase()->eraseEmptyTS();
8030 }
8031
8032 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8033 {
8034   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8035 }
8036
8037 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8038 {
8039   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8040 }
8041
8042 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8043 {
8044   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8045   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8046   ret->_content=c;
8047   return ret.retn();
8048 }
8049
8050 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8051 {
8052   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8053   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8054   ret->_content=c;
8055   return ret.retn();
8056 }
8057
8058 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8059 {
8060   return contentNotNullBase()->getIterations();
8061 }
8062
8063 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8064 {
8065   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8066     pushBackTimeStep(*it);
8067 }
8068
8069 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8070 {
8071   if(!f1ts)
8072     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8073   checkCoherencyOfType(f1ts);
8074   f1ts->incrRef();
8075   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8076   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8077   c->incrRef();
8078   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8079   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8080     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8081   _content->pushBackTimeStep(cSafe);
8082   appendGlobs(*f1ts,1e-12);
8083 }
8084
8085 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8086 {
8087   contentNotNullBase()->synchronizeNameScope();
8088 }
8089
8090 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8091 {
8092   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8093 }
8094
8095 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8096 {
8097   return contentNotNullBase()->getPosGivenTime(time,eps);
8098 }
8099
8100 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8101 {
8102   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8103 }
8104
8105 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8106 {
8107   return contentNotNullBase()->getTypesOfFieldAvailable();
8108 }
8109
8110 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
8111 {
8112   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8113 }
8114
8115 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8116 {
8117   return contentNotNullBase()->getName();
8118 }
8119
8120 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8121 {
8122   contentNotNullBase()->setName(name);
8123 }
8124
8125 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8126 {
8127   return contentNotNullBase()->getDtUnit();
8128 }
8129
8130 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8131 {
8132   contentNotNullBase()->setDtUnit(dtUnit);
8133 }
8134
8135 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8136 {
8137   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8138 }
8139
8140 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8141 {
8142   return contentNotNullBase()->getTimeSteps(ret1);
8143 }
8144
8145 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8146 {
8147   return contentNotNullBase()->getMeshName();
8148 }
8149
8150 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8151 {
8152   contentNotNullBase()->setMeshName(newMeshName);
8153 }
8154
8155 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8156 {
8157   return contentNotNullBase()->changeMeshNames(modifTab);
8158 }
8159
8160 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8161 {
8162   return contentNotNullBase()->getInfo();
8163 }
8164
8165 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8166 {
8167   return contentNotNullBase()->setInfo(info);
8168 }
8169
8170 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8171 {
8172   const std::vector<std::string> ret=getInfo();
8173   return (int)ret.size();
8174 }
8175
8176 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8177 {
8178   writeGlobals(fid,*this);
8179   contentNotNullBase()->writeLL(fid,*this);
8180 }
8181
8182 /*!
8183  * Writes \a this field into a MED file specified by its name.
8184  *  \param [in] fileName - the MED file name.
8185  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8186  * - 2 - erase; an existing file is removed.
8187  * - 1 - append; same data should not be present in an existing file.
8188  * - 0 - overwrite; same data present in an existing file is overwritten.
8189  *  \throw If the field name is not set.
8190  *  \throw If no field data is set.
8191  *  \throw If \a mode == 1 and the same data is present in an existing file.
8192  */
8193 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8194 {
8195   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8196   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8197   writeLL(fid);
8198 }
8199
8200 /*!
8201  * This method alloc the arrays and load potentially huge arrays contained in this field.
8202  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8203  * This method can be also called to refresh or reinit values from a file.
8204  * 
8205  * \throw If the fileName is not set or points to a non readable MED file.
8206  */
8207 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8208 {
8209   if(getFileName().empty())
8210     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8211   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8212   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8213 }
8214
8215 /*!
8216  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8217  * But once data loaded once, this method does nothing.
8218  * 
8219  * \throw If the fileName is not set or points to a non readable MED file.
8220  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8221  */
8222 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8223 {
8224   if(!getFileName().empty())
8225     {
8226       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8227       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8228     }
8229 }
8230
8231 /*!
8232  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8233  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8234  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8235  * 
8236  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8237  */
8238 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8239 {
8240   contentNotNullBase()->unloadArrays();
8241 }
8242
8243 /*!
8244  * 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.
8245  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8246  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8247  * 
8248  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8249  */
8250 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8251 {
8252   if(!getFileName().empty())
8253     contentNotNullBase()->unloadArrays();
8254 }
8255
8256 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8257 {
8258   std::ostringstream oss;
8259   contentNotNullBase()->simpleRepr(0,oss,-1);
8260   simpleReprGlobs(oss);
8261   return oss.str();
8262 }
8263
8264 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8265 {
8266   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8267 }
8268
8269 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8270 {
8271   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8272   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8273   return ret;
8274 }
8275
8276 /*!
8277  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8278  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8279  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8280  */
8281 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8282 {
8283   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8284   if(!content)
8285     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8286   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8287   std::size_t sz(contentsSplit.size());
8288   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8289   for(std::size_t i=0;i<sz;i++)
8290     {
8291       ret[i]=shallowCpy();
8292       ret[i]->_content=contentsSplit[i];
8293     }
8294   return ret;
8295 }
8296
8297 /*!
8298  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8299  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8300  */
8301 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8302 {
8303   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8304   if(!content)
8305     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8306   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitDiscretizations();
8307   std::size_t sz(contentsSplit.size());
8308   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8309   for(std::size_t i=0;i<sz;i++)
8310     {
8311       ret[i]=shallowCpy();
8312       ret[i]->_content=contentsSplit[i];
8313     }
8314   return ret;
8315 }
8316
8317 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const
8318 {
8319   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8320   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8321     ret->_content=_content->deepCpy();
8322   ret->deepCpyGlobs(*this);
8323   return ret.retn();
8324 }
8325
8326 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8327 {
8328   return _content;
8329 }
8330
8331 /*!
8332  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8333  *  \param [in] iteration - the iteration number of a required time step.
8334  *  \param [in] order - the iteration order number of required time step.
8335  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8336  *          delete this field using decrRef() as it is no more needed.
8337  *  \throw If there is no required time step in \a this field.
8338  */
8339 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8340 {
8341   int pos=getPosOfTimeStep(iteration,order);
8342   return getTimeStepAtPos(pos);
8343 }
8344
8345 /*!
8346  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8347  *  \param [in] time - the time of the time step of interest.
8348  *  \param [in] eps - a precision used to compare time values.
8349  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8350  *          delete this field using decrRef() as it is no more needed.
8351  *  \throw If there is no required time step in \a this field.
8352  */
8353 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8354 {
8355   int pos=getPosGivenTime(time,eps);
8356   return getTimeStepAtPos(pos);
8357 }
8358
8359 /*!
8360  * 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.
8361  * The float64 value of time attached to the pair of integers are not considered here.
8362  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8363  *
8364  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8365  * \throw If there is a null pointer in \a vectFMTS.
8366  */
8367 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8368 {
8369   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8370   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8371   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8372   while(!lstFMTS.empty())
8373     {
8374       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8375       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8376       if(!curIt)
8377         throw INTERP_KERNEL::Exception(msg);
8378       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8379       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8380       elt.push_back(curIt); it=lstFMTS.erase(it);
8381       while(it!=lstFMTS.end())
8382         {
8383           curIt=*it;
8384           if(!curIt)
8385             throw INTERP_KERNEL::Exception(msg);
8386           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8387           if(refIts==curIts)
8388             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8389           else
8390             it++;
8391         }
8392       ret.push_back(elt);
8393     }
8394   return ret;
8395 }
8396
8397 /*!
8398  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8399  * All returned instances in a subvector can be safely loaded, rendered along time
8400  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8401  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8402  * 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).
8403  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8404  * 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.
8405  *
8406  * \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().
8407  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8408  * \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.
8409  * \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.
8410  *
8411  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8412  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8413  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8414  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8415  * \throw If mesh is null.
8416  * \throw If an element in \a vectFMTS is null.
8417  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8418  */
8419 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& fsc)
8420 {
8421   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8422   if(!mesh)
8423     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8424   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8425   if(vectFMTS.empty())
8426     return ret;
8427   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8428   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8429   if(!frstElt)
8430     throw INTERP_KERNEL::Exception(msg);
8431   std::size_t i=0;
8432   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8433   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8434   for(;it!=vectFMTS.end();it++,i++)
8435     {
8436       if(!(*it))
8437         throw INTERP_KERNEL::Exception(msg);
8438       TypeOfField tof0,tof1;
8439       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8440         {
8441           if(tof1!=ON_NODES)
8442             vectFMTSNotNodes.push_back(*it);
8443           else
8444             vectFMTSNodes.push_back(*it);
8445         }
8446       else
8447         vectFMTSNotNodes.push_back(*it);
8448     }
8449   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8450   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8451   ret=retCell;
8452   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8453     {
8454       i=0;
8455       bool isFetched(false);
8456       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8457         {
8458           if((*it0).empty())
8459             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8460           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8461             { ret[i].push_back(*it2); isFetched=true; }
8462         }
8463       if(!isFetched)
8464         {
8465           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8466           MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8467           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8468         }
8469     }
8470   fsc=cmps;
8471   return ret;
8472 }
8473
8474 /*!
8475  * 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.
8476  * \param [out] cmps - same size than the returned vector.
8477  */
8478 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps)
8479 {
8480   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8481   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8482   while(!lstFMTS.empty())
8483     {
8484       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8485       MEDFileAnyTypeFieldMultiTS *ref(*it);
8486       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8487       elt.push_back(ref); it=lstFMTS.erase(it);
8488       MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8489       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8490       while(it!=lstFMTS.end())
8491         {
8492           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8493           if(cmp->isEqual(curIt))
8494             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8495           else
8496             it++;
8497         }
8498       ret.push_back(elt); cmps.push_back(cmp);
8499     }
8500   return ret;
8501 }
8502
8503 /*!
8504  * 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.
8505  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8506  *
8507  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8508  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8509  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8510  * \thorw If \a f0 and \a f1 do not have the same times steps.
8511  * \throw If mesh is null.
8512  * \throw If \a f0 or \a f1 is null.
8513  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8514  */
8515 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8516 {
8517   if(!mesh)
8518     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8519   if(!f0 || !f1)
8520     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8521   if(f0->getMeshName()!=mesh->getName())
8522     {
8523       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8524       throw INTERP_KERNEL::Exception(oss.str().c_str());
8525     }
8526   if(f1->getMeshName()!=mesh->getName())
8527     {
8528       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8529       throw INTERP_KERNEL::Exception(oss.str().c_str());
8530     }
8531   int nts=f0->getNumberOfTS();
8532   if(nts!=f1->getNumberOfTS())
8533     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8534   if(nts==0)
8535     return nts;
8536   for(int i=0;i<nts;i++)
8537     {
8538       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8539       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8540       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8541       if(tofs0.size()!=1 || tofs1.size()!=1)
8542         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8543       if(i!=0)
8544         {
8545           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8546             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8547         }
8548       else
8549         { tof0=tofs0[0]; tof1=tofs1[0]; }
8550       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8551         {
8552           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() << ") !";
8553           throw INTERP_KERNEL::Exception(oss.str().c_str());
8554         }
8555       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8556         {
8557           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() << ") !";
8558           throw INTERP_KERNEL::Exception(oss.str().c_str());
8559         }
8560       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8561         {
8562           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() << ") !";
8563           throw INTERP_KERNEL::Exception(oss.str().c_str());
8564         }
8565     }
8566   return nts;
8567 }
8568
8569 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8570 {
8571   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8572 }
8573
8574 //= MEDFileFieldMultiTS
8575
8576 /*!
8577  * Returns a new empty instance of MEDFileFieldMultiTS.
8578  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8579  *          is to delete this field using decrRef() as it is no more needed.
8580  */
8581 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8582 {
8583   return new MEDFileFieldMultiTS;
8584 }
8585
8586 /*!
8587  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8588  * that has been read from a specified MED file.
8589  *  \param [in] fileName - the name of the MED file to read.
8590  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8591  *          is to delete this field using decrRef() as it is no more needed.
8592  *  \throw If reading the file fails.
8593  */
8594 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8595 {
8596   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
8597   ret->contentNotNull();//to check that content type matches with \a this type.
8598   return ret.retn();
8599 }
8600
8601 /*!
8602  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8603  * that has been read from a specified MED file.
8604  *  \param [in] fileName - the name of the MED file to read.
8605  *  \param [in] fieldName - the name of the field to read.
8606  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8607  *          is to delete this field using decrRef() as it is no more needed.
8608  *  \throw If reading the file fails.
8609  *  \throw If there is no field named \a fieldName in the file.
8610  */
8611 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8612 {
8613   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
8614   ret->contentNotNull();//to check that content type matches with \a this type.
8615   return ret.retn();
8616 }
8617
8618 /*!
8619  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8620  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8621  *
8622  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8623  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8624  * \warning this is a shallow copy constructor
8625  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8626  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8627  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8628  *          is to delete this field using decrRef() as it is no more needed.
8629  */
8630 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8631 {
8632   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8633 }
8634
8635 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8636 {
8637   return new MEDFileFieldMultiTS(*this);
8638 }
8639
8640 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
8641 {
8642   if(!f1ts)
8643     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8644   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8645   if(!f1tsC)
8646     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8647 }
8648
8649 /*!
8650  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8651  * following the given input policy.
8652  *
8653  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8654  *                            By default (true) the globals are deeply copied.
8655  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8656  */
8657 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
8658 {
8659   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
8660   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8661   if(content)
8662     {
8663       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8664       if(!contc)
8665         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8666       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8667       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
8668     }
8669   else
8670     ret=MEDFileIntFieldMultiTS::New();
8671   if(isDeepCpyGlobs)
8672     ret->deepCpyGlobs(*this);
8673   else
8674     ret->shallowCpyGlobs(*this);
8675   return ret.retn();
8676 }
8677
8678 /*!
8679  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
8680  *  \param [in] pos - a time step id.
8681  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8682  *          delete this field using decrRef() as it is no more needed.
8683  *  \throw If \a pos is not a valid time step id.
8684  */
8685 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
8686 {
8687   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8688   if(!item)
8689     {
8690       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8691       throw INTERP_KERNEL::Exception(oss.str().c_str());
8692     }
8693   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
8694   if(itemC)
8695     {
8696       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
8697       ret->shallowCpyGlobs(*this);
8698       return ret.retn();
8699     }
8700   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
8701   throw INTERP_KERNEL::Exception(oss.str().c_str());
8702 }
8703
8704 /*!
8705  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8706  * mesh entities of a given dimension of the first mesh in MED file.
8707  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8708  *  \param [in] type - a spatial discretization of interest.
8709  *  \param [in] iteration - the iteration number of a required time step.
8710  *  \param [in] order - the iteration order number of required time step.
8711  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8712  *  \param [in] renumPol - specifies how to permute values of the result field according to
8713  *          the optional numbers of cells and nodes, if any. The valid values are
8714  *          - 0 - do not permute.
8715  *          - 1 - permute cells.
8716  *          - 2 - permute nodes.
8717  *          - 3 - permute cells and nodes.
8718  *
8719  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8720  *          caller is to delete this field using decrRef() as it is no more needed. 
8721  *  \throw If the MED file is not readable.
8722  *  \throw If there is no mesh in the MED file.
8723  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8724  *  \throw If no field values of the required parameters are available.
8725  */
8726 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
8727 {
8728   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8729   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8730   if(!myF1TSC)
8731     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
8732   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8733   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8734   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8735   return ret.retn();
8736 }
8737
8738 /*!
8739  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8740  * the top level cells of the first mesh in MED file.
8741  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8742  *  \param [in] type - a spatial discretization of interest.
8743  *  \param [in] iteration - the iteration number of a required time step.
8744  *  \param [in] order - the iteration order number of required time step.
8745  *  \param [in] renumPol - specifies how to permute values of the result field according to
8746  *          the optional numbers of cells and nodes, if any. The valid values are
8747  *          - 0 - do not permute.
8748  *          - 1 - permute cells.
8749  *          - 2 - permute nodes.
8750  *          - 3 - permute cells and nodes.
8751  *
8752  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8753  *          caller is to delete this field using decrRef() as it is no more needed. 
8754  *  \throw If the MED file is not readable.
8755  *  \throw If there is no mesh in the MED file.
8756  *  \throw If no field values of the required parameters are available.
8757  */
8758 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
8759 {
8760   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8761   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8762   if(!myF1TSC)
8763     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
8764   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8765   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8766   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8767   return ret.retn();
8768 }
8769
8770 /*!
8771  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8772  * a given support.
8773  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8774  *  \param [in] type - a spatial discretization of interest.
8775  *  \param [in] iteration - the iteration number of a required time step.
8776  *  \param [in] order - the iteration order number of required time step.
8777  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8778  *  \param [in] mesh - the supporting mesh.
8779  *  \param [in] renumPol - specifies how to permute values of the result field according to
8780  *          the optional numbers of cells and nodes, if any. The valid values are
8781  *          - 0 - do not permute.
8782  *          - 1 - permute cells.
8783  *          - 2 - permute nodes.
8784  *          - 3 - permute cells and nodes.
8785  *
8786  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8787  *          caller is to delete this field using decrRef() as it is no more needed. 
8788  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8789  *  \throw If no field of \a this is lying on \a mesh.
8790  *  \throw If no field values of the required parameters are available.
8791  */
8792 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
8793 {
8794   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8795   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8796   if(!myF1TSC)
8797     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8798   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8799   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
8800   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8801   return ret.retn();
8802 }
8803
8804 /*!
8805  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8806  * given support. 
8807  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8808  *  \param [in] type - a spatial discretization of the new field.
8809  *  \param [in] iteration - the iteration number of a required time step.
8810  *  \param [in] order - the iteration order number of required time step.
8811  *  \param [in] mesh - the supporting mesh.
8812  *  \param [in] renumPol - specifies how to permute values of the result field according to
8813  *          the optional numbers of cells and nodes, if any. The valid values are
8814  *          - 0 - do not permute.
8815  *          - 1 - permute cells.
8816  *          - 2 - permute nodes.
8817  *          - 3 - permute cells and nodes.
8818  *
8819  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8820  *          caller is to delete this field using decrRef() as it is no more needed. 
8821  *  \throw If no field of \a this is lying on \a mesh.
8822  *  \throw If no field values of the required parameters are available.
8823  */
8824 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
8825 {
8826   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8827   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8828   if(!myF1TSC)
8829     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8830   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8831   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
8832   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8833   return ret.retn();
8834 }
8835
8836 /*!
8837  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
8838  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8839  * This method is useful for MED2 file format when field on different mesh was autorized.
8840  */
8841 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
8842 {
8843   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8844   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8845   if(!myF1TSC)
8846     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
8847   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8848   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
8849   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8850   return ret.retn();
8851 }
8852
8853 /*!
8854  * Returns values and a profile of the field of a given type, of a given time step,
8855  * lying on a given support.
8856  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8857  *  \param [in] type - a spatial discretization of the field.
8858  *  \param [in] iteration - the iteration number of a required time step.
8859  *  \param [in] order - the iteration order number of required time step.
8860  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8861  *  \param [in] mesh - the supporting mesh.
8862  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8863  *          field of interest lies on. If the field lies on all entities of the given
8864  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8865  *          using decrRef() as it is no more needed.  
8866  *  \param [in] glob - the global data storing profiles and localization.
8867  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
8868  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8869  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8870  *  \throw If no field of \a this is lying on \a mesh.
8871  *  \throw If no field values of the required parameters are available.
8872  */
8873 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
8874 {
8875   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8876   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8877   if(!myF1TSC)
8878     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
8879   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8880   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
8881 }
8882
8883 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
8884 {
8885   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8886   if(!pt)
8887     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
8888   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
8889   if(!ret)
8890     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 !");
8891   return ret;
8892 }
8893
8894 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
8895 {
8896   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8897   if(!pt)
8898     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
8899   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
8900   if(!ret)
8901     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 !");
8902   return ret;
8903 }
8904
8905 /*!
8906  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8907  * the given field is checked if its elements are sorted suitable for writing to MED file
8908  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8909  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8910  *  \param [in] field - the field to add to \a this.
8911  *  \throw If the name of \a field is empty.
8912  *  \throw If the data array of \a field is not set.
8913  *  \throw If existing time steps have different name or number of components than \a field.
8914  *  \throw If the underlying mesh of \a field has no name.
8915  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8916  */
8917 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
8918 {
8919   const DataArrayDouble *arr=0;
8920   if(field)
8921     arr=field->getArray();
8922   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
8923 }
8924
8925 /*!
8926  * Adds a MEDCouplingFieldDouble to \a this as another time step.
8927  * The mesh support of input parameter \a field is ignored here, it can be NULL.
8928  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
8929  * and \a profile.
8930  *
8931  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
8932  * A new profile is added only if no equal profile is missing.
8933  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8934  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
8935  *  \param [in] mesh - the supporting mesh of \a field.
8936  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
8937  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8938  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8939  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8940  *  \throw If the data array of \a field is not set.
8941  *  \throw If the data array of \a this is already allocated but has different number of
8942  *         components than \a field.
8943  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8944  *  \sa setFieldNoProfileSBT()
8945  */
8946 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
8947 {
8948   const DataArrayDouble *arr=0;
8949   if(field)
8950     arr=field->getArray();
8951   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
8952 }
8953
8954 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
8955 {
8956   _content=new MEDFileFieldMultiTSWithoutSDA;
8957 }
8958
8959 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8960 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
8961 {
8962 }
8963 catch(INTERP_KERNEL::Exception& e)
8964 { throw e; }
8965
8966 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
8967 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms)
8968 {
8969 }
8970 catch(INTERP_KERNEL::Exception& e)
8971 { throw e; }
8972
8973 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8974 {
8975 }
8976
8977 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
8978 {
8979   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
8980 }
8981
8982 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
8983 {
8984   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8985 }
8986
8987 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
8988 {
8989   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
8990 }
8991
8992 //= MEDFileAnyTypeFieldMultiTSIterator
8993
8994 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
8995 {
8996   if(fmts)
8997     {
8998       fmts->incrRef();
8999       _nb_iter=fmts->getNumberOfTS();
9000     }
9001 }
9002
9003 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9004 {
9005 }
9006
9007 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9008 {
9009   if(_iter_id<_nb_iter)
9010     {
9011       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9012       if(fmts)
9013         return fmts->getTimeStepAtPos(_iter_id++);
9014       else
9015         return 0;
9016     }
9017   else
9018     return 0;
9019 }
9020
9021 //= MEDFileIntFieldMultiTS
9022
9023 /*!
9024  * Returns a new empty instance of MEDFileFieldMultiTS.
9025  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9026  *          is to delete this field using decrRef() as it is no more needed.
9027  */
9028 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9029 {
9030   return new MEDFileIntFieldMultiTS;
9031 }
9032
9033 /*!
9034  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9035  * that has been read from a specified MED file.
9036  *  \param [in] fileName - the name of the MED file to read.
9037  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9038  *          is to delete this field using decrRef() as it is no more needed.
9039  *  \throw If reading the file fails.
9040  */
9041 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9042 {
9043   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9044   ret->contentNotNull();//to check that content type matches with \a this type.
9045   return ret.retn();
9046 }
9047
9048 /*!
9049  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9050  * that has been read from a specified MED file.
9051  *  \param [in] fileName - the name of the MED file to read.
9052  *  \param [in] fieldName - the name of the field to read.
9053  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9054  *          is to delete this field using decrRef() as it is no more needed.
9055  *  \throw If reading the file fails.
9056  *  \throw If there is no field named \a fieldName in the file.
9057  */
9058 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9059 {
9060   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9061   ret->contentNotNull();//to check that content type matches with \a this type.
9062   return ret.retn();
9063 }
9064
9065 /*!
9066  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9067  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9068  *
9069  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9070  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9071  * \warning this is a shallow copy constructor
9072  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9073  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9074  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9075  *          is to delete this field using decrRef() as it is no more needed.
9076  */
9077 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9078 {
9079   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9080 }
9081
9082 /*!
9083  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9084  * following the given input policy.
9085  *
9086  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9087  *                            By default (true) the globals are deeply copied.
9088  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9089  */
9090 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9091 {
9092   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
9093   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9094   if(content)
9095     {
9096       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9097       if(!contc)
9098         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9099       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9100       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9101     }
9102   else
9103     ret=MEDFileFieldMultiTS::New();
9104   if(isDeepCpyGlobs)
9105     ret->deepCpyGlobs(*this);
9106   else
9107     ret->shallowCpyGlobs(*this);
9108   return ret.retn();
9109 }
9110
9111 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9112 {
9113   return new MEDFileIntFieldMultiTS(*this);
9114 }
9115
9116 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9117 {
9118   if(!f1ts)
9119     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9120   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9121   if(!f1tsC)
9122     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9123 }
9124
9125 /*!
9126  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9127  * mesh entities of a given dimension of the first mesh in MED file.
9128  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9129  *  \param [in] type - a spatial discretization of interest.
9130  *  \param [in] iteration - the iteration number of a required time step.
9131  *  \param [in] order - the iteration order number of required time step.
9132  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9133  *  \param [out] arrOut - the DataArrayInt containing values of field.
9134  *  \param [in] renumPol - specifies how to permute values of the result field according to
9135  *          the optional numbers of cells and nodes, if any. The valid values are
9136  *          - 0 - do not permute.
9137  *          - 1 - permute cells.
9138  *          - 2 - permute nodes.
9139  *          - 3 - permute cells and nodes.
9140  *
9141  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9142  *          caller is to delete this field using decrRef() as it is no more needed. 
9143  *  \throw If the MED file is not readable.
9144  *  \throw If there is no mesh in the MED file.
9145  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9146  *  \throw If no field values of the required parameters are available.
9147  */
9148 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9149 {
9150   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9151   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9152   if(!myF1TSC)
9153     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9154   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9155   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9156   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9157   return ret.retn();
9158 }
9159
9160 /*!
9161  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9162  * the top level cells of the first mesh in MED file.
9163  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9164  *  \param [in] type - a spatial discretization of interest.
9165  *  \param [in] iteration - the iteration number of a required time step.
9166  *  \param [in] order - the iteration order number of required time step.
9167  *  \param [out] arrOut - the DataArrayInt containing values of field.
9168  *  \param [in] renumPol - specifies how to permute values of the result field according to
9169  *          the optional numbers of cells and nodes, if any. The valid values are
9170  *          - 0 - do not permute.
9171  *          - 1 - permute cells.
9172  *          - 2 - permute nodes.
9173  *          - 3 - permute cells and nodes.
9174  *
9175  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9176  *          caller is to delete this field using decrRef() as it is no more needed. 
9177  *  \throw If the MED file is not readable.
9178  *  \throw If there is no mesh in the MED file.
9179  *  \throw If no field values of the required parameters are available.
9180  */
9181 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9182 {
9183   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9184   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9185   if(!myF1TSC)
9186     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9187   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9188   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9189   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9190   return ret.retn();
9191 }
9192
9193 /*!
9194  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9195  * a given support.
9196  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9197  *  \param [in] type - a spatial discretization of interest.
9198  *  \param [in] iteration - the iteration number of a required time step.
9199  *  \param [in] order - the iteration order number of required time step.
9200  *  \param [out] arrOut - the DataArrayInt containing values of field.
9201  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9202  *  \param [in] mesh - the supporting mesh.
9203  *  \param [in] renumPol - specifies how to permute values of the result field according to
9204  *          the optional numbers of cells and nodes, if any. The valid values are
9205  *          - 0 - do not permute.
9206  *          - 1 - permute cells.
9207  *          - 2 - permute nodes.
9208  *          - 3 - permute cells and nodes.
9209  *
9210  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9211  *          caller is to delete this field using decrRef() as it is no more needed. 
9212  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9213  *  \throw If no field of \a this is lying on \a mesh.
9214  *  \throw If no field values of the required parameters are available.
9215  */
9216 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9217 {
9218   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9219   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9220   if(!myF1TSC)
9221     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9222   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9223   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9224   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9225   return ret.retn();
9226 }
9227
9228 /*!
9229  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9230  * given support. 
9231  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9232  *  \param [in] type - a spatial discretization of the new field.
9233  *  \param [in] iteration - the iteration number of a required time step.
9234  *  \param [in] order - the iteration order number of required time step.
9235  *  \param [in] mesh - the supporting mesh.
9236  *  \param [out] arrOut - the DataArrayInt containing values of field.
9237  *  \param [in] renumPol - specifies how to permute values of the result field according to
9238  *          the optional numbers of cells and nodes, if any. The valid values are
9239  *          - 0 - do not permute.
9240  *          - 1 - permute cells.
9241  *          - 2 - permute nodes.
9242  *          - 3 - permute cells and nodes.
9243  *
9244  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9245  *          caller is to delete this field using decrRef() as it is no more needed. 
9246  *  \throw If no field of \a this is lying on \a mesh.
9247  *  \throw If no field values of the required parameters are available.
9248  */
9249 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9250 {
9251   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9252   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9253   if(!myF1TSC)
9254     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9255   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9256   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9257   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9258   return ret.retn();
9259 }
9260
9261 /*!
9262  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9263  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9264  * This method is useful for MED2 file format when field on different mesh was autorized.
9265  */
9266 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9267 {
9268   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9269   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9270   if(!myF1TSC)
9271     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9272   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9273   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9274   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9275   return ret.retn();
9276 }
9277
9278 /*!
9279  * Returns values and a profile of the field of a given type, of a given time step,
9280  * lying on a given support.
9281  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9282  *  \param [in] type - a spatial discretization of the field.
9283  *  \param [in] iteration - the iteration number of a required time step.
9284  *  \param [in] order - the iteration order number of required time step.
9285  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9286  *  \param [in] mesh - the supporting mesh.
9287  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9288  *          field of interest lies on. If the field lies on all entities of the given
9289  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9290  *          using decrRef() as it is no more needed.  
9291  *  \param [in] glob - the global data storing profiles and localization.
9292  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9293  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9294  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9295  *  \throw If no field of \a this is lying on \a mesh.
9296  *  \throw If no field values of the required parameters are available.
9297  */
9298 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9299 {
9300   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9301   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9302   if(!myF1TSC)
9303     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9304   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9305   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9306 }
9307
9308 /*!
9309  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9310  *  \param [in] pos - a time step id.
9311  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9312  *          delete this field using decrRef() as it is no more needed.
9313  *  \throw If \a pos is not a valid time step id.
9314  */
9315 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9316 {
9317   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9318   if(!item)
9319     {
9320       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9321       throw INTERP_KERNEL::Exception(oss.str().c_str());
9322     }
9323   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9324   if(itemC)
9325     {
9326       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9327       ret->shallowCpyGlobs(*this);
9328       return ret.retn();
9329     }
9330   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9331   throw INTERP_KERNEL::Exception(oss.str().c_str());
9332 }
9333
9334 /*!
9335  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9336  * the given field is checked if its elements are sorted suitable for writing to MED file
9337  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9338  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9339  *  \param [in] field - the field to add to \a this.
9340  *  \throw If the name of \a field is empty.
9341  *  \throw If the data array of \a field is not set.
9342  *  \throw If existing time steps have different name or number of components than \a field.
9343  *  \throw If the underlying mesh of \a field has no name.
9344  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9345  */
9346 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9347 {
9348   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9349 }
9350
9351 /*!
9352  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9353  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9354  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9355  * and \a profile.
9356  *
9357  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9358  * A new profile is added only if no equal profile is missing.
9359  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9360  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9361  *  \param [in] arrOfVals - the values of the field \a field used.
9362  *  \param [in] mesh - the supporting mesh of \a field.
9363  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9364  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9365  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9366  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9367  *  \throw If the data array of \a field is not set.
9368  *  \throw If the data array of \a this is already allocated but has different number of
9369  *         components than \a field.
9370  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9371  *  \sa setFieldNoProfileSBT()
9372  */
9373 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9374 {
9375   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9376 }
9377
9378 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9379 {
9380   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9381   if(!pt)
9382     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9383   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9384   if(!ret)
9385     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 !");
9386   return ret;
9387 }
9388
9389 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9390 {
9391   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9392   if(!pt)
9393     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9394   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9395   if(!ret)
9396     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 !");
9397   return ret;
9398 }
9399
9400 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9401 {
9402   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9403 }
9404
9405 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9406 {
9407 }
9408
9409 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9410 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9411 {
9412 }
9413 catch(INTERP_KERNEL::Exception& e)
9414 { throw e; }
9415
9416 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
9417 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms)
9418 {
9419 }
9420 catch(INTERP_KERNEL::Exception& e)
9421 { throw e; }
9422
9423 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9424 {
9425   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9426 }
9427
9428 //= MEDFileFields
9429
9430 MEDFileFields *MEDFileFields::New()
9431 {
9432   return new MEDFileFields;
9433 }
9434
9435 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9436 {
9437   return new MEDFileFields(fileName,loadAll,0);
9438 }
9439
9440 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9441 {
9442   return new MEDFileFields(fileName,loadAll,ms);
9443 }
9444
9445 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9446 {
9447   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9448   ret+=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9449   return ret;
9450 }
9451
9452 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9453 {
9454   std::vector<const BigMemoryObject *> ret;
9455   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9456     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9457   return ret;
9458 }
9459
9460 MEDFileFields *MEDFileFields::deepCpy() const
9461 {
9462   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9463   std::size_t i=0;
9464   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9465     {
9466       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9467         ret->_fields[i]=(*it)->deepCpy();
9468     }
9469   ret->deepCpyGlobs(*this);
9470   return ret.retn();
9471 }
9472
9473 MEDFileFields *MEDFileFields::shallowCpy() const
9474 {
9475   return new MEDFileFields(*this);
9476 }
9477
9478 /*!
9479  * 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
9480  * 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.
9481  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9482  *
9483  * \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.
9484  * \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.
9485  * 
9486  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9487  */
9488 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9489 {
9490   std::set< std::pair<int,int> > s;
9491   bool firstShot=true;
9492   areThereSomeForgottenTS=false;
9493   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9494     {
9495       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9496         continue;
9497       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9498       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9499       if(firstShot)
9500         { s=s1; firstShot=false; }
9501       else
9502         {
9503           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9504           if(s!=s2)
9505             areThereSomeForgottenTS=true;
9506           s=s2;
9507         }
9508     }
9509   std::vector< std::pair<int,int> > ret;
9510   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9511   return ret;
9512 }
9513
9514 int MEDFileFields::getNumberOfFields() const
9515 {
9516   return _fields.size();
9517 }
9518
9519 std::vector<std::string> MEDFileFields::getFieldsNames() const
9520 {
9521   std::vector<std::string> ret(_fields.size());
9522   int i=0;
9523   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9524     {
9525       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9526       if(f)
9527         {
9528           ret[i]=f->getName();
9529         }
9530       else
9531         {
9532           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9533           throw INTERP_KERNEL::Exception(oss.str().c_str());
9534         }
9535     }
9536   return ret;
9537 }
9538
9539 std::vector<std::string> MEDFileFields::getMeshesNames() const
9540 {
9541   std::vector<std::string> ret;
9542   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9543     {
9544       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9545       if(cur)
9546         ret.push_back(cur->getMeshName());
9547     }
9548   return ret;
9549 }
9550
9551 std::string MEDFileFields::simpleRepr() const
9552 {
9553   std::ostringstream oss;
9554   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9555   simpleRepr(0,oss);
9556   return oss.str();
9557 }
9558
9559 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9560 {
9561   int nbOfFields=getNumberOfFields();
9562   std::string startLine(bkOffset,' ');
9563   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9564   int i=0;
9565   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9566     {
9567       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9568       if(cur)
9569         {
9570           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9571         }
9572       else
9573         {
9574           oss << startLine << "  - not defined !" << std::endl;
9575         }
9576     }
9577   i=0;
9578   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9579     {
9580       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9581       std::string chapter(17,'0'+i);
9582       oss << startLine << chapter << std::endl;
9583       if(cur)
9584         {
9585           cur->simpleRepr(bkOffset+2,oss,i);
9586         }
9587       else
9588         {
9589           oss << startLine << "  - not defined !" << std::endl;
9590         }
9591       oss << startLine << chapter << std::endl;
9592     }
9593   simpleReprGlobs(oss);
9594 }
9595
9596 MEDFileFields::MEDFileFields()
9597 {
9598 }
9599
9600 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9601 try:MEDFileFieldGlobsReal(fileName)
9602 {
9603   MEDFileUtilities::CheckFileForRead(fileName);
9604   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
9605   int nbFields(MEDnField(fid));
9606   _fields.resize(nbFields);
9607   med_field_type typcha;
9608   for(int i=0;i<nbFields;i++)
9609     {
9610       std::vector<std::string> infos;
9611       std::string fieldName,dtunit;
9612       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
9613       switch(typcha)
9614       {
9615         case MED_FLOAT64:
9616           {
9617             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms);
9618             break;
9619           }
9620         case MED_INT32:
9621           {
9622             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms);
9623             break;
9624           }
9625         default:
9626           {
9627             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] !";
9628             throw INTERP_KERNEL::Exception(oss.str().c_str());
9629           }
9630       }
9631     }
9632   loadAllGlobals(fid);
9633 }
9634 catch(INTERP_KERNEL::Exception& e)
9635 {
9636     throw e;
9637 }
9638
9639 void MEDFileFields::writeLL(med_idt fid) const
9640 {
9641   int i=0;
9642   writeGlobals(fid,*this);
9643   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9644     {
9645       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9646       if(!elt)
9647         {
9648           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9649           throw INTERP_KERNEL::Exception(oss.str().c_str());
9650         }
9651       elt->writeLL(fid,*this);
9652     }
9653 }
9654
9655 void MEDFileFields::write(const std::string& fileName, int mode) const
9656 {
9657   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
9658   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
9659   writeLL(fid);
9660 }
9661
9662 /*!
9663  * This method alloc the arrays and load potentially huge arrays contained in this field.
9664  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9665  * This method can be also called to refresh or reinit values from a file.
9666  * 
9667  * \throw If the fileName is not set or points to a non readable MED file.
9668  */
9669 void MEDFileFields::loadArrays()
9670 {
9671   if(getFileName().empty())
9672     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
9673   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9674   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9675     {
9676       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9677       if(elt)
9678         elt->loadBigArraysRecursively(fid,*elt);
9679     }
9680 }
9681
9682 /*!
9683  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9684  * But once data loaded once, this method does nothing.
9685  * 
9686  * \throw If the fileName is not set or points to a non readable MED file.
9687  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
9688  */
9689 void MEDFileFields::loadArraysIfNecessary()
9690 {
9691   if(!getFileName().empty())
9692     {
9693       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9694       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9695         {
9696           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9697           if(elt)
9698             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9699         }
9700     }
9701 }
9702
9703 /*!
9704  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9705  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9706  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
9707  * 
9708  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
9709  */
9710 void MEDFileFields::unloadArrays()
9711 {
9712   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9713     {
9714       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9715       if(elt)
9716         elt->unloadArrays();
9717     }
9718 }
9719
9720 /*!
9721  * 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.
9722  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
9723  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9724  * 
9725  * \sa MEDFileFields::loadArraysIfNecessary
9726  */
9727 void MEDFileFields::unloadArraysWithoutDataLoss()
9728 {
9729   if(!getFileName().empty())
9730     unloadArrays();
9731 }
9732
9733 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9734 {
9735   std::vector<std::string> ret;
9736   std::set<std::string> ret2;
9737   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9738     {
9739       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9740       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9741         if(ret2.find(*it2)==ret2.end())
9742           {
9743             ret.push_back(*it2);
9744             ret2.insert(*it2);
9745           }
9746     }
9747   return ret;
9748 }
9749
9750 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9751 {
9752   std::vector<std::string> ret;
9753   std::set<std::string> ret2;
9754   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9755     {
9756       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9757       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9758         if(ret2.find(*it2)==ret2.end())
9759           {
9760             ret.push_back(*it2);
9761             ret2.insert(*it2);
9762           }
9763     }
9764   return ret;
9765 }
9766
9767 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
9768 {
9769   std::vector<std::string> ret;
9770   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9771     {
9772       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
9773       ret.insert(ret.end(),tmp.begin(),tmp.end());
9774     }
9775   return ret;
9776 }
9777
9778 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
9779 {
9780   std::vector<std::string> ret;
9781   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9782     {
9783       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9784       ret.insert(ret.end(),tmp.begin(),tmp.end());
9785     }
9786   return ret;
9787 }
9788
9789 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9790 {
9791   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9792     (*it)->changePflsRefsNamesGen2(mapOfModif);
9793 }
9794
9795 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9796 {
9797   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9798     (*it)->changeLocsRefsNamesGen2(mapOfModif);
9799 }
9800
9801 void MEDFileFields::resize(int newSize)
9802 {
9803   _fields.resize(newSize);
9804 }
9805
9806 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
9807 {
9808   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
9809     pushField(*it);
9810 }
9811
9812 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
9813 {
9814   if(!field)
9815     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
9816   _fields.push_back(field->getContent());
9817   appendGlobs(*field,1e-12);
9818 }
9819
9820 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
9821 {
9822   if(!field)
9823     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9824   if(i>=(int)_fields.size())
9825     _fields.resize(i+1);
9826   _fields[i]=field->getContent();
9827   appendGlobs(*field,1e-12);
9828 }
9829
9830 void MEDFileFields::destroyFieldAtPos(int i)
9831 {
9832   destroyFieldsAtPos(&i,&i+1);
9833 }
9834
9835 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
9836 {
9837   std::vector<bool> b(_fields.size(),true);
9838   for(const int *i=startIds;i!=endIds;i++)
9839     {
9840       if(*i<0 || *i>=(int)_fields.size())
9841         {
9842           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9843           throw INTERP_KERNEL::Exception(oss.str().c_str());
9844         }
9845       b[*i]=false;
9846     }
9847   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9848   std::size_t j=0;
9849   for(std::size_t i=0;i<_fields.size();i++)
9850     if(b[i])
9851       fields[j++]=_fields[i];
9852   _fields=fields;
9853 }
9854
9855 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
9856 {
9857   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9858   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
9859   std::vector<bool> b(_fields.size(),true);
9860   int k=bg;
9861   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9862     {
9863       if(k<0 || k>=(int)_fields.size())
9864         {
9865           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9866           throw INTERP_KERNEL::Exception(oss.str().c_str());
9867         }
9868       b[k]=false;
9869     }
9870   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9871   std::size_t j=0;
9872   for(std::size_t i=0;i<_fields.size();i++)
9873     if(b[i])
9874       fields[j++]=_fields[i];
9875   _fields=fields;
9876 }
9877
9878 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9879 {
9880   bool ret=false;
9881   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9882     {
9883       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9884       if(cur)
9885         ret=cur->changeMeshNames(modifTab) || ret;
9886     }
9887   return ret;
9888 }
9889
9890 /*!
9891  * \param [in] meshName the name of the mesh that will be renumbered.
9892  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9893  *             This code corresponds to the distribution of types in the corresponding mesh.
9894  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9895  * \param [in] renumO2N the old to new renumber array.
9896  * \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 
9897  *         field in \a this.
9898  */
9899 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
9900 {
9901   bool ret=false;
9902   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9903     {
9904       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9905       if(fmts)
9906         {
9907           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9908         }
9909     }
9910   return ret;
9911 }
9912
9913 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
9914 {
9915   if(i<0 || i>=(int)_fields.size())
9916     {
9917       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9918       throw INTERP_KERNEL::Exception(oss.str().c_str());
9919     }
9920   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9921   if(!fmts)
9922     return 0;
9923   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
9924   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
9925   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
9926   if(fmtsC)
9927     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9928   else if(fmtsC2)
9929     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9930   else
9931     {
9932       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
9933       throw INTERP_KERNEL::Exception(oss.str().c_str());
9934     }
9935   ret->shallowCpyGlobs(*this);
9936   return ret.retn();
9937 }
9938
9939 /*!
9940  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9941  * This method is accessible in python using __getitem__ with a list in input.
9942  * \return a new object that the caller should deal with.
9943  */
9944 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
9945 {
9946   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9947   std::size_t sz=std::distance(startIds,endIds);
9948   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9949   int j=0;
9950   for(const int *i=startIds;i!=endIds;i++,j++)
9951     {
9952       if(*i<0 || *i>=(int)_fields.size())
9953         {
9954           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9955           throw INTERP_KERNEL::Exception(oss.str().c_str());
9956         }
9957       fields[j]=_fields[*i];
9958     }
9959   ret->_fields=fields;
9960   return ret.retn();
9961 }
9962
9963 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
9964 {
9965   return getFieldAtPos(getPosFromFieldName(fieldName));
9966 }
9967
9968 /*!
9969  * This method removes, if any, fields in \a this having no time steps.
9970  * 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.
9971  * 
9972  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
9973  */
9974 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
9975 {
9976   std::vector<MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
9977   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9978     {
9979       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9980       if(elt)
9981         {
9982           if(elt->getNumberOfTS()>0)
9983             newFields.push_back(*it);
9984         }
9985     }
9986   if(_fields.size()==newFields.size())
9987     return false;
9988   _fields=newFields;
9989   return true;
9990 }
9991
9992 /*!
9993  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9994  * This method can be seen as a filter applied on \a this, that returns an object containing
9995  * 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
9996  * shallow copied from \a this.
9997  * 
9998  * \param [in] meshName - the name of the mesh on w
9999  * \return a new object that the caller should deal with.
10000  */
10001 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10002 {
10003   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10004   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10005     {
10006       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10007       if(!cur)
10008         continue;
10009       if(cur->getMeshName()==meshName)
10010         {
10011           cur->incrRef();
10012           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10013           ret->_fields.push_back(cur2);
10014         }
10015     }
10016   ret->shallowCpyOnlyUsedGlobs(*this);
10017   return ret.retn();
10018 }
10019
10020 /*!
10021  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10022  * Input time steps are specified using a pair of integer (iteration, order).
10023  * 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,
10024  * but for each multitimestep only the time steps in \a timeSteps are kept.
10025  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10026  * 
10027  * The returned object points to shallow copy of elements in \a this.
10028  * 
10029  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10030  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10031  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10032  */
10033 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10034 {
10035   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10036   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10037     {
10038       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10039       if(!cur)
10040         continue;
10041       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10042       ret->_fields.push_back(elt);
10043     }
10044   ret->shallowCpyOnlyUsedGlobs(*this);
10045   return ret.retn();
10046 }
10047
10048 /*!
10049  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10050  */
10051 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10052 {
10053   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10054   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10055     {
10056       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10057       if(!cur)
10058         continue;
10059       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10060       if(elt->getNumberOfTS()!=0)
10061         ret->_fields.push_back(elt);
10062     }
10063   ret->shallowCpyOnlyUsedGlobs(*this);
10064   return ret.retn();
10065 }
10066
10067 MEDFileFieldsIterator *MEDFileFields::iterator()
10068 {
10069   return new MEDFileFieldsIterator(this);
10070 }
10071
10072 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10073 {
10074   std::string tmp(fieldName);
10075   std::vector<std::string> poss;
10076   for(std::size_t i=0;i<_fields.size();i++)
10077     {
10078       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10079       if(f)
10080         {
10081           std::string fname(f->getName());
10082           if(tmp==fname)
10083             return i;
10084           else
10085             poss.push_back(fname);
10086         }
10087     }
10088   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10089   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10090   oss << " !";
10091   throw INTERP_KERNEL::Exception(oss.str().c_str());
10092 }
10093
10094 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10095 {
10096   if(fs)
10097     {
10098       fs->incrRef();
10099       _nb_iter=fs->getNumberOfFields();
10100     }
10101 }
10102
10103 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10104 {
10105 }
10106
10107 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10108 {
10109   if(_iter_id<_nb_iter)
10110     {
10111       MEDFileFields *fs(_fs);
10112       if(fs)
10113         return fs->getFieldAtPos(_iter_id++);
10114       else
10115         return 0;
10116     }
10117   else
10118     return 0;
10119 }