Salome HOME
bbb30fc38a7510a4d2bb47248788d7a12db1ed92
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileUtilities.hxx"
25 #include "MEDFileSafeCaller.txx"
26 #include "MEDFileFieldOverView.hxx"
27
28 #include "MEDCouplingFieldDouble.hxx"
29 #include "MEDCouplingFieldDiscretization.hxx"
30
31 #include "InterpKernelAutoPtr.hxx"
32 #include "CellModel.hxx"
33
34 #include <algorithm>
35 #include <iterator>
36
37 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
38 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
39 extern med_geometry_type typmainoeud[1];
40 extern med_geometry_type typmai3[34];
41
42 using namespace MEDCoupling;
43
44 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
45 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
46
47 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
48 {
49   return new MEDFileFieldLoc(fid,locName);
50 }
51
52 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
53 {
54   return new MEDFileFieldLoc(fid,id);
55 }
56
57 MEDFileFieldLoc *MEDFileFieldLoc::New(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
58 {
59   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
60 }
61
62 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
63 {
64   med_geometry_type geotype;
65   med_geometry_type sectiongeotype;
66   int nsectionmeshcell;
67   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
68   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
69   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
70   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
71   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
72   _nb_node_per_cell=cm.getNumberOfNodes();
73   _ref_coo.resize(_dim*_nb_node_per_cell);
74   _gs_coo.resize(_dim*_nb_gauss_pt);
75   _w.resize(_nb_gauss_pt);
76   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
77 }
78
79 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
80 {
81   med_geometry_type geotype;
82   med_geometry_type sectiongeotype;
83   int nsectionmeshcell;
84   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
85   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
86   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
87   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
88   _name=locName;
89   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
90   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
91   _nb_node_per_cell=cm.getNumberOfNodes();
92   _ref_coo.resize(_dim*_nb_node_per_cell);
93   _gs_coo.resize(_dim*_nb_gauss_pt);
94   _w.resize(_nb_gauss_pt);
95   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
96 }
97
98 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
99                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_geo_type(geoType),_ref_coo(refCoo),_gs_coo(gsCoo),
100                                      _w(w)
101 {
102   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
103   _dim=cm.getDimension();
104   _nb_node_per_cell=cm.getNumberOfNodes();
105   _nb_gauss_pt=_w.size();
106 }
107
108 MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const
109 {
110   return new MEDFileFieldLoc(*this);
111 }
112
113 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
114 {
115   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
116 }
117
118 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
119 {
120   return std::vector<const BigMemoryObject *>();
121 }
122
123 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
124 {
125   static const char OFF7[]="\n    ";
126   oss << "\"" << _name << "\"" << OFF7;
127   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
128   oss << "Dimension=" << _dim << OFF7;
129   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
130   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
131   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
132   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
133   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
134 }
135
136 void MEDFileFieldLoc::setName(const std::string& name)
137 {
138   _name=name;
139 }
140
141 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
142 {
143   if(_name!=other._name)
144     return false;
145   if(_dim!=other._dim)
146     return false;
147   if(_nb_gauss_pt!=other._nb_gauss_pt)
148     return false;
149   if(_nb_node_per_cell!=other._nb_node_per_cell)
150     return false;
151   if(_geo_type!=other._geo_type)
152     return false;
153   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
154     return false;
155   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
156     return false;
157   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
158     return false;
159
160   return true;
161 }
162
163 void MEDFileFieldLoc::writeLL(med_idt fid) const
164 {
165   MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)_geo_type],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT);
166 }
167
168 std::string MEDFileFieldLoc::repr() const
169 {
170   std::ostringstream oss; oss.precision(15);
171   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
172   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
173   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
174   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
175   oss << "\n  - Ref coords are : ";
176   int sz=_ref_coo.size();
177   if(sz%_dim==0)
178     {
179       int nbOfTuples=sz/_dim;
180       for(int i=0;i<nbOfTuples;i++)
181         {
182           oss << "(";
183           for(int j=0;j<_dim;j++)
184             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
185           oss << ") ";
186         }
187     }
188   else
189     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
190   oss << "\n  - Gauss coords in reference element : ";
191   sz=_gs_coo.size();
192   if(sz%_dim==0)
193     {
194       int nbOfTuples=sz/_dim;
195       for(int i=0;i<nbOfTuples;i++)
196         {
197           oss << "(";
198           for(int j=0;j<_dim;j++)
199             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
200           oss << ") ";
201         }
202     }
203   else
204     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
205   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
206   return oss.str();
207 }
208
209 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
210 {
211   _type=field->getTypeOfField();
212   _start=start;
213   switch(_type)
214   {
215     case ON_CELLS:
216       {
217         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,offset,offset+nbOfCells,1);
218         _end=_start+nbOfCells;
219         _nval=nbOfCells;
220         break;
221       }
222     case ON_GAUSS_NE:
223       {
224         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
225         const int *arrPtr=arr->getConstPointer();
226         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
227         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
228         _nval=nbOfCells;
229         break;
230       }
231     case ON_GAUSS_PT:
232       {
233         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
234         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
235         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
236         if(!disc2)
237           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
238         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
239         MCAuto<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
240         const int *dai2Ptr=dai2->getConstPointer();
241         int nbi=gsLoc.getWeights().size();
242         MCAuto<DataArrayInt> da2=dai->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
243         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
244         const int *da3Ptr=da3->getConstPointer();
245         if(da3->getNumberOfTuples()!=nbOfCells)
246           {//profile : for gauss even in NoProfile !!!
247             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
248             _profile=oss.str();
249             da3->setName(_profile.c_str());
250             glob.appendProfile(da3);
251           }
252         MCAuto<DataArrayInt> da4=DataArrayInt::New();
253         _nval=da3->getNbOfElems();
254         da4->alloc(_nval*nbi,1);
255         int *da4Ptr=da4->getPointer();
256         for(int i=0;i<_nval;i++)
257           {
258             int ref=dai2Ptr[offset+da3Ptr[i]];
259             for(int j=0;j<nbi;j++)
260               *da4Ptr++=ref+j;
261           }
262         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
263         _localization=oss2.str();
264         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
265         _end=_start+_nval*nbi;
266         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
267         break;
268       }
269     default:
270       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
271   }
272   start=_end;
273 }
274
275 /*!
276  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
277  * \param [in] pflName input containing name of profile if any. 0 if no profile (except for GAUSS_PT where a no profile can hide a profile when splitted by loc_id).
278  * \param [in] multiTypePfl is the end user profile specified in high level API
279  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
280  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
281  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
282  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
283  */
284 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
285 {
286   _profile.clear();
287   _type=field->getTypeOfField();
288   std::string pflName(multiTypePfl->getName());
289   std::ostringstream oss; oss << pflName;
290   if(_type!=ON_NODES)
291     {
292       if(!isPflAlone)
293         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
294     }
295   else
296     { oss << "_NODE"; }
297   if(locIds)
298     {
299       if(pflName.empty())
300         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
301       if(_type!=ON_GAUSS_PT)
302         {
303           locIds->setName(oss.str().c_str());
304           glob.appendProfile(locIds);
305           _profile=oss.str();
306         }
307     }
308   _start=start;
309   switch(_type)
310   {
311     case ON_NODES:
312       {
313         _nval=idsInPfl->getNumberOfTuples();
314         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,arrr->getNumberOfTuples(),1);
315         _end=_start+_nval;
316         break;
317       }
318     case ON_CELLS:
319       {
320         _nval=idsInPfl->getNumberOfTuples();
321         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
322         _end=_start+_nval;
323         break;
324       }
325     case ON_GAUSS_NE:
326       {
327         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
328         MCAuto<DataArrayInt> arr2=arr->deltaShiftIndex();
329         MCAuto<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
330         arr3->computeOffsetsFull();
331         MCAuto<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
332         int trueNval=tmp->getNumberOfTuples();
333         _nval=idsInPfl->getNumberOfTuples();
334         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
335         _end=_start+trueNval;
336         break;
337       }
338     case ON_GAUSS_PT:
339       {
340         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
341         if(!disc2)
342           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
343         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
344         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
345         MCAuto<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
346         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
347         MCAuto<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
348         //
349         MCAuto<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
350         MCAuto<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
351         //
352         MCAuto<DataArrayInt> tmp=DataArrayInt::New();
353         int trueNval=0;
354         for(const int *pt=da4->begin();pt!=da4->end();pt++)
355           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
356         tmp->alloc(trueNval,1);
357         int *tmpPtr=tmp->getPointer();
358         for(const int *pt=da4->begin();pt!=da4->end();pt++)
359           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
360             *tmpPtr++=j;
361         //
362         _nval=da4->getNumberOfTuples();
363         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
364         _end=_start+trueNval;
365         oss << "_loc_" << _loc_id;
366         if(locIds)
367           {
368             MCAuto<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
369             da5->setName(oss.str().c_str());
370             glob.appendProfile(da5);
371             _profile=oss.str();
372           }
373         else
374           {
375             if(!da3->isIota(nbOfEltsInWholeMesh))
376               {
377                 da3->setName(oss.str().c_str());
378                 glob.appendProfile(da3);
379                 _profile=oss.str();
380               }
381           }
382         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
383         _localization=oss2.str();
384         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
385         break;
386       }
387     default:
388       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
389   }
390   start=_end;
391 }
392
393 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
394 {
395   _start=start;
396   _nval=arrr->getNumberOfTuples();
397   getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,_nval,1);
398   _end=_start+_nval;
399   start=_end;
400 }
401
402 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
403 {
404   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
405 }
406
407 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
408 {
409   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
410 }
411
412 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
413 {
414   return new MEDFileFieldPerMeshPerTypePerDisc(other);
415 }
416
417 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
418 {
419   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
420 }
421
422 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
423 {
424   std::vector<const BigMemoryObject *> ret(1);
425   ret[0]=(const PartDefinition*)_pd;
426   return ret;
427 }
428
429 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerType *father) const
430 {
431   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
432   ret->_father=father;
433   return ret.retn();
434 }
435
436 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
437 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
438 {
439   if(pd)
440     pd->incrRef();
441 }
442 catch(INTERP_KERNEL::Exception& e)
443 {
444     throw e;
445 }
446
447 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
448 {
449 }
450
451 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& other):RefCountObject(other),_type(other._type),_father(0),_start(other._start),_end(other._end),_nval(other._nval),_profile(other._profile),_localization(other._localization),_loc_id(other._loc_id),_profile_it(other._profile_it),_pd(other._pd),_tmp_work1(other._tmp_work1)
452 {
453 }
454
455 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
456     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
457 {
458 }
459
460 void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const std::string& fieldName, int nbOfCompo, int iteration, int order, med_entity_type menti, med_geometry_type mgeoti, unsigned char *startFeedingPtr)
461 {
462   const PartDefinition *pd(_pd);
463   if(!pd)
464     {
465       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
466       int nbi,tmp1;
467       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
468       if(_end-_start!=nbValsInFile*nbi)
469         {
470           std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
471           throw INTERP_KERNEL::Exception(oss.str().c_str());
472         }
473       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
474     }
475   else
476     {
477       if(!_profile.empty())
478         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
479       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
480       int profilesize,nbi;
481       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
482       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
483       if(spd)
484         {
485           int start,stop,step;
486           spd->getSlice(start,stop,step);
487           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
488           med_filter filter=MED_FILTER_INIT;
489           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
490                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
491                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
492                                    /*lastblocksize=useless because count=1*/0,&filter);
493           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
494           MEDfilterClose(&filter);
495           return ;
496         }
497       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
498       if(dpd)
499         {
500           dpd->checkConsistencyLight();
501           MCAuto<DataArrayInt> myIds(dpd->toDAI());
502           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
503           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
504           myIds->applyLin(1,-a);
505           int nbOfEltsToLoad(b-a+1);
506           med_filter filter=MED_FILTER_INIT;
507           {//TODO : manage int32 !
508             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
509             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
510             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
511                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
512                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
513                                      /*lastblocksize=useless because count=1*/0,&filter);
514             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
515             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
516             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
517             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
518           }
519           MEDfilterClose(&filter);
520         }
521       else
522         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
523     }
524 }
525
526 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
527 {
528   return _father;
529 }
530
531 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
532 {
533   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
534   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
535   std::string fieldName(nasc.getName()),meshName(getMeshName());
536   int iteration(getIteration()),order(getOrder());
537   TypeOfField type(getType());
538   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
539   int profilesize,nbi;
540   med_geometry_type mgeoti;
541   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
542   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
543   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
544   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
545   const PartDefinition *pd(_pd);
546   if(!pd)
547     {
548       _nval=zeNVal;
549     }
550   else
551     {
552       if(!_profile.empty())
553         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
554       _nval=pd->getNumberOfElems();
555     }
556   _start=start;
557   _end=start+_nval*nbi;
558   start=_end;
559   if(type==ON_CELLS && !_localization.empty())
560     {
561       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
562         setType(ON_GAUSS_PT);
563       else
564         {
565           setType(ON_GAUSS_NE);
566           _localization.clear();
567         }
568     }
569 }
570
571 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
572 {
573   std::string fieldName(nasc.getName()),meshName(getMeshName());
574   int iteration(getIteration()),order(getOrder());
575   TypeOfField type(getType());
576   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
577   med_geometry_type mgeoti;
578   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
579   if(_start>_end)
580     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
581   if(_start==_end)
582     return ;
583   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
584   if(_start<0 || _start>=arr->getNumberOfTuples())
585     {
586       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
587       throw INTERP_KERNEL::Exception(oss.str().c_str());
588     }
589   if(_end<0 || _end>arr->getNumberOfTuples())
590     {
591       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
592       throw INTERP_KERNEL::Exception(oss.str().c_str());
593     }
594   int nbOfCompo(arr->getNumberOfComponents());
595   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
596   if(arrD)
597     {
598       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
599       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
600       return ;
601     }
602   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
603   if(arrI)
604     {
605       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
606       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
607       return ;
608     }
609   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
610 }
611
612 /*!
613  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
614  */
615 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
616 {
617   int delta=_end-_start;
618   _start=newValueOfStart;
619   _end=_start+delta;
620 }
621
622 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
623 {
624   return _father->getIteration();
625 }
626
627 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
628 {
629   return _father->getOrder();
630 }
631
632 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
633 {
634   return _father->getTime();
635 }
636
637 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
638 {
639   return _father->getMeshName();
640 }
641
642 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
643 {
644   const char startLine[]="    ## ";
645   std::string startLine2(bkOffset,' ');
646   startLine2+=startLine;
647   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
648   oss << startLine2 << "Localization #" << id << "." << std::endl;
649   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
650   delete tmp;
651   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
652   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
653   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
654 }
655
656 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
657 {
658   return _type;
659 }
660
661 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
662 {
663   types.insert(_type);
664 }
665
666 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
667 {
668   _type=newType;
669 }
670
671 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
672 {
673   return _father->getGeoType();
674 }
675
676 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
677 {
678   return _father->getNumberOfComponents();
679 }
680
681 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
682 {
683   return _end-_start;
684 }
685
686 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
687 {
688   return _father->getOrCreateAndGetArray();
689 }
690
691 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
692 {
693   const MEDFileFieldPerMeshPerType *fath=_father;
694   return fath->getOrCreateAndGetArray();
695 }
696
697 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
698 {
699   return _father->getInfo();
700 }
701
702 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
703 {
704   return _profile;
705 }
706
707 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
708 {
709   _profile=newPflName;
710 }
711
712 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
713 {
714   return _localization;
715 }
716
717 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
718 {
719   _localization=newLocName;
720 }
721
722 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
723 {
724   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
725     {
726       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
727         {
728           _profile=(*it2).second;
729           return;
730         }
731     }
732 }
733
734 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
735 {
736   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
737     {
738       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
739         {
740           _localization=(*it2).second;
741           return;
742         }
743     }
744 }
745
746 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
747 {
748   if(type!=_type)
749     return ;
750   dads.push_back(std::pair<int,int>(_start,_end));
751   geoTypes.push_back(getGeoType());
752   if(_profile.empty())
753     pfls.push_back(0);
754   else
755     {
756       pfls.push_back(glob->getProfile(_profile.c_str()));
757     }
758   if(_localization.empty())
759     locs.push_back(-1);
760   else
761     {
762       locs.push_back(glob->getLocalizationId(_localization.c_str()));
763     }
764 }
765
766 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
767 {
768   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));
769   startEntryId++;
770 }
771
772 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
773 {
774   TypeOfField type=getType();
775   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
776   med_geometry_type mgeoti;
777   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
778   const DataArray *arr=getOrCreateAndGetArray();
779   if(!arr)
780     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
781   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
782   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
783   const unsigned char *locToWrite=0;
784   if(arrD)
785     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
786   else if(arrI)
787     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
788   else
789     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
790   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
791                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
792                                                    locToWrite));
793 }
794
795 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
796 {
797   type=_type;
798   pfl=_profile;
799   loc=_localization;
800   dad.first=_start; dad.second=_end;
801 }
802
803 /*!
804  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
805  *             This code corresponds to the distribution of types in the corresponding mesh.
806  * \param [out] ptToFill memory zone where the output will be stored.
807  * \return the size of data pushed into output param \a ptToFill
808  */
809 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
810 {
811   _loc_id=offset;
812   std::ostringstream oss;
813   std::size_t nbOfType=codeOfMesh.size()/3;
814   int found=-1;
815   for(std::size_t i=0;i<nbOfType && found==-1;i++)
816     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
817       found=(int)i;
818   if(found==-1)
819     {
820       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
821       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
822       throw INTERP_KERNEL::Exception(oss.str().c_str());
823     }
824   int *work=ptToFill;
825   if(_profile.empty())
826     {
827       if(_nval!=codeOfMesh[3*found+1])
828         {
829           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
830           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
831           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
832           throw INTERP_KERNEL::Exception(oss.str().c_str());
833         }
834       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
835         *work++=ii;
836     }
837   else
838     {
839       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
840       if(pfl->getNumberOfTuples()!=_nval)
841         {
842           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
843           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
844           oss << _nval;
845           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
846           throw INTERP_KERNEL::Exception(oss.str().c_str());
847         }
848       int offset2=codeOfMesh[3*found+2];
849       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
850         {
851           if(*pflId<codeOfMesh[3*found+1])
852             *work++=offset2+*pflId;
853         }
854     }
855   return _nval;
856 }
857
858 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
859 {
860   for(int i=_start;i<_end;i++)
861     *ptToFill++=i;
862   return _end-_start;
863 }
864
865 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
866 {
867   switch(type)
868   {
869     case ON_CELLS:
870       return -2;
871     case ON_GAUSS_NE:
872       return -1;
873     case ON_GAUSS_PT:
874       return locId;
875     default:
876       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
877   }
878 }
879
880 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
881 {
882   int id=0;
883   std::map<std::pair<std::string,TypeOfField>,int> m;
884   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
885   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
886     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
887       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
888   ret.resize(id);
889   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
890     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
891   return ret;
892 }
893
894 /*!
895  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
896  * 
897  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
898  * \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.
899  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
900  * \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)
901  * \param [in,out] glob if necessary by the method, new profiles can be added to it
902  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
903  * \param [out] result All new entries will be appended on it.
904  * \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 !)
905  */
906 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
907                                                        const DataArrayInt *explicitIdsInMesh,
908                                                        const std::vector<int>& newCode,
909                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
910                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
911 {
912   if(entriesOnSameDisc.empty())
913     return false;
914   TypeOfField type=entriesOnSameDisc[0]->getType();
915   int szEntities=0,szTuples=0;
916   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
917     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
918   int nbi=szTuples/szEntities;
919   if(szTuples%szEntities!=0)
920     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
921   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
922   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
923   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
924   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
925   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
926   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
927   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
928   int id=0;
929   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
930     {
931       int startOfEltIdOfChunk=(*it)->_start;
932       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
933       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
934       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
935       //
936       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
937       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
938       //
939       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
940       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
941     }
942   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
943   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
944   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
945   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
946   //
947   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
948   //
949   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
950   arrPart->renumberInPlace(renumTupleIds->begin());
951   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
952   bool ret=false;
953   const int *idIt=diffVals->begin();
954   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
955   int offset2=0;
956   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
957     {
958       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
959       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
960       int nbEntityElts=subIds->getNumberOfTuples();
961       bool ret2;
962       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
963           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
964                                       offset+offset2,
965                                       li,glob,ret2);
966       ret=ret || ret2;
967       result.push_back(eltToAdd);
968       offset2+=nbEntityElts*nbi;
969     }
970   ret=ret || li.empty();
971   return ret;
972 }
973
974 /*!
975  * \param [in] typeF type of field of new chunk
976  * \param [in] geoType the geometric type of the chunk
977  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
978  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
979  * \param [in] nbi number of integration points
980  * \param [in] offset The offset in the **global array of data**.
981  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
982  *                 to the new chunk to create.
983  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
984  * \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
985  *              and corresponding entry erased from \a entriesOnSameDisc.
986  * \return a newly allocated chunk
987  */
988 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
989                                                                                                   bool isPfl, int nbi, int offset,
990                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
991                                                                                                   MEDFileFieldGlobsReal& glob,
992                                                                                                   bool &notInExisting)
993 {
994   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
995   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
996   for(;it!=entriesOnSameDisc.end();it++)
997     {
998       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
999         {
1000           if(!isPfl)
1001             {
1002               if((*it)->_profile.empty())
1003                 break;
1004               else
1005                 if(!(*it)->_profile.empty())
1006                   {
1007                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1008                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1009                       break;
1010                   }
1011             }
1012         }
1013     }
1014   if(it==entriesOnSameDisc.end())
1015     {
1016       notInExisting=true;
1017       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1018       ret->_type=typeF;
1019       ret->_loc_id=(int)geoType;
1020       ret->_nval=nbMeshEntities;
1021       ret->_start=offset;
1022       ret->_end=ret->_start+ret->_nval*nbi;
1023       if(isPfl)
1024         {
1025           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1026           glob.appendProfile(idsOfMeshElt);
1027           ret->_profile=idsOfMeshElt->getName();
1028         }
1029       //tony treatment of localization
1030       return ret;
1031     }
1032   else
1033     {
1034       notInExisting=false;
1035       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1036       ret->_loc_id=(int)geoType;
1037       ret->setNewStart(offset);
1038       entriesOnSameDisc.erase(it);
1039       return ret;
1040     }
1041
1042 }
1043
1044 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1045 {
1046   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1047 }
1048
1049 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1050 {
1051   return new MEDFileFieldPerMeshPerType(fath,geoType);
1052 }
1053
1054 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
1055 {
1056   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1057 }
1058
1059 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
1060 {
1061   std::vector<const BigMemoryObject *> ret;
1062   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1063     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1064   return ret;
1065 }
1066
1067 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1068 {
1069   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1070   ret->_father=father;
1071   std::size_t i=0;
1072   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1073     {
1074       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1075         ret->_field_pm_pt_pd[i]=(*it)->deepCopy((MEDFileFieldPerMeshPerType *)ret);
1076     }
1077   return ret.retn();
1078 }
1079
1080 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1081 {
1082   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1083   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1084     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1085 }
1086
1087 /*!
1088  * This method is the most general one. No optimization is done here.
1089  * \param [in] multiTypePfl is the end user profile specified in high level API
1090  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1091  * \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.
1092  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1093  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1094  * \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.
1095  */
1096 void MEDFileFieldPerMeshPerType::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1097 {
1098   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1099   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1100     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1101 }
1102
1103 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1104 {
1105   _field_pm_pt_pd.resize(1);
1106   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1107   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1108 }
1109
1110 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1111 {
1112   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1113   if(!arr || !arr->isAllocated())
1114     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1115   _field_pm_pt_pd.resize(1);
1116   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1117   _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.
1118 }
1119
1120 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1121 {
1122   TypeOfField type=field->getTypeOfField();
1123   if(type!=ON_GAUSS_PT)
1124     {
1125       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1126       int sz=_field_pm_pt_pd.size();
1127       bool found=false;
1128       for(int j=0;j<sz && !found;j++)
1129         {
1130           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1131             {
1132               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1133               found=true;
1134             }
1135         }
1136       if(!found)
1137         {
1138           _field_pm_pt_pd.resize(sz+1);
1139           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1140         }
1141       std::vector<int> ret(1,(int)sz);
1142       return ret;
1143     }
1144   else
1145     {
1146       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1147       int sz2=ret2.size();
1148       std::vector<int> ret3(sz2);
1149       int k=0;
1150       for(int i=0;i<sz2;i++)
1151         {
1152           int sz=_field_pm_pt_pd.size();
1153           int locIdToFind=ret2[i];
1154           bool found=false;
1155           for(int j=0;j<sz && !found;j++)
1156             {
1157               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1158                 {
1159                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1160                   ret3[k++]=j;
1161                   found=true;
1162                 }
1163             }
1164           if(!found)
1165             {
1166               _field_pm_pt_pd.resize(sz+1);
1167               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1168               ret3[k++]=sz;
1169             }
1170         }
1171       return ret3;
1172     }
1173 }
1174
1175 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1176 {
1177   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1178   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1179   if(!disc2)
1180     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1181   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1182   if(!da)
1183     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1184   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1185   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1186   if(retTmp->presenceOfValue(-1))
1187     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1188   std::vector<int> ret(retTmp->begin(),retTmp->end());
1189   return ret;
1190 }
1191
1192 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1193 {
1194   TypeOfField type=field->getTypeOfField();
1195   if(type!=ON_GAUSS_PT)
1196     {
1197       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1198       int sz=_field_pm_pt_pd.size();
1199       bool found=false;
1200       for(int j=0;j<sz && !found;j++)
1201         {
1202           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1203             {
1204               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1205               found=true;
1206             }
1207         }
1208       if(!found)
1209         {
1210           _field_pm_pt_pd.resize(sz+1);
1211           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1212         }
1213       std::vector<int> ret(1,0);
1214       return ret;
1215     }
1216   else
1217     {
1218       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1219       int sz2=ret2.size();
1220       std::vector<int> ret3(sz2);
1221       int k=0;
1222       for(int i=0;i<sz2;i++)
1223         {
1224           int sz=_field_pm_pt_pd.size();
1225           int locIdToFind=ret2[i];
1226           bool found=false;
1227           for(int j=0;j<sz && !found;j++)
1228             {
1229               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1230                 {
1231                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1232                   ret3[k++]=j;
1233                   found=true;
1234                 }
1235             }
1236           if(!found)
1237             {
1238               _field_pm_pt_pd.resize(sz+1);
1239               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1240               ret3[k++]=sz;
1241             }
1242         }
1243       return ret3;
1244     }
1245 }
1246
1247 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1248 {
1249   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1250   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1251   if(!disc2)
1252     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1253   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1254   if(!da)
1255     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1256   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1257   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1258   if(retTmp->presenceOfValue(-1))
1259     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1260   std::vector<int> ret(retTmp->begin(),retTmp->end());
1261   return ret;
1262 }
1263
1264 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1265 {
1266   return _father;
1267 }
1268
1269 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1270 {
1271   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1272   int curDim=(int)cm.getDimension();
1273   dim=std::max(dim,curDim);
1274 }
1275
1276 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1277 {
1278   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1279     {
1280       (*it)->fillTypesOfFieldAvailable(types);
1281     }
1282 }
1283
1284 void MEDFileFieldPerMeshPerType::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1285 {
1286   int sz=_field_pm_pt_pd.size();
1287   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1288   for(int i=0;i<sz;i++)
1289     {
1290       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1291     }
1292 }
1293
1294 int MEDFileFieldPerMeshPerType::getIteration() const
1295 {
1296   return _father->getIteration();
1297 }
1298
1299 int MEDFileFieldPerMeshPerType::getOrder() const
1300 {
1301   return _father->getOrder();
1302 }
1303
1304 double MEDFileFieldPerMeshPerType::getTime() const
1305 {
1306   return _father->getTime();
1307 }
1308
1309 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1310 {
1311   return _father->getMeshName();
1312 }
1313
1314 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1315 {
1316   const char startLine[]="  ## ";
1317   std::string startLine2(bkOffset,' ');
1318   std::string startLine3(startLine2);
1319   startLine3+=startLine;
1320   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1321     {
1322       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1323       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1324     }
1325   else
1326     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1327   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1328   int i=0;
1329   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1330     {
1331       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1332       if(cur)
1333         cur->simpleRepr(bkOffset,oss,i);
1334       else
1335         {
1336           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1337         }
1338     }
1339 }
1340
1341 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1342 {
1343   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1344     {
1345       globalSz+=(*it)->getNumberOfTuples();
1346     }
1347   nbOfEntries+=(int)_field_pm_pt_pd.size();
1348 }
1349
1350 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1351 {
1352   return _geo_type;
1353 }
1354
1355
1356 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1357 {
1358   return _father->getNumberOfComponents();
1359 }
1360
1361 bool MEDFileFieldPerMeshPerType::presenceOfMultiDiscPerGeoType() const
1362 {
1363   std::size_t nb(0);
1364   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1365     {
1366       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1367       if(fmtd)
1368         nb++;
1369     }
1370   return nb>1;
1371 }
1372
1373 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1374 {
1375   return _father->getOrCreateAndGetArray();
1376 }
1377
1378 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1379 {
1380   const MEDFileFieldPerMesh *fath=_father;
1381   return fath->getOrCreateAndGetArray();
1382 }
1383
1384 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1385 {
1386   return _father->getInfo();
1387 }
1388
1389 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1390 {
1391   std::vector<std::string> ret;
1392   std::set<std::string> ret2;
1393   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1394     {
1395       std::string tmp=(*it1)->getProfile();
1396       if(!tmp.empty())
1397         if(ret2.find(tmp)==ret2.end())
1398           {
1399             ret.push_back(tmp);
1400             ret2.insert(tmp);
1401           }
1402     }
1403   return ret;
1404 }
1405
1406 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1407 {
1408   std::vector<std::string> ret;
1409   std::set<std::string> ret2;
1410   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1411     {
1412       std::string tmp=(*it1)->getLocalization();
1413       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1414         if(ret2.find(tmp)==ret2.end())
1415           {
1416             ret.push_back(tmp);
1417             ret2.insert(tmp);
1418           }
1419     }
1420   return ret;
1421 }
1422
1423 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1424 {
1425   std::vector<std::string> ret;
1426   std::set<std::string> ret2;
1427   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1428     {
1429       std::string tmp=(*it1)->getProfile();
1430       if(!tmp.empty())
1431         ret.push_back(tmp);
1432     }
1433   return ret;
1434 }
1435
1436 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1437 {
1438   std::vector<std::string> ret;
1439   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1440     {
1441       std::string tmp=(*it1)->getLocalization();
1442       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1443         ret.push_back(tmp);
1444     }
1445   return ret;
1446 }
1447
1448 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1449 {
1450   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1451     (*it1)->changePflsRefsNamesGen(mapOfModif);
1452 }
1453
1454 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1455 {
1456   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1457     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1458 }
1459
1460 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1461 {
1462   if(_field_pm_pt_pd.empty())
1463     {
1464       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1465       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1466       throw INTERP_KERNEL::Exception(oss.str().c_str());
1467     }
1468   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1469     return _field_pm_pt_pd[locId];
1470   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1471   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1472   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1473   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1474   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1475 }
1476
1477 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1478 {
1479   if(_field_pm_pt_pd.empty())
1480     {
1481       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1482       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1483       throw INTERP_KERNEL::Exception(oss.str().c_str());
1484     }
1485   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1486     return _field_pm_pt_pd[locId];
1487   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1488   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1489   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1490   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1491   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1492 }
1493
1494 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
1495 {
1496   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1497     {
1498       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1499       if(meshDim!=(int)cm.getDimension())
1500         return ;
1501     }
1502   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1503     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1504 }
1505
1506 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1507 {
1508   int i=0;
1509   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1510     {
1511       (*it)->fillValues(i,startEntryId,entries);
1512     }
1513 }
1514
1515 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1516 {
1517   _field_pm_pt_pd=leaves;
1518   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1519     (*it)->setFather(this);
1520 }
1521
1522 /*!
1523  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1524  *  \param [out] its - list of pair (start,stop) kept
1525  *  \return bool - false if the type of field \a tof is not contained in \a this.
1526  */
1527 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1528 {
1529   bool ret(false);
1530   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1531   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1532     if((*it)->getType()==tof)
1533       {
1534         newPmPtPd.push_back(*it);
1535         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1536         (*it)->setNewStart(globalNum);
1537         globalNum=(*it)->getEnd();
1538         its.push_back(bgEnd);
1539         ret=true;
1540       }
1541   if(ret)
1542     _field_pm_pt_pd=newPmPtPd;
1543   return ret;
1544 }
1545
1546 /*!
1547  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1548  *  \param [out] its - list of pair (start,stop) kept
1549  *  \return bool - false if the type of field \a tof is not contained in \a this.
1550  */
1551 bool MEDFileFieldPerMeshPerType::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1552 {
1553   if(_field_pm_pt_pd.size()<=idOfDisc)
1554     return false;
1555   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1556   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1557   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1558   elt->setNewStart(globalNum);
1559   globalNum=elt->getEnd();
1560   its.push_back(bgEnd);
1561   _field_pm_pt_pd=newPmPtPd;
1562   return true;
1563 }
1564
1565 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1566 {
1567 }
1568
1569 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType)
1570 {
1571   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1572   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1573   med_geometry_type mgeoti;
1574   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1575   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1576   _field_pm_pt_pd.resize(nbProfiles);
1577   for(int i=0;i<nbProfiles;i++)
1578     {
1579       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1580     }
1581   if(type==ON_CELLS)
1582     {
1583       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1584       for(int i=0;i<nbProfiles2;i++)
1585         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1586     }
1587 }
1588
1589 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1590 {
1591   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1592     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1593 }
1594
1595 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1596 {
1597   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1598     (*it)->loadBigArray(fid,nasc);
1599 }
1600
1601 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1602 {
1603   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1604     {
1605       (*it)->copyOptionsFrom(*this);
1606       (*it)->writeLL(fid,nasc);
1607     }
1608 }
1609
1610 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1611 {
1612   switch(ikType)
1613   {
1614     case ON_CELLS:
1615       medfGeoType=typmai3[(int)ikGeoType];
1616       return MED_CELL;
1617     case ON_NODES:
1618       medfGeoType=MED_NONE;
1619       return MED_NODE;
1620     case ON_GAUSS_NE:
1621       medfGeoType=typmai3[(int)ikGeoType];
1622       return MED_NODE_ELEMENT;
1623     case ON_GAUSS_PT:
1624       medfGeoType=typmai3[(int)ikGeoType];
1625       return MED_CELL;
1626     default:
1627       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1628   }
1629   return MED_UNDEF_ENTITY_TYPE;
1630 }
1631
1632 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
1633 {
1634   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1635 }
1636
1637 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1638 {
1639   return new MEDFileFieldPerMesh(fath,mesh);
1640 }
1641
1642 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1643 {
1644   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1645 }
1646
1647 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1648 {
1649   std::vector<const BigMemoryObject *> ret;
1650   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1651     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1652   return ret;
1653 }
1654
1655 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1656 {
1657   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1658   ret->_father=father;
1659   std::size_t i=0;
1660   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1661     {
1662       if((const MEDFileFieldPerMeshPerType *)*it)
1663         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1664     }
1665   return ret.retn();
1666 }
1667
1668 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1669 {
1670   std::string startLine(bkOffset,' ');
1671   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1672   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1673   int i=0;
1674   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1675     {
1676       const MEDFileFieldPerMeshPerType *cur=*it;
1677       if(cur)
1678         cur->simpleRepr(bkOffset,oss,i);
1679       else
1680         {
1681           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1682         }
1683     }
1684 }
1685
1686 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1687 {
1688   _mesh_name=mesh->getName();
1689   mesh->getTime(_mesh_iteration,_mesh_order);
1690 }
1691
1692 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1693 {
1694   int nbOfTypes=code.size()/3;
1695   int offset=0;
1696   for(int i=0;i<nbOfTypes;i++)
1697     {
1698       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1699       int nbOfCells=code[3*i+1];
1700       int pos=addNewEntryIfNecessary(type);
1701       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1702       offset+=nbOfCells;
1703     }
1704 }
1705
1706 /*!
1707  * This method is the most general one. No optimization is done here.
1708  * \param [in] multiTypePfl is the end user profile specified in high level API
1709  * \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].
1710  * \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.
1711  * \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.
1712  * \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.
1713  * \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.
1714  */
1715 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)
1716 {
1717   int nbOfTypes(code.size()/3);
1718   for(int i=0;i<nbOfTypes;i++)
1719     {
1720       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1721       int pos=addNewEntryIfNecessary(type);
1722       DataArrayInt *pfl=0;
1723       if(code[3*i+2]!=-1)
1724         pfl=idsPerType[code[3*i+2]];
1725       int nbOfTupes2=code2.size()/3;
1726       int found=0;
1727       for(;found<nbOfTupes2;found++)
1728         if(code[3*i]==code2[3*found])
1729           break;
1730       if(found==nbOfTupes2)
1731         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1732       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1733     }
1734 }
1735
1736 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1737 {
1738   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1739   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1740 }
1741
1742 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1743 {
1744   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1745   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1746 }
1747
1748 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1749 {
1750   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1751     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1752 }
1753
1754 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1755 {
1756   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1757     (*it)->loadBigArraysRecursively(fid,nasc);
1758 }
1759
1760 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1761 {
1762   int nbOfTypes=_field_pm_pt.size();
1763   for(int i=0;i<nbOfTypes;i++)
1764     {
1765       _field_pm_pt[i]->copyOptionsFrom(*this);
1766       _field_pm_pt[i]->writeLL(fid,nasc);
1767     }
1768 }
1769
1770 void MEDFileFieldPerMesh::getDimension(int& dim) const
1771 {
1772   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1773     (*it)->getDimension(dim);
1774 }
1775
1776 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1777 {
1778   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1779     (*it)->fillTypesOfFieldAvailable(types);
1780 }
1781
1782 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
1783 {
1784   int sz=_field_pm_pt.size();
1785   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1786   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1787   for(int i=0;i<sz;i++)
1788     {
1789       types[i]=_field_pm_pt[i]->getGeoType();
1790       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1791     }
1792   return ret;
1793 }
1794
1795 double MEDFileFieldPerMesh::getTime() const
1796 {
1797   int tmp1,tmp2;
1798   return _father->getTime(tmp1,tmp2);
1799 }
1800
1801 int MEDFileFieldPerMesh::getIteration() const
1802 {
1803   return _father->getIteration();
1804 }
1805
1806 int MEDFileFieldPerMesh::getOrder() const
1807 {
1808   return _father->getOrder();
1809 }
1810
1811 int MEDFileFieldPerMesh::getNumberOfComponents() const
1812 {
1813   return _father->getNumberOfComponents();
1814 }
1815
1816 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1817 {
1818   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1819     {
1820       const MEDFileFieldPerMeshPerType *fpmt(*it);
1821       if(!fpmt)
1822         continue;
1823       if(fpmt->presenceOfMultiDiscPerGeoType())
1824         return true;
1825     }
1826   return false;
1827 }
1828
1829 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1830 {
1831   if(!_father)
1832     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1833   return _father->getOrCreateAndGetArray();
1834 }
1835
1836 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1837 {
1838   if(!_father)
1839     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1840   return _father->getOrCreateAndGetArray();
1841 }
1842
1843 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1844 {
1845   return _father->getInfo();
1846 }
1847
1848 /*!
1849  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1850  * 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.
1851  * It returns 2 output vectors :
1852  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1853  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1854  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1855  */
1856 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)
1857 {
1858   int notNullPflsSz=0;
1859   int nbOfArrs=geoTypes.size();
1860   for(int i=0;i<nbOfArrs;i++)
1861     if(pfls[i])
1862       notNullPflsSz++;
1863   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1864   int nbOfDiffGeoTypes=geoTypes3.size();
1865   code.resize(3*nbOfDiffGeoTypes);
1866   notNullPfls.resize(notNullPflsSz);
1867   notNullPflsSz=0;
1868   int j=0;
1869   for(int i=0;i<nbOfDiffGeoTypes;i++)
1870     {
1871       int startZone=j;
1872       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1873       std::vector<const DataArrayInt *> notNullTmp;
1874       if(pfls[j])
1875         notNullTmp.push_back(pfls[j]);
1876       j++;
1877       for(;j<nbOfArrs;j++)
1878         if(geoTypes[j]==refType)
1879           {
1880             if(pfls[j])
1881               notNullTmp.push_back(pfls[j]);
1882           }
1883         else
1884           break;
1885       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1886       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1887       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1888       code[3*i]=(int)refType;
1889       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1890       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1891       if(notNullTmp.empty())
1892         code[3*i+2]=-1;
1893       else
1894         {
1895           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1896           code[3*i+2]=notNullPflsSz++;
1897         }
1898     }
1899 }
1900
1901 /*!
1902  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1903  */
1904 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)
1905 {
1906   int sz=dads.size();
1907   int ret=0;
1908   for(int i=0;i<sz;i++)
1909     {
1910       if(locs[i]==-1)
1911         {
1912           if(type!=ON_GAUSS_NE)
1913             ret+=dads[i].second-dads[i].first;
1914           else
1915             {
1916               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1917               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1918             }
1919         }
1920       else
1921         {
1922           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1923           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1924         }
1925     }
1926   return ret;
1927 }
1928
1929 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1930 {
1931   std::vector<std::string> ret;
1932   std::set<std::string> ret2;
1933   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1934     {
1935       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1936       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1937         if(ret2.find(*it2)==ret2.end())
1938           {
1939             ret.push_back(*it2);
1940             ret2.insert(*it2);
1941           }
1942     }
1943   return ret;
1944 }
1945
1946 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1947 {
1948   std::vector<std::string> ret;
1949   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1950     {
1951       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1952       ret.insert(ret.end(),tmp.begin(),tmp.end());
1953     }
1954   return ret;
1955 }
1956
1957 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1958 {
1959   std::vector<std::string> ret;
1960   std::set<std::string> ret2;
1961   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1962     {
1963       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1964       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1965         if(ret2.find(*it2)==ret2.end())
1966           {
1967             ret.push_back(*it2);
1968             ret2.insert(*it2);
1969           }
1970     }
1971   return ret;
1972 }
1973
1974 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1975 {
1976   std::vector<std::string> ret;
1977   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1978     {
1979       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1980       ret.insert(ret.end(),tmp.begin(),tmp.end());
1981     }
1982   return ret;
1983 }
1984
1985 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1986 {
1987   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1988     {
1989       if((*it).first==_mesh_name)
1990         {
1991           _mesh_name=(*it).second;
1992           return true;
1993         }
1994     }
1995   return false;
1996 }
1997
1998 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1999                                                       MEDFileFieldGlobsReal& glob)
2000 {
2001   if(_mesh_name!=meshName)
2002     return false;
2003   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2004   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2005   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2006   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2007   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2008   getUndergroundDataArrayExt(entries);
2009   DataArray *arr0=getOrCreateAndGetArray();//tony
2010   if(!arr0)
2011     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2012   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
2013   if(!arr0)
2014     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2015   int sz=0;
2016   if(!arr)
2017     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2018   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2019     {
2020       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2021         {
2022           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2023           sz+=(*it).second.second-(*it).second.first;
2024         }
2025       else
2026         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2027     }
2028   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2029   ////////////////////
2030   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2031   int *workI2=explicitIdsOldInMesh->getPointer();
2032   int sz1=0,sz2=0,sid=1;
2033   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2034   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2035   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2036     {
2037       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2038       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2039       int *workI=explicitIdsOldInArr->getPointer();
2040       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2041         {
2042           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2043           (*itL2)->setLocId(sz2);
2044           (*itL2)->_tmp_work1=(*itL2)->getStart();
2045           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2046         }
2047       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2048     }
2049   explicitIdsOldInMesh->reAlloc(sz2);
2050   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2051   ////////////////////
2052   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2053   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2054   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2055   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2056     {
2057       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2058       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2059       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2060     }
2061   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2062   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2063   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2064     {
2065       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2066       int newStart=elt->getLocId();
2067       elt->setLocId((*it)->getGeoType());
2068       elt->setNewStart(newStart);
2069       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2070       entriesKeptNew.push_back(elt);
2071       entriesKeptNew2.push_back(elt);
2072     }
2073   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2074   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2075   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2076   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2077   bool ret=false;
2078   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2079     {
2080       sid=0;
2081       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2082         {
2083           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2084           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2085           }*/
2086       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2087                                                             glob,arr2,otherEntriesNew) || ret;
2088     }
2089   if(!ret)
2090     return false;
2091   // Assign new dispatching
2092   assignNewLeaves(otherEntriesNew);
2093   arr->deepCopyFrom(*arr2);
2094   return true;
2095 }
2096
2097 /*!
2098  * \param [in,out] globalNum a global numbering counter for the renumbering.
2099  * \param [out] its - list of pair (start,stop) kept
2100  */
2101 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2102 {
2103   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret;
2104   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2105     {
2106       std::vector< std::pair<int,int> > its2;
2107       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2108         {
2109           ret.push_back(*it);
2110           its.insert(its.end(),its2.begin(),its2.end());
2111         }
2112     }
2113   _field_pm_pt=ret;
2114 }
2115
2116 /*!
2117  * \param [in,out] globalNum a global numbering counter for the renumbering.
2118  * \param [out] its - list of pair (start,stop) kept
2119  */
2120 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2121 {
2122   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret;
2123   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2124     {
2125       std::vector< std::pair<int,int> > its2;
2126       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2127         {
2128           ret.push_back(*it);
2129           its.insert(its.end(),its2.begin(),its2.end());
2130         }
2131     }
2132   _field_pm_pt=ret;
2133 }
2134
2135 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2136 {
2137   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2138   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2139     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2140   //
2141   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2142   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2143   std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2144   for(;it1!=types.end();it1++,it2++)
2145     {
2146       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2147       elt->setLeaves((*it1).second);
2148       *it2=elt;
2149     }
2150   _field_pm_pt=fieldPmPt;
2151 }
2152
2153 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2154 {
2155   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2156     (*it)->changePflsRefsNamesGen(mapOfModif);
2157 }
2158
2159 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2160 {
2161   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2162     (*it)->changeLocsRefsNamesGen(mapOfModif);
2163 }
2164
2165 /*!
2166  * \param [in] mesh is the whole mesh
2167  */
2168 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2169 {
2170   if(_field_pm_pt.empty())
2171     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2172   //
2173   std::vector< std::pair<int,int> > dads;
2174   std::vector<const DataArrayInt *> pfls;
2175   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2176   std::vector<int> locs,code;
2177   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2178   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2179     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2180   // Sort by types
2181   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2182   if(code.empty())
2183     {
2184       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2185       throw INTERP_KERNEL::Exception(oss.str().c_str());
2186     }
2187   //
2188   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2189   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2190   if(type!=ON_NODES)
2191     {
2192       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2193       if(!arr)
2194         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2195       else
2196         {
2197           MCAuto<DataArrayInt> arr2(arr);
2198           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2199         }
2200     }
2201   else
2202     {
2203       if(code.size()!=3)
2204         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2205       int nb=code[1];
2206       if(code[2]==-1)
2207         {
2208           if(nb!=mesh->getNumberOfNodes())
2209             {
2210               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2211               oss << " nodes in mesh !";
2212               throw INTERP_KERNEL::Exception(oss.str().c_str());
2213             }
2214           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2215         }
2216       else
2217         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2218     }
2219 }
2220
2221 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2222 {
2223   if(_field_pm_pt.empty())
2224     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2225   //
2226   std::vector<std::pair<int,int> > dads;
2227   std::vector<const DataArrayInt *> pfls;
2228   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2229   std::vector<int> locs,code;
2230   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2231   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2232     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2233   // Sort by types
2234   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2235   if(code.empty())
2236     {
2237       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2238       throw INTERP_KERNEL::Exception(oss.str().c_str());
2239     }
2240   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2241   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2242   if(type!=ON_NODES)
2243     {
2244       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2245       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2246     }
2247   else
2248     {
2249       if(code.size()!=3)
2250         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2251       int nb=code[1];
2252       if(code[2]==-1)
2253         {
2254           if(nb!=mesh->getNumberOfNodes())
2255             {
2256               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2257               oss << " nodes in mesh !";
2258               throw INTERP_KERNEL::Exception(oss.str().c_str());
2259             }
2260         }
2261       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2262     }
2263   //
2264   return 0;
2265 }
2266
2267 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2268 {
2269   int globalSz=0;
2270   int nbOfEntries=0;
2271   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2272     {
2273       (*it)->getSizes(globalSz,nbOfEntries);
2274     }
2275   entries.resize(nbOfEntries);
2276   nbOfEntries=0;
2277   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2278     {
2279       (*it)->fillValues(nbOfEntries,entries);
2280     }
2281 }
2282
2283 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2284 {
2285   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2286     {
2287       if((*it)->getGeoType()==typ)
2288         return (*it)->getLeafGivenLocId(locId);
2289     }
2290   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2291   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2292   oss << "Possiblities are : ";
2293   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2294     {
2295       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2296       oss << "\"" << cm2.getRepr() << "\", ";
2297     }
2298   throw INTERP_KERNEL::Exception(oss.str().c_str());
2299 }
2300
2301 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2302 {
2303   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2304     {
2305       if((*it)->getGeoType()==typ)
2306         return (*it)->getLeafGivenLocId(locId);
2307     }
2308   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2309   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2310   oss << "Possiblities are : ";
2311   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2312     {
2313       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2314       oss << "\"" << cm2.getRepr() << "\", ";
2315     }
2316   throw INTERP_KERNEL::Exception(oss.str().c_str());
2317 }
2318
2319 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2320 {
2321   int i=0;
2322   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2323   std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2324   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2325     {
2326       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2327       if(type==curType)
2328         return i;
2329       else
2330         {
2331           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2332           if(pos>pos2)
2333             it2=it+1;
2334         }
2335     }
2336   int ret=std::distance(_field_pm_pt.begin(),it2);
2337   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2338   return ret;
2339 }
2340
2341 /*!
2342  * 'dads' and 'locs' input parameters have the same number of elements
2343  * \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
2344  */
2345 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2346                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2347                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2348 {
2349   isPfl=false;
2350   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2351   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2352   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2353   const std::vector<std::string>& infos=getInfo();
2354   da->setInfoOnComponents(infos);
2355   da->setName("");
2356   if(type==ON_GAUSS_PT)
2357     {
2358       int offset=0;
2359       int nbOfArrs=dads.size();
2360       for(int i=0;i<nbOfArrs;i++)
2361         {
2362           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2363           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2364           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2365           MCAuto<DataArrayInt> di=DataArrayInt::New();
2366           di->alloc(nbOfElems,1);
2367           di->iota(offset);
2368           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2369           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2370           offset+=nbOfElems;
2371         }
2372     }
2373   arrOut=da;
2374   return ret.retn();
2375 }
2376
2377 /*!
2378  * 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.
2379  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2380  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2381  * The order of cells in the returned field is those imposed by the profile.
2382  * \param [in] mesh is the global mesh.
2383  */
2384 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2385                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2386                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2387                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2388 {
2389   if(da->isIota(mesh->getNumberOfCells()))
2390     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2391   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2392   m2->setName(mesh->getName().c_str());
2393   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2394   isPfl=true;
2395   return ret.retn();
2396 }
2397
2398 /*!
2399  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2400  */
2401 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2402                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2403                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2404 {
2405   if(da->isIota(mesh->getNumberOfNodes()))
2406     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2407   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2408   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2409   if(meshu)
2410     {
2411       if(meshu->getNodalConnectivity()==0)
2412         {
2413           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2414           int nb=da->getNbOfElems();
2415           const int *ptr=da->getConstPointer();
2416           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2417           meshuc->allocateCells(nb);
2418           for(int i=0;i<nb;i++)
2419             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2420           meshuc->finishInsertingCells();
2421           ret->setMesh(meshuc);
2422           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2423           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2424           disc->checkCoherencyBetween(meshuc,arrOut);
2425           return ret.retn();
2426         }
2427     }
2428   //
2429   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2430   isPfl=true;
2431   DataArrayInt *arr2=0;
2432   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2433   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2434   MCAuto<DataArrayInt> arr3(arr2);
2435   int nnodes=mesh2->getNumberOfNodes();
2436   if(nnodes==(int)da->getNbOfElems())
2437     {
2438       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2439       arrOut->renumberInPlace(da3->getConstPointer());
2440       mesh2->setName(mesh->getName().c_str());
2441       ret->setMesh(mesh2);
2442       return ret.retn();
2443     }
2444   else
2445     {
2446       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 !!!";
2447       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2448       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2449       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2450       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2451       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2452       throw INTERP_KERNEL::Exception(oss.str().c_str());
2453     }
2454   return 0;
2455 }
2456
2457 /*!
2458  * This method is the most light method of field retrieving.
2459  */
2460 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2461 {
2462   if(!pflIn)
2463     {
2464       pflOut=DataArrayInt::New();
2465       pflOut->alloc(nbOfElems,1);
2466       pflOut->iota(0);
2467     }
2468   else
2469     {
2470       pflOut=const_cast<DataArrayInt*>(pflIn);
2471       pflOut->incrRef();
2472     }
2473   MCAuto<DataArrayInt> safePfl(pflOut);
2474   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2475   const std::vector<std::string>& infos=getInfo();
2476   int nbOfComp=infos.size();
2477   for(int i=0;i<nbOfComp;i++)
2478     da->setInfoOnComponent(i,infos[i].c_str());
2479   safePfl->incrRef();
2480   return da.retn();
2481 }
2482
2483
2484 /// @cond INTERNAL
2485
2486 class MFFPMIter
2487 {
2488 public:
2489   static MFFPMIter *NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2490   static bool IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2491   virtual ~MFFPMIter() { }
2492   virtual void begin() = 0;
2493   virtual bool finished() const = 0;
2494   virtual void next() = 0;
2495   virtual int current() const = 0;
2496 };
2497
2498 class MFFPMIterSimple : public MFFPMIter
2499 {
2500 public:
2501   MFFPMIterSimple():_pos(0) { }
2502   void begin() { _pos=0; }
2503   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2504   void next() { _pos++; }
2505   int current() const { return _pos; }
2506 private:
2507   int _pos;
2508 };
2509
2510 class MFFPMIter2 : public MFFPMIter
2511 {
2512 public:
2513   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2514   void begin() { _it=_ids.begin(); }
2515   bool finished() const { return _it==_ids.end(); }
2516   void next() { _it++; }
2517   int current() const { return *_it; }
2518 private:
2519   std::vector<int> _ids;
2520   std::vector<int>::const_iterator _it;
2521 };
2522
2523 MFFPMIter *MFFPMIter::NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2524 {
2525   if(!entities)
2526     return new MFFPMIterSimple;
2527   else
2528     {
2529       std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2530       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2531         {
2532           if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2533             tmp.push_back((*it).second);
2534         }
2535       return new MFFPMIter2(tmp);
2536     }
2537 }
2538
2539 bool MFFPMIter::IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2540 {
2541   if(!entities)
2542     return true;
2543   else
2544     {
2545       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2546         if((*it).first==ON_NODES)
2547           return true;
2548       return false;
2549     }
2550 }
2551
2552 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2553 {
2554   std::size_t sz(cts.size());
2555   _ids.resize(sz);
2556   for(std::size_t i=0;i<sz;i++)
2557     {
2558       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2559       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2560         _ids[i]=(int)std::distance(typmai2,loc);
2561       else
2562         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2563     }
2564 }
2565
2566 /// @endcond
2567
2568 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2569     _father(fath)
2570 {
2571   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2572   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2573   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2574   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2575   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2576   for(iter0->begin();!iter0->finished();iter0->next())
2577     {
2578       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2579       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2580       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2581       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2582       if(nbProfile>0 || nbProfile2>0)
2583         {
2584           const PartDefinition *pd(0);
2585           if(mmu)
2586             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2587           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2588           if(nbProfile>0)
2589             _mesh_name=name0;
2590           else
2591             _mesh_name=name1;
2592         }
2593     }
2594   if(MFFPMIter::IsPresenceOfNode(entities))
2595     {
2596       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2597       if(nbProfile>0)
2598         {
2599           const PartDefinition *pd(0);
2600           if(mmu)
2601             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2602           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2603           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2604         }
2605     }
2606 }
2607
2608 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2609 {
2610   copyTinyInfoFrom(mesh);
2611 }
2612
2613 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2614 {
2615   if(id>=(int)_pfls.size())
2616     _pfls.resize(id+1);
2617   _pfls[id]=DataArrayInt::New();
2618   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2619   _pfls[id]->setName(pflName);
2620   _pfls[id]->alloc(lgth,1);
2621   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2622   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2623 }
2624
2625 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2626 {
2627   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2628   int sz;
2629   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
2630   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2631   if(i>=(int)_pfls.size())
2632     _pfls.resize(i+1);
2633   _pfls[i]=DataArrayInt::New();
2634   _pfls[i]->alloc(sz,1);
2635   _pfls[i]->setName(pflCpp.c_str());
2636   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
2637   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2638 }
2639
2640 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2641 {
2642   int nbOfPfls=_pfls.size();
2643   for(int i=0;i<nbOfPfls;i++)
2644     {
2645       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
2646       cpy->applyLin(1,1,0);
2647       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2648       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2649       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
2650     }
2651   //
2652   int nbOfLocs=_locs.size();
2653   for(int i=0;i<nbOfLocs;i++)
2654     _locs[i]->writeLL(fid);
2655 }
2656
2657 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2658 {
2659   std::vector<std::string> pfls=getPfls();
2660   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2661     {
2662       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2663       if(it2==pfls.end())
2664         {
2665           _pfls.push_back(*it);
2666         }
2667       else
2668         {
2669           int id=std::distance(pfls.begin(),it2);
2670           if(!(*it)->isEqual(*_pfls[id]))
2671             {
2672               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2673               throw INTERP_KERNEL::Exception(oss.str().c_str());
2674             }
2675         }
2676     }
2677   std::vector<std::string> locs=getLocs();
2678   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2679     {
2680       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2681       if(it2==locs.end())
2682         {
2683           _locs.push_back(*it);
2684         }
2685       else
2686         {
2687           int id=std::distance(locs.begin(),it2);
2688           if(!(*it)->isEqual(*_locs[id],eps))
2689             {
2690               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2691               throw INTERP_KERNEL::Exception(oss.str().c_str());
2692             }
2693         }
2694     }
2695 }
2696
2697 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2698 {
2699   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2700     getProfile((*it).c_str());
2701 }
2702
2703 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2704 {
2705   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2706     getLocalization((*it).c_str());
2707 }
2708
2709 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2710 {
2711   std::vector<std::string> profiles=real.getPflsReallyUsed();
2712   int sz=profiles.size();
2713   _pfls.resize(sz);
2714   for(int i=0;i<sz;i++)
2715     loadProfileInFile(fid,i,profiles[i].c_str());
2716   //
2717   std::vector<std::string> locs=real.getLocsReallyUsed();
2718   sz=locs.size();
2719   _locs.resize(sz);
2720   for(int i=0;i<sz;i++)
2721     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2722 }
2723
2724 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2725 {
2726   int nProfil=MEDnProfile(fid);
2727   for(int i=0;i<nProfil;i++)
2728     loadProfileInFile(fid,i);
2729   int sz=MEDnLocalization(fid);
2730   _locs.resize(sz);
2731   for(int i=0;i<sz;i++)
2732     {
2733       _locs[i]=MEDFileFieldLoc::New(fid,i);
2734     }
2735 }
2736
2737 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2738 {
2739   return new MEDFileFieldGlobs(fname);
2740 }
2741
2742 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2743 {
2744   return new MEDFileFieldGlobs;
2745 }
2746
2747 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2748 {
2749   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
2750 }
2751
2752 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2753 {
2754   std::vector<const BigMemoryObject *> ret;
2755   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2756     ret.push_back((const DataArrayInt *)*it);
2757   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2758     ret.push_back((const MEDFileFieldLoc *)*it);
2759   return ret;
2760 }
2761
2762 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
2763 {
2764   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2765   std::size_t i=0;
2766   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2767     {
2768       if((const DataArrayInt *)*it)
2769         ret->_pfls[i]=(*it)->deepCopy();
2770     }
2771   i=0;
2772   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2773     {
2774       if((const MEDFileFieldLoc*)*it)
2775         ret->_locs[i]=(*it)->deepCopy();
2776     }
2777   return ret.retn();
2778 }
2779
2780 /*!
2781  * \throw if a profile in \a pfls in not in \a this.
2782  * \throw if a localization in \a locs in not in \a this.
2783  * \sa MEDFileFieldGlobs::deepCpyPart
2784  */
2785 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2786 {
2787   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2788   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2789     {
2790       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2791       if(!pfl)
2792         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2793       pfl->incrRef();
2794       MCAuto<DataArrayInt> pfl2(pfl);
2795       ret->_pfls.push_back(pfl2);
2796     }
2797   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2798     {
2799       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2800       if(!loc)
2801         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2802       loc->incrRef();
2803       MCAuto<MEDFileFieldLoc> loc2(loc);
2804       ret->_locs.push_back(loc2);
2805     }
2806   ret->setFileName(getFileName());
2807   return ret.retn();
2808 }
2809
2810 /*!
2811  * \throw if a profile in \a pfls in not in \a this.
2812  * \throw if a localization in \a locs in not in \a this.
2813  * \sa MEDFileFieldGlobs::shallowCpyPart
2814  */
2815 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2816 {
2817   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2818   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2819     {
2820       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2821       if(!pfl)
2822         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2823       ret->_pfls.push_back(pfl->deepCopy());
2824     }
2825   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2826     {
2827       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2828       if(!loc)
2829         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2830       ret->_locs.push_back(loc->deepCopy());
2831     }
2832   ret->setFileName(getFileName());
2833   return ret.retn();
2834 }
2835
2836 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2837 {
2838 }
2839
2840 MEDFileFieldGlobs::MEDFileFieldGlobs()
2841 {
2842 }
2843
2844 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2845 {
2846 }
2847
2848 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2849 {
2850   oss << "Profiles :\n";
2851   std::size_t n=_pfls.size();
2852   for(std::size_t i=0;i<n;i++)
2853     {
2854       oss << "  - #" << i << " ";
2855       const DataArrayInt *pfl=_pfls[i];
2856       if(pfl)
2857         oss << "\"" << pfl->getName() << "\"\n";
2858       else
2859         oss << "EMPTY !\n";
2860     }
2861   n=_locs.size();
2862   oss << "Localizations :\n";
2863   for(std::size_t i=0;i<n;i++)
2864     {
2865       oss << "  - #" << i << " ";
2866       const MEDFileFieldLoc *loc=_locs[i];
2867       if(loc)
2868         loc->simpleRepr(oss);
2869       else
2870         oss<< "EMPTY !\n";
2871     }
2872 }
2873
2874 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2875 {
2876   _file_name=fileName;
2877 }
2878
2879 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2880 {
2881   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2882     {
2883       DataArrayInt *elt(*it);
2884       if(elt)
2885         {
2886           std::string name(elt->getName());
2887           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2888             {
2889               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2890                 {
2891                   elt->setName((*it2).second.c_str());
2892                   return;
2893                 }
2894             }
2895         }
2896     }
2897 }
2898
2899 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2900 {
2901   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2902     {
2903       MEDFileFieldLoc *elt(*it);
2904       if(elt)
2905         {
2906           std::string name(elt->getName());
2907           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2908             {
2909               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2910                 {
2911                   elt->setName((*it2).second.c_str());
2912                   return;
2913                 }
2914             }
2915         }
2916     }
2917 }
2918
2919 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2920 {
2921   if(locId<0 || locId>=(int)_locs.size())
2922     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2923   return _locs[locId]->getNbOfGaussPtPerCell();
2924 }
2925
2926 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2927 {
2928   return getLocalizationFromId(getLocalizationId(locName));
2929 }
2930
2931 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2932 {
2933   if(locId<0 || locId>=(int)_locs.size())
2934     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2935   return *_locs[locId];
2936 }
2937
2938 /// @cond INTERNAL
2939 namespace MEDCouplingImpl
2940 {
2941   class LocFinder
2942   {
2943   public:
2944     LocFinder(const std::string& loc):_loc(loc) { }
2945     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2946   private:
2947     const std::string &_loc;
2948   };
2949
2950   class PflFinder
2951   {
2952   public:
2953     PflFinder(const std::string& pfl):_pfl(pfl) { }
2954     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2955   private:
2956     const std::string& _pfl;
2957   };
2958 }
2959 /// @endcond
2960
2961 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2962 {
2963   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
2964   if(it==_locs.end())
2965     {
2966       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2967       for(it=_locs.begin();it!=_locs.end();it++)
2968         oss << "\"" << (*it)->getName() << "\", ";
2969       throw INTERP_KERNEL::Exception(oss.str().c_str());
2970     }
2971   return std::distance(_locs.begin(),it);
2972 }
2973
2974 /*!
2975  * The returned value is never null.
2976  */
2977 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2978 {
2979   std::string pflNameCpp(pflName);
2980   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
2981   if(it==_pfls.end())
2982     {
2983       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2984       for(it=_pfls.begin();it!=_pfls.end();it++)
2985         oss << "\"" << (*it)->getName() << "\", ";
2986       throw INTERP_KERNEL::Exception(oss.str().c_str());
2987     }
2988   return *it;
2989 }
2990
2991 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2992 {
2993   if(pflId<0 || pflId>=(int)_pfls.size())
2994     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2995   return _pfls[pflId];
2996 }
2997
2998 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
2999 {
3000   if(locId<0 || locId>=(int)_locs.size())
3001     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3002   return *_locs[locId];
3003 }
3004
3005 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3006 {
3007   return getLocalizationFromId(getLocalizationId(locName));
3008 }
3009
3010 /*!
3011  * The returned value is never null.
3012  */
3013 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3014 {
3015   std::string pflNameCpp(pflName);
3016   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3017   if(it==_pfls.end())
3018     {
3019       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3020       for(it=_pfls.begin();it!=_pfls.end();it++)
3021         oss << "\"" << (*it)->getName() << "\", ";
3022       throw INTERP_KERNEL::Exception(oss.str().c_str());
3023     }
3024   return *it;
3025 }
3026
3027 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3028 {
3029   if(pflId<0 || pflId>=(int)_pfls.size())
3030     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3031   return _pfls[pflId];
3032 }
3033
3034 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3035 {
3036   std::vector< MCAuto<DataArrayInt> > newPfls;
3037   int i=0;
3038   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3039     {
3040       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3041         newPfls.push_back(*it);
3042     }
3043   _pfls=newPfls;
3044 }
3045
3046 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3047 {
3048   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3049   int i=0;
3050   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3051     {
3052       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3053         newLocs.push_back(*it);
3054     }
3055   _locs=newLocs;
3056 }
3057
3058 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3059 {
3060   int sz=_pfls.size();
3061   std::vector<std::string> ret(sz);
3062   for(int i=0;i<sz;i++)
3063     ret[i]=_pfls[i]->getName();
3064   return ret;
3065 }
3066
3067 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3068 {
3069   int sz=_locs.size();
3070   std::vector<std::string> ret(sz);
3071   for(int i=0;i<sz;i++)
3072     ret[i]=_locs[i]->getName();
3073   return ret;
3074 }
3075
3076 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3077 {
3078   std::vector<std::string> v=getPfls();
3079   std::string s(pflName);
3080   return std::find(v.begin(),v.end(),s)!=v.end();
3081 }
3082
3083 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3084 {
3085   std::vector<std::string> v=getLocs();
3086   std::string s(locName);
3087   return std::find(v.begin(),v.end(),s)!=v.end();
3088 }
3089
3090 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3091 {
3092   std::map<int,std::vector<int> > m;
3093   int i=0;
3094   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3095     {
3096       const DataArrayInt *tmp=(*it);
3097       if(tmp)
3098         {
3099           m[tmp->getHashCode()].push_back(i);
3100         }
3101     }
3102   std::vector< std::vector<int> > ret;
3103   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3104     {
3105       if((*it2).second.size()>1)
3106         {
3107           std::vector<int> ret0;
3108           bool equalityOrNot=false;
3109           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3110             {
3111               std::vector<int>::const_iterator it4=it3; it4++;
3112               for(;it4!=(*it2).second.end();it4++)
3113                 {
3114                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3115                     {
3116                       if(!equalityOrNot)
3117                         ret0.push_back(*it3);
3118                       ret0.push_back(*it4);
3119                       equalityOrNot=true;
3120                     }
3121                 }
3122             }
3123           if(!ret0.empty())
3124             ret.push_back(ret0);
3125         }
3126     }
3127   return ret;
3128 }
3129
3130 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3131 {
3132   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3133 }
3134
3135 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3136 {
3137   std::string name(pfl->getName());
3138   if(name.empty())
3139     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3140   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3141     if(name==(*it)->getName())
3142       {
3143         if(!pfl->isEqual(*(*it)))
3144           {
3145             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3146             throw INTERP_KERNEL::Exception(oss.str().c_str());
3147           }
3148       }
3149   pfl->incrRef();
3150   _pfls.push_back(pfl);
3151 }
3152
3153 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)
3154 {
3155   std::string name(locName);
3156   if(name.empty())
3157     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3158   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3159   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3160     if((*it)->isName(locName))
3161       {
3162         if(!(*it)->isEqual(*obj,1e-12))
3163           {
3164             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3165             throw INTERP_KERNEL::Exception(oss.str().c_str());
3166           }
3167       }
3168   _locs.push_back(obj);
3169 }
3170
3171 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3172 {
3173   std::vector<std::string> names=getPfls();
3174   return CreateNewNameNotIn("NewPfl_",names);
3175 }
3176
3177 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3178 {
3179   std::vector<std::string> names=getLocs();
3180   return CreateNewNameNotIn("NewLoc_",names);
3181 }
3182
3183 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3184 {
3185   for(std::size_t sz=0;sz<100000;sz++)
3186     {
3187       std::ostringstream tryName;
3188       tryName << prefix << sz;
3189       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3190         return tryName.str();
3191     }
3192   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3193 }
3194
3195 /*!
3196  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3197  *  \param [in] fname - the file name.
3198  */
3199 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
3200 {
3201 }
3202
3203 /*!
3204  * Creates an empty MEDFileFieldGlobsReal.
3205  */
3206 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3207 {
3208 }
3209
3210 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3211 {
3212   return 0;
3213 }
3214
3215 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3216 {
3217   std::vector<const BigMemoryObject *> ret;
3218   ret.push_back((const MEDFileFieldGlobs *)_globals);
3219   return ret;
3220 }
3221
3222 /*!
3223  * Returns a string describing profiles and Gauss points held in \a this.
3224  *  \return std::string - the description string.
3225  */
3226 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3227 {
3228   const MEDFileFieldGlobs *glob=_globals;
3229   std::ostringstream oss2; oss2 << glob;
3230   std::string stars(oss2.str().length(),'*');
3231   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3232   if(glob)
3233     glob->simpleRepr(oss);
3234   else
3235     oss << "NO GLOBAL INFORMATION !\n";
3236 }
3237
3238 void MEDFileFieldGlobsReal::resetContent()
3239 {
3240   _globals=MEDFileFieldGlobs::New();
3241 }
3242
3243 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3244 {
3245 }
3246
3247 /*!
3248  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3249  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3250  */
3251 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3252 {
3253   _globals=other._globals;
3254 }
3255
3256 /*!
3257  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3258  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3259  */
3260 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3261 {
3262   const MEDFileFieldGlobs *otherg(other._globals);
3263   if(!otherg)
3264     return ;
3265   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3266 }
3267
3268 /*!
3269  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3270  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3271  */
3272 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3273 {
3274   const MEDFileFieldGlobs *otherg(other._globals);
3275   if(!otherg)
3276     return ;
3277   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3278 }
3279
3280 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3281 {
3282   _globals=other._globals;
3283   if((const MEDFileFieldGlobs *)_globals)
3284     _globals=other._globals->deepCopy();
3285 }
3286
3287 /*!
3288  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3289  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3290  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3291  *         \a this and \a other MEDFileFieldGlobsReal.
3292  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3293  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3294  */
3295 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3296 {
3297   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3298   if(thisGlobals==otherGlobals)
3299     return ;
3300   if(!thisGlobals)
3301     {
3302       _globals=other._globals;
3303       return ;
3304     }
3305   _globals->appendGlobs(*other._globals,eps);
3306 }
3307
3308 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3309 {
3310   checkGlobsPflsPartCoherency();
3311   checkGlobsLocsPartCoherency();
3312 }
3313
3314 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3315 {
3316   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3317 }
3318
3319 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3320 {
3321   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3322 }
3323
3324 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3325 {
3326   contentNotNull()->loadProfileInFile(fid,id,pflName);
3327 }
3328
3329 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3330 {
3331   contentNotNull()->loadProfileInFile(fid,id);
3332 }
3333
3334 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3335 {
3336   contentNotNull()->loadGlobals(fid,*this);
3337 }
3338
3339 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3340 {
3341   contentNotNull()->loadAllGlobals(fid);
3342 }
3343
3344 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3345 {
3346   contentNotNull()->writeGlobals(fid,opt);
3347 }
3348
3349 /*!
3350  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3351  * or getPflsReallyUsedMulti().
3352  *  \return std::vector<std::string> - a sequence of names of all profiles.
3353  */
3354 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3355 {
3356   return contentNotNull()->getPfls();
3357 }
3358
3359 /*!
3360  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3361  * or getLocsReallyUsedMulti().
3362  *  \return std::vector<std::string> - a sequence of names of all localizations.
3363  */
3364 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3365 {
3366   return contentNotNull()->getLocs();
3367 }
3368
3369 /*!
3370  * Checks if the profile with a given name exists.
3371  *  \param [in] pflName - the profile name of interest.
3372  *  \return bool - \c true if the profile named \a pflName exists.
3373  */
3374 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3375 {
3376   return contentNotNull()->existsPfl(pflName);
3377 }
3378
3379 /*!
3380  * Checks if the localization with a given name exists.
3381  *  \param [in] locName - the localization name of interest.
3382  *  \return bool - \c true if the localization named \a locName exists.
3383  */
3384 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3385 {
3386   return contentNotNull()->existsLoc(locName);
3387 }
3388
3389 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3390 {
3391   return contentNotNull()->createNewNameOfPfl();
3392 }
3393
3394 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3395 {
3396   return contentNotNull()->createNewNameOfLoc();
3397 }
3398
3399 /*!
3400  * Sets the name of a MED file.
3401  *  \param [inout] fileName - the file name.
3402  */
3403 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3404 {
3405   contentNotNull()->setFileName(fileName);
3406 }
3407
3408 /*!
3409  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3410  * in the same order.
3411  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3412  *          Each item of this sequence is a vector containing ids of equal profiles.
3413  */
3414 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3415 {
3416   return contentNotNull()->whichAreEqualProfiles();
3417 }
3418
3419 /*!
3420  * Finds equal localizations.
3421  *  \param [in] eps - a precision used to compare real values of the localizations.
3422  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3423  *          Each item of this sequence is a vector containing ids of equal localizations.
3424  */
3425 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3426 {
3427   return contentNotNull()->whichAreEqualLocs(eps);
3428 }
3429
3430 /*!
3431  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3432  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3433  *        this sequence is a pair whose 
3434  *        - the first item is a vector of profile names to replace by the second item,
3435  *        - the second item is a profile name to replace every profile name of the first item.
3436  */
3437 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3438 {
3439   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3440 }
3441
3442 /*!
3443  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3444  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3445  *        this sequence is a pair whose 
3446  *        - the first item is a vector of localization names to replace by the second item,
3447  *        - the second item is a localization name to replace every localization name of the first item.
3448  */
3449 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3450 {
3451   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3452 }
3453
3454 /*!
3455  * Replaces references to some profiles (a reference is a profile name) by references
3456  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3457  * them-selves accordingly. <br>
3458  * This method is a generalization of changePflName().
3459  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3460  *        this sequence is a pair whose 
3461  *        - the first item is a vector of profile names to replace by the second item,
3462  *        - the second item is a profile name to replace every profile of the first item.
3463  * \sa changePflsRefsNamesGen()
3464  * \sa changePflName()
3465  */
3466 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3467 {
3468   changePflsRefsNamesGen(mapOfModif);
3469   changePflsNamesInStruct(mapOfModif);
3470 }
3471
3472 /*!
3473  * Replaces references to some localizations (a reference is a localization name) by references
3474  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3475  * them-selves accordingly. <br>
3476  * This method is a generalization of changeLocName().
3477  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3478  *        this sequence is a pair whose 
3479  *        - the first item is a vector of localization names to replace by the second item,
3480  *        - the second item is a localization name to replace every localization of the first item.
3481  * \sa changeLocsRefsNamesGen()
3482  * \sa changeLocName()
3483  */
3484 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3485 {
3486   changeLocsRefsNamesGen(mapOfModif);
3487   changeLocsNamesInStruct(mapOfModif);
3488 }
3489
3490 /*!
3491  * Renames the profile having a given name and updates references to this profile.
3492  *  \param [in] oldName - the name of the profile to rename.
3493  *  \param [in] newName - a new name of the profile.
3494  * \sa changePflsNames().
3495  */
3496 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3497 {
3498   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3499   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3500   mapOfModif[0]=p;
3501   changePflsNames(mapOfModif);
3502 }
3503
3504 /*!
3505  * Renames the localization having a given name and updates references to this localization.
3506  *  \param [in] oldName - the name of the localization to rename.
3507  *  \param [in] newName - a new name of the localization.
3508  * \sa changeLocsNames().
3509  */
3510 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3511 {
3512   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3513   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3514   mapOfModif[0]=p;
3515   changeLocsNames(mapOfModif);
3516 }
3517
3518 /*!
3519  * Removes duplicated profiles. Returns a map used to update references to removed 
3520  * profiles via changePflsRefsNamesGen().
3521  * Equal profiles are found using whichAreEqualProfiles().
3522  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3523  *          a sequence describing the performed replacements of profiles. Each element of
3524  *          this sequence is a pair whose
3525  *          - the first item is a vector of profile names replaced by the second item,
3526  *          - the second item is a profile name replacing every profile of the first item.
3527  */
3528 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3529 {
3530   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3531   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3532   int i=0;
3533   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3534     {
3535       std::vector< std::string > tmp((*it).size());
3536       int j=0;
3537       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3538         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3539       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3540       ret[i]=p;
3541       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3542       killProfileIds(tmp2);
3543     }
3544   changePflsRefsNamesGen(ret);
3545   return ret;
3546 }
3547
3548 /*!
3549  * Removes duplicated localizations. Returns a map used to update references to removed 
3550  * localizations via changeLocsRefsNamesGen().
3551  * Equal localizations are found using whichAreEqualLocs().
3552  *  \param [in] eps - a precision used to compare real values of the localizations.
3553  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3554  *          a sequence describing the performed replacements of localizations. Each element of
3555  *          this sequence is a pair whose
3556  *          - the first item is a vector of localization names replaced by the second item,
3557  *          - the second item is a localization name replacing every localization of the first item.
3558  */
3559 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3560 {
3561   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3562   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3563   int i=0;
3564   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3565     {
3566       std::vector< std::string > tmp((*it).size());
3567       int j=0;
3568       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3569         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3570       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3571       ret[i]=p;
3572       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3573       killLocalizationIds(tmp2);
3574     }
3575   changeLocsRefsNamesGen(ret);
3576   return ret;
3577 }
3578
3579 /*!
3580  * Returns number of Gauss points per cell in a given localization.
3581  *  \param [in] locId - an id of the localization of interest.
3582  *  \return int - the number of the Gauss points per cell.
3583  */
3584 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3585 {
3586   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3587 }
3588
3589 /*!
3590  * Returns an id of a localization by its name.
3591  *  \param [in] loc - the localization name of interest.
3592  *  \return int - the id of the localization.
3593  *  \throw If there is no a localization named \a loc.
3594  */
3595 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3596 {
3597   return contentNotNull()->getLocalizationId(loc);
3598 }
3599
3600 /*!
3601  * Returns the name of the MED file.
3602  *  \return const std::string&  - the MED file name.
3603  */
3604 std::string MEDFileFieldGlobsReal::getFileName() const
3605 {
3606   return contentNotNull()->getFileName();
3607 }
3608
3609 /*!
3610  * Returns a localization object by its name.
3611  *  \param [in] locName - the name of the localization of interest.
3612  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3613  *  \throw If there is no a localization named \a locName.
3614  */
3615 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3616 {
3617   return contentNotNull()->getLocalization(locName);
3618 }
3619
3620 /*!
3621  * Returns a localization object by its id.
3622  *  \param [in] locId - the id of the localization of interest.
3623  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3624  *  \throw If there is no a localization with id \a locId.
3625  */
3626 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3627 {
3628   return contentNotNull()->getLocalizationFromId(locId);
3629 }
3630
3631 /*!
3632  * Returns a profile array by its name.
3633  *  \param [in] pflName - the name of the profile of interest.
3634  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3635  *  \throw If there is no a profile named \a pflName.
3636  */
3637 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3638 {
3639   return contentNotNull()->getProfile(pflName);
3640 }
3641
3642 /*!
3643  * Returns a profile array by its id.
3644  *  \param [in] pflId - the id of the profile of interest.
3645  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3646  *  \throw If there is no a profile with id \a pflId.
3647  */
3648 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3649 {
3650   return contentNotNull()->getProfileFromId(pflId);
3651 }
3652
3653 /*!
3654  * Returns a localization object, apt for modification, by its id.
3655  *  \param [in] locId - the id of the localization of interest.
3656  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3657  *          having the id \a locId.
3658  *  \throw If there is no a localization with id \a locId.
3659  */
3660 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3661 {
3662   return contentNotNull()->getLocalizationFromId(locId);
3663 }
3664
3665 /*!
3666  * Returns a localization object, apt for modification, by its name.
3667  *  \param [in] locName - the name of the localization of interest.
3668  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3669  *          having the name \a locName.
3670  *  \throw If there is no a localization named \a locName.
3671  */
3672 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3673 {
3674   return contentNotNull()->getLocalization(locName);
3675 }
3676
3677 /*!
3678  * Returns a profile array, apt for modification, by its name.
3679  *  \param [in] pflName - the name of the profile of interest.
3680  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3681  *  \throw If there is no a profile named \a pflName.
3682  */
3683 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3684 {
3685   return contentNotNull()->getProfile(pflName);
3686 }
3687
3688 /*!
3689  * Returns a profile array, apt for modification, by its id.
3690  *  \param [in] pflId - the id of the profile of interest.
3691  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3692  *  \throw If there is no a profile with id \a pflId.
3693  */
3694 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3695 {
3696   return contentNotNull()->getProfileFromId(pflId);
3697 }
3698
3699 /*!
3700  * Removes profiles given by their ids. No data is updated to track this removal.
3701  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3702  */
3703 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3704 {
3705   contentNotNull()->killProfileIds(pflIds);
3706 }
3707
3708 /*!
3709  * Removes localizations given by their ids. No data is updated to track this removal.
3710  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3711  */
3712 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3713 {
3714   contentNotNull()->killLocalizationIds(locIds);
3715 }
3716
3717 /*!
3718  * Stores a profile array.
3719  *  \param [in] pfl - the profile array to store.
3720  *  \throw If the name of \a pfl is empty.
3721  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3722  *         different ids.
3723  */
3724 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3725 {
3726   contentNotNull()->appendProfile(pfl);
3727 }
3728
3729 /*!
3730  * Adds a new localization of Gauss points.
3731  *  \param [in] locName - the name of the new localization.
3732  *  \param [in] geoType - a geometrical type of the reference cell.
3733  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3734  *         must be \c nbOfNodesPerCell * \c dimOfType.
3735  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3736  *         must be  _wg_.size() * \c dimOfType.
3737  *  \param [in] w - the weights of Gauss points.
3738  *  \throw If \a locName is empty.
3739  *  \throw If a localization with the name \a locName already exists but is
3740  *         different form the new one.
3741  */
3742 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)
3743 {
3744   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3745 }
3746
3747 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3748 {
3749   MEDFileFieldGlobs *g(_globals);
3750   if(!g)
3751     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3752   return g;
3753 }
3754
3755 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3756 {
3757   const MEDFileFieldGlobs *g(_globals);
3758   if(!g)
3759     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3760   return g;
3761 }
3762
3763 //= MEDFileFieldNameScope
3764
3765 MEDFileFieldNameScope::MEDFileFieldNameScope()
3766 {
3767 }
3768
3769 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3770 {
3771 }
3772
3773 /*!
3774  * Returns the name of \a this field.
3775  *  \return std::string - a string containing the field name.
3776  */
3777 std::string MEDFileFieldNameScope::getName() const
3778 {
3779   return _name;
3780 }
3781
3782 /*!
3783  * Sets name of \a this field
3784  *  \param [in] name - the new field name.
3785  */
3786 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3787 {
3788   _name=fieldName;
3789 }
3790
3791 std::string MEDFileFieldNameScope::getDtUnit() const
3792 {
3793   return _dt_unit;
3794 }
3795
3796 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3797 {
3798   _dt_unit=dtUnit;
3799 }
3800
3801 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3802 {
3803   _name=other._name;
3804   _dt_unit=other._dt_unit;
3805 }
3806
3807 //= MEDFileAnyTypeField1TSWithoutSDA
3808
3809 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3810 {
3811   _field_per_mesh.resize(other._field_per_mesh.size());
3812   std::size_t i=0;
3813   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3814     {
3815       if((const MEDFileFieldPerMesh *)*it)
3816         _field_per_mesh[i]=(*it)->deepCopy(this);
3817     }
3818 }
3819
3820 /*!
3821  * Prints a string describing \a this field into a stream. This string is outputted 
3822  * by \c print Python command.
3823  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3824  *  \param [in,out] oss - the out stream.
3825  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3826  *          info id printed, else, not.
3827  */
3828 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3829 {
3830   std::string startOfLine(bkOffset,' ');
3831   oss << startOfLine << "Field ";
3832   if(bkOffset==0)
3833     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3834   oss << "on one time Step ";
3835   if(f1tsId>=0)
3836     oss << "(" << f1tsId << ") ";
3837   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3838   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3839   const DataArray *arr=getUndergroundDataArray();
3840   if(arr)
3841     {
3842       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3843       if(f1tsId<0)
3844         {
3845           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3846           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3847             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3848         }
3849       if(arr->isAllocated())
3850         {
3851           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3852         }
3853       else
3854         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3855     }
3856   else
3857     {
3858       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3859     }
3860   oss << startOfLine << "----------------------" << std::endl;
3861   if(!_field_per_mesh.empty())
3862     {
3863       int i=0;
3864       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3865         {
3866           const MEDFileFieldPerMesh *cur=(*it2);
3867           if(cur)
3868             cur->simpleRepr(bkOffset,oss,i);
3869           else
3870             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3871         }
3872     }
3873   else
3874     {
3875       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3876     }
3877   oss << startOfLine << "----------------------" << std::endl;
3878 }
3879
3880 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3881 {
3882   const DataArray *arr(getUndergroundDataArray());
3883   if(!arr)
3884     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3885   int nbOfCompo=arr->getNumberOfComponents();
3886   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3887   for(int i=0;i<nbOfCompo;i++)
3888     {
3889       ret[i]=deepCopy();
3890       std::vector<int> v(1,i);
3891       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
3892       ret[i]->setArray(arr2);
3893     }
3894   return ret;
3895 }
3896
3897 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)
3898 {
3899 }
3900
3901 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3902 {
3903 }
3904
3905 /*!
3906  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3907  * empty. Returns -1 if this in on nodes.
3908  *  \return int - the dimension of \a this.
3909  */
3910 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3911 {
3912   int ret=-2;
3913   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3914     (*it)->getDimension(ret);
3915   return ret;
3916 }
3917
3918 /*!
3919  * Returns the mesh name.
3920  *  \return std::string - a string holding the mesh name.
3921  *  \throw If \c _field_per_mesh.empty()
3922  */
3923 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3924 {
3925   if(_field_per_mesh.empty())
3926     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3927   return _field_per_mesh[0]->getMeshName();
3928 }
3929
3930 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3931 {
3932   std::string oldName(getMeshName());
3933   std::vector< std::pair<std::string,std::string> > v(1);
3934   v[0].first=oldName; v[0].second=newMeshName;
3935   changeMeshNames(v);
3936 }
3937
3938 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3939 {
3940   bool ret=false;
3941   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3942     {
3943       MEDFileFieldPerMesh *cur(*it);
3944       if(cur)
3945         ret=cur->changeMeshNames(modifTab) || ret;
3946     }
3947   return ret;
3948 }
3949
3950 /*!
3951  * Returns the number of iteration of the state of underlying mesh.
3952  *  \return int - the iteration number.
3953  *  \throw If \c _field_per_mesh.empty()
3954  */
3955 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3956 {
3957   if(_field_per_mesh.empty())
3958     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3959   return _field_per_mesh[0]->getMeshIteration();
3960 }
3961
3962 /*!
3963  * Returns the order number of iteration of the state of underlying mesh.
3964  *  \return int - the order number.
3965  *  \throw If \c _field_per_mesh.empty()
3966  */
3967 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3968 {
3969   if(_field_per_mesh.empty())
3970     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3971   return _field_per_mesh[0]->getMeshOrder();
3972 }
3973
3974 /*!
3975  * Checks if \a this field is tagged by a given iteration number and a given
3976  * iteration order number.
3977  *  \param [in] iteration - the iteration number of interest.
3978  *  \param [in] order - the iteration order number of interest.
3979  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3980  *          \a this->getOrder() == \a order.
3981  */
3982 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3983 {
3984   return iteration==_iteration && order==_order;
3985 }
3986
3987 /*!
3988  * Returns number of iteration and order number of iteration when
3989  * \a this field has been calculated.
3990  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3991  *          order number.
3992  */
3993 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3994 {
3995   std::pair<int,int> p;
3996   fillIteration(p);
3997   return p;
3998 }
3999
4000 /*!
4001  * Returns number of iteration and order number of iteration when
4002  * \a this field has been calculated.
4003  *  \param [in,out] p - a pair returning the iteration number and the iteration
4004  *          order number.
4005  */
4006 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4007 {
4008   p.first=_iteration;
4009   p.second=_order;
4010 }
4011
4012 /*!
4013  * Returns all types of spatial discretization of \a this field.
4014  *  \param [in,out] types - a sequence of types of \a this field.
4015  */
4016 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4017 {
4018   std::set<TypeOfField> types2;
4019   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4020     {
4021       (*it)->fillTypesOfFieldAvailable(types2);
4022     }
4023   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4024   std::copy(types2.begin(),types2.end(),bi);
4025 }
4026
4027 /*!
4028  * Returns all types of spatial discretization of \a this field.
4029  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4030  *          of \a this field.
4031  */
4032 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4033 {
4034   std::vector<TypeOfField> ret;
4035   fillTypesOfFieldAvailable(ret);
4036   return ret;
4037 }
4038
4039 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4040 {
4041   std::vector<std::string> ret;
4042   std::set<std::string> ret2;
4043   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4044     {
4045       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4046       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4047         if(ret2.find(*it2)==ret2.end())
4048           {
4049             ret.push_back(*it2);
4050             ret2.insert(*it2);
4051           }
4052     }
4053   return ret;
4054 }
4055
4056 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4057 {
4058   std::vector<std::string> ret;
4059   std::set<std::string> ret2;
4060   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4061     {
4062       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4063       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4064         if(ret2.find(*it2)==ret2.end())
4065           {
4066             ret.push_back(*it2);
4067             ret2.insert(*it2);
4068           }
4069     }
4070   return ret;
4071 }
4072
4073 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4074 {
4075   std::vector<std::string> ret;
4076   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4077     {
4078       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4079       ret.insert(ret.end(),tmp.begin(),tmp.end());
4080     }
4081   return ret;
4082 }
4083
4084 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4085 {
4086   std::vector<std::string> ret;
4087   std::set<std::string> ret2;
4088   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4089     {
4090       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4091       ret.insert(ret.end(),tmp.begin(),tmp.end());
4092     }
4093   return ret;
4094 }
4095
4096 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4097 {
4098   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4099     (*it)->changePflsRefsNamesGen(mapOfModif);
4100 }
4101
4102 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4103 {
4104   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4105     (*it)->changeLocsRefsNamesGen(mapOfModif);
4106 }
4107
4108 /*!
4109  * Returns all attributes of parts of \a this field lying on a given mesh.
4110  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4111  * item of every of returned sequences refers to the _i_-th part of \a this field.
4112  * Thus all sequences returned by this method are of the same length equal to number
4113  * of different types of supporting entities.<br>
4114  * A field part can include sub-parts with several different spatial discretizations,
4115  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4116  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4117  * of a nested sequence corresponds to a type of spatial discretization.<br>
4118  * This method allows for iteration over MEDFile DataStructure without any overhead.
4119  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4120  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4121  *          not checked if \a mname == \c NULL).
4122  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4123  *          a field part is returned. 
4124  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4125  *          This sequence is of the same length as \a types. 
4126  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4127  *          discretization. A profile name can be empty.
4128  *          Length of this and of nested sequences is the same as that of \a typesF.
4129  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4130  *          discretization. A localization name can be empty.
4131  *          Length of this and of nested sequences is the same as that of \a typesF.
4132  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4133  *          of ids of tuples within the data array, per each type of spatial
4134  *          discretization within one mesh entity type. 
4135  *          Length of this and of nested sequences is the same as that of \a typesF.
4136  *  \throw If no field is lying on \a mname.
4137  */
4138 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
4139 {
4140   int meshId=0;
4141   if(!mname.empty())
4142     meshId=getMeshIdFromMeshName(mname);
4143   else
4144     if(_field_per_mesh.empty())
4145       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4146   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4147 }
4148
4149 /*!
4150  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4151  * maximal absolute dimension and values returned via the out parameter \a levs are 
4152  * dimensions relative to the maximal absolute dimension. <br>
4153  * This method is designed for MEDFileField1TS instances that have a discretization
4154  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4155  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4156  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4157  * Only these 3 discretizations will be taken into account here. If \a this is
4158  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4159  * This method is useful to make the link between the dimension of the underlying mesh
4160  * and the levels of \a this, because it is possible that the highest dimension of \a this
4161  * field is not equal to the dimension of the underlying mesh.
4162  * 
4163  * Let's consider the following case:
4164  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4165  * TETRA4, HEXA8, TRI3 and SEG2.
4166  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4167  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4168  *
4169  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4170  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4171  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4172  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4173  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4174  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4175  * For example<br>
4176  * to retrieve the highest level of
4177  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4178  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4179  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4180  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4181  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4182  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4183  *          not checked if \a mname == \c NULL).
4184  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4185  *          absolute one. They are in decreasing order. This sequence is cleared before
4186  *          filling it in.
4187  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4188  *  \throw If no field is lying on \a mname.
4189  */
4190 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4191 {
4192   levs.clear();
4193   int meshId=getMeshIdFromMeshName(mname);
4194   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4195   std::vector< std::vector<TypeOfField> > typesF;
4196   std::vector< std::vector<std::string> > pfls, locs;
4197   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4198   if(types.empty())
4199     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4200   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4201   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4202     return -1;
4203   st.erase(INTERP_KERNEL::NORM_ERROR);
4204   std::set<int> ret1;
4205   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4206     {
4207       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4208       ret1.insert((int)cm.getDimension());
4209     }
4210   int ret=*std::max_element(ret1.begin(),ret1.end());
4211   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4212   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4213   return ret;
4214 }
4215
4216 /*!
4217  * \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.
4218  * \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.
4219  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4220  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4221  */
4222 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4223 {
4224   int mid=getMeshIdFromMeshName(mName);
4225   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4226 }
4227
4228 /*!
4229  * \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.
4230  * \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.
4231  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4232  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4233  */
4234 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4235 {
4236   int mid=getMeshIdFromMeshName(mName);
4237   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4238 }
4239
4240 /*!
4241  * \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.
4242  */
4243 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4244 {
4245   if(_field_per_mesh.empty())
4246     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4247   if(mName.empty())
4248     return 0;
4249   std::string mName2(mName);
4250   int ret=0;
4251   std::vector<std::string> msg;
4252   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4253     if(mName2==(*it)->getMeshName())
4254       return ret;
4255     else
4256       msg.push_back((*it)->getMeshName());
4257   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4258   oss << "Possible meshes are : ";
4259   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4260     oss << "\"" << (*it2) << "\" ";
4261   throw INTERP_KERNEL::Exception(oss.str().c_str());
4262 }
4263
4264 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4265 {
4266   if(!mesh)
4267     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4268   std::string tmp(mesh->getName());
4269   if(tmp.empty())
4270     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4271   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4272   int i=0;
4273   for(;it!=_field_per_mesh.end();it++,i++)
4274     {
4275       if((*it)->getMeshName()==tmp)
4276         return i;
4277     }
4278   int sz=_field_per_mesh.size();
4279   _field_per_mesh.resize(sz+1);
4280   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4281   return sz;
4282 }
4283
4284 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4285                                                                    MEDFileFieldGlobsReal& glob)
4286 {
4287   bool ret=false;
4288   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4289     {
4290       MEDFileFieldPerMesh *fpm(*it);
4291       if(fpm)
4292         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4293     }
4294   return ret;
4295 }
4296
4297 /*!
4298  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4299  * splitting that leads to single spatial discretization of this.
4300  *
4301  * \sa splitMultiDiscrPerGeoTypes
4302  */
4303 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4304 {
4305   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4306   std::vector< std::vector<TypeOfField> > typesF;
4307   std::vector< std::vector<std::string> > pfls,locs;
4308   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4309   std::set<TypeOfField> allEnt;
4310   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4311     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4312       allEnt.insert(*it2);
4313   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4314   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4315   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4316     {
4317       std::vector< std::pair<int,int> > its;
4318       ret[i]=shallowCpy();
4319       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4320       ret[i]->updateData(newLgth,its);
4321     }
4322   return ret;
4323 }
4324
4325 /*!
4326  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4327  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4328  *
4329  * \sa splitDiscretizations
4330  */
4331 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4332 {
4333   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4334   std::vector< std::vector<TypeOfField> > typesF;
4335   std::vector< std::vector<std::string> > pfls,locs;
4336   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4337   std::set<TypeOfField> allEnt;
4338   std::size_t nbOfMDPGT(0),ii(0);
4339   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4340     {
4341       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4342       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4343         allEnt.insert(*it2);
4344     }
4345   if(allEnt.size()!=1)
4346     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4347   if(nbOfMDPGT==0)
4348     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4349   if(nbOfMDPGT==1)
4350     {
4351       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4352       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4353       return ret0;
4354     }
4355   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4356   for(std::size_t i=0;i<nbOfMDPGT;i++)
4357     {
4358       std::vector< std::pair<int,int> > its;
4359       ret[i]=shallowCpy();
4360       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4361       ret[i]->updateData(newLgth,its);
4362     }
4363   return ret;
4364 }
4365
4366 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4367 {
4368   int globalCounter(0);
4369   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4370     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4371   return globalCounter;
4372 }
4373
4374 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4375 {
4376   int globalCounter(0);
4377   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4378     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4379   return globalCounter;
4380 }
4381
4382 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4383 {
4384   if(_nb_of_tuples_to_be_allocated>=0)
4385     {
4386       _nb_of_tuples_to_be_allocated=newLgth;
4387       const DataArray *oldArr(getUndergroundDataArray());
4388       if(oldArr)
4389         {
4390           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4391           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4392           setArray(newArr);
4393           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4394         }
4395       return ;
4396     }
4397   if(_nb_of_tuples_to_be_allocated==-1)
4398     return ;
4399   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4400     {
4401       const DataArray *oldArr(getUndergroundDataArray());
4402       if(!oldArr || !oldArr->isAllocated())
4403         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4404       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4405       newArr->alloc(newLgth,getNumberOfComponents());
4406       if(oldArr)
4407         newArr->copyStringInfoFrom(*oldArr);
4408       int pos=0;
4409       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4410         {
4411           if((*it).second<(*it).first)
4412             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4413           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4414           pos+=(*it).second-(*it).first;
4415         }
4416       setArray(newArr);
4417       return ;
4418     }
4419   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4420 }
4421
4422 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4423 {
4424   if(_field_per_mesh.empty())
4425     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4426   if(_field_per_mesh.size()>1)
4427     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4428   _field_per_mesh[0]->copyOptionsFrom(opts);
4429   _field_per_mesh[0]->writeLL(fid,nasc);
4430 }
4431
4432 /*!
4433  * 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.
4434  * If false is returned the memory allocation is not required.
4435  */
4436 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4437 {
4438   if(_nb_of_tuples_to_be_allocated>=0)
4439     {
4440       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4441       _nb_of_tuples_to_be_allocated=-2;
4442       return true;
4443     }
4444   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4445     return false;
4446   if(_nb_of_tuples_to_be_allocated==-1)
4447     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4448   if(_nb_of_tuples_to_be_allocated<-3)
4449     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4450   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4451 }
4452
4453 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4454 {
4455   med_int numdt,numit;
4456   med_float dt;
4457   med_int nmesh;
4458   med_bool localMesh;
4459   med_int meshnumdt,meshnumit;
4460   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4461   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4462   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4463   if(_iteration!=numdt || _order!=numit)
4464     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4465   _field_per_mesh.resize(nmesh);
4466   //
4467   MEDFileMesh *mm(0);
4468   if(ms)
4469     {
4470       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4471       mm=ms->getMeshWithName(meshNameCpp);
4472     }
4473   //
4474   for(int i=0;i<nmesh;i++)
4475     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4476   _nb_of_tuples_to_be_allocated=0;
4477   for(int i=0;i<nmesh;i++)
4478     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4479 }
4480
4481 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4482 {
4483   allocIfNecessaryTheArrayToReceiveDataFromFile();
4484   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4485     (*it)->loadBigArraysRecursively(fid,nasc);
4486 }
4487
4488 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4489 {
4490   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4491     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4492       (*it)->loadBigArraysRecursively(fid,nasc);
4493 }
4494
4495 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4496 {
4497   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4498   loadBigArraysRecursively(fid,nasc);
4499 }
4500
4501 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4502 {
4503   DataArray *thisArr(getUndergroundDataArray());
4504   if(thisArr && thisArr->isAllocated())
4505     {
4506       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4507       thisArr->desallocate();
4508     }
4509 }
4510
4511 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4512 {
4513   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
4514 }
4515
4516 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4517 {
4518   std::vector<const BigMemoryObject *> ret;
4519   if(getUndergroundDataArray())
4520     ret.push_back(getUndergroundDataArray());
4521   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4522     ret.push_back((const MEDFileFieldPerMesh *)*it);
4523   return ret;
4524 }
4525
4526 /*!
4527  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4528  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4529  * "Sort By Type"), if not, an exception is thrown. 
4530  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4531  *  \param [in] arr - the array of values.
4532  *  \param [in,out] glob - the global data where profiles and localization present in
4533  *          \a field, if any, are added.
4534  *  \throw If the name of \a field is empty.
4535  *  \throw If the data array of \a field is not set.
4536  *  \throw If \a this->_arr is already allocated but has different number of components
4537  *         than \a field.
4538  *  \throw If the underlying mesh of \a field has no name.
4539  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4540  */
4541 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4542 {
4543   const MEDCouplingMesh *mesh=field->getMesh();
4544   //
4545   TypeOfField type=field->getTypeOfField();
4546   std::vector<DataArrayInt *> dummy;
4547   int start=copyTinyInfoFrom(field,arr);
4548   int pos=addNewEntryIfNecessary(mesh);
4549   if(type!=ON_NODES)
4550     {
4551       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4552       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4553     }
4554   else
4555     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4556 }
4557
4558 /*!
4559  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4560  * of a given mesh are used as the support of the given field (a real support is not used). 
4561  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4562  * Order of underlying mesh entities of the given field specified by \a profile parameter
4563  * is not prescribed; this method permutes field values to have them sorted by element
4564  * type as required for writing to MED file. A new profile is added only if no equal
4565  * profile is missing. 
4566  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4567  *  \param [in] arrOfVals - the values of the field \a field used.
4568  *  \param [in] mesh - the supporting mesh of \a field.
4569  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4570  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4571  *  \param [in,out] glob - the global data where profiles and localization present in
4572  *          \a field, if any, are added.
4573  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4574  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4575  *  \throw If the data array of \a field is not set.
4576  *  \throw If \a this->_arr is already allocated but has different number of components
4577  *         than \a field.
4578  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4579  *  \sa setFieldNoProfileSBT()
4580  */
4581 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4582 {
4583   if(!field)
4584     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4585   if(!arrOfVals || !arrOfVals->isAllocated())
4586     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4587   TypeOfField type=field->getTypeOfField();
4588   std::vector<DataArrayInt *> idsInPflPerType;
4589   std::vector<DataArrayInt *> idsPerType;
4590   std::vector<int> code,code2;
4591   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4592   if(type!=ON_NODES)
4593     {
4594       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4595       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4596       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4597       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4598       // start of check
4599       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
4600       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4601       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4602         {
4603           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4604           throw INTERP_KERNEL::Exception(oss.str().c_str());
4605         }
4606       // end of check
4607       int start=copyTinyInfoFrom(field,arrOfVals);
4608       code2=m->getDistributionOfTypes();
4609       //
4610       int pos=addNewEntryIfNecessary(m);
4611       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4612     }
4613   else
4614     {
4615       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4616         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4617       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4618       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4619       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4620       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4621         {
4622           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4623           throw INTERP_KERNEL::Exception(oss.str().c_str());
4624         }
4625       int start=copyTinyInfoFrom(field,arrOfVals);
4626       int pos=addNewEntryIfNecessary(m);
4627       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4628     }
4629 }
4630
4631 /*!
4632  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4633  */
4634 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4635 {
4636   if(_nb_of_tuples_to_be_allocated>=0)
4637     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 !");
4638   DataArray *arr(getOrCreateAndGetArray());
4639   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4640   _nb_of_tuples_to_be_allocated=-3;
4641 }
4642
4643 /*!
4644  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4645  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4646  * larger by the size of \a field. Returns an id of the first not filled
4647  * tuple of \a this->_arr.
4648  *  \param [in] field - the field to copy the info on components and the name from.
4649  *  \return int - the id of first not initialized tuple of \a this->_arr.
4650  *  \throw If the name of \a field is empty.
4651  *  \throw If the data array of \a field is not set.
4652  *  \throw If \a this->_arr is already allocated but has different number of components
4653  *         than \a field.
4654  */
4655 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4656 {
4657   if(!field)
4658     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4659   std::string name(field->getName());
4660   setName(name.c_str());
4661   setDtUnit(field->getTimeUnit());
4662   if(name.empty())
4663     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4664   if(!arr)
4665     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4666   if(!arr->isAllocated())
4667     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4668   _dt=field->getTime(_iteration,_order);
4669   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4670   if(!getOrCreateAndGetArray()->isAllocated())
4671     {
4672       allocNotFromFile(arr->getNumberOfTuples());
4673       return 0;
4674     }
4675   else
4676     {
4677       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4678       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4679       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4680       _nb_of_tuples_to_be_allocated=-3;
4681       return oldNbOfTuples;
4682     }
4683 }
4684
4685 /*!
4686  * Returns number of components in \a this field
4687  *  \return int - the number of components.
4688  */
4689 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4690 {
4691   return getOrCreateAndGetArray()->getNumberOfComponents();
4692 }
4693
4694 /*!
4695  * Change info on components in \a this.
4696  * \throw If size of \a infos is not equal to the number of components already in \a this.
4697  */
4698 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4699 {
4700   DataArray *arr=getOrCreateAndGetArray();
4701   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4702 }
4703
4704 /*!
4705  * Returns info on components of \a this field.
4706  *  \return const std::vector<std::string>& - a sequence of strings each being an
4707  *          information on _i_-th component.
4708  */
4709 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4710 {
4711   const DataArray *arr=getOrCreateAndGetArray();
4712   return arr->getInfoOnComponents();
4713 }
4714
4715 /*!
4716  * Returns a mutable info on components of \a this field.
4717  *  \return std::vector<std::string>& - a sequence of strings each being an
4718  *          information on _i_-th component.
4719  */
4720 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4721 {
4722   DataArray *arr=getOrCreateAndGetArray();
4723   return arr->getInfoOnComponents();
4724 }
4725
4726 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4727 {
4728   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4729     {
4730       const MEDFileFieldPerMesh *fpm(*it);
4731       if(!fpm)
4732         continue;
4733       if(fpm->presenceOfMultiDiscPerGeoType())
4734         return true;
4735     }
4736   return false;
4737 }
4738
4739 /*!
4740  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4741  *  \param [in] type - a spatial discretization of the new field.
4742  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4743  *  \param [in] mName - a name of the supporting mesh.
4744  *  \param [in] renumPol - specifies how to permute values of the result field according to
4745  *          the optional numbers of cells and nodes, if any. The valid values are
4746  *          - 0 - do not permute.
4747  *          - 1 - permute cells.
4748  *          - 2 - permute nodes.
4749  *          - 3 - permute cells and nodes.
4750  *
4751  *  \param [in] glob - the global data storing profiles and localization.
4752  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4753  *          caller is to delete this field using decrRef() as it is no more needed. 
4754  *  \throw If the MED file is not readable.
4755  *  \throw If there is no mesh named \a mName in the MED file.
4756  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4757  *  \throw If no field of \a this is lying on the mesh \a mName.
4758  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4759  */
4760 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4761 {
4762   MCAuto<MEDFileMesh> mm;
4763   if(mName.empty())
4764     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4765   else
4766     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4767   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4768 }
4769
4770 /*!
4771  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4772  *  \param [in] type - a spatial discretization of the new field.
4773  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4774  *  \param [in] renumPol - specifies how to permute values of the result field according to
4775  *          the optional numbers of cells and nodes, if any. The valid values are
4776  *          - 0 - do not permute.
4777  *          - 1 - permute cells.
4778  *          - 2 - permute nodes.
4779  *          - 3 - permute cells and nodes.
4780  *
4781  *  \param [in] glob - the global data storing profiles and localization.
4782  *  \param [in] mesh - the supporting mesh.
4783  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4784  *          caller is to delete this field using decrRef() as it is no more needed. 
4785  *  \throw If the MED file is not readable.
4786  *  \throw If no field of \a this is lying on \a mesh.
4787  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4788  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4789  */
4790 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4791 {
4792   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
4793   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4794   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4795   if(meshDimRelToMax==1)
4796     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4797   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4798 }
4799
4800 /*!
4801  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4802  * given mesh. 
4803  *  \param [in] type - a spatial discretization of the new field.
4804  *  \param [in] mName - a name of the supporting mesh.
4805  *  \param [in] renumPol - specifies how to permute values of the result field according to
4806  *          the optional numbers of cells and nodes, if any. The valid values are
4807  *          - 0 - do not permute.
4808  *          - 1 - permute cells.
4809  *          - 2 - permute nodes.
4810  *          - 3 - permute cells and nodes.
4811  *
4812  *  \param [in] glob - the global data storing profiles and localization.
4813  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4814  *          caller is to delete this field using decrRef() as it is no more needed. 
4815  *  \throw If the MED file is not readable.
4816  *  \throw If there is no mesh named \a mName in the MED file.
4817  *  \throw If there are no mesh entities in the mesh.
4818  *  \throw If no field values of the given \a type are available.
4819  */
4820 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4821 {
4822   MCAuto<MEDFileMesh> mm;
4823   if(mName.empty())
4824     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4825   else
4826     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4827   int absDim=getDimension();
4828   int meshDimRelToMax=absDim-mm->getMeshDimension();
4829   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4830 }
4831
4832 /*!
4833  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4834  *  \param [in] type - a spatial discretization of the new field.
4835  *  \param [in] renumPol - specifies how to permute values of the result field according to
4836  *          the optional numbers of cells and nodes, if any. The valid values are
4837  *          - 0 - do not permute.
4838  *          - 1 - permute cells.
4839  *          - 2 - permute nodes.
4840  *          - 3 - permute cells and nodes.
4841  *
4842  *  \param [in] glob - the global data storing profiles and localization.
4843  *  \param [in] mesh - the supporting mesh.
4844  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4845  *         field according to \a renumPol.
4846  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4847  *         field according to \a renumPol.
4848  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4849  *          caller is to delete this field using decrRef() as it is no more needed. 
4850  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4851  *  \throw If no field of \a this is lying on \a mesh.
4852  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4853  */
4854 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
4855 {
4856   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4857   int meshId=getMeshIdFromMeshName(mesh->getName());
4858   bool isPfl=false;
4859   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4860   switch(renumPol)
4861   {
4862     case 0:
4863       {
4864         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4865         return ret.retn();
4866       }
4867     case 3:
4868     case 1:
4869       {
4870         if(isPfl)
4871           throw INTERP_KERNEL::Exception(msg1);
4872         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4873         if(cellRenum)
4874           {
4875             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4876               {
4877                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4878                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4879                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4880               }
4881             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4882             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4883             std::vector<DataArray *> arrOut2(1,arrOut);
4884             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4885             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4886             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4887           }
4888         if(renumPol==1)
4889           return ret.retn();
4890       }
4891     case 2:
4892       {
4893         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4894         if(isPfl)
4895           throw INTERP_KERNEL::Exception(msg1);
4896         if(nodeRenum)
4897           {
4898             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4899               {
4900                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4901                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4902                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4903               }
4904             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4905             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4906               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4907             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4908           }
4909         return ret.retn();
4910       }
4911     default:
4912       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4913   }
4914 }
4915
4916 /*!
4917  * Returns values and a profile of the field of a given type lying on a given support.
4918  *  \param [in] type - a spatial discretization of the field.
4919  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4920  *  \param [in] mesh - the supporting mesh.
4921  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4922  *          field of interest lies on. If the field lies on all entities of the given
4923  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4924  *          using decrRef() as it is no more needed.  
4925  *  \param [in] glob - the global data storing profiles and localization.
4926  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4927  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4928  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4929  *  \throw If no field of \a this is lying on \a mesh.
4930  *  \throw If no field values of the given \a type are available.
4931  */
4932 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4933 {
4934   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4935   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4936   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4937   ret->setName(nasc.getName().c_str());
4938   return ret.retn();
4939 }
4940
4941 //= MEDFileField1TSWithoutSDA
4942
4943 /*!
4944  * Throws if a given value is not a valid (non-extended) relative dimension.
4945  *  \param [in] meshDimRelToMax - the relative dimension value.
4946  *  \throw If \a meshDimRelToMax > 0.
4947  */
4948 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4949 {
4950   if(meshDimRelToMax>0)
4951     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4952 }
4953
4954 /*!
4955  * Checks if elements of a given mesh are in the order suitable for writing 
4956  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4957  * vector describing types of elements and their number.
4958  *  \param [in] mesh - the mesh to check.
4959  *  \return std::vector<int> - a vector holding for each element type (1) item of
4960  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4961  *          These values are in full-interlace mode.
4962  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4963  */
4964 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4965 {
4966   if(!mesh)
4967     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4968   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4969   int nbOfTypes=geoTypes.size();
4970   std::vector<int> code(3*nbOfTypes);
4971   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
4972   arr1->alloc(nbOfTypes,1);
4973   int *arrPtr=arr1->getPointer();
4974   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4975   for(int i=0;i<nbOfTypes;i++,it++)
4976     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4977   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4978   const int *arrPtr2=arr2->getConstPointer();
4979   int i=0;
4980   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4981     {
4982       int pos=arrPtr2[i];
4983       int nbCells=mesh->getNumberOfCellsWithType(*it);
4984       code[3*pos]=(int)(*it);
4985       code[3*pos+1]=nbCells;
4986       code[3*pos+2]=-1;//no profiles
4987     }
4988   std::vector<const DataArrayInt *> idsPerType;//no profiles
4989   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4990   if(da)
4991     {
4992       da->decrRef();
4993       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4994     }
4995   return code;
4996 }
4997
4998 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4999 {
5000   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5001 }
5002
5003 /*!
5004  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5005  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5006  * item of every of returned sequences refers to the _i_-th part of \a this field.
5007  * Thus all sequences returned by this method are of the same length equal to number
5008  * of different types of supporting entities.<br>
5009  * A field part can include sub-parts with several different spatial discretizations,
5010  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5011  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5012  * of a nested sequence corresponds to a type of spatial discretization.<br>
5013  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5014  * The overhead is due to selecting values into new instances of DataArrayDouble.
5015  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5016  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5017  *          not checked if \a mname == \c NULL).
5018  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5019  *          a field part is returned. 
5020  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5021  *          A field part can include sub-parts with several different spatial discretizations,
5022  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5023  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5024  *          This sequence is of the same length as \a types. 
5025  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5026  *          discretization. A profile name can be empty.
5027  *          Length of this and of nested sequences is the same as that of \a typesF.
5028  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5029  *          discretization. A localization name can be empty.
5030  *          Length of this and of nested sequences is the same as that of \a typesF.
5031  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5032  *          per each type of spatial discretization within one mesh entity type.
5033  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5034  *          Length of this and of nested sequences is the same as that of \a typesF.
5035  *  \throw If no field is lying on \a mname.
5036  */
5037 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
5038 {
5039   int meshId=0;
5040   if(!mname.empty())
5041     meshId=getMeshIdFromMeshName(mname);
5042   else
5043     if(_field_per_mesh.empty())
5044       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5045   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5046   int nbOfRet=ret0.size();
5047   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5048   for(int i=0;i<nbOfRet;i++)
5049     {
5050       const std::vector< std::pair<int,int> >& p=ret0[i];
5051       int nbOfRet1=p.size();
5052       ret[i].resize(nbOfRet1);
5053       for(int j=0;j<nbOfRet1;j++)
5054         {
5055           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5056           ret[i][j]=tmp;
5057         }
5058     }
5059   return ret;
5060 }
5061
5062 /*!
5063  * Returns a pointer to the underground DataArrayDouble instance. So the
5064  * caller should not decrRef() it. This method allows for a direct access to the field
5065  * values. This method is quite unusable if there is more than a nodal field or a cell
5066  * field on single geometric cell type. 
5067  *  \return DataArrayDouble * - the pointer to the field values array.
5068  */
5069 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
5070 {
5071   const DataArrayDouble *ret=_arr;
5072   if(ret)
5073     return const_cast<DataArrayDouble *>(ret);
5074   else
5075     return 0;
5076 }
5077
5078 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5079 {
5080   return TYPE_STR;
5081 }
5082
5083 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5084 {
5085   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5086   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5087   ret->deepCpyLeavesFrom(*this);
5088   const DataArrayDouble *arr(_arr);
5089   if(arr)
5090     {
5091       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5092       ret->setArray(arr2);
5093     }
5094   return ret.retn();
5095 }
5096
5097 /*!
5098  * Returns a pointer to the underground DataArrayDouble instance. So the
5099  * caller should not decrRef() it. This method allows for a direct access to the field
5100  * values. This method is quite unusable if there is more than a nodal field or a cell
5101  * field on single geometric cell type. 
5102  *  \return DataArrayDouble * - the pointer to the field values array.
5103  */
5104 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
5105 {
5106   return getUndergroundDataArrayDouble();
5107 }
5108
5109 /*!
5110  * Returns a pointer to the underground DataArrayDouble instance and a
5111  * sequence describing parameters of a support of each part of \a this field. The
5112  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5113  * direct access to the field values. This method is intended for the field lying on one
5114  * mesh only.
5115  *  \param [in,out] entries - the sequence describing parameters of a support of each
5116  *         part of \a this field. Each item of this sequence consists of two parts. The
5117  *         first part describes a type of mesh entity and an id of discretization of a
5118  *         current field part. The second part describes a range of values [begin,end)
5119  *         within the returned array relating to the current field part.
5120  *  \return DataArrayDouble * - the pointer to the field values array.
5121  *  \throw If the number of underlying meshes is not equal to 1.
5122  *  \throw If no field values are available.
5123  *  \sa getUndergroundDataArray()
5124  */
5125 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5126 {
5127   if(_field_per_mesh.size()!=1)
5128     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5129   if(_field_per_mesh[0]==0)
5130     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5131   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5132   return getUndergroundDataArrayDouble();
5133 }
5134
5135 /*!
5136  * Returns a pointer to the underground DataArrayDouble instance and a
5137  * sequence describing parameters of a support of each part of \a this field. The
5138  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5139  * direct access to the field values. This method is intended for the field lying on one
5140  * mesh only.
5141  *  \param [in,out] entries - the sequence describing parameters of a support of each
5142  *         part of \a this field. Each item of this sequence consists of two parts. The
5143  *         first part describes a type of mesh entity and an id of discretization of a
5144  *         current field part. The second part describes a range of values [begin,end)
5145  *         within the returned array relating to the current field part.
5146  *  \return DataArrayDouble * - the pointer to the field values array.
5147  *  \throw If the number of underlying meshes is not equal to 1.
5148  *  \throw If no field values are available.
5149  *  \sa getUndergroundDataArray()
5150  */
5151 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5152 {
5153   return getUndergroundDataArrayDoubleExt(entries);
5154 }
5155
5156 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5157 {
5158   DataArrayDouble *arr(getOrCreateAndGetArrayDouble());
5159   arr->setInfoAndChangeNbOfCompo(infos);
5160 }
5161
5162 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5163 {
5164 }
5165
5166 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5167 {
5168   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5169   ret->deepCpyLeavesFrom(*this);
5170   return ret.retn();
5171 }
5172
5173 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5174 {
5175   MCAuto<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5176   if((const DataArrayDouble *)_arr)
5177     ret->_arr=_arr->deepCopy();
5178   return ret.retn();
5179 }
5180
5181 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
5182 {
5183   if(!arr)
5184     {
5185       _nb_of_tuples_to_be_allocated=-1;
5186       _arr=0;
5187       return ;
5188     }
5189   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
5190   if(!arrC)
5191     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
5192   else
5193     _nb_of_tuples_to_be_allocated=-3;
5194   arrC->incrRef();
5195   _arr=arrC;
5196 }
5197
5198 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5199 {
5200   return DataArrayDouble::New();
5201 }
5202
5203 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
5204 {
5205   DataArrayDouble *ret=_arr;
5206   if(ret)
5207     return ret;
5208   _arr=DataArrayDouble::New();
5209   return _arr;
5210 }
5211
5212 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
5213 {
5214   return getOrCreateAndGetArrayDouble();
5215 }
5216
5217 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
5218 {
5219   const DataArrayDouble *ret=_arr;
5220   if(ret)
5221     return ret;
5222   DataArrayDouble *ret2=DataArrayDouble::New();
5223   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
5224   return ret2;
5225 }
5226
5227 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
5228 {
5229   return getOrCreateAndGetArrayDouble();
5230 }
5231
5232 //= MEDFileIntField1TSWithoutSDA
5233
5234 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5235 {
5236   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5237 }
5238
5239 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5240 {
5241 }
5242
5243 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5244                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5245 {
5246   DataArrayInt *arr(getOrCreateAndGetArrayInt());
5247   arr->setInfoAndChangeNbOfCompo(infos);
5248 }
5249
5250 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5251 {
5252   return TYPE_STR;
5253 }
5254
5255 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5256 {
5257   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5258   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5259   ret->deepCpyLeavesFrom(*this);
5260   const DataArrayInt *arr(_arr);
5261   if(arr)
5262     {
5263       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5264       ret->setArray(arr2);
5265     }
5266   return ret.retn();
5267 }
5268
5269 /*!
5270  * Returns a pointer to the underground DataArrayInt instance. So the
5271  * caller should not decrRef() it. This method allows for a direct access to the field
5272  * values. This method is quite unusable if there is more than a nodal field or a cell
5273  * field on single geometric cell type. 
5274  *  \return DataArrayInt * - the pointer to the field values array.
5275  */
5276 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
5277 {
5278   return getUndergroundDataArrayInt();
5279 }
5280
5281 /*!
5282  * Returns a pointer to the underground DataArrayInt instance. So the
5283  * caller should not decrRef() it. This method allows for a direct access to the field
5284  * values. This method is quite unusable if there is more than a nodal field or a cell
5285  * field on single geometric cell type. 
5286  *  \return DataArrayInt * - the pointer to the field values array.
5287  */
5288 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5289 {
5290   const DataArrayInt *ret=_arr;
5291   if(ret)
5292     return const_cast<DataArrayInt *>(ret);
5293   else
5294     return 0;
5295 }
5296
5297 /*!
5298  * Returns a pointer to the underground DataArrayInt instance and a
5299  * sequence describing parameters of a support of each part of \a this field. The
5300  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5301  * direct access to the field values. This method is intended for the field lying on one
5302  * mesh only.
5303  *  \param [in,out] entries - the sequence describing parameters of a support of each
5304  *         part of \a this field. Each item of this sequence consists of two parts. The
5305  *         first part describes a type of mesh entity and an id of discretization of a
5306  *         current field part. The second part describes a range of values [begin,end)
5307  *         within the returned array relating to the current field part.
5308  *  \return DataArrayInt * - the pointer to the field values array.
5309  *  \throw If the number of underlying meshes is not equal to 1.
5310  *  \throw If no field values are available.
5311  *  \sa getUndergroundDataArray()
5312  */
5313 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5314 {
5315   return getUndergroundDataArrayIntExt(entries);
5316 }
5317
5318 /*!
5319  * Returns a pointer to the underground DataArrayInt instance and a
5320  * sequence describing parameters of a support of each part of \a this field. The
5321  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5322  * direct access to the field values. This method is intended for the field lying on one
5323  * mesh only.
5324  *  \param [in,out] entries - the sequence describing parameters of a support of each
5325  *         part of \a this field. Each item of this sequence consists of two parts. The
5326  *         first part describes a type of mesh entity and an id of discretization of a
5327  *         current field part. The second part describes a range of values [begin,end)
5328  *         within the returned array relating to the current field part.
5329  *  \return DataArrayInt * - the pointer to the field values array.
5330  *  \throw If the number of underlying meshes is not equal to 1.
5331  *  \throw If no field values are available.
5332  *  \sa getUndergroundDataArray()
5333  */
5334 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5335 {
5336   if(_field_per_mesh.size()!=1)
5337     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5338   if(_field_per_mesh[0]==0)
5339     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5340   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5341   return getUndergroundDataArrayInt();
5342 }
5343
5344 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5345 {
5346   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5347   ret->deepCpyLeavesFrom(*this);
5348   return ret.retn();
5349 }
5350
5351 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5352 {
5353   MCAuto<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5354   if((const DataArrayInt *)_arr)
5355     ret->_arr=_arr->deepCopy();
5356   return ret.retn();
5357 }
5358
5359 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5360 {
5361   if(!arr)
5362     {
5363       _nb_of_tuples_to_be_allocated=-1;
5364       _arr=0;
5365       return ;
5366     }
5367   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5368   if(!arrC)
5369     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5370   else
5371     _nb_of_tuples_to_be_allocated=-3;
5372   arrC->incrRef();
5373   _arr=arrC;
5374 }
5375
5376 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5377 {
5378   return DataArrayInt::New();
5379 }
5380
5381 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5382 {
5383   DataArrayInt *ret=_arr;
5384   if(ret)
5385     return ret;
5386   _arr=DataArrayInt::New();
5387   return _arr;
5388 }
5389
5390 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5391 {
5392   return getOrCreateAndGetArrayInt();
5393 }
5394
5395 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5396 {
5397   const DataArrayInt *ret=_arr;
5398   if(ret)
5399     return ret;
5400   DataArrayInt *ret2=DataArrayInt::New();
5401   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5402   return ret2;
5403 }
5404
5405 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5406 {
5407   return getOrCreateAndGetArrayInt();
5408 }
5409
5410 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5411 {
5412 }
5413
5414 //= MEDFileAnyTypeField1TS
5415
5416 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5417 {
5418   med_field_type typcha;
5419   //
5420   std::vector<std::string> infos;
5421   std::string dtunit,fieldName;
5422   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5423   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5424   switch(typcha)
5425   {
5426     case MED_FLOAT64:
5427       {
5428         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5429         break;
5430       }
5431     case MED_INT32:
5432       {
5433         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5434         break;
5435       }
5436     default:
5437       {
5438         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
5439         throw INTERP_KERNEL::Exception(oss.str().c_str());
5440       }
5441   }
5442   ret->setDtUnit(dtunit.c_str());
5443   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5444   //
5445   med_int numdt,numit;
5446   med_float dt;
5447   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5448   ret->setTime(numdt,numit,dt);
5449   ret->_csit=1;
5450   if(loadAll)
5451     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5452   else
5453     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5454   return ret.retn();
5455 }
5456
5457 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5458 try:MEDFileFieldGlobsReal(fileName)
5459 {
5460   MEDFileUtilities::CheckFileForRead(fileName);
5461   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5462   _content=BuildContentFrom(fid,fileName,loadAll,ms);
5463   loadGlobals(fid);
5464 }
5465 catch(INTERP_KERNEL::Exception& e)
5466 {
5467     throw e;
5468 }
5469
5470 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5471 {
5472   med_field_type typcha;
5473   std::vector<std::string> infos;
5474   std::string dtunit;
5475   int iii=-1;
5476   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5477   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5478   switch(typcha)
5479   {
5480     case MED_FLOAT64:
5481       {
5482         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5483         break;
5484       }
5485     case MED_INT32:
5486       {
5487         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5488         break;
5489       }
5490     default:
5491       {
5492         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5493         throw INTERP_KERNEL::Exception(oss.str().c_str());
5494       }
5495   }
5496   ret->setDtUnit(dtunit.c_str());
5497   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5498   //
5499   if(nbSteps<1)
5500     {
5501       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5502       throw INTERP_KERNEL::Exception(oss.str().c_str());
5503     }
5504   //
5505   med_int numdt,numit;
5506   med_float dt;
5507   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5508   ret->setTime(numdt,numit,dt);
5509   ret->_csit=1;
5510   if(loadAll)
5511     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5512   else
5513     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5514   return ret.retn();
5515 }
5516
5517 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5518 try:MEDFileFieldGlobsReal(fileName)
5519 {
5520   MEDFileUtilities::CheckFileForRead(fileName);
5521   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5522   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
5523   loadGlobals(fid);
5524 }
5525 catch(INTERP_KERNEL::Exception& e)
5526 {
5527     throw e;
5528 }
5529
5530 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5531 {
5532   if(!c)
5533     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5534   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5535     {
5536       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New();
5537       ret->setFileName(fileName);
5538       ret->_content=c; c->incrRef();
5539       return ret.retn();
5540     }
5541   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5542     {
5543       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5544       ret->setFileName(fileName);
5545       ret->_content=c; c->incrRef();
5546       return ret.retn();
5547     }
5548   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5549 }
5550
5551 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5552 {
5553   MEDFileUtilities::CheckFileForRead(fileName);
5554   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5555   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
5556   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5557   ret->loadGlobals(fid);
5558   return ret.retn();
5559 }
5560
5561 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5562 {
5563   MEDFileUtilities::CheckFileForRead(fileName);
5564   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5565   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
5566   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5567   ret->loadGlobals(fid);
5568   return ret.retn();
5569 }
5570
5571 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5572 {
5573   MEDFileUtilities::CheckFileForRead(fileName);
5574   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5575   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll,0);
5576   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5577   ret->loadGlobals(fid);
5578   return ret.retn();
5579 }
5580
5581 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, 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 nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5588   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5589   switch(typcha)
5590   {
5591     case MED_FLOAT64:
5592       {
5593         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5594         break;
5595       }
5596     case MED_INT32:
5597       {
5598         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5599         break;
5600       }
5601     default:
5602       {
5603         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName,iteration,order) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5604         throw INTERP_KERNEL::Exception(oss.str().c_str());
5605       }
5606   }
5607   ret->setDtUnit(dtunit.c_str());
5608   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5609   //
5610   bool found=false;
5611   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5612   for(int i=0;i<nbOfStep2 && !found;i++)
5613     {
5614       med_int numdt,numit;
5615       med_float dt;
5616       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5617       if(numdt==iteration && numit==order)
5618         {
5619           found=true;
5620           ret->_csit=i+1;
5621         }
5622       else
5623         dtits[i]=std::pair<int,int>(numdt,numit);
5624     }
5625   if(!found)
5626     {
5627       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5628       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5629         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5630       throw INTERP_KERNEL::Exception(oss.str().c_str());
5631     }
5632   if(loadAll)
5633     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5634   else
5635     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5636   return ret.retn();
5637 }
5638
5639 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5640 try:MEDFileFieldGlobsReal(fileName)
5641 {
5642   MEDFileUtilities::CheckFileForRead(fileName);
5643   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5644   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll,ms);
5645   loadGlobals(fid);
5646 }
5647 catch(INTERP_KERNEL::Exception& e)
5648 {
5649     throw e;
5650 }
5651
5652 /*!
5653  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5654  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5655  *
5656  * \warning this is a shallow copy constructor
5657  */
5658 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5659 {
5660   if(!shallowCopyOfContent)
5661     {
5662       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5663       otherPtr->incrRef();
5664       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5665     }
5666   else
5667     {
5668       _content=other.shallowCpy();
5669     }
5670 }
5671
5672 int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, const std::string& fileName, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5673 {
5674   if(checkFieldId)
5675     {
5676       int nbFields=MEDnField(fid);
5677       if(fieldIdCFormat>=nbFields)
5678         {
5679           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5680           throw INTERP_KERNEL::Exception(oss.str().c_str());
5681         }
5682     }
5683   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5684   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5685   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5686   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5687   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5688   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5689   med_bool localMesh;
5690   int nbOfStep;
5691   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5692   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5693   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5694   infos.clear(); infos.resize(ncomp);
5695   for(int j=0;j<ncomp;j++)
5696     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5697   return nbOfStep;
5698 }
5699
5700 /*!
5701  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5702  * 
5703  * \param [out]
5704  * \return in case of success the number of time steps available for the field with name \a fieldName.
5705  */
5706 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fileName, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5707 {
5708   int nbFields=MEDnField(fid);
5709   bool found=false;
5710   std::vector<std::string> fns(nbFields);
5711   int nbOfStep2=-1;
5712   for(int i=0;i<nbFields && !found;i++)
5713     {
5714       std::string tmp;
5715       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5716       fns[i]=tmp;
5717       found=(tmp==fieldName);
5718       if(found)
5719         posCFormat=i;
5720     }
5721   if(!found)
5722     {
5723       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5724       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5725         oss << "\"" << *it << "\" ";
5726       throw INTERP_KERNEL::Exception(oss.str().c_str());
5727     }
5728   return nbOfStep2;
5729 }
5730
5731 /*!
5732  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5733  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5734  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5735  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5736  * to keep a valid instance.
5737  * 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.
5738  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5739  * 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.
5740  *
5741  * \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.
5742  * \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.
5743  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5744  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5745  * \param [in] newLocName is the new localization name.
5746  * \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.
5747  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5748  */
5749 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5750 {
5751   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5752   std::string oldPflName=disc->getProfile();
5753   std::vector<std::string> vv=getPflsReallyUsedMulti();
5754   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5755   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5756     {
5757       disc->setProfile(newPflName);
5758       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5759       pfl->setName(newPflName);
5760     }
5761   else
5762     {
5763       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5764       throw INTERP_KERNEL::Exception(oss.str().c_str());
5765     }
5766 }
5767
5768 /*!
5769  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5770  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5771  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5772  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5773  * to keep a valid instance.
5774  * 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.
5775  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5776  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5777  * 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.
5778  *
5779  * \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.
5780  * \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.
5781  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5782  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5783  * \param [in] newLocName is the new localization name.
5784  * \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.
5785  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5786  */
5787 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5788 {
5789   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5790   std::string oldLocName=disc->getLocalization();
5791   std::vector<std::string> vv=getLocsReallyUsedMulti();
5792   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5793   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5794     {
5795       disc->setLocalization(newLocName);
5796       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5797       loc.setName(newLocName);
5798     }
5799   else
5800     {
5801       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5802       throw INTERP_KERNEL::Exception(oss.str().c_str());
5803     }
5804 }
5805
5806 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5807 {
5808   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5809   if(!ret)
5810     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5811   return ret;
5812 }
5813
5814 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5815 {
5816   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5817   if(!ret)
5818     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5819   return ret;
5820 }
5821
5822 /*!
5823  * Writes \a this field into a MED file specified by its name.
5824  *  \param [in] fileName - the MED file name.
5825  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5826  * - 2 - erase; an existing file is removed.
5827  * - 1 - append; same data should not be present in an existing file.
5828  * - 0 - overwrite; same data present in an existing file is overwritten.
5829  *  \throw If the field name is not set.
5830  *  \throw If no field data is set.
5831  *  \throw If \a mode == 1 and the same data is present in an existing file.
5832  */
5833 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5834 {
5835   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5836   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5837   writeLL(fid);
5838 }
5839
5840 /*!
5841  * This method alloc the arrays and load potentially huge arrays contained in this field.
5842  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5843  * This method can be also called to refresh or reinit values from a file.
5844  * 
5845  * \throw If the fileName is not set or points to a non readable MED file.
5846  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5847  */
5848 void MEDFileAnyTypeField1TS::loadArrays()
5849 {
5850   if(getFileName().empty())
5851     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5852   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5853   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5854 }
5855
5856 /*!
5857  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5858  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5859  * this method does not throw if \a this does not come from file read.
5860  * 
5861  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5862  */
5863 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5864 {
5865   if(!getFileName().empty())
5866     {
5867       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5868       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5869     }
5870 }
5871
5872 /*!
5873  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5874  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5875  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5876  * 
5877  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5878  */
5879 void MEDFileAnyTypeField1TS::unloadArrays()
5880 {
5881   contentNotNullBase()->unloadArrays();
5882 }
5883
5884 /*!
5885  * 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.
5886  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5887  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5888  * 
5889  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5890  */
5891 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5892 {
5893   if(!getFileName().empty())
5894     contentNotNullBase()->unloadArrays();
5895 }
5896
5897 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5898 {
5899   int nbComp=getNumberOfComponents();
5900   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5901   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5902   for(int i=0;i<nbComp;i++)
5903     {
5904       std::string info=getInfo()[i];
5905       std::string c,u;
5906       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5907       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5908       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5909     }
5910   if(getName().empty())
5911     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5912   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
5913   writeGlobals(fid,*this);
5914   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5915 }
5916
5917 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5918 {
5919   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5920 }
5921
5922 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5923 {
5924   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5925   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5926   return ret;
5927 }
5928
5929 /*!
5930  * Returns a string describing \a this field. This string is outputted 
5931  * by \c print Python command.
5932  */
5933 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5934 {
5935   std::ostringstream oss;
5936   contentNotNullBase()->simpleRepr(0,oss,-1);
5937   simpleReprGlobs(oss);
5938   return oss.str();
5939 }
5940
5941 /*!
5942  * This method returns all profiles whose name is non empty used.
5943  * \b WARNING If profile is used several times it will be reported \b only \b once.
5944  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5945  */
5946 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5947 {
5948   return contentNotNullBase()->getPflsReallyUsed2();
5949 }
5950
5951 /*!
5952  * This method returns all localizations whose name is non empty used.
5953  * \b WARNING If localization is used several times it will be reported \b only \b once.
5954  */
5955 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5956 {
5957   return contentNotNullBase()->getLocsReallyUsed2();
5958 }
5959
5960 /*!
5961  * This method returns all profiles whose name is non empty used.
5962  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5963  */
5964 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5965 {
5966   return contentNotNullBase()->getPflsReallyUsedMulti2();
5967 }
5968
5969 /*!
5970  * This method returns all localizations whose name is non empty used.
5971  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5972  */
5973 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5974 {
5975   return contentNotNullBase()->getLocsReallyUsedMulti2();
5976 }
5977
5978 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5979 {
5980   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5981 }
5982
5983 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5984 {
5985   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5986 }
5987
5988 int MEDFileAnyTypeField1TS::getDimension() const
5989 {
5990   return contentNotNullBase()->getDimension();
5991 }
5992
5993 int MEDFileAnyTypeField1TS::getIteration() const
5994 {
5995   return contentNotNullBase()->getIteration();
5996 }
5997
5998 int MEDFileAnyTypeField1TS::getOrder() const
5999 {
6000   return contentNotNullBase()->getOrder();
6001 }
6002
6003 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6004 {
6005   return contentNotNullBase()->getTime(iteration,order);
6006 }
6007
6008 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6009 {
6010   contentNotNullBase()->setTime(iteration,order,val);
6011 }
6012
6013 std::string MEDFileAnyTypeField1TS::getName() const
6014 {
6015   return contentNotNullBase()->getName();
6016 }
6017
6018 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6019 {
6020   contentNotNullBase()->setName(name);
6021 }
6022
6023 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6024 {
6025   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6026 }
6027
6028 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6029 {
6030   return contentNotNullBase()->getDtUnit();
6031 }
6032
6033 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6034 {
6035   contentNotNullBase()->setDtUnit(dtUnit);
6036 }
6037
6038 std::string MEDFileAnyTypeField1TS::getMeshName() const
6039 {
6040   return contentNotNullBase()->getMeshName();
6041 }
6042
6043 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6044 {
6045   contentNotNullBase()->setMeshName(newMeshName);
6046 }
6047
6048 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6049 {
6050   return contentNotNullBase()->changeMeshNames(modifTab);
6051 }
6052
6053 int MEDFileAnyTypeField1TS::getMeshIteration() const
6054 {
6055   return contentNotNullBase()->getMeshIteration();
6056 }
6057
6058 int MEDFileAnyTypeField1TS::getMeshOrder() const
6059 {
6060   return contentNotNullBase()->getMeshOrder();
6061 }
6062
6063 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6064 {
6065   return contentNotNullBase()->getNumberOfComponents();
6066 }
6067
6068 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6069 {
6070   return contentNotNullBase()->isDealingTS(iteration,order);
6071 }
6072
6073 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6074 {
6075   return contentNotNullBase()->getDtIt();
6076 }
6077
6078 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6079 {
6080   contentNotNullBase()->fillIteration(p);
6081 }
6082
6083 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6084 {
6085   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6086 }
6087
6088 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6089 {
6090   contentNotNullBase()->setInfo(infos);
6091 }
6092
6093 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6094 {
6095   return contentNotNullBase()->getInfo();
6096 }
6097 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6098 {
6099   return contentNotNullBase()->getInfo();
6100 }
6101
6102 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6103 {
6104   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6105 }
6106
6107 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6108 {
6109   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6110 }
6111
6112 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6113 {
6114   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6115 }
6116
6117 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6118 {
6119   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6120 }
6121
6122 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6123 {
6124   return contentNotNullBase()->getTypesOfFieldAvailable();
6125 }
6126
6127 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,
6128                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6129 {
6130   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6131 }
6132
6133 /*!
6134  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6135  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6136  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6137  */
6138 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6139 {
6140   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6141   if(!content)
6142     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6143   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6144   std::size_t sz(contentsSplit.size());
6145   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6146   for(std::size_t i=0;i<sz;i++)
6147     {
6148       ret[i]=shallowCpy();
6149       ret[i]->_content=contentsSplit[i];
6150     }
6151   return ret;
6152 }
6153
6154 /*!
6155  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6156  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6157  */
6158 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6159 {
6160   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6161   if(!content)
6162     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6163   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6164   std::size_t sz(contentsSplit.size());
6165   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6166   for(std::size_t i=0;i<sz;i++)
6167     {
6168       ret[i]=shallowCpy();
6169       ret[i]->_content=contentsSplit[i];
6170     }
6171   return ret;
6172 }
6173
6174 /*!
6175  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6176  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6177  */
6178 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6179 {
6180   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6181   if(!content)
6182     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6183   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6184   std::size_t sz(contentsSplit.size());
6185   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6186   for(std::size_t i=0;i<sz;i++)
6187     {
6188       ret[i]=shallowCpy();
6189       ret[i]->_content=contentsSplit[i];
6190     }
6191   return ret;
6192 }
6193
6194 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6195 {
6196   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6197   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6198     ret->_content=_content->deepCopy();
6199   ret->deepCpyGlobs(*this);
6200   return ret.retn();
6201 }
6202
6203 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6204 {
6205   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6206 }
6207
6208 //= MEDFileField1TS
6209
6210 /*!
6211  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6212  * the first field that has been read from a specified MED file.
6213  *  \param [in] fileName - the name of the MED file to read.
6214  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6215  *          is to delete this field using decrRef() as it is no more needed.
6216  *  \throw If reading the file fails.
6217  */
6218 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6219 {
6220   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,loadAll,0));
6221   ret->contentNotNull();
6222   return ret.retn();
6223 }
6224
6225 /*!
6226  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6227  * a given field that has been read from a specified MED file.
6228  *  \param [in] fileName - the name of the MED file to read.
6229  *  \param [in] fieldName - the name of the field to read.
6230  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6231  *          is to delete this field using decrRef() as it is no more needed.
6232  *  \throw If reading the file fails.
6233  *  \throw If there is no field named \a fieldName in the file.
6234  */
6235 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6236 {
6237   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,loadAll,0));
6238   ret->contentNotNull();
6239   return ret.retn();
6240 }
6241
6242 /*!
6243  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6244  * a given field that has been read from a specified MED file.
6245  *  \param [in] fileName - the name of the MED file to read.
6246  *  \param [in] fieldName - the name of the field to read.
6247  *  \param [in] iteration - the iteration number of a required time step.
6248  *  \param [in] order - the iteration order number of required time step.
6249  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6250  *          is to delete this field using decrRef() as it is no more needed.
6251  *  \throw If reading the file fails.
6252  *  \throw If there is no field named \a fieldName in the file.
6253  *  \throw If the required time step is missing from the file.
6254  */
6255 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6256 {
6257   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll,0));
6258   ret->contentNotNull();
6259   return ret.retn();
6260 }
6261
6262 /*!
6263  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6264  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6265  *
6266  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6267  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6268  * \warning this is a shallow copy constructor
6269  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6270  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6271  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6272  *          is to delete this field using decrRef() as it is no more needed.
6273  */
6274 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6275 {
6276   MCAuto<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
6277   ret->contentNotNull();
6278   return ret.retn();
6279 }
6280
6281 /*!
6282  * Returns a new empty instance of MEDFileField1TS.
6283  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6284  *          is to delete this field using decrRef() as it is no more needed.
6285  */
6286 MEDFileField1TS *MEDFileField1TS::New()
6287 {
6288   MCAuto<MEDFileField1TS> ret=new MEDFileField1TS;
6289   ret->contentNotNull();
6290   return ret.retn();
6291 }
6292
6293 /*!
6294  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6295  * following the given input policy.
6296  *
6297  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6298  *                            By default (true) the globals are deeply copied.
6299  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6300  */
6301 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6302 {
6303   MCAuto<MEDFileIntField1TS> ret;
6304   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6305   if(content)
6306     {
6307       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6308       if(!contc)
6309         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6310       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6311       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6312     }
6313   else
6314     ret=MEDFileIntField1TS::New();
6315   if(isDeepCpyGlobs)
6316     ret->deepCpyGlobs(*this);
6317   else
6318     ret->shallowCpyGlobs(*this);
6319   return ret.retn();
6320 }
6321
6322 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6323 {
6324   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6325   if(!pt)
6326     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6327   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6328   if(!ret)
6329     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 !");
6330   return ret;
6331 }
6332
6333 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6334 {
6335   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6336   if(!pt)
6337     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6338   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6339   if(!ret)
6340     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 !");
6341   return ret;
6342 }
6343
6344 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6345 {
6346   if(!f)
6347     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6348   if(!((DataArray*)arr))
6349     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6350   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6351   if(!arrOutC)
6352     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6353   f->setArray(arrOutC);
6354 }
6355
6356 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6357 {
6358   if(!((DataArray*)arr))
6359     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6360   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6361   if(!arrOutC)
6362     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6363   arrOutC->incrRef();
6364   return arrOutC;
6365 }
6366
6367 /*!
6368  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6369  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6370  *
6371  * \return A new object that the caller is responsible to deallocate.
6372  */
6373 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6374 {
6375   if(!mm)
6376     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6377   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6378   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6379   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6380     {
6381       if((*it0)!=ON_NODES)
6382         {
6383           std::vector<int> levs;
6384           getNonEmptyLevels(mm->getName(),levs);
6385           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6386             {
6387               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6388               if(it2!=extractDef.end())
6389                 {
6390                   MCAuto<DataArrayInt> t((*it2).second);
6391                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6392                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6393                   ret->setFieldNoProfileSBT(fOut);
6394                 }
6395             }
6396         }
6397       else
6398         {
6399           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6400           if(it2==extractDef.end())
6401             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6402           MCAuto<DataArrayInt> t((*it2).second);
6403           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6404           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6405           DataArrayDouble *arr(f->getArray());
6406           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6407           fOut->setArray(newArr);
6408           ret->setFieldNoProfileSBT(fOut);
6409         }
6410     }
6411   return ret.retn();
6412 }
6413
6414 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6415 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6416 {
6417 }
6418 catch(INTERP_KERNEL::Exception& e)
6419 { throw e; }
6420
6421 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6422 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6423 {
6424 }
6425 catch(INTERP_KERNEL::Exception& e)
6426 { throw e; }
6427
6428 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6429 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6430 {
6431 }
6432 catch(INTERP_KERNEL::Exception& e)
6433 { throw e; }
6434
6435 /*!
6436  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6437  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6438  *
6439  * \warning this is a shallow copy constructor
6440  */
6441 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6442 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6443 {
6444 }
6445 catch(INTERP_KERNEL::Exception& e)
6446 { throw e; }
6447
6448 MEDFileField1TS::MEDFileField1TS()
6449 {
6450   _content=new MEDFileField1TSWithoutSDA;
6451 }
6452
6453 /*!
6454  * Returns a new MEDCouplingFieldDouble of a given type lying on
6455  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6456  * has not been constructed via file reading, an exception is thrown.
6457  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6458  *  \param [in] type - a spatial discretization of interest.
6459  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6460  *  \param [in] renumPol - specifies how to permute values of the result field according to
6461  *          the optional numbers of cells and nodes, if any. The valid values are
6462  *          - 0 - do not permute.
6463  *          - 1 - permute cells.
6464  *          - 2 - permute nodes.
6465  *          - 3 - permute cells and nodes.
6466  *
6467  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6468  *          caller is to delete this field using decrRef() as it is no more needed. 
6469  *  \throw If \a this field has not been constructed via file reading.
6470  *  \throw If the MED file is not readable.
6471  *  \throw If there is no mesh in the MED file.
6472  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6473  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6474  *  \sa getFieldOnMeshAtLevel()
6475  */
6476 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6477 {
6478   if(getFileName().empty())
6479     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6480   MCAuto<DataArray> arrOut;
6481   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6482   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6483   return ret.retn();
6484 }
6485
6486 /*!
6487  * Returns a new MEDCouplingFieldDouble of a given type lying on
6488  * the top level cells of the first mesh in MED file. If \a this field 
6489  * has not been constructed via file reading, an exception is thrown.
6490  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6491  *  \param [in] type - a spatial discretization of interest.
6492  *  \param [in] renumPol - specifies how to permute values of the result field according to
6493  *          the optional numbers of cells and nodes, if any. The valid values are
6494  *          - 0 - do not permute.
6495  *          - 1 - permute cells.
6496  *          - 2 - permute nodes.
6497  *          - 3 - permute cells and nodes.
6498  *
6499  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6500  *          caller is to delete this field using decrRef() as it is no more needed. 
6501  *  \throw If \a this field has not been constructed via file reading.
6502  *  \throw If the MED file is not readable.
6503  *  \throw If there is no mesh in the MED file.
6504  *  \throw If no field values of the given \a type.
6505  *  \throw If no field values lying on the top level support.
6506  *  \sa getFieldAtLevel()
6507  */
6508 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6509 {
6510   if(getFileName().empty())
6511     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6512   MCAuto<DataArray> arrOut;
6513   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6514   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6515   return ret.retn();
6516 }
6517
6518 /*!
6519  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6520  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6521  *  \param [in] type - a spatial discretization of the new field.
6522  *  \param [in] mesh - the supporting mesh.
6523  *  \param [in] renumPol - specifies how to permute values of the result field according to
6524  *          the optional numbers of cells and nodes, if any. The valid values are
6525  *          - 0 - do not permute.
6526  *          - 1 - permute cells.
6527  *          - 2 - permute nodes.
6528  *          - 3 - permute cells and nodes.
6529  *
6530  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6531  *          caller is to delete this field using decrRef() as it is no more needed. 
6532  *  \throw If no field of \a this is lying on \a mesh.
6533  *  \throw If the mesh is empty.
6534  *  \throw If no field values of the given \a type are available.
6535  *  \sa getFieldAtLevel()
6536  *  \sa getFieldOnMeshAtLevel() 
6537  */
6538 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6539 {
6540   MCAuto<DataArray> arrOut;
6541   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6542   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6543   return ret.retn();
6544 }
6545
6546 /*!
6547  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6548  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6549  *  \param [in] type - a spatial discretization of interest.
6550  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6551  *  \param [in] mesh - the supporting mesh.
6552  *  \param [in] renumPol - specifies how to permute values of the result field according to
6553  *          the optional numbers of cells and nodes, if any. The valid values are
6554  *          - 0 - do not permute.
6555  *          - 1 - permute cells.
6556  *          - 2 - permute nodes.
6557  *          - 3 - permute cells and nodes.
6558  *
6559  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6560  *          caller is to delete this field using decrRef() as it is no more needed. 
6561  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6562  *  \throw If no field of \a this is lying on \a mesh.
6563  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6564  *  \sa getFieldAtLevel()
6565  *  \sa getFieldOnMeshAtLevel() 
6566  */
6567 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6568 {
6569   MCAuto<DataArray> arrOut;
6570   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6571   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6572   return ret.retn();
6573 }
6574
6575 /*!
6576  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6577  * This method is called "Old" because in MED3 norm a field has only one meshName
6578  * attached, so this method is for readers of MED2 files. If \a this field 
6579  * has not been constructed via file reading, an exception is thrown.
6580  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6581  *  \param [in] type - a spatial discretization of interest.
6582  *  \param [in] mName - a name of the supporting mesh.
6583  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6584  *  \param [in] renumPol - specifies how to permute values of the result field according to
6585  *          the optional numbers of cells and nodes, if any. The valid values are
6586  *          - 0 - do not permute.
6587  *          - 1 - permute cells.
6588  *          - 2 - permute nodes.
6589  *          - 3 - permute cells and nodes.
6590  *
6591  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6592  *          caller is to delete this field using decrRef() as it is no more needed. 
6593  *  \throw If the MED file is not readable.
6594  *  \throw If there is no mesh named \a mName in the MED file.
6595  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6596  *  \throw If \a this field has not been constructed via file reading.
6597  *  \throw If no field of \a this is lying on the mesh named \a mName.
6598  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6599  *  \sa getFieldAtLevel()
6600  */
6601 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6602 {
6603   if(getFileName().empty())
6604     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6605   MCAuto<DataArray> arrOut;
6606   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6607   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6608   return ret.retn();
6609 }
6610
6611 /*!
6612  * Returns values and a profile of the field of a given type lying on a given support.
6613  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6614  *  \param [in] type - a spatial discretization of the field.
6615  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6616  *  \param [in] mesh - the supporting mesh.
6617  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6618  *          field of interest lies on. If the field lies on all entities of the given
6619  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6620  *          using decrRef() as it is no more needed.  
6621  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6622  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6623  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6624  *  \throw If no field of \a this is lying on \a mesh.
6625  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6626  */
6627 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6628 {
6629   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6630   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6631 }
6632
6633 /*!
6634  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6635  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6636  * "Sort By Type"), if not, an exception is thrown. 
6637  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6638  *  \param [in] field - the field to add to \a this.
6639  *  \throw If the name of \a field is empty.
6640  *  \throw If the data array of \a field is not set.
6641  *  \throw If the data array is already allocated but has different number of components
6642  *         than \a field.
6643  *  \throw If the underlying mesh of \a field has no name.
6644  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6645  */
6646 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6647 {
6648   setFileName("");
6649   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6650 }
6651
6652 /*!
6653  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6654  * can be an aggregation of several MEDCouplingFieldDouble instances.
6655  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6656  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6657  * and \a profile.
6658  *
6659  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6660  * A new profile is added only if no equal profile is missing.
6661  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6662  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6663  *  \param [in] mesh - the supporting mesh of \a field.
6664  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6665  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6666  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6667  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6668  *  \throw If the data array of \a field is not set.
6669  *  \throw If the data array of \a this is already allocated but has different number of
6670  *         components than \a field.
6671  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6672  *  \sa setFieldNoProfileSBT()
6673  */
6674 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6675 {
6676   setFileName("");
6677   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6678 }
6679
6680 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6681 {
6682   return new MEDFileField1TS(*this);
6683 }
6684
6685 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6686 {
6687   return contentNotNull()->getUndergroundDataArrayDouble();
6688 }
6689
6690 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6691 {
6692   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6693 }
6694
6695 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6696                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6697 {
6698   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6699 }
6700
6701 //= MEDFileIntField1TS
6702
6703 MEDFileIntField1TS *MEDFileIntField1TS::New()
6704 {
6705   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6706   ret->contentNotNull();
6707   return ret.retn();
6708 }
6709
6710 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6711 {
6712   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6713   ret->contentNotNull();
6714   return ret.retn();
6715 }
6716
6717 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6718 {
6719   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6720   ret->contentNotNull();
6721   return ret.retn();
6722 }
6723
6724 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6725 {
6726   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6727   ret->contentNotNull();
6728   return ret.retn();
6729 }
6730
6731 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6732 {
6733   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6734   ret->contentNotNull();
6735   return ret.retn();
6736 }
6737
6738 MEDFileIntField1TS::MEDFileIntField1TS()
6739 {
6740   _content=new MEDFileIntField1TSWithoutSDA;
6741 }
6742
6743 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6744 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6745 {
6746 }
6747 catch(INTERP_KERNEL::Exception& e)
6748 { throw e; }
6749
6750 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6751 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6752 {
6753 }
6754 catch(INTERP_KERNEL::Exception& e)
6755 { throw e; }
6756
6757 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6758 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6759 {
6760 }
6761 catch(INTERP_KERNEL::Exception& e)
6762 { throw e; }
6763
6764 /*!
6765  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6766  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6767  *
6768  * \warning this is a shallow copy constructor
6769  */
6770 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6771 {
6772 }
6773
6774 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6775 {
6776   return new MEDFileIntField1TS(*this);
6777 }
6778
6779 /*!
6780  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6781  * following the given input policy.
6782  *
6783  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6784  *                            By default (true) the globals are deeply copied.
6785  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6786  */
6787 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6788 {
6789   MCAuto<MEDFileField1TS> ret;
6790   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6791   if(content)
6792     {
6793       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6794       if(!contc)
6795         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6796       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6797       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6798     }
6799   else
6800     ret=MEDFileField1TS::New();
6801   if(isDeepCpyGlobs)
6802     ret->deepCpyGlobs(*this);
6803   else
6804     ret->shallowCpyGlobs(*this);
6805   return ret.retn();
6806 }
6807
6808 /*!
6809  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6810  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6811  * "Sort By Type"), if not, an exception is thrown. 
6812  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6813  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6814  *  \param [in] arrOfVals - the values of the field \a field used.
6815  *  \throw If the name of \a field is empty.
6816  *  \throw If the data array of \a field is not set.
6817  *  \throw If the data array is already allocated but has different number of components
6818  *         than \a field.
6819  *  \throw If the underlying mesh of \a field has no name.
6820  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6821  */
6822 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6823 {
6824   setFileName("");
6825   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6826 }
6827
6828 /*!
6829  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6830  * can be an aggregation of several MEDCouplingFieldDouble instances.
6831  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6832  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6833  * and \a profile.
6834  *
6835  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6836  * A new profile is added only if no equal profile is missing.
6837  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6838  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6839  *  \param [in] arrOfVals - the values of the field \a field used.
6840  *  \param [in] mesh - the supporting mesh of \a field.
6841  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6842  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6843  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6844  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6845  *  \throw If the data array of \a field is not set.
6846  *  \throw If the data array of \a this is already allocated but has different number of
6847  *         components than \a field.
6848  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6849  *  \sa setFieldNoProfileSBT()
6850  */
6851 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6852 {
6853   setFileName("");
6854   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6855 }
6856
6857 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6858 {
6859   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6860   if(!pt)
6861     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6862   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6863   if(!ret)
6864     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 !");
6865   return ret;
6866 }
6867
6868 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6869 {
6870   if(getFileName().empty())
6871     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6872   MCAuto<DataArray> arrOut2;
6873   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6874   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6875   if(!arrOutC)
6876     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6877   arrOut=arrOutC;
6878   arrOut->incrRef();  // arrOut2 dies at the end of the func
6879   return ret.retn();
6880 }
6881
6882 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
6883 {
6884   if(!((DataArray *)arr))
6885     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6886   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6887   if(!arrC)
6888     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6889   arrC->incrRef();
6890   return arrC;
6891 }
6892
6893 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6894 {
6895   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
6896 }
6897
6898 /*!
6899  * Returns a new MEDCouplingFieldDouble of a given type lying on
6900  * the top level cells of the first mesh in MED file. If \a this field 
6901  * has not been constructed via file reading, an exception is thrown.
6902  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6903  *  \param [in] type - a spatial discretization of interest.
6904  *  \param [out] arrOut - the DataArrayInt containing values of field.
6905  *  \param [in] renumPol - specifies how to permute values of the result field according to
6906  *          the optional numbers of cells and nodes, if any. The valid values are
6907  *          - 0 - do not permute.
6908  *          - 1 - permute cells.
6909  *          - 2 - permute nodes.
6910  *          - 3 - permute cells and nodes.
6911  *
6912  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6913  *          caller is to delete this field using decrRef() as it is no more needed. 
6914  *  \throw If \a this field has not been constructed via file reading.
6915  *  \throw If the MED file is not readable.
6916  *  \throw If there is no mesh in the MED file.
6917  *  \throw If no field values of the given \a type.
6918  *  \throw If no field values lying on the top level support.
6919  *  \sa getFieldAtLevel()
6920  */
6921 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6922 {
6923   if(getFileName().empty())
6924     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6925   MCAuto<DataArray> arr;
6926   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6927   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6928   return ret.retn();
6929 }
6930
6931 /*!
6932  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6933  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6934  *  \param [in] type - a spatial discretization of the new field.
6935  *  \param [in] mesh - the supporting mesh.
6936  *  \param [out] arrOut - the DataArrayInt containing values of field.
6937  *  \param [in] renumPol - specifies how to permute values of the result field according to
6938  *          the optional numbers of cells and nodes, if any. The valid values are
6939  *          - 0 - do not permute.
6940  *          - 1 - permute cells.
6941  *          - 2 - permute nodes.
6942  *          - 3 - permute cells and nodes.
6943  *
6944  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6945  *          caller is to delete this field using decrRef() as it is no more needed. 
6946  *  \throw If no field of \a this is lying on \a mesh.
6947  *  \throw If the mesh is empty.
6948  *  \throw If no field values of the given \a type are available.
6949  *  \sa getFieldAtLevel()
6950  *  \sa getFieldOnMeshAtLevel() 
6951  */
6952 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6953 {
6954   MCAuto<DataArray> arr;
6955   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6956   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6957   return ret.retn();
6958 }
6959
6960 /*!
6961  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6962  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6963  *  \param [in] type - a spatial discretization of interest.
6964  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6965  *  \param [out] arrOut - the DataArrayInt containing values of field.
6966  *  \param [in] mesh - the supporting mesh.
6967  *  \param [in] renumPol - specifies how to permute values of the result field according to
6968  *          the optional numbers of cells and nodes, if any. The valid values are
6969  *          - 0 - do not permute.
6970  *          - 1 - permute cells.
6971  *          - 2 - permute nodes.
6972  *          - 3 - permute cells and nodes.
6973  *
6974  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6975  *          caller is to delete this field using decrRef() as it is no more needed. 
6976  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6977  *  \throw If no field of \a this is lying on \a mesh.
6978  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6979  *  \sa getFieldAtLevel()
6980  *  \sa getFieldOnMeshAtLevel() 
6981  */
6982 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6983 {
6984   MCAuto<DataArray> arr;
6985   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6986   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6987   return ret.retn();
6988 }
6989
6990 /*!
6991  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6992  * This method is called "Old" because in MED3 norm a field has only one meshName
6993  * attached, so this method is for readers of MED2 files. If \a this field 
6994  * has not been constructed via file reading, an exception is thrown.
6995  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6996  *  \param [in] type - a spatial discretization of interest.
6997  *  \param [in] mName - a name of the supporting mesh.
6998  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6999  *  \param [out] arrOut - the DataArrayInt containing values of field.
7000  *  \param [in] renumPol - specifies how to permute values of the result field according to
7001  *          the optional numbers of cells and nodes, if any. The valid values are
7002  *          - 0 - do not permute.
7003  *          - 1 - permute cells.
7004  *          - 2 - permute nodes.
7005  *          - 3 - permute cells and nodes.
7006  *
7007  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7008  *          caller is to delete this field using decrRef() as it is no more needed. 
7009  *  \throw If the MED file is not readable.
7010  *  \throw If there is no mesh named \a mName in the MED file.
7011  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7012  *  \throw If \a this field has not been constructed via file reading.
7013  *  \throw If no field of \a this is lying on the mesh named \a mName.
7014  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7015  *  \sa getFieldAtLevel()
7016  */
7017 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
7018 {
7019   if(getFileName().empty())
7020     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7021   MCAuto<DataArray> arr;
7022   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
7023   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7024   return ret.retn();
7025 }
7026
7027 /*!
7028  * Returns values and a profile of the field of a given type lying on a given support.
7029  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7030  *  \param [in] type - a spatial discretization of the field.
7031  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7032  *  \param [in] mesh - the supporting mesh.
7033  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7034  *          field of interest lies on. If the field lies on all entities of the given
7035  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7036  *          using decrRef() as it is no more needed.  
7037  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7038  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7039  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7040  *  \throw If no field of \a this is lying on \a mesh.
7041  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7042  */
7043 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7044 {
7045   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7046   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7047 }
7048
7049 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7050 {
7051   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7052   if(!pt)
7053     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7054   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7055   if(!ret)
7056     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 !");
7057   return ret;
7058 }
7059
7060 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7061 {
7062   return contentNotNull()->getUndergroundDataArrayInt();
7063 }
7064
7065 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7066
7067 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7068 {
7069 }
7070
7071 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7072 {
7073 }
7074
7075 /*!
7076  * \param [in] fieldId field id in C mode
7077  */
7078 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7079 {
7080   med_field_type typcha;
7081   std::string dtunitOut;
7082   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
7083   setDtUnit(dtunitOut.c_str());
7084   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7085 }
7086
7087 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7088 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7089 {
7090   setDtUnit(dtunit.c_str());
7091   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7092 }
7093 catch(INTERP_KERNEL::Exception& e)
7094 {
7095     throw e;
7096 }
7097
7098 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7099 {
7100   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7101   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7102     ret+=(*it).capacity();
7103   return ret;
7104 }
7105
7106 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7107 {
7108   std::vector<const BigMemoryObject *> ret;
7109   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7110     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7111   return ret;
7112 }
7113
7114 /*!
7115  * 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
7116  * NULL.
7117  */
7118 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7119 {
7120   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7121   ret->setInfo(_infos);
7122   int sz=(int)_time_steps.size();
7123   for(const int *id=startIds;id!=endIds;id++)
7124     {
7125       if(*id>=0 && *id<sz)
7126         {
7127           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7128           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7129           if(tse)
7130             {
7131               tse->incrRef();
7132               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7133             }
7134           ret->pushBackTimeStep(tse2);
7135         }
7136       else
7137         {
7138           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7139           oss << " ! Should be in [0," << sz << ") !";
7140           throw INTERP_KERNEL::Exception(oss.str().c_str());
7141         }
7142     }
7143   if(ret->getNumberOfTS()>0)
7144     ret->synchronizeNameScope();
7145   ret->copyNameScope(*this);
7146   return ret.retn();
7147 }
7148
7149 /*!
7150  * 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
7151  * NULL.
7152  */
7153 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7154 {
7155   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7156   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7157   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7158   ret->setInfo(_infos);
7159   int sz=(int)_time_steps.size();
7160   int j=bg;
7161   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7162     {
7163       if(j>=0 && j<sz)
7164         {
7165           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7166           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7167           if(tse)
7168             {
7169               tse->incrRef();
7170               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7171             }
7172           ret->pushBackTimeStep(tse2);
7173         }
7174       else
7175         {
7176           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7177           oss << " ! Should be in [0," << sz << ") !";
7178           throw INTERP_KERNEL::Exception(oss.str().c_str());
7179         }
7180     }
7181   if(ret->getNumberOfTS()>0)
7182     ret->synchronizeNameScope();
7183   ret->copyNameScope(*this);
7184   return ret.retn();
7185 }
7186
7187 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7188 {
7189   int id=0;
7190   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7191   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7192     {
7193       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7194       if(!cur)
7195         continue;
7196       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7197       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7198         ids->pushBackSilent(id);
7199     }
7200   return buildFromTimeStepIds(ids->begin(),ids->end());
7201 }
7202
7203 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7204 {
7205   int id=0;
7206   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7207   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7208     {
7209       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7210       if(!cur)
7211         continue;
7212       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7213       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7214         ids->pushBackSilent(id);
7215     }
7216   return buildFromTimeStepIds(ids->begin(),ids->end());
7217 }
7218
7219 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7220 {
7221   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7222     {
7223       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7224       if(!cur)
7225         continue;
7226       if(cur->presenceOfMultiDiscPerGeoType())
7227         return true;
7228     }
7229   return false;
7230 }
7231
7232 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7233 {
7234   return _infos;
7235 }
7236
7237 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7238 {
7239   _infos=info;
7240 }
7241
7242 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7243 {
7244   int ret=0;
7245   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7246     {
7247       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7248       if(pt->isDealingTS(iteration,order))
7249         return ret;
7250     }
7251   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7252   std::vector< std::pair<int,int> > vp=getIterations();
7253   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7254     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7255   throw INTERP_KERNEL::Exception(oss.str().c_str());
7256 }
7257
7258 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7259 {
7260   return *_time_steps[getTimeStepPos(iteration,order)];
7261 }
7262
7263 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7264 {
7265   return *_time_steps[getTimeStepPos(iteration,order)];
7266 }
7267
7268 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7269 {
7270   if(_time_steps.empty())
7271     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7272   return _time_steps[0]->getMeshName();
7273 }
7274
7275 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7276 {
7277   std::string oldName(getMeshName());
7278   std::vector< std::pair<std::string,std::string> > v(1);
7279   v[0].first=oldName; v[0].second=newMeshName;
7280   changeMeshNames(v);
7281 }
7282
7283 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7284 {
7285   bool ret=false;
7286   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7287     {
7288       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7289       if(cur)
7290         ret=cur->changeMeshNames(modifTab) || ret;
7291     }
7292   return ret;
7293 }
7294
7295 /*!
7296  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7297  */
7298 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7299 {
7300   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7301 }
7302
7303 /*!
7304  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7305  */
7306 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7307 {
7308   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7309 }
7310
7311 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7312                                                                        MEDFileFieldGlobsReal& glob)
7313 {
7314   bool ret=false;
7315   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7316     {
7317       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7318       if(f1ts)
7319         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7320     }
7321   return ret;
7322 }
7323
7324 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7325 {
7326   std::string startLine(bkOffset,' ');
7327   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7328   if(fmtsId>=0)
7329     oss << " (" << fmtsId << ")";
7330   oss << " has the following name: \"" << _name << "\"." << std::endl;
7331   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7332   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7333     {
7334       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7335     }
7336   int i=0;
7337   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7338     {
7339       std::string chapter(17,'0'+i);
7340       oss << startLine << chapter << std::endl;
7341       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7342       if(cur)
7343         cur->simpleRepr(bkOffset+2,oss,i);
7344       else
7345         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7346       oss << startLine << chapter << std::endl;
7347     }
7348 }
7349
7350 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7351 {
7352   std::size_t sz=_time_steps.size();
7353   std::vector< std::pair<int,int> > ret(sz);
7354   ret1.resize(sz);
7355   for(std::size_t i=0;i<sz;i++)
7356     {
7357       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7358       if(f1ts)
7359         {
7360           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7361         }
7362       else
7363         {
7364           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7365           throw INTERP_KERNEL::Exception(oss.str().c_str());
7366         }
7367     }
7368   return ret;
7369 }
7370
7371 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7372 {
7373   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7374   if(!tse2)
7375     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7376   checkCoherencyOfType(tse2);
7377   if(_time_steps.empty())
7378     {
7379       setName(tse2->getName().c_str());
7380       setInfo(tse2->getInfo());
7381     }
7382   checkThatComponentsMatch(tse2->getInfo());
7383   _time_steps.push_back(tse);
7384 }
7385
7386 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7387 {
7388   std::size_t nbOfCompo=_infos.size();
7389   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7390     {
7391       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7392       if(cur)
7393         {
7394           if((cur->getInfo()).size()!=nbOfCompo)
7395             {
7396               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7397               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7398               throw INTERP_KERNEL::Exception(oss.str().c_str());
7399             }
7400           cur->copyNameScope(*this);
7401         }
7402     }
7403 }
7404
7405 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7406 {
7407   _time_steps.resize(nbPdt);
7408   for(int i=0;i<nbPdt;i++)
7409     {
7410       std::vector< std::pair<int,int> > ts;
7411       med_int numdt=0,numo=0;
7412       med_int meshIt=0,meshOrder=0;
7413       med_float dt=0.0;
7414       MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder));
7415       switch(fieldTyp)
7416       {
7417         case MED_FLOAT64:
7418           {
7419             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7420             break;
7421           }
7422         case MED_INT32:
7423           {
7424             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7425             break;
7426           }
7427         default:
7428           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7429       }
7430       if(loadAll)
7431         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7432       else
7433         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7434     }
7435 }
7436
7437 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7438 {
7439   if(_time_steps.empty())
7440     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7441   checkThatNbOfCompoOfTSMatchThis();
7442   std::vector<std::string> infos(getInfo());
7443   int nbComp=infos.size();
7444   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7445   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7446   for(int i=0;i<nbComp;i++)
7447     {
7448       std::string info=infos[i];
7449       std::string c,u;
7450       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7451       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7452       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7453     }
7454   if(_name.empty())
7455     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7456   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7457   int nbOfTS=_time_steps.size();
7458   for(int i=0;i<nbOfTS;i++)
7459     _time_steps[i]->writeLL(fid,opts,*this);
7460 }
7461
7462 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7463 {
7464   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7465     {
7466       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7467       if(elt)
7468         elt->loadBigArraysRecursively(fid,nasc);
7469     }
7470 }
7471
7472 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7473 {
7474   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7475     {
7476       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7477       if(elt)
7478         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7479     }
7480 }
7481
7482 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7483 {
7484   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7485     {
7486       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7487       if(elt)
7488         elt->unloadArrays();
7489     }
7490 }
7491
7492 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7493 {
7494   return _time_steps.size();
7495 }
7496
7497 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7498 {
7499   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7500   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7501     {
7502       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7503       if(tmp)
7504         newTS.push_back(*it);
7505     }
7506   _time_steps=newTS;
7507 }
7508
7509 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7510 {
7511   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7512   int maxId=(int)_time_steps.size();
7513   int ii=0;
7514   std::set<int> idsToDel;
7515   for(const int *id=startIds;id!=endIds;id++,ii++)
7516     {
7517       if(*id>=0 && *id<maxId)
7518         {
7519           idsToDel.insert(*id);
7520         }
7521       else
7522         {
7523           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7524           throw INTERP_KERNEL::Exception(oss.str().c_str());
7525         }
7526     }
7527   for(int iii=0;iii<maxId;iii++)
7528     if(idsToDel.find(iii)==idsToDel.end())
7529       newTS.push_back(_time_steps[iii]);
7530   _time_steps=newTS;
7531 }
7532
7533 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7534 {
7535   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7536   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7537   if(nbOfEntriesToKill==0)
7538     return ;
7539   std::size_t sz=_time_steps.size();
7540   std::vector<bool> b(sz,true);
7541   int j=bg;
7542   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7543     b[j]=false;
7544   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7545   for(std::size_t i=0;i<sz;i++)
7546     if(b[i])
7547       newTS.push_back(_time_steps[i]);
7548   _time_steps=newTS;
7549 }
7550
7551 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7552 {
7553   int ret=0;
7554   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7555   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7556     {
7557       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7558       if(tmp)
7559         {
7560           int it2,ord;
7561           tmp->getTime(it2,ord);
7562           if(it2==iteration && order==ord)
7563             return ret;
7564           else
7565             oss << "(" << it2 << ","  << ord << "), ";
7566         }
7567     }
7568   throw INTERP_KERNEL::Exception(oss.str().c_str());
7569 }
7570
7571 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7572 {
7573   int ret=0;
7574   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7575   oss.precision(15);
7576   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7577     {
7578       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7579       if(tmp)
7580         {
7581           int it2,ord;
7582           double ti=tmp->getTime(it2,ord);
7583           if(fabs(time-ti)<eps)
7584             return ret;
7585           else
7586             oss << ti << ", ";
7587         }
7588     }
7589   throw INTERP_KERNEL::Exception(oss.str().c_str());
7590 }
7591
7592 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7593 {
7594   int lgth=_time_steps.size();
7595   std::vector< std::pair<int,int> > ret(lgth);
7596   for(int i=0;i<lgth;i++)
7597     _time_steps[i]->fillIteration(ret[i]);
7598   return ret;
7599 }
7600
7601 /*!
7602  * 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'
7603  * This method returns two things.
7604  * - The absolute dimension of 'this' in first parameter. 
7605  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7606  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7607  *
7608  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7609  * Only these 3 discretizations will be taken into account here.
7610  *
7611  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7612  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7613  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7614  *
7615  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7616  * 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'.
7617  * 
7618  * Let's consider the typical following case :
7619  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7620  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7621  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7622  *   TETRA4 and SEG2
7623  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7624  *
7625  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7626  * 
7627  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7628  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7629  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7630  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7631  */
7632 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7633 {
7634   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7635 }
7636
7637 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7638 {
7639   if(pos<0 || pos>=(int)_time_steps.size())
7640     {
7641       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7642       throw INTERP_KERNEL::Exception(oss.str().c_str());
7643     }
7644   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7645   if(item==0)
7646     {
7647       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7648       oss << "\nTry to use following method eraseEmptyTS !";
7649       throw INTERP_KERNEL::Exception(oss.str().c_str());
7650     }
7651   return item;
7652 }
7653
7654 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7655 {
7656   if(pos<0 || pos>=(int)_time_steps.size())
7657     {
7658       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7659       throw INTERP_KERNEL::Exception(oss.str().c_str());
7660     }
7661   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7662   if(item==0)
7663     {
7664       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7665       oss << "\nTry to use following method eraseEmptyTS !";
7666       throw INTERP_KERNEL::Exception(oss.str().c_str());
7667     }
7668   return item;
7669 }
7670
7671 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7672 {
7673   std::vector<std::string> ret;
7674   std::set<std::string> ret2;
7675   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7676     {
7677       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7678       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7679         if(ret2.find(*it2)==ret2.end())
7680           {
7681             ret.push_back(*it2);
7682             ret2.insert(*it2);
7683           }
7684     }
7685   return ret;
7686 }
7687
7688 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7689 {
7690   std::vector<std::string> ret;
7691   std::set<std::string> ret2;
7692   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7693     {
7694       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7695       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7696         if(ret2.find(*it2)==ret2.end())
7697           {
7698             ret.push_back(*it2);
7699             ret2.insert(*it2);
7700           }
7701     }
7702   return ret;
7703 }
7704
7705 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7706 {
7707   std::vector<std::string> ret;
7708   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7709     {
7710       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7711       ret.insert(ret.end(),tmp.begin(),tmp.end());
7712     }
7713   return ret;
7714 }
7715
7716 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7717 {
7718   std::vector<std::string> ret;
7719   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7720     {
7721       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7722       ret.insert(ret.end(),tmp.begin(),tmp.end());
7723     }
7724   return ret;
7725 }
7726
7727 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7728 {
7729   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7730     (*it)->changePflsRefsNamesGen2(mapOfModif);
7731 }
7732
7733 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7734 {
7735   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7736     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7737 }
7738
7739 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7740 {
7741   int lgth=_time_steps.size();
7742   std::vector< std::vector<TypeOfField> > ret(lgth);
7743   for(int i=0;i<lgth;i++)
7744     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7745   return ret;
7746 }
7747
7748 /*!
7749  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7750  */
7751 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
7752 {
7753   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7754 }
7755
7756 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7757 {
7758   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7759   std::size_t i=0;
7760   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7761     {
7762       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7763         ret->_time_steps[i]=(*it)->deepCopy();
7764     }
7765   return ret.retn();
7766 }
7767
7768 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7769 {
7770   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7771   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7772   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7773   for(std::size_t i=0;i<sz;i++)
7774     {
7775       ret[i]=shallowCpy();
7776       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7777     }
7778   for(std::size_t i=0;i<sz2;i++)
7779     {
7780       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7781       if(ret1.size()!=sz)
7782         {
7783           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7784           throw INTERP_KERNEL::Exception(oss.str().c_str());
7785         }
7786       ts[i]=ret1;
7787     }
7788   for(std::size_t i=0;i<sz;i++)
7789     for(std::size_t j=0;j<sz2;j++)
7790       ret[i]->_time_steps[j]=ts[j][i];
7791   return ret;
7792 }
7793
7794 /*!
7795  * This method splits into discretization each time steps in \a this.
7796  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7797  */
7798 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7799 {
7800   std::size_t sz(_time_steps.size());
7801   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7802   for(std::size_t i=0;i<sz;i++)
7803     {
7804       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7805       if(!timeStep)
7806         {
7807           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7808           throw INTERP_KERNEL::Exception(oss.str().c_str());
7809         }
7810       items[i]=timeStep->splitDiscretizations();  
7811     }
7812   //
7813   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7814   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7815   std::vector< TypeOfField > types;
7816   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7817     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7818       {
7819         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7820         if(ts.size()!=1)
7821           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7822         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7823         if(it2==types.end())
7824           types.push_back(ts[0]);
7825       }
7826   ret.resize(types.size()); ret2.resize(types.size());
7827   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7828     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7829       {
7830         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7831         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7832         ret2[pos].push_back(*it1);
7833       }
7834   for(std::size_t i=0;i<types.size();i++)
7835     {
7836       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7837       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7838         elt->pushBackTimeStep(*it1);//also updates infos in elt
7839       ret[i]=elt;
7840       elt->MEDFileFieldNameScope::operator=(*this);
7841     }
7842   return ret;
7843 }
7844
7845 /*!
7846  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7847  */
7848 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7849 {
7850   std::size_t sz(_time_steps.size());
7851   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7852   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7853   for(std::size_t i=0;i<sz;i++)
7854     {
7855       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7856       if(!timeStep)
7857         {
7858           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7859           throw INTERP_KERNEL::Exception(oss.str().c_str());
7860         }
7861       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7862       if(szOut==std::numeric_limits<std::size_t>::max())
7863         szOut=items[i].size();
7864       else
7865         if(items[i].size()!=szOut)
7866           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7867     }
7868   if(szOut==std::numeric_limits<std::size_t>::max())
7869     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7870   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7871   for(std::size_t i=0;i<szOut;i++)
7872     {
7873       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7874       for(std::size_t j=0;j<sz;j++)
7875         elt->pushBackTimeStep(items[j][i]);
7876       ret[i]=elt;
7877       elt->MEDFileFieldNameScope::operator=(*this);
7878     }
7879   return ret;
7880 }
7881
7882 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7883 {
7884   _name=field->getName();
7885   if(_name.empty())
7886     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7887   if(!arr)
7888     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7889   _infos=arr->getInfoOnComponents();
7890 }
7891
7892 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7893 {
7894   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7895   if(_name!=field->getName())
7896     {
7897       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7898       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7899       throw INTERP_KERNEL::Exception(oss.str().c_str());
7900     }
7901   if(!arr)
7902     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7903   checkThatComponentsMatch(arr->getInfoOnComponents());
7904 }
7905
7906 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7907 {
7908   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7909   if(getInfo().size()!=compos.size())
7910     {
7911       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7912       oss << " number of components of element to append (" << compos.size() << ") !";
7913       throw INTERP_KERNEL::Exception(oss.str().c_str());
7914     }
7915   if(_infos!=compos)
7916     {
7917       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7918       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7919       oss << " But compo in input fields are : ";
7920       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7921       oss << " !";
7922       throw INTERP_KERNEL::Exception(oss.str().c_str());
7923     }
7924 }
7925
7926 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7927 {
7928   std::size_t sz=_infos.size();
7929   int j=0;
7930   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7931     {
7932       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7933       if(elt)
7934         if(elt->getInfo().size()!=sz)
7935           {
7936             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7937             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7938             throw INTERP_KERNEL::Exception(oss.str().c_str());
7939           }
7940     }
7941 }
7942
7943 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7944 {
7945   if(!field)
7946     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7947   if(!_time_steps.empty())
7948     checkCoherencyOfTinyInfo(field,arr);
7949   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7950   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7951   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7952   copyTinyInfoFrom(field,arr);
7953   _time_steps.push_back(obj);
7954 }
7955
7956 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7957 {
7958   if(!field)
7959     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7960   if(!_time_steps.empty())
7961     checkCoherencyOfTinyInfo(field,arr);
7962   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7963   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7964   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7965   copyTinyInfoFrom(field,arr);
7966   _time_steps.push_back(obj);
7967 }
7968
7969 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
7970 {
7971   int sz=(int)_time_steps.size();
7972   if(i<0 || i>=sz)
7973     {
7974       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7975       throw INTERP_KERNEL::Exception(oss.str().c_str());
7976     }
7977   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7978   if(tsPtr)
7979     {
7980       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7981         {
7982           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7983           throw INTERP_KERNEL::Exception(oss.str().c_str());
7984         }
7985     }
7986   _time_steps[i]=ts;
7987 }
7988
7989 //= MEDFileFieldMultiTSWithoutSDA
7990
7991 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7992 {
7993   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
7994 }
7995
7996 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7997 {
7998 }
7999
8000 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8001 {
8002 }
8003
8004 /*!
8005  * \param [in] fieldId field id in C mode
8006  */
8007 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8008 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8009 {
8010 }
8011 catch(INTERP_KERNEL::Exception& e)
8012 { throw e; }
8013
8014 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8015 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8016 {
8017 }
8018 catch(INTERP_KERNEL::Exception& e)
8019 { throw e; }
8020
8021 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8022 {
8023   return new MEDFileField1TSWithoutSDA;
8024 }
8025
8026 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8027 {
8028   if(!f1ts)
8029     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8030   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8031   if(!f1tsC)
8032     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8033 }
8034
8035 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8036 {
8037   return MEDFileField1TSWithoutSDA::TYPE_STR;
8038 }
8039
8040 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8041 {
8042   return new MEDFileFieldMultiTSWithoutSDA(*this);
8043 }
8044
8045 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8046 {
8047   return new MEDFileFieldMultiTSWithoutSDA;
8048 }
8049
8050 /*!
8051  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8052  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8053  */
8054 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
8055 {
8056   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8057   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8058   if(!myF1TSC)
8059     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8060   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8061 }
8062
8063 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8064 {
8065   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8066   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8067   int i=0;
8068   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8069     {
8070       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8071       if(eltToConv)
8072         {
8073           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8074           if(!eltToConvC)
8075             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8076           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8077           ret->setIteration(i,elt);
8078         }
8079     }
8080   return ret.retn();
8081 }
8082
8083 //= MEDFileAnyTypeFieldMultiTS
8084
8085 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8086 {
8087 }
8088
8089 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8090 try:MEDFileFieldGlobsReal(fileName)
8091 {
8092   MEDFileUtilities::CheckFileForRead(fileName);
8093   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8094   _content=BuildContentFrom(fid,fileName,loadAll,ms);
8095   loadGlobals(fid);
8096 }
8097 catch(INTERP_KERNEL::Exception& e)
8098 {
8099     throw e;
8100 }
8101
8102 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8103 {
8104   med_field_type typcha;
8105   std::vector<std::string> infos;
8106   std::string dtunit;
8107   int i=-1;
8108   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
8109   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8110   switch(typcha)
8111   {
8112     case MED_FLOAT64:
8113       {
8114         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8115         break;
8116       }
8117     case MED_INT32:
8118       {
8119         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8120         break;
8121       }
8122     default:
8123       {
8124         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
8125         throw INTERP_KERNEL::Exception(oss.str().c_str());
8126       }
8127   }
8128   ret->setDtUnit(dtunit.c_str());
8129   return ret.retn();
8130 }
8131
8132 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8133 {
8134   med_field_type typcha;
8135   //
8136   std::vector<std::string> infos;
8137   std::string dtunit,fieldName;
8138   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
8139   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8140   switch(typcha)
8141   {
8142     case MED_FLOAT64:
8143       {
8144         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8145         break;
8146       }
8147     case MED_INT32:
8148       {
8149         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8150         break;
8151       }
8152     default:
8153       {
8154         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
8155         throw INTERP_KERNEL::Exception(oss.str().c_str());
8156       }
8157   }
8158   ret->setDtUnit(dtunit.c_str());
8159   return ret.retn();
8160 }
8161
8162 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
8163 {
8164   if(!c)
8165     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8166   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8167     {
8168       MCAuto<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
8169       ret->setFileName(fileName);
8170       ret->_content=c;  c->incrRef();
8171       return ret.retn();
8172     }
8173   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8174     {
8175       MCAuto<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
8176       ret->setFileName(fileName);
8177       ret->_content=c;  c->incrRef();
8178       return ret.retn();
8179     }
8180   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8181 }
8182
8183 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8184 try:MEDFileFieldGlobsReal(fileName)
8185 {
8186   MEDFileUtilities::CheckFileForRead(fileName);
8187   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8188   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms,entities);
8189   loadGlobals(fid);
8190 }
8191 catch(INTERP_KERNEL::Exception& e)
8192 {
8193     throw e;
8194 }
8195
8196 //= MEDFileIntFieldMultiTSWithoutSDA
8197
8198 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8199 {
8200   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8201 }
8202
8203 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8204 {
8205 }
8206
8207 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8208 {
8209 }
8210
8211 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8212 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8213 {
8214 }
8215 catch(INTERP_KERNEL::Exception& e)
8216 { throw e; }
8217
8218 /*!
8219  * \param [in] fieldId field id in C mode
8220  */
8221 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8222 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8223 {
8224 }
8225 catch(INTERP_KERNEL::Exception& e)
8226 { throw e; }
8227
8228 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8229 {
8230   return new MEDFileIntField1TSWithoutSDA;
8231 }
8232
8233 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8234 {
8235   if(!f1ts)
8236     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8237   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8238   if(!f1tsC)
8239     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8240 }
8241
8242 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8243 {
8244   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8245 }
8246
8247 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8248 {
8249   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8250 }
8251
8252 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8253 {
8254   return new MEDFileIntFieldMultiTSWithoutSDA;
8255 }
8256
8257 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8258 {
8259   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8260   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8261   int i=0;
8262   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8263     {
8264       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8265       if(eltToConv)
8266         {
8267           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8268           if(!eltToConvC)
8269             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8270           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8271           ret->setIteration(i,elt);
8272         }
8273     }
8274   return ret.retn();
8275 }
8276
8277 //= MEDFileAnyTypeFieldMultiTS
8278
8279 /*!
8280  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8281  * that has been read from a specified MED file.
8282  *  \param [in] fileName - the name of the MED file to read.
8283  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8284  *          is to delete this field using decrRef() as it is no more needed.
8285  *  \throw If reading the file fails.
8286  */
8287 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8288 {
8289   MEDFileUtilities::CheckFileForRead(fileName);
8290   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8291   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
8292   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8293   ret->loadGlobals(fid);
8294   return ret.retn();
8295 }
8296
8297 /*!
8298  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8299  * that has been read from a specified MED file.
8300  *  \param [in] fileName - the name of the MED file to read.
8301  *  \param [in] fieldName - the name of the field to read.
8302  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8303  *          is to delete this field using decrRef() as it is no more needed.
8304  *  \throw If reading the file fails.
8305  *  \throw If there is no field named \a fieldName in the file.
8306  */
8307 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8308 {
8309   MEDFileUtilities::CheckFileForRead(fileName);
8310   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8311   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fileName,fieldName,loadAll,0,0));
8312   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8313   ret->loadGlobals(fid);
8314   return ret.retn();
8315 }
8316
8317 /*!
8318  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8319  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8320  *
8321  * \warning this is a shallow copy constructor
8322  */
8323 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8324 {
8325   if(!shallowCopyOfContent)
8326     {
8327       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8328       otherPtr->incrRef();
8329       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8330     }
8331   else
8332     {
8333       _content=other.shallowCpy();
8334     }
8335 }
8336
8337 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8338 {
8339   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8340   if(!ret)
8341     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8342   return ret;
8343 }
8344
8345 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8346 {
8347   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8348   if(!ret)
8349     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8350   return ret;
8351 }
8352
8353 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8354 {
8355   return contentNotNullBase()->getPflsReallyUsed2();
8356 }
8357
8358 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8359 {
8360   return contentNotNullBase()->getLocsReallyUsed2();
8361 }
8362
8363 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8364 {
8365   return contentNotNullBase()->getPflsReallyUsedMulti2();
8366 }
8367
8368 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8369 {
8370   return contentNotNullBase()->getLocsReallyUsedMulti2();
8371 }
8372
8373 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8374 {
8375   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8376 }
8377
8378 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8379 {
8380   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8381 }
8382
8383 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8384 {
8385   return contentNotNullBase()->getNumberOfTS();
8386 }
8387
8388 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8389 {
8390   contentNotNullBase()->eraseEmptyTS();
8391 }
8392
8393 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8394 {
8395   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8396 }
8397
8398 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8399 {
8400   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8401 }
8402
8403 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8404 {
8405   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8406   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8407   ret->_content=c;
8408   return ret.retn();
8409 }
8410
8411 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8412 {
8413   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8414   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8415   ret->_content=c;
8416   return ret.retn();
8417 }
8418
8419 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8420 {
8421   return contentNotNullBase()->getIterations();
8422 }
8423
8424 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8425 {
8426   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8427     pushBackTimeStep(*it);
8428 }
8429
8430 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8431 {
8432   if(!fmts)
8433     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8434   int nbOfTS(fmts->getNumberOfTS());
8435   for(int i=0;i<nbOfTS;i++)
8436     {
8437       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8438       pushBackTimeStep(elt);
8439     }
8440 }
8441
8442 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8443 {
8444   if(!f1ts)
8445     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8446   checkCoherencyOfType(f1ts);
8447   f1ts->incrRef();
8448   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8449   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8450   c->incrRef();
8451   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8452   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8453     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8454   _content->pushBackTimeStep(cSafe);
8455   appendGlobs(*f1ts,1e-12);
8456 }
8457
8458 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8459 {
8460   contentNotNullBase()->synchronizeNameScope();
8461 }
8462
8463 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8464 {
8465   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8466 }
8467
8468 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8469 {
8470   return contentNotNullBase()->getPosGivenTime(time,eps);
8471 }
8472
8473 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8474 {
8475   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8476 }
8477
8478 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8479 {
8480   return contentNotNullBase()->getTypesOfFieldAvailable();
8481 }
8482
8483 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
8484 {
8485   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8486 }
8487
8488 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8489 {
8490   return contentNotNullBase()->getName();
8491 }
8492
8493 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8494 {
8495   contentNotNullBase()->setName(name);
8496 }
8497
8498 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8499 {
8500   return contentNotNullBase()->getDtUnit();
8501 }
8502
8503 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8504 {
8505   contentNotNullBase()->setDtUnit(dtUnit);
8506 }
8507
8508 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8509 {
8510   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8511 }
8512
8513 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8514 {
8515   return contentNotNullBase()->getTimeSteps(ret1);
8516 }
8517
8518 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8519 {
8520   return contentNotNullBase()->getMeshName();
8521 }
8522
8523 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8524 {
8525   contentNotNullBase()->setMeshName(newMeshName);
8526 }
8527
8528 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8529 {
8530   return contentNotNullBase()->changeMeshNames(modifTab);
8531 }
8532
8533 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8534 {
8535   return contentNotNullBase()->getInfo();
8536 }
8537
8538 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8539 {
8540   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8541 }
8542
8543 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8544 {
8545   return contentNotNullBase()->setInfo(info);
8546 }
8547
8548 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8549 {
8550   const std::vector<std::string> ret=getInfo();
8551   return (int)ret.size();
8552 }
8553
8554 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8555 {
8556   writeGlobals(fid,*this);
8557   contentNotNullBase()->writeLL(fid,*this);
8558 }
8559
8560 /*!
8561  * Writes \a this field into a MED file specified by its name.
8562  *  \param [in] fileName - the MED file name.
8563  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8564  * - 2 - erase; an existing file is removed.
8565  * - 1 - append; same data should not be present in an existing file.
8566  * - 0 - overwrite; same data present in an existing file is overwritten.
8567  *  \throw If the field name is not set.
8568  *  \throw If no field data is set.
8569  *  \throw If \a mode == 1 and the same data is present in an existing file.
8570  */
8571 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8572 {
8573   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8574   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8575   writeLL(fid);
8576 }
8577
8578 /*!
8579  * This method alloc the arrays and load potentially huge arrays contained in this field.
8580  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8581  * This method can be also called to refresh or reinit values from a file.
8582  * 
8583  * \throw If the fileName is not set or points to a non readable MED file.
8584  */
8585 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8586 {
8587   if(getFileName().empty())
8588     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8589   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8590   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8591 }
8592
8593 /*!
8594  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8595  * But once data loaded once, this method does nothing.
8596  * 
8597  * \throw If the fileName is not set or points to a non readable MED file.
8598  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8599  */
8600 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8601 {
8602   if(!getFileName().empty())
8603     {
8604       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8605       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8606     }
8607 }
8608
8609 /*!
8610  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8611  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8612  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8613  * 
8614  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8615  */
8616 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8617 {
8618   contentNotNullBase()->unloadArrays();
8619 }
8620
8621 /*!
8622  * 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.
8623  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8624  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8625  * 
8626  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8627  */
8628 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8629 {
8630   if(!getFileName().empty())
8631     contentNotNullBase()->unloadArrays();
8632 }
8633
8634 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8635 {
8636   std::ostringstream oss;
8637   contentNotNullBase()->simpleRepr(0,oss,-1);
8638   simpleReprGlobs(oss);
8639   return oss.str();
8640 }
8641
8642 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8643 {
8644   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8645 }
8646
8647 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8648 {
8649   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8650   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8651   return ret;
8652 }
8653
8654 /*!
8655  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8656  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8657  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8658  */
8659 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8660 {
8661   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8662   if(!content)
8663     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8664   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8665   std::size_t sz(contentsSplit.size());
8666   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8667   for(std::size_t i=0;i<sz;i++)
8668     {
8669       ret[i]=shallowCpy();
8670       ret[i]->_content=contentsSplit[i];
8671     }
8672   return ret;
8673 }
8674
8675 /*!
8676  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8677  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8678  */
8679 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8680 {
8681   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8682   if(!content)
8683     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8684   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8685   std::size_t sz(contentsSplit.size());
8686   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8687   for(std::size_t i=0;i<sz;i++)
8688     {
8689       ret[i]=shallowCpy();
8690       ret[i]->_content=contentsSplit[i];
8691     }
8692   return ret;
8693 }
8694
8695 /*!
8696  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8697  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8698  */
8699 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8700 {
8701   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8702   if(!content)
8703     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8704   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8705   std::size_t sz(contentsSplit.size());
8706   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8707   for(std::size_t i=0;i<sz;i++)
8708     {
8709       ret[i]=shallowCpy();
8710       ret[i]->_content=contentsSplit[i];
8711     }
8712   return ret;
8713 }
8714
8715 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8716 {
8717   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8718   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8719     ret->_content=_content->deepCopy();
8720   ret->deepCpyGlobs(*this);
8721   return ret.retn();
8722 }
8723
8724 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8725 {
8726   return _content;
8727 }
8728
8729 /*!
8730  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8731  *  \param [in] iteration - the iteration number of a required time step.
8732  *  \param [in] order - the iteration order number of required time step.
8733  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8734  *          delete this field using decrRef() as it is no more needed.
8735  *  \throw If there is no required time step in \a this field.
8736  */
8737 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8738 {
8739   int pos=getPosOfTimeStep(iteration,order);
8740   return getTimeStepAtPos(pos);
8741 }
8742
8743 /*!
8744  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8745  *  \param [in] time - the time of the time step of interest.
8746  *  \param [in] eps - a precision used to compare time values.
8747  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8748  *          delete this field using decrRef() as it is no more needed.
8749  *  \throw If there is no required time step in \a this field.
8750  */
8751 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8752 {
8753   int pos=getPosGivenTime(time,eps);
8754   return getTimeStepAtPos(pos);
8755 }
8756
8757 /*!
8758  * 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.
8759  * The float64 value of time attached to the pair of integers are not considered here.
8760  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8761  *
8762  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8763  * \throw If there is a null pointer in \a vectFMTS.
8764  */
8765 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8766 {
8767   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8768   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8769   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8770   while(!lstFMTS.empty())
8771     {
8772       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8773       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8774       if(!curIt)
8775         throw INTERP_KERNEL::Exception(msg);
8776       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8777       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8778       elt.push_back(curIt); it=lstFMTS.erase(it);
8779       while(it!=lstFMTS.end())
8780         {
8781           curIt=*it;
8782           if(!curIt)
8783             throw INTERP_KERNEL::Exception(msg);
8784           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8785           if(refIts==curIts)
8786             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8787           else
8788             it++;
8789         }
8790       ret.push_back(elt);
8791     }
8792   return ret;
8793 }
8794
8795 /*!
8796  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8797  * All returned instances in a subvector can be safely loaded, rendered along time
8798  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8799  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8800  * 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).
8801  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8802  * 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.
8803  *
8804  * \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().
8805  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8806  * \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.
8807  * \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.
8808  *
8809  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8810  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8811  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8812  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8813  * \throw If mesh is null.
8814  * \throw If an element in \a vectFMTS is null.
8815  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8816  */
8817 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
8818 {
8819   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8820   if(!mesh)
8821     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8822   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8823   if(vectFMTS.empty())
8824     return ret;
8825   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8826   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8827   if(!frstElt)
8828     throw INTERP_KERNEL::Exception(msg);
8829   std::size_t i=0;
8830   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8831   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8832   for(;it!=vectFMTS.end();it++,i++)
8833     {
8834       if(!(*it))
8835         throw INTERP_KERNEL::Exception(msg);
8836       TypeOfField tof0,tof1;
8837       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8838         {
8839           if(tof1!=ON_NODES)
8840             vectFMTSNotNodes.push_back(*it);
8841           else
8842             vectFMTSNodes.push_back(*it);
8843         }
8844       else
8845         vectFMTSNotNodes.push_back(*it);
8846     }
8847   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
8848   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8849   ret=retCell;
8850   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8851     {
8852       i=0;
8853       bool isFetched(false);
8854       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8855         {
8856           if((*it0).empty())
8857             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8858           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8859             { ret[i].push_back(*it2); isFetched=true; }
8860         }
8861       if(!isFetched)
8862         {
8863           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8864           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8865           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8866         }
8867     }
8868   fsc=cmps;
8869   return ret;
8870 }
8871
8872 /*!
8873  * 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.
8874  * \param [out] cmps - same size than the returned vector.
8875  */
8876 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
8877 {
8878   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8879   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8880   while(!lstFMTS.empty())
8881     {
8882       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8883       MEDFileAnyTypeFieldMultiTS *ref(*it);
8884       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8885       elt.push_back(ref); it=lstFMTS.erase(it);
8886       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8887       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8888       while(it!=lstFMTS.end())
8889         {
8890           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8891           if(cmp->isEqual(curIt))
8892             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8893           else
8894             it++;
8895         }
8896       ret.push_back(elt); cmps.push_back(cmp);
8897     }
8898   return ret;
8899 }
8900
8901 /*!
8902  * 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.
8903  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8904  *
8905  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8906  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8907  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8908  * \thorw If \a f0 and \a f1 do not have the same times steps.
8909  * \throw If mesh is null.
8910  * \throw If \a f0 or \a f1 is null.
8911  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8912  */
8913 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8914 {
8915   if(!mesh)
8916     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8917   if(!f0 || !f1)
8918     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8919   if(f0->getMeshName()!=mesh->getName())
8920     {
8921       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8922       throw INTERP_KERNEL::Exception(oss.str().c_str());
8923     }
8924   if(f1->getMeshName()!=mesh->getName())
8925     {
8926       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8927       throw INTERP_KERNEL::Exception(oss.str().c_str());
8928     }
8929   int nts=f0->getNumberOfTS();
8930   if(nts!=f1->getNumberOfTS())
8931     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8932   if(nts==0)
8933     return nts;
8934   for(int i=0;i<nts;i++)
8935     {
8936       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8937       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8938       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8939       if(tofs0.size()!=1 || tofs1.size()!=1)
8940         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8941       if(i!=0)
8942         {
8943           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8944             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8945         }
8946       else
8947         { tof0=tofs0[0]; tof1=tofs1[0]; }
8948       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8949         {
8950           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() << ") !";
8951           throw INTERP_KERNEL::Exception(oss.str().c_str());
8952         }
8953       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8954         {
8955           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() << ") !";
8956           throw INTERP_KERNEL::Exception(oss.str().c_str());
8957         }
8958       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8959         {
8960           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() << ") !";
8961           throw INTERP_KERNEL::Exception(oss.str().c_str());
8962         }
8963     }
8964   return nts;
8965 }
8966
8967 /*!
8968  * Return an extraction of \a this using \a extractDef map to specify the extraction.
8969  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
8970  *
8971  * \return A new object that the caller is responsible to deallocate.
8972  */
8973 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
8974 {
8975   if(!mm)
8976     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
8977   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
8978   int nbTS(getNumberOfTS());
8979   for(int i=0;i<nbTS;i++)
8980     {
8981       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
8982       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
8983       fmtsOut->pushBackTimeStep(f1tsOut);
8984     }
8985   return fmtsOut.retn();
8986 }
8987
8988 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8989 {
8990   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8991 }
8992
8993 //= MEDFileFieldMultiTS
8994
8995 /*!
8996  * Returns a new empty instance of MEDFileFieldMultiTS.
8997  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8998  *          is to delete this field using decrRef() as it is no more needed.
8999  */
9000 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9001 {
9002   return new MEDFileFieldMultiTS;
9003 }
9004
9005 /*!
9006  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9007  * that has been read from a specified MED file.
9008  *  \param [in] fileName - the name of the MED file to read.
9009  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9010  *          is to delete this field using decrRef() as it is no more needed.
9011  *  \throw If reading the file fails.
9012  */
9013 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9014 {
9015   MCAuto<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
9016   ret->contentNotNull();//to check that content type matches with \a this type.
9017   return ret.retn();
9018 }
9019
9020 /*!
9021  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9022  * that has been read from a specified MED file.
9023  *  \param [in] fileName - the name of the MED file to read.
9024  *  \param [in] fieldName - the name of the field to read.
9025  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9026  *          is to delete this field using decrRef() as it is no more needed.
9027  *  \throw If reading the file fails.
9028  *  \throw If there is no field named \a fieldName in the file.
9029  */
9030 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9031 {
9032   MCAuto<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
9033   ret->contentNotNull();//to check that content type matches with \a this type.
9034   return ret.retn();
9035 }
9036
9037 /*!
9038  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9039  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9040  *
9041  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9042  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9043  * \warning this is a shallow copy constructor
9044  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9045  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9046  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9047  *          is to delete this field using decrRef() as it is no more needed.
9048  */
9049 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9050 {
9051   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9052 }
9053
9054 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9055 {
9056   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0,&entities));
9057   ret->contentNotNull();//to check that content type matches with \a this type.
9058   return ret.retn();
9059 }
9060
9061 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9062 {
9063   return new MEDFileFieldMultiTS(*this);
9064 }
9065
9066 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9067 {
9068   if(!f1ts)
9069     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9070   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9071   if(!f1tsC)
9072     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9073 }
9074
9075 /*!
9076  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9077  * following the given input policy.
9078  *
9079  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9080  *                            By default (true) the globals are deeply copied.
9081  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9082  */
9083 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9084 {
9085   MCAuto<MEDFileIntFieldMultiTS> ret;
9086   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9087   if(content)
9088     {
9089       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9090       if(!contc)
9091         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9092       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9093       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
9094     }
9095   else
9096     ret=MEDFileIntFieldMultiTS::New();
9097   if(isDeepCpyGlobs)
9098     ret->deepCpyGlobs(*this);
9099   else
9100     ret->shallowCpyGlobs(*this);
9101   return ret.retn();
9102 }
9103
9104 /*!
9105  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9106  *  \param [in] pos - a time step id.
9107  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9108  *          delete this field using decrRef() as it is no more needed.
9109  *  \throw If \a pos is not a valid time step id.
9110  */
9111 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9112 {
9113   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9114   if(!item)
9115     {
9116       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9117       throw INTERP_KERNEL::Exception(oss.str().c_str());
9118     }
9119   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9120   if(itemC)
9121     {
9122       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9123       ret->shallowCpyGlobs(*this);
9124       return ret.retn();
9125     }
9126   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9127   throw INTERP_KERNEL::Exception(oss.str().c_str());
9128 }
9129
9130 /*!
9131  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9132  * mesh entities of a given dimension of the first mesh in MED file.
9133  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9134  *  \param [in] type - a spatial discretization of interest.
9135  *  \param [in] iteration - the iteration number of a required time step.
9136  *  \param [in] order - the iteration order number of required time step.
9137  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9138  *  \param [in] renumPol - specifies how to permute values of the result field according to
9139  *          the optional numbers of cells and nodes, if any. The valid values are
9140  *          - 0 - do not permute.
9141  *          - 1 - permute cells.
9142  *          - 2 - permute nodes.
9143  *          - 3 - permute cells and nodes.
9144  *
9145  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9146  *          caller is to delete this field using decrRef() as it is no more needed. 
9147  *  \throw If the MED file is not readable.
9148  *  \throw If there is no mesh in the MED file.
9149  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9150  *  \throw If no field values of the required parameters are available.
9151  */
9152 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9153 {
9154   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9155   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9156   if(!myF1TSC)
9157     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9158   MCAuto<DataArray> arrOut;
9159   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9160   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9161   return ret.retn();
9162 }
9163
9164 /*!
9165  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9166  * the top level cells of the first mesh in MED file.
9167  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9168  *  \param [in] type - a spatial discretization of interest.
9169  *  \param [in] iteration - the iteration number of a required time step.
9170  *  \param [in] order - the iteration order number of required time step.
9171  *  \param [in] renumPol - specifies how to permute values of the result field according to
9172  *          the optional numbers of cells and nodes, if any. The valid values are
9173  *          - 0 - do not permute.
9174  *          - 1 - permute cells.
9175  *          - 2 - permute nodes.
9176  *          - 3 - permute cells and nodes.
9177  *
9178  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9179  *          caller is to delete this field using decrRef() as it is no more needed. 
9180  *  \throw If the MED file is not readable.
9181  *  \throw If there is no mesh in the MED file.
9182  *  \throw If no field values of the required parameters are available.
9183  */
9184 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9185 {
9186   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9187   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9188   if(!myF1TSC)
9189     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9190   MCAuto<DataArray> arrOut;
9191   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9192   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9193   return ret.retn();
9194 }
9195
9196 /*!
9197  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9198  * a given support.
9199  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9200  *  \param [in] type - a spatial discretization of interest.
9201  *  \param [in] iteration - the iteration number of a required time step.
9202  *  \param [in] order - the iteration order number of required time step.
9203  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9204  *  \param [in] mesh - the supporting mesh.
9205  *  \param [in] renumPol - specifies how to permute values of the result field according to
9206  *          the optional numbers of cells and nodes, if any. The valid values are
9207  *          - 0 - do not permute.
9208  *          - 1 - permute cells.
9209  *          - 2 - permute nodes.
9210  *          - 3 - permute cells and nodes.
9211  *
9212  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9213  *          caller is to delete this field using decrRef() as it is no more needed. 
9214  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9215  *  \throw If no field of \a this is lying on \a mesh.
9216  *  \throw If no field values of the required parameters are available.
9217  */
9218 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9219 {
9220   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9221   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9222   if(!myF1TSC)
9223     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9224   MCAuto<DataArray> arrOut;
9225   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9226   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9227   return ret.retn();
9228 }
9229
9230 /*!
9231  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9232  * given support. 
9233  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9234  *  \param [in] type - a spatial discretization of the new field.
9235  *  \param [in] iteration - the iteration number of a required time step.
9236  *  \param [in] order - the iteration order number of required time step.
9237  *  \param [in] mesh - the supporting mesh.
9238  *  \param [in] renumPol - specifies how to permute values of the result field according to
9239  *          the optional numbers of cells and nodes, if any. The valid values are
9240  *          - 0 - do not permute.
9241  *          - 1 - permute cells.
9242  *          - 2 - permute nodes.
9243  *          - 3 - permute cells and nodes.
9244  *
9245  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9246  *          caller is to delete this field using decrRef() as it is no more needed. 
9247  *  \throw If no field of \a this is lying on \a mesh.
9248  *  \throw If no field values of the required parameters are available.
9249  */
9250 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9251 {
9252   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9253   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9254   if(!myF1TSC)
9255     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9256   MCAuto<DataArray> arrOut;
9257   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9258   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9259   return ret.retn();
9260 }
9261
9262 /*!
9263  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9264  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9265  * This method is useful for MED2 file format when field on different mesh was autorized.
9266  */
9267 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9268 {
9269   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9270   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9271   if(!myF1TSC)
9272     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9273   MCAuto<DataArray> arrOut;
9274   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9275   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9276   return ret.retn();
9277 }
9278
9279 /*!
9280  * Returns values and a profile of the field of a given type, of a given time step,
9281  * lying on a given support.
9282  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9283  *  \param [in] type - a spatial discretization of the field.
9284  *  \param [in] iteration - the iteration number of a required time step.
9285  *  \param [in] order - the iteration order number of required time step.
9286  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9287  *  \param [in] mesh - the supporting mesh.
9288  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9289  *          field of interest lies on. If the field lies on all entities of the given
9290  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9291  *          using decrRef() as it is no more needed.  
9292  *  \param [in] glob - the global data storing profiles and localization.
9293  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9294  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9295  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9296  *  \throw If no field of \a this is lying on \a mesh.
9297  *  \throw If no field values of the required parameters are available.
9298  */
9299 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9300 {
9301   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9302   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9303   if(!myF1TSC)
9304     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9305   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9306   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9307 }
9308
9309 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9310 {
9311   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9312   if(!pt)
9313     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9314   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9315   if(!ret)
9316     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 !");
9317   return ret;
9318 }
9319
9320 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9321 {
9322   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9323   if(!pt)
9324     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9325   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9326   if(!ret)
9327     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 !");
9328   return ret;
9329 }
9330
9331 /*!
9332  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9333  * the given field is checked if its elements are sorted suitable for writing to MED file
9334  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9335  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9336  *  \param [in] field - the field to add to \a this.
9337  *  \throw If the name of \a field is empty.
9338  *  \throw If the data array of \a field is not set.
9339  *  \throw If existing time steps have different name or number of components than \a field.
9340  *  \throw If the underlying mesh of \a field has no name.
9341  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9342  */
9343 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9344 {
9345   const DataArrayDouble *arr=0;
9346   if(field)
9347     arr=field->getArray();
9348   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9349 }
9350
9351 /*!
9352  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9353  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9354  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9355  * and \a profile.
9356  *
9357  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9358  * A new profile is added only if no equal profile is missing.
9359  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9360  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9361  *  \param [in] mesh - the supporting mesh of \a field.
9362  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9363  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9364  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9365  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9366  *  \throw If the data array of \a field is not set.
9367  *  \throw If the data array of \a this is already allocated but has different number of
9368  *         components than \a field.
9369  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9370  *  \sa setFieldNoProfileSBT()
9371  */
9372 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9373 {
9374   const DataArrayDouble *arr=0;
9375   if(field)
9376     arr=field->getArray();
9377   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9378 }
9379
9380 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9381 {
9382   _content=new MEDFileFieldMultiTSWithoutSDA;
9383 }
9384
9385 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9386 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9387 {
9388 }
9389 catch(INTERP_KERNEL::Exception& e)
9390 { throw e; }
9391
9392 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9393 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9394 {
9395 }
9396 catch(INTERP_KERNEL::Exception& e)
9397 { throw e; }
9398
9399 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9400 {
9401 }
9402
9403 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
9404 {
9405   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9406 }
9407
9408 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9409 {
9410   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9411 }
9412
9413 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9414 {
9415   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9416 }
9417
9418 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
9419 {
9420   return MEDFileFieldMultiTS::New();
9421 }
9422
9423 //= MEDFileAnyTypeFieldMultiTSIterator
9424
9425 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9426 {
9427   if(fmts)
9428     {
9429       fmts->incrRef();
9430       _nb_iter=fmts->getNumberOfTS();
9431     }
9432 }
9433
9434 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9435 {
9436 }
9437
9438 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9439 {
9440   if(_iter_id<_nb_iter)
9441     {
9442       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9443       if(fmts)
9444         return fmts->getTimeStepAtPos(_iter_id++);
9445       else
9446         return 0;
9447     }
9448   else
9449     return 0;
9450 }
9451
9452 //= MEDFileIntFieldMultiTS
9453
9454 /*!
9455  * Returns a new empty instance of MEDFileFieldMultiTS.
9456  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9457  *          is to delete this field using decrRef() as it is no more needed.
9458  */
9459 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9460 {
9461   return new MEDFileIntFieldMultiTS;
9462 }
9463
9464 /*!
9465  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9466  * that has been read from a specified MED file.
9467  *  \param [in] fileName - the name of the MED file to read.
9468  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9469  *          is to delete this field using decrRef() as it is no more needed.
9470  *  \throw If reading the file fails.
9471  */
9472 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9473 {
9474   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9475   ret->contentNotNull();//to check that content type matches with \a this type.
9476   return ret.retn();
9477 }
9478
9479 /*!
9480  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9481  * that has been read from a specified MED file.
9482  *  \param [in] fileName - the name of the MED file to read.
9483  *  \param [in] fieldName - the name of the field to read.
9484  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9485  *          is to delete this field using decrRef() as it is no more needed.
9486  *  \throw If reading the file fails.
9487  *  \throw If there is no field named \a fieldName in the file.
9488  */
9489 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9490 {
9491   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9492   ret->contentNotNull();//to check that content type matches with \a this type.
9493   return ret.retn();
9494 }
9495
9496 /*!
9497  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9498  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9499  *
9500  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9501  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9502  * \warning this is a shallow copy constructor
9503  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9504  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9505  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9506  *          is to delete this field using decrRef() as it is no more needed.
9507  */
9508 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9509 {
9510   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9511 }
9512
9513 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9514 {
9515   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0,&entities);
9516   ret->contentNotNull();//to check that content type matches with \a this type.
9517   return ret.retn();
9518 }
9519
9520 /*!
9521  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9522  * following the given input policy.
9523  *
9524  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9525  *                            By default (true) the globals are deeply copied.
9526  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9527  */
9528 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9529 {
9530   MCAuto<MEDFileFieldMultiTS> ret;
9531   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9532   if(content)
9533     {
9534       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9535       if(!contc)
9536         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9537       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9538       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9539     }
9540   else
9541     ret=MEDFileFieldMultiTS::New();
9542   if(isDeepCpyGlobs)
9543     ret->deepCpyGlobs(*this);
9544   else
9545     ret->shallowCpyGlobs(*this);
9546   return ret.retn();
9547 }
9548
9549 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9550 {
9551   return new MEDFileIntFieldMultiTS(*this);
9552 }
9553
9554 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9555 {
9556   if(!f1ts)
9557     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9558   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9559   if(!f1tsC)
9560     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9561 }
9562
9563 /*!
9564  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9565  * mesh entities of a given dimension of the first mesh in MED file.
9566  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9567  *  \param [in] type - a spatial discretization of interest.
9568  *  \param [in] iteration - the iteration number of a required time step.
9569  *  \param [in] order - the iteration order number of required time step.
9570  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9571  *  \param [out] arrOut - the DataArrayInt containing values of field.
9572  *  \param [in] renumPol - specifies how to permute values of the result field according to
9573  *          the optional numbers of cells and nodes, if any. The valid values are
9574  *          - 0 - do not permute.
9575  *          - 1 - permute cells.
9576  *          - 2 - permute nodes.
9577  *          - 3 - permute cells and nodes.
9578  *
9579  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9580  *          caller is to delete this field using decrRef() as it is no more needed. 
9581  *  \throw If the MED file is not readable.
9582  *  \throw If there is no mesh in the MED file.
9583  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9584  *  \throw If no field values of the required parameters are available.
9585  */
9586 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9587 {
9588   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9589   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9590   if(!myF1TSC)
9591     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9592   MCAuto<DataArray> arr;
9593   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9594   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9595   return ret.retn();
9596 }
9597
9598 /*!
9599  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9600  * the top level cells of the first mesh in MED file.
9601  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9602  *  \param [in] type - a spatial discretization of interest.
9603  *  \param [in] iteration - the iteration number of a required time step.
9604  *  \param [in] order - the iteration order number of required time step.
9605  *  \param [out] arrOut - the DataArrayInt containing values of field.
9606  *  \param [in] renumPol - specifies how to permute values of the result field according to
9607  *          the optional numbers of cells and nodes, if any. The valid values are
9608  *          - 0 - do not permute.
9609  *          - 1 - permute cells.
9610  *          - 2 - permute nodes.
9611  *          - 3 - permute cells and nodes.
9612  *
9613  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9614  *          caller is to delete this field using decrRef() as it is no more needed. 
9615  *  \throw If the MED file is not readable.
9616  *  \throw If there is no mesh in the MED file.
9617  *  \throw If no field values of the required parameters are available.
9618  */
9619 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9620 {
9621   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9622   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9623   if(!myF1TSC)
9624     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9625   MCAuto<DataArray> arr;
9626   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9627   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9628   return ret.retn();
9629 }
9630
9631 /*!
9632  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9633  * a given support.
9634  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9635  *  \param [in] type - a spatial discretization of interest.
9636  *  \param [in] iteration - the iteration number of a required time step.
9637  *  \param [in] order - the iteration order number of required time step.
9638  *  \param [out] arrOut - the DataArrayInt containing values of field.
9639  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9640  *  \param [in] mesh - the supporting mesh.
9641  *  \param [in] renumPol - specifies how to permute values of the result field according to
9642  *          the optional numbers of cells and nodes, if any. The valid values are
9643  *          - 0 - do not permute.
9644  *          - 1 - permute cells.
9645  *          - 2 - permute nodes.
9646  *          - 3 - permute cells and nodes.
9647  *
9648  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9649  *          caller is to delete this field using decrRef() as it is no more needed. 
9650  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9651  *  \throw If no field of \a this is lying on \a mesh.
9652  *  \throw If no field values of the required parameters are available.
9653  */
9654 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9655 {
9656   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9657   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9658   if(!myF1TSC)
9659     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9660   MCAuto<DataArray> arr;
9661   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9662   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9663   return ret.retn();
9664 }
9665
9666 /*!
9667  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9668  * given support. 
9669  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9670  *  \param [in] type - a spatial discretization of the new field.
9671  *  \param [in] iteration - the iteration number of a required time step.
9672  *  \param [in] order - the iteration order number of required time step.
9673  *  \param [in] mesh - the supporting mesh.
9674  *  \param [out] arrOut - the DataArrayInt containing values of field.
9675  *  \param [in] renumPol - specifies how to permute values of the result field according to
9676  *          the optional numbers of cells and nodes, if any. The valid values are
9677  *          - 0 - do not permute.
9678  *          - 1 - permute cells.
9679  *          - 2 - permute nodes.
9680  *          - 3 - permute cells and nodes.
9681  *
9682  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9683  *          caller is to delete this field using decrRef() as it is no more needed. 
9684  *  \throw If no field of \a this is lying on \a mesh.
9685  *  \throw If no field values of the required parameters are available.
9686  */
9687 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9688 {
9689   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9690   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9691   if(!myF1TSC)
9692     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9693   MCAuto<DataArray> arr;
9694   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9695   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9696   return ret.retn();
9697 }
9698
9699 /*!
9700  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9701  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9702  * This method is useful for MED2 file format when field on different mesh was autorized.
9703  */
9704 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9705 {
9706   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9707   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9708   if(!myF1TSC)
9709     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9710   MCAuto<DataArray> arr;
9711   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9712   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9713   return ret.retn();
9714 }
9715
9716 /*!
9717  * Returns values and a profile of the field of a given type, of a given time step,
9718  * lying on a given support.
9719  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9720  *  \param [in] type - a spatial discretization of the field.
9721  *  \param [in] iteration - the iteration number of a required time step.
9722  *  \param [in] order - the iteration order number of required time step.
9723  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9724  *  \param [in] mesh - the supporting mesh.
9725  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9726  *          field of interest lies on. If the field lies on all entities of the given
9727  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9728  *          using decrRef() as it is no more needed.  
9729  *  \param [in] glob - the global data storing profiles and localization.
9730  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9731  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9732  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9733  *  \throw If no field of \a this is lying on \a mesh.
9734  *  \throw If no field values of the required parameters are available.
9735  */
9736 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9737 {
9738   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9739   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9740   if(!myF1TSC)
9741     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9742   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9743   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9744 }
9745
9746 /*!
9747  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9748  *  \param [in] pos - a time step id.
9749  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9750  *          delete this field using decrRef() as it is no more needed.
9751  *  \throw If \a pos is not a valid time step id.
9752  */
9753 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9754 {
9755   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9756   if(!item)
9757     {
9758       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9759       throw INTERP_KERNEL::Exception(oss.str().c_str());
9760     }
9761   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9762   if(itemC)
9763     {
9764       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9765       ret->shallowCpyGlobs(*this);
9766       return ret.retn();
9767     }
9768   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9769   throw INTERP_KERNEL::Exception(oss.str().c_str());
9770 }
9771
9772 /*!
9773  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9774  * the given field is checked if its elements are sorted suitable for writing to MED file
9775  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9776  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9777  *  \param [in] field - the field to add to \a this.
9778  *  \throw If the name of \a field is empty.
9779  *  \throw If the data array of \a field is not set.
9780  *  \throw If existing time steps have different name or number of components than \a field.
9781  *  \throw If the underlying mesh of \a field has no name.
9782  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9783  */
9784 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9785 {
9786   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9787 }
9788
9789 /*!
9790  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9791  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9792  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9793  * and \a profile.
9794  *
9795  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9796  * A new profile is added only if no equal profile is missing.
9797  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9798  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9799  *  \param [in] arrOfVals - the values of the field \a field used.
9800  *  \param [in] mesh - the supporting mesh of \a field.
9801  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9802  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9803  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9804  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9805  *  \throw If the data array of \a field is not set.
9806  *  \throw If the data array of \a this is already allocated but has different number of
9807  *         components than \a field.
9808  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9809  *  \sa setFieldNoProfileSBT()
9810  */
9811 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9812 {
9813   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9814 }
9815
9816 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9817 {
9818   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9819   if(!pt)
9820     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9821   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9822   if(!ret)
9823     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 !");
9824   return ret;
9825 }
9826
9827 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9828 {
9829   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9830   if(!pt)
9831     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9832   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9833   if(!ret)
9834     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 !");
9835   return ret;
9836 }
9837
9838 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9839 {
9840   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9841 }
9842
9843 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9844 {
9845 }
9846
9847 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9848 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9849 {
9850 }
9851 catch(INTERP_KERNEL::Exception& e)
9852 { throw e; }
9853
9854 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9855 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9856 {
9857 }
9858 catch(INTERP_KERNEL::Exception& e)
9859 { throw e; }
9860
9861 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9862 {
9863   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9864 }
9865
9866 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
9867 {
9868   return MEDFileIntFieldMultiTS::New();
9869 }
9870
9871 //= MEDFileFields
9872
9873 MEDFileFields *MEDFileFields::New()
9874 {
9875   return new MEDFileFields;
9876 }
9877
9878 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9879 {
9880   return new MEDFileFields(fileName,loadAll,0,0);
9881 }
9882
9883 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9884 {
9885   return new MEDFileFields(fileName,loadAll,ms,0);
9886 }
9887
9888 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9889 {
9890   return new MEDFileFields(fileName,loadAll,0,&entities);
9891 }
9892
9893 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9894 {
9895   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9896   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9897   return ret;
9898 }
9899
9900 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9901 {
9902   std::vector<const BigMemoryObject *> ret;
9903   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9904     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9905   return ret;
9906 }
9907
9908 MEDFileFields *MEDFileFields::deepCopy() const
9909 {
9910   MCAuto<MEDFileFields> ret=shallowCpy();
9911   std::size_t i=0;
9912   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9913     {
9914       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9915         ret->_fields[i]=(*it)->deepCopy();
9916     }
9917   ret->deepCpyGlobs(*this);
9918   return ret.retn();
9919 }
9920
9921 MEDFileFields *MEDFileFields::shallowCpy() const
9922 {
9923   return new MEDFileFields(*this);
9924 }
9925
9926 /*!
9927  * 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
9928  * 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.
9929  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9930  *
9931  * \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.
9932  * \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.
9933  * 
9934  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9935  */
9936 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9937 {
9938   std::set< std::pair<int,int> > s;
9939   bool firstShot=true;
9940   areThereSomeForgottenTS=false;
9941   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9942     {
9943       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9944         continue;
9945       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9946       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9947       if(firstShot)
9948         { s=s1; firstShot=false; }
9949       else
9950         {
9951           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9952           if(s!=s2)
9953             areThereSomeForgottenTS=true;
9954           s=s2;
9955         }
9956     }
9957   std::vector< std::pair<int,int> > ret;
9958   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9959   return ret;
9960 }
9961
9962 int MEDFileFields::getNumberOfFields() const
9963 {
9964   return _fields.size();
9965 }
9966
9967 std::vector<std::string> MEDFileFields::getFieldsNames() const
9968 {
9969   std::vector<std::string> ret(_fields.size());
9970   int i=0;
9971   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9972     {
9973       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9974       if(f)
9975         {
9976           ret[i]=f->getName();
9977         }
9978       else
9979         {
9980           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9981           throw INTERP_KERNEL::Exception(oss.str().c_str());
9982         }
9983     }
9984   return ret;
9985 }
9986
9987 std::vector<std::string> MEDFileFields::getMeshesNames() const
9988 {
9989   std::vector<std::string> ret;
9990   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9991     {
9992       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9993       if(cur)
9994         ret.push_back(cur->getMeshName());
9995     }
9996   return ret;
9997 }
9998
9999 std::string MEDFileFields::simpleRepr() const
10000 {
10001   std::ostringstream oss;
10002   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10003   simpleRepr(0,oss);
10004   return oss.str();
10005 }
10006
10007 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10008 {
10009   int nbOfFields=getNumberOfFields();
10010   std::string startLine(bkOffset,' ');
10011   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10012   int i=0;
10013   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10014     {
10015       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10016       if(cur)
10017         {
10018           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10019         }
10020       else
10021         {
10022           oss << startLine << "  - not defined !" << std::endl;
10023         }
10024     }
10025   i=0;
10026   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10027     {
10028       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10029       std::string chapter(17,'0'+i);
10030       oss << startLine << chapter << std::endl;
10031       if(cur)
10032         {
10033           cur->simpleRepr(bkOffset+2,oss,i);
10034         }
10035       else
10036         {
10037           oss << startLine << "  - not defined !" << std::endl;
10038         }
10039       oss << startLine << chapter << std::endl;
10040     }
10041   simpleReprGlobs(oss);
10042 }
10043
10044 MEDFileFields::MEDFileFields()
10045 {
10046 }
10047
10048 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
10049 try:MEDFileFieldGlobsReal(fileName)
10050 {
10051   MEDFileUtilities::CheckFileForRead(fileName);
10052   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
10053   int nbFields(MEDnField(fid));
10054   _fields.resize(nbFields);
10055   med_field_type typcha;
10056   for(int i=0;i<nbFields;i++)
10057     {
10058       std::vector<std::string> infos;
10059       std::string fieldName,dtunit;
10060       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
10061       switch(typcha)
10062       {
10063         case MED_FLOAT64:
10064           {
10065             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10066             break;
10067           }
10068         case MED_INT32:
10069           {
10070             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10071             break;
10072           }
10073         default:
10074           {
10075             std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << fileName << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
10076             throw INTERP_KERNEL::Exception(oss.str().c_str());
10077           }
10078       }
10079     }
10080   loadAllGlobals(fid);
10081 }
10082 catch(INTERP_KERNEL::Exception& e)
10083 {
10084     throw e;
10085 }
10086
10087 void MEDFileFields::writeLL(med_idt fid) const
10088 {
10089   int i=0;
10090   writeGlobals(fid,*this);
10091   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10092     {
10093       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10094       if(!elt)
10095         {
10096           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10097           throw INTERP_KERNEL::Exception(oss.str().c_str());
10098         }
10099       elt->writeLL(fid,*this);
10100     }
10101 }
10102
10103 void MEDFileFields::write(const std::string& fileName, int mode) const
10104 {
10105   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
10106   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
10107   writeLL(fid);
10108 }
10109
10110 /*!
10111  * This method alloc the arrays and load potentially huge arrays contained in this field.
10112  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10113  * This method can be also called to refresh or reinit values from a file.
10114  * 
10115  * \throw If the fileName is not set or points to a non readable MED file.
10116  */
10117 void MEDFileFields::loadArrays()
10118 {
10119   if(getFileName().empty())
10120     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10121   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10122   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10123     {
10124       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10125       if(elt)
10126         elt->loadBigArraysRecursively(fid,*elt);
10127     }
10128 }
10129
10130 /*!
10131  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10132  * But once data loaded once, this method does nothing.
10133  * 
10134  * \throw If the fileName is not set or points to a non readable MED file.
10135  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10136  */
10137 void MEDFileFields::loadArraysIfNecessary()
10138 {
10139   if(!getFileName().empty())
10140     {
10141       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10142       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10143         {
10144           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10145           if(elt)
10146             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10147         }
10148     }
10149 }
10150
10151 /*!
10152  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10153  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10154  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10155  * 
10156  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10157  */
10158 void MEDFileFields::unloadArrays()
10159 {
10160   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10161     {
10162       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10163       if(elt)
10164         elt->unloadArrays();
10165     }
10166 }
10167
10168 /*!
10169  * 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.
10170  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10171  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10172  * 
10173  * \sa MEDFileFields::loadArraysIfNecessary
10174  */
10175 void MEDFileFields::unloadArraysWithoutDataLoss()
10176 {
10177   if(!getFileName().empty())
10178     unloadArrays();
10179 }
10180
10181 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10182 {
10183   std::vector<std::string> ret;
10184   std::set<std::string> ret2;
10185   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10186     {
10187       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10188       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10189         if(ret2.find(*it2)==ret2.end())
10190           {
10191             ret.push_back(*it2);
10192             ret2.insert(*it2);
10193           }
10194     }
10195   return ret;
10196 }
10197
10198 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10199 {
10200   std::vector<std::string> ret;
10201   std::set<std::string> ret2;
10202   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10203     {
10204       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10205       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10206         if(ret2.find(*it2)==ret2.end())
10207           {
10208             ret.push_back(*it2);
10209             ret2.insert(*it2);
10210           }
10211     }
10212   return ret;
10213 }
10214
10215 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10216 {
10217   std::vector<std::string> ret;
10218   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10219     {
10220       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
10221       ret.insert(ret.end(),tmp.begin(),tmp.end());
10222     }
10223   return ret;
10224 }
10225
10226 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10227 {
10228   std::vector<std::string> ret;
10229   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10230     {
10231       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10232       ret.insert(ret.end(),tmp.begin(),tmp.end());
10233     }
10234   return ret;
10235 }
10236
10237 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10238 {
10239   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10240     (*it)->changePflsRefsNamesGen2(mapOfModif);
10241 }
10242
10243 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10244 {
10245   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10246     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10247 }
10248
10249 void MEDFileFields::resize(int newSize)
10250 {
10251   _fields.resize(newSize);
10252 }
10253
10254 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10255 {
10256   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10257     pushField(*it);
10258 }
10259
10260 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10261 {
10262   if(!field)
10263     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10264   _fields.push_back(field->getContent());
10265   appendGlobs(*field,1e-12);
10266 }
10267
10268 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10269 {
10270   if(!field)
10271     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10272   if(i>=(int)_fields.size())
10273     _fields.resize(i+1);
10274   _fields[i]=field->getContent();
10275   appendGlobs(*field,1e-12);
10276 }
10277
10278 void MEDFileFields::destroyFieldAtPos(int i)
10279 {
10280   destroyFieldsAtPos(&i,&i+1);
10281 }
10282
10283 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10284 {
10285   std::vector<bool> b(_fields.size(),true);
10286   for(const int *i=startIds;i!=endIds;i++)
10287     {
10288       if(*i<0 || *i>=(int)_fields.size())
10289         {
10290           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10291           throw INTERP_KERNEL::Exception(oss.str().c_str());
10292         }
10293       b[*i]=false;
10294     }
10295   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10296   std::size_t j=0;
10297   for(std::size_t i=0;i<_fields.size();i++)
10298     if(b[i])
10299       fields[j++]=_fields[i];
10300   _fields=fields;
10301 }
10302
10303 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10304 {
10305   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10306   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
10307   std::vector<bool> b(_fields.size(),true);
10308   int k=bg;
10309   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10310     {
10311       if(k<0 || k>=(int)_fields.size())
10312         {
10313           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10314           throw INTERP_KERNEL::Exception(oss.str().c_str());
10315         }
10316       b[k]=false;
10317     }
10318   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10319   std::size_t j=0;
10320   for(std::size_t i=0;i<_fields.size();i++)
10321     if(b[i])
10322       fields[j++]=_fields[i];
10323   _fields=fields;
10324 }
10325
10326 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10327 {
10328   bool ret=false;
10329   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10330     {
10331       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10332       if(cur)
10333         ret=cur->changeMeshNames(modifTab) || ret;
10334     }
10335   return ret;
10336 }
10337
10338 /*!
10339  * \param [in] meshName the name of the mesh that will be renumbered.
10340  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10341  *             This code corresponds to the distribution of types in the corresponding mesh.
10342  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10343  * \param [in] renumO2N the old to new renumber array.
10344  * \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 
10345  *         field in \a this.
10346  */
10347 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10348 {
10349   bool ret=false;
10350   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10351     {
10352       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10353       if(fmts)
10354         {
10355           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10356         }
10357     }
10358   return ret;
10359 }
10360
10361 /*!
10362  * Return an extraction of \a this using \a extractDef map to specify the extraction.
10363  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
10364  *
10365  * \return A new object that the caller is responsible to deallocate.
10366  */
10367 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
10368 {
10369   if(!mm)
10370     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
10371   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
10372   int nbFields(getNumberOfFields());
10373   for(int i=0;i<nbFields;i++)
10374     {
10375       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
10376       if(!fmts)
10377         {
10378           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
10379           throw INTERP_KERNEL::Exception(oss.str().c_str());
10380         }
10381       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
10382       fsOut->pushField(fmtsOut);
10383     }
10384   return fsOut.retn();
10385 }
10386
10387 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10388 {
10389   if(i<0 || i>=(int)_fields.size())
10390     {
10391       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10392       throw INTERP_KERNEL::Exception(oss.str().c_str());
10393     }
10394   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10395   if(!fmts)
10396     return 0;
10397   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
10398   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
10399   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
10400   if(fmtsC)
10401     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10402   else if(fmtsC2)
10403     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10404   else
10405     {
10406       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10407       throw INTERP_KERNEL::Exception(oss.str().c_str());
10408     }
10409   ret->shallowCpyGlobs(*this);
10410   return ret.retn();
10411 }
10412
10413 /*!
10414  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10415  * This method is accessible in python using __getitem__ with a list in input.
10416  * \return a new object that the caller should deal with.
10417  */
10418 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10419 {
10420   MCAuto<MEDFileFields> ret=shallowCpy();
10421   std::size_t sz=std::distance(startIds,endIds);
10422   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10423   int j=0;
10424   for(const int *i=startIds;i!=endIds;i++,j++)
10425     {
10426       if(*i<0 || *i>=(int)_fields.size())
10427         {
10428           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10429           throw INTERP_KERNEL::Exception(oss.str().c_str());
10430         }
10431       fields[j]=_fields[*i];
10432     }
10433   ret->_fields=fields;
10434   return ret.retn();
10435 }
10436
10437 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10438 {
10439   return getFieldAtPos(getPosFromFieldName(fieldName));
10440 }
10441
10442 /*!
10443  * This method removes, if any, fields in \a this having no time steps.
10444  * 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.
10445  * 
10446  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10447  */
10448 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10449 {
10450   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10451   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10452     {
10453       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10454       if(elt)
10455         {
10456           if(elt->getNumberOfTS()>0)
10457             newFields.push_back(*it);
10458         }
10459     }
10460   if(_fields.size()==newFields.size())
10461     return false;
10462   _fields=newFields;
10463   return true;
10464 }
10465
10466 /*!
10467  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10468  * This method can be seen as a filter applied on \a this, that returns an object containing
10469  * 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
10470  * shallow copied from \a this.
10471  * 
10472  * \param [in] meshName - the name of the mesh on w
10473  * \return a new object that the caller should deal with.
10474  */
10475 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10476 {
10477   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10478   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10479     {
10480       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10481       if(!cur)
10482         continue;
10483       if(cur->getMeshName()==meshName)
10484         {
10485           cur->incrRef();
10486           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10487           ret->_fields.push_back(cur2);
10488         }
10489     }
10490   ret->shallowCpyOnlyUsedGlobs(*this);
10491   return ret.retn();
10492 }
10493
10494 /*!
10495  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10496  * Input time steps are specified using a pair of integer (iteration, order).
10497  * 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,
10498  * but for each multitimestep only the time steps in \a timeSteps are kept.
10499  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10500  * 
10501  * The returned object points to shallow copy of elements in \a this.
10502  * 
10503  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10504  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10505  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10506  */
10507 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10508 {
10509   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10510   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10511     {
10512       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10513       if(!cur)
10514         continue;
10515       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10516       ret->_fields.push_back(elt);
10517     }
10518   ret->shallowCpyOnlyUsedGlobs(*this);
10519   return ret.retn();
10520 }
10521
10522 /*!
10523  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10524  */
10525 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10526 {
10527   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10528   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10529     {
10530       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10531       if(!cur)
10532         continue;
10533       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10534       if(elt->getNumberOfTS()!=0)
10535         ret->_fields.push_back(elt);
10536     }
10537   ret->shallowCpyOnlyUsedGlobs(*this);
10538   return ret.retn();
10539 }
10540
10541 MEDFileFieldsIterator *MEDFileFields::iterator()
10542 {
10543   return new MEDFileFieldsIterator(this);
10544 }
10545
10546 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10547 {
10548   std::string tmp(fieldName);
10549   std::vector<std::string> poss;
10550   for(std::size_t i=0;i<_fields.size();i++)
10551     {
10552       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10553       if(f)
10554         {
10555           std::string fname(f->getName());
10556           if(tmp==fname)
10557             return i;
10558           else
10559             poss.push_back(fname);
10560         }
10561     }
10562   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10563   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10564   oss << " !";
10565   throw INTERP_KERNEL::Exception(oss.str().c_str());
10566 }
10567
10568 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10569 {
10570   if(fs)
10571     {
10572       fs->incrRef();
10573       _nb_iter=fs->getNumberOfFields();
10574     }
10575 }
10576
10577 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10578 {
10579 }
10580
10581 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10582 {
10583   if(_iter_id<_nb_iter)
10584     {
10585       MEDFileFields *fs(_fs);
10586       if(fs)
10587         return fs->getFieldAtPos(_iter_id++);
10588       else
10589         return 0;
10590     }
10591   else
10592     return 0;
10593 }