Salome HOME
Step 6 : Read structure element data from MEDFileUMesh.
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2016  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.txx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDLoaderTraits.hxx"
25 #include "MEDFileSafeCaller.txx"
26 #include "MEDFileFieldOverView.hxx"
27
28 #include "MEDCouplingFieldDouble.hxx"
29 #include "MEDCouplingFieldTemplate.hxx"
30 #include "MEDCouplingFieldDiscretization.hxx"
31
32 #include "InterpKernelAutoPtr.hxx"
33 #include "CellModel.hxx"
34
35 #include <algorithm>
36 #include <iterator>
37
38 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
39 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
40 extern med_geometry_type typmainoeud[1];
41 extern med_geometry_type typmai3[34];
42
43 using namespace MEDCoupling;
44
45 template class MEDFileField1TSTemplateWithoutSDA<int>;
46 template class MEDFileField1TSTemplateWithoutSDA<double>;
47
48 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
49 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
50
51 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
52 {
53   return new MEDFileFieldLoc(fid,locName);
54 }
55
56 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
57 {
58   return new MEDFileFieldLoc(fid,id);
59 }
60
61 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)
62 {
63   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
64 }
65
66 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
67 {
68   med_geometry_type geotype;
69   med_geometry_type sectiongeotype;
70   int nsectionmeshcell;
71   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
72   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
73   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
74   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
75   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
76   _nb_node_per_cell=cm.getNumberOfNodes();
77   _ref_coo.resize(_dim*_nb_node_per_cell);
78   _gs_coo.resize(_dim*_nb_gauss_pt);
79   _w.resize(_nb_gauss_pt);
80   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
81 }
82
83 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
84 {
85   med_geometry_type geotype;
86   med_geometry_type sectiongeotype;
87   int nsectionmeshcell;
88   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
89   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
90   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
91   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
92   _name=locName;
93   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
94   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
95   _nb_node_per_cell=cm.getNumberOfNodes();
96   _ref_coo.resize(_dim*_nb_node_per_cell);
97   _gs_coo.resize(_dim*_nb_gauss_pt);
98   _w.resize(_nb_gauss_pt);
99   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
100 }
101
102 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
103                                  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),
104                                      _w(w)
105 {
106   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
107   _dim=cm.getDimension();
108   _nb_node_per_cell=cm.getNumberOfNodes();
109   _nb_gauss_pt=_w.size();
110 }
111
112 MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const
113 {
114   return new MEDFileFieldLoc(*this);
115 }
116
117 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
118 {
119   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
120 }
121
122 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
123 {
124   return std::vector<const BigMemoryObject *>();
125 }
126
127 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
128 {
129   static const char OFF7[]="\n    ";
130   oss << "\"" << _name << "\"" << OFF7;
131   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
132   oss << "Dimension=" << _dim << OFF7;
133   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
134   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
135   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
136   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
137   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
138 }
139
140 void MEDFileFieldLoc::setName(const std::string& name)
141 {
142   _name=name;
143 }
144
145 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
146 {
147   if(_name!=other._name)
148     return false;
149   if(_dim!=other._dim)
150     return false;
151   if(_nb_gauss_pt!=other._nb_gauss_pt)
152     return false;
153   if(_nb_node_per_cell!=other._nb_node_per_cell)
154     return false;
155   if(_geo_type!=other._geo_type)
156     return false;
157   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
158     return false;
159   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
160     return false;
161   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
162     return false;
163
164   return true;
165 }
166
167 void MEDFileFieldLoc::writeLL(med_idt fid) const
168 {
169   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);
170 }
171
172 std::string MEDFileFieldLoc::repr() const
173 {
174   std::ostringstream oss; oss.precision(15);
175   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
176   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
177   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
178   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
179   oss << "\n  - Ref coords are : ";
180   int sz=_ref_coo.size();
181   if(sz%_dim==0)
182     {
183       int nbOfTuples=sz/_dim;
184       for(int i=0;i<nbOfTuples;i++)
185         {
186           oss << "(";
187           for(int j=0;j<_dim;j++)
188             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
189           oss << ") ";
190         }
191     }
192   else
193     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
194   oss << "\n  - Gauss coords in reference element : ";
195   sz=_gs_coo.size();
196   if(sz%_dim==0)
197     {
198       int nbOfTuples=sz/_dim;
199       for(int i=0;i<nbOfTuples;i++)
200         {
201           oss << "(";
202           for(int j=0;j<_dim;j++)
203             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
204           oss << ") ";
205         }
206     }
207   else
208     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
209   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
210   return oss.str();
211 }
212
213 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
214 {
215   _type=field->getTypeOfField();
216   _start=start;
217   switch(_type)
218   {
219     case ON_CELLS:
220       {
221         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,offset,offset+nbOfCells,1);
222         _end=_start+nbOfCells;
223         _nval=nbOfCells;
224         break;
225       }
226     case ON_GAUSS_NE:
227       {
228         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
229         const int *arrPtr=arr->getConstPointer();
230         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
231         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
232         _nval=nbOfCells;
233         break;
234       }
235     case ON_GAUSS_PT:
236       {
237         const MEDCouplingFieldDiscretization *disc(field->getDiscretization());
238         const MEDCouplingGaussLocalization& gsLoc(field->getGaussLocalization(_loc_id));
239         const MEDCouplingFieldDiscretizationGauss *disc2(dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc));
240         if(!disc2)
241           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
242         const DataArrayInt *dai(disc2->getArrayOfDiscIds());
243         MCAuto<DataArrayInt> dai2(disc2->getOffsetArr(field->getMesh()));
244         const int *dai2Ptr(dai2->getConstPointer());
245         int nbi(gsLoc.getWeights().size());
246         MCAuto<DataArrayInt> da2(dai->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1));
247         MCAuto<DataArrayInt> da3(da2->findIdsEqual(_loc_id));
248         const int *da3Ptr(da3->getConstPointer());
249         if(da3->getNumberOfTuples()!=nbOfCells)
250           {//profile : for gauss even in NoProfile !!!
251             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
252             _profile=oss.str();
253             da3->setName(_profile.c_str());
254             glob.appendProfile(da3);
255           }
256         MCAuto<DataArrayInt> da4(DataArrayInt::New());
257         _nval=da3->getNbOfElems();
258         da4->alloc(_nval*nbi,1);
259         int *da4Ptr(da4->getPointer());
260         for(int i=0;i<_nval;i++)
261           {
262             int ref=dai2Ptr[offset+da3Ptr[i]];
263             for(int j=0;j<nbi;j++)
264               *da4Ptr++=ref+j;
265           }
266         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
267         _localization=oss2.str();
268         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
269         _end=_start+_nval*nbi;
270         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
271         break;
272       }
273     default:
274       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
275   }
276   start=_end;
277 }
278
279 /*!
280  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
281  * \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).
282  * \param [in] multiTypePfl is the end user profile specified in high level API
283  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
284  * \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.
285  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
286  * \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.
287  */
288 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)
289 {
290   _profile.clear();
291   _type=field->getTypeOfField();
292   std::string pflName(multiTypePfl->getName());
293   std::ostringstream oss; oss << pflName;
294   if(_type!=ON_NODES)
295     {
296       if(!isPflAlone)
297         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
298     }
299   else
300     { oss << "_NODE"; }
301   if(locIds)
302     {
303       if(pflName.empty())
304         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
305       if(_type!=ON_GAUSS_PT)
306         {
307           locIds->setName(oss.str());
308           glob.appendProfile(locIds);
309           _profile=oss.str();
310         }
311     }
312   _start=start;
313   switch(_type)
314   {
315     case ON_NODES:
316       {
317         _nval=idsInPfl->getNumberOfTuples();
318         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,arrr->getNumberOfTuples(),1);
319         _end=_start+_nval;
320         break;
321       }
322     case ON_CELLS:
323       {
324         _nval=idsInPfl->getNumberOfTuples();
325         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
326         _end=_start+_nval;
327         break;
328       }
329     case ON_GAUSS_NE:
330       {
331         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
332         MCAuto<DataArrayInt> arr2=arr->deltaShiftIndex();
333         MCAuto<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
334         arr3->computeOffsetsFull();
335         MCAuto<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
336         int trueNval=tmp->getNumberOfTuples();
337         _nval=idsInPfl->getNumberOfTuples();
338         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
339         _end=_start+trueNval;
340         break;
341       }
342     case ON_GAUSS_PT:
343       {
344         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
345         if(!disc2)
346           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
347         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
348         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
349         MCAuto<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
350         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
351         MCAuto<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
352         //
353         MCAuto<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
354         MCAuto<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
355         //
356         MCAuto<DataArrayInt> tmp=DataArrayInt::New();
357         int trueNval=0;
358         for(const int *pt=da4->begin();pt!=da4->end();pt++)
359           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
360         tmp->alloc(trueNval,1);
361         int *tmpPtr=tmp->getPointer();
362         for(const int *pt=da4->begin();pt!=da4->end();pt++)
363           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
364             *tmpPtr++=j;
365         //
366         _nval=da4->getNumberOfTuples();
367         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
368         _end=_start+trueNval;
369         oss << "_loc_" << _loc_id;
370         if(locIds)
371           {
372             MCAuto<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
373             da5->setName(oss.str());
374             glob.appendProfile(da5);
375             _profile=oss.str();
376           }
377         else
378           {
379             if(!da3->isIota(nbOfEltsInWholeMesh))
380               {
381                 da3->setName(oss.str());
382                 glob.appendProfile(da3);
383                 _profile=oss.str();
384               }
385           }
386         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
387         _localization=oss2.str();
388         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
389         break;
390       }
391     default:
392       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
393   }
394   start=_end;
395 }
396
397 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
398 {
399   _start=start;
400   _nval=arrr->getNumberOfTuples();
401   getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,_nval,1);
402   _end=_start+_nval;
403   start=_end;
404 }
405
406 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
407 {
408   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
409 }
410
411 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId)
412 {
413   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
414 }
415
416 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
417 {
418   return new MEDFileFieldPerMeshPerTypePerDisc(other);
419 }
420
421 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
422 {
423   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
424 }
425
426 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
427 {
428   std::vector<const BigMemoryObject *> ret(1);
429   ret[0]=(const PartDefinition*)_pd;
430   return ret;
431 }
432
433 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerTypeCommon *father) const
434 {
435   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
436   ret->_father=father;
437   return ret.retn();
438 }
439
440 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
441 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
442 {
443   if(pd)
444     pd->incrRef();
445 }
446 catch(INTERP_KERNEL::Exception& e)
447 {
448     throw e;
449 }
450
451 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
452 {
453 }
454
455 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)
456 {
457 }
458
459 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
460     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
461 {
462 }
463
464 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)
465 {
466   const PartDefinition *pd(_pd);
467   if(!pd)
468     {
469       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
470       int nbi,tmp1;
471       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
472       if(_end-_start!=nbValsInFile*nbi)
473         {
474           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 !";
475           throw INTERP_KERNEL::Exception(oss.str());
476         }
477       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
478     }
479   else
480     {
481       if(!_profile.empty())
482         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
483       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
484       int profilesize,nbi;
485       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
486       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
487       if(spd)
488         {
489           int start,stop,step;
490           spd->getSlice(start,stop,step);
491           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
492           med_filter filter=MED_FILTER_INIT;
493           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
494                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
495                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
496                                    /*lastblocksize=useless because count=1*/0,&filter);
497           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
498           MEDfilterClose(&filter);
499           return ;
500         }
501       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
502       if(dpd)
503         {
504           dpd->checkConsistencyLight();
505           MCAuto<DataArrayInt> myIds(dpd->toDAI());
506           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
507           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
508           myIds->applyLin(1,-a);
509           int nbOfEltsToLoad(b-a+1);
510           med_filter filter=MED_FILTER_INIT;
511           {//TODO : manage int32 !
512             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
513             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
514             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
515                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
516                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
517                                      /*lastblocksize=useless because count=1*/0,&filter);
518             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
519             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
520             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
521             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
522           }
523           MEDfilterClose(&filter);
524         }
525       else
526         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
527     }
528 }
529
530 const MEDFileFieldPerMeshPerTypeCommon *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
531 {
532   return _father;
533 }
534
535 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
536 {
537   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
538   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
539   std::string fieldName(nasc.getName()),meshName(getMeshName());
540   int iteration(getIteration()),order(getOrder()),profilesize,nbi;
541   TypeOfField type(getType());
542   med_geometry_type mgeoti;
543   med_entity_type menti;
544   _father->entriesForMEDfile(type,mgeoti,menti);
545   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
546   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
547   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
548   const PartDefinition *pd(_pd);
549   if(!pd)
550     {
551       _nval=zeNVal;
552     }
553   else
554     {
555       if(!_profile.empty())
556         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
557       _nval=pd->getNumberOfElems();
558     }
559   _start=start;
560   _end=start+_nval*nbi;
561   start=_end;
562   if(type==ON_CELLS && !_localization.empty())
563     {
564       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
565         setType(ON_GAUSS_PT);
566       else
567         {
568           setType(ON_GAUSS_NE);
569           _localization.clear();
570         }
571     }
572 }
573
574 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
575 {
576   std::string fieldName(nasc.getName()),meshName(getMeshName());
577   int iteration(getIteration()),order(getOrder());
578   TypeOfField type(getType());
579   med_geometry_type mgeoti;
580   med_entity_type menti;
581   _father->entriesForMEDfile(type,mgeoti,menti);
582   if(_start>_end)
583     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
584   if(_start==_end)
585     return ;
586   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
587   if(_start<0 || _start>=arr->getNumberOfTuples())
588     {
589       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
590       throw INTERP_KERNEL::Exception(oss.str());
591     }
592   if(_end<0 || _end>arr->getNumberOfTuples())
593     {
594       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
595       throw INTERP_KERNEL::Exception(oss.str());
596     }
597   int nbOfCompo(arr->getNumberOfComponents());
598   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
599   if(arrD)
600     {
601       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
602       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
603       return ;
604     }
605   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
606   if(arrI)
607     {
608       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
609       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
610       return ;
611     }
612   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
613 }
614
615 /*!
616  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
617  */
618 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
619 {
620   int delta=_end-_start;
621   _start=newValueOfStart;
622   _end=_start+delta;
623 }
624
625 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
626 {
627   return _father->getIteration();
628 }
629
630 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
631 {
632   return _father->getOrder();
633 }
634
635 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
636 {
637   return _father->getTime();
638 }
639
640 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
641 {
642   return _father->getMeshName();
643 }
644
645 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
646 {
647   const char startLine[]="    ## ";
648   std::string startLine2(bkOffset,' ');
649   startLine2+=startLine;
650   INTERP_KERNEL::AutoCppPtr<MEDCouplingFieldDiscretization> tmp(MEDCouplingFieldDiscretization::New(_type));
651   oss << startLine2 << "Localization #" << id << "." << std::endl;
652   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
653   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
654   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
655   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
656 }
657
658 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
659 {
660   return _type;
661 }
662
663 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
664 {
665   return _father->getGeoType();
666 }
667
668 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
669 {
670   types.insert(_type);
671 }
672
673 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
674 {
675   _type=newType;
676 }
677
678 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
679 {
680   return _father->getNumberOfComponents();
681 }
682
683 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
684 {
685   return _end-_start;
686 }
687
688 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
689 {
690   return _father->getOrCreateAndGetArray();
691 }
692
693 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
694 {
695   const MEDFileFieldPerMeshPerTypeCommon *fath=_father;
696   return fath->getOrCreateAndGetArray();
697 }
698
699 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
700 {
701   return _father->getInfo();
702 }
703
704 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
705 {
706   return _profile;
707 }
708
709 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
710 {
711   _profile=newPflName;
712 }
713
714 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
715 {
716   return _localization;
717 }
718
719 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
720 {
721   _localization=newLocName;
722 }
723
724 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
725 {
726   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
727     {
728       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
729         {
730           _profile=(*it2).second;
731           return;
732         }
733     }
734 }
735
736 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
737 {
738   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
739     {
740       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
741         {
742           _localization=(*it2).second;
743           return;
744         }
745     }
746 }
747
748 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
749 {
750   if(type!=_type)
751     return ;
752   dads.push_back(std::pair<int,int>(_start,_end));
753   geoTypes.push_back(getGeoType());
754   if(_profile.empty())
755     pfls.push_back(0);
756   else
757     {
758       pfls.push_back(glob->getProfile(_profile.c_str()));
759     }
760   if(_localization.empty())
761     locs.push_back(-1);
762   else
763     {
764       locs.push_back(glob->getLocalizationId(_localization.c_str()));
765     }
766 }
767
768 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
769 {
770   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));
771   startEntryId++;
772 }
773
774 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
775 {
776   TypeOfField type=getType();
777   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
778   med_geometry_type mgeoti;
779   med_entity_type menti;
780   _father->entriesForMEDfile(getType(),mgeoti,menti);
781   const DataArray *arr(getOrCreateAndGetArray());
782   if(!arr)
783     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
784   if(!arr->isAllocated())
785     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
786   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
787   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
788   const unsigned char *locToWrite=0;
789   if(arrD)
790     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
791   else if(arrI)
792     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
793   else
794     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
795   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
796                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
797                                                    locToWrite));
798 }
799
800 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
801 {
802   type=_type;
803   pfl=_profile;
804   loc=_localization;
805   dad.first=_start; dad.second=_end;
806 }
807
808 /*!
809  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
810  *             This code corresponds to the distribution of types in the corresponding mesh.
811  * \param [out] ptToFill memory zone where the output will be stored.
812  * \return the size of data pushed into output param \a ptToFill
813  */
814 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
815 {
816   _loc_id=offset;
817   std::ostringstream oss;
818   std::size_t nbOfType=codeOfMesh.size()/3;
819   int found=-1;
820   for(std::size_t i=0;i<nbOfType && found==-1;i++)
821     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
822       found=(int)i;
823   if(found==-1)
824     {
825       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
826       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
827       throw INTERP_KERNEL::Exception(oss.str());
828     }
829   int *work=ptToFill;
830   if(_profile.empty())
831     {
832       if(_nval!=codeOfMesh[3*found+1])
833         {
834           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
835           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
836           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
837           throw INTERP_KERNEL::Exception(oss.str());
838         }
839       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
840         *work++=ii;
841     }
842   else
843     {
844       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
845       if(pfl->getNumberOfTuples()!=_nval)
846         {
847           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
848           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
849           oss << _nval;
850           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
851           throw INTERP_KERNEL::Exception(oss.str());
852         }
853       int offset2=codeOfMesh[3*found+2];
854       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
855         {
856           if(*pflId<codeOfMesh[3*found+1])
857             *work++=offset2+*pflId;
858         }
859     }
860   return _nval;
861 }
862
863 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
864 {
865   for(int i=_start;i<_end;i++)
866     *ptToFill++=i;
867   return _end-_start;
868 }
869
870 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
871 {
872   switch(type)
873   {
874     case ON_CELLS:
875       return -2;
876     case ON_GAUSS_NE:
877       return -1;
878     case ON_GAUSS_PT:
879       return locId;
880     default:
881       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
882   }
883 }
884
885 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
886 {
887   int id=0;
888   std::map<std::pair<std::string,TypeOfField>,int> m;
889   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
890   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
891     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
892       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
893   ret.resize(id);
894   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
895     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
896   return ret;
897 }
898
899 /*!
900  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
901  * 
902  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
903  * \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.
904  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
905  * \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)
906  * \param [in,out] glob if necessary by the method, new profiles can be added to it
907  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
908  * \param [out] result All new entries will be appended on it.
909  * \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 !)
910  */
911 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
912                                                        const DataArrayInt *explicitIdsInMesh,
913                                                        const std::vector<int>& newCode,
914                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
915                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
916 {
917   if(entriesOnSameDisc.empty())
918     return false;
919   TypeOfField type=entriesOnSameDisc[0]->getType();
920   int szEntities=0,szTuples=0;
921   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
922     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
923   int nbi=szTuples/szEntities;
924   if(szTuples%szEntities!=0)
925     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
926   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
927   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
928   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
929   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
930   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
931   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
932   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
933   int id=0;
934   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
935     {
936       int startOfEltIdOfChunk=(*it)->_start;
937       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
938       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
939       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
940       //
941       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
942       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
943       //
944       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
945       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
946     }
947   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
948   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
949   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
950   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
951   //
952   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
953   //
954   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
955   arrPart->renumberInPlace(renumTupleIds->begin());
956   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
957   bool ret=false;
958   const int *idIt=diffVals->begin();
959   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
960   int offset2=0;
961   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
962     {
963       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
964       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
965       int nbEntityElts=subIds->getNumberOfTuples();
966       bool ret2;
967       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
968           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
969                                       offset+offset2,
970                                       li,glob,ret2);
971       ret=ret || ret2;
972       result.push_back(eltToAdd);
973       offset2+=nbEntityElts*nbi;
974     }
975   ret=ret || li.empty();
976   return ret;
977 }
978
979 /*!
980  * \param [in] typeF type of field of new chunk
981  * \param [in] geoType the geometric type of the chunk
982  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
983  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
984  * \param [in] nbi number of integration points
985  * \param [in] offset The offset in the **global array of data**.
986  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
987  *                 to the new chunk to create.
988  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
989  * \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
990  *              and corresponding entry erased from \a entriesOnSameDisc.
991  * \return a newly allocated chunk
992  */
993 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
994                                                                                                   bool isPfl, int nbi, int offset,
995                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
996                                                                                                   MEDFileFieldGlobsReal& glob,
997                                                                                                   bool &notInExisting)
998 {
999   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1000   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1001   for(;it!=entriesOnSameDisc.end();it++)
1002     {
1003       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1004         {
1005           if(!isPfl)
1006             {
1007               if((*it)->_profile.empty())
1008                 break;
1009               else
1010                 if(!(*it)->_profile.empty())
1011                   {
1012                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1013                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1014                       break;
1015                   }
1016             }
1017         }
1018     }
1019   if(it==entriesOnSameDisc.end())
1020     {
1021       notInExisting=true;
1022       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1023       ret->_type=typeF;
1024       ret->_loc_id=(int)geoType;
1025       ret->_nval=nbMeshEntities;
1026       ret->_start=offset;
1027       ret->_end=ret->_start+ret->_nval*nbi;
1028       if(isPfl)
1029         {
1030           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1031           glob.appendProfile(idsOfMeshElt);
1032           ret->_profile=idsOfMeshElt->getName();
1033         }
1034       //tony treatment of localization
1035       return ret;
1036     }
1037   else
1038     {
1039       notInExisting=false;
1040       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1041       ret->_loc_id=(int)geoType;
1042       ret->setNewStart(offset);
1043       entriesOnSameDisc.erase(it);
1044       return ret;
1045     }
1046
1047 }
1048
1049 ////////////////////////////////////
1050
1051 MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon()
1052  {
1053  }
1054
1055 void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father)
1056 {
1057   _father=father;
1058 }
1059
1060 void MEDFileFieldPerMeshPerTypeCommon::deepCopyElements()
1061 {
1062   std::size_t i=0;
1063   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1064     {
1065       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1066         _field_pm_pt_pd[i]=(*it)->deepCopy(this);
1067     }
1068 }
1069
1070 std::size_t MEDFileFieldPerMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
1071 {
1072   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1073 }
1074
1075 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypeCommon::getDirectChildrenWithNull() const
1076 {
1077   std::vector<const BigMemoryObject *> ret;
1078   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1079     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1080   return ret;
1081 }
1082
1083 void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1084 {
1085   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1086   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1087     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1088 }
1089
1090 /*!
1091  * This method is the most general one. No optimization is done here.
1092  * \param [in] multiTypePfl is the end user profile specified in high level API
1093  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1094  * \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.
1095  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1096  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1097  * \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.
1098  */
1099 void MEDFileFieldPerMeshPerTypeCommon::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)
1100 {
1101   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1102   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1103     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1104 }
1105
1106 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1107 {
1108   _field_pm_pt_pd.resize(1);
1109   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1110   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1111 }
1112
1113 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1114 {
1115   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1116   if(!arr || !arr->isAllocated())
1117     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile : input array is null, or not allocated !");
1118   _field_pm_pt_pd.resize(1);
1119   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1120   _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.
1121 }
1122
1123 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1124 {
1125   TypeOfField type=field->getTypeOfField();
1126   if(type!=ON_GAUSS_PT)
1127     {
1128       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1129       int sz=_field_pm_pt_pd.size();
1130       bool found=false;
1131       for(int j=0;j<sz && !found;j++)
1132         {
1133           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1134             {
1135               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1136               found=true;
1137             }
1138         }
1139       if(!found)
1140         {
1141           _field_pm_pt_pd.resize(sz+1);
1142           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1143         }
1144       std::vector<int> ret(1,(int)sz);
1145       return ret;
1146     }
1147   else
1148     {
1149       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1150       int sz2=ret2.size();
1151       std::vector<int> ret3(sz2);
1152       int k=0;
1153       for(int i=0;i<sz2;i++)
1154         {
1155           int sz=_field_pm_pt_pd.size();
1156           int locIdToFind=ret2[i];
1157           bool found=false;
1158           for(int j=0;j<sz && !found;j++)
1159             {
1160               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1161                 {
1162                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1163                   ret3[k++]=j;
1164                   found=true;
1165                 }
1166             }
1167           if(!found)
1168             {
1169               _field_pm_pt_pd.resize(sz+1);
1170               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1171               ret3[k++]=sz;
1172             }
1173         }
1174       return ret3;
1175     }
1176 }
1177
1178 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1179 {
1180   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1181   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1182   if(!disc2)
1183     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1184   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1185   if(!da)
1186     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1187   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1188   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1189   if(retTmp->presenceOfValue(-1))
1190     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1191   std::vector<int> ret(retTmp->begin(),retTmp->end());
1192   return ret;
1193 }
1194
1195 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1196 {
1197   TypeOfField type=field->getTypeOfField();
1198   if(type!=ON_GAUSS_PT)
1199     {
1200       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1201       int sz=_field_pm_pt_pd.size();
1202       bool found=false;
1203       for(int j=0;j<sz && !found;j++)
1204         {
1205           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1206             {
1207               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1208               found=true;
1209             }
1210         }
1211       if(!found)
1212         {
1213           _field_pm_pt_pd.resize(sz+1);
1214           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1215         }
1216       std::vector<int> ret(1,0);
1217       return ret;
1218     }
1219   else
1220     {
1221       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1222       int sz2=ret2.size();
1223       std::vector<int> ret3(sz2);
1224       int k=0;
1225       for(int i=0;i<sz2;i++)
1226         {
1227           int sz=_field_pm_pt_pd.size();
1228           int locIdToFind=ret2[i];
1229           bool found=false;
1230           for(int j=0;j<sz && !found;j++)
1231             {
1232               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1233                 {
1234                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1235                   ret3[k++]=j;
1236                   found=true;
1237                 }
1238             }
1239           if(!found)
1240             {
1241               _field_pm_pt_pd.resize(sz+1);
1242               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1243               ret3[k++]=sz;
1244             }
1245         }
1246       return ret3;
1247     }
1248 }
1249
1250 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1251 {
1252   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1253   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1254   if(!disc2)
1255     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1256   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1257   if(!da)
1258     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1259   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1260   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1261   if(retTmp->presenceOfValue(-1))
1262     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1263   std::vector<int> ret(retTmp->begin(),retTmp->end());
1264   return ret;
1265 }
1266
1267 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const
1268 {
1269   return _father;
1270 }
1271
1272 bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const
1273 {
1274   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
1275   int curDim((int)cm.getDimension());
1276   if(dim!=std::numeric_limits<int>::max())
1277     {
1278       if(dim!=curDim)
1279         return false;
1280     }
1281   else
1282     dim=curDim;
1283   return true;
1284 }
1285
1286 void MEDFileFieldPerMeshPerTypeCommon::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1287 {
1288   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1289     {
1290       (*it)->fillTypesOfFieldAvailable(types);
1291     }
1292 }
1293
1294 void MEDFileFieldPerMeshPerTypeCommon::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1295 {
1296   int sz=_field_pm_pt_pd.size();
1297   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1298   for(int i=0;i<sz;i++)
1299     {
1300       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1301     }
1302 }
1303
1304 int MEDFileFieldPerMeshPerTypeCommon::getIteration() const
1305 {
1306   return _father->getIteration();
1307 }
1308
1309 int MEDFileFieldPerMeshPerTypeCommon::getOrder() const
1310 {
1311   return _father->getOrder();
1312 }
1313
1314 double MEDFileFieldPerMeshPerTypeCommon::getTime() const
1315 {
1316   return _father->getTime();
1317 }
1318
1319 std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const
1320 {
1321   return _father->getMeshName();
1322 }
1323
1324 void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) const
1325 {
1326   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1327     {
1328       globalSz+=(*it)->getNumberOfTuples();
1329     }
1330   nbOfEntries+=(int)_field_pm_pt_pd.size();
1331 }
1332
1333 int MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const
1334 {
1335   return _father->getNumberOfComponents();
1336 }
1337
1338 bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const
1339 {
1340   std::size_t nb(0);
1341   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1342     {
1343       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1344       if(fmtd)
1345         nb++;
1346     }
1347   return nb>1;
1348 }
1349
1350 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1351 {
1352   return _father->getOrCreateAndGetArray();
1353 }
1354
1355 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1356 {
1357   const MEDFileFieldPerMesh *fath=_father;
1358   return fath->getOrCreateAndGetArray();
1359 }
1360
1361 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1362 {
1363   return _father->getInfo();
1364 }
1365
1366 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1367 {
1368   std::vector<std::string> ret;
1369   std::set<std::string> ret2;
1370   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1371     {
1372       std::string tmp=(*it1)->getProfile();
1373       if(!tmp.empty())
1374         if(ret2.find(tmp)==ret2.end())
1375           {
1376             ret.push_back(tmp);
1377             ret2.insert(tmp);
1378           }
1379     }
1380   return ret;
1381 }
1382
1383 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1384 {
1385   std::vector<std::string> ret;
1386   std::set<std::string> ret2;
1387   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1388     {
1389       std::string tmp=(*it1)->getLocalization();
1390       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1391         if(ret2.find(tmp)==ret2.end())
1392           {
1393             ret.push_back(tmp);
1394             ret2.insert(tmp);
1395           }
1396     }
1397   return ret;
1398 }
1399
1400 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1401 {
1402   std::vector<std::string> ret;
1403   std::set<std::string> ret2;
1404   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1405     {
1406       std::string tmp=(*it1)->getProfile();
1407       if(!tmp.empty())
1408         ret.push_back(tmp);
1409     }
1410   return ret;
1411 }
1412
1413 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1414 {
1415   std::vector<std::string> ret;
1416   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1417     {
1418       std::string tmp=(*it1)->getLocalization();
1419       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1420         ret.push_back(tmp);
1421     }
1422   return ret;
1423 }
1424
1425 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1426 {
1427   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1428     (*it1)->changePflsRefsNamesGen(mapOfModif);
1429 }
1430
1431 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1432 {
1433   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1434     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1435 }
1436
1437 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId)
1438 {
1439   if(_field_pm_pt_pd.empty())
1440     {
1441       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1442       throw INTERP_KERNEL::Exception(oss.str());
1443     }
1444   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1445     return _field_pm_pt_pd[locId];
1446   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1447   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1448   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1449   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1450 }
1451
1452 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId) const
1453 {
1454   if(_field_pm_pt_pd.empty())
1455     {
1456       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1457       throw INTERP_KERNEL::Exception(oss.str());
1458     }
1459   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1460     return _field_pm_pt_pd[locId];
1461   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1462   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1463   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1464   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1465 }
1466
1467 void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1468 {
1469   int i=0;
1470   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1471     {
1472       (*it)->fillValues(i,startEntryId,entries);
1473     }
1474 }
1475
1476 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1477 {
1478   _field_pm_pt_pd=leaves;
1479   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1480     (*it)->setFather(this);
1481 }
1482
1483 /*!
1484  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1485  *  \param [out] its - list of pair (start,stop) kept
1486  *  \return bool - false if the type of field \a tof is not contained in \a this.
1487  */
1488 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1489 {
1490   bool ret(false);
1491   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1492   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1493     if((*it)->getType()==tof)
1494       {
1495         newPmPtPd.push_back(*it);
1496         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1497         (*it)->setNewStart(globalNum);
1498         globalNum=(*it)->getEnd();
1499         its.push_back(bgEnd);
1500         ret=true;
1501       }
1502   if(ret)
1503     _field_pm_pt_pd=newPmPtPd;
1504   return ret;
1505 }
1506
1507 /*!
1508  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1509  *  \param [out] its - list of pair (start,stop) kept
1510  *  \return bool - false if the type of field \a tof is not contained in \a this.
1511  */
1512 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1513 {
1514   if(_field_pm_pt_pd.size()<=idOfDisc)
1515     return false;
1516   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1517   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1518   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1519   elt->setNewStart(globalNum);
1520   globalNum=elt->getEnd();
1521   its.push_back(bgEnd);
1522   _field_pm_pt_pd=newPmPtPd;
1523   return true;
1524 }
1525
1526 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1527 {
1528   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1529     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1530 }
1531
1532 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1533 {
1534   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1535     (*it)->loadBigArray(fid,nasc);
1536 }
1537
1538 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1539 {
1540   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1541     {
1542       (*it)->copyOptionsFrom(*this);
1543       (*it)->writeLL(fid,nasc);
1544     }
1545 }
1546
1547 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1548 {
1549   switch(ikType)
1550   {
1551     case ON_CELLS:
1552       medfGeoType=typmai3[(int)ikGeoType];
1553       return MED_CELL;
1554     case ON_NODES:
1555       medfGeoType=MED_NONE;
1556       return MED_NODE;
1557     case ON_GAUSS_NE:
1558       medfGeoType=typmai3[(int)ikGeoType];
1559       return MED_NODE_ELEMENT;
1560     case ON_GAUSS_PT:
1561       medfGeoType=typmai3[(int)ikGeoType];
1562       return MED_CELL;
1563     default:
1564       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1565   }
1566   return MED_UNDEF_ENTITY_TYPE;
1567 }
1568
1569 //////////////////////////////////////////////////
1570
1571 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1572 {
1573   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1574 }
1575
1576 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1577 {
1578   return new MEDFileFieldPerMeshPerType(fath,geoType);
1579 }
1580
1581 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1582 {
1583   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1584   ret->setFather(father);
1585   ret->deepCopyElements();
1586   return ret.retn();
1587 }
1588
1589 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
1590 {
1591   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1592     {
1593       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1594       if(meshDim!=(int)cm.getDimension())
1595         return ;
1596     }
1597   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1598     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1599 }
1600
1601 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1602 {
1603   return _geo_type;
1604 }
1605
1606 void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1607 {
1608   ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt);
1609 }
1610
1611 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1612 {
1613   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1614   int curDim((int)cm.getDimension());
1615   dim=std::max(dim,curDim);
1616 }
1617
1618 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1619 {
1620   const char startLine[]="  ## ";
1621   std::string startLine2(bkOffset,' ');
1622   std::string startLine3(startLine2);
1623   startLine3+=startLine;
1624   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1625     {
1626       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1627       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1628     }
1629   else
1630     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1631   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1632   int i=0;
1633   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1634     {
1635       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1636       if(cur)
1637         cur->simpleRepr(bkOffset,oss,i);
1638       else
1639         {
1640           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1641         }
1642     }
1643 }
1644
1645 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1646 {
1647   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1648   return std::string(cm.getRepr());
1649 }
1650
1651 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1652 {
1653 }
1654
1655 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1656 {
1657   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1658   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1659   med_geometry_type mgeoti;
1660   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1661   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1662   _field_pm_pt_pd.resize(nbProfiles);
1663   for(int i=0;i<nbProfiles;i++)
1664     {
1665       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1666     }
1667   if(type==ON_CELLS)
1668     {
1669       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1670       for(int i=0;i<nbProfiles2;i++)
1671         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1672     }
1673 }
1674
1675 MCAuto<MEDFileFieldPerMeshPerType> MEDFileFieldPerMeshPerType::Aggregate(int &start, const std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
1676 {
1677   MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1678   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1679   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1680     {
1681       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1682         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1683     }
1684   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1685     {
1686       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1687       ret->_field_pm_pt_pd.push_back(agg);
1688     }
1689   return ret;
1690 }
1691
1692 //////////////////////////////////////////////////
1693
1694 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc)
1695 {
1696   if(!entities)
1697     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !");
1698   const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
1699   if(!entities2)
1700     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !");
1701   const MEDFileStructureElement *se(entities2->getWithGT(idGT));
1702   return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc);
1703 }
1704
1705 MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath)
1706 {
1707   _se.takeRef(se);
1708   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1709   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1710   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName));
1711   _field_pm_pt_pd.resize(nbProfiles);
1712   for(int i=0;i<nbProfiles;i++)
1713     {
1714       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,_se->getEntity(),i,NULL);
1715     }
1716 }
1717
1718 int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const
1719 {
1720   return _se->getDynGT();
1721 }
1722
1723 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1724 {
1725   throw INTERP_KERNEL::Exception("not implemented yet !");
1726 }
1727
1728 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1729 {
1730   gt=getDynGT();
1731   ent=MED_STRUCT_ELEMENT;
1732 }
1733
1734 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1735 {
1736   throw INTERP_KERNEL::Exception("not implemented yet !");
1737 }
1738
1739 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1740 {
1741   const char startLine[]="  ## ";
1742   std::string startLine2(bkOffset,' ');
1743   std::string startLine3(startLine2);
1744   startLine3+=startLine;
1745   oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1746   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1747   int i=0;
1748   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1749     {
1750       if((*it).isNotNull())
1751         (*it)->simpleRepr(bkOffset,oss,i);
1752       else
1753         {
1754           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1755         }
1756     }
1757 }
1758
1759 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1760 {
1761   throw INTERP_KERNEL::Exception("not implemented yet !");
1762 }
1763
1764 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1765 {
1766   throw INTERP_KERNEL::Exception("not implemented yet !");
1767 }
1768
1769 void MEDFileFieldPerMeshPerTypeDyn::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
1770 {
1771   throw INTERP_KERNEL::Exception("not implemented yet !");
1772 }
1773
1774 //////////////////////////////////////////////////
1775
1776 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1777 {
1778   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1779 }
1780
1781 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1782 {
1783   return new MEDFileFieldPerMesh(fath,mesh);
1784 }
1785
1786 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1787 {
1788   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1789 }
1790
1791 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1792 {
1793   std::vector<const BigMemoryObject *> ret;
1794   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1795     ret.push_back(*it);
1796   return ret;
1797 }
1798
1799 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1800 {
1801   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1802   ret->_father=father;
1803   std::size_t i=0;
1804   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1805     {
1806       if((*it).isNotNull())
1807         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1808     }
1809   return ret.retn();
1810 }
1811
1812 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1813 {
1814   std::string startLine(bkOffset,' ');
1815   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1816   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1817   int i=0;
1818   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1819     {
1820       if((*it).isNotNull())
1821         (*it)->simpleRepr(bkOffset,oss,i);
1822       else
1823         {
1824           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1825         }
1826     }
1827 }
1828
1829 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1830 {
1831   _mesh_name=mesh->getName();
1832   mesh->getTime(_mesh_iteration,_mesh_order);
1833 }
1834
1835 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1836 {
1837   int nbOfTypes=code.size()/3;
1838   int offset=0;
1839   for(int i=0;i<nbOfTypes;i++)
1840     {
1841       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1842       int nbOfCells=code[3*i+1];
1843       int pos=addNewEntryIfNecessary(type);
1844       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1845       offset+=nbOfCells;
1846     }
1847 }
1848
1849 /*!
1850  * This method is the most general one. No optimization is done here.
1851  * \param [in] multiTypePfl is the end user profile specified in high level API
1852  * \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].
1853  * \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.
1854  * \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.
1855  * \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.
1856  * \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.
1857  */
1858 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)
1859 {
1860   int nbOfTypes(code.size()/3);
1861   for(int i=0;i<nbOfTypes;i++)
1862     {
1863       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1864       int pos=addNewEntryIfNecessary(type);
1865       DataArrayInt *pfl=0;
1866       if(code[3*i+2]!=-1)
1867         pfl=idsPerType[code[3*i+2]];
1868       int nbOfTupes2=code2.size()/3;
1869       int found=0;
1870       for(;found<nbOfTupes2;found++)
1871         if(code[3*i]==code2[3*found])
1872           break;
1873       if(found==nbOfTupes2)
1874         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1875       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1876     }
1877 }
1878
1879 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1880 {
1881   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1882   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1883 }
1884
1885 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1886 {
1887   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1888   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1889 }
1890
1891 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1892 {
1893   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1894     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1895 }
1896
1897 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1898 {
1899   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1900     (*it)->loadBigArraysRecursively(fid,nasc);
1901 }
1902
1903 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1904 {
1905   int nbOfTypes=_field_pm_pt.size();
1906   for(int i=0;i<nbOfTypes;i++)
1907     {
1908       _field_pm_pt[i]->copyOptionsFrom(*this);
1909       _field_pm_pt[i]->writeLL(fid,nasc);
1910     }
1911 }
1912
1913 void MEDFileFieldPerMesh::getDimension(int& dim) const
1914 {
1915   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1916     (*it)->getDimension(dim);
1917 }
1918
1919 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
1920 {
1921   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1922     if(!(*it)->isUniqueLevel(dim))
1923       return false;
1924   return true;
1925 }
1926
1927 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1928 {
1929   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1930     (*it)->fillTypesOfFieldAvailable(types);
1931 }
1932
1933 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
1934 {
1935   int sz=_field_pm_pt.size();
1936   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1937   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1938   for(int i=0;i<sz;i++)
1939     {
1940       types[i]=_field_pm_pt[i]->getGeoType();
1941       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1942     }
1943   return ret;
1944 }
1945
1946 double MEDFileFieldPerMesh::getTime() const
1947 {
1948   int tmp1,tmp2;
1949   return _father->getTime(tmp1,tmp2);
1950 }
1951
1952 int MEDFileFieldPerMesh::getIteration() const
1953 {
1954   return _father->getIteration();
1955 }
1956
1957 int MEDFileFieldPerMesh::getOrder() const
1958 {
1959   return _father->getOrder();
1960 }
1961
1962 int MEDFileFieldPerMesh::getNumberOfComponents() const
1963 {
1964   return _father->getNumberOfComponents();
1965 }
1966
1967 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1968 {
1969   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1970     {
1971       if((*it).isNull())
1972         continue;
1973       if((*it)->presenceOfMultiDiscPerGeoType())
1974         return true;
1975     }
1976   return false;
1977 }
1978
1979 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1980 {
1981   if(!_father)
1982     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1983   return _father->getOrCreateAndGetArray();
1984 }
1985
1986 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1987 {
1988   if(!_father)
1989     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1990   return _father->getOrCreateAndGetArray();
1991 }
1992
1993 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1994 {
1995   return _father->getInfo();
1996 }
1997
1998 /*!
1999  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2000  * 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.
2001  * It returns 2 output vectors :
2002  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2003  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2004  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2005  */
2006 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)
2007 {
2008   int notNullPflsSz=0;
2009   int nbOfArrs=geoTypes.size();
2010   for(int i=0;i<nbOfArrs;i++)
2011     if(pfls[i])
2012       notNullPflsSz++;
2013   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2014   int nbOfDiffGeoTypes=geoTypes3.size();
2015   code.resize(3*nbOfDiffGeoTypes);
2016   notNullPfls.resize(notNullPflsSz);
2017   notNullPflsSz=0;
2018   int j=0;
2019   for(int i=0;i<nbOfDiffGeoTypes;i++)
2020     {
2021       int startZone=j;
2022       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2023       std::vector<const DataArrayInt *> notNullTmp;
2024       if(pfls[j])
2025         notNullTmp.push_back(pfls[j]);
2026       j++;
2027       for(;j<nbOfArrs;j++)
2028         if(geoTypes[j]==refType)
2029           {
2030             if(pfls[j])
2031               notNullTmp.push_back(pfls[j]);
2032           }
2033         else
2034           break;
2035       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2036       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2037       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2038       code[3*i]=(int)refType;
2039       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2040       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2041       if(notNullTmp.empty())
2042         code[3*i+2]=-1;
2043       else
2044         {
2045           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
2046           code[3*i+2]=notNullPflsSz++;
2047         }
2048     }
2049 }
2050
2051 /*!
2052  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2053  */
2054 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)
2055 {
2056   int sz=dads.size();
2057   int ret=0;
2058   for(int i=0;i<sz;i++)
2059     {
2060       if(locs[i]==-1)
2061         {
2062           if(type!=ON_GAUSS_NE)
2063             ret+=dads[i].second-dads[i].first;
2064           else
2065             {
2066               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2067               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2068             }
2069         }
2070       else
2071         {
2072           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2073           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2074         }
2075     }
2076   return ret;
2077 }
2078
2079 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2080 {
2081   std::vector<std::string> ret;
2082   std::set<std::string> ret2;
2083   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2084     {
2085       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2086       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2087         if(ret2.find(*it2)==ret2.end())
2088           {
2089             ret.push_back(*it2);
2090             ret2.insert(*it2);
2091           }
2092     }
2093   return ret;
2094 }
2095
2096 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2097 {
2098   std::vector<std::string> ret;
2099   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2100     {
2101       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2102       ret.insert(ret.end(),tmp.begin(),tmp.end());
2103     }
2104   return ret;
2105 }
2106
2107 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2108 {
2109   std::vector<std::string> ret;
2110   std::set<std::string> ret2;
2111   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2112     {
2113       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2114       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2115         if(ret2.find(*it2)==ret2.end())
2116           {
2117             ret.push_back(*it2);
2118             ret2.insert(*it2);
2119           }
2120     }
2121   return ret;
2122 }
2123
2124 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2125 {
2126   std::vector<std::string> ret;
2127   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2128     {
2129       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2130       ret.insert(ret.end(),tmp.begin(),tmp.end());
2131     }
2132   return ret;
2133 }
2134
2135 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2136 {
2137   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2138     {
2139       if((*it).first==_mesh_name)
2140         {
2141           _mesh_name=(*it).second;
2142           return true;
2143         }
2144     }
2145   return false;
2146 }
2147
2148 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2149                                                       MEDFileFieldGlobsReal& glob)
2150 {
2151   if(_mesh_name!=meshName)
2152     return false;
2153   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2154   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2155   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2156   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2157   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2158   getUndergroundDataArrayExt(entries);
2159   DataArray *arr0(getOrCreateAndGetArray());//tony
2160   if(!arr0)
2161     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2162   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2163   if(!arr0)
2164     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2165   int sz=0;
2166   if(!arr)
2167     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2168   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2169     {
2170       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2171         {
2172           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2173           sz+=(*it).second.second-(*it).second.first;
2174         }
2175       else
2176         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2177     }
2178   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2179   ////////////////////
2180   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2181   int *workI2=explicitIdsOldInMesh->getPointer();
2182   int sz1=0,sz2=0,sid=1;
2183   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2184   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2185   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2186     {
2187       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2188       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2189       int *workI=explicitIdsOldInArr->getPointer();
2190       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2191         {
2192           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2193           (*itL2)->setLocId(sz2);
2194           (*itL2)->_tmp_work1=(*itL2)->getStart();
2195           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2196         }
2197       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2198     }
2199   explicitIdsOldInMesh->reAlloc(sz2);
2200   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2201   ////////////////////
2202   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2203   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2204   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2205   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2206     {
2207       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2208       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2209       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2210     }
2211   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2212   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2213   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2214     {
2215       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2216       int newStart=elt->getLocId();
2217       elt->setLocId((*it)->getGeoType());
2218       elt->setNewStart(newStart);
2219       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2220       entriesKeptNew.push_back(elt);
2221       entriesKeptNew2.push_back(elt);
2222     }
2223   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2224   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2225   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2226   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2227   bool ret=false;
2228   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2229     {
2230       sid=0;
2231       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2232         {
2233           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2234           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2235           }*/
2236       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2237                                                             glob,arr2,otherEntriesNew) || ret;
2238     }
2239   if(!ret)
2240     return false;
2241   // Assign new dispatching
2242   assignNewLeaves(otherEntriesNew);
2243   arr->deepCopyFrom(*arr2);
2244   return true;
2245 }
2246
2247 /*!
2248  * \param [in,out] globalNum a global numbering counter for the renumbering.
2249  * \param [out] its - list of pair (start,stop) kept
2250  */
2251 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2252 {
2253   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2254   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2255     {
2256       std::vector< std::pair<int,int> > its2;
2257       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2258         {
2259           ret.push_back(*it);
2260           its.insert(its.end(),its2.begin(),its2.end());
2261         }
2262     }
2263   _field_pm_pt=ret;
2264 }
2265
2266 /*!
2267  * \param [in,out] globalNum a global numbering counter for the renumbering.
2268  * \param [out] its - list of pair (start,stop) kept
2269  */
2270 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2271 {
2272   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2273   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2274     {
2275       std::vector< std::pair<int,int> > its2;
2276       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2277         {
2278           ret.push_back(*it);
2279           its.insert(its.end(),its2.begin(),its2.end());
2280         }
2281     }
2282   _field_pm_pt=ret;
2283 }
2284
2285 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2286 {
2287   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2288   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2289     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2290   //
2291   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2292   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2293   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2294   for(;it1!=types.end();it1++,it2++)
2295     {
2296       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2297       elt->setLeaves((*it1).second);
2298       MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2299       *it2=elt2;
2300     }
2301   _field_pm_pt=fieldPmPt;
2302 }
2303
2304 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2305 {
2306   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2307     (*it)->changePflsRefsNamesGen(mapOfModif);
2308 }
2309
2310 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2311 {
2312   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2313     (*it)->changeLocsRefsNamesGen(mapOfModif);
2314 }
2315
2316 /*!
2317  * \param [in] mesh is the whole mesh
2318  */
2319 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2320 {
2321   if(_field_pm_pt.empty())
2322     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2323   //
2324   std::vector< std::pair<int,int> > dads;
2325   std::vector<const DataArrayInt *> pfls;
2326   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2327   std::vector<int> locs,code;
2328   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2329   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2330     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2331   // Sort by types
2332   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2333   if(code.empty())
2334     {
2335       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2336       throw INTERP_KERNEL::Exception(oss.str());
2337     }
2338   //
2339   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2340   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2341   if(type!=ON_NODES)
2342     {
2343       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2344       if(!arr)
2345         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2346       else
2347         {
2348           MCAuto<DataArrayInt> arr2(arr);
2349           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2350         }
2351     }
2352   else
2353     {
2354       if(code.size()!=3)
2355         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2356       int nb=code[1];
2357       if(code[2]==-1)
2358         {
2359           if(nb!=mesh->getNumberOfNodes())
2360             {
2361               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2362               oss << " nodes in mesh !";
2363               throw INTERP_KERNEL::Exception(oss.str());
2364             }
2365           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2366         }
2367       else
2368         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2369     }
2370 }
2371
2372 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2373 {
2374   if(_field_pm_pt.empty())
2375     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2376   //
2377   std::vector<std::pair<int,int> > dads;
2378   std::vector<const DataArrayInt *> pfls;
2379   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2380   std::vector<int> locs,code;
2381   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2382   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2383     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2384   // Sort by types
2385   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2386   if(code.empty())
2387     {
2388       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2389       throw INTERP_KERNEL::Exception(oss.str());
2390     }
2391   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2392   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2393   if(type!=ON_NODES)
2394     {
2395       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2396       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2397     }
2398   else
2399     {
2400       if(code.size()!=3)
2401         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2402       int nb=code[1];
2403       if(code[2]==-1)
2404         {
2405           if(nb!=mesh->getNumberOfNodes())
2406             {
2407               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2408               oss << " nodes in mesh !";
2409               throw INTERP_KERNEL::Exception(oss.str());
2410             }
2411         }
2412       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2413     }
2414   //
2415   return 0;
2416 }
2417
2418 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2419 {
2420   int globalSz=0;
2421   int nbOfEntries=0;
2422   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2423     {
2424       (*it)->getSizes(globalSz,nbOfEntries);
2425     }
2426   entries.resize(nbOfEntries);
2427   nbOfEntries=0;
2428   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2429     {
2430       (*it)->fillValues(nbOfEntries,entries);
2431     }
2432 }
2433
2434 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2435 {
2436   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2437     {
2438       if((*it)->getGeoType()==typ)
2439         return (*it)->getLeafGivenLocId(locId);
2440     }
2441   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2442   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2443   oss << "Possiblities are : ";
2444   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2445     {
2446       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2447       oss << "\"" << cm2.getRepr() << "\", ";
2448     }
2449   throw INTERP_KERNEL::Exception(oss.str());
2450 }
2451
2452 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2453 {
2454   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2455     {
2456       if((*it)->getGeoType()==typ)
2457         return (*it)->getLeafGivenLocId(locId);
2458     }
2459   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2460   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2461   oss << "Possiblities are : ";
2462   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2463     {
2464       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2465       oss << "\"" << cm2.getRepr() << "\", ";
2466     }
2467   throw INTERP_KERNEL::Exception(oss.str());
2468 }
2469
2470 /*!
2471  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2472  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2473  * \param [in] dts - (Distribution of types) = level 1 : meshes to aggregate. Level 2 : all geo type. Level 3 pair specifying geo type and number of elem in geotype.
2474  * \param [out] extractInfo - Gives information about the where the data comes from. It is a vector of triplet. First element in the triplet the mesh pos. The 2nd one the start pos. The 3rd the end pos.
2475  */
2476 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> MEDFileFieldPerMeshPerTypePerDisc::Aggregate(int &start, const std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, TypeOfField tof, MEDFileFieldPerMeshPerType *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
2477 {
2478   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2479   if(pms.empty())
2480     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2481   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2482     {
2483       if(!(*it).second)
2484         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2485       if(!(*it).second->getProfile().empty())
2486         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2487       if(!(*it).second->getLocalization().empty())
2488         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2489     }
2490   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2491   std::size_t i(0);
2492   std::vector< std::pair<int,int> > filteredDTS;
2493   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2494     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2495       if((*it2).first==gt)
2496         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2497   if(pms.size()!=filteredDTS.size())
2498     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2499   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2500   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2501   int zeStart(start),nval(0);
2502   for(;it1!=pms.end();it1++,it2++)
2503     {
2504       if((*it1).first!=(*it2).first)
2505         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2506       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2507       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2508       start+=e1-s1;
2509       nval+=((*it1).second)->getNumberOfVals();
2510     }
2511   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2512   return ret;
2513 }
2514
2515 MCAuto<MEDFileFieldPerMesh> MEDFileFieldPerMesh::Aggregate(int &start, const std::vector<const MEDFileFieldPerMesh *>& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, MEDFileAnyTypeField1TSWithoutSDA *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
2516 {
2517   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2518   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2519   std::size_t i(0);
2520   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2521     {
2522       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2523       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2524         {
2525           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2526           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2527           if(!elt)
2528             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2529           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2530         }
2531     }
2532   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2533     {
2534       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2535       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2536       ret->_field_pm_pt.push_back(agg2);
2537     }
2538   return ret;
2539 }
2540
2541 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2542 {
2543   int i=0;
2544   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2545   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2546   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2547     {
2548       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2549       if(type==curType)
2550         return i;
2551       else
2552         {
2553           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2554           if(pos>pos2)
2555             it2=it+1;
2556         }
2557     }
2558   int ret=std::distance(_field_pm_pt.begin(),it2);
2559   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2560   return ret;
2561 }
2562
2563 /*!
2564  * 'dads' and 'locs' input parameters have the same number of elements
2565  * \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
2566  */
2567 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2568                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2569                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2570 {
2571   isPfl=false;
2572   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2573   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2574   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2575   const std::vector<std::string>& infos=getInfo();
2576   da->setInfoOnComponents(infos);
2577   da->setName("");
2578   if(type==ON_GAUSS_PT)
2579     {
2580       int offset=0;
2581       int nbOfArrs=dads.size();
2582       for(int i=0;i<nbOfArrs;i++)
2583         {
2584           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2585           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2586           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2587           MCAuto<DataArrayInt> di=DataArrayInt::New();
2588           di->alloc(nbOfElems,1);
2589           di->iota(offset);
2590           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2591           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2592           offset+=nbOfElems;
2593         }
2594     }
2595   arrOut=da;
2596   return ret.retn();
2597 }
2598
2599 /*!
2600  * 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.
2601  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2602  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2603  * The order of cells in the returned field is those imposed by the profile.
2604  * \param [in] mesh is the global mesh.
2605  */
2606 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2607                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2608                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2609                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2610 {
2611   if(da->isIota(mesh->getNumberOfCells()))
2612     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2613   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2614   m2->setName(mesh->getName().c_str());
2615   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2616   isPfl=true;
2617   return ret.retn();
2618 }
2619
2620 /*!
2621  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2622  */
2623 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2624                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2625                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2626 {
2627   if(da->isIota(mesh->getNumberOfNodes()))
2628     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2629   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2630   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2631   if(meshu)
2632     {
2633       if(meshu->getNodalConnectivity()==0)
2634         {
2635           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2636           int nb=da->getNbOfElems();
2637           const int *ptr=da->getConstPointer();
2638           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2639           meshuc->allocateCells(nb);
2640           for(int i=0;i<nb;i++)
2641             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2642           meshuc->finishInsertingCells();
2643           ret->setMesh(meshuc);
2644           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2645           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2646           disc->checkCoherencyBetween(meshuc,arrOut);
2647           return ret.retn();
2648         }
2649     }
2650   //
2651   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2652   isPfl=true;
2653   DataArrayInt *arr2=0;
2654   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2655   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2656   MCAuto<DataArrayInt> arr3(arr2);
2657   int nnodes=mesh2->getNumberOfNodes();
2658   if(nnodes==(int)da->getNbOfElems())
2659     {
2660       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2661       arrOut->renumberInPlace(da3->getConstPointer());
2662       mesh2->setName(mesh->getName().c_str());
2663       ret->setMesh(mesh2);
2664       return ret.retn();
2665     }
2666   else
2667     {
2668       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 !!!";
2669       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2670       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2671       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2672       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2673       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2674       throw INTERP_KERNEL::Exception(oss.str());
2675     }
2676   return 0;
2677 }
2678
2679 /*!
2680  * This method is the most light method of field retrieving.
2681  */
2682 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2683 {
2684   if(!pflIn)
2685     {
2686       pflOut=DataArrayInt::New();
2687       pflOut->alloc(nbOfElems,1);
2688       pflOut->iota(0);
2689     }
2690   else
2691     {
2692       pflOut=const_cast<DataArrayInt*>(pflIn);
2693       pflOut->incrRef();
2694     }
2695   MCAuto<DataArrayInt> safePfl(pflOut);
2696   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2697   const std::vector<std::string>& infos=getInfo();
2698   int nbOfComp=infos.size();
2699   for(int i=0;i<nbOfComp;i++)
2700     da->setInfoOnComponent(i,infos[i].c_str());
2701   safePfl->incrRef();
2702   return da.retn();
2703 }
2704
2705
2706 /// @cond INTERNAL
2707
2708 class MFFPMIter
2709 {
2710 public:
2711   static MFFPMIter *NewCell(const MEDFileEntities *entities);
2712   static bool IsPresenceOfNode(const MEDFileEntities *entities);
2713   virtual ~MFFPMIter() { }
2714   virtual void begin() = 0;
2715   virtual bool finished() const = 0;
2716   virtual void next() = 0;
2717   virtual int current() const = 0;
2718 };
2719
2720 class MFFPMIterSimple : public MFFPMIter
2721 {
2722 public:
2723   MFFPMIterSimple():_pos(0) { }
2724   void begin() { _pos=0; }
2725   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2726   void next() { _pos++; }
2727   int current() const { return _pos; }
2728 private:
2729   int _pos;
2730 };
2731
2732 class MFFPMIter2 : public MFFPMIter
2733 {
2734 public:
2735   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2736   void begin() { _it=_ids.begin(); }
2737   bool finished() const { return _it==_ids.end(); }
2738   void next() { _it++; }
2739   int current() const { return *_it; }
2740 private:
2741   std::vector<int> _ids;
2742   std::vector<int>::const_iterator _it;
2743 };
2744
2745 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
2746 {
2747   if(!entities)
2748     return new MFFPMIterSimple;
2749   else
2750     {
2751       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2752       if(entities2)
2753         {
2754           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2755           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2756           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2757             {
2758               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2759                 tmp.push_back((*it).second);
2760             }
2761           return new MFFPMIter2(tmp);
2762         }
2763       return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
2764     }
2765 }
2766
2767 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
2768 {
2769   if(!entities)
2770     return true;
2771   else
2772     {
2773       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2774       if(entities2)
2775         {
2776           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2777           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2778             if((*it).first==ON_NODES)
2779               return true;
2780           return false;
2781         }
2782       return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
2783     }
2784 }
2785
2786 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2787 {
2788   std::size_t sz(cts.size());
2789   _ids.resize(sz);
2790   for(std::size_t i=0;i<sz;i++)
2791     {
2792       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2793       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2794         _ids[i]=(int)std::distance(typmai2,loc);
2795       else
2796         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2797     }
2798 }
2799
2800 /// @endcond
2801
2802 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2803     _father(fath)
2804 {
2805   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2806   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2807   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2808   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2809   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2810   for(iter0->begin();!iter0->finished();iter0->next())
2811     {
2812       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2813       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2814       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2815       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2816       if(nbProfile>0 || nbProfile2>0)
2817         {
2818           const PartDefinition *pd(0);
2819           if(mmu)
2820             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2821           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2822           if(nbProfile>0)
2823             _mesh_name=name0;
2824           else
2825             _mesh_name=name1;
2826         }
2827     }
2828   if(MFFPMIter::IsPresenceOfNode(entities))
2829     {
2830       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2831       if(nbProfile>0)
2832         {
2833           const PartDefinition *pd(0);
2834           if(mmu)
2835             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2836           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2837           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2838         }
2839     }
2840   if(!entities)
2841     return ;
2842   std::vector<int> dynGT(entities->getDynGTAvail());
2843   for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
2844     {
2845       int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
2846       if(nbPfl>0)
2847         {
2848           _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
2849           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2850         }
2851     }
2852 }
2853
2854 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2855 {
2856   copyTinyInfoFrom(mesh);
2857 }
2858
2859 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2860 {
2861   if(id>=(int)_pfls.size())
2862     _pfls.resize(id+1);
2863   _pfls[id]=DataArrayInt::New();
2864   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2865   _pfls[id]->setName(pflName);
2866   _pfls[id]->alloc(lgth,1);
2867   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2868   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2869 }
2870
2871 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2872 {
2873   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2874   int sz;
2875   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
2876   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2877   if(i>=(int)_pfls.size())
2878     _pfls.resize(i+1);
2879   _pfls[i]=DataArrayInt::New();
2880   _pfls[i]->alloc(sz,1);
2881   _pfls[i]->setName(pflCpp.c_str());
2882   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
2883   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2884 }
2885
2886 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2887 {
2888   int nbOfPfls=_pfls.size();
2889   for(int i=0;i<nbOfPfls;i++)
2890     {
2891       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
2892       cpy->applyLin(1,1,0);
2893       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2894       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2895       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
2896     }
2897   //
2898   int nbOfLocs=_locs.size();
2899   for(int i=0;i<nbOfLocs;i++)
2900     _locs[i]->writeLL(fid);
2901 }
2902
2903 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2904 {
2905   std::vector<std::string> pfls=getPfls();
2906   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2907     {
2908       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2909       if(it2==pfls.end())
2910         {
2911           _pfls.push_back(*it);
2912         }
2913       else
2914         {
2915           int id=std::distance(pfls.begin(),it2);
2916           if(!(*it)->isEqual(*_pfls[id]))
2917             {
2918               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2919               throw INTERP_KERNEL::Exception(oss.str());
2920             }
2921         }
2922     }
2923   std::vector<std::string> locs=getLocs();
2924   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2925     {
2926       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2927       if(it2==locs.end())
2928         {
2929           _locs.push_back(*it);
2930         }
2931       else
2932         {
2933           int id=std::distance(locs.begin(),it2);
2934           if(!(*it)->isEqual(*_locs[id],eps))
2935             {
2936               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2937               throw INTERP_KERNEL::Exception(oss.str());
2938             }
2939         }
2940     }
2941 }
2942
2943 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2944 {
2945   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2946     getProfile((*it).c_str());
2947 }
2948
2949 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2950 {
2951   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2952     getLocalization((*it).c_str());
2953 }
2954
2955 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2956 {
2957   std::vector<std::string> profiles=real.getPflsReallyUsed();
2958   int sz=profiles.size();
2959   _pfls.resize(sz);
2960   for(int i=0;i<sz;i++)
2961     loadProfileInFile(fid,i,profiles[i].c_str());
2962   //
2963   std::vector<std::string> locs=real.getLocsReallyUsed();
2964   sz=locs.size();
2965   _locs.resize(sz);
2966   for(int i=0;i<sz;i++)
2967     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2968 }
2969
2970 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2971 {
2972   int nProfil=MEDnProfile(fid);
2973   for(int i=0;i<nProfil;i++)
2974     loadProfileInFile(fid,i);
2975   int sz=MEDnLocalization(fid);
2976   _locs.resize(sz);
2977   for(int i=0;i<sz;i++)
2978     {
2979       _locs[i]=MEDFileFieldLoc::New(fid,i);
2980     }
2981 }
2982
2983 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
2984 {
2985   return new MEDFileFieldGlobs(fid);
2986 }
2987
2988 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2989 {
2990   return new MEDFileFieldGlobs;
2991 }
2992
2993 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2994 {
2995   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
2996 }
2997
2998 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2999 {
3000   std::vector<const BigMemoryObject *> ret;
3001   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3002     ret.push_back((const DataArrayInt *)*it);
3003   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3004     ret.push_back((const MEDFileFieldLoc *)*it);
3005   return ret;
3006 }
3007
3008 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
3009 {
3010   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
3011   std::size_t i=0;
3012   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3013     {
3014       if((const DataArrayInt *)*it)
3015         ret->_pfls[i]=(*it)->deepCopy();
3016     }
3017   i=0;
3018   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3019     {
3020       if((const MEDFileFieldLoc*)*it)
3021         ret->_locs[i]=(*it)->deepCopy();
3022     }
3023   return ret.retn();
3024 }
3025
3026 /*!
3027  * \throw if a profile in \a pfls in not in \a this.
3028  * \throw if a localization in \a locs in not in \a this.
3029  * \sa MEDFileFieldGlobs::deepCpyPart
3030  */
3031 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3032 {
3033   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3034   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3035     {
3036       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3037       if(!pfl)
3038         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
3039       pfl->incrRef();
3040       MCAuto<DataArrayInt> pfl2(pfl);
3041       ret->_pfls.push_back(pfl2);
3042     }
3043   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3044     {
3045       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3046       if(!loc)
3047         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
3048       loc->incrRef();
3049       MCAuto<MEDFileFieldLoc> loc2(loc);
3050       ret->_locs.push_back(loc2);
3051     }
3052   ret->setFileName(getFileName());
3053   return ret.retn();
3054 }
3055
3056 /*!
3057  * \throw if a profile in \a pfls in not in \a this.
3058  * \throw if a localization in \a locs in not in \a this.
3059  * \sa MEDFileFieldGlobs::shallowCpyPart
3060  */
3061 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3062 {
3063   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3064   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3065     {
3066       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3067       if(!pfl)
3068         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
3069       ret->_pfls.push_back(pfl->deepCopy());
3070     }
3071   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3072     {
3073       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3074       if(!loc)
3075         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
3076       ret->_locs.push_back(loc->deepCopy());
3077     }
3078   ret->setFileName(getFileName());
3079   return ret.retn();
3080 }
3081
3082 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
3083 {
3084 }
3085
3086 MEDFileFieldGlobs::MEDFileFieldGlobs()
3087 {
3088 }
3089
3090 MEDFileFieldGlobs::~MEDFileFieldGlobs()
3091 {
3092 }
3093
3094 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
3095 {
3096   oss << "Profiles :\n";
3097   std::size_t n=_pfls.size();
3098   for(std::size_t i=0;i<n;i++)
3099     {
3100       oss << "  - #" << i << " ";
3101       const DataArrayInt *pfl=_pfls[i];
3102       if(pfl)
3103         oss << "\"" << pfl->getName() << "\"\n";
3104       else
3105         oss << "EMPTY !\n";
3106     }
3107   n=_locs.size();
3108   oss << "Localizations :\n";
3109   for(std::size_t i=0;i<n;i++)
3110     {
3111       oss << "  - #" << i << " ";
3112       const MEDFileFieldLoc *loc=_locs[i];
3113       if(loc)
3114         loc->simpleRepr(oss);
3115       else
3116         oss<< "EMPTY !\n";
3117     }
3118 }
3119
3120 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3121 {
3122   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3123     {
3124       DataArrayInt *elt(*it);
3125       if(elt)
3126         {
3127           std::string name(elt->getName());
3128           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3129             {
3130               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3131                 {
3132                   elt->setName((*it2).second.c_str());
3133                   return;
3134                 }
3135             }
3136         }
3137     }
3138 }
3139
3140 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3141 {
3142   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3143     {
3144       MEDFileFieldLoc *elt(*it);
3145       if(elt)
3146         {
3147           std::string name(elt->getName());
3148           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3149             {
3150               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3151                 {
3152                   elt->setName((*it2).second.c_str());
3153                   return;
3154                 }
3155             }
3156         }
3157     }
3158 }
3159
3160 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3161 {
3162   if(locId<0 || locId>=(int)_locs.size())
3163     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3164   return _locs[locId]->getNbOfGaussPtPerCell();
3165 }
3166
3167 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3168 {
3169   return getLocalizationFromId(getLocalizationId(locName));
3170 }
3171
3172 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3173 {
3174   if(locId<0 || locId>=(int)_locs.size())
3175     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3176   return *_locs[locId];
3177 }
3178
3179 /// @cond INTERNAL
3180 namespace MEDCouplingImpl
3181 {
3182   class LocFinder
3183   {
3184   public:
3185     LocFinder(const std::string& loc):_loc(loc) { }
3186     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3187   private:
3188     const std::string &_loc;
3189   };
3190
3191   class PflFinder
3192   {
3193   public:
3194     PflFinder(const std::string& pfl):_pfl(pfl) { }
3195     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3196   private:
3197     const std::string& _pfl;
3198   };
3199 }
3200 /// @endcond
3201
3202 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3203 {
3204   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3205   if(it==_locs.end())
3206     {
3207       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3208       for(it=_locs.begin();it!=_locs.end();it++)
3209         oss << "\"" << (*it)->getName() << "\", ";
3210       throw INTERP_KERNEL::Exception(oss.str());
3211     }
3212   return std::distance(_locs.begin(),it);
3213 }
3214
3215 /*!
3216  * The returned value is never null.
3217  */
3218 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3219 {
3220   std::string pflNameCpp(pflName);
3221   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3222   if(it==_pfls.end())
3223     {
3224       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3225       for(it=_pfls.begin();it!=_pfls.end();it++)
3226         oss << "\"" << (*it)->getName() << "\", ";
3227       throw INTERP_KERNEL::Exception(oss.str());
3228     }
3229   return *it;
3230 }
3231
3232 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3233 {
3234   if(pflId<0 || pflId>=(int)_pfls.size())
3235     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3236   return _pfls[pflId];
3237 }
3238
3239 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3240 {
3241   if(locId<0 || locId>=(int)_locs.size())
3242     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3243   return *_locs[locId];
3244 }
3245
3246 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3247 {
3248   return getLocalizationFromId(getLocalizationId(locName));
3249 }
3250
3251 /*!
3252  * The returned value is never null.
3253  */
3254 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3255 {
3256   std::string pflNameCpp(pflName);
3257   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3258   if(it==_pfls.end())
3259     {
3260       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3261       for(it=_pfls.begin();it!=_pfls.end();it++)
3262         oss << "\"" << (*it)->getName() << "\", ";
3263       throw INTERP_KERNEL::Exception(oss.str());
3264     }
3265   return *it;
3266 }
3267
3268 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3269 {
3270   if(pflId<0 || pflId>=(int)_pfls.size())
3271     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3272   return _pfls[pflId];
3273 }
3274
3275 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3276 {
3277   std::vector< MCAuto<DataArrayInt> > newPfls;
3278   int i=0;
3279   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3280     {
3281       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3282         newPfls.push_back(*it);
3283     }
3284   _pfls=newPfls;
3285 }
3286
3287 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3288 {
3289   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3290   int i=0;
3291   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3292     {
3293       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3294         newLocs.push_back(*it);
3295     }
3296   _locs=newLocs;
3297 }
3298
3299 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3300 {
3301   int sz=_pfls.size();
3302   std::vector<std::string> ret(sz);
3303   for(int i=0;i<sz;i++)
3304     ret[i]=_pfls[i]->getName();
3305   return ret;
3306 }
3307
3308 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3309 {
3310   int sz=_locs.size();
3311   std::vector<std::string> ret(sz);
3312   for(int i=0;i<sz;i++)
3313     ret[i]=_locs[i]->getName();
3314   return ret;
3315 }
3316
3317 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3318 {
3319   std::vector<std::string> v=getPfls();
3320   std::string s(pflName);
3321   return std::find(v.begin(),v.end(),s)!=v.end();
3322 }
3323
3324 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3325 {
3326   std::vector<std::string> v=getLocs();
3327   std::string s(locName);
3328   return std::find(v.begin(),v.end(),s)!=v.end();
3329 }
3330
3331 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3332 {
3333   std::map<int,std::vector<int> > m;
3334   int i=0;
3335   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3336     {
3337       const DataArrayInt *tmp=(*it);
3338       if(tmp)
3339         {
3340           m[tmp->getHashCode()].push_back(i);
3341         }
3342     }
3343   std::vector< std::vector<int> > ret;
3344   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3345     {
3346       if((*it2).second.size()>1)
3347         {
3348           std::vector<int> ret0;
3349           bool equalityOrNot=false;
3350           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3351             {
3352               std::vector<int>::const_iterator it4=it3; it4++;
3353               for(;it4!=(*it2).second.end();it4++)
3354                 {
3355                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3356                     {
3357                       if(!equalityOrNot)
3358                         ret0.push_back(*it3);
3359                       ret0.push_back(*it4);
3360                       equalityOrNot=true;
3361                     }
3362                 }
3363             }
3364           if(!ret0.empty())
3365             ret.push_back(ret0);
3366         }
3367     }
3368   return ret;
3369 }
3370
3371 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3372 {
3373   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3374 }
3375
3376 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3377 {
3378   std::string name(pfl->getName());
3379   if(name.empty())
3380     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3381   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3382     if(name==(*it)->getName())
3383       {
3384         if(!pfl->isEqual(*(*it)))
3385           {
3386             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3387             throw INTERP_KERNEL::Exception(oss.str());
3388           }
3389       }
3390   pfl->incrRef();
3391   _pfls.push_back(pfl);
3392 }
3393
3394 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)
3395 {
3396   std::string name(locName);
3397   if(name.empty())
3398     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3399   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3400   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3401     if((*it)->isName(locName))
3402       {
3403         if(!(*it)->isEqual(*obj,1e-12))
3404           {
3405             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3406             throw INTERP_KERNEL::Exception(oss.str());
3407           }
3408       }
3409   _locs.push_back(obj);
3410 }
3411
3412 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3413 {
3414   std::vector<std::string> names=getPfls();
3415   return CreateNewNameNotIn("NewPfl_",names);
3416 }
3417
3418 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3419 {
3420   std::vector<std::string> names=getLocs();
3421   return CreateNewNameNotIn("NewLoc_",names);
3422 }
3423
3424 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3425 {
3426   for(std::size_t sz=0;sz<100000;sz++)
3427     {
3428       std::ostringstream tryName;
3429       tryName << prefix << sz;
3430       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3431         return tryName.str();
3432     }
3433   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3434 }
3435
3436 /*!
3437  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3438  *  \param [in] fname - the file name.
3439  */
3440 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3441 {
3442 }
3443
3444 /*!
3445  * Creates an empty MEDFileFieldGlobsReal.
3446  */
3447 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3448 {
3449 }
3450
3451 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3452 {
3453   return 0;
3454 }
3455
3456 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3457 {
3458   std::vector<const BigMemoryObject *> ret;
3459   ret.push_back((const MEDFileFieldGlobs *)_globals);
3460   return ret;
3461 }
3462
3463 /*!
3464  * Returns a string describing profiles and Gauss points held in \a this.
3465  *  \return std::string - the description string.
3466  */
3467 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3468 {
3469   const MEDFileFieldGlobs *glob=_globals;
3470   std::ostringstream oss2; oss2 << glob;
3471   std::string stars(oss2.str().length(),'*');
3472   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3473   if(glob)
3474     glob->simpleRepr(oss);
3475   else
3476     oss << "NO GLOBAL INFORMATION !\n";
3477 }
3478
3479 void MEDFileFieldGlobsReal::resetContent()
3480 {
3481   _globals=MEDFileFieldGlobs::New();
3482 }
3483
3484 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3485 {
3486 }
3487
3488 /*!
3489  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3490  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3491  */
3492 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3493 {
3494   _globals=other._globals;
3495 }
3496
3497 /*!
3498  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3499  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3500  */
3501 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3502 {
3503   const MEDFileFieldGlobs *otherg(other._globals);
3504   if(!otherg)
3505     return ;
3506   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3507 }
3508
3509 /*!
3510  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3511  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3512  */
3513 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3514 {
3515   const MEDFileFieldGlobs *otherg(other._globals);
3516   if(!otherg)
3517     return ;
3518   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3519 }
3520
3521 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3522 {
3523   _globals=other._globals;
3524   if((const MEDFileFieldGlobs *)_globals)
3525     _globals=other._globals->deepCopy();
3526 }
3527
3528 /*!
3529  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3530  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3531  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3532  *         \a this and \a other MEDFileFieldGlobsReal.
3533  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3534  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3535  */
3536 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3537 {
3538   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3539   if(thisGlobals==otherGlobals)
3540     return ;
3541   if(!thisGlobals)
3542     {
3543       _globals=other._globals;
3544       return ;
3545     }
3546   _globals->appendGlobs(*other._globals,eps);
3547 }
3548
3549 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3550 {
3551   checkGlobsPflsPartCoherency();
3552   checkGlobsLocsPartCoherency();
3553 }
3554
3555 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3556 {
3557   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3558 }
3559
3560 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3561 {
3562   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3563 }
3564
3565 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3566 {
3567   contentNotNull()->loadProfileInFile(fid,id,pflName);
3568 }
3569
3570 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3571 {
3572   contentNotNull()->loadProfileInFile(fid,id);
3573 }
3574
3575 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3576 {
3577   contentNotNull()->loadGlobals(fid,*this);
3578 }
3579
3580 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3581 {
3582   contentNotNull()->loadAllGlobals(fid);
3583 }
3584
3585 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3586 {
3587   contentNotNull()->writeGlobals(fid,opt);
3588 }
3589
3590 /*!
3591  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3592  * or getPflsReallyUsedMulti().
3593  *  \return std::vector<std::string> - a sequence of names of all profiles.
3594  */
3595 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3596 {
3597   return contentNotNull()->getPfls();
3598 }
3599
3600 /*!
3601  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3602  * or getLocsReallyUsedMulti().
3603  *  \return std::vector<std::string> - a sequence of names of all localizations.
3604  */
3605 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3606 {
3607   return contentNotNull()->getLocs();
3608 }
3609
3610 /*!
3611  * Checks if the profile with a given name exists.
3612  *  \param [in] pflName - the profile name of interest.
3613  *  \return bool - \c true if the profile named \a pflName exists.
3614  */
3615 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3616 {
3617   return contentNotNull()->existsPfl(pflName);
3618 }
3619
3620 /*!
3621  * Checks if the localization with a given name exists.
3622  *  \param [in] locName - the localization name of interest.
3623  *  \return bool - \c true if the localization named \a locName exists.
3624  */
3625 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3626 {
3627   return contentNotNull()->existsLoc(locName);
3628 }
3629
3630 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3631 {
3632   return contentNotNull()->createNewNameOfPfl();
3633 }
3634
3635 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3636 {
3637   return contentNotNull()->createNewNameOfLoc();
3638 }
3639
3640 /*!
3641  * Sets the name of a MED file.
3642  *  \param [inout] fileName - the file name.
3643  */
3644 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3645 {
3646   contentNotNull()->setFileName(fileName);
3647 }
3648
3649 /*!
3650  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3651  * in the same order.
3652  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3653  *          Each item of this sequence is a vector containing ids of equal profiles.
3654  */
3655 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3656 {
3657   return contentNotNull()->whichAreEqualProfiles();
3658 }
3659
3660 /*!
3661  * Finds equal localizations.
3662  *  \param [in] eps - a precision used to compare real values of the localizations.
3663  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3664  *          Each item of this sequence is a vector containing ids of equal localizations.
3665  */
3666 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3667 {
3668   return contentNotNull()->whichAreEqualLocs(eps);
3669 }
3670
3671 /*!
3672  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3673  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3674  *        this sequence is a pair whose 
3675  *        - the first item is a vector of profile names to replace by the second item,
3676  *        - the second item is a profile name to replace every profile name of the first item.
3677  */
3678 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3679 {
3680   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3681 }
3682
3683 /*!
3684  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3685  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3686  *        this sequence is a pair whose 
3687  *        - the first item is a vector of localization names to replace by the second item,
3688  *        - the second item is a localization name to replace every localization name of the first item.
3689  */
3690 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3691 {
3692   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3693 }
3694
3695 /*!
3696  * Replaces references to some profiles (a reference is a profile name) by references
3697  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3698  * them-selves accordingly. <br>
3699  * This method is a generalization of changePflName().
3700  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3701  *        this sequence is a pair whose 
3702  *        - the first item is a vector of profile names to replace by the second item,
3703  *        - the second item is a profile name to replace every profile of the first item.
3704  * \sa changePflsRefsNamesGen()
3705  * \sa changePflName()
3706  */
3707 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3708 {
3709   changePflsRefsNamesGen(mapOfModif);
3710   changePflsNamesInStruct(mapOfModif);
3711 }
3712
3713 /*!
3714  * Replaces references to some localizations (a reference is a localization name) by references
3715  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3716  * them-selves accordingly. <br>
3717  * This method is a generalization of changeLocName().
3718  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3719  *        this sequence is a pair whose 
3720  *        - the first item is a vector of localization names to replace by the second item,
3721  *        - the second item is a localization name to replace every localization of the first item.
3722  * \sa changeLocsRefsNamesGen()
3723  * \sa changeLocName()
3724  */
3725 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3726 {
3727   changeLocsRefsNamesGen(mapOfModif);
3728   changeLocsNamesInStruct(mapOfModif);
3729 }
3730
3731 /*!
3732  * Renames the profile having a given name and updates references to this profile.
3733  *  \param [in] oldName - the name of the profile to rename.
3734  *  \param [in] newName - a new name of the profile.
3735  * \sa changePflsNames().
3736  */
3737 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3738 {
3739   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3740   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3741   mapOfModif[0]=p;
3742   changePflsNames(mapOfModif);
3743 }
3744
3745 /*!
3746  * Renames the localization having a given name and updates references to this localization.
3747  *  \param [in] oldName - the name of the localization to rename.
3748  *  \param [in] newName - a new name of the localization.
3749  * \sa changeLocsNames().
3750  */
3751 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3752 {
3753   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3754   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3755   mapOfModif[0]=p;
3756   changeLocsNames(mapOfModif);
3757 }
3758
3759 /*!
3760  * Removes duplicated profiles. Returns a map used to update references to removed 
3761  * profiles via changePflsRefsNamesGen().
3762  * Equal profiles are found using whichAreEqualProfiles().
3763  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3764  *          a sequence describing the performed replacements of profiles. Each element of
3765  *          this sequence is a pair whose
3766  *          - the first item is a vector of profile names replaced by the second item,
3767  *          - the second item is a profile name replacing every profile of the first item.
3768  */
3769 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3770 {
3771   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3772   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3773   int i=0;
3774   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3775     {
3776       std::vector< std::string > tmp((*it).size());
3777       int j=0;
3778       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3779         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3780       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3781       ret[i]=p;
3782       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3783       killProfileIds(tmp2);
3784     }
3785   changePflsRefsNamesGen(ret);
3786   return ret;
3787 }
3788
3789 /*!
3790  * Removes duplicated localizations. Returns a map used to update references to removed 
3791  * localizations via changeLocsRefsNamesGen().
3792  * Equal localizations are found using whichAreEqualLocs().
3793  *  \param [in] eps - a precision used to compare real values of the localizations.
3794  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3795  *          a sequence describing the performed replacements of localizations. Each element of
3796  *          this sequence is a pair whose
3797  *          - the first item is a vector of localization names replaced by the second item,
3798  *          - the second item is a localization name replacing every localization of the first item.
3799  */
3800 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3801 {
3802   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3803   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3804   int i=0;
3805   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3806     {
3807       std::vector< std::string > tmp((*it).size());
3808       int j=0;
3809       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3810         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3811       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3812       ret[i]=p;
3813       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3814       killLocalizationIds(tmp2);
3815     }
3816   changeLocsRefsNamesGen(ret);
3817   return ret;
3818 }
3819
3820 /*!
3821  * Returns number of Gauss points per cell in a given localization.
3822  *  \param [in] locId - an id of the localization of interest.
3823  *  \return int - the number of the Gauss points per cell.
3824  */
3825 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3826 {
3827   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3828 }
3829
3830 /*!
3831  * Returns an id of a localization by its name.
3832  *  \param [in] loc - the localization name of interest.
3833  *  \return int - the id of the localization.
3834  *  \throw If there is no a localization named \a loc.
3835  */
3836 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3837 {
3838   return contentNotNull()->getLocalizationId(loc);
3839 }
3840
3841 /*!
3842  * Returns the name of the MED file.
3843  *  \return const std::string&  - the MED file name.
3844  */
3845 std::string MEDFileFieldGlobsReal::getFileName() const
3846 {
3847   return contentNotNull()->getFileName();
3848 }
3849
3850 /*!
3851  * Returns a localization object by its name.
3852  *  \param [in] locName - the name of the localization of interest.
3853  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3854  *  \throw If there is no a localization named \a locName.
3855  */
3856 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3857 {
3858   return contentNotNull()->getLocalization(locName);
3859 }
3860
3861 /*!
3862  * Returns a localization object by its id.
3863  *  \param [in] locId - the id of the localization of interest.
3864  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3865  *  \throw If there is no a localization with id \a locId.
3866  */
3867 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3868 {
3869   return contentNotNull()->getLocalizationFromId(locId);
3870 }
3871
3872 /*!
3873  * Returns a profile array by its name.
3874  *  \param [in] pflName - the name of the profile of interest.
3875  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3876  *  \throw If there is no a profile named \a pflName.
3877  */
3878 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3879 {
3880   return contentNotNull()->getProfile(pflName);
3881 }
3882
3883 /*!
3884  * Returns a profile array by its id.
3885  *  \param [in] pflId - the id of the profile of interest.
3886  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3887  *  \throw If there is no a profile with id \a pflId.
3888  */
3889 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3890 {
3891   return contentNotNull()->getProfileFromId(pflId);
3892 }
3893
3894 /*!
3895  * Returns a localization object, apt for modification, by its id.
3896  *  \param [in] locId - the id of the localization of interest.
3897  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3898  *          having the id \a locId.
3899  *  \throw If there is no a localization with id \a locId.
3900  */
3901 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3902 {
3903   return contentNotNull()->getLocalizationFromId(locId);
3904 }
3905
3906 /*!
3907  * Returns a localization object, apt for modification, by its name.
3908  *  \param [in] locName - the name of the localization of interest.
3909  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3910  *          having the name \a locName.
3911  *  \throw If there is no a localization named \a locName.
3912  */
3913 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3914 {
3915   return contentNotNull()->getLocalization(locName);
3916 }
3917
3918 /*!
3919  * Returns a profile array, apt for modification, by its name.
3920  *  \param [in] pflName - the name of the profile of interest.
3921  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3922  *  \throw If there is no a profile named \a pflName.
3923  */
3924 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3925 {
3926   return contentNotNull()->getProfile(pflName);
3927 }
3928
3929 /*!
3930  * Returns a profile array, apt for modification, by its id.
3931  *  \param [in] pflId - the id of the profile of interest.
3932  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3933  *  \throw If there is no a profile with id \a pflId.
3934  */
3935 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3936 {
3937   return contentNotNull()->getProfileFromId(pflId);
3938 }
3939
3940 /*!
3941  * Removes profiles given by their ids. No data is updated to track this removal.
3942  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3943  */
3944 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3945 {
3946   contentNotNull()->killProfileIds(pflIds);
3947 }
3948
3949 /*!
3950  * Removes localizations given by their ids. No data is updated to track this removal.
3951  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3952  */
3953 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3954 {
3955   contentNotNull()->killLocalizationIds(locIds);
3956 }
3957
3958 /*!
3959  * Stores a profile array.
3960  *  \param [in] pfl - the profile array to store.
3961  *  \throw If the name of \a pfl is empty.
3962  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3963  *         different ids.
3964  */
3965 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3966 {
3967   contentNotNull()->appendProfile(pfl);
3968 }
3969
3970 /*!
3971  * Adds a new localization of Gauss points.
3972  *  \param [in] locName - the name of the new localization.
3973  *  \param [in] geoType - a geometrical type of the reference cell.
3974  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3975  *         must be \c nbOfNodesPerCell * \c dimOfType.
3976  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3977  *         must be  _wg_.size() * \c dimOfType.
3978  *  \param [in] w - the weights of Gauss points.
3979  *  \throw If \a locName is empty.
3980  *  \throw If a localization with the name \a locName already exists but is
3981  *         different form the new one.
3982  */
3983 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)
3984 {
3985   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3986 }
3987
3988 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3989 {
3990   MEDFileFieldGlobs *g(_globals);
3991   if(!g)
3992     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3993   return g;
3994 }
3995
3996 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3997 {
3998   const MEDFileFieldGlobs *g(_globals);
3999   if(!g)
4000     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
4001   return g;
4002 }
4003
4004 //= MEDFileFieldNameScope
4005
4006 MEDFileFieldNameScope::MEDFileFieldNameScope()
4007 {
4008 }
4009
4010 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
4011 {
4012 }
4013
4014 /*!
4015  * Returns the name of \a this field.
4016  *  \return std::string - a string containing the field name.
4017  */
4018 std::string MEDFileFieldNameScope::getName() const
4019 {
4020   return _name;
4021 }
4022
4023 /*!
4024  * Sets name of \a this field
4025  *  \param [in] name - the new field name.
4026  */
4027 void MEDFileFieldNameScope::setName(const std::string& fieldName)
4028 {
4029   _name=fieldName;
4030 }
4031
4032 std::string MEDFileFieldNameScope::getDtUnit() const
4033 {
4034   return _dt_unit;
4035 }
4036
4037 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
4038 {
4039   _dt_unit=dtUnit;
4040 }
4041
4042 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
4043 {
4044   _name=other._name;
4045   _dt_unit=other._dt_unit;
4046 }
4047
4048 //= MEDFileAnyTypeField1TSWithoutSDA
4049
4050 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
4051 {
4052   _field_per_mesh.resize(other._field_per_mesh.size());
4053   std::size_t i=0;
4054   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
4055     {
4056       if((const MEDFileFieldPerMesh *)*it)
4057         _field_per_mesh[i]=(*it)->deepCopy(this);
4058     }
4059 }
4060
4061 /*!
4062  * Prints a string describing \a this field into a stream. This string is outputted 
4063  * by \c print Python command.
4064  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
4065  *  \param [in,out] oss - the out stream.
4066  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
4067  *          info id printed, else, not.
4068  */
4069 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4070 {
4071   std::string startOfLine(bkOffset,' ');
4072   oss << startOfLine << "Field ";
4073   if(bkOffset==0)
4074     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
4075   oss << "on one time Step ";
4076   if(f1tsId>=0)
4077     oss << "(" << f1tsId << ") ";
4078   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
4079   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
4080   const DataArray *arr=getUndergroundDataArray();
4081   if(arr)
4082     {
4083       const std::vector<std::string> &comps=arr->getInfoOnComponents();
4084       if(f1tsId<0)
4085         {
4086           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
4087           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
4088             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
4089         }
4090       if(arr->isAllocated())
4091         {
4092           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
4093         }
4094       else
4095         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
4096     }
4097   else
4098     {
4099       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4100     }
4101   oss << startOfLine << "----------------------" << std::endl;
4102   if(!_field_per_mesh.empty())
4103     {
4104       int i=0;
4105       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4106         {
4107           const MEDFileFieldPerMesh *cur=(*it2);
4108           if(cur)
4109             cur->simpleRepr(bkOffset,oss,i);
4110           else
4111             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4112         }
4113     }
4114   else
4115     {
4116       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4117     }
4118   oss << startOfLine << "----------------------" << std::endl;
4119 }
4120
4121 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4122 {
4123   const DataArray *arr(getUndergroundDataArray());
4124   if(!arr)
4125     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4126   int nbOfCompo=arr->getNumberOfComponents();
4127   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4128   for(int i=0;i<nbOfCompo;i++)
4129     {
4130       ret[i]=deepCopy();
4131       std::vector<int> v(1,i);
4132       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4133       ret[i]->setArray(arr2);
4134     }
4135   return ret;
4136 }
4137
4138 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)
4139 {
4140 }
4141
4142 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4143 {
4144 }
4145
4146 /*!
4147  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4148  * empty. Returns -1 if this in on nodes.
4149  *  \return int - the dimension of \a this.
4150  */
4151 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4152 {
4153   int ret=-2;
4154   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4155     (*it)->getDimension(ret);
4156   return ret;
4157 }
4158
4159 /*!
4160  * Returns the mesh name.
4161  *  \return std::string - a string holding the mesh name.
4162  *  \throw If \c _field_per_mesh.empty()
4163  */
4164 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
4165 {
4166   if(_field_per_mesh.empty())
4167     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
4168   return _field_per_mesh[0]->getMeshName();
4169 }
4170
4171 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
4172 {
4173   std::string oldName(getMeshName());
4174   std::vector< std::pair<std::string,std::string> > v(1);
4175   v[0].first=oldName; v[0].second=newMeshName;
4176   changeMeshNames(v);
4177 }
4178
4179 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4180 {
4181   bool ret=false;
4182   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4183     {
4184       MEDFileFieldPerMesh *cur(*it);
4185       if(cur)
4186         ret=cur->changeMeshNames(modifTab) || ret;
4187     }
4188   return ret;
4189 }
4190
4191 /*!
4192  * Returns the number of iteration of the state of underlying mesh.
4193  *  \return int - the iteration number.
4194  *  \throw If \c _field_per_mesh.empty()
4195  */
4196 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4197 {
4198   if(_field_per_mesh.empty())
4199     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4200   return _field_per_mesh[0]->getMeshIteration();
4201 }
4202
4203 /*!
4204  * Returns the order number of iteration of the state of underlying mesh.
4205  *  \return int - the order number.
4206  *  \throw If \c _field_per_mesh.empty()
4207  */
4208 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4209 {
4210   if(_field_per_mesh.empty())
4211     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4212   return _field_per_mesh[0]->getMeshOrder();
4213 }
4214
4215 /*!
4216  * Checks if \a this field is tagged by a given iteration number and a given
4217  * iteration order number.
4218  *  \param [in] iteration - the iteration number of interest.
4219  *  \param [in] order - the iteration order number of interest.
4220  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4221  *          \a this->getOrder() == \a order.
4222  */
4223 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4224 {
4225   return iteration==_iteration && order==_order;
4226 }
4227
4228 /*!
4229  * Returns number of iteration and order number of iteration when
4230  * \a this field has been calculated.
4231  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4232  *          order number.
4233  */
4234 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4235 {
4236   std::pair<int,int> p;
4237   fillIteration(p);
4238   return p;
4239 }
4240
4241 /*!
4242  * Returns number of iteration and order number of iteration when
4243  * \a this field has been calculated.
4244  *  \param [in,out] p - a pair returning the iteration number and the iteration
4245  *          order number.
4246  */
4247 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4248 {
4249   p.first=_iteration;
4250   p.second=_order;
4251 }
4252
4253 /*!
4254  * Returns all types of spatial discretization of \a this field.
4255  *  \param [in,out] types - a sequence of types of \a this field.
4256  */
4257 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4258 {
4259   std::set<TypeOfField> types2;
4260   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4261     {
4262       (*it)->fillTypesOfFieldAvailable(types2);
4263     }
4264   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4265   std::copy(types2.begin(),types2.end(),bi);
4266 }
4267
4268 /*!
4269  * Returns all types of spatial discretization of \a this field.
4270  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4271  *          of \a this field.
4272  */
4273 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4274 {
4275   std::vector<TypeOfField> ret;
4276   fillTypesOfFieldAvailable(ret);
4277   return ret;
4278 }
4279
4280 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4281 {
4282   std::vector<std::string> ret;
4283   std::set<std::string> ret2;
4284   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4285     {
4286       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4287       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4288         if(ret2.find(*it2)==ret2.end())
4289           {
4290             ret.push_back(*it2);
4291             ret2.insert(*it2);
4292           }
4293     }
4294   return ret;
4295 }
4296
4297 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4298 {
4299   std::vector<std::string> ret;
4300   std::set<std::string> ret2;
4301   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4302     {
4303       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4304       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4305         if(ret2.find(*it2)==ret2.end())
4306           {
4307             ret.push_back(*it2);
4308             ret2.insert(*it2);
4309           }
4310     }
4311   return ret;
4312 }
4313
4314 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4315 {
4316   std::vector<std::string> ret;
4317   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4318     {
4319       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4320       ret.insert(ret.end(),tmp.begin(),tmp.end());
4321     }
4322   return ret;
4323 }
4324
4325 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4326 {
4327   std::vector<std::string> ret;
4328   std::set<std::string> ret2;
4329   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4330     {
4331       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4332       ret.insert(ret.end(),tmp.begin(),tmp.end());
4333     }
4334   return ret;
4335 }
4336
4337 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4338 {
4339   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4340     (*it)->changePflsRefsNamesGen(mapOfModif);
4341 }
4342
4343 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4344 {
4345   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4346     (*it)->changeLocsRefsNamesGen(mapOfModif);
4347 }
4348
4349 /*!
4350  * Returns all attributes of parts of \a this field lying on a given mesh.
4351  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4352  * item of every of returned sequences refers to the _i_-th part of \a this field.
4353  * Thus all sequences returned by this method are of the same length equal to number
4354  * of different types of supporting entities.<br>
4355  * A field part can include sub-parts with several different spatial discretizations,
4356  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4357  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4358  * of a nested sequence corresponds to a type of spatial discretization.<br>
4359  * This method allows for iteration over MEDFile DataStructure without any overhead.
4360  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4361  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4362  *          not checked if \a mname == \c NULL).
4363  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4364  *          a field part is returned. 
4365  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4366  *          This sequence is of the same length as \a types. 
4367  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4368  *          discretization. A profile name can be empty.
4369  *          Length of this and of nested sequences is the same as that of \a typesF.
4370  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4371  *          discretization. A localization name can be empty.
4372  *          Length of this and of nested sequences is the same as that of \a typesF.
4373  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4374  *          of ids of tuples within the data array, per each type of spatial
4375  *          discretization within one mesh entity type. 
4376  *          Length of this and of nested sequences is the same as that of \a typesF.
4377  *  \throw If no field is lying on \a mname.
4378  */
4379 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
4380 {
4381   int meshId=0;
4382   if(!mname.empty())
4383     meshId=getMeshIdFromMeshName(mname);
4384   else
4385     if(_field_per_mesh.empty())
4386       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4387   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4388 }
4389
4390 /*!
4391  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4392  * maximal absolute dimension and values returned via the out parameter \a levs are 
4393  * dimensions relative to the maximal absolute dimension. <br>
4394  * This method is designed for MEDFileField1TS instances that have a discretization
4395  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4396  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4397  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4398  * Only these 3 discretizations will be taken into account here. If \a this is
4399  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4400  * This method is useful to make the link between the dimension of the underlying mesh
4401  * and the levels of \a this, because it is possible that the highest dimension of \a this
4402  * field is not equal to the dimension of the underlying mesh.
4403  * 
4404  * Let's consider the following case:
4405  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4406  * TETRA4, HEXA8, TRI3 and SEG2.
4407  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4408  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4409  *
4410  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4411  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4412  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4413  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4414  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4415  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4416  * For example<br>
4417  * to retrieve the highest level of
4418  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4419  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4420  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4421  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4422  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4423  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4424  *          not checked if \a mname == \c NULL).
4425  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4426  *          absolute one. They are in decreasing order. This sequence is cleared before
4427  *          filling it in.
4428  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4429  *  \throw If no field is lying on \a mname.
4430  */
4431 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4432 {
4433   levs.clear();
4434   int meshId=getMeshIdFromMeshName(mname);
4435   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4436   std::vector< std::vector<TypeOfField> > typesF;
4437   std::vector< std::vector<std::string> > pfls, locs;
4438   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4439   if(types.empty())
4440     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4441   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4442   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4443     return -1;
4444   st.erase(INTERP_KERNEL::NORM_ERROR);
4445   std::set<int> ret1;
4446   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4447     {
4448       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4449       ret1.insert((int)cm.getDimension());
4450     }
4451   int ret=*std::max_element(ret1.begin(),ret1.end());
4452   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4453   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4454   return ret;
4455 }
4456
4457 /*!
4458  * \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.
4459  * \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.
4460  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4461  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4462  */
4463 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4464 {
4465   int mid=getMeshIdFromMeshName(mName);
4466   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4467 }
4468
4469 /*!
4470  * \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.
4471  * \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.
4472  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4473  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4474  */
4475 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4476 {
4477   int mid=getMeshIdFromMeshName(mName);
4478   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4479 }
4480
4481 /*!
4482  * \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.
4483  */
4484 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4485 {
4486   if(_field_per_mesh.empty())
4487     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4488   if(mName.empty())
4489     return 0;
4490   std::string mName2(mName);
4491   int ret=0;
4492   std::vector<std::string> msg;
4493   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4494     if(mName2==(*it)->getMeshName())
4495       return ret;
4496     else
4497       msg.push_back((*it)->getMeshName());
4498   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4499   oss << "Possible meshes are : ";
4500   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4501     oss << "\"" << (*it2) << "\" ";
4502   throw INTERP_KERNEL::Exception(oss.str());
4503 }
4504
4505 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4506 {
4507   if(!mesh)
4508     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4509   std::string tmp(mesh->getName());
4510   if(tmp.empty())
4511     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4512   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4513   int i=0;
4514   for(;it!=_field_per_mesh.end();it++,i++)
4515     {
4516       if((*it)->getMeshName()==tmp)
4517         return i;
4518     }
4519   int sz=_field_per_mesh.size();
4520   _field_per_mesh.resize(sz+1);
4521   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4522   return sz;
4523 }
4524
4525 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4526                                                                    MEDFileFieldGlobsReal& glob)
4527 {
4528   bool ret=false;
4529   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4530     {
4531       MEDFileFieldPerMesh *fpm(*it);
4532       if(fpm)
4533         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4534     }
4535   return ret;
4536 }
4537
4538 /*!
4539  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4540  * splitting that leads to single spatial discretization of this.
4541  *
4542  * \sa splitMultiDiscrPerGeoTypes
4543  */
4544 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4545 {
4546   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4547   std::vector< std::vector<TypeOfField> > typesF;
4548   std::vector< std::vector<std::string> > pfls,locs;
4549   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4550   std::set<TypeOfField> allEnt;
4551   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4552     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4553       allEnt.insert(*it2);
4554   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4555   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4556   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4557     {
4558       std::vector< std::pair<int,int> > its;
4559       ret[i]=shallowCpy();
4560       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4561       ret[i]->updateData(newLgth,its);
4562     }
4563   return ret;
4564 }
4565
4566 /*!
4567  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4568  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4569  *
4570  * \sa splitDiscretizations
4571  */
4572 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4573 {
4574   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4575   std::vector< std::vector<TypeOfField> > typesF;
4576   std::vector< std::vector<std::string> > pfls,locs;
4577   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4578   std::set<TypeOfField> allEnt;
4579   std::size_t nbOfMDPGT(0),ii(0);
4580   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4581     {
4582       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4583       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4584         allEnt.insert(*it2);
4585     }
4586   if(allEnt.size()!=1)
4587     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4588   if(nbOfMDPGT==0)
4589     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4590   if(nbOfMDPGT==1)
4591     {
4592       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4593       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4594       return ret0;
4595     }
4596   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4597   for(std::size_t i=0;i<nbOfMDPGT;i++)
4598     {
4599       std::vector< std::pair<int,int> > its;
4600       ret[i]=shallowCpy();
4601       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4602       ret[i]->updateData(newLgth,its);
4603     }
4604   return ret;
4605 }
4606
4607 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4608 {
4609   int globalCounter(0);
4610   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4611     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4612   return globalCounter;
4613 }
4614
4615 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4616 {
4617   int globalCounter(0);
4618   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4619     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4620   return globalCounter;
4621 }
4622
4623 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4624 {
4625   if(_nb_of_tuples_to_be_allocated>=0)
4626     {
4627       _nb_of_tuples_to_be_allocated=newLgth;
4628       const DataArray *oldArr(getUndergroundDataArray());
4629       if(oldArr)
4630         {
4631           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4632           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4633           setArray(newArr);
4634           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4635         }
4636       return ;
4637     }
4638   if(_nb_of_tuples_to_be_allocated==-1)
4639     return ;
4640   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4641     {
4642       const DataArray *oldArr(getUndergroundDataArray());
4643       if(!oldArr || !oldArr->isAllocated())
4644         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4645       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4646       newArr->alloc(newLgth,getNumberOfComponents());
4647       if(oldArr)
4648         newArr->copyStringInfoFrom(*oldArr);
4649       int pos=0;
4650       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4651         {
4652           if((*it).second<(*it).first)
4653             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4654           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4655           pos+=(*it).second-(*it).first;
4656         }
4657       setArray(newArr);
4658       return ;
4659     }
4660   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4661 }
4662
4663 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4664 {
4665   if(_field_per_mesh.empty())
4666     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4667   if(_field_per_mesh.size()>1)
4668     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4669   _field_per_mesh[0]->copyOptionsFrom(opts);
4670   _field_per_mesh[0]->writeLL(fid,nasc);
4671 }
4672
4673 /*!
4674  * 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.
4675  * If false is returned the memory allocation is not required.
4676  */
4677 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4678 {
4679   if(_nb_of_tuples_to_be_allocated>=0)
4680     {
4681       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4682       _nb_of_tuples_to_be_allocated=-2;
4683       return true;
4684     }
4685   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4686     return false;
4687   if(_nb_of_tuples_to_be_allocated==-1)
4688     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4689   if(_nb_of_tuples_to_be_allocated<-3)
4690     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4691   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4692 }
4693
4694 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4695 {
4696   med_int numdt,numit;
4697   med_float dt;
4698   med_int nmesh;
4699   med_bool localMesh;
4700   med_int meshnumdt,meshnumit;
4701   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4702   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4703   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4704   if(_iteration!=numdt || _order!=numit)
4705     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4706   _field_per_mesh.resize(nmesh);
4707   //
4708   MEDFileMesh *mm(0);
4709   if(ms)
4710     {
4711       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4712       mm=ms->getMeshWithName(meshNameCpp);
4713     }
4714   //
4715   for(int i=0;i<nmesh;i++)
4716     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4717   _nb_of_tuples_to_be_allocated=0;
4718   for(int i=0;i<nmesh;i++)
4719     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4720 }
4721
4722 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4723 {
4724   allocIfNecessaryTheArrayToReceiveDataFromFile();
4725   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4726     (*it)->loadBigArraysRecursively(fid,nasc);
4727 }
4728
4729 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4730 {
4731   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4732     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4733       (*it)->loadBigArraysRecursively(fid,nasc);
4734 }
4735
4736 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4737 {
4738   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4739   loadBigArraysRecursively(fid,nasc);
4740 }
4741
4742 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4743 {
4744   DataArray *thisArr(getUndergroundDataArray());
4745   if(thisArr && thisArr->isAllocated())
4746     {
4747       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4748       thisArr->desallocate();
4749     }
4750 }
4751
4752 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4753 {
4754   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
4755 }
4756
4757 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4758 {
4759   std::vector<const BigMemoryObject *> ret;
4760   if(getUndergroundDataArray())
4761     ret.push_back(getUndergroundDataArray());
4762   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4763     ret.push_back((const MEDFileFieldPerMesh *)*it);
4764   return ret;
4765 }
4766
4767 /*!
4768  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4769  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4770  * "Sort By Type"), if not, an exception is thrown. 
4771  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4772  *  \param [in] arr - the array of values.
4773  *  \param [in,out] glob - the global data where profiles and localization present in
4774  *          \a field, if any, are added.
4775  *  \throw If the name of \a field is empty.
4776  *  \throw If the data array of \a field is not set.
4777  *  \throw If \a this->_arr is already allocated but has different number of components
4778  *         than \a field.
4779  *  \throw If the underlying mesh of \a field has no name.
4780  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4781  */
4782 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4783 {
4784   const MEDCouplingMesh *mesh=field->getMesh();
4785   //
4786   TypeOfField type=field->getTypeOfField();
4787   std::vector<DataArrayInt *> dummy;
4788   int start=copyTinyInfoFrom(field,arr);
4789   int pos=addNewEntryIfNecessary(mesh);
4790   if(type!=ON_NODES)
4791     {
4792       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4793       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4794     }
4795   else
4796     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4797 }
4798
4799 /*!
4800  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4801  * of a given mesh are used as the support of the given field (a real support is not used). 
4802  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4803  * Order of underlying mesh entities of the given field specified by \a profile parameter
4804  * is not prescribed; this method permutes field values to have them sorted by element
4805  * type as required for writing to MED file. A new profile is added only if no equal
4806  * profile is missing. 
4807  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4808  *  \param [in] arrOfVals - the values of the field \a field used.
4809  *  \param [in] mesh - the supporting mesh of \a field.
4810  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4811  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4812  *  \param [in,out] glob - the global data where profiles and localization present in
4813  *          \a field, if any, are added.
4814  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4815  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4816  *  \throw If the data array of \a field is not set.
4817  *  \throw If \a this->_arr is already allocated but has different number of components
4818  *         than \a field.
4819  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4820  *  \sa setFieldNoProfileSBT()
4821  */
4822 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4823 {
4824   if(!field)
4825     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4826   if(!arrOfVals || !arrOfVals->isAllocated())
4827     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4828   TypeOfField type=field->getTypeOfField();
4829   std::vector<DataArrayInt *> idsInPflPerType;
4830   std::vector<DataArrayInt *> idsPerType;
4831   std::vector<int> code,code2;
4832   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4833   if(type!=ON_NODES)
4834     {
4835       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4836       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4837       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4838       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4839       // start of check
4840       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
4841       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4842       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4843         {
4844           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4845           throw INTERP_KERNEL::Exception(oss.str());
4846         }
4847       // end of check
4848       int start=copyTinyInfoFrom(field,arrOfVals);
4849       code2=m->getDistributionOfTypes();
4850       //
4851       int pos=addNewEntryIfNecessary(m);
4852       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4853     }
4854   else
4855     {
4856       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4857         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4858       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4859       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4860       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4861       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4862         {
4863           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4864           throw INTERP_KERNEL::Exception(oss.str());
4865         }
4866       int start=copyTinyInfoFrom(field,arrOfVals);
4867       int pos=addNewEntryIfNecessary(m);
4868       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4869     }
4870 }
4871
4872 /*!
4873  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4874  */
4875 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4876 {
4877   if(_nb_of_tuples_to_be_allocated>=0)
4878     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 !");
4879   DataArray *arr(getOrCreateAndGetArray());
4880   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4881   _nb_of_tuples_to_be_allocated=-3;
4882 }
4883
4884 /*!
4885  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4886  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4887  * larger by the size of \a field. Returns an id of the first not filled
4888  * tuple of \a this->_arr.
4889  *  \param [in] field - the field to copy the info on components and the name from.
4890  *  \return int - the id of first not initialized tuple of \a this->_arr.
4891  *  \throw If the name of \a field is empty.
4892  *  \throw If the data array of \a field is not set.
4893  *  \throw If \a this->_arr is already allocated but has different number of components
4894  *         than \a field.
4895  */
4896 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4897 {
4898   if(!field)
4899     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4900   std::string name(field->getName());
4901   setName(name.c_str());
4902   setDtUnit(field->getTimeUnit());
4903   if(name.empty())
4904     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4905   if(!arr)
4906     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4907   if(!arr->isAllocated())
4908     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4909   _dt=field->getTime(_iteration,_order);
4910   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4911   if(!getOrCreateAndGetArray()->isAllocated())
4912     {
4913       allocNotFromFile(arr->getNumberOfTuples());
4914       return 0;
4915     }
4916   else
4917     {
4918       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4919       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4920       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4921       _nb_of_tuples_to_be_allocated=-3;
4922       return oldNbOfTuples;
4923     }
4924 }
4925
4926 /*!
4927  * Returns number of components in \a this field
4928  *  \return int - the number of components.
4929  */
4930 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4931 {
4932   return getOrCreateAndGetArray()->getNumberOfComponents();
4933 }
4934
4935 /*!
4936  * Change info on components in \a this.
4937  * \throw If size of \a infos is not equal to the number of components already in \a this.
4938  */
4939 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4940 {
4941   DataArray *arr=getOrCreateAndGetArray();
4942   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4943 }
4944
4945 /*!
4946  * Returns info on components of \a this field.
4947  *  \return const std::vector<std::string>& - a sequence of strings each being an
4948  *          information on _i_-th component.
4949  */
4950 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4951 {
4952   const DataArray *arr=getOrCreateAndGetArray();
4953   return arr->getInfoOnComponents();
4954 }
4955
4956 /*!
4957  * Returns a mutable info on components of \a this field.
4958  *  \return std::vector<std::string>& - a sequence of strings each being an
4959  *          information on _i_-th component.
4960  */
4961 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4962 {
4963   DataArray *arr=getOrCreateAndGetArray();
4964   return arr->getInfoOnComponents();
4965 }
4966
4967 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4968 {
4969   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4970     {
4971       const MEDFileFieldPerMesh *fpm(*it);
4972       if(!fpm)
4973         continue;
4974       if(fpm->presenceOfMultiDiscPerGeoType())
4975         return true;
4976     }
4977   return false;
4978 }
4979
4980 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4981 {
4982   static const char MSG0[]="MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is too complex to be able to be extracted with  \"field\" method ! Call getFieldOnMeshAtLevel method instead to deal with complexity !";
4983   if(_field_per_mesh.empty())
4984     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
4985   if(_field_per_mesh.size()>1)
4986     throw INTERP_KERNEL::Exception(MSG0);
4987   if(_field_per_mesh[0].isNull())
4988     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
4989   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
4990   std::set<TypeOfField> types;
4991   pm->fillTypesOfFieldAvailable(types);
4992   if(types.size()!=1)
4993     throw INTERP_KERNEL::Exception(MSG0);
4994   TypeOfField type(*types.begin());
4995   int meshDimRelToMax(0);
4996   if(type==ON_NODES)
4997     meshDimRelToMax=0;
4998   else
4999     {
5000       int myDim(std::numeric_limits<int>::max());
5001       bool isUnique(pm->isUniqueLevel(myDim));
5002       if(!isUnique)
5003         throw INTERP_KERNEL::Exception(MSG0);
5004       meshDimRelToMax=myDim-mesh->getMeshDimension();
5005       if(meshDimRelToMax>0)
5006         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
5007     }
5008   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
5009 }
5010
5011 /*!
5012  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5013  *  \param [in] type - a spatial discretization of the new field.
5014  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5015  *  \param [in] mName - a name of the supporting mesh.
5016  *  \param [in] renumPol - specifies how to permute values of the result field according to
5017  *          the optional numbers of cells and nodes, if any. The valid values are
5018  *          - 0 - do not permute.
5019  *          - 1 - permute cells.
5020  *          - 2 - permute nodes.
5021  *          - 3 - permute cells and nodes.
5022  *
5023  *  \param [in] glob - the global data storing profiles and localization.
5024  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5025  *          caller is to delete this field using decrRef() as it is no more needed. 
5026  *  \throw If the MED file is not readable.
5027  *  \throw If there is no mesh named \a mName in the MED file.
5028  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5029  *  \throw If no field of \a this is lying on the mesh \a mName.
5030  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5031  */
5032 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5033 {
5034   MCAuto<MEDFileMesh> mm;
5035   if(mName.empty())
5036     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5037   else
5038     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5039   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5040 }
5041
5042 /*!
5043  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5044  *  \param [in] type - a spatial discretization of the new field.
5045  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5046  *  \param [in] renumPol - specifies how to permute values of the result field according to
5047  *          the optional numbers of cells and nodes, if any. The valid values are
5048  *          - 0 - do not permute.
5049  *          - 1 - permute cells.
5050  *          - 2 - permute nodes.
5051  *          - 3 - permute cells and nodes.
5052  *
5053  *  \param [in] glob - the global data storing profiles and localization.
5054  *  \param [in] mesh - the supporting mesh.
5055  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5056  *          caller is to delete this field using decrRef() as it is no more needed. 
5057  *  \throw If the MED file is not readable.
5058  *  \throw If no field of \a this is lying on \a mesh.
5059  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5060  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5061  */
5062 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5063 {
5064   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
5065   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
5066   if(meshDimRelToMax==1)
5067     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
5068   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
5069 }
5070
5071 /*!
5072  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
5073  * given mesh. 
5074  *  \param [in] type - a spatial discretization of the new field.
5075  *  \param [in] mName - a name of the supporting mesh.
5076  *  \param [in] renumPol - specifies how to permute values of the result field according to
5077  *          the optional numbers of cells and nodes, if any. The valid values are
5078  *          - 0 - do not permute.
5079  *          - 1 - permute cells.
5080  *          - 2 - permute nodes.
5081  *          - 3 - permute cells and nodes.
5082  *
5083  *  \param [in] glob - the global data storing profiles and localization.
5084  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5085  *          caller is to delete this field using decrRef() as it is no more needed. 
5086  *  \throw If the MED file is not readable.
5087  *  \throw If there is no mesh named \a mName in the MED file.
5088  *  \throw If there are no mesh entities in the mesh.
5089  *  \throw If no field values of the given \a type are available.
5090  */
5091 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5092 {
5093   MCAuto<MEDFileMesh> mm;
5094   if(mName.empty())
5095     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5096   else
5097     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5098   int absDim=getDimension();
5099   int meshDimRelToMax=absDim-mm->getMeshDimension();
5100   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5101 }
5102
5103 /*!
5104  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5105  *  \param [in] type - a spatial discretization of the new field.
5106  *  \param [in] renumPol - specifies how to permute values of the result field according to
5107  *          the optional numbers of cells and nodes, if any. The valid values are
5108  *          - 0 - do not permute.
5109  *          - 1 - permute cells.
5110  *          - 2 - permute nodes.
5111  *          - 3 - permute cells and nodes.
5112  *
5113  *  \param [in] glob - the global data storing profiles and localization.
5114  *  \param [in] mesh - the supporting mesh.
5115  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5116  *         field according to \a renumPol.
5117  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5118  *         field according to \a renumPol.
5119  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5120  *          caller is to delete this field using decrRef() as it is no more needed. 
5121  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5122  *  \throw If no field of \a this is lying on \a mesh.
5123  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5124  */
5125 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5126 {
5127   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5128   int meshId=getMeshIdFromMeshName(mesh->getName());
5129   bool isPfl=false;
5130   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5131   switch(renumPol)
5132   {
5133     case 0:
5134       {
5135         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5136         return ret.retn();
5137       }
5138     case 3:
5139     case 1:
5140       {
5141         if(isPfl)
5142           throw INTERP_KERNEL::Exception(msg1);
5143         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5144         if(cellRenum)
5145           {
5146             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5147               {
5148                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5149                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5150                 throw INTERP_KERNEL::Exception(oss.str());
5151               }
5152             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5153             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5154             std::vector<DataArray *> arrOut2(1,arrOut);
5155             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5156             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5157             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5158           }
5159         if(renumPol==1)
5160           return ret.retn();
5161       }
5162     case 2:
5163       {
5164         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5165         if(isPfl)
5166           throw INTERP_KERNEL::Exception(msg1);
5167         if(nodeRenum)
5168           {
5169             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5170               {
5171                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5172                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5173                 throw INTERP_KERNEL::Exception(oss.str());
5174               }
5175             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5176             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5177               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5178             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5179           }
5180         return ret.retn();
5181       }
5182     default:
5183       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5184   }
5185 }
5186
5187 /*!
5188  * Returns values and a profile of the field of a given type lying on a given support.
5189  *  \param [in] type - a spatial discretization of the field.
5190  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5191  *  \param [in] mesh - the supporting mesh.
5192  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5193  *          field of interest lies on. If the field lies on all entities of the given
5194  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5195  *          using decrRef() as it is no more needed.  
5196  *  \param [in] glob - the global data storing profiles and localization.
5197  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5198  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5199  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5200  *  \throw If no field of \a this is lying on \a mesh.
5201  *  \throw If no field values of the given \a type are available.
5202  */
5203 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5204 {
5205   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5206   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
5207   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5208   ret->setName(nasc.getName().c_str());
5209   return ret.retn();
5210 }
5211
5212 //= MEDFileField1TSWithoutSDA
5213
5214 /*!
5215  * Throws if a given value is not a valid (non-extended) relative dimension.
5216  *  \param [in] meshDimRelToMax - the relative dimension value.
5217  *  \throw If \a meshDimRelToMax > 0.
5218  */
5219 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5220 {
5221   if(meshDimRelToMax>0)
5222     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5223 }
5224
5225 /*!
5226  * Checks if elements of a given mesh are in the order suitable for writing 
5227  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5228  * vector describing types of elements and their number.
5229  *  \param [in] mesh - the mesh to check.
5230  *  \return std::vector<int> - a vector holding for each element type (1) item of
5231  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5232  *          These values are in full-interlace mode.
5233  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5234  */
5235 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5236 {
5237   if(!mesh)
5238     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5239   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5240   int nbOfTypes=geoTypes.size();
5241   std::vector<int> code(3*nbOfTypes);
5242   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5243   arr1->alloc(nbOfTypes,1);
5244   int *arrPtr=arr1->getPointer();
5245   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5246   for(int i=0;i<nbOfTypes;i++,it++)
5247     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5248   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5249   const int *arrPtr2=arr2->getConstPointer();
5250   int i=0;
5251   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5252     {
5253       int pos=arrPtr2[i];
5254       int nbCells=mesh->getNumberOfCellsWithType(*it);
5255       code[3*pos]=(int)(*it);
5256       code[3*pos+1]=nbCells;
5257       code[3*pos+2]=-1;//no profiles
5258     }
5259   std::vector<const DataArrayInt *> idsPerType;//no profiles
5260   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5261   if(da)
5262     {
5263       da->decrRef();
5264       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5265     }
5266   return code;
5267 }
5268
5269 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5270 {
5271   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5272 }
5273
5274 /*!
5275  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5276  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5277  * item of every of returned sequences refers to the _i_-th part of \a this field.
5278  * Thus all sequences returned by this method are of the same length equal to number
5279  * of different types of supporting entities.<br>
5280  * A field part can include sub-parts with several different spatial discretizations,
5281  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5282  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5283  * of a nested sequence corresponds to a type of spatial discretization.<br>
5284  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5285  * The overhead is due to selecting values into new instances of DataArrayDouble.
5286  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5287  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5288  *          not checked if \a mname == \c NULL).
5289  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5290  *          a field part is returned. 
5291  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5292  *          A field part can include sub-parts with several different spatial discretizations,
5293  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5294  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5295  *          This sequence is of the same length as \a types. 
5296  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5297  *          discretization. A profile name can be empty.
5298  *          Length of this and of nested sequences is the same as that of \a typesF.
5299  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5300  *          discretization. A localization name can be empty.
5301  *          Length of this and of nested sequences is the same as that of \a typesF.
5302  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5303  *          per each type of spatial discretization within one mesh entity type.
5304  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5305  *          Length of this and of nested sequences is the same as that of \a typesF.
5306  *  \throw If no field is lying on \a mname.
5307  */
5308 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
5309 {
5310   int meshId=0;
5311   if(!mname.empty())
5312     meshId=getMeshIdFromMeshName(mname);
5313   else
5314     if(_field_per_mesh.empty())
5315       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5316   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5317   int nbOfRet=ret0.size();
5318   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5319   for(int i=0;i<nbOfRet;i++)
5320     {
5321       const std::vector< std::pair<int,int> >& p=ret0[i];
5322       int nbOfRet1=p.size();
5323       ret[i].resize(nbOfRet1);
5324       for(int j=0;j<nbOfRet1;j++)
5325         {
5326           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5327           ret[i][j]=tmp;
5328         }
5329     }
5330   return ret;
5331 }
5332
5333 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5334 {
5335   return TYPE_STR;
5336 }
5337
5338 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5339 {
5340   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5341   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5342   ret->deepCpyLeavesFrom(*this);
5343   const DataArrayDouble *arr(_arr);
5344   if(arr)
5345     {
5346       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5347       ret->setArray(arr2);
5348     }
5349   return ret.retn();
5350 }
5351
5352 /*!
5353  * Returns a pointer to the underground DataArrayDouble instance and a
5354  * sequence describing parameters of a support of each part of \a this field. The
5355  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5356  * direct access to the field values. This method is intended for the field lying on one
5357  * mesh only.
5358  *  \param [in,out] entries - the sequence describing parameters of a support of each
5359  *         part of \a this field. Each item of this sequence consists of two parts. The
5360  *         first part describes a type of mesh entity and an id of discretization of a
5361  *         current field part. The second part describes a range of values [begin,end)
5362  *         within the returned array relating to the current field part.
5363  *  \return DataArrayDouble * - the pointer to the field values array.
5364  *  \throw If the number of underlying meshes is not equal to 1.
5365  *  \throw If no field values are available.
5366  *  \sa getUndergroundDataArray()
5367  */
5368 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5369 {
5370   if(_field_per_mesh.size()!=1)
5371     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5372   if(_field_per_mesh[0]==0)
5373     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5374   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5375   return getUndergroundDataArrayTemplate();
5376 }
5377
5378 /*!
5379  * Returns a pointer to the underground DataArrayDouble instance and a
5380  * sequence describing parameters of a support of each part of \a this field. The
5381  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5382  * direct access to the field values. This method is intended for the field lying on one
5383  * mesh only.
5384  *  \param [in,out] entries - the sequence describing parameters of a support of each
5385  *         part of \a this field. Each item of this sequence consists of two parts. The
5386  *         first part describes a type of mesh entity and an id of discretization of a
5387  *         current field part. The second part describes a range of values [begin,end)
5388  *         within the returned array relating to the current field part.
5389  *  \return DataArrayDouble * - the pointer to the field values array.
5390  *  \throw If the number of underlying meshes is not equal to 1.
5391  *  \throw If no field values are available.
5392  *  \sa getUndergroundDataArray()
5393  */
5394 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5395 {
5396   return getUndergroundDataArrayDoubleExt(entries);
5397 }
5398
5399 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,csit,iteration,order)
5400 {
5401   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5402   arr->setInfoAndChangeNbOfCompo(infos);
5403 }
5404
5405 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5406 {
5407 }
5408
5409 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5410 {
5411   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5412   ret->deepCpyLeavesFrom(*this);
5413   return ret.retn();
5414 }
5415
5416 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5417 {
5418   MCAuto<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5419   if((const DataArrayDouble *)_arr)
5420     ret->_arr=_arr->deepCopy();
5421   return ret.retn();
5422 }
5423
5424 //= MEDFileIntField1TSWithoutSDA
5425
5426 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5427 {
5428   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5429 }
5430
5431 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<int>()
5432 {
5433 }
5434
5435 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5436                                                            const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,csit,iteration,order)
5437 {
5438   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5439   arr->setInfoAndChangeNbOfCompo(infos);
5440 }
5441
5442 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5443 {
5444   return TYPE_STR;
5445 }
5446
5447 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5448 {
5449   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5450   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5451   ret->deepCpyLeavesFrom(*this);
5452   const DataArrayInt *arr(_arr);
5453   if(arr)
5454     {
5455       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5456       ret->setArray(arr2);
5457     }
5458   return ret.retn();
5459 }
5460
5461 /*!
5462  * Returns a pointer to the underground DataArrayInt instance and a
5463  * sequence describing parameters of a support of each part of \a this field. The
5464  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5465  * direct access to the field values. This method is intended for the field lying on one
5466  * mesh only.
5467  *  \param [in,out] entries - the sequence describing parameters of a support of each
5468  *         part of \a this field. Each item of this sequence consists of two parts. The
5469  *         first part describes a type of mesh entity and an id of discretization of a
5470  *         current field part. The second part describes a range of values [begin,end)
5471  *         within the returned array relating to the current field part.
5472  *  \return DataArrayInt * - the pointer to the field values array.
5473  *  \throw If the number of underlying meshes is not equal to 1.
5474  *  \throw If no field values are available.
5475  *  \sa getUndergroundDataArray()
5476  */
5477 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5478 {
5479   return getUndergroundDataArrayIntExt(entries);
5480 }
5481
5482 /*!
5483  * Returns a pointer to the underground DataArrayInt instance and a
5484  * sequence describing parameters of a support of each part of \a this field. The
5485  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5486  * direct access to the field values. This method is intended for the field lying on one
5487  * mesh only.
5488  *  \param [in,out] entries - the sequence describing parameters of a support of each
5489  *         part of \a this field. Each item of this sequence consists of two parts. The
5490  *         first part describes a type of mesh entity and an id of discretization of a
5491  *         current field part. The second part describes a range of values [begin,end)
5492  *         within the returned array relating to the current field part.
5493  *  \return DataArrayInt * - the pointer to the field values array.
5494  *  \throw If the number of underlying meshes is not equal to 1.
5495  *  \throw If no field values are available.
5496  *  \sa getUndergroundDataArray()
5497  */
5498 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5499 {
5500   if(_field_per_mesh.size()!=1)
5501     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5502   if(_field_per_mesh[0]==0)
5503     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5504   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5505   return getUndergroundDataArrayTemplate();
5506 }
5507
5508 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5509 {
5510   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5511   ret->deepCpyLeavesFrom(*this);
5512   return ret.retn();
5513 }
5514
5515 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5516 {
5517   MCAuto<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5518   if((const DataArrayInt *)_arr)
5519     ret->_arr=_arr->deepCopy();
5520   return ret.retn();
5521 }
5522
5523 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5524 {
5525 }
5526
5527 //= MEDFileAnyTypeField1TS
5528
5529 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5530 {
5531   med_field_type typcha;
5532   //
5533   std::vector<std::string> infos;
5534   std::string dtunit,fieldName;
5535   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
5536   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5537   switch(typcha)
5538   {
5539     case MED_FLOAT64:
5540       {
5541         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5542         break;
5543       }
5544     case MED_INT32:
5545       {
5546         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5547         break;
5548       }
5549     default:
5550       {
5551         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
5552         throw INTERP_KERNEL::Exception(oss.str());
5553       }
5554   }
5555   ret->setDtUnit(dtunit.c_str());
5556   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5557   //
5558   med_int numdt,numit;
5559   med_float dt;
5560   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5561   ret->setTime(numdt,numit,dt);
5562   ret->_csit=1;
5563   if(loadAll)
5564     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5565   else
5566     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5567   return ret.retn();
5568 }
5569
5570 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5571 try:MEDFileFieldGlobsReal(fid)
5572 {
5573   _content=BuildContentFrom(fid,loadAll,ms);
5574   loadGlobals(fid);
5575 }
5576 catch(INTERP_KERNEL::Exception& e)
5577 {
5578     throw e;
5579 }
5580
5581 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5582 {
5583   med_field_type typcha;
5584   std::vector<std::string> infos;
5585   std::string dtunit;
5586   int iii=-1;
5587   int nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit);
5588   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5589   switch(typcha)
5590   {
5591     case MED_FLOAT64:
5592       {
5593         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5594         break;
5595       }
5596     case MED_INT32:
5597       {
5598         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5599         break;
5600       }
5601     default:
5602       {
5603         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5604         throw INTERP_KERNEL::Exception(oss.str());
5605       }
5606   }
5607   ret->setDtUnit(dtunit.c_str());
5608   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5609   //
5610   if(nbSteps<1)
5611     {
5612       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5613       throw INTERP_KERNEL::Exception(oss.str());
5614     }
5615   //
5616   med_int numdt,numit;
5617   med_float dt;
5618   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5619   ret->setTime(numdt,numit,dt);
5620   ret->_csit=1;
5621   if(loadAll)
5622     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5623   else
5624     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5625   return ret.retn();
5626 }
5627
5628 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5629 try:MEDFileFieldGlobsReal(fid)
5630 {
5631   _content=BuildContentFrom(fid,fieldName,loadAll,ms);
5632   loadGlobals(fid);
5633 }
5634 catch(INTERP_KERNEL::Exception& e)
5635 {
5636     throw e;
5637 }
5638
5639 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
5640 {
5641   if(!c)
5642     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5643   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5644     {
5645       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
5646       ret->_content=c; c->incrRef();
5647       return ret.retn();
5648     }
5649   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5650     {
5651       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
5652       ret->_content=c; c->incrRef();
5653       return ret.retn();
5654     }
5655   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5656 }
5657
5658 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
5659 {
5660   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
5661   ret->setFileName(FileNameFromFID(fid));
5662   return ret;
5663 }
5664
5665 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5666 {
5667   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5668   return New(fid,loadAll);
5669 }
5670
5671 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
5672 {
5673   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
5674   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5675   ret->loadGlobals(fid);
5676   return ret.retn();
5677 }
5678
5679 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5680 {
5681   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5682   return New(fid,fieldName,loadAll);
5683 }
5684
5685 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
5686 {
5687   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0));
5688   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5689   ret->loadGlobals(fid);
5690   return ret.retn();
5691 }
5692
5693 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5694 {
5695   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5696   return New(fid,fieldName,iteration,order,loadAll);
5697 }
5698
5699 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
5700 {
5701   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0));
5702   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5703   ret->loadGlobals(fid);
5704   return ret.retn();
5705 }
5706
5707 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5708 {
5709   med_field_type typcha;
5710   std::vector<std::string> infos;
5711   std::string dtunit;
5712   int iii(-1);
5713   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit));
5714   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5715   switch(typcha)
5716   {
5717     case MED_FLOAT64:
5718       {
5719         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5720         break;
5721       }
5722     case MED_INT32:
5723       {
5724         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5725         break;
5726       }
5727     default:
5728       {
5729         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName,iteration,order) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5730         throw INTERP_KERNEL::Exception(oss.str());
5731       }
5732   }
5733   ret->setDtUnit(dtunit.c_str());
5734   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5735   //
5736   bool found=false;
5737   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5738   for(int i=0;i<nbOfStep2 && !found;i++)
5739     {
5740       med_int numdt,numit;
5741       med_float dt;
5742       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5743       if(numdt==iteration && numit==order)
5744         {
5745           found=true;
5746           ret->_csit=i+1;
5747         }
5748       else
5749         dtits[i]=std::pair<int,int>(numdt,numit);
5750     }
5751   if(!found)
5752     {
5753       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
5754       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5755         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5756       throw INTERP_KERNEL::Exception(oss.str());
5757     }
5758   if(loadAll)
5759     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5760   else
5761     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5762   return ret.retn();
5763 }
5764
5765 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5766 try:MEDFileFieldGlobsReal(fid)
5767 {
5768   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms);
5769   loadGlobals(fid);
5770 }
5771 catch(INTERP_KERNEL::Exception& e)
5772 {
5773     throw e;
5774 }
5775
5776 /*!
5777  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5778  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5779  *
5780  * \warning this is a shallow copy constructor
5781  */
5782 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5783 {
5784   if(!shallowCopyOfContent)
5785     {
5786       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5787       otherPtr->incrRef();
5788       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5789     }
5790   else
5791     {
5792       _content=other.shallowCpy();
5793     }
5794 }
5795
5796 int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5797 {
5798   if(checkFieldId)
5799     {
5800       int nbFields=MEDnField(fid);
5801       if(fieldIdCFormat>=nbFields)
5802         {
5803           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5804           throw INTERP_KERNEL::Exception(oss.str());
5805         }
5806     }
5807   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5808   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5809   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5810   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5811   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5812   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5813   med_bool localMesh;
5814   int nbOfStep;
5815   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5816   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5817   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5818   infos.clear(); infos.resize(ncomp);
5819   for(int j=0;j<ncomp;j++)
5820     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5821   return nbOfStep;
5822 }
5823
5824 /*!
5825  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5826  * 
5827  * \param [out]
5828  * \return in case of success the number of time steps available for the field with name \a fieldName.
5829  */
5830 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5831 {
5832   int nbFields=MEDnField(fid);
5833   bool found=false;
5834   std::vector<std::string> fns(nbFields);
5835   int nbOfStep2(-1);
5836   for(int i=0;i<nbFields && !found;i++)
5837     {
5838       std::string tmp;
5839       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut);
5840       fns[i]=tmp;
5841       found=(tmp==fieldName);
5842       if(found)
5843         posCFormat=i;
5844     }
5845   if(!found)
5846     {
5847       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
5848       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5849         oss << "\"" << *it << "\" ";
5850       throw INTERP_KERNEL::Exception(oss.str());
5851     }
5852   return nbOfStep2;
5853 }
5854
5855 /*!
5856  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5857  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5858  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5859  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5860  * to keep a valid instance.
5861  * 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.
5862  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5863  * 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.
5864  *
5865  * \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.
5866  * \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.
5867  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5868  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5869  * \param [in] newLocName is the new localization name.
5870  * \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.
5871  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5872  */
5873 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5874 {
5875   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5876   std::string oldPflName=disc->getProfile();
5877   std::vector<std::string> vv=getPflsReallyUsedMulti();
5878   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5879   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5880     {
5881       disc->setProfile(newPflName);
5882       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5883       pfl->setName(newPflName);
5884     }
5885   else
5886     {
5887       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5888       throw INTERP_KERNEL::Exception(oss.str());
5889     }
5890 }
5891
5892 /*!
5893  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5894  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5895  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5896  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5897  * to keep a valid instance.
5898  * 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.
5899  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5900  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5901  * 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.
5902  *
5903  * \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.
5904  * \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.
5905  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5906  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5907  * \param [in] newLocName is the new localization name.
5908  * \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.
5909  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5910  */
5911 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5912 {
5913   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5914   std::string oldLocName=disc->getLocalization();
5915   std::vector<std::string> vv=getLocsReallyUsedMulti();
5916   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5917   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5918     {
5919       disc->setLocalization(newLocName);
5920       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5921       loc.setName(newLocName);
5922     }
5923   else
5924     {
5925       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5926       throw INTERP_KERNEL::Exception(oss.str());
5927     }
5928 }
5929
5930 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5931 {
5932   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5933   if(!ret)
5934     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5935   return ret;
5936 }
5937
5938 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5939 {
5940   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5941   if(!ret)
5942     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5943   return ret;
5944 }
5945
5946 /*!
5947  * This method alloc the arrays and load potentially huge arrays contained in this field.
5948  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5949  * This method can be also called to refresh or reinit values from a file.
5950  * 
5951  * \throw If the fileName is not set or points to a non readable MED file.
5952  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5953  */
5954 void MEDFileAnyTypeField1TS::loadArrays()
5955 {
5956   if(getFileName().empty())
5957     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5958   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
5959   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5960 }
5961
5962 /*!
5963  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5964  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5965  * this method does not throw if \a this does not come from file read.
5966  * 
5967  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5968  */
5969 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5970 {
5971   if(!getFileName().empty())
5972     {
5973       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
5974       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5975     }
5976 }
5977
5978 /*!
5979  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5980  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5981  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5982  * 
5983  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5984  */
5985 void MEDFileAnyTypeField1TS::unloadArrays()
5986 {
5987   contentNotNullBase()->unloadArrays();
5988 }
5989
5990 /*!
5991  * 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.
5992  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5993  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5994  * 
5995  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5996  */
5997 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5998 {
5999   if(!getFileName().empty())
6000     contentNotNullBase()->unloadArrays();
6001 }
6002
6003 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
6004 {
6005   int nbComp(getNumberOfComponents());
6006   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6007   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6008   for(int i=0;i<nbComp;i++)
6009     {
6010       std::string info=getInfo()[i];
6011       std::string c,u;
6012       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6013       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
6014       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
6015     }
6016   if(getName().empty())
6017     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
6018   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
6019   writeGlobals(fid,*this);
6020   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
6021 }
6022
6023 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
6024 {
6025   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
6026 }
6027
6028 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
6029 {
6030   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
6031   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
6032   return ret;
6033 }
6034
6035 /*!
6036  * Returns a string describing \a this field. This string is outputted 
6037  * by \c print Python command.
6038  */
6039 std::string MEDFileAnyTypeField1TS::simpleRepr() const
6040 {
6041   std::ostringstream oss;
6042   contentNotNullBase()->simpleRepr(0,oss,-1);
6043   simpleReprGlobs(oss);
6044   return oss.str();
6045 }
6046
6047 /*!
6048  * This method returns all profiles whose name is non empty used.
6049  * \b WARNING If profile is used several times it will be reported \b only \b once.
6050  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
6051  */
6052 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
6053 {
6054   return contentNotNullBase()->getPflsReallyUsed2();
6055 }
6056
6057 /*!
6058  * This method returns all localizations whose name is non empty used.
6059  * \b WARNING If localization is used several times it will be reported \b only \b once.
6060  */
6061 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
6062 {
6063   return contentNotNullBase()->getLocsReallyUsed2();
6064 }
6065
6066 /*!
6067  * This method returns all profiles whose name is non empty used.
6068  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
6069  */
6070 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
6071 {
6072   return contentNotNullBase()->getPflsReallyUsedMulti2();
6073 }
6074
6075 /*!
6076  * This method returns all localizations whose name is non empty used.
6077  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
6078  */
6079 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
6080 {
6081   return contentNotNullBase()->getLocsReallyUsedMulti2();
6082 }
6083
6084 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6085 {
6086   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
6087 }
6088
6089 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6090 {
6091   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
6092 }
6093
6094 int MEDFileAnyTypeField1TS::getDimension() const
6095 {
6096   return contentNotNullBase()->getDimension();
6097 }
6098
6099 int MEDFileAnyTypeField1TS::getIteration() const
6100 {
6101   return contentNotNullBase()->getIteration();
6102 }
6103
6104 int MEDFileAnyTypeField1TS::getOrder() const
6105 {
6106   return contentNotNullBase()->getOrder();
6107 }
6108
6109 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6110 {
6111   return contentNotNullBase()->getTime(iteration,order);
6112 }
6113
6114 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6115 {
6116   contentNotNullBase()->setTime(iteration,order,val);
6117 }
6118
6119 std::string MEDFileAnyTypeField1TS::getName() const
6120 {
6121   return contentNotNullBase()->getName();
6122 }
6123
6124 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6125 {
6126   contentNotNullBase()->setName(name);
6127 }
6128
6129 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6130 {
6131   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6132 }
6133
6134 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6135 {
6136   return contentNotNullBase()->getDtUnit();
6137 }
6138
6139 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6140 {
6141   contentNotNullBase()->setDtUnit(dtUnit);
6142 }
6143
6144 std::string MEDFileAnyTypeField1TS::getMeshName() const
6145 {
6146   return contentNotNullBase()->getMeshName();
6147 }
6148
6149 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6150 {
6151   contentNotNullBase()->setMeshName(newMeshName);
6152 }
6153
6154 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6155 {
6156   return contentNotNullBase()->changeMeshNames(modifTab);
6157 }
6158
6159 int MEDFileAnyTypeField1TS::getMeshIteration() const
6160 {
6161   return contentNotNullBase()->getMeshIteration();
6162 }
6163
6164 int MEDFileAnyTypeField1TS::getMeshOrder() const
6165 {
6166   return contentNotNullBase()->getMeshOrder();
6167 }
6168
6169 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6170 {
6171   return contentNotNullBase()->getNumberOfComponents();
6172 }
6173
6174 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6175 {
6176   return contentNotNullBase()->isDealingTS(iteration,order);
6177 }
6178
6179 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6180 {
6181   return contentNotNullBase()->getDtIt();
6182 }
6183
6184 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6185 {
6186   contentNotNullBase()->fillIteration(p);
6187 }
6188
6189 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6190 {
6191   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6192 }
6193
6194 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6195 {
6196   contentNotNullBase()->setInfo(infos);
6197 }
6198
6199 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6200 {
6201   return contentNotNullBase()->getInfo();
6202 }
6203 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6204 {
6205   return contentNotNullBase()->getInfo();
6206 }
6207
6208 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6209 {
6210   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6211 }
6212
6213 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6214 {
6215   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6216 }
6217
6218 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6219 {
6220   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6221 }
6222
6223 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6224 {
6225   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6226 }
6227
6228 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6229 {
6230   return contentNotNullBase()->getTypesOfFieldAvailable();
6231 }
6232
6233 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,
6234                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6235 {
6236   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6237 }
6238
6239 /*!
6240  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6241  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6242  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6243  */
6244 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6245 {
6246   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6247   if(!content)
6248     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6249   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6250   std::size_t sz(contentsSplit.size());
6251   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6252   for(std::size_t i=0;i<sz;i++)
6253     {
6254       ret[i]=shallowCpy();
6255       ret[i]->_content=contentsSplit[i];
6256     }
6257   return ret;
6258 }
6259
6260 /*!
6261  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6262  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6263  */
6264 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6265 {
6266   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6267   if(!content)
6268     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6269   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6270   std::size_t sz(contentsSplit.size());
6271   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6272   for(std::size_t i=0;i<sz;i++)
6273     {
6274       ret[i]=shallowCpy();
6275       ret[i]->_content=contentsSplit[i];
6276     }
6277   return ret;
6278 }
6279
6280 /*!
6281  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6282  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6283  */
6284 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6285 {
6286   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6287   if(!content)
6288     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6289   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6290   std::size_t sz(contentsSplit.size());
6291   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6292   for(std::size_t i=0;i<sz;i++)
6293     {
6294       ret[i]=shallowCpy();
6295       ret[i]->_content=contentsSplit[i];
6296     }
6297   return ret;
6298 }
6299
6300 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6301 {
6302   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6303   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6304     ret->_content=_content->deepCopy();
6305   ret->deepCpyGlobs(*this);
6306   return ret.retn();
6307 }
6308
6309 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6310 {
6311   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6312 }
6313
6314 //= MEDFileField1TS
6315
6316 /*!
6317  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6318  * the first field that has been read from a specified MED file.
6319  *  \param [in] fileName - the name of the MED file to read.
6320  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6321  *          is to delete this field using decrRef() as it is no more needed.
6322  *  \throw If reading the file fails.
6323  */
6324 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6325 {
6326   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6327   return New(fid,loadAll);
6328 }
6329
6330 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, bool loadAll)
6331 {
6332   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,loadAll,0));
6333   ret->contentNotNull();
6334   return ret.retn();
6335 }
6336
6337 /*!
6338  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6339  * a given field that has been read from a specified MED file.
6340  *  \param [in] fileName - the name of the MED file to read.
6341  *  \param [in] fieldName - the name of the field to read.
6342  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6343  *          is to delete this field using decrRef() as it is no more needed.
6344  *  \throw If reading the file fails.
6345  *  \throw If there is no field named \a fieldName in the file.
6346  */
6347 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6348 {
6349   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6350   return New(fid,fieldName,loadAll);
6351 }
6352
6353 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6354 {
6355   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,loadAll,0));
6356   ret->contentNotNull();
6357   return ret.retn();
6358 }
6359
6360 /*!
6361  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6362  * a given field that has been read from a specified MED file.
6363  *  \param [in] fileName - the name of the MED file to read.
6364  *  \param [in] fieldName - the name of the field to read.
6365  *  \param [in] iteration - the iteration number of a required time step.
6366  *  \param [in] order - the iteration order number of required time step.
6367  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6368  *          is to delete this field using decrRef() as it is no more needed.
6369  *  \throw If reading the file fails.
6370  *  \throw If there is no field named \a fieldName in the file.
6371  *  \throw If the required time step is missing from the file.
6372  */
6373 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6374 {
6375   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6376   return New(fid,fieldName,iteration,order,loadAll);
6377 }
6378
6379 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6380 {
6381   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,iteration,order,loadAll,0));
6382   ret->contentNotNull();
6383   return ret.retn();
6384 }
6385
6386 /*!
6387  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6388  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6389  *
6390  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6391  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6392  * \warning this is a shallow copy constructor
6393  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6394  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6395  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6396  *          is to delete this field using decrRef() as it is no more needed.
6397  */
6398 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6399 {
6400   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(other,shallowCopyOfContent));
6401   ret->contentNotNull();
6402   return ret.retn();
6403 }
6404
6405 /*!
6406  * Returns a new empty instance of MEDFileField1TS.
6407  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6408  *          is to delete this field using decrRef() as it is no more needed.
6409  */
6410 MEDFileField1TS *MEDFileField1TS::New()
6411 {
6412   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS);
6413   ret->contentNotNull();
6414   return ret.retn();
6415 }
6416
6417 /*!
6418  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6419  * following the given input policy.
6420  *
6421  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6422  *                            By default (true) the globals are deeply copied.
6423  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6424  */
6425 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6426 {
6427   MCAuto<MEDFileIntField1TS> ret;
6428   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6429   if(content)
6430     {
6431       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6432       if(!contc)
6433         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6434       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6435       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6436     }
6437   else
6438     ret=MEDFileIntField1TS::New();
6439   if(isDeepCpyGlobs)
6440     ret->deepCpyGlobs(*this);
6441   else
6442     ret->shallowCpyGlobs(*this);
6443   return ret.retn();
6444 }
6445
6446 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6447 {
6448   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6449   if(!pt)
6450     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6451   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6452   if(!ret)
6453     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 !");
6454   return ret;
6455 }
6456
6457 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6458 {
6459   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6460   if(!pt)
6461     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6462   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6463   if(!ret)
6464     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 !");
6465   return ret;
6466 }
6467
6468 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6469 {
6470   if(!f)
6471     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6472   if(arr.isNull())
6473     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6474   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6475   if(!arrOutC)
6476     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6477   f->setArray(arrOutC);
6478 }
6479
6480 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6481 {
6482   if(arr.isNull())
6483     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6484   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6485   if(!arrOutC)
6486     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6487   arrOutC->incrRef();
6488   return arrOutC;
6489 }
6490
6491 /*!
6492  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6493  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6494  *
6495  * \return A new object that the caller is responsible to deallocate.
6496  * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
6497  */
6498 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6499 {
6500   if(!mm)
6501     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6502   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6503   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6504   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6505     {
6506       if((*it0)!=ON_NODES)
6507         {
6508           std::vector<int> levs;
6509           getNonEmptyLevels(mm->getName(),levs);
6510           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6511             {
6512               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6513               if(it2!=extractDef.end())
6514                 {
6515                   MCAuto<DataArrayInt> t((*it2).second);
6516                   if(t.isNull())
6517                     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6518                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6519                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6520                   ret->setFieldNoProfileSBT(fOut);
6521                 }
6522             }
6523         }
6524       else
6525         {
6526           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6527           if(it2==extractDef.end())
6528             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6529           MCAuto<DataArrayInt> t((*it2).second);
6530           if(t.isNull())
6531             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6532           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6533           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6534           DataArrayDouble *arr(f->getArray());
6535           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6536           fOut->setArray(newArr);
6537           ret->setFieldNoProfileSBT(fOut);
6538         }
6539     }
6540   return ret.retn();
6541 }
6542
6543 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6544 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6545 {
6546 }
6547 catch(INTERP_KERNEL::Exception& e)
6548 { throw e; }
6549
6550 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6551 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6552 {
6553 }
6554 catch(INTERP_KERNEL::Exception& e)
6555 { throw e; }
6556
6557 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6558 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6559 {
6560 }
6561 catch(INTERP_KERNEL::Exception& e)
6562 { throw e; }
6563
6564 /*!
6565  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6566  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6567  *
6568  * \warning this is a shallow copy constructor
6569  */
6570 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6571 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6572 {
6573 }
6574 catch(INTERP_KERNEL::Exception& e)
6575 { throw e; }
6576
6577 MEDFileField1TS::MEDFileField1TS()
6578 {
6579   _content=new MEDFileField1TSWithoutSDA;
6580 }
6581
6582 /*!
6583  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
6584  * method should be called (getFieldOnMeshAtLevel for example).
6585  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6586  *
6587  * \param [in] mesh - the mesh the field is lying on
6588  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6589  *          caller is to delete this field using decrRef() as it is no more needed. 
6590  */
6591 MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
6592 {
6593   MCAuto<DataArray> arrOut;
6594   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6595   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6596   return ret.retn();
6597 }
6598
6599 /*!
6600  * Returns a new MEDCouplingFieldDouble of a given type lying on
6601  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6602  * has not been constructed via file reading, an exception is thrown.
6603  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6604  *  \param [in] type - a spatial discretization of interest.
6605  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6606  *  \param [in] renumPol - specifies how to permute values of the result field according to
6607  *          the optional numbers of cells and nodes, if any. The valid values are
6608  *          - 0 - do not permute.
6609  *          - 1 - permute cells.
6610  *          - 2 - permute nodes.
6611  *          - 3 - permute cells and nodes.
6612  *
6613  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6614  *          caller is to delete this field using decrRef() as it is no more needed. 
6615  *  \throw If \a this field has not been constructed via file reading.
6616  *  \throw If the MED file is not readable.
6617  *  \throw If there is no mesh in the MED file.
6618  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6619  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6620  *  \sa getFieldOnMeshAtLevel()
6621  */
6622 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6623 {
6624   if(getFileName().empty())
6625     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6626   MCAuto<DataArray> arrOut;
6627   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
6628   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6629   return ret.retn();
6630 }
6631
6632 /*!
6633  * Returns a new MEDCouplingFieldDouble of a given type lying on
6634  * the top level cells of the first mesh in MED file. If \a this field 
6635  * has not been constructed via file reading, an exception is thrown.
6636  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6637  *  \param [in] type - a spatial discretization of interest.
6638  *  \param [in] renumPol - specifies how to permute values of the result field according to
6639  *          the optional numbers of cells and nodes, if any. The valid values are
6640  *          - 0 - do not permute.
6641  *          - 1 - permute cells.
6642  *          - 2 - permute nodes.
6643  *          - 3 - permute cells and nodes.
6644  *
6645  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6646  *          caller is to delete this field using decrRef() as it is no more needed. 
6647  *  \throw If \a this field has not been constructed via file reading.
6648  *  \throw If the MED file is not readable.
6649  *  \throw If there is no mesh in the MED file.
6650  *  \throw If no field values of the given \a type.
6651  *  \throw If no field values lying on the top level support.
6652  *  \sa getFieldAtLevel()
6653  */
6654 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6655 {
6656   if(getFileName().empty())
6657     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6658   MCAuto<DataArray> arrOut;
6659   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
6660   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6661   return ret.retn();
6662 }
6663
6664 /*!
6665  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6666  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6667  *  \param [in] type - a spatial discretization of the new field.
6668  *  \param [in] mesh - the supporting mesh.
6669  *  \param [in] renumPol - specifies how to permute values of the result field according to
6670  *          the optional numbers of cells and nodes, if any. The valid values are
6671  *          - 0 - do not permute.
6672  *          - 1 - permute cells.
6673  *          - 2 - permute nodes.
6674  *          - 3 - permute cells and nodes.
6675  *
6676  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6677  *          caller is to delete this field using decrRef() as it is no more needed. 
6678  *  \throw If no field of \a this is lying on \a mesh.
6679  *  \throw If the mesh is empty.
6680  *  \throw If no field values of the given \a type are available.
6681  *  \sa getFieldAtLevel()
6682  *  \sa getFieldOnMeshAtLevel() 
6683  */
6684 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6685 {
6686   MCAuto<DataArray> arrOut;
6687   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
6688   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6689   return ret.retn();
6690 }
6691
6692 /*!
6693  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6694  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6695  *  \param [in] type - a spatial discretization of interest.
6696  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6697  *  \param [in] mesh - the supporting mesh.
6698  *  \param [in] renumPol - specifies how to permute values of the result field according to
6699  *          the optional numbers of cells and nodes, if any. The valid values are
6700  *          - 0 - do not permute.
6701  *          - 1 - permute cells.
6702  *          - 2 - permute nodes.
6703  *          - 3 - permute cells and nodes.
6704  *
6705  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6706  *          caller is to delete this field using decrRef() as it is no more needed. 
6707  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6708  *  \throw If no field of \a this is lying on \a mesh.
6709  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6710  *  \sa getFieldAtLevel()
6711  *  \sa getFieldOnMeshAtLevel() 
6712  */
6713 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6714 {
6715   MCAuto<DataArray> arrOut;
6716   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
6717   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6718   return ret.retn();
6719 }
6720
6721 /*!
6722  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6723  * This method is called "Old" because in MED3 norm a field has only one meshName
6724  * attached, so this method is for readers of MED2 files. If \a this field 
6725  * has not been constructed via file reading, an exception is thrown.
6726  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6727  *  \param [in] type - a spatial discretization of interest.
6728  *  \param [in] mName - a name of the supporting mesh.
6729  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6730  *  \param [in] renumPol - specifies how to permute values of the result field according to
6731  *          the optional numbers of cells and nodes, if any. The valid values are
6732  *          - 0 - do not permute.
6733  *          - 1 - permute cells.
6734  *          - 2 - permute nodes.
6735  *          - 3 - permute cells and nodes.
6736  *
6737  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6738  *          caller is to delete this field using decrRef() as it is no more needed. 
6739  *  \throw If the MED file is not readable.
6740  *  \throw If there is no mesh named \a mName in the MED file.
6741  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6742  *  \throw If \a this field has not been constructed via file reading.
6743  *  \throw If no field of \a this is lying on the mesh named \a mName.
6744  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6745  *  \sa getFieldAtLevel()
6746  */
6747 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6748 {
6749   if(getFileName().empty())
6750     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6751   MCAuto<DataArray> arrOut;
6752   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
6753   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6754   return ret.retn();
6755 }
6756
6757 /*!
6758  * Returns values and a profile of the field of a given type lying on a given support.
6759  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6760  *  \param [in] type - a spatial discretization of the field.
6761  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6762  *  \param [in] mesh - the supporting mesh.
6763  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6764  *          field of interest lies on. If the field lies on all entities of the given
6765  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6766  *          using decrRef() as it is no more needed.  
6767  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6768  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6769  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6770  *  \throw If no field of \a this is lying on \a mesh.
6771  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6772  */
6773 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6774 {
6775   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6776   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6777 }
6778
6779 /*!
6780  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6781  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6782  * "Sort By Type"), if not, an exception is thrown. 
6783  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6784  *  \param [in] field - the field to add to \a this.
6785  *  \throw If the name of \a field is empty.
6786  *  \throw If the data array of \a field is not set.
6787  *  \throw If the data array is already allocated but has different number of components
6788  *         than \a field.
6789  *  \throw If the underlying mesh of \a field has no name.
6790  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6791  */
6792 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6793 {
6794   setFileName("");
6795   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6796 }
6797
6798 /*!
6799  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6800  * can be an aggregation of several MEDCouplingFieldDouble instances.
6801  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6802  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6803  * and \a profile.
6804  *
6805  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6806  * A new profile is added only if no equal profile is missing.
6807  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6808  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6809  *  \param [in] mesh - the supporting mesh of \a field.
6810  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6811  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6812  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6813  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6814  *  \throw If the data array of \a field is not set.
6815  *  \throw If the data array of \a this is already allocated but has different number of
6816  *         components than \a field.
6817  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6818  *  \sa setFieldNoProfileSBT()
6819  */
6820 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6821 {
6822   setFileName("");
6823   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6824 }
6825
6826 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6827 {
6828   return new MEDFileField1TS(*this);
6829 }
6830
6831 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6832 {
6833   return contentNotNull()->getUndergroundDataArrayTemplate();
6834 }
6835
6836 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6837 {
6838   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6839 }
6840
6841 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6842                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6843 {
6844   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6845 }
6846
6847 //= MEDFileIntField1TS
6848
6849 MEDFileIntField1TS *MEDFileIntField1TS::New()
6850 {
6851   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS);
6852   ret->contentNotNull();
6853   return ret.retn();
6854 }
6855
6856 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6857 {
6858   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6859   return MEDFileIntField1TS::New(fid,loadAll);
6860 }
6861
6862 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, bool loadAll)
6863 {
6864   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,loadAll,0));
6865   ret->contentNotNull();
6866   return ret.retn();
6867 }
6868
6869 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6870 {
6871   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6872   return MEDFileIntField1TS::New(fid,fieldName,loadAll);
6873 }
6874
6875 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6876 {
6877   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,loadAll,0));
6878   ret->contentNotNull();
6879   return ret.retn();
6880 }
6881
6882 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6883 {
6884   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6885   return MEDFileIntField1TS::New(fid,fieldName,iteration,order,loadAll);
6886 }
6887
6888 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6889 {
6890   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,iteration,order,loadAll,0));
6891   ret->contentNotNull();
6892   return ret.retn();
6893 }
6894
6895 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6896 {
6897   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6898   ret->contentNotNull();
6899   return ret.retn();
6900 }
6901
6902 MEDFileIntField1TS::MEDFileIntField1TS()
6903 {
6904   _content=new MEDFileIntField1TSWithoutSDA;
6905 }
6906
6907 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6908 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6909 {
6910 }
6911 catch(INTERP_KERNEL::Exception& e)
6912 { throw e; }
6913
6914 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6915 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6916 {
6917 }
6918 catch(INTERP_KERNEL::Exception& e)
6919 { throw e; }
6920
6921 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6922 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6923 {
6924 }
6925 catch(INTERP_KERNEL::Exception& e)
6926 { throw e; }
6927
6928 /*!
6929  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6930  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6931  *
6932  * \warning this is a shallow copy constructor
6933  */
6934 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6935 {
6936 }
6937
6938 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6939 {
6940   return new MEDFileIntField1TS(*this);
6941 }
6942
6943 /*!
6944  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6945  * following the given input policy.
6946  *
6947  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6948  *                            By default (true) the globals are deeply copied.
6949  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6950  */
6951 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6952 {
6953   MCAuto<MEDFileField1TS> ret;
6954   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6955   if(content)
6956     {
6957       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6958       if(!contc)
6959         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6960       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6961       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
6962     }
6963   else
6964     ret=MEDFileField1TS::New();
6965   if(isDeepCpyGlobs)
6966     ret->deepCpyGlobs(*this);
6967   else
6968     ret->shallowCpyGlobs(*this);
6969   return ret.retn();
6970 }
6971
6972 /*!
6973  * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
6974  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6975  * "Sort By Type"), if not, an exception is thrown. 
6976  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6977  *  \param [in] field - the field to add to \a this.
6978  *  \throw If the name of \a field is empty.
6979  *  \throw If the data array of \a field is not set.
6980  *  \throw If the data array is already allocated but has different number of components
6981  *         than \a field.
6982  *  \throw If the underlying mesh of \a field has no name.
6983  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6984  */
6985 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
6986 {
6987   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
6988   setFileName("");
6989   contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
6990 }
6991
6992 /*!
6993  * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6994  * can be an aggregation of several MEDCouplingFieldDouble instances.
6995  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6996  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6997  * and \a profile.
6998  *
6999  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
7000  * A new profile is added only if no equal profile is missing.
7001  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7002  *  \param [in] field - the field to add to \a this.
7003  *  \param [in] mesh - the supporting mesh of \a field.
7004  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
7005  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
7006  *  \throw If either \a field or \a mesh or \a profile has an empty name.
7007  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7008  *  \throw If the data array of \a field is not set.
7009  *  \throw If the data array of \a this is already allocated but has different number of
7010  *         components than \a field.
7011  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7012  *  \sa setFieldNoProfileSBT()
7013  */
7014 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7015 {
7016   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7017   setFileName("");
7018   contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7019 }
7020
7021 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
7022 {
7023   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7024   if(!pt)
7025     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
7026   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
7027   if(!ret)
7028     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 !");
7029   return ret;
7030 }
7031
7032 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
7033 {
7034   if(getFileName().empty())
7035     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7036   MCAuto<DataArray> arrOut;
7037   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
7038   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7039   return ret2.retn();
7040 }
7041
7042 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
7043 {
7044   if(arr.isNull())
7045     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
7046   DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
7047   if(!arrC)
7048     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
7049   arrC->incrRef();
7050   return arrC;
7051 }
7052
7053 MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
7054 {
7055   int t1,t2;
7056   double t0(f->getTime(t1,t2));
7057   MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
7058   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7059   MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
7060   ret->setTime(t0,t1,t2); ret->setArray(arr2);
7061   return ret.retn();
7062 }
7063
7064 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
7065 {
7066   if(!f)
7067     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
7068   int t1,t2;
7069   double t0(f->getTime(t1,t2));
7070   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7071   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
7072   ret->setTime(t0,t1,t2);
7073   return ret;
7074 }
7075
7076 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
7077 {
7078   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
7079 }
7080
7081 /*!
7082  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
7083  * method should be called (getFieldOnMeshAtLevel for example).
7084  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
7085  *
7086  * \param [in] mesh - the mesh the field is lying on
7087  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
7088  *          caller is to delete this field using decrRef() as it is no more needed. 
7089  */
7090 MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
7091 {
7092   MCAuto<DataArray> arrOut;
7093   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
7094   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7095   return ret2.retn();
7096 }
7097
7098 /*!
7099  * Returns a new MEDCouplingFieldInt of a given type lying on
7100  * the top level cells of the first mesh in MED file. If \a this field 
7101  * has not been constructed via file reading, an exception is thrown.
7102  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7103  *  \param [in] type - a spatial discretization of interest.
7104  *  \param [in] renumPol - specifies how to permute values of the result field according to
7105  *          the optional numbers of cells and nodes, if any. The valid values are
7106  *          - 0 - do not permute.
7107  *          - 1 - permute cells.
7108  *          - 2 - permute nodes.
7109  *          - 3 - permute cells and nodes.
7110  *
7111  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7112  *          caller is to delete this field using decrRef() as it is no more needed. 
7113  *  \throw If \a this field has not been constructed via file reading.
7114  *  \throw If the MED file is not readable.
7115  *  \throw If there is no mesh in the MED file.
7116  *  \throw If no field values of the given \a type.
7117  *  \throw If no field values lying on the top level support.
7118  *  \sa getFieldAtLevel()
7119  */
7120 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7121 {
7122   if(getFileName().empty())
7123     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7124   MCAuto<DataArray> arrOut;
7125   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7126   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7127   return ret2.retn();
7128 }
7129
7130 /*!
7131  * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
7132  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7133  *  \param [in] type - a spatial discretization of the new field.
7134  *  \param [in] mesh - the supporting mesh.
7135  *  \param [in] renumPol - specifies how to permute values of the result field according to
7136  *          the optional numbers of cells and nodes, if any. The valid values are
7137  *          - 0 - do not permute.
7138  *          - 1 - permute cells.
7139  *          - 2 - permute nodes.
7140  *          - 3 - permute cells and nodes.
7141  *
7142  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7143  *          caller is to delete this field using decrRef() as it is no more needed. 
7144  *  \throw If no field of \a this is lying on \a mesh.
7145  *  \throw If the mesh is empty.
7146  *  \throw If no field values of the given \a type are available.
7147  *  \sa getFieldAtLevel()
7148  *  \sa getFieldOnMeshAtLevel() 
7149  */
7150 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7151 {
7152   MCAuto<DataArray> arrOut;
7153   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7154   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7155   return ret2.retn();
7156 }
7157
7158 /*!
7159  * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
7160  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7161  *  \param [in] type - a spatial discretization of interest.
7162  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7163  *  \param [in] mesh - the supporting mesh.
7164  *  \param [in] renumPol - specifies how to permute values of the result field according to
7165  *          the optional numbers of cells and nodes, if any. The valid values are
7166  *          - 0 - do not permute.
7167  *          - 1 - permute cells.
7168  *          - 2 - permute nodes.
7169  *          - 3 - permute cells and nodes.
7170  *
7171  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7172  *          caller is to delete this field using decrRef() as it is no more needed. 
7173  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7174  *  \throw If no field of \a this is lying on \a mesh.
7175  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7176  *  \sa getFieldAtLevel()
7177  *  \sa getFieldOnMeshAtLevel() 
7178  */
7179 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7180 {
7181   MCAuto<DataArray> arrOut;
7182   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7183   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7184   return ret2.retn();
7185 }
7186
7187 /*!
7188  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7189  * This method is called "Old" because in MED3 norm a field has only one meshName
7190  * attached, so this method is for readers of MED2 files. If \a this field 
7191  * has not been constructed via file reading, an exception is thrown.
7192  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7193  *  \param [in] type - a spatial discretization of interest.
7194  *  \param [in] mName - a name of the supporting mesh.
7195  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7196  *  \param [in] renumPol - specifies how to permute values of the result field according to
7197  *          the optional numbers of cells and nodes, if any. The valid values are
7198  *          - 0 - do not permute.
7199  *          - 1 - permute cells.
7200  *          - 2 - permute nodes.
7201  *          - 3 - permute cells and nodes.
7202  *
7203  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7204  *          caller is to delete this field using decrRef() as it is no more needed. 
7205  *  \throw If the MED file is not readable.
7206  *  \throw If there is no mesh named \a mName in the MED file.
7207  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7208  *  \throw If \a this field has not been constructed via file reading.
7209  *  \throw If no field of \a this is lying on the mesh named \a mName.
7210  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7211  *  \sa getFieldAtLevel()
7212  */
7213 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7214 {
7215   if(getFileName().empty())
7216     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7217   MCAuto<DataArray> arrOut;
7218   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
7219   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7220   return ret2.retn();
7221 }
7222
7223 /*!
7224  * Returns values and a profile of the field of a given type lying on a given support.
7225  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7226  *  \param [in] type - a spatial discretization of the field.
7227  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7228  *  \param [in] mesh - the supporting mesh.
7229  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7230  *          field of interest lies on. If the field lies on all entities of the given
7231  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7232  *          using decrRef() as it is no more needed.  
7233  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7234  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7235  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7236  *  \throw If no field of \a this is lying on \a mesh.
7237  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7238  */
7239 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7240 {
7241   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7242   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7243 }
7244
7245 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7246 {
7247   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7248   if(!pt)
7249     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7250   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7251   if(!ret)
7252     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 !");
7253   return ret;
7254 }
7255
7256 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7257 {
7258   return contentNotNull()->getUndergroundDataArrayTemplate();
7259 }
7260
7261 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7262
7263 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7264 {
7265 }
7266
7267 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7268 {
7269 }
7270
7271 /*!
7272  * \param [in] fieldId field id in C mode
7273  */
7274 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7275 {
7276   med_field_type typcha;
7277   std::string dtunitOut;
7278   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut));
7279   setDtUnit(dtunitOut.c_str());
7280   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7281 }
7282
7283 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7284 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7285 {
7286   setDtUnit(dtunit.c_str());
7287   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7288 }
7289 catch(INTERP_KERNEL::Exception& e)
7290 {
7291     throw e;
7292 }
7293
7294 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7295 {
7296   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7297   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7298     ret+=(*it).capacity();
7299   return ret;
7300 }
7301
7302 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7303 {
7304   std::vector<const BigMemoryObject *> ret;
7305   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7306     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7307   return ret;
7308 }
7309
7310 /*!
7311  * 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
7312  * NULL.
7313  */
7314 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7315 {
7316   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7317   ret->setInfo(_infos);
7318   int sz=(int)_time_steps.size();
7319   for(const int *id=startIds;id!=endIds;id++)
7320     {
7321       if(*id>=0 && *id<sz)
7322         {
7323           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7324           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7325           if(tse)
7326             {
7327               tse->incrRef();
7328               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7329             }
7330           ret->pushBackTimeStep(tse2);
7331         }
7332       else
7333         {
7334           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7335           oss << " ! Should be in [0," << sz << ") !";
7336           throw INTERP_KERNEL::Exception(oss.str());
7337         }
7338     }
7339   if(ret->getNumberOfTS()>0)
7340     ret->synchronizeNameScope();
7341   ret->copyNameScope(*this);
7342   return ret.retn();
7343 }
7344
7345 /*!
7346  * 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
7347  * NULL.
7348  */
7349 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7350 {
7351   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7352   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7353   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7354   ret->setInfo(_infos);
7355   int sz=(int)_time_steps.size();
7356   int j=bg;
7357   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7358     {
7359       if(j>=0 && j<sz)
7360         {
7361           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7362           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7363           if(tse)
7364             {
7365               tse->incrRef();
7366               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7367             }
7368           ret->pushBackTimeStep(tse2);
7369         }
7370       else
7371         {
7372           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7373           oss << " ! Should be in [0," << sz << ") !";
7374           throw INTERP_KERNEL::Exception(oss.str());
7375         }
7376     }
7377   if(ret->getNumberOfTS()>0)
7378     ret->synchronizeNameScope();
7379   ret->copyNameScope(*this);
7380   return ret.retn();
7381 }
7382
7383 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7384 {
7385   int id=0;
7386   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7387   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7388     {
7389       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7390       if(!cur)
7391         continue;
7392       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7393       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7394         ids->pushBackSilent(id);
7395     }
7396   return buildFromTimeStepIds(ids->begin(),ids->end());
7397 }
7398
7399 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7400 {
7401   int id=0;
7402   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7403   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7404     {
7405       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7406       if(!cur)
7407         continue;
7408       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7409       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7410         ids->pushBackSilent(id);
7411     }
7412   return buildFromTimeStepIds(ids->begin(),ids->end());
7413 }
7414
7415 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7416 {
7417   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7418     {
7419       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7420       if(!cur)
7421         continue;
7422       if(cur->presenceOfMultiDiscPerGeoType())
7423         return true;
7424     }
7425   return false;
7426 }
7427
7428 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7429 {
7430   return _infos;
7431 }
7432
7433 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7434 {
7435   _infos=info;
7436 }
7437
7438 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7439 {
7440   int ret=0;
7441   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7442     {
7443       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7444       if(pt->isDealingTS(iteration,order))
7445         return ret;
7446     }
7447   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7448   std::vector< std::pair<int,int> > vp=getIterations();
7449   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7450     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7451   throw INTERP_KERNEL::Exception(oss.str());
7452 }
7453
7454 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7455 {
7456   return *_time_steps[getTimeStepPos(iteration,order)];
7457 }
7458
7459 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7460 {
7461   return *_time_steps[getTimeStepPos(iteration,order)];
7462 }
7463
7464 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7465 {
7466   if(_time_steps.empty())
7467     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7468   return _time_steps[0]->getMeshName();
7469 }
7470
7471 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7472 {
7473   std::string oldName(getMeshName());
7474   std::vector< std::pair<std::string,std::string> > v(1);
7475   v[0].first=oldName; v[0].second=newMeshName;
7476   changeMeshNames(v);
7477 }
7478
7479 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7480 {
7481   bool ret=false;
7482   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7483     {
7484       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7485       if(cur)
7486         ret=cur->changeMeshNames(modifTab) || ret;
7487     }
7488   return ret;
7489 }
7490
7491 /*!
7492  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7493  */
7494 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7495 {
7496   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7497 }
7498
7499 /*!
7500  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7501  */
7502 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7503 {
7504   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7505 }
7506
7507 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7508                                                                        MEDFileFieldGlobsReal& glob)
7509 {
7510   bool ret=false;
7511   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7512     {
7513       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7514       if(f1ts)
7515         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7516     }
7517   return ret;
7518 }
7519
7520 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7521 {
7522   std::string startLine(bkOffset,' ');
7523   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7524   if(fmtsId>=0)
7525     oss << " (" << fmtsId << ")";
7526   oss << " has the following name: \"" << _name << "\"." << std::endl;
7527   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7528   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7529     {
7530       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7531     }
7532   int i=0;
7533   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7534     {
7535       std::string chapter(17,'0'+i);
7536       oss << startLine << chapter << std::endl;
7537       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7538       if(cur)
7539         cur->simpleRepr(bkOffset+2,oss,i);
7540       else
7541         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7542       oss << startLine << chapter << std::endl;
7543     }
7544 }
7545
7546 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7547 {
7548   std::size_t sz=_time_steps.size();
7549   std::vector< std::pair<int,int> > ret(sz);
7550   ret1.resize(sz);
7551   for(std::size_t i=0;i<sz;i++)
7552     {
7553       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7554       if(f1ts)
7555         {
7556           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7557         }
7558       else
7559         {
7560           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7561           throw INTERP_KERNEL::Exception(oss.str());
7562         }
7563     }
7564   return ret;
7565 }
7566
7567 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7568 {
7569   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7570   if(!tse2)
7571     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7572   checkCoherencyOfType(tse2);
7573   if(_time_steps.empty())
7574     {
7575       setName(tse2->getName().c_str());
7576       setInfo(tse2->getInfo());
7577     }
7578   checkThatComponentsMatch(tse2->getInfo());
7579   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7580     setDtUnit(tse->getDtUnit());
7581   _time_steps.push_back(tse);
7582 }
7583
7584 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7585 {
7586   std::size_t nbOfCompo=_infos.size();
7587   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7588     {
7589       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7590       if(cur)
7591         {
7592           if((cur->getInfo()).size()!=nbOfCompo)
7593             {
7594               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7595               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7596               throw INTERP_KERNEL::Exception(oss.str());
7597             }
7598           cur->copyNameScope(*this);
7599         }
7600     }
7601 }
7602
7603 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7604 {
7605   _time_steps.resize(nbPdt);
7606   for(int i=0;i<nbPdt;i++)
7607     {
7608       std::vector< std::pair<int,int> > ts;
7609       med_int numdt=0,numo=0;
7610       med_float dt=0.0;
7611       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
7612       switch(fieldTyp)
7613       {
7614         case MED_FLOAT64:
7615           {
7616             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7617             break;
7618           }
7619         case MED_INT32:
7620           {
7621             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7622             break;
7623           }
7624         default:
7625           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7626       }
7627       if(loadAll)
7628         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7629       else
7630         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7631       synchronizeNameScope();
7632     }
7633 }
7634
7635 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7636 {
7637   if(_time_steps.empty())
7638     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7639   checkThatNbOfCompoOfTSMatchThis();
7640   std::vector<std::string> infos(getInfo());
7641   int nbComp=infos.size();
7642   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7643   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7644   for(int i=0;i<nbComp;i++)
7645     {
7646       std::string info=infos[i];
7647       std::string c,u;
7648       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7649       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7650       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7651     }
7652   if(_name.empty())
7653     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7654   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7655   int nbOfTS=_time_steps.size();
7656   for(int i=0;i<nbOfTS;i++)
7657     _time_steps[i]->writeLL(fid,opts,*this);
7658 }
7659
7660 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7661 {
7662   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7663     {
7664       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7665       if(elt)
7666         elt->loadBigArraysRecursively(fid,nasc);
7667     }
7668 }
7669
7670 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7671 {
7672   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7673     {
7674       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7675       if(elt)
7676         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7677     }
7678 }
7679
7680 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7681 {
7682   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7683     {
7684       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7685       if(elt)
7686         elt->unloadArrays();
7687     }
7688 }
7689
7690 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7691 {
7692   return _time_steps.size();
7693 }
7694
7695 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7696 {
7697   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7698   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7699     {
7700       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7701       if(tmp)
7702         newTS.push_back(*it);
7703     }
7704   _time_steps=newTS;
7705 }
7706
7707 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7708 {
7709   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7710   int maxId=(int)_time_steps.size();
7711   int ii=0;
7712   std::set<int> idsToDel;
7713   for(const int *id=startIds;id!=endIds;id++,ii++)
7714     {
7715       if(*id>=0 && *id<maxId)
7716         {
7717           idsToDel.insert(*id);
7718         }
7719       else
7720         {
7721           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7722           throw INTERP_KERNEL::Exception(oss.str());
7723         }
7724     }
7725   for(int iii=0;iii<maxId;iii++)
7726     if(idsToDel.find(iii)==idsToDel.end())
7727       newTS.push_back(_time_steps[iii]);
7728   _time_steps=newTS;
7729 }
7730
7731 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7732 {
7733   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7734   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7735   if(nbOfEntriesToKill==0)
7736     return ;
7737   std::size_t sz=_time_steps.size();
7738   std::vector<bool> b(sz,true);
7739   int j=bg;
7740   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7741     b[j]=false;
7742   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7743   for(std::size_t i=0;i<sz;i++)
7744     if(b[i])
7745       newTS.push_back(_time_steps[i]);
7746   _time_steps=newTS;
7747 }
7748
7749 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7750 {
7751   int ret=0;
7752   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7753   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7754     {
7755       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7756       if(tmp)
7757         {
7758           int it2,ord;
7759           tmp->getTime(it2,ord);
7760           if(it2==iteration && order==ord)
7761             return ret;
7762           else
7763             oss << "(" << it2 << ","  << ord << "), ";
7764         }
7765     }
7766   throw INTERP_KERNEL::Exception(oss.str());
7767 }
7768
7769 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7770 {
7771   int ret=0;
7772   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7773   oss.precision(15);
7774   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7775     {
7776       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7777       if(tmp)
7778         {
7779           int it2,ord;
7780           double ti=tmp->getTime(it2,ord);
7781           if(fabs(time-ti)<eps)
7782             return ret;
7783           else
7784             oss << ti << ", ";
7785         }
7786     }
7787   throw INTERP_KERNEL::Exception(oss.str());
7788 }
7789
7790 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7791 {
7792   int lgth=_time_steps.size();
7793   std::vector< std::pair<int,int> > ret(lgth);
7794   for(int i=0;i<lgth;i++)
7795     _time_steps[i]->fillIteration(ret[i]);
7796   return ret;
7797 }
7798
7799 /*!
7800  * 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'
7801  * This method returns two things.
7802  * - The absolute dimension of 'this' in first parameter. 
7803  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7804  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7805  *
7806  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7807  * Only these 3 discretizations will be taken into account here.
7808  *
7809  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7810  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7811  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7812  *
7813  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7814  * 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'.
7815  * 
7816  * Let's consider the typical following case :
7817  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7818  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7819  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7820  *   TETRA4 and SEG2
7821  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7822  *
7823  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7824  * 
7825  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7826  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7827  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7828  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7829  */
7830 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7831 {
7832   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7833 }
7834
7835 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7836 {
7837   if(pos<0 || pos>=(int)_time_steps.size())
7838     {
7839       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7840       throw INTERP_KERNEL::Exception(oss.str());
7841     }
7842   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7843   if(item==0)
7844     {
7845       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7846       oss << "\nTry to use following method eraseEmptyTS !";
7847       throw INTERP_KERNEL::Exception(oss.str());
7848     }
7849   return item;
7850 }
7851
7852 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7853 {
7854   if(pos<0 || pos>=(int)_time_steps.size())
7855     {
7856       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7857       throw INTERP_KERNEL::Exception(oss.str());
7858     }
7859   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7860   if(item==0)
7861     {
7862       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7863       oss << "\nTry to use following method eraseEmptyTS !";
7864       throw INTERP_KERNEL::Exception(oss.str());
7865     }
7866   return item;
7867 }
7868
7869 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7870 {
7871   std::vector<std::string> ret;
7872   std::set<std::string> ret2;
7873   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7874     {
7875       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7876       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7877         if(ret2.find(*it2)==ret2.end())
7878           {
7879             ret.push_back(*it2);
7880             ret2.insert(*it2);
7881           }
7882     }
7883   return ret;
7884 }
7885
7886 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7887 {
7888   std::vector<std::string> ret;
7889   std::set<std::string> ret2;
7890   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7891     {
7892       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7893       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7894         if(ret2.find(*it2)==ret2.end())
7895           {
7896             ret.push_back(*it2);
7897             ret2.insert(*it2);
7898           }
7899     }
7900   return ret;
7901 }
7902
7903 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7904 {
7905   std::vector<std::string> ret;
7906   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7907     {
7908       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7909       ret.insert(ret.end(),tmp.begin(),tmp.end());
7910     }
7911   return ret;
7912 }
7913
7914 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7915 {
7916   std::vector<std::string> ret;
7917   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7918     {
7919       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7920       ret.insert(ret.end(),tmp.begin(),tmp.end());
7921     }
7922   return ret;
7923 }
7924
7925 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7926 {
7927   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7928     (*it)->changePflsRefsNamesGen2(mapOfModif);
7929 }
7930
7931 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7932 {
7933   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7934     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7935 }
7936
7937 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7938 {
7939   int lgth=_time_steps.size();
7940   std::vector< std::vector<TypeOfField> > ret(lgth);
7941   for(int i=0;i<lgth;i++)
7942     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7943   return ret;
7944 }
7945
7946 /*!
7947  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7948  */
7949 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
7950 {
7951   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7952 }
7953
7954 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7955 {
7956   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7957   std::size_t i=0;
7958   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7959     {
7960       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7961         ret->_time_steps[i]=(*it)->deepCopy();
7962     }
7963   return ret.retn();
7964 }
7965
7966 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7967 {
7968   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7969   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7970   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7971   for(std::size_t i=0;i<sz;i++)
7972     {
7973       ret[i]=shallowCpy();
7974       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7975     }
7976   for(std::size_t i=0;i<sz2;i++)
7977     {
7978       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7979       if(ret1.size()!=sz)
7980         {
7981           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7982           throw INTERP_KERNEL::Exception(oss.str());
7983         }
7984       ts[i]=ret1;
7985     }
7986   for(std::size_t i=0;i<sz;i++)
7987     for(std::size_t j=0;j<sz2;j++)
7988       ret[i]->_time_steps[j]=ts[j][i];
7989   return ret;
7990 }
7991
7992 /*!
7993  * This method splits into discretization each time steps in \a this.
7994  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7995  */
7996 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7997 {
7998   std::size_t sz(_time_steps.size());
7999   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8000   for(std::size_t i=0;i<sz;i++)
8001     {
8002       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8003       if(!timeStep)
8004         {
8005           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
8006           throw INTERP_KERNEL::Exception(oss.str());
8007         }
8008       items[i]=timeStep->splitDiscretizations();  
8009     }
8010   //
8011   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
8012   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
8013   std::vector< TypeOfField > types;
8014   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8015     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8016       {
8017         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
8018         if(ts.size()!=1)
8019           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
8020         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
8021         if(it2==types.end())
8022           types.push_back(ts[0]);
8023       }
8024   ret.resize(types.size()); ret2.resize(types.size());
8025   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8026     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8027       {
8028         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
8029         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
8030         ret2[pos].push_back(*it1);
8031       }
8032   for(std::size_t i=0;i<types.size();i++)
8033     {
8034       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8035       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
8036         elt->pushBackTimeStep(*it1);//also updates infos in elt
8037       ret[i]=elt;
8038       elt->MEDFileFieldNameScope::operator=(*this);
8039     }
8040   return ret;
8041 }
8042
8043 /*!
8044  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
8045  */
8046 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
8047 {
8048   std::size_t sz(_time_steps.size());
8049   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8050   std::size_t szOut(std::numeric_limits<std::size_t>::max());
8051   for(std::size_t i=0;i<sz;i++)
8052     {
8053       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8054       if(!timeStep)
8055         {
8056           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
8057           throw INTERP_KERNEL::Exception(oss.str());
8058         }
8059       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
8060       if(szOut==std::numeric_limits<std::size_t>::max())
8061         szOut=items[i].size();
8062       else
8063         if(items[i].size()!=szOut)
8064           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
8065     }
8066   if(szOut==std::numeric_limits<std::size_t>::max())
8067     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
8068   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
8069   for(std::size_t i=0;i<szOut;i++)
8070     {
8071       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8072       for(std::size_t j=0;j<sz;j++)
8073         elt->pushBackTimeStep(items[j][i]);
8074       ret[i]=elt;
8075       elt->MEDFileFieldNameScope::operator=(*this);
8076     }
8077   return ret;
8078 }
8079
8080 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
8081 {
8082   _name=field->getName();
8083   if(_name.empty())
8084     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
8085   if(!arr)
8086     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
8087   _infos=arr->getInfoOnComponents();
8088 }
8089
8090 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
8091 {
8092   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
8093   if(_name!=field->getName())
8094     {
8095       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
8096       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
8097       throw INTERP_KERNEL::Exception(oss.str());
8098     }
8099   if(!arr)
8100     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
8101   checkThatComponentsMatch(arr->getInfoOnComponents());
8102 }
8103
8104 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
8105 {
8106   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
8107   if(getInfo().size()!=compos.size())
8108     {
8109       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
8110       oss << " number of components of element to append (" << compos.size() << ") !";
8111       throw INTERP_KERNEL::Exception(oss.str());
8112     }
8113   if(_infos!=compos)
8114     {
8115       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
8116       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
8117       oss << " But compo in input fields are : ";
8118       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
8119       oss << " !";
8120       throw INTERP_KERNEL::Exception(oss.str());
8121     }
8122 }
8123
8124 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
8125 {
8126   std::size_t sz=_infos.size();
8127   int j=0;
8128   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
8129     {
8130       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8131       if(elt)
8132         if(elt->getInfo().size()!=sz)
8133           {
8134             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
8135             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
8136             throw INTERP_KERNEL::Exception(oss.str());
8137           }
8138     }
8139 }
8140
8141 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
8142 {
8143   if(!field)
8144     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8145   if(!_time_steps.empty())
8146     checkCoherencyOfTinyInfo(field,arr);
8147   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8148   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8149   objC->setFieldNoProfileSBT(field,arr,glob,*this);
8150   copyTinyInfoFrom(field,arr);
8151   _time_steps.push_back(obj);
8152 }
8153
8154 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
8155 {
8156   if(!field)
8157     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8158   if(!_time_steps.empty())
8159     checkCoherencyOfTinyInfo(field,arr);
8160   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8161   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8162   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
8163   copyTinyInfoFrom(field,arr);
8164   _time_steps.push_back(obj);
8165 }
8166
8167 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8168 {
8169   int sz=(int)_time_steps.size();
8170   if(i<0 || i>=sz)
8171     {
8172       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8173       throw INTERP_KERNEL::Exception(oss.str());
8174     }
8175   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8176   if(tsPtr)
8177     {
8178       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8179         {
8180           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8181           throw INTERP_KERNEL::Exception(oss.str());
8182         }
8183     }
8184   _time_steps[i]=ts;
8185 }
8186
8187 //= MEDFileFieldMultiTSWithoutSDA
8188
8189 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8190 {
8191   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8192 }
8193
8194 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
8195 {
8196 }
8197
8198 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8199 {
8200 }
8201
8202 /*!
8203  * \param [in] fieldId field id in C mode
8204  */
8205 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8206 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8207 {
8208 }
8209 catch(INTERP_KERNEL::Exception& e)
8210 { throw e; }
8211
8212 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8213 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8214 {
8215 }
8216 catch(INTERP_KERNEL::Exception& e)
8217 { throw e; }
8218
8219 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8220 {
8221   return new MEDFileField1TSWithoutSDA;
8222 }
8223
8224 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8225 {
8226   if(!f1ts)
8227     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8228   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8229   if(!f1tsC)
8230     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8231 }
8232
8233 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8234 {
8235   return MEDFileField1TSWithoutSDA::TYPE_STR;
8236 }
8237
8238 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8239 {
8240   return new MEDFileFieldMultiTSWithoutSDA(*this);
8241 }
8242
8243 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8244 {
8245   return new MEDFileFieldMultiTSWithoutSDA;
8246 }
8247
8248 /*!
8249  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8250  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8251  */
8252 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
8253 {
8254   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8255   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8256   if(!myF1TSC)
8257     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8258   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8259 }
8260
8261 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8262 {
8263   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8264   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8265   int i=0;
8266   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8267     {
8268       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8269       if(eltToConv)
8270         {
8271           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8272           if(!eltToConvC)
8273             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8274           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8275           ret->setIteration(i,elt);
8276         }
8277     }
8278   return ret.retn();
8279 }
8280
8281 //= MEDFileAnyTypeFieldMultiTS
8282
8283 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8284 {
8285 }
8286
8287 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8288 try:MEDFileFieldGlobsReal(fid)
8289 {
8290   _content=BuildContentFrom(fid,loadAll,ms);
8291   loadGlobals(fid);
8292 }
8293 catch(INTERP_KERNEL::Exception& e)
8294 {
8295     throw e;
8296 }
8297
8298 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8299 {
8300   med_field_type typcha;
8301   std::vector<std::string> infos;
8302   std::string dtunit;
8303   int i(-1);
8304   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit);
8305   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8306   switch(typcha)
8307   {
8308     case MED_FLOAT64:
8309       {
8310         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8311         break;
8312       }
8313     case MED_INT32:
8314       {
8315         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8316         break;
8317       }
8318     default:
8319       {
8320         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
8321         throw INTERP_KERNEL::Exception(oss.str());
8322       }
8323   }
8324   ret->setDtUnit(dtunit.c_str());
8325   return ret.retn();
8326 }
8327
8328 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8329 {
8330   med_field_type typcha;
8331   //
8332   std::vector<std::string> infos;
8333   std::string dtunit,fieldName;
8334   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
8335   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8336   switch(typcha)
8337   {
8338     case MED_FLOAT64:
8339       {
8340         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8341         break;
8342       }
8343     case MED_INT32:
8344       {
8345         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8346         break;
8347       }
8348     default:
8349       {
8350         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
8351         throw INTERP_KERNEL::Exception(oss.str());
8352       }
8353   }
8354   ret->setDtUnit(dtunit.c_str());
8355   return ret.retn();
8356 }
8357
8358 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8359 {
8360   if(!c)
8361     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8362   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8363     {
8364       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8365       ret->_content=c;  c->incrRef();
8366       return ret.retn();
8367     }
8368   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8369     {
8370       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8371       ret->_content=c;  c->incrRef();
8372       return ret.retn();
8373     }
8374   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8375 }
8376
8377 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8378 {
8379   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8380   std::string fileName(FileNameFromFID(fid));
8381   ret->setFileName(fileName);
8382   return ret;
8383 }
8384
8385 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8386 try:MEDFileFieldGlobsReal(fid)
8387 {
8388   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8389   loadGlobals(fid);
8390 }
8391 catch(INTERP_KERNEL::Exception& e)
8392 {
8393     throw e;
8394 }
8395
8396 //= MEDFileIntFieldMultiTSWithoutSDA
8397
8398 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8399 {
8400   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8401 }
8402
8403 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8404 {
8405 }
8406
8407 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8408 {
8409 }
8410
8411 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8412 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8413 {
8414 }
8415 catch(INTERP_KERNEL::Exception& e)
8416 { throw e; }
8417
8418 /*!
8419  * \param [in] fieldId field id in C mode
8420  */
8421 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8422 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8423 {
8424 }
8425 catch(INTERP_KERNEL::Exception& e)
8426 { throw e; }
8427
8428 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8429 {
8430   return new MEDFileIntField1TSWithoutSDA;
8431 }
8432
8433 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8434 {
8435   if(!f1ts)
8436     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8437   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8438   if(!f1tsC)
8439     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8440 }
8441
8442 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8443 {
8444   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8445 }
8446
8447 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8448 {
8449   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8450 }
8451
8452 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8453 {
8454   return new MEDFileIntFieldMultiTSWithoutSDA;
8455 }
8456
8457 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8458 {
8459   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8460   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8461   int i=0;
8462   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8463     {
8464       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8465       if(eltToConv)
8466         {
8467           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8468           if(!eltToConvC)
8469             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8470           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8471           ret->setIteration(i,elt);
8472         }
8473     }
8474   return ret.retn();
8475 }
8476
8477 //= MEDFileAnyTypeFieldMultiTS
8478
8479 /*!
8480  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8481  * that has been read from a specified MED file.
8482  *  \param [in] fileName - the name of the MED file to read.
8483  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8484  *          is to delete this field using decrRef() as it is no more needed.
8485  *  \throw If reading the file fails.
8486  */
8487 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8488 {
8489   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8490   return New(fid,loadAll);
8491 }
8492
8493 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8494 {
8495   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8496   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8497   ret->loadGlobals(fid);
8498   return ret.retn();
8499 }
8500
8501 /*!
8502  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8503  * that has been read from a specified MED file.
8504  *  \param [in] fileName - the name of the MED file to read.
8505  *  \param [in] fieldName - the name of the field to read.
8506  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8507  *          is to delete this field using decrRef() as it is no more needed.
8508  *  \throw If reading the file fails.
8509  *  \throw If there is no field named \a fieldName in the file.
8510  */
8511 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8512 {
8513   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8514   return New(fid,fieldName,loadAll);
8515 }
8516
8517 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8518 {
8519   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8520   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8521   ret->loadGlobals(fid);
8522   return ret.retn();
8523 }
8524
8525 /*!
8526  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8527  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8528  *
8529  * \warning this is a shallow copy constructor
8530  */
8531 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8532 {
8533   if(!shallowCopyOfContent)
8534     {
8535       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8536       otherPtr->incrRef();
8537       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8538     }
8539   else
8540     {
8541       _content=other.shallowCpy();
8542     }
8543 }
8544
8545 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8546 {
8547   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8548   if(!ret)
8549     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8550   return ret;
8551 }
8552
8553 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8554 {
8555   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8556   if(!ret)
8557     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8558   return ret;
8559 }
8560
8561 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8562 {
8563   return contentNotNullBase()->getPflsReallyUsed2();
8564 }
8565
8566 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8567 {
8568   return contentNotNullBase()->getLocsReallyUsed2();
8569 }
8570
8571 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8572 {
8573   return contentNotNullBase()->getPflsReallyUsedMulti2();
8574 }
8575
8576 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8577 {
8578   return contentNotNullBase()->getLocsReallyUsedMulti2();
8579 }
8580
8581 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8582 {
8583   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8584 }
8585
8586 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8587 {
8588   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8589 }
8590
8591 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8592 {
8593   return contentNotNullBase()->getNumberOfTS();
8594 }
8595
8596 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8597 {
8598   contentNotNullBase()->eraseEmptyTS();
8599 }
8600
8601 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8602 {
8603   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8604 }
8605
8606 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8607 {
8608   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8609 }
8610
8611 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8612 {
8613   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8614   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8615   ret->_content=c;
8616   return ret.retn();
8617 }
8618
8619 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8620 {
8621   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8622   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8623   ret->_content=c;
8624   return ret.retn();
8625 }
8626
8627 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8628 {
8629   return contentNotNullBase()->getIterations();
8630 }
8631
8632 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8633 {
8634   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8635     pushBackTimeStep(*it);
8636 }
8637
8638 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8639 {
8640   if(!fmts)
8641     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8642   int nbOfTS(fmts->getNumberOfTS());
8643   for(int i=0;i<nbOfTS;i++)
8644     {
8645       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8646       pushBackTimeStep(elt);
8647     }
8648 }
8649
8650 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8651 {
8652   if(!f1ts)
8653     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8654   checkCoherencyOfType(f1ts);
8655   f1ts->incrRef();
8656   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8657   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8658   c->incrRef();
8659   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8660   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8661     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8662   _content->pushBackTimeStep(cSafe);
8663   appendGlobs(*f1ts,1e-12);
8664 }
8665
8666 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8667 {
8668   contentNotNullBase()->synchronizeNameScope();
8669 }
8670
8671 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8672 {
8673   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8674 }
8675
8676 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8677 {
8678   return contentNotNullBase()->getPosGivenTime(time,eps);
8679 }
8680
8681 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8682 {
8683   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8684 }
8685
8686 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8687 {
8688   return contentNotNullBase()->getTypesOfFieldAvailable();
8689 }
8690
8691 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
8692 {
8693   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8694 }
8695
8696 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8697 {
8698   return contentNotNullBase()->getName();
8699 }
8700
8701 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8702 {
8703   contentNotNullBase()->setName(name);
8704 }
8705
8706 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8707 {
8708   return contentNotNullBase()->getDtUnit();
8709 }
8710
8711 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8712 {
8713   contentNotNullBase()->setDtUnit(dtUnit);
8714 }
8715
8716 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8717 {
8718   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8719 }
8720
8721 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8722 {
8723   return contentNotNullBase()->getTimeSteps(ret1);
8724 }
8725
8726 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8727 {
8728   return contentNotNullBase()->getMeshName();
8729 }
8730
8731 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8732 {
8733   contentNotNullBase()->setMeshName(newMeshName);
8734 }
8735
8736 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8737 {
8738   return contentNotNullBase()->changeMeshNames(modifTab);
8739 }
8740
8741 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8742 {
8743   return contentNotNullBase()->getInfo();
8744 }
8745
8746 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8747 {
8748   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8749 }
8750
8751 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8752 {
8753   return contentNotNullBase()->setInfo(info);
8754 }
8755
8756 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8757 {
8758   const std::vector<std::string> ret=getInfo();
8759   return (int)ret.size();
8760 }
8761
8762 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8763 {
8764   writeGlobals(fid,*this);
8765   contentNotNullBase()->writeLL(fid,*this);
8766 }
8767
8768 /*!
8769  * This method alloc the arrays and load potentially huge arrays contained in this field.
8770  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8771  * This method can be also called to refresh or reinit values from a file.
8772  * 
8773  * \throw If the fileName is not set or points to a non readable MED file.
8774  */
8775 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8776 {
8777   if(getFileName().empty())
8778     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8779   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8780   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8781 }
8782
8783 /*!
8784  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8785  * But once data loaded once, this method does nothing.
8786  * 
8787  * \throw If the fileName is not set or points to a non readable MED file.
8788  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8789  */
8790 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8791 {
8792   if(!getFileName().empty())
8793     {
8794       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8795       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8796     }
8797 }
8798
8799 /*!
8800  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8801  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8802  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8803  * 
8804  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8805  */
8806 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8807 {
8808   contentNotNullBase()->unloadArrays();
8809 }
8810
8811 /*!
8812  * 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.
8813  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8814  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8815  * 
8816  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8817  */
8818 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8819 {
8820   if(!getFileName().empty())
8821     contentNotNullBase()->unloadArrays();
8822 }
8823
8824 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8825 {
8826   std::ostringstream oss;
8827   contentNotNullBase()->simpleRepr(0,oss,-1);
8828   simpleReprGlobs(oss);
8829   return oss.str();
8830 }
8831
8832 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8833 {
8834   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8835 }
8836
8837 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8838 {
8839   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8840   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8841   return ret;
8842 }
8843
8844 /*!
8845  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8846  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8847  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8848  */
8849 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8850 {
8851   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8852   if(!content)
8853     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8854   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8855   std::size_t sz(contentsSplit.size());
8856   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8857   for(std::size_t i=0;i<sz;i++)
8858     {
8859       ret[i]=shallowCpy();
8860       ret[i]->_content=contentsSplit[i];
8861     }
8862   return ret;
8863 }
8864
8865 /*!
8866  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8867  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8868  */
8869 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8870 {
8871   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8872   if(!content)
8873     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8874   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8875   std::size_t sz(contentsSplit.size());
8876   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8877   for(std::size_t i=0;i<sz;i++)
8878     {
8879       ret[i]=shallowCpy();
8880       ret[i]->_content=contentsSplit[i];
8881     }
8882   return ret;
8883 }
8884
8885 /*!
8886  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8887  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8888  */
8889 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8890 {
8891   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8892   if(!content)
8893     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8894   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8895   std::size_t sz(contentsSplit.size());
8896   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8897   for(std::size_t i=0;i<sz;i++)
8898     {
8899       ret[i]=shallowCpy();
8900       ret[i]->_content=contentsSplit[i];
8901     }
8902   return ret;
8903 }
8904
8905 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8906 {
8907   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8908   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8909     ret->_content=_content->deepCopy();
8910   ret->deepCpyGlobs(*this);
8911   return ret.retn();
8912 }
8913
8914 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8915 {
8916   return _content;
8917 }
8918
8919 /*!
8920  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8921  *  \param [in] iteration - the iteration number of a required time step.
8922  *  \param [in] order - the iteration order number of required time step.
8923  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8924  *          delete this field using decrRef() as it is no more needed.
8925  *  \throw If there is no required time step in \a this field.
8926  */
8927 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8928 {
8929   int pos=getPosOfTimeStep(iteration,order);
8930   return getTimeStepAtPos(pos);
8931 }
8932
8933 /*!
8934  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8935  *  \param [in] time - the time of the time step of interest.
8936  *  \param [in] eps - a precision used to compare time values.
8937  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8938  *          delete this field using decrRef() as it is no more needed.
8939  *  \throw If there is no required time step in \a this field.
8940  */
8941 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8942 {
8943   int pos=getPosGivenTime(time,eps);
8944   return getTimeStepAtPos(pos);
8945 }
8946
8947 /*!
8948  * 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.
8949  * The float64 value of time attached to the pair of integers are not considered here.
8950  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8951  *
8952  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8953  * \throw If there is a null pointer in \a vectFMTS.
8954  */
8955 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8956 {
8957   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8958   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8959   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8960   while(!lstFMTS.empty())
8961     {
8962       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8963       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8964       if(!curIt)
8965         throw INTERP_KERNEL::Exception(msg);
8966       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8967       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8968       elt.push_back(curIt); it=lstFMTS.erase(it);
8969       while(it!=lstFMTS.end())
8970         {
8971           curIt=*it;
8972           if(!curIt)
8973             throw INTERP_KERNEL::Exception(msg);
8974           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8975           if(refIts==curIts)
8976             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8977           else
8978             it++;
8979         }
8980       ret.push_back(elt);
8981     }
8982   return ret;
8983 }
8984
8985 /*!
8986  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8987  * All returned instances in a subvector can be safely loaded, rendered along time
8988  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8989  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8990  * 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).
8991  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8992  * 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.
8993  *
8994  * \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().
8995  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8996  * \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.
8997  * \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.
8998  *
8999  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
9000  * \throw If an element in \a vectFMTS change of spatial discretization along time.
9001  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
9002  * \thorw If some elements in \a vectFMTS do not have the same times steps.
9003  * \throw If mesh is null.
9004  * \throw If an element in \a vectFMTS is null.
9005  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
9006  */
9007 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
9008 {
9009   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
9010   if(!mesh)
9011     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
9012   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9013   if(vectFMTS.empty())
9014     return ret;
9015   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
9016   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
9017   if(!frstElt)
9018     throw INTERP_KERNEL::Exception(msg);
9019   std::size_t i=0;
9020   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
9021   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
9022   for(;it!=vectFMTS.end();it++,i++)
9023     {
9024       if(!(*it))
9025         throw INTERP_KERNEL::Exception(msg);
9026       TypeOfField tof0,tof1;
9027       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
9028         {
9029           if(tof1!=ON_NODES)
9030             vectFMTSNotNodes.push_back(*it);
9031           else
9032             vectFMTSNodes.push_back(*it);
9033         }
9034       else
9035         vectFMTSNotNodes.push_back(*it);
9036     }
9037   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
9038   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
9039   ret=retCell;
9040   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
9041     {
9042       i=0;
9043       bool isFetched(false);
9044       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
9045         {
9046           if((*it0).empty())
9047             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
9048           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
9049             { ret[i].push_back(*it2); isFetched=true; }
9050         }
9051       if(!isFetched)
9052         {
9053           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
9054           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
9055           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
9056         }
9057     }
9058   fsc=cmps;
9059   return ret;
9060 }
9061
9062 /*!
9063  * 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.
9064  * \param [out] cmps - same size than the returned vector.
9065  */
9066 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
9067 {
9068   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9069   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9070   while(!lstFMTS.empty())
9071     {
9072       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9073       MEDFileAnyTypeFieldMultiTS *ref(*it);
9074       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9075       elt.push_back(ref); it=lstFMTS.erase(it);
9076       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
9077       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
9078       while(it!=lstFMTS.end())
9079         {
9080           MEDFileAnyTypeFieldMultiTS *curIt(*it);
9081           if(cmp->isEqual(curIt))
9082             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9083           else
9084             it++;
9085         }
9086       ret.push_back(elt); cmps.push_back(cmp);
9087     }
9088   return ret;
9089 }
9090
9091 /*!
9092  * 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.
9093  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
9094  *
9095  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
9096  * \throw If \a f0 or \a f1 change of spatial discretization along time.
9097  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
9098  * \thorw If \a f0 and \a f1 do not have the same times steps.
9099  * \throw If mesh is null.
9100  * \throw If \a f0 or \a f1 is null.
9101  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
9102  */
9103 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
9104 {
9105   if(!mesh)
9106     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
9107   if(!f0 || !f1)
9108     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
9109   if(f0->getMeshName()!=mesh->getName())
9110     {
9111       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9112       throw INTERP_KERNEL::Exception(oss.str());
9113     }
9114   if(f1->getMeshName()!=mesh->getName())
9115     {
9116       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9117       throw INTERP_KERNEL::Exception(oss.str());
9118     }
9119   int nts=f0->getNumberOfTS();
9120   if(nts!=f1->getNumberOfTS())
9121     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
9122   if(nts==0)
9123     return nts;
9124   for(int i=0;i<nts;i++)
9125     {
9126       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
9127       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
9128       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
9129       if(tofs0.size()!=1 || tofs1.size()!=1)
9130         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
9131       if(i!=0)
9132         {
9133           if(tof0!=tofs0[0] || tof1!=tofs1[0])
9134             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
9135         }
9136       else
9137         { tof0=tofs0[0]; tof1=tofs1[0]; }
9138       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
9139         {
9140           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() << ") !";
9141           throw INTERP_KERNEL::Exception(oss.str());
9142         }
9143       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
9144         {
9145           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() << ") !";
9146           throw INTERP_KERNEL::Exception(oss.str());
9147         }
9148       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
9149         {
9150           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() << ") !";
9151           throw INTERP_KERNEL::Exception(oss.str());
9152         }
9153     }
9154   return nts;
9155 }
9156
9157 /*!
9158  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9159  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9160  *
9161  * \return A new object that the caller is responsible to deallocate.
9162  */
9163 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9164 {
9165   if(!mm)
9166     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9167   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
9168   int nbTS(getNumberOfTS());
9169   for(int i=0;i<nbTS;i++)
9170     {
9171       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
9172       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9173       fmtsOut->pushBackTimeStep(f1tsOut);
9174     }
9175   return fmtsOut.retn();
9176 }
9177
9178 template<class T>
9179 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9180 {
9181   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
9182   if(f1tss.empty())
9183     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
9184   std::size_t sz(f1tss.size()),i(0);
9185   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
9186   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
9187     {
9188       typename MLFieldTraits<T>::F1TSType const *elt(*it);
9189       if(!elt)
9190         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
9191       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
9192     }
9193   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
9194   if(!retc)
9195     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
9196   retc->aggregate(f1tsw,dts);
9197   ret->setDtUnit(f1tss[0]->getDtUnit());
9198   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
9199 }
9200
9201 template<class T>
9202 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9203 {
9204   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
9205   if(fmtss.empty())
9206     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
9207   std::size_t sz(fmtss.size());
9208   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9209     {
9210       typename MLFieldTraits<T>::FMTSType const *elt(*it);
9211       if(!elt)
9212         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
9213     }
9214   int nbTS(fmtss[0]->getNumberOfTS());
9215   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9216     if((*it)->getNumberOfTS()!=nbTS)
9217       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
9218   for(int iterTS=0;iterTS<nbTS;iterTS++)
9219     {
9220       std::size_t i(0);
9221       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
9222       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
9223       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
9224         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
9225       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
9226       ret->pushBackTimeStep(f1ts);
9227       ret->setDtUnit(f1ts->getDtUnit());
9228     }
9229   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
9230 }
9231
9232 /*!
9233  * \a dts and \a ftmss are expected to have same size.
9234  */
9235 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9236 {
9237   if(fmtss.empty())
9238     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
9239   std::size_t sz(fmtss.size());
9240   std::vector<const MEDFileFieldMultiTS *> fmtss1;
9241   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
9242   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9243     {
9244       if(!(*it))
9245         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
9246       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
9247       if(elt1)
9248         {
9249           fmtss1.push_back(elt1);
9250           continue;
9251         }
9252       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
9253       if(elt2)
9254         {
9255           fmtss2.push_back(elt2);
9256           continue;
9257         }
9258       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
9259     }
9260   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
9261     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
9262   if(fmtss1.size()==sz)
9263     return AggregateHelperFMTS<double>(fmtss1,dts);
9264   if(fmtss2.size()!=sz)
9265     return AggregateHelperFMTS<int>(fmtss2,dts);
9266   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9267 }
9268
9269 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9270 {
9271   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9272 }
9273
9274 //= MEDFileFieldMultiTS
9275
9276 /*!
9277  * Returns a new empty instance of MEDFileFieldMultiTS.
9278  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9279  *          is to delete this field using decrRef() as it is no more needed.
9280  */
9281 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9282 {
9283   return new MEDFileFieldMultiTS;
9284 }
9285
9286 /*!
9287  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9288  * that has been read from a specified MED file.
9289  *  \param [in] fileName - the name of the MED file to read.
9290  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9291  *          is to delete this field using decrRef() as it is no more needed.
9292  *  \throw If reading the file fails.
9293  */
9294 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9295 {
9296   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9297   return New(fid,loadAll);
9298 }
9299
9300 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, bool loadAll)
9301 {
9302   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,loadAll,0));
9303   ret->contentNotNull();//to check that content type matches with \a this type.
9304   return ret.retn();
9305 }
9306
9307 /*!
9308  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9309  * that has been read from a specified MED file.
9310  *  \param [in] fileName - the name of the MED file to read.
9311  *  \param [in] fieldName - the name of the field to read.
9312  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9313  *          is to delete this field using decrRef() as it is no more needed.
9314  *  \throw If reading the file fails.
9315  *  \throw If there is no field named \a fieldName in the file.
9316  */
9317 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9318 {
9319   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9320   return New(fid,fieldName,loadAll);
9321 }
9322
9323 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9324 {
9325   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0));
9326   ret->contentNotNull();//to check that content type matches with \a this type.
9327   return ret.retn();
9328 }
9329
9330 /*!
9331  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9332  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9333  *
9334  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9335  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9336  * \warning this is a shallow copy constructor
9337  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9338  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9339  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9340  *          is to delete this field using decrRef() as it is no more needed.
9341  */
9342 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9343 {
9344   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9345 }
9346
9347 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9348 {
9349   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9350   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9351   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0,ent));
9352   ret->contentNotNull();//to check that content type matches with \a this type.
9353   return ret.retn();
9354 }
9355
9356 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9357 {
9358   return new MEDFileFieldMultiTS(*this);
9359 }
9360
9361 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9362 {
9363   if(!f1ts)
9364     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9365   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9366   if(!f1tsC)
9367     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9368 }
9369
9370 /*!
9371  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9372  * following the given input policy.
9373  *
9374  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9375  *                            By default (true) the globals are deeply copied.
9376  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9377  */
9378 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9379 {
9380   MCAuto<MEDFileIntFieldMultiTS> ret;
9381   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9382   if(content)
9383     {
9384       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9385       if(!contc)
9386         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9387       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9388       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
9389     }
9390   else
9391     ret=MEDFileIntFieldMultiTS::New();
9392   if(isDeepCpyGlobs)
9393     ret->deepCpyGlobs(*this);
9394   else
9395     ret->shallowCpyGlobs(*this);
9396   return ret.retn();
9397 }
9398
9399 /*!
9400  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9401  *  \param [in] pos - a time step id.
9402  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9403  *          delete this field using decrRef() as it is no more needed.
9404  *  \throw If \a pos is not a valid time step id.
9405  */
9406 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9407 {
9408   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9409   if(!item)
9410     {
9411       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9412       throw INTERP_KERNEL::Exception(oss.str());
9413     }
9414   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9415   if(itemC)
9416     {
9417       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9418       ret->shallowCpyGlobs(*this);
9419       return ret.retn();
9420     }
9421   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9422   throw INTERP_KERNEL::Exception(oss.str());
9423 }
9424
9425 /*!
9426  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9427  * mesh entities of a given dimension of the first mesh in MED file.
9428  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9429  *  \param [in] type - a spatial discretization of interest.
9430  *  \param [in] iteration - the iteration number of a required time step.
9431  *  \param [in] order - the iteration order number of required time step.
9432  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9433  *  \param [in] renumPol - specifies how to permute values of the result field according to
9434  *          the optional numbers of cells and nodes, if any. The valid values are
9435  *          - 0 - do not permute.
9436  *          - 1 - permute cells.
9437  *          - 2 - permute nodes.
9438  *          - 3 - permute cells and nodes.
9439  *
9440  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9441  *          caller is to delete this field using decrRef() as it is no more needed. 
9442  *  \throw If the MED file is not readable.
9443  *  \throw If there is no mesh in the MED file.
9444  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9445  *  \throw If no field values of the required parameters are available.
9446  */
9447 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9448 {
9449   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9450   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9451   if(!myF1TSC)
9452     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9453   MCAuto<DataArray> arrOut;
9454   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9455   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9456   return ret.retn();
9457 }
9458
9459 /*!
9460  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9461  * the top level cells of the first mesh in MED file.
9462  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9463  *  \param [in] type - a spatial discretization of interest.
9464  *  \param [in] iteration - the iteration number of a required time step.
9465  *  \param [in] order - the iteration order number of required time step.
9466  *  \param [in] renumPol - specifies how to permute values of the result field according to
9467  *          the optional numbers of cells and nodes, if any. The valid values are
9468  *          - 0 - do not permute.
9469  *          - 1 - permute cells.
9470  *          - 2 - permute nodes.
9471  *          - 3 - permute cells and nodes.
9472  *
9473  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9474  *          caller is to delete this field using decrRef() as it is no more needed. 
9475  *  \throw If the MED file is not readable.
9476  *  \throw If there is no mesh in the MED file.
9477  *  \throw If no field values of the required parameters are available.
9478  */
9479 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9480 {
9481   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9482   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9483   if(!myF1TSC)
9484     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9485   MCAuto<DataArray> arrOut;
9486   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9487   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9488   return ret.retn();
9489 }
9490
9491 /*!
9492  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
9493  * method should be called (getFieldOnMeshAtLevel for example).
9494  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9495  *
9496  * \param [in] iteration - the iteration number of a required time step.
9497  * \param [in] order - the iteration order number of required time step.
9498  * \param [in] mesh - the mesh the field is lying on
9499  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9500  *          caller is to delete this field using decrRef() as it is no more needed. 
9501  */
9502 MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9503 {
9504   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9505   MCAuto<DataArray> arrOut;
9506   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9507   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9508   return ret.retn();
9509 }
9510
9511 /*!
9512  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9513  * a given support.
9514  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9515  *  \param [in] type - a spatial discretization of interest.
9516  *  \param [in] iteration - the iteration number of a required time step.
9517  *  \param [in] order - the iteration order number of required time step.
9518  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9519  *  \param [in] mesh - the supporting mesh.
9520  *  \param [in] renumPol - specifies how to permute values of the result field according to
9521  *          the optional numbers of cells and nodes, if any. The valid values are
9522  *          - 0 - do not permute.
9523  *          - 1 - permute cells.
9524  *          - 2 - permute nodes.
9525  *          - 3 - permute cells and nodes.
9526  *
9527  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9528  *          caller is to delete this field using decrRef() as it is no more needed. 
9529  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9530  *  \throw If no field of \a this is lying on \a mesh.
9531  *  \throw If no field values of the required parameters are available.
9532  */
9533 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9534 {
9535   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9536   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9537   if(!myF1TSC)
9538     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9539   MCAuto<DataArray> arrOut;
9540   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9541   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9542   return ret.retn();
9543 }
9544
9545 /*!
9546  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9547  * given support. 
9548  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9549  *  \param [in] type - a spatial discretization of the new field.
9550  *  \param [in] iteration - the iteration number of a required time step.
9551  *  \param [in] order - the iteration order number of required time step.
9552  *  \param [in] mesh - the supporting mesh.
9553  *  \param [in] renumPol - specifies how to permute values of the result field according to
9554  *          the optional numbers of cells and nodes, if any. The valid values are
9555  *          - 0 - do not permute.
9556  *          - 1 - permute cells.
9557  *          - 2 - permute nodes.
9558  *          - 3 - permute cells and nodes.
9559  *
9560  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9561  *          caller is to delete this field using decrRef() as it is no more needed. 
9562  *  \throw If no field of \a this is lying on \a mesh.
9563  *  \throw If no field values of the required parameters are available.
9564  */
9565 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9566 {
9567   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9568   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9569   if(!myF1TSC)
9570     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9571   MCAuto<DataArray> arrOut;
9572   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9573   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9574   return ret.retn();
9575 }
9576
9577 /*!
9578  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9579  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9580  * This method is useful for MED2 file format when field on different mesh was autorized.
9581  */
9582 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9583 {
9584   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9585   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9586   if(!myF1TSC)
9587     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9588   MCAuto<DataArray> arrOut;
9589   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9590   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9591   return ret.retn();
9592 }
9593
9594 /*!
9595  * Returns values and a profile of the field of a given type, of a given time step,
9596  * lying on a given support.
9597  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9598  *  \param [in] type - a spatial discretization of the field.
9599  *  \param [in] iteration - the iteration number of a required time step.
9600  *  \param [in] order - the iteration order number of required time step.
9601  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9602  *  \param [in] mesh - the supporting mesh.
9603  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9604  *          field of interest lies on. If the field lies on all entities of the given
9605  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9606  *          using decrRef() as it is no more needed.  
9607  *  \param [in] glob - the global data storing profiles and localization.
9608  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9609  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9610  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9611  *  \throw If no field of \a this is lying on \a mesh.
9612  *  \throw If no field values of the required parameters are available.
9613  */
9614 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9615 {
9616   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9617   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9618   if(!myF1TSC)
9619     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9620   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9621   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9622 }
9623
9624 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9625 {
9626   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9627   if(!pt)
9628     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9629   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9630   if(!ret)
9631     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 !");
9632   return ret;
9633 }
9634
9635 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9636 {
9637   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9638   if(!pt)
9639     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9640   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9641   if(!ret)
9642     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 !");
9643   return ret;
9644 }
9645
9646 /*!
9647  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9648  * the given field is checked if its elements are sorted suitable for writing to MED file
9649  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9650  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9651  *  \param [in] field - the field to add to \a this.
9652  *  \throw If the name of \a field is empty.
9653  *  \throw If the data array of \a field is not set.
9654  *  \throw If existing time steps have different name or number of components than \a field.
9655  *  \throw If the underlying mesh of \a field has no name.
9656  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9657  */
9658 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9659 {
9660   const DataArrayDouble *arr=0;
9661   if(field)
9662     arr=field->getArray();
9663   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9664 }
9665
9666 /*!
9667  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9668  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9669  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9670  * and \a profile.
9671  *
9672  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9673  * A new profile is added only if no equal profile is missing.
9674  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9675  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9676  *  \param [in] mesh - the supporting mesh of \a field.
9677  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9678  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9679  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9680  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9681  *  \throw If the data array of \a field is not set.
9682  *  \throw If the data array of \a this is already allocated but has different number of
9683  *         components than \a field.
9684  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9685  *  \sa setFieldNoProfileSBT()
9686  */
9687 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9688 {
9689   const DataArrayDouble *arr=0;
9690   if(field)
9691     arr=field->getArray();
9692   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9693 }
9694
9695 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9696 {
9697   _content=new MEDFileFieldMultiTSWithoutSDA;
9698 }
9699
9700 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
9701 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
9702 {
9703 }
9704 catch(INTERP_KERNEL::Exception& e)
9705 { throw e; }
9706
9707 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
9708 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
9709 {
9710 }
9711 catch(INTERP_KERNEL::Exception& e)
9712 { throw e; }
9713
9714 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9715 {
9716 }
9717
9718 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
9719 {
9720   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9721 }
9722
9723 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9724 {
9725   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9726 }
9727
9728 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9729 {
9730   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9731 }
9732
9733 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
9734 {
9735   return MEDFileFieldMultiTS::New();
9736 }
9737
9738 //= MEDFileAnyTypeFieldMultiTSIterator
9739
9740 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9741 {
9742   if(fmts)
9743     {
9744       fmts->incrRef();
9745       _nb_iter=fmts->getNumberOfTS();
9746     }
9747 }
9748
9749 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9750 {
9751 }
9752
9753 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9754 {
9755   if(_iter_id<_nb_iter)
9756     {
9757       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9758       if(fmts)
9759         return fmts->getTimeStepAtPos(_iter_id++);
9760       else
9761         return 0;
9762     }
9763   else
9764     return 0;
9765 }
9766
9767 //= MEDFileIntFieldMultiTS
9768
9769 /*!
9770  * Returns a new empty instance of MEDFileFieldMultiTS.
9771  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9772  *          is to delete this field using decrRef() as it is no more needed.
9773  */
9774 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9775 {
9776   return new MEDFileIntFieldMultiTS;
9777 }
9778
9779 /*!
9780  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9781  * that has been read from a specified MED file.
9782  *  \param [in] fileName - the name of the MED file to read.
9783  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9784  *          is to delete this field using decrRef() as it is no more needed.
9785  *  \throw If reading the file fails.
9786  */
9787 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9788 {
9789   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9790   return New(fid,loadAll);
9791 }
9792
9793 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, bool loadAll)
9794 {
9795   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,loadAll,0));
9796   ret->contentNotNull();//to check that content type matches with \a this type.
9797   return ret.retn();
9798 }
9799
9800 /*!
9801  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9802  * that has been read from a specified MED file.
9803  *  \param [in] fileName - the name of the MED file to read.
9804  *  \param [in] fieldName - the name of the field to read.
9805  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9806  *          is to delete this field using decrRef() as it is no more needed.
9807  *  \throw If reading the file fails.
9808  *  \throw If there is no field named \a fieldName in the file.
9809  */
9810 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9811 {
9812   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9813   return New(fid,fieldName,loadAll);
9814 }
9815
9816 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9817 {
9818   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0));
9819   ret->contentNotNull();//to check that content type matches with \a this type.
9820   return ret.retn();
9821 }
9822
9823 /*!
9824  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9825  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9826  *
9827  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9828  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9829  * \warning this is a shallow copy constructor
9830  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9831  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9832  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9833  *          is to delete this field using decrRef() as it is no more needed.
9834  */
9835 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9836 {
9837   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9838 }
9839
9840 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9841 {
9842   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9843   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9844   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0,ent));
9845   ret->contentNotNull();//to check that content type matches with \a this type.
9846   return ret.retn();
9847 }
9848
9849 /*!
9850  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9851  * following the given input policy.
9852  *
9853  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9854  *                            By default (true) the globals are deeply copied.
9855  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9856  */
9857 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9858 {
9859   MCAuto<MEDFileFieldMultiTS> ret;
9860   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9861   if(content)
9862     {
9863       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9864       if(!contc)
9865         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9866       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9867       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
9868     }
9869   else
9870     ret=MEDFileFieldMultiTS::New();
9871   if(isDeepCpyGlobs)
9872     ret->deepCpyGlobs(*this);
9873   else
9874     ret->shallowCpyGlobs(*this);
9875   return ret.retn();
9876 }
9877
9878 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9879 {
9880   return new MEDFileIntFieldMultiTS(*this);
9881 }
9882
9883 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9884 {
9885   if(!f1ts)
9886     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9887   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9888   if(!f1tsC)
9889     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9890 }
9891
9892 /*!
9893  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
9894  * method should be called (getFieldOnMeshAtLevel for example).
9895  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9896  *
9897  * \param [in] iteration - the iteration number of a required time step.
9898  * \param [in] order - the iteration order number of required time step.
9899  * \param [in] mesh - the mesh the field is lying on
9900  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
9901  *          caller is to delete this field using decrRef() as it is no more needed. 
9902  */
9903 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9904 {
9905   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9906   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9907   if(!myF1TSC)
9908     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
9909   MCAuto<DataArray> arrOut;
9910   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9911   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
9912   return ret2.retn();
9913 }
9914
9915 /*!
9916  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9917  * mesh entities of a given dimension of the first mesh in MED file.
9918  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9919  *  \param [in] type - a spatial discretization of interest.
9920  *  \param [in] iteration - the iteration number of a required time step.
9921  *  \param [in] order - the iteration order number of required time step.
9922  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9923  *  \param [in] renumPol - specifies how to permute values of the result field according to
9924  *          the optional numbers of cells and nodes, if any. The valid values are
9925  *          - 0 - do not permute.
9926  *          - 1 - permute cells.
9927  *          - 2 - permute nodes.
9928  *          - 3 - permute cells and nodes.
9929  *
9930  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9931  *          caller is to delete this field using decrRef() as it is no more needed. 
9932  *  \throw If the MED file is not readable.
9933  *  \throw If there is no mesh in the MED file.
9934  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9935  *  \throw If no field values of the required parameters are available.
9936  */
9937 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9938 {
9939   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9940   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9941   if(!myF1TSC)
9942     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9943   MCAuto<DataArray> arr;
9944   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
9945   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9946   return ret2.retn();
9947 }
9948
9949 /*!
9950  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9951  * the top level cells of the first mesh in MED file.
9952  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9953  *  \param [in] type - a spatial discretization of interest.
9954  *  \param [in] iteration - the iteration number of a required time step.
9955  *  \param [in] order - the iteration order number of required time step.
9956  *  \param [in] renumPol - specifies how to permute values of the result field according to
9957  *          the optional numbers of cells and nodes, if any. The valid values are
9958  *          - 0 - do not permute.
9959  *          - 1 - permute cells.
9960  *          - 2 - permute nodes.
9961  *          - 3 - permute cells and nodes.
9962  *
9963  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9964  *          caller is to delete this field using decrRef() as it is no more needed. 
9965  *  \throw If the MED file is not readable.
9966  *  \throw If there is no mesh in the MED file.
9967  *  \throw If no field values of the required parameters are available.
9968  */
9969 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9970 {
9971   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9972   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9973   if(!myF1TSC)
9974     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9975   MCAuto<DataArray> arr;
9976   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
9977   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9978   return ret2.retn();
9979 }
9980
9981 /*!
9982  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9983  * a given support.
9984  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9985  *  \param [in] type - a spatial discretization of interest.
9986  *  \param [in] iteration - the iteration number of a required time step.
9987  *  \param [in] order - the iteration order number of required time step.
9988  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9989  *  \param [in] mesh - the supporting mesh.
9990  *  \param [in] renumPol - specifies how to permute values of the result field according to
9991  *          the optional numbers of cells and nodes, if any. The valid values are
9992  *          - 0 - do not permute.
9993  *          - 1 - permute cells.
9994  *          - 2 - permute nodes.
9995  *          - 3 - permute cells and nodes.
9996  *
9997  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9998  *          caller is to delete this field using decrRef() as it is no more needed. 
9999  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10000  *  \throw If no field of \a this is lying on \a mesh.
10001  *  \throw If no field values of the required parameters are available.
10002  */
10003 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
10004 {
10005   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10006   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10007   if(!myF1TSC)
10008     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10009   MCAuto<DataArray> arr;
10010   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
10011   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10012   return ret2.retn();
10013 }
10014
10015 /*!
10016  * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
10017  * given support. 
10018  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10019  *  \param [in] type - a spatial discretization of the new field.
10020  *  \param [in] iteration - the iteration number of a required time step.
10021  *  \param [in] order - the iteration order number of required time step.
10022  *  \param [in] mesh - the supporting mesh.
10023  *  \param [out] arrOut - the DataArrayInt containing values of field.
10024  *  \param [in] renumPol - specifies how to permute values of the result field according to
10025  *          the optional numbers of cells and nodes, if any. The valid values are
10026  *          - 0 - do not permute.
10027  *          - 1 - permute cells.
10028  *          - 2 - permute nodes.
10029  *          - 3 - permute cells and nodes.
10030  *
10031  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10032  *          caller is to delete this field using decrRef() as it is no more needed. 
10033  *  \throw If no field of \a this is lying on \a mesh.
10034  *  \throw If no field values of the required parameters are available.
10035  */
10036 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
10037 {
10038   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10039   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10040   if(!myF1TSC)
10041     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10042   MCAuto<DataArray> arr;
10043   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
10044   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10045   return ret2.retn();
10046 }
10047
10048 /*!
10049  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
10050  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
10051  * This method is useful for MED2 file format when field on different mesh was autorized.
10052  */
10053 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
10054 {
10055   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10056   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10057   if(!myF1TSC)
10058     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10059   MCAuto<DataArray> arr;
10060   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
10061   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10062   return ret2.retn();
10063 }
10064
10065 /*!
10066  * Returns values and a profile of the field of a given type, of a given time step,
10067  * lying on a given support.
10068  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10069  *  \param [in] type - a spatial discretization of the field.
10070  *  \param [in] iteration - the iteration number of a required time step.
10071  *  \param [in] order - the iteration order number of required time step.
10072  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10073  *  \param [in] mesh - the supporting mesh.
10074  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
10075  *          field of interest lies on. If the field lies on all entities of the given
10076  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
10077  *          using decrRef() as it is no more needed.  
10078  *  \param [in] glob - the global data storing profiles and localization.
10079  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
10080  *          field. The caller is to delete this array using decrRef() as it is no more needed.
10081  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10082  *  \throw If no field of \a this is lying on \a mesh.
10083  *  \throw If no field values of the required parameters are available.
10084  */
10085 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
10086 {
10087   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10088   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
10089   if(!myF1TSC)
10090     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
10091   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
10092   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
10093 }
10094
10095 /*!
10096  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
10097  *  \param [in] pos - a time step id.
10098  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
10099  *          delete this field using decrRef() as it is no more needed.
10100  *  \throw If \a pos is not a valid time step id.
10101  */
10102 MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
10103 {
10104   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
10105   if(!item)
10106     {
10107       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
10108       throw INTERP_KERNEL::Exception(oss.str());
10109     }
10110   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
10111   if(itemC)
10112     {
10113       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
10114       ret->shallowCpyGlobs(*this);
10115       return ret.retn();
10116     }
10117   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
10118   throw INTERP_KERNEL::Exception(oss.str());
10119 }
10120
10121 /*!
10122  * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
10123  * the given field is checked if its elements are sorted suitable for writing to MED file
10124  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10125  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10126  *  \param [in] field - the field to add to \a this.
10127  *  \throw If the name of \a field is empty.
10128  *  \throw If the data array of \a field is not set.
10129  *  \throw If existing time steps have different name or number of components than \a field.
10130  *  \throw If the underlying mesh of \a field has no name.
10131  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10132  */
10133 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
10134 {
10135   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10136   contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
10137 }
10138
10139 /*!
10140  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
10141  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10142  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10143  * and \a profile.
10144  *
10145  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10146  * A new profile is added only if no equal profile is missing.
10147  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10148  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
10149  *  \param [in] arrOfVals - the values of the field \a field used.
10150  *  \param [in] mesh - the supporting mesh of \a field.
10151  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10152  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10153  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10154  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10155  *  \throw If the data array of \a field is not set.
10156  *  \throw If the data array of \a this is already allocated but has different number of
10157  *         components than \a field.
10158  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10159  *  \sa setFieldNoProfileSBT()
10160  */
10161 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10162 {
10163   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10164   contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
10165 }
10166
10167 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
10168 {
10169   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10170   if(!pt)
10171     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
10172   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10173   if(!ret)
10174     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 !");
10175   return ret;
10176 }
10177
10178 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
10179 {
10180   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10181   if(!pt)
10182     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
10183   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10184   if(!ret)
10185     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 !");
10186   return ret;
10187 }
10188
10189 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
10190 {
10191   _content=new MEDFileIntFieldMultiTSWithoutSDA;
10192 }
10193
10194 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10195 {
10196 }
10197
10198 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10199 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10200 {
10201 }
10202 catch(INTERP_KERNEL::Exception& e)
10203 { throw e; }
10204
10205 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10206 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10207 {
10208 }
10209 catch(INTERP_KERNEL::Exception& e)
10210 { throw e; }
10211
10212 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10213 {
10214   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10215 }
10216
10217 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
10218 {
10219   return MEDFileIntFieldMultiTS::New();
10220 }
10221
10222 //= MEDFileFields
10223
10224 MEDFileFields *MEDFileFields::New()
10225 {
10226   return new MEDFileFields;
10227 }
10228
10229 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
10230 {
10231   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10232   return New(fid,loadAll);
10233 }
10234
10235 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
10236 {
10237   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10238   return NewWithDynGT(fid,se,loadAll);
10239 }
10240
10241 MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll)
10242 {
10243   if(!se)
10244     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
10245   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
10246   return new MEDFileFields(fid,loadAll,0,entities);
10247 }
10248
10249 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
10250 {
10251   return new MEDFileFields(fid,loadAll,0,0);
10252 }
10253
10254 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10255 {
10256   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10257   return new MEDFileFields(fid,loadAll,ms,0);
10258 }
10259
10260 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10261 {
10262   MEDFileUtilities::CheckFileForRead(fileName);
10263   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10264   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10265   return new MEDFileFields(fid,loadAll,0,ent);
10266 }
10267
10268 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
10269 {
10270   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
10271   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
10272   return ret;
10273 }
10274
10275 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
10276 {
10277   std::vector<const BigMemoryObject *> ret;
10278   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10279     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
10280   return ret;
10281 }
10282
10283 MEDFileFields *MEDFileFields::deepCopy() const
10284 {
10285   MCAuto<MEDFileFields> ret(shallowCpy());
10286   std::size_t i(0);
10287   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10288     {
10289       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10290         ret->_fields[i]=(*it)->deepCopy();
10291     }
10292   ret->deepCpyGlobs(*this);
10293   return ret.retn();
10294 }
10295
10296 MEDFileFields *MEDFileFields::shallowCpy() const
10297 {
10298   return new MEDFileFields(*this);
10299 }
10300
10301 /*!
10302  * 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
10303  * 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.
10304  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
10305  *
10306  * \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.
10307  * \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.
10308  * 
10309  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10310  */
10311 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
10312 {
10313   std::set< std::pair<int,int> > s;
10314   bool firstShot=true;
10315   areThereSomeForgottenTS=false;
10316   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10317     {
10318       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10319         continue;
10320       std::vector< std::pair<int,int> > v=(*it)->getIterations();
10321       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
10322       if(firstShot)
10323         { s=s1; firstShot=false; }
10324       else
10325         {
10326           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
10327           if(s!=s2)
10328             areThereSomeForgottenTS=true;
10329           s=s2;
10330         }
10331     }
10332   std::vector< std::pair<int,int> > ret;
10333   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
10334   return ret;
10335 }
10336
10337 int MEDFileFields::getNumberOfFields() const
10338 {
10339   return _fields.size();
10340 }
10341
10342 std::vector<std::string> MEDFileFields::getFieldsNames() const
10343 {
10344   std::vector<std::string> ret(_fields.size());
10345   int i(0);
10346   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10347     {
10348       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
10349       if(f)
10350         {
10351           ret[i]=f->getName();
10352         }
10353       else
10354         {
10355           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
10356           throw INTERP_KERNEL::Exception(oss.str());
10357         }
10358     }
10359   return ret;
10360 }
10361
10362 std::vector<std::string> MEDFileFields::getMeshesNames() const
10363 {
10364   std::vector<std::string> ret;
10365   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10366     {
10367       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10368       if(cur)
10369         ret.push_back(cur->getMeshName());
10370     }
10371   return ret;
10372 }
10373
10374 std::string MEDFileFields::simpleRepr() const
10375 {
10376   std::ostringstream oss;
10377   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10378   simpleRepr(0,oss);
10379   return oss.str();
10380 }
10381
10382 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10383 {
10384   int nbOfFields(getNumberOfFields());
10385   std::string startLine(bkOffset,' ');
10386   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10387   int i=0;
10388   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10389     {
10390       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10391       if(cur)
10392         {
10393           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10394         }
10395       else
10396         {
10397           oss << startLine << "  - not defined !" << std::endl;
10398         }
10399     }
10400   i=0;
10401   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10402     {
10403       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10404       std::string chapter(17,'0'+i);
10405       oss << startLine << chapter << std::endl;
10406       if(cur)
10407         {
10408           cur->simpleRepr(bkOffset+2,oss,i);
10409         }
10410       else
10411         {
10412           oss << startLine << "  - not defined !" << std::endl;
10413         }
10414       oss << startLine << chapter << std::endl;
10415     }
10416   simpleReprGlobs(oss);
10417 }
10418
10419 MEDFileFields::MEDFileFields()
10420 {
10421 }
10422
10423 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10424 try:MEDFileFieldGlobsReal(fid)
10425 {
10426   int nbFields(MEDnField(fid));
10427   _fields.resize(nbFields);
10428   med_field_type typcha;
10429   for(int i=0;i<nbFields;i++)
10430     {
10431       std::vector<std::string> infos;
10432       std::string fieldName,dtunit;
10433       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit));
10434       switch(typcha)
10435       {
10436         case MED_FLOAT64:
10437           {
10438             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10439             break;
10440           }
10441         case MED_INT32:
10442           {
10443             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10444             break;
10445           }
10446         default:
10447           {
10448             std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << FileNameFromFID(fid) << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
10449             throw INTERP_KERNEL::Exception(oss.str());
10450           }
10451       }
10452     }
10453   loadAllGlobals(fid);
10454 }
10455 catch(INTERP_KERNEL::Exception& e)
10456 {
10457     throw e;
10458 }
10459
10460 void MEDFileFields::writeLL(med_idt fid) const
10461 {
10462   int i=0;
10463   writeGlobals(fid,*this);
10464   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10465     {
10466       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10467       if(!elt)
10468         {
10469           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10470           throw INTERP_KERNEL::Exception(oss.str());
10471         }
10472       elt->writeLL(fid,*this);
10473     }
10474 }
10475
10476 /*!
10477  * This method alloc the arrays and load potentially huge arrays contained in this field.
10478  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10479  * This method can be also called to refresh or reinit values from a file.
10480  * 
10481  * \throw If the fileName is not set or points to a non readable MED file.
10482  */
10483 void MEDFileFields::loadArrays()
10484 {
10485   if(getFileName().empty())
10486     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10487   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10488   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10489     {
10490       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10491       if(elt)
10492         elt->loadBigArraysRecursively(fid,*elt);
10493     }
10494 }
10495
10496 /*!
10497  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10498  * But once data loaded once, this method does nothing.
10499  * 
10500  * \throw If the fileName is not set or points to a non readable MED file.
10501  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10502  */
10503 void MEDFileFields::loadArraysIfNecessary()
10504 {
10505   if(!getFileName().empty())
10506     {
10507       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10508       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10509         {
10510           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10511           if(elt)
10512             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10513         }
10514     }
10515 }
10516
10517 /*!
10518  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10519  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10520  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10521  * 
10522  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10523  */
10524 void MEDFileFields::unloadArrays()
10525 {
10526   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10527     {
10528       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10529       if(elt)
10530         elt->unloadArrays();
10531     }
10532 }
10533
10534 /*!
10535  * 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.
10536  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10537  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10538  * 
10539  * \sa MEDFileFields::loadArraysIfNecessary
10540  */
10541 void MEDFileFields::unloadArraysWithoutDataLoss()
10542 {
10543   if(!getFileName().empty())
10544     unloadArrays();
10545 }
10546
10547 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10548 {
10549   std::vector<std::string> ret;
10550   std::set<std::string> ret2;
10551   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10552     {
10553       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10554       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10555         if(ret2.find(*it2)==ret2.end())
10556           {
10557             ret.push_back(*it2);
10558             ret2.insert(*it2);
10559           }
10560     }
10561   return ret;
10562 }
10563
10564 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10565 {
10566   std::vector<std::string> ret;
10567   std::set<std::string> ret2;
10568   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10569     {
10570       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10571       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10572         if(ret2.find(*it2)==ret2.end())
10573           {
10574             ret.push_back(*it2);
10575             ret2.insert(*it2);
10576           }
10577     }
10578   return ret;
10579 }
10580
10581 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10582 {
10583   std::vector<std::string> ret;
10584   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10585     {
10586       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
10587       ret.insert(ret.end(),tmp.begin(),tmp.end());
10588     }
10589   return ret;
10590 }
10591
10592 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10593 {
10594   std::vector<std::string> ret;
10595   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10596     {
10597       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10598       ret.insert(ret.end(),tmp.begin(),tmp.end());
10599     }
10600   return ret;
10601 }
10602
10603 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10604 {
10605   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10606     (*it)->changePflsRefsNamesGen2(mapOfModif);
10607 }
10608
10609 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10610 {
10611   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10612     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10613 }
10614
10615 void MEDFileFields::resize(int newSize)
10616 {
10617   _fields.resize(newSize);
10618 }
10619
10620 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10621 {
10622   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10623     pushField(*it);
10624 }
10625
10626 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10627 {
10628   if(!field)
10629     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10630   _fields.push_back(field->getContent());
10631   appendGlobs(*field,1e-12);
10632 }
10633
10634 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10635 {
10636   if(!field)
10637     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10638   if(i>=(int)_fields.size())
10639     _fields.resize(i+1);
10640   _fields[i]=field->getContent();
10641   appendGlobs(*field,1e-12);
10642 }
10643
10644 void MEDFileFields::destroyFieldAtPos(int i)
10645 {
10646   destroyFieldsAtPos(&i,&i+1);
10647 }
10648
10649 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10650 {
10651   std::vector<bool> b(_fields.size(),true);
10652   for(const int *i=startIds;i!=endIds;i++)
10653     {
10654       if(*i<0 || *i>=(int)_fields.size())
10655         {
10656           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10657           throw INTERP_KERNEL::Exception(oss.str());
10658         }
10659       b[*i]=false;
10660     }
10661   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10662   std::size_t j=0;
10663   for(std::size_t i=0;i<_fields.size();i++)
10664     if(b[i])
10665       fields[j++]=_fields[i];
10666   _fields=fields;
10667 }
10668
10669 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10670 {
10671   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10672   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
10673   std::vector<bool> b(_fields.size(),true);
10674   int k=bg;
10675   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10676     {
10677       if(k<0 || k>=(int)_fields.size())
10678         {
10679           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10680           throw INTERP_KERNEL::Exception(oss.str());
10681         }
10682       b[k]=false;
10683     }
10684   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10685   std::size_t j(0);
10686   for(std::size_t i=0;i<_fields.size();i++)
10687     if(b[i])
10688       fields[j++]=_fields[i];
10689   _fields=fields;
10690 }
10691
10692 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10693 {
10694   bool ret(false);
10695   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10696     {
10697       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10698       if(cur)
10699         ret=cur->changeMeshNames(modifTab) || ret;
10700     }
10701   return ret;
10702 }
10703
10704 /*!
10705  * \param [in] meshName the name of the mesh that will be renumbered.
10706  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10707  *             This code corresponds to the distribution of types in the corresponding mesh.
10708  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10709  * \param [in] renumO2N the old to new renumber array.
10710  * \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 
10711  *         field in \a this.
10712  */
10713 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10714 {
10715   bool ret(false);
10716   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10717     {
10718       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10719       if(fmts)
10720         {
10721           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10722         }
10723     }
10724   return ret;
10725 }
10726
10727 /*!
10728  * Return an extraction of \a this using \a extractDef map to specify the extraction.
10729  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
10730  *
10731  * \return A new object that the caller is responsible to deallocate.
10732  */
10733 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
10734 {
10735   if(!mm)
10736     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
10737   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
10738   int nbFields(getNumberOfFields());
10739   for(int i=0;i<nbFields;i++)
10740     {
10741       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
10742       if(!fmts)
10743         {
10744           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
10745           throw INTERP_KERNEL::Exception(oss.str());
10746         }
10747       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
10748       fsOut->pushField(fmtsOut);
10749     }
10750   return fsOut.retn();
10751 }
10752
10753 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10754 {
10755   if(i<0 || i>=(int)_fields.size())
10756     {
10757       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10758       throw INTERP_KERNEL::Exception(oss.str());
10759     }
10760   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10761   if(!fmts)
10762     return 0;
10763   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
10764   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
10765   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
10766   if(fmtsC)
10767     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10768   else if(fmtsC2)
10769     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10770   else
10771     {
10772       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10773       throw INTERP_KERNEL::Exception(oss.str());
10774     }
10775   ret->shallowCpyGlobs(*this);
10776   return ret.retn();
10777 }
10778
10779 /*!
10780  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10781  * This method is accessible in python using __getitem__ with a list in input.
10782  * \return a new object that the caller should deal with.
10783  */
10784 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10785 {
10786   MCAuto<MEDFileFields> ret=shallowCpy();
10787   std::size_t sz=std::distance(startIds,endIds);
10788   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10789   int j=0;
10790   for(const int *i=startIds;i!=endIds;i++,j++)
10791     {
10792       if(*i<0 || *i>=(int)_fields.size())
10793         {
10794           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10795           throw INTERP_KERNEL::Exception(oss.str());
10796         }
10797       fields[j]=_fields[*i];
10798     }
10799   ret->_fields=fields;
10800   return ret.retn();
10801 }
10802
10803 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10804 {
10805   return getFieldAtPos(getPosFromFieldName(fieldName));
10806 }
10807
10808 /*!
10809  * This method removes, if any, fields in \a this having no time steps.
10810  * 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.
10811  * 
10812  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10813  */
10814 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10815 {
10816   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10817   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10818     {
10819       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10820       if(elt)
10821         {
10822           if(elt->getNumberOfTS()>0)
10823             newFields.push_back(*it);
10824         }
10825     }
10826   if(_fields.size()==newFields.size())
10827     return false;
10828   _fields=newFields;
10829   return true;
10830 }
10831
10832 /*!
10833  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10834  * This method can be seen as a filter applied on \a this, that returns an object containing
10835  * 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
10836  * shallow copied from \a this.
10837  * 
10838  * \param [in] meshName - the name of the mesh on w
10839  * \return a new object that the caller should deal with.
10840  */
10841 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10842 {
10843   MCAuto<MEDFileFields> ret(MEDFileFields::New());
10844   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10845     {
10846       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10847       if(!cur)
10848         continue;
10849       if(cur->getMeshName()==meshName)
10850         {
10851           cur->incrRef();
10852           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10853           ret->_fields.push_back(cur2);
10854         }
10855     }
10856   ret->shallowCpyOnlyUsedGlobs(*this);
10857   return ret.retn();
10858 }
10859
10860 /*!
10861  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10862  * Input time steps are specified using a pair of integer (iteration, order).
10863  * 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,
10864  * but for each multitimestep only the time steps in \a timeSteps are kept.
10865  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10866  * 
10867  * The returned object points to shallow copy of elements in \a this.
10868  * 
10869  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10870  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10871  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10872  */
10873 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10874 {
10875   MCAuto<MEDFileFields> ret(MEDFileFields::New());
10876   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10877     {
10878       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10879       if(!cur)
10880         continue;
10881       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10882       ret->_fields.push_back(elt);
10883     }
10884   ret->shallowCpyOnlyUsedGlobs(*this);
10885   return ret.retn();
10886 }
10887
10888 /*!
10889  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10890  */
10891 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10892 {
10893   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10894   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10895     {
10896       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10897       if(!cur)
10898         continue;
10899       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10900       if(elt->getNumberOfTS()!=0)
10901         ret->_fields.push_back(elt);
10902     }
10903   ret->shallowCpyOnlyUsedGlobs(*this);
10904   return ret.retn();
10905 }
10906
10907 MEDFileFieldsIterator *MEDFileFields::iterator()
10908 {
10909   return new MEDFileFieldsIterator(this);
10910 }
10911
10912 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10913 {
10914   std::string tmp(fieldName);
10915   std::vector<std::string> poss;
10916   for(std::size_t i=0;i<_fields.size();i++)
10917     {
10918       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
10919       if(f)
10920         {
10921           std::string fname(f->getName());
10922           if(tmp==fname)
10923             return i;
10924           else
10925             poss.push_back(fname);
10926         }
10927     }
10928   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10929   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10930   oss << " !";
10931   throw INTERP_KERNEL::Exception(oss.str());
10932 }
10933
10934 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10935 {
10936   if(fs)
10937     {
10938       fs->incrRef();
10939       _nb_iter=fs->getNumberOfFields();
10940     }
10941 }
10942
10943 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10944 {
10945 }
10946
10947 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10948 {
10949   if(_iter_id<_nb_iter)
10950     {
10951       MEDFileFields *fs(_fs);
10952       if(fs)
10953         return fs->getFieldAtPos(_iter_id++);
10954       else
10955         return 0;
10956     }
10957   else
10958     return 0;
10959 }