Salome HOME
22aefdc4aec2e5af97616322251be0b3f471082f
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.txx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDLoaderTraits.hxx"
25 #include "MEDFileSafeCaller.txx"
26 #include "MEDFileFieldOverView.hxx"
27 #include "MEDFileBlowStrEltUp.hxx"
28 #include "MEDFileFieldVisitor.hxx"
29
30 #include "MEDCouplingFieldDouble.hxx"
31 #include "MEDCouplingFieldTemplate.hxx"
32 #include "MEDCouplingFieldDiscretization.hxx"
33
34 #include "InterpKernelAutoPtr.hxx"
35 #include "CellModel.hxx"
36
37 #include <algorithm>
38 #include <iterator>
39
40 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
41 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
42 extern med_geometry_type typmainoeud[1];
43 extern med_geometry_type typmai3[34];
44
45 using namespace MEDCoupling;
46
47 template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<int>;
48 template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<float>;
49 template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<double>;
50 template class MEDCoupling::MEDFileTemplateField1TS<int>;
51 template class MEDCoupling::MEDFileTemplateField1TS<double>;
52
53 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
54 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
55 const char MEDFileFloatField1TSWithoutSDA::TYPE_STR[]="FLOAT32";
56
57 MEDFileGTKeeper::~MEDFileGTKeeper()
58 {
59 }
60
61 MEDFileGTKeeper *MEDFileGTKeeperSta::deepCopy() const
62 {
63   return new MEDFileGTKeeperSta(_geo_type);
64 }
65
66 INTERP_KERNEL::NormalizedCellType MEDFileGTKeeperSta::getGeoType() const
67 {
68   return _geo_type;
69 }
70
71 std::string MEDFileGTKeeperSta::getRepr() const
72 {
73   return INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr();
74 }
75
76 bool MEDFileGTKeeperSta::isEqual(const MEDFileGTKeeper *other) const
77 {
78   const MEDFileGTKeeperSta *otherC(dynamic_cast<const MEDFileGTKeeperSta *>(other));
79   if(!otherC)
80     return false;
81   return _geo_type==otherC->_geo_type;
82 }
83
84 MEDFileGTKeeperDyn::MEDFileGTKeeperDyn(const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileStructureElement *se):_mesh(mesh),_section(section),_se(se)
85 {
86   if(mesh)
87     mesh->incrRef();
88   if(section)
89     section->incrRef();
90   if(se)
91     se->incrRef();
92   if(_mesh.isNull() || _section.isNull() || _se.isNull())
93     throw INTERP_KERNEL::Exception("MEDFileGTKeeperDyn constructor : null pointer not allowed !");
94 }
95
96 MEDFileGTKeeper *MEDFileGTKeeperDyn::deepCopy() const
97 {
98   return new MEDFileGTKeeperDyn(_mesh,_section,_se);
99 }
100
101 INTERP_KERNEL::NormalizedCellType MEDFileGTKeeperDyn::getGeoType() const
102 {
103   throw INTERP_KERNEL::Exception("MEDFileGTKeeperDyn::getGeoType : not valid !");
104 }
105
106 std::string MEDFileGTKeeperDyn::getRepr() const
107 {
108   std::ostringstream oss;
109   oss << _se->getDynGT();
110   return oss.str();
111 }
112
113 bool MEDFileGTKeeperDyn::isEqual(const MEDFileGTKeeper *other) const
114 {
115   const MEDFileGTKeeperDyn *otherC(dynamic_cast<const MEDFileGTKeeperDyn *>(other));
116   if(!otherC)
117     return false;
118   return this==otherC;
119 }
120
121 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
122 {
123   return new MEDFileFieldLoc(fid,locName);
124 }
125
126 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id, const MEDFileEntities *entities)
127 {
128   return new MEDFileFieldLoc(fid,id,entities);
129 }
130
131 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)
132 {
133   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
134 }
135
136 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
137 {
138   med_geometry_type geotype;
139   med_geometry_type sectiongeotype;
140   int nsectionmeshcell;
141   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
142   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
143   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
144   _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype))));
145   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
146   _nb_node_per_cell=cm.getNumberOfNodes();
147   _ref_coo.resize(_dim*_nb_node_per_cell);
148   _gs_coo.resize(_dim*_nb_gauss_pt);
149   _w.resize(_nb_gauss_pt);
150   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
151 }
152
153 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id, const MEDFileEntities *entities)
154 {
155   med_geometry_type geotype;
156   med_geometry_type sectiongeotype;
157   int nsectionmeshcell;
158   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
159   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
160   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
161   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
162   _name=locName;
163   std::string sectionName(MEDLoaderBase::buildStringFromFortran(sectionmeshname,MED_NAME_SIZE));
164   if(sectionName.empty())
165     {
166       _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype))));
167       const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
168       _nb_node_per_cell=cm.getNumberOfNodes();
169     }
170   else
171     {
172       const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
173       if(!entities2)
174         {
175           std::ostringstream oss; oss << "MEDFileFieldLoc cstr : for loc \"" << _name << "\" presence of non static type ! Expect entities !";
176           throw INTERP_KERNEL::Exception(oss.str());
177         }
178       const MEDFileStructureElement *se(entities2->getWithGT(geotype));
179       const MEDFileUMesh *um(entities2->getSupMeshWithName(se->getMeshName()));
180       const MEDFileUMesh *section(entities2->getSupMeshWithName(sectionName));
181       _gt=new MEDFileGTKeeperDyn(um,section,se);
182       {
183         int dummy;
184         MEDFILESAFECALLERWR0(MEDmeshGeotypeParameter,(fid,geotype,&dummy,&_nb_node_per_cell));
185       }
186     }
187   _ref_coo.resize(_dim*_nb_node_per_cell);
188   _gs_coo.resize(_dim*_nb_gauss_pt);
189   _w.resize(_nb_gauss_pt);
190   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
191 }
192
193 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
194                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_gt(new MEDFileGTKeeperSta(geoType)),_ref_coo(refCoo),_gs_coo(gsCoo),_w(w)
195 {
196   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
197   _dim=cm.getDimension();
198   _nb_node_per_cell=cm.getNumberOfNodes();
199   _nb_gauss_pt=_w.size();
200 }
201
202
203 MEDFileFieldLoc::MEDFileFieldLoc(const MEDFileFieldLoc& other):_dim(other._dim),_nb_gauss_pt(other._nb_gauss_pt),_gt(other._gt->deepCopy()),_nb_node_per_cell(other._nb_node_per_cell),_name(other._name),_ref_coo(other._ref_coo),_gs_coo(other._gs_coo),_w(other._w)
204 {
205 }
206
207 MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const
208 {
209   return new MEDFileFieldLoc(*this);
210 }
211
212 bool MEDFileFieldLoc::isOnStructureElement() const
213 {
214   const MEDFileGTKeeper *gt(_gt);
215   if(!gt)
216     throw INTERP_KERNEL::Exception("MEDFileFieldLoc::isOnStructureElement : null pointer !");
217   const MEDFileGTKeeperDyn *gt2(dynamic_cast<const MEDFileGTKeeperDyn *>(gt));
218   return gt2!=NULL;
219 }
220
221 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
222 {
223   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
224 }
225
226 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
227 {
228   return std::vector<const BigMemoryObject *>();
229 }
230
231 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
232 {
233   static const char OFF7[]="\n    ";
234   oss << "\"" << _name << "\"" << OFF7;
235   oss << "GeoType=" << _gt->getRepr() << OFF7;
236   oss << "Dimension=" << _dim << OFF7;
237   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
238   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
239   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
240   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
241   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
242 }
243
244 void MEDFileFieldLoc::setName(const std::string& name)
245 {
246   _name=name;
247 }
248
249 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
250 {
251   if(_name!=other._name)
252     return false;
253   if(_dim!=other._dim)
254     return false;
255   if(_nb_gauss_pt!=other._nb_gauss_pt)
256     return false;
257   if(_nb_node_per_cell!=other._nb_node_per_cell)
258     return false;
259   if(!_gt->isEqual(other._gt))
260     return false;
261   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
262     return false;
263   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
264     return false;
265   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
266     return false;
267
268   return true;
269 }
270
271 void MEDFileFieldLoc::writeLL(med_idt fid) const
272 {
273   MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)getGeoType()],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT);
274 }
275
276 std::string MEDFileFieldLoc::repr() const
277 {
278   std::ostringstream oss; oss.precision(15);
279   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
280   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
281   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
282   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
283   oss << "\n  - Ref coords are : ";
284   int sz=_ref_coo.size();
285   if(sz%_dim==0)
286     {
287       int nbOfTuples=sz/_dim;
288       for(int i=0;i<nbOfTuples;i++)
289         {
290           oss << "(";
291           for(int j=0;j<_dim;j++)
292             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
293           oss << ") ";
294         }
295     }
296   else
297     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
298   oss << "\n  - Gauss coords in reference element : ";
299   sz=_gs_coo.size();
300   if(sz%_dim==0)
301     {
302       int nbOfTuples=sz/_dim;
303       for(int i=0;i<nbOfTuples;i++)
304         {
305           oss << "(";
306           for(int j=0;j<_dim;j++)
307             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
308           oss << ") ";
309         }
310     }
311   else
312     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
313   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
314   return oss.str();
315 }
316
317 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
318 {
319   _type=field->getTypeOfField();
320   _start=start;
321   switch(_type)
322   {
323     case ON_CELLS:
324       {
325         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,offset,offset+nbOfCells,1);
326         _end=_start+nbOfCells;
327         _nval=nbOfCells;
328         break;
329       }
330     case ON_GAUSS_NE:
331       {
332         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
333         const int *arrPtr=arr->getConstPointer();
334         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
335         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
336         _nval=nbOfCells;
337         break;
338       }
339     case ON_GAUSS_PT:
340       {
341         const MEDCouplingFieldDiscretization *disc(field->getDiscretization());
342         const MEDCouplingGaussLocalization& gsLoc(field->getGaussLocalization(_loc_id));
343         const MEDCouplingFieldDiscretizationGauss *disc2(dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc));
344         if(!disc2)
345           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
346         const DataArrayInt *dai(disc2->getArrayOfDiscIds());
347         MCAuto<DataArrayInt> dai2(disc2->getOffsetArr(field->getMesh()));
348         const int *dai2Ptr(dai2->getConstPointer());
349         int nbi(gsLoc.getWeights().size());
350         MCAuto<DataArrayInt> da2(dai->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1));
351         MCAuto<DataArrayInt> da3(da2->findIdsEqual(_loc_id));
352         const int *da3Ptr(da3->getConstPointer());
353         if(da3->getNumberOfTuples()!=nbOfCells)
354           {//profile : for gauss even in NoProfile !!!
355             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
356             _profile=oss.str();
357             da3->setName(_profile.c_str());
358             glob.appendProfile(da3);
359           }
360         MCAuto<DataArrayInt> da4(DataArrayInt::New());
361         _nval=da3->getNbOfElems();
362         da4->alloc(_nval*nbi,1);
363         int *da4Ptr(da4->getPointer());
364         for(int i=0;i<_nval;i++)
365           {
366             int ref=dai2Ptr[offset+da3Ptr[i]];
367             for(int j=0;j<nbi;j++)
368               *da4Ptr++=ref+j;
369           }
370         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
371         _localization=oss2.str();
372         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
373         _end=_start+_nval*nbi;
374         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
375         break;
376       }
377     default:
378       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
379   }
380   start=_end;
381 }
382
383 /*!
384  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
385  * \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).
386  * \param [in] multiTypePfl is the end user profile specified in high level API
387  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
388  * \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.
389  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
390  * \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.
391  */
392 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)
393 {
394   _profile.clear();
395   _type=field->getTypeOfField();
396   std::string pflName(multiTypePfl->getName());
397   std::ostringstream oss; oss << pflName;
398   if(_type!=ON_NODES)
399     {
400       if(!isPflAlone)
401         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
402     }
403   else
404     { oss << "_NODE"; }
405   if(locIds)
406     {
407       if(pflName.empty())
408         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
409       if(_type!=ON_GAUSS_PT)
410         {
411           locIds->setName(oss.str());
412           glob.appendProfile(locIds);
413           _profile=oss.str();
414         }
415     }
416   _start=start;
417   switch(_type)
418   {
419     case ON_NODES:
420       {
421         _nval=idsInPfl->getNumberOfTuples();
422         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,arrr->getNumberOfTuples(),1);
423         _end=_start+_nval;
424         break;
425       }
426     case ON_CELLS:
427       {
428         _nval=idsInPfl->getNumberOfTuples();
429         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
430         _end=_start+_nval;
431         break;
432       }
433     case ON_GAUSS_NE:
434       {
435         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
436         MCAuto<DataArrayInt> arr2=arr->deltaShiftIndex();
437         MCAuto<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
438         arr3->computeOffsetsFull();
439         MCAuto<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
440         int trueNval=tmp->getNumberOfTuples();
441         _nval=idsInPfl->getNumberOfTuples();
442         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
443         _end=_start+trueNval;
444         break;
445       }
446     case ON_GAUSS_PT:
447       {
448         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
449         if(!disc2)
450           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
451         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
452         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
453         MCAuto<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
454         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
455         MCAuto<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
456         //
457         MCAuto<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
458         MCAuto<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
459         //
460         MCAuto<DataArrayInt> tmp=DataArrayInt::New();
461         int trueNval=0;
462         for(const int *pt=da4->begin();pt!=da4->end();pt++)
463           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
464         tmp->alloc(trueNval,1);
465         int *tmpPtr=tmp->getPointer();
466         for(const int *pt=da4->begin();pt!=da4->end();pt++)
467           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
468             *tmpPtr++=j;
469         //
470         _nval=da4->getNumberOfTuples();
471         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
472         _end=_start+trueNval;
473         oss << "_loc_" << _loc_id;
474         if(locIds)
475           {
476             MCAuto<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
477             da5->setName(oss.str());
478             glob.appendProfile(da5);
479             _profile=oss.str();
480           }
481         else
482           {
483             if(!da3->isIota(nbOfEltsInWholeMesh))
484               {
485                 da3->setName(oss.str());
486                 glob.appendProfile(da3);
487                 _profile=oss.str();
488               }
489           }
490         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
491         _localization=oss2.str();
492         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
493         break;
494       }
495     default:
496       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
497   }
498   start=_end;
499 }
500
501 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
502 {
503   _start=start;
504   _nval=arrr->getNumberOfTuples();
505   getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,_nval,1);
506   _end=_start+_nval;
507   start=_end;
508 }
509
510 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
511 {
512   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
513 }
514
515 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId)
516 {
517   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
518 }
519
520 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
521 {
522   return new MEDFileFieldPerMeshPerTypePerDisc(other);
523 }
524
525 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
526 {
527   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
528 }
529
530 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
531 {
532   std::vector<const BigMemoryObject *> ret(1);
533   ret[0]=(const PartDefinition*)_pd;
534   return ret;
535 }
536
537 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerTypeCommon *father) const
538 {
539   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(*this));
540   ret->_father=father;
541   return ret.retn();
542 }
543
544 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
545 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
546 {
547   if(pd)
548     pd->incrRef();
549 }
550 catch(INTERP_KERNEL::Exception& e)
551 {
552     throw e;
553 }
554
555 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
556 {
557 }
558
559 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)
560 {
561 }
562
563 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
564     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
565 {
566 }
567
568 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)
569 {
570   const PartDefinition *pd(_pd);
571   if(!pd)
572     {
573       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
574       int nbi,tmp1;
575       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
576       if(_end-_start!=nbValsInFile*nbi)
577         {
578           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 !";
579           throw INTERP_KERNEL::Exception(oss.str());
580         }
581       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
582     }
583   else
584     {
585       if(!_profile.empty())
586         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
587       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
588       int profilesize,nbi;
589       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
590       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
591       if(spd)
592         {
593           int start,stop,step;
594           spd->getSlice(start,stop,step);
595           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
596           med_filter filter=MED_FILTER_INIT;
597           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
598                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
599                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
600                                    /*lastblocksize=useless because count=1*/0,&filter);
601           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
602           MEDfilterClose(&filter);
603           return ;
604         }
605       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
606       if(dpd)
607         {
608           dpd->checkConsistencyLight();
609           MCAuto<DataArrayInt> myIds(dpd->toDAI());
610           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
611           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
612           myIds->applyLin(1,-a);
613           int nbOfEltsToLoad(b-a+1);
614           med_filter filter=MED_FILTER_INIT;
615           {//TODO : manage int32 !
616             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
617             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
618             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
619                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
620                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
621                                      /*lastblocksize=useless because count=1*/0,&filter);
622             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
623             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
624             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
625             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
626           }
627           MEDfilterClose(&filter);
628         }
629       else
630         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
631     }
632 }
633
634 const MEDFileFieldPerMeshPerTypeCommon *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
635 {
636   return _father;
637 }
638
639 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
640 {
641   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
642   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
643   std::string fieldName(nasc.getName()),meshName(getMeshName());
644   int iteration(getIteration()),order(getOrder()),profilesize,nbi;
645   TypeOfField type(getType());
646   med_geometry_type mgeoti;
647   med_entity_type menti;
648   _father->entriesForMEDfile(type,mgeoti,menti);
649   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
650   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
651   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
652   const PartDefinition *pd(_pd);
653   if(!pd)
654     {
655       _nval=zeNVal;
656     }
657   else
658     {
659       if(!_profile.empty())
660         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
661       _nval=pd->getNumberOfElems();
662     }
663   _start=start;
664   _end=start+_nval*nbi;
665   start=_end;
666   if(type==ON_CELLS && !_localization.empty())
667     {
668       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
669         setType(ON_GAUSS_PT);
670       else
671         {
672           setType(ON_GAUSS_NE);
673           _localization.clear();
674         }
675     }
676 }
677
678 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
679 {
680   std::string fieldName(nasc.getName()),meshName(getMeshName());
681   int iteration(getIteration()),order(getOrder());
682   TypeOfField type(getType());
683   med_geometry_type mgeoti;
684   med_entity_type menti;
685   _father->entriesForMEDfile(type,mgeoti,menti);
686   if(_start>_end)
687     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
688   if(_start==_end)
689     return ;
690   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
691   if(_start<0 || _start>=arr->getNumberOfTuples())
692     {
693       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
694       throw INTERP_KERNEL::Exception(oss.str());
695     }
696   if(_end<0 || _end>arr->getNumberOfTuples())
697     {
698       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
699       throw INTERP_KERNEL::Exception(oss.str());
700     }
701   int nbOfCompo(arr->getNumberOfComponents());
702   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
703   if(arrD)
704     {
705       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
706       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
707       return ;
708     }
709   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
710   if(arrI)
711     {
712       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
713       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
714       return ;
715     }
716   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
717 }
718
719 /*!
720  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
721  */
722 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
723 {
724   int delta=_end-_start;
725   _start=newValueOfStart;
726   _end=_start+delta;
727 }
728
729 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
730 {
731   return _father->getIteration();
732 }
733
734 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
735 {
736   return _father->getOrder();
737 }
738
739 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
740 {
741   return _father->getTime();
742 }
743
744 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
745 {
746   return _father->getMeshName();
747 }
748
749 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
750 {
751   const char startLine[]="    ## ";
752   std::string startLine2(bkOffset,' ');
753   startLine2+=startLine;
754   INTERP_KERNEL::AutoCppPtr<MEDCouplingFieldDiscretization> tmp(MEDCouplingFieldDiscretization::New(_type));
755   oss << startLine2 << "Localization #" << id << "." << std::endl;
756   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
757   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
758   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
759   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
760 }
761
762 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
763 {
764   return _type;
765 }
766
767 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
768 {
769   return _father->getGeoType();
770 }
771
772 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
773 {
774   types.insert(_type);
775 }
776
777 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
778 {
779   _type=newType;
780 }
781
782 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
783 {
784   return _father->getNumberOfComponents();
785 }
786
787 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
788 {
789   return _end-_start;
790 }
791
792 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
793 {
794   return _father->getOrCreateAndGetArray();
795 }
796
797 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
798 {
799   const MEDFileFieldPerMeshPerTypeCommon *fath=_father;
800   return fath->getOrCreateAndGetArray();
801 }
802
803 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
804 {
805   return _father->getInfo();
806 }
807
808 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
809 {
810   return _profile;
811 }
812
813 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
814 {
815   _profile=newPflName;
816 }
817
818 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
819 {
820   return _localization;
821 }
822
823 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
824 {
825   _localization=newLocName;
826 }
827
828 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
829 {
830   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
831     {
832       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
833         {
834           _profile=(*it2).second;
835           return;
836         }
837     }
838 }
839
840 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
841 {
842   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
843     {
844       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
845         {
846           _localization=(*it2).second;
847           return;
848         }
849     }
850 }
851
852 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
853 {
854   if(type!=_type)
855     return ;
856   dads.push_back(std::pair<int,int>(_start,_end));
857   geoTypes.push_back(getGeoType());
858   if(_profile.empty())
859     pfls.push_back(0);
860   else
861     {
862       pfls.push_back(glob->getProfile(_profile.c_str()));
863     }
864   if(_localization.empty())
865     locs.push_back(-1);
866   else
867     {
868       locs.push_back(glob->getLocalizationId(_localization.c_str()));
869     }
870 }
871
872 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
873 {
874   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));
875   startEntryId++;
876 }
877
878 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
879 {
880   TypeOfField type=getType();
881   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
882   med_geometry_type mgeoti;
883   med_entity_type menti;
884   _father->entriesForMEDfile(getType(),mgeoti,menti);
885   const DataArray *arr(getOrCreateAndGetArray());
886   if(!arr)
887     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
888   if(!arr->isAllocated())
889     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
890   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
891   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
892   const unsigned char *locToWrite=0;
893   if(arrD)
894     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
895   else if(arrI)
896     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
897   else
898     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
899   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
900                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
901                                                    locToWrite));
902 }
903
904 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
905 {
906   type=_type;
907   pfl=_profile;
908   loc=_localization;
909   dad.first=_start; dad.second=_end;
910 }
911
912 /*!
913  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
914  *             This code corresponds to the distribution of types in the corresponding mesh.
915  * \param [out] ptToFill memory zone where the output will be stored.
916  * \return the size of data pushed into output param \a ptToFill
917  */
918 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
919 {
920   _loc_id=offset;
921   std::ostringstream oss;
922   std::size_t nbOfType=codeOfMesh.size()/3;
923   int found=-1;
924   for(std::size_t i=0;i<nbOfType && found==-1;i++)
925     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
926       found=(int)i;
927   if(found==-1)
928     {
929       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
930       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
931       throw INTERP_KERNEL::Exception(oss.str());
932     }
933   int *work=ptToFill;
934   if(_profile.empty())
935     {
936       if(_nval!=codeOfMesh[3*found+1])
937         {
938           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
939           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
940           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
941           throw INTERP_KERNEL::Exception(oss.str());
942         }
943       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
944         *work++=ii;
945     }
946   else
947     {
948       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
949       if(pfl->getNumberOfTuples()!=_nval)
950         {
951           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
952           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
953           oss << _nval;
954           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
955           throw INTERP_KERNEL::Exception(oss.str());
956         }
957       int offset2=codeOfMesh[3*found+2];
958       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
959         {
960           if(*pflId<codeOfMesh[3*found+1])
961             *work++=offset2+*pflId;
962         }
963     }
964   return _nval;
965 }
966
967 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
968 {
969   for(int i=_start;i<_end;i++)
970     *ptToFill++=i;
971   return _end-_start;
972 }
973
974 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
975 {
976   switch(type)
977   {
978     case ON_CELLS:
979       return -2;
980     case ON_GAUSS_NE:
981       return -1;
982     case ON_GAUSS_PT:
983       return locId;
984     default:
985       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
986   }
987 }
988
989 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
990 {
991   int id=0;
992   std::map<std::pair<std::string,TypeOfField>,int> m;
993   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
994   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
995     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
996       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
997   ret.resize(id);
998   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
999     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
1000   return ret;
1001 }
1002
1003 /*!
1004  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
1005  * 
1006  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
1007  * \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.
1008  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
1009  * \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)
1010  * \param [in,out] glob if necessary by the method, new profiles can be added to it
1011  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
1012  * \param [out] result All new entries will be appended on it.
1013  * \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 !)
1014  */
1015 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1016                                                        const DataArrayInt *explicitIdsInMesh,
1017                                                        const std::vector<int>& newCode,
1018                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
1019                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
1020 {
1021   if(entriesOnSameDisc.empty())
1022     return false;
1023   TypeOfField type=entriesOnSameDisc[0]->getType();
1024   int szEntities=0,szTuples=0;
1025   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
1026     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
1027   int nbi=szTuples/szEntities;
1028   if(szTuples%szEntities!=0)
1029     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
1030   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
1031   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
1032   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
1033   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
1034   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
1035   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
1036   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
1037   int id=0;
1038   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
1039     {
1040       int startOfEltIdOfChunk=(*it)->_start;
1041       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
1042       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
1043       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
1044       //
1045       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
1046       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
1047       //
1048       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
1049       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
1050     }
1051   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
1052   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
1053   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
1054   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
1055   //
1056   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
1057   //
1058   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
1059   arrPart->renumberInPlace(renumTupleIds->begin());
1060   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
1061   bool ret=false;
1062   const int *idIt=diffVals->begin();
1063   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
1064   int offset2=0;
1065   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
1066     {
1067       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
1068       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
1069       int nbEntityElts=subIds->getNumberOfTuples();
1070       bool ret2;
1071       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
1072           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
1073                                       offset+offset2,
1074                                       li,glob,ret2);
1075       ret=ret || ret2;
1076       result.push_back(eltToAdd);
1077       offset2+=nbEntityElts*nbi;
1078     }
1079   ret=ret || li.empty();
1080   return ret;
1081 }
1082
1083 /*!
1084  * \param [in] typeF type of field of new chunk
1085  * \param [in] geoType the geometric type of the chunk
1086  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
1087  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
1088  * \param [in] nbi number of integration points
1089  * \param [in] offset The offset in the **global array of data**.
1090  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
1091  *                 to the new chunk to create.
1092  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
1093  * \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
1094  *              and corresponding entry erased from \a entriesOnSameDisc.
1095  * \return a newly allocated chunk
1096  */
1097 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
1098                                                                                                   bool isPfl, int nbi, int offset,
1099                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1100                                                                                                   MEDFileFieldGlobsReal& glob,
1101                                                                                                   bool &notInExisting)
1102 {
1103   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1104   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1105   for(;it!=entriesOnSameDisc.end();it++)
1106     {
1107       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1108         {
1109           if(!isPfl)
1110             {
1111               if((*it)->_profile.empty())
1112                 break;
1113               else
1114                 if(!(*it)->_profile.empty())
1115                   {
1116                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1117                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1118                       break;
1119                   }
1120             }
1121         }
1122     }
1123   if(it==entriesOnSameDisc.end())
1124     {
1125       notInExisting=true;
1126       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1127       ret->_type=typeF;
1128       ret->_loc_id=(int)geoType;
1129       ret->_nval=nbMeshEntities;
1130       ret->_start=offset;
1131       ret->_end=ret->_start+ret->_nval*nbi;
1132       if(isPfl)
1133         {
1134           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1135           glob.appendProfile(idsOfMeshElt);
1136           ret->_profile=idsOfMeshElt->getName();
1137         }
1138       //tony treatment of localization
1139       return ret;
1140     }
1141   else
1142     {
1143       notInExisting=false;
1144       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1145       ret->_loc_id=(int)geoType;
1146       ret->setNewStart(offset);
1147       entriesOnSameDisc.erase(it);
1148       return ret;
1149     }
1150
1151 }
1152
1153 ////////////////////////////////////
1154
1155 MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon()
1156 {
1157 }
1158
1159 void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father)
1160 {
1161   _father=father;
1162 }
1163
1164 void MEDFileFieldPerMeshPerTypeCommon::accept(MEDFileFieldVisitor& visitor) const
1165 {
1166   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1167     if((*it).isNotNull())
1168       {
1169         visitor.newPerMeshPerTypePerDisc(*it);
1170       }
1171 }
1172
1173 void MEDFileFieldPerMeshPerTypeCommon::deepCopyElements()
1174 {
1175   std::size_t i=0;
1176   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1177     {
1178       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1179         _field_pm_pt_pd[i]=(*it)->deepCopy(this);
1180     }
1181 }
1182
1183 std::size_t MEDFileFieldPerMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
1184 {
1185   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1186 }
1187
1188 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypeCommon::getDirectChildrenWithNull() const
1189 {
1190   std::vector<const BigMemoryObject *> ret;
1191   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1192     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1193   return ret;
1194 }
1195
1196 void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1197 {
1198   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1199   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1200     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1201 }
1202
1203 /*!
1204  * This method is the most general one. No optimization is done here.
1205  * \param [in] multiTypePfl is the end user profile specified in high level API
1206  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1207  * \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.
1208  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1209  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1210  * \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.
1211  */
1212 void MEDFileFieldPerMeshPerTypeCommon::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1213 {
1214   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1215   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1216     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1217 }
1218
1219 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1220 {
1221   _field_pm_pt_pd.resize(1);
1222   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1223   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1224 }
1225
1226 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1227 {
1228   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1229   if(!arr || !arr->isAllocated())
1230     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile : input array is null, or not allocated !");
1231   _field_pm_pt_pd.resize(1);
1232   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1233   _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.
1234 }
1235
1236 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1237 {
1238   TypeOfField type=field->getTypeOfField();
1239   if(type!=ON_GAUSS_PT)
1240     {
1241       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1242       int sz=_field_pm_pt_pd.size();
1243       bool found=false;
1244       for(int j=0;j<sz && !found;j++)
1245         {
1246           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1247             {
1248               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1249               found=true;
1250             }
1251         }
1252       if(!found)
1253         {
1254           _field_pm_pt_pd.resize(sz+1);
1255           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1256         }
1257       std::vector<int> ret(1,(int)sz);
1258       return ret;
1259     }
1260   else
1261     {
1262       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1263       int sz2=ret2.size();
1264       std::vector<int> ret3(sz2);
1265       int k=0;
1266       for(int i=0;i<sz2;i++)
1267         {
1268           int sz=_field_pm_pt_pd.size();
1269           int locIdToFind=ret2[i];
1270           bool found=false;
1271           for(int j=0;j<sz && !found;j++)
1272             {
1273               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1274                 {
1275                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1276                   ret3[k++]=j;
1277                   found=true;
1278                 }
1279             }
1280           if(!found)
1281             {
1282               _field_pm_pt_pd.resize(sz+1);
1283               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1284               ret3[k++]=sz;
1285             }
1286         }
1287       return ret3;
1288     }
1289 }
1290
1291 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1292 {
1293   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1294   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1295   if(!disc2)
1296     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1297   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1298   if(!da)
1299     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1300   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1301   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1302   if(retTmp->presenceOfValue(-1))
1303     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1304   std::vector<int> ret(retTmp->begin(),retTmp->end());
1305   return ret;
1306 }
1307
1308 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1309 {
1310   TypeOfField type=field->getTypeOfField();
1311   if(type!=ON_GAUSS_PT)
1312     {
1313       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1314       int sz=_field_pm_pt_pd.size();
1315       bool found=false;
1316       for(int j=0;j<sz && !found;j++)
1317         {
1318           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1319             {
1320               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1321               found=true;
1322             }
1323         }
1324       if(!found)
1325         {
1326           _field_pm_pt_pd.resize(sz+1);
1327           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1328         }
1329       std::vector<int> ret(1,0);
1330       return ret;
1331     }
1332   else
1333     {
1334       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1335       int sz2=ret2.size();
1336       std::vector<int> ret3(sz2);
1337       int k=0;
1338       for(int i=0;i<sz2;i++)
1339         {
1340           int sz=_field_pm_pt_pd.size();
1341           int locIdToFind=ret2[i];
1342           bool found=false;
1343           for(int j=0;j<sz && !found;j++)
1344             {
1345               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1346                 {
1347                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1348                   ret3[k++]=j;
1349                   found=true;
1350                 }
1351             }
1352           if(!found)
1353             {
1354               _field_pm_pt_pd.resize(sz+1);
1355               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1356               ret3[k++]=sz;
1357             }
1358         }
1359       return ret3;
1360     }
1361 }
1362
1363 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1364 {
1365   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1366   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1367   if(!disc2)
1368     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1369   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1370   if(!da)
1371     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1372   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1373   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1374   if(retTmp->presenceOfValue(-1))
1375     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1376   std::vector<int> ret(retTmp->begin(),retTmp->end());
1377   return ret;
1378 }
1379
1380 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const
1381 {
1382   return _father;
1383 }
1384
1385 bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const
1386 {
1387   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
1388   int curDim((int)cm.getDimension());
1389   if(dim!=std::numeric_limits<int>::max())
1390     {
1391       if(dim!=curDim)
1392         return false;
1393     }
1394   else
1395     dim=curDim;
1396   return true;
1397 }
1398
1399 void MEDFileFieldPerMeshPerTypeCommon::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1400 {
1401   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1402     {
1403       (*it)->fillTypesOfFieldAvailable(types);
1404     }
1405 }
1406
1407 void MEDFileFieldPerMeshPerTypeCommon::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1408 {
1409   int sz=_field_pm_pt_pd.size();
1410   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1411   for(int i=0;i<sz;i++)
1412     {
1413       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1414     }
1415 }
1416
1417 int MEDFileFieldPerMeshPerTypeCommon::getIteration() const
1418 {
1419   return _father->getIteration();
1420 }
1421
1422 int MEDFileFieldPerMeshPerTypeCommon::getOrder() const
1423 {
1424   return _father->getOrder();
1425 }
1426
1427 double MEDFileFieldPerMeshPerTypeCommon::getTime() const
1428 {
1429   return _father->getTime();
1430 }
1431
1432 std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const
1433 {
1434   return _father->getMeshName();
1435 }
1436
1437 void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) const
1438 {
1439   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1440     {
1441       globalSz+=(*it)->getNumberOfTuples();
1442     }
1443   nbOfEntries+=(int)_field_pm_pt_pd.size();
1444 }
1445
1446 int MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const
1447 {
1448   return _father->getNumberOfComponents();
1449 }
1450
1451 bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const
1452 {
1453   std::size_t nb(0);
1454   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1455     {
1456       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1457       if(fmtd)
1458         nb++;
1459     }
1460   return nb>1;
1461 }
1462
1463 void MEDFileFieldPerMeshPerTypeCommon::pushDiscretization(MEDFileFieldPerMeshPerTypePerDisc *disc)
1464 {
1465   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt;
1466   elt.takeRef(disc);
1467   _field_pm_pt_pd.push_back(elt);
1468 }
1469
1470 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1471 {
1472   return _father->getOrCreateAndGetArray();
1473 }
1474
1475 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1476 {
1477   const MEDFileFieldPerMesh *fath=_father;
1478   return fath->getOrCreateAndGetArray();
1479 }
1480
1481 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1482 {
1483   return _father->getInfo();
1484 }
1485
1486 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1487 {
1488   std::vector<std::string> ret;
1489   std::set<std::string> ret2;
1490   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1491     {
1492       std::string tmp=(*it1)->getProfile();
1493       if(!tmp.empty())
1494         if(ret2.find(tmp)==ret2.end())
1495           {
1496             ret.push_back(tmp);
1497             ret2.insert(tmp);
1498           }
1499     }
1500   return ret;
1501 }
1502
1503 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1504 {
1505   std::vector<std::string> ret;
1506   std::set<std::string> ret2;
1507   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1508     {
1509       std::string tmp=(*it1)->getLocalization();
1510       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1511         if(ret2.find(tmp)==ret2.end())
1512           {
1513             ret.push_back(tmp);
1514             ret2.insert(tmp);
1515           }
1516     }
1517   return ret;
1518 }
1519
1520 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1521 {
1522   std::vector<std::string> ret;
1523   std::set<std::string> ret2;
1524   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1525     {
1526       std::string tmp=(*it1)->getProfile();
1527       if(!tmp.empty())
1528         ret.push_back(tmp);
1529     }
1530   return ret;
1531 }
1532
1533 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1534 {
1535   std::vector<std::string> ret;
1536   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1537     {
1538       std::string tmp=(*it1)->getLocalization();
1539       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1540         ret.push_back(tmp);
1541     }
1542   return ret;
1543 }
1544
1545 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1546 {
1547   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1548     (*it1)->changePflsRefsNamesGen(mapOfModif);
1549 }
1550
1551 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1552 {
1553   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1554     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1555 }
1556
1557 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId)
1558 {
1559   if(_field_pm_pt_pd.empty())
1560     {
1561       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1562       throw INTERP_KERNEL::Exception(oss.str());
1563     }
1564   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1565     return _field_pm_pt_pd[locId];
1566   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1567   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1568   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1569   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1570 }
1571
1572 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId) const
1573 {
1574   if(_field_pm_pt_pd.empty())
1575     {
1576       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1577       throw INTERP_KERNEL::Exception(oss.str());
1578     }
1579   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1580     return _field_pm_pt_pd[locId];
1581   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1582   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1583   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1584   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1585 }
1586
1587 void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1588 {
1589   int i=0;
1590   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1591     {
1592       (*it)->fillValues(i,startEntryId,entries);
1593     }
1594 }
1595
1596 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1597 {
1598   _field_pm_pt_pd=leaves;
1599   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1600     (*it)->setFather(this);
1601 }
1602
1603 /*!
1604  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1605  *  \param [out] its - list of pair (start,stop) kept
1606  *  \return bool - false if the type of field \a tof is not contained in \a this.
1607  */
1608 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1609 {
1610   bool ret(false);
1611   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1612   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1613     if((*it)->getType()==tof)
1614       {
1615         newPmPtPd.push_back(*it);
1616         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1617         (*it)->setNewStart(globalNum);
1618         globalNum=(*it)->getEnd();
1619         its.push_back(bgEnd);
1620         ret=true;
1621       }
1622   if(ret)
1623     _field_pm_pt_pd=newPmPtPd;
1624   return ret;
1625 }
1626
1627 /*!
1628  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1629  *  \param [out] its - list of pair (start,stop) kept
1630  *  \return bool - false if the type of field \a tof is not contained in \a this.
1631  */
1632 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1633 {
1634   if(_field_pm_pt_pd.size()<=idOfDisc)
1635     return false;
1636   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1637   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1638   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1639   elt->setNewStart(globalNum);
1640   globalNum=elt->getEnd();
1641   its.push_back(bgEnd);
1642   _field_pm_pt_pd=newPmPtPd;
1643   return true;
1644 }
1645
1646 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1647 {
1648   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1649     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1650 }
1651
1652 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1653 {
1654   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1655     (*it)->loadBigArray(fid,nasc);
1656 }
1657
1658 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1659 {
1660   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1661     {
1662       (*it)->copyOptionsFrom(*this);
1663       (*it)->writeLL(fid,nasc);
1664     }
1665 }
1666
1667 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1668 {
1669   switch(ikType)
1670   {
1671     case ON_CELLS:
1672       medfGeoType=typmai3[(int)ikGeoType];
1673       return MED_CELL;
1674     case ON_NODES:
1675       medfGeoType=MED_NONE;
1676       return MED_NODE;
1677     case ON_GAUSS_NE:
1678       medfGeoType=typmai3[(int)ikGeoType];
1679       return MED_NODE_ELEMENT;
1680     case ON_GAUSS_PT:
1681       medfGeoType=typmai3[(int)ikGeoType];
1682       return MED_CELL;
1683     default:
1684       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1685   }
1686   return MED_UNDEF_ENTITY_TYPE;
1687 }
1688
1689 //////////////////////////////////////////////////
1690
1691 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1692 {
1693   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1694 }
1695
1696 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1697 {
1698   return new MEDFileFieldPerMeshPerType(fath,geoType);
1699 }
1700
1701 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1702 {
1703   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1704   ret->setFather(father);
1705   ret->deepCopyElements();
1706   return ret.retn();
1707 }
1708
1709 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
1710 {
1711   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1712     {
1713       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1714       if(meshDim!=(int)cm.getDimension())
1715         return ;
1716     }
1717   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1718     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1719 }
1720
1721 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1722 {
1723   return _geo_type;
1724 }
1725
1726 void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1727 {
1728   ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt);
1729 }
1730
1731 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1732 {
1733   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1734   int curDim((int)cm.getDimension());
1735   dim=std::max(dim,curDim);
1736 }
1737
1738 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1739 {
1740   const char startLine[]="  ## ";
1741   std::string startLine2(bkOffset,' ');
1742   std::string startLine3(startLine2);
1743   startLine3+=startLine;
1744   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1745     {
1746       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1747       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1748     }
1749   else
1750     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1751   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1752   int i=0;
1753   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1754     {
1755       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1756       if(cur)
1757         cur->simpleRepr(bkOffset,oss,i);
1758       else
1759         {
1760           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1761         }
1762     }
1763 }
1764
1765 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1766 {
1767   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1768   return std::string(cm.getRepr());
1769 }
1770
1771 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1772 {
1773 }
1774
1775 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1776 {
1777   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1778   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1779   med_geometry_type mgeoti;
1780   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1781   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1782   _field_pm_pt_pd.resize(nbProfiles);
1783   for(int i=0;i<nbProfiles;i++)
1784     {
1785       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1786     }
1787   if(type==ON_CELLS)
1788     {
1789       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1790       for(int i=0;i<nbProfiles2;i++)
1791         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1792     }
1793 }
1794
1795 MCAuto<MEDFileFieldPerMeshPerType> MEDFileFieldPerMeshPerType::Aggregate(int &start, const std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
1796 {
1797   MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1798   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1799   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1800     {
1801       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1802         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1803     }
1804   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1805     {
1806       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1807       ret->_field_pm_pt_pd.push_back(agg);
1808     }
1809   return ret;
1810 }
1811
1812 //////////////////////////////////////////////////
1813
1814 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc)
1815 {
1816   if(!entities)
1817     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !");
1818   const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
1819   if(!entities2)
1820     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !");
1821   const MEDFileStructureElement *se(entities2->getWithGT(idGT));
1822   return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc);
1823 }
1824
1825 MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath)
1826 {
1827   _se.takeRef(se);
1828   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1829   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1830   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName));
1831   _field_pm_pt_pd.resize(nbProfiles);
1832   for(int i=0;i<nbProfiles;i++)
1833     {
1834       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,_se->getEntity(),i,NULL);
1835     }
1836 }
1837
1838 int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const
1839 {
1840   return _se->getDynGT();
1841 }
1842
1843 std::string MEDFileFieldPerMeshPerTypeDyn::getModelName() const
1844 {
1845   return _se->getName();
1846 }
1847
1848 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1849 {
1850   throw INTERP_KERNEL::Exception("not implemented yet !");
1851 }
1852
1853 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1854 {
1855   gt=getDynGT();
1856   ent=MED_STRUCT_ELEMENT;
1857 }
1858
1859 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1860 {
1861   throw INTERP_KERNEL::Exception("not implemented yet !");
1862 }
1863
1864 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1865 {
1866   const char startLine[]="  ## ";
1867   std::string startLine2(bkOffset,' ');
1868   std::string startLine3(startLine2);
1869   startLine3+=startLine;
1870   oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1871   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1872   int i=0;
1873   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1874     {
1875       if((*it).isNotNull())
1876         (*it)->simpleRepr(bkOffset,oss,i);
1877       else
1878         {
1879           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1880         }
1881     }
1882 }
1883
1884 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1885 {
1886   throw INTERP_KERNEL::Exception("not implemented yet !");
1887 }
1888
1889 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1890 {
1891   MCAuto<MEDFileFieldPerMeshPerTypeDyn> ret(new MEDFileFieldPerMeshPerTypeDyn(*this));
1892   ret->setFather(father);
1893   ret->deepCopyElements();
1894   return ret.retn();
1895 }
1896
1897 void MEDFileFieldPerMeshPerTypeDyn::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
1898 {
1899   throw INTERP_KERNEL::Exception("not implemented yet !");
1900 }
1901
1902 //////////////////////////////////////////////////
1903
1904 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1905 {
1906   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1907 }
1908
1909 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1910 {
1911   return new MEDFileFieldPerMesh(fath,mesh);
1912 }
1913
1914 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1915 {
1916   return _field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1917 }
1918
1919 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1920 {
1921   std::vector<const BigMemoryObject *> ret;
1922   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1923     ret.push_back(*it);
1924   return ret;
1925 }
1926
1927 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1928 {
1929   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1930   ret->_father=father;
1931   std::size_t i=0;
1932   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1933     {
1934       if((*it).isNotNull())
1935         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1936     }
1937   return ret.retn();
1938 }
1939
1940 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1941 {
1942   std::string startLine(bkOffset,' ');
1943   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << getMeshName() << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1944   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1945   int i=0;
1946   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1947     {
1948       if((*it).isNotNull())
1949         (*it)->simpleRepr(bkOffset,oss,i);
1950       else
1951         {
1952           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1953         }
1954     }
1955 }
1956
1957 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1958 {
1959   mesh->getTime(_mesh_iteration,_mesh_order);
1960 }
1961
1962 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1963 {
1964   int nbOfTypes=code.size()/3;
1965   int offset=0;
1966   for(int i=0;i<nbOfTypes;i++)
1967     {
1968       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1969       int nbOfCells=code[3*i+1];
1970       int pos=addNewEntryIfNecessary(type);
1971       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1972       offset+=nbOfCells;
1973     }
1974 }
1975
1976 /*!
1977  * This method is the most general one. No optimization is done here.
1978  * \param [in] multiTypePfl is the end user profile specified in high level API
1979  * \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].
1980  * \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.
1981  * \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.
1982  * \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.
1983  * \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.
1984  */
1985 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)
1986 {
1987   int nbOfTypes(code.size()/3);
1988   for(int i=0;i<nbOfTypes;i++)
1989     {
1990       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1991       int pos=addNewEntryIfNecessary(type);
1992       DataArrayInt *pfl=0;
1993       if(code[3*i+2]!=-1)
1994         pfl=idsPerType[code[3*i+2]];
1995       int nbOfTupes2=code2.size()/3;
1996       int found=0;
1997       for(;found<nbOfTupes2;found++)
1998         if(code[3*i]==code2[3*found])
1999           break;
2000       if(found==nbOfTupes2)
2001         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
2002       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
2003     }
2004 }
2005
2006 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
2007 {
2008   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2009   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
2010 }
2011
2012 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2013 {
2014   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2015   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
2016 }
2017
2018 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
2019 {
2020   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2021     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
2022 }
2023
2024 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
2025 {
2026   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2027     (*it)->loadBigArraysRecursively(fid,nasc);
2028 }
2029
2030 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
2031 {
2032   int nbOfTypes=_field_pm_pt.size();
2033   for(int i=0;i<nbOfTypes;i++)
2034     {
2035       _field_pm_pt[i]->copyOptionsFrom(*this);
2036       _field_pm_pt[i]->writeLL(fid,nasc);
2037     }
2038 }
2039
2040 void MEDFileFieldPerMesh::getDimension(int& dim) const
2041 {
2042   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2043     (*it)->getDimension(dim);
2044 }
2045
2046 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
2047 {
2048   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2049     if(!(*it)->isUniqueLevel(dim))
2050       return false;
2051   return true;
2052 }
2053
2054 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
2055 {
2056   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2057     (*it)->fillTypesOfFieldAvailable(types);
2058 }
2059
2060 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
2061 {
2062   int sz=_field_pm_pt.size();
2063   std::vector< std::vector<std::pair<int,int> > > ret(sz);
2064   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
2065   for(int i=0;i<sz;i++)
2066     {
2067       types[i]=_field_pm_pt[i]->getGeoType();
2068       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
2069     }
2070   return ret;
2071 }
2072
2073 double MEDFileFieldPerMesh::getTime() const
2074 {
2075   int tmp1,tmp2;
2076   return _father->getTime(tmp1,tmp2);
2077 }
2078
2079 int MEDFileFieldPerMesh::getIteration() const
2080 {
2081   return _father->getIteration();
2082 }
2083
2084 int MEDFileFieldPerMesh::getOrder() const
2085 {
2086   return _father->getOrder();
2087 }
2088
2089 int MEDFileFieldPerMesh::getNumberOfComponents() const
2090 {
2091   return _father->getNumberOfComponents();
2092 }
2093
2094 std::string MEDFileFieldPerMesh::getMeshName() const
2095 {
2096   return _father->getMeshName();
2097 }
2098
2099 void MEDFileFieldPerMesh::setMeshName(const std::string& meshName)
2100 {
2101   _father->setMeshName(meshName);
2102 }
2103
2104 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
2105 {
2106   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2107     {
2108       if((*it).isNull())
2109         continue;
2110       if((*it)->presenceOfMultiDiscPerGeoType())
2111         return true;
2112     }
2113   return false;
2114 }
2115
2116 bool MEDFileFieldPerMesh::presenceOfStructureElements() const
2117 {
2118   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2119     if((*it).isNotNull())
2120       {
2121         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2122         if(pt)
2123           return true;
2124       }
2125   return false;
2126 }
2127
2128 bool MEDFileFieldPerMesh::onlyStructureElements() const
2129 {
2130   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2131     if((*it).isNotNull())
2132       {
2133         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2134         if(!pt)
2135           return false;
2136       }
2137   return true;
2138 }
2139
2140 void MEDFileFieldPerMesh::killStructureElements()
2141 {
2142   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2143   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2144     {
2145       if((*it).isNotNull())
2146         {
2147           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2148           if(!pt)
2149             res.push_back(*it);
2150         }
2151     }
2152   _field_pm_pt=res;
2153 }
2154
2155 void MEDFileFieldPerMesh::keepOnlyStructureElements()
2156 {
2157   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2158   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2159     {
2160       if((*it).isNotNull())
2161         {
2162           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2163           if(pt)
2164             res.push_back(*it);
2165         }
2166     }
2167   _field_pm_pt=res;
2168 }
2169
2170 void MEDFileFieldPerMesh::keepOnlyOnSE(const std::string& seName)
2171 {
2172   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2173   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2174     {
2175       if((*it).isNotNull())
2176         {
2177           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2178           if(!pt)
2179             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::keepOnlyOnSE : presence of non SE !");
2180           if(pt->getModelName()==seName)
2181             res.push_back(*it);
2182         }
2183     }
2184   _field_pm_pt=res;
2185 }
2186
2187 void MEDFileFieldPerMesh::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
2188 {
2189   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2190     {
2191       if((*it).isNotNull())
2192         {
2193           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2194           if(pt)
2195             {
2196               ps.push_back(std::pair<std::string,std::string>(getMeshName(),pt->getModelName()));
2197             }
2198           else
2199             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getMeshSENames : presence of a non structure element part !");
2200         }
2201     }
2202 }
2203
2204 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
2205 {
2206   if(!_father)
2207     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2208   return _father->getOrCreateAndGetArray();
2209 }
2210
2211 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
2212 {
2213   if(!_father)
2214     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2215   return _father->getOrCreateAndGetArray();
2216 }
2217
2218 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
2219 {
2220   return _father->getInfo();
2221 }
2222
2223 /*!
2224  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2225  * 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.
2226  * It returns 2 output vectors :
2227  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2228  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2229  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2230  */
2231 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)
2232 {
2233   int notNullPflsSz=0;
2234   int nbOfArrs=geoTypes.size();
2235   for(int i=0;i<nbOfArrs;i++)
2236     if(pfls[i])
2237       notNullPflsSz++;
2238   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2239   int nbOfDiffGeoTypes=geoTypes3.size();
2240   code.resize(3*nbOfDiffGeoTypes);
2241   notNullPfls.resize(notNullPflsSz);
2242   notNullPflsSz=0;
2243   int j=0;
2244   for(int i=0;i<nbOfDiffGeoTypes;i++)
2245     {
2246       int startZone=j;
2247       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2248       std::vector<const DataArrayInt *> notNullTmp;
2249       if(pfls[j])
2250         notNullTmp.push_back(pfls[j]);
2251       j++;
2252       for(;j<nbOfArrs;j++)
2253         if(geoTypes[j]==refType)
2254           {
2255             if(pfls[j])
2256               notNullTmp.push_back(pfls[j]);
2257           }
2258         else
2259           break;
2260       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2261       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2262       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2263       code[3*i]=(int)refType;
2264       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2265       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2266       if(notNullTmp.empty())
2267         code[3*i+2]=-1;
2268       else
2269         {
2270           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
2271           code[3*i+2]=notNullPflsSz++;
2272         }
2273     }
2274 }
2275
2276 /*!
2277  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2278  */
2279 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)
2280 {
2281   int sz=dads.size();
2282   int ret=0;
2283   for(int i=0;i<sz;i++)
2284     {
2285       if(locs[i]==-1)
2286         {
2287           if(type!=ON_GAUSS_NE)
2288             ret+=dads[i].second-dads[i].first;
2289           else
2290             {
2291               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2292               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2293             }
2294         }
2295       else
2296         {
2297           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2298           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2299         }
2300     }
2301   return ret;
2302 }
2303
2304 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2305 {
2306   std::vector<std::string> ret;
2307   std::set<std::string> ret2;
2308   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2309     {
2310       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2311       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2312         if(ret2.find(*it2)==ret2.end())
2313           {
2314             ret.push_back(*it2);
2315             ret2.insert(*it2);
2316           }
2317     }
2318   return ret;
2319 }
2320
2321 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2322 {
2323   std::vector<std::string> ret;
2324   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2325     {
2326       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2327       ret.insert(ret.end(),tmp.begin(),tmp.end());
2328     }
2329   return ret;
2330 }
2331
2332 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2333 {
2334   std::vector<std::string> ret;
2335   std::set<std::string> ret2;
2336   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2337     {
2338       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2339       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2340         if(ret2.find(*it2)==ret2.end())
2341           {
2342             ret.push_back(*it2);
2343             ret2.insert(*it2);
2344           }
2345     }
2346   return ret;
2347 }
2348
2349 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2350 {
2351   std::vector<std::string> ret;
2352   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2353     {
2354       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2355       ret.insert(ret.end(),tmp.begin(),tmp.end());
2356     }
2357   return ret;
2358 }
2359
2360 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2361 {
2362   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2363     {
2364       if((*it).first==getMeshName())
2365         {
2366           setMeshName((*it).second);
2367           return true;
2368         }
2369     }
2370   return false;
2371 }
2372
2373 void MEDFileFieldPerMesh::convertMedBallIntoClassic()
2374 {
2375   if(_field_pm_pt.size()!=1)
2376     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : Only managed for single mesh !");
2377   if(_field_pm_pt[0].isNull())
2378     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : null pointer !");
2379   MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<MEDFileFieldPerMeshPerTypeDyn *>((MEDFileFieldPerMeshPerTypeCommon *)_field_pm_pt[0]));
2380   if(!pt)
2381     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : this is expected to be marked as structure element !");
2382   if(pt->getNumberOfLoc()!=1)
2383     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : only one loc managed !");
2384   const MEDFileFieldPerMeshPerTypePerDisc *disc(pt->getLeafGivenLocId(0));
2385   if(!disc)
2386     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : internal error !");
2387   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> disc2(MEDFileFieldPerMeshPerTypePerDisc::New(*disc));
2388   disc2->setType(ON_NODES);
2389   MCAuto<MEDFileFieldPerMeshPerType> pt2(MEDFileFieldPerMeshPerType::New(this,INTERP_KERNEL::NORM_ERROR));
2390   disc2->setFather(pt2);
2391   pt2->setFather(this);
2392   pt2->pushDiscretization(disc2);
2393   _field_pm_pt[0]=DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(pt2);
2394 }
2395
2396 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2397                                                       MEDFileFieldGlobsReal& glob)
2398 {
2399   if(getMeshName()!=meshName)
2400     return false;
2401   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2402   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2403   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2404   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2405   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2406   getUndergroundDataArrayExt(entries);
2407   DataArray *arr0(getOrCreateAndGetArray());//tony
2408   if(!arr0)
2409     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2410   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2411   if(!arr0)
2412     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2413   int sz=0;
2414   if(!arr)
2415     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2416   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2417     {
2418       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2419         {
2420           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2421           sz+=(*it).second.second-(*it).second.first;
2422         }
2423       else
2424         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2425     }
2426   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2427   ////////////////////
2428   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2429   int *workI2=explicitIdsOldInMesh->getPointer();
2430   int sz1=0,sz2=0,sid=1;
2431   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2432   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2433   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2434     {
2435       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2436       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2437       int *workI=explicitIdsOldInArr->getPointer();
2438       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2439         {
2440           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2441           (*itL2)->setLocId(sz2);
2442           (*itL2)->_tmp_work1=(*itL2)->getStart();
2443           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2444         }
2445       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2446     }
2447   explicitIdsOldInMesh->reAlloc(sz2);
2448   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2449   ////////////////////
2450   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2451   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2452   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2453   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2454     {
2455       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2456       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2457       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2458     }
2459   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2460   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2461   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2462     {
2463       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2464       int newStart=elt->getLocId();
2465       elt->setLocId((*it)->getGeoType());
2466       elt->setNewStart(newStart);
2467       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2468       entriesKeptNew.push_back(elt);
2469       entriesKeptNew2.push_back(elt);
2470     }
2471   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2472   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2473   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2474   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2475   bool ret=false;
2476   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2477     {
2478       sid=0;
2479       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2480         {
2481           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2482           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2483           }*/
2484       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2485                                                             glob,arr2,otherEntriesNew) || ret;
2486     }
2487   if(!ret)
2488     return false;
2489   // Assign new dispatching
2490   assignNewLeaves(otherEntriesNew);
2491   arr->deepCopyFrom(*arr2);
2492   return true;
2493 }
2494
2495 /*!
2496  * \param [in,out] globalNum a global numbering counter for the renumbering.
2497  * \param [out] its - list of pair (start,stop) kept
2498  */
2499 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2500 {
2501   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2502   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2503     {
2504       std::vector< std::pair<int,int> > its2;
2505       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2506         {
2507           ret.push_back(*it);
2508           its.insert(its.end(),its2.begin(),its2.end());
2509         }
2510     }
2511   _field_pm_pt=ret;
2512 }
2513
2514 /*!
2515  * \param [in,out] globalNum a global numbering counter for the renumbering.
2516  * \param [out] its - list of pair (start,stop) kept
2517  */
2518 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2519 {
2520   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2521   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2522     {
2523       std::vector< std::pair<int,int> > its2;
2524       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2525         {
2526           ret.push_back(*it);
2527           its.insert(its.end(),its2.begin(),its2.end());
2528         }
2529     }
2530   _field_pm_pt=ret;
2531 }
2532
2533 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2534 {
2535   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2536   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2537     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2538   //
2539   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2540   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2541   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2542   for(;it1!=types.end();it1++,it2++)
2543     {
2544       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2545       elt->setLeaves((*it1).second);
2546       MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2547       *it2=elt2;
2548     }
2549   _field_pm_pt=fieldPmPt;
2550 }
2551
2552 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2553 {
2554   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2555     (*it)->changePflsRefsNamesGen(mapOfModif);
2556 }
2557
2558 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2559 {
2560   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2561     (*it)->changeLocsRefsNamesGen(mapOfModif);
2562 }
2563
2564 /*!
2565  * \param [in] mesh is the whole mesh
2566  */
2567 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2568 {
2569   if(_field_pm_pt.empty())
2570     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2571   //
2572   std::vector< std::pair<int,int> > dads;
2573   std::vector<const DataArrayInt *> pfls;
2574   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2575   std::vector<int> locs,code;
2576   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2577   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2578     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2579   // Sort by types
2580   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2581   if(code.empty())
2582     {
2583       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2584       throw INTERP_KERNEL::Exception(oss.str());
2585     }
2586   //
2587   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2588   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2589   if(type!=ON_NODES)
2590     {
2591       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2592       if(!arr)
2593         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2594       else
2595         {
2596           MCAuto<DataArrayInt> arr2(arr);
2597           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2598         }
2599     }
2600   else
2601     {
2602       if(code.size()!=3)
2603         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2604       int nb=code[1];
2605       if(code[2]==-1)
2606         {
2607           if(nb!=mesh->getNumberOfNodes())
2608             {
2609               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2610               oss << " nodes in mesh !";
2611               throw INTERP_KERNEL::Exception(oss.str());
2612             }
2613           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2614         }
2615       else
2616         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2617     }
2618 }
2619
2620 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2621 {
2622   if(_field_pm_pt.empty())
2623     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2624   //
2625   std::vector<std::pair<int,int> > dads;
2626   std::vector<const DataArrayInt *> pfls;
2627   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2628   std::vector<int> locs,code;
2629   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2630   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2631     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2632   // Sort by types
2633   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2634   if(code.empty())
2635     {
2636       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2637       throw INTERP_KERNEL::Exception(oss.str());
2638     }
2639   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2640   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2641   if(type!=ON_NODES)
2642     {
2643       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2644       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2645     }
2646   else
2647     {
2648       if(code.size()!=3)
2649         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2650       int nb=code[1];
2651       if(code[2]==-1)
2652         {
2653           if(nb!=mesh->getNumberOfNodes())
2654             {
2655               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2656               oss << " nodes in mesh !";
2657               throw INTERP_KERNEL::Exception(oss.str());
2658             }
2659         }
2660       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2661     }
2662   //
2663   return 0;
2664 }
2665
2666 void MEDFileFieldPerMesh::accept(MEDFileFieldVisitor& visitor) const
2667 {
2668   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2669     if((*it).isNotNull())
2670       {
2671         visitor.newPerMeshPerTypeEntry(*it);
2672         (*it)->accept(visitor);
2673         visitor.endPerMeshPerTypeEntry(*it);
2674       }
2675 }
2676
2677 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2678 {
2679   int globalSz=0;
2680   int nbOfEntries=0;
2681   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2682     {
2683       (*it)->getSizes(globalSz,nbOfEntries);
2684     }
2685   entries.resize(nbOfEntries);
2686   nbOfEntries=0;
2687   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2688     {
2689       (*it)->fillValues(nbOfEntries,entries);
2690     }
2691 }
2692
2693 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2694 {
2695   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2696     {
2697       if((*it)->getGeoType()==typ)
2698         return (*it)->getLeafGivenLocId(locId);
2699     }
2700   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2701   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2702   oss << "Possiblities are : ";
2703   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2704     {
2705       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2706       oss << "\"" << cm2.getRepr() << "\", ";
2707     }
2708   throw INTERP_KERNEL::Exception(oss.str());
2709 }
2710
2711 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2712 {
2713   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2714     {
2715       if((*it)->getGeoType()==typ)
2716         return (*it)->getLeafGivenLocId(locId);
2717     }
2718   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2719   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2720   oss << "Possiblities are : ";
2721   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2722     {
2723       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2724       oss << "\"" << cm2.getRepr() << "\", ";
2725     }
2726   throw INTERP_KERNEL::Exception(oss.str());
2727 }
2728
2729 /*!
2730  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2731  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2732  * \param [in] dts - (Distribution of types) = level 1 : meshes to aggregate. Level 2 : all geo type. Level 3 pair specifying geo type and number of elem in geotype.
2733  * \param [out] extractInfo - Gives information about the where the data comes from. It is a vector of triplet. First element in the triplet the mesh pos. The 2nd one the start pos. The 3rd the end pos.
2734  */
2735 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> MEDFileFieldPerMeshPerTypePerDisc::Aggregate(int &start, const std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, TypeOfField tof, MEDFileFieldPerMeshPerType *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
2736 {
2737   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2738   if(pms.empty())
2739     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2740   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2741     {
2742       if(!(*it).second)
2743         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2744       if(!(*it).second->getProfile().empty())
2745         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2746       if(!(*it).second->getLocalization().empty())
2747         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2748     }
2749   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2750   std::size_t i(0);
2751   std::vector< std::pair<int,int> > filteredDTS;
2752   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2753     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2754       if((*it2).first==gt)
2755         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2756   if(pms.size()!=filteredDTS.size())
2757     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2758   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2759   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2760   int zeStart(start),nval(0);
2761   for(;it1!=pms.end();it1++,it2++)
2762     {
2763       if((*it1).first!=(*it2).first)
2764         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2765       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2766       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2767       start+=e1-s1;
2768       nval+=((*it1).second)->getNumberOfVals();
2769     }
2770   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2771   return ret;
2772 }
2773
2774 MCAuto<MEDFileFieldPerMesh> MEDFileFieldPerMesh::Aggregate(int &start, const std::vector<const MEDFileFieldPerMesh *>& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, MEDFileAnyTypeField1TSWithoutSDA *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
2775 {
2776   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2777   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2778   std::size_t i(0);
2779   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2780     {
2781       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2782       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2783         {
2784           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2785           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2786           if(!elt)
2787             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2788           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2789         }
2790     }
2791   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2792     {
2793       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2794       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2795       ret->_field_pm_pt.push_back(agg2);
2796     }
2797   return ret;
2798 }
2799
2800 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2801 {
2802   int i=0;
2803   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2804   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2805   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2806     {
2807       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2808       if(type==curType)
2809         return i;
2810       else
2811         {
2812           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2813           if(pos>pos2)
2814             it2=it+1;
2815         }
2816     }
2817   int ret=std::distance(_field_pm_pt.begin(),it2);
2818   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2819   return ret;
2820 }
2821
2822 /*!
2823  * 'dads' and 'locs' input parameters have the same number of elements
2824  * \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
2825  */
2826 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2827                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2828                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2829 {
2830   isPfl=false;
2831   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2832   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2833   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2834   const std::vector<std::string>& infos=getInfo();
2835   da->setInfoOnComponents(infos);
2836   da->setName("");
2837   if(type==ON_GAUSS_PT)
2838     {
2839       int offset=0;
2840       int nbOfArrs=dads.size();
2841       for(int i=0;i<nbOfArrs;i++)
2842         {
2843           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2844           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2845           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2846           MCAuto<DataArrayInt> di=DataArrayInt::New();
2847           di->alloc(nbOfElems,1);
2848           di->iota(offset);
2849           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2850           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2851           offset+=nbOfElems;
2852         }
2853     }
2854   arrOut=da;
2855   return ret.retn();
2856 }
2857
2858 /*!
2859  * 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.
2860  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2861  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2862  * The order of cells in the returned field is those imposed by the profile.
2863  * \param [in] mesh is the global mesh.
2864  */
2865 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2866                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2867                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2868                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2869 {
2870   if(da->isIota(mesh->getNumberOfCells()))
2871     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2872   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2873   m2->setName(mesh->getName().c_str());
2874   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2875   isPfl=true;
2876   return ret.retn();
2877 }
2878
2879 /*!
2880  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2881  */
2882 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2883                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2884                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2885 {
2886   if(da->isIota(mesh->getNumberOfNodes()))
2887     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2888   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2889   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2890   if(meshu)
2891     {
2892       if(meshu->getNodalConnectivity()==0)
2893         {
2894           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2895           int nb=da->getNbOfElems();
2896           const int *ptr=da->getConstPointer();
2897           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2898           meshuc->allocateCells(nb);
2899           for(int i=0;i<nb;i++)
2900             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2901           meshuc->finishInsertingCells();
2902           ret->setMesh(meshuc);
2903           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2904           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2905           disc->checkCoherencyBetween(meshuc,arrOut);
2906           return ret.retn();
2907         }
2908     }
2909   //
2910   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2911   isPfl=true;
2912   DataArrayInt *arr2=0;
2913   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2914   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2915   MCAuto<DataArrayInt> arr3(arr2);
2916   int nnodes=mesh2->getNumberOfNodes();
2917   if(nnodes==(int)da->getNbOfElems())
2918     {
2919       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2920       arrOut->renumberInPlace(da3->getConstPointer());
2921       mesh2->setName(mesh->getName().c_str());
2922       ret->setMesh(mesh2);
2923       return ret.retn();
2924     }
2925   else
2926     {
2927       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 !!!";
2928       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2929       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2930       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2931       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2932       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2933       throw INTERP_KERNEL::Exception(oss.str());
2934     }
2935   return 0;
2936 }
2937
2938 /*!
2939  * This method is the most light method of field retrieving.
2940  */
2941 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2942 {
2943   if(!pflIn)
2944     {
2945       pflOut=DataArrayInt::New();
2946       pflOut->alloc(nbOfElems,1);
2947       pflOut->iota(0);
2948     }
2949   else
2950     {
2951       pflOut=const_cast<DataArrayInt*>(pflIn);
2952       pflOut->incrRef();
2953     }
2954   MCAuto<DataArrayInt> safePfl(pflOut);
2955   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2956   const std::vector<std::string>& infos=getInfo();
2957   int nbOfComp=infos.size();
2958   for(int i=0;i<nbOfComp;i++)
2959     da->setInfoOnComponent(i,infos[i].c_str());
2960   safePfl->incrRef();
2961   return da.retn();
2962 }
2963
2964
2965 /// @cond INTERNAL
2966
2967 class MFFPMIter
2968 {
2969 public:
2970   static MFFPMIter *NewCell(const MEDFileEntities *entities);
2971   static bool IsPresenceOfNode(const MEDFileEntities *entities);
2972   virtual ~MFFPMIter() { }
2973   virtual void begin() = 0;
2974   virtual bool finished() const = 0;
2975   virtual void next() = 0;
2976   virtual int current() const = 0;
2977 };
2978
2979 class MFFPMIterSimple : public MFFPMIter
2980 {
2981 public:
2982   MFFPMIterSimple():_pos(0) { }
2983   void begin() { _pos=0; }
2984   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2985   void next() { _pos++; }
2986   int current() const { return _pos; }
2987 private:
2988   int _pos;
2989 };
2990
2991 class MFFPMIter2 : public MFFPMIter
2992 {
2993 public:
2994   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2995   void begin() { _it=_ids.begin(); }
2996   bool finished() const { return _it==_ids.end(); }
2997   void next() { _it++; }
2998   int current() const { return *_it; }
2999 private:
3000   std::vector<int> _ids;
3001   std::vector<int>::const_iterator _it;
3002 };
3003
3004 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
3005 {
3006   if(!entities)
3007     return new MFFPMIterSimple;
3008   else
3009     {
3010       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3011       if(entities2)
3012         {
3013           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
3014           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3015           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3016             {
3017               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
3018                 tmp.push_back((*it).second);
3019             }
3020           return new MFFPMIter2(tmp);
3021         }
3022       return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
3023     }
3024 }
3025
3026 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
3027 {
3028   if(!entities)
3029     return true;
3030   else
3031     {
3032       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3033       if(entities2)
3034         {
3035           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3036           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3037             if((*it).first==ON_NODES)
3038               return true;
3039           return false;
3040         }
3041       return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
3042     }
3043 }
3044
3045 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
3046 {
3047   std::size_t sz(cts.size());
3048   _ids.resize(sz);
3049   for(std::size_t i=0;i<sz;i++)
3050     {
3051       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
3052       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
3053         _ids[i]=(int)std::distance(typmai2,loc);
3054       else
3055         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
3056     }
3057 }
3058
3059 /// @endcond
3060
3061 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
3062     _father(fath)
3063 {
3064   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3065   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3066   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3067   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
3068   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
3069   for(iter0->begin();!iter0->finished();iter0->next())
3070     {
3071       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3072       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3073       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3074       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3075       if(nbProfile>0 || nbProfile2>0)
3076         {
3077           const PartDefinition *pd(0);
3078           if(mmu)
3079             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
3080           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
3081           if(nbProfile>0)
3082             setMeshName(name0);
3083           else
3084             setMeshName(name1);
3085         }
3086     }
3087   if(MFFPMIter::IsPresenceOfNode(entities))
3088     {
3089       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
3090       if(nbProfile>0)
3091         {
3092           const PartDefinition *pd(0);
3093           if(mmu)
3094             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
3095           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
3096           setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3097         }
3098     }
3099   if(!entities)
3100     return ;
3101   std::vector<int> dynGT(entities->getDynGTAvail());
3102   for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
3103     {
3104       int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
3105       if(nbPfl>0)
3106         {
3107           _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
3108           setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3109         }
3110     }
3111 }
3112
3113 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
3114 {
3115   copyTinyInfoFrom(mesh);
3116 }
3117
3118 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3119 {
3120   if(id>=(int)_pfls.size())
3121     _pfls.resize(id+1);
3122   _pfls[id]=DataArrayInt::New();
3123   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
3124   _pfls[id]->setName(pflName);
3125   _pfls[id]->alloc(lgth,1);
3126   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
3127   _pfls[id]->applyLin(1,-1,0);//Converting into C format
3128 }
3129
3130 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
3131 {
3132   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3133   int sz;
3134   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
3135   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
3136   if(i>=(int)_pfls.size())
3137     _pfls.resize(i+1);
3138   _pfls[i]=DataArrayInt::New();
3139   _pfls[i]->alloc(sz,1);
3140   _pfls[i]->setName(pflCpp.c_str());
3141   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
3142   _pfls[i]->applyLin(1,-1,0);//Converting into C format
3143 }
3144
3145 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3146 {
3147   int nbOfPfls=_pfls.size();
3148   for(int i=0;i<nbOfPfls;i++)
3149     {
3150       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
3151       cpy->applyLin(1,1,0);
3152       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3153       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
3154       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
3155     }
3156   //
3157   int nbOfLocs=_locs.size();
3158   for(int i=0;i<nbOfLocs;i++)
3159     _locs[i]->writeLL(fid);
3160 }
3161
3162 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
3163 {
3164   std::vector<std::string> pfls=getPfls();
3165   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
3166     {
3167       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
3168       if(it2==pfls.end())
3169         {
3170           _pfls.push_back(*it);
3171         }
3172       else
3173         {
3174           int id=std::distance(pfls.begin(),it2);
3175           if(!(*it)->isEqual(*_pfls[id]))
3176             {
3177               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3178               throw INTERP_KERNEL::Exception(oss.str());
3179             }
3180         }
3181     }
3182   std::vector<std::string> locs=getLocs();
3183   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
3184     {
3185       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
3186       if(it2==locs.end())
3187         {
3188           _locs.push_back(*it);
3189         }
3190       else
3191         {
3192           int id=std::distance(locs.begin(),it2);
3193           if(!(*it)->isEqual(*_locs[id],eps))
3194             {
3195               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3196               throw INTERP_KERNEL::Exception(oss.str());
3197             }
3198         }
3199     }
3200 }
3201
3202 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
3203 {
3204   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
3205     getProfile((*it).c_str());
3206 }
3207
3208 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
3209 {
3210   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
3211     getLocalization((*it).c_str());
3212 }
3213
3214 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
3215 {
3216   std::vector<std::string> profiles=real.getPflsReallyUsed();
3217   int sz=profiles.size();
3218   _pfls.resize(sz);
3219   for(int i=0;i<sz;i++)
3220     loadProfileInFile(fid,i,profiles[i].c_str());
3221   //
3222   std::vector<std::string> locs=real.getLocsReallyUsed();
3223   sz=locs.size();
3224   _locs.resize(sz);
3225   for(int i=0;i<sz;i++)
3226     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
3227 }
3228
3229 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3230 {
3231   int nProfil=MEDnProfile(fid);
3232   for(int i=0;i<nProfil;i++)
3233     loadProfileInFile(fid,i);
3234   int sz=MEDnLocalization(fid);
3235   _locs.resize(sz);
3236   for(int i=0;i<sz;i++)
3237     {
3238       _locs[i]=MEDFileFieldLoc::New(fid,i,entities);
3239     }
3240 }
3241
3242 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
3243 {
3244   return new MEDFileFieldGlobs(fid);
3245 }
3246
3247 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
3248 {
3249   return new MEDFileFieldGlobs;
3250 }
3251
3252 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
3253 {
3254   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
3255 }
3256
3257 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
3258 {
3259   std::vector<const BigMemoryObject *> ret;
3260   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3261     ret.push_back((const DataArrayInt *)*it);
3262   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3263     ret.push_back((const MEDFileFieldLoc *)*it);
3264   return ret;
3265 }
3266
3267 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
3268 {
3269   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
3270   std::size_t i=0;
3271   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3272     {
3273       if((const DataArrayInt *)*it)
3274         ret->_pfls[i]=(*it)->deepCopy();
3275     }
3276   i=0;
3277   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3278     {
3279       if((const MEDFileFieldLoc*)*it)
3280         ret->_locs[i]=(*it)->deepCopy();
3281     }
3282   return ret.retn();
3283 }
3284
3285 /*!
3286  * \throw if a profile in \a pfls in not in \a this.
3287  * \throw if a localization in \a locs in not in \a this.
3288  * \sa MEDFileFieldGlobs::deepCpyPart
3289  */
3290 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3291 {
3292   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3293   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3294     {
3295       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3296       if(!pfl)
3297         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
3298       pfl->incrRef();
3299       MCAuto<DataArrayInt> pfl2(pfl);
3300       ret->_pfls.push_back(pfl2);
3301     }
3302   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3303     {
3304       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3305       if(!loc)
3306         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
3307       loc->incrRef();
3308       MCAuto<MEDFileFieldLoc> loc2(loc);
3309       ret->_locs.push_back(loc2);
3310     }
3311   ret->setFileName(getFileName());
3312   return ret.retn();
3313 }
3314
3315 /*!
3316  * \throw if a profile in \a pfls in not in \a this.
3317  * \throw if a localization in \a locs in not in \a this.
3318  * \sa MEDFileFieldGlobs::shallowCpyPart
3319  */
3320 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3321 {
3322   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3323   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3324     {
3325       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3326       if(!pfl)
3327         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
3328       ret->_pfls.push_back(pfl->deepCopy());
3329     }
3330   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3331     {
3332       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3333       if(!loc)
3334         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
3335       ret->_locs.push_back(loc->deepCopy());
3336     }
3337   ret->setFileName(getFileName());
3338   return ret.retn();
3339 }
3340
3341 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
3342 {
3343 }
3344
3345 MEDFileFieldGlobs::MEDFileFieldGlobs()
3346 {
3347 }
3348
3349 MEDFileFieldGlobs::~MEDFileFieldGlobs()
3350 {
3351 }
3352
3353 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
3354 {
3355   oss << "Profiles :\n";
3356   std::size_t n=_pfls.size();
3357   for(std::size_t i=0;i<n;i++)
3358     {
3359       oss << "  - #" << i << " ";
3360       const DataArrayInt *pfl=_pfls[i];
3361       if(pfl)
3362         oss << "\"" << pfl->getName() << "\"\n";
3363       else
3364         oss << "EMPTY !\n";
3365     }
3366   n=_locs.size();
3367   oss << "Localizations :\n";
3368   for(std::size_t i=0;i<n;i++)
3369     {
3370       oss << "  - #" << i << " ";
3371       const MEDFileFieldLoc *loc=_locs[i];
3372       if(loc)
3373         loc->simpleRepr(oss);
3374       else
3375         oss<< "EMPTY !\n";
3376     }
3377 }
3378
3379 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3380 {
3381   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3382     {
3383       DataArrayInt *elt(*it);
3384       if(elt)
3385         {
3386           std::string name(elt->getName());
3387           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3388             {
3389               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3390                 {
3391                   elt->setName((*it2).second.c_str());
3392                   return;
3393                 }
3394             }
3395         }
3396     }
3397 }
3398
3399 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3400 {
3401   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3402     {
3403       MEDFileFieldLoc *elt(*it);
3404       if(elt)
3405         {
3406           std::string name(elt->getName());
3407           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3408             {
3409               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3410                 {
3411                   elt->setName((*it2).second.c_str());
3412                   return;
3413                 }
3414             }
3415         }
3416     }
3417 }
3418
3419 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3420 {
3421   if(locId<0 || locId>=(int)_locs.size())
3422     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3423   return _locs[locId]->getNbOfGaussPtPerCell();
3424 }
3425
3426 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3427 {
3428   return getLocalizationFromId(getLocalizationId(locName));
3429 }
3430
3431 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3432 {
3433   if(locId<0 || locId>=(int)_locs.size())
3434     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3435   return *_locs[locId];
3436 }
3437
3438 /// @cond INTERNAL
3439 namespace MEDCouplingImpl
3440 {
3441   class LocFinder
3442   {
3443   public:
3444     LocFinder(const std::string& loc):_loc(loc) { }
3445     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3446   private:
3447     const std::string &_loc;
3448   };
3449
3450   class PflFinder
3451   {
3452   public:
3453     PflFinder(const std::string& pfl):_pfl(pfl) { }
3454     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3455   private:
3456     const std::string& _pfl;
3457   };
3458 }
3459 /// @endcond
3460
3461 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3462 {
3463   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3464   if(it==_locs.end())
3465     {
3466       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3467       for(it=_locs.begin();it!=_locs.end();it++)
3468         oss << "\"" << (*it)->getName() << "\", ";
3469       throw INTERP_KERNEL::Exception(oss.str());
3470     }
3471   return std::distance(_locs.begin(),it);
3472 }
3473
3474 /*!
3475  * The returned value is never null.
3476  */
3477 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3478 {
3479   std::string pflNameCpp(pflName);
3480   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3481   if(it==_pfls.end())
3482     {
3483       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3484       for(it=_pfls.begin();it!=_pfls.end();it++)
3485         oss << "\"" << (*it)->getName() << "\", ";
3486       throw INTERP_KERNEL::Exception(oss.str());
3487     }
3488   return *it;
3489 }
3490
3491 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3492 {
3493   if(pflId<0 || pflId>=(int)_pfls.size())
3494     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3495   return _pfls[pflId];
3496 }
3497
3498 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3499 {
3500   if(locId<0 || locId>=(int)_locs.size())
3501     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3502   return *_locs[locId];
3503 }
3504
3505 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3506 {
3507   return getLocalizationFromId(getLocalizationId(locName));
3508 }
3509
3510 /*!
3511  * The returned value is never null.
3512  */
3513 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3514 {
3515   std::string pflNameCpp(pflName);
3516   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3517   if(it==_pfls.end())
3518     {
3519       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3520       for(it=_pfls.begin();it!=_pfls.end();it++)
3521         oss << "\"" << (*it)->getName() << "\", ";
3522       throw INTERP_KERNEL::Exception(oss.str());
3523     }
3524   return *it;
3525 }
3526
3527 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3528 {
3529   if(pflId<0 || pflId>=(int)_pfls.size())
3530     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3531   return _pfls[pflId];
3532 }
3533
3534 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3535 {
3536   std::vector< MCAuto<DataArrayInt> > newPfls;
3537   int i=0;
3538   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3539     {
3540       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3541         newPfls.push_back(*it);
3542     }
3543   _pfls=newPfls;
3544 }
3545
3546 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3547 {
3548   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3549   int i=0;
3550   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3551     {
3552       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3553         newLocs.push_back(*it);
3554     }
3555   _locs=newLocs;
3556 }
3557
3558 void MEDFileFieldGlobs::killStructureElementsInGlobs()
3559 {
3560   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3561   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3562     {
3563       if((*it).isNull())
3564         continue;
3565       if(!(*it)->isOnStructureElement())
3566         newLocs.push_back(*it);
3567     }
3568   _locs=newLocs;
3569 }
3570
3571 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3572 {
3573   int sz=_pfls.size();
3574   std::vector<std::string> ret(sz);
3575   for(int i=0;i<sz;i++)
3576     ret[i]=_pfls[i]->getName();
3577   return ret;
3578 }
3579
3580 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3581 {
3582   int sz=_locs.size();
3583   std::vector<std::string> ret(sz);
3584   for(int i=0;i<sz;i++)
3585     ret[i]=_locs[i]->getName();
3586   return ret;
3587 }
3588
3589 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3590 {
3591   std::vector<std::string> v=getPfls();
3592   std::string s(pflName);
3593   return std::find(v.begin(),v.end(),s)!=v.end();
3594 }
3595
3596 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3597 {
3598   std::vector<std::string> v=getLocs();
3599   std::string s(locName);
3600   return std::find(v.begin(),v.end(),s)!=v.end();
3601 }
3602
3603 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3604 {
3605   std::map<int,std::vector<int> > m;
3606   int i=0;
3607   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3608     {
3609       const DataArrayInt *tmp=(*it);
3610       if(tmp)
3611         {
3612           m[tmp->getHashCode()].push_back(i);
3613         }
3614     }
3615   std::vector< std::vector<int> > ret;
3616   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3617     {
3618       if((*it2).second.size()>1)
3619         {
3620           std::vector<int> ret0;
3621           bool equalityOrNot=false;
3622           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3623             {
3624               std::vector<int>::const_iterator it4=it3; it4++;
3625               for(;it4!=(*it2).second.end();it4++)
3626                 {
3627                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3628                     {
3629                       if(!equalityOrNot)
3630                         ret0.push_back(*it3);
3631                       ret0.push_back(*it4);
3632                       equalityOrNot=true;
3633                     }
3634                 }
3635             }
3636           if(!ret0.empty())
3637             ret.push_back(ret0);
3638         }
3639     }
3640   return ret;
3641 }
3642
3643 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3644 {
3645   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3646 }
3647
3648 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3649 {
3650   std::string name(pfl->getName());
3651   if(name.empty())
3652     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3653   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3654     if(name==(*it)->getName())
3655       {
3656         if(!pfl->isEqual(*(*it)))
3657           {
3658             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3659             throw INTERP_KERNEL::Exception(oss.str());
3660           }
3661       }
3662   pfl->incrRef();
3663   _pfls.push_back(pfl);
3664 }
3665
3666 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)
3667 {
3668   std::string name(locName);
3669   if(name.empty())
3670     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3671   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3672   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3673     if((*it)->isName(locName))
3674       {
3675         if(!(*it)->isEqual(*obj,1e-12))
3676           {
3677             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3678             throw INTERP_KERNEL::Exception(oss.str());
3679           }
3680       }
3681   _locs.push_back(obj);
3682 }
3683
3684 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3685 {
3686   std::vector<std::string> names=getPfls();
3687   return CreateNewNameNotIn("NewPfl_",names);
3688 }
3689
3690 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3691 {
3692   std::vector<std::string> names=getLocs();
3693   return CreateNewNameNotIn("NewLoc_",names);
3694 }
3695
3696 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3697 {
3698   for(std::size_t sz=0;sz<100000;sz++)
3699     {
3700       std::ostringstream tryName;
3701       tryName << prefix << sz;
3702       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3703         return tryName.str();
3704     }
3705   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3706 }
3707
3708 /*!
3709  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3710  *  \param [in] fname - the file name.
3711  */
3712 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3713 {
3714 }
3715
3716 /*!
3717  * Creates an empty MEDFileFieldGlobsReal.
3718  */
3719 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3720 {
3721 }
3722
3723 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3724 {
3725   return 0;
3726 }
3727
3728 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3729 {
3730   std::vector<const BigMemoryObject *> ret;
3731   ret.push_back((const MEDFileFieldGlobs *)_globals);
3732   return ret;
3733 }
3734
3735 /*!
3736  * Returns a string describing profiles and Gauss points held in \a this.
3737  *  \return std::string - the description string.
3738  */
3739 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3740 {
3741   const MEDFileFieldGlobs *glob=_globals;
3742   std::ostringstream oss2; oss2 << glob;
3743   std::string stars(oss2.str().length(),'*');
3744   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3745   if(glob)
3746     glob->simpleRepr(oss);
3747   else
3748     oss << "NO GLOBAL INFORMATION !\n";
3749 }
3750
3751 void MEDFileFieldGlobsReal::resetContent()
3752 {
3753   _globals=MEDFileFieldGlobs::New();
3754 }
3755
3756 void MEDFileFieldGlobsReal::killStructureElementsInGlobs()
3757 {
3758   contentNotNull()->killStructureElementsInGlobs();
3759 }
3760
3761 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3762 {
3763 }
3764
3765 /*!
3766  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3767  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3768  */
3769 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3770 {
3771   _globals=other._globals;
3772 }
3773
3774 /*!
3775  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3776  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3777  */
3778 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3779 {
3780   const MEDFileFieldGlobs *otherg(other._globals);
3781   if(!otherg)
3782     return ;
3783   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3784 }
3785
3786 /*!
3787  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3788  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3789  */
3790 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3791 {
3792   const MEDFileFieldGlobs *otherg(other._globals);
3793   if(!otherg)
3794     return ;
3795   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3796 }
3797
3798 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3799 {
3800   _globals=other._globals;
3801   if((const MEDFileFieldGlobs *)_globals)
3802     _globals=other._globals->deepCopy();
3803 }
3804
3805 /*!
3806  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3807  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3808  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3809  *         \a this and \a other MEDFileFieldGlobsReal.
3810  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3811  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3812  */
3813 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3814 {
3815   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3816   if(thisGlobals==otherGlobals)
3817     return ;
3818   if(!thisGlobals)
3819     {
3820       _globals=other._globals;
3821       return ;
3822     }
3823   _globals->appendGlobs(*other._globals,eps);
3824 }
3825
3826 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3827 {
3828   checkGlobsPflsPartCoherency();
3829   checkGlobsLocsPartCoherency();
3830 }
3831
3832 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3833 {
3834   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3835 }
3836
3837 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3838 {
3839   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3840 }
3841
3842 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3843 {
3844   contentNotNull()->loadProfileInFile(fid,id,pflName);
3845 }
3846
3847 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3848 {
3849   contentNotNull()->loadProfileInFile(fid,id);
3850 }
3851
3852 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3853 {
3854   contentNotNull()->loadGlobals(fid,*this);
3855 }
3856
3857 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3858 {
3859   contentNotNull()->loadAllGlobals(fid,entities);
3860 }
3861
3862 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3863 {
3864   contentNotNull()->writeGlobals(fid,opt);
3865 }
3866
3867 /*!
3868  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3869  * or getPflsReallyUsedMulti().
3870  *  \return std::vector<std::string> - a sequence of names of all profiles.
3871  */
3872 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3873 {
3874   return contentNotNull()->getPfls();
3875 }
3876
3877 /*!
3878  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3879  * or getLocsReallyUsedMulti().
3880  *  \return std::vector<std::string> - a sequence of names of all localizations.
3881  */
3882 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3883 {
3884   return contentNotNull()->getLocs();
3885 }
3886
3887 /*!
3888  * Checks if the profile with a given name exists.
3889  *  \param [in] pflName - the profile name of interest.
3890  *  \return bool - \c true if the profile named \a pflName exists.
3891  */
3892 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3893 {
3894   return contentNotNull()->existsPfl(pflName);
3895 }
3896
3897 /*!
3898  * Checks if the localization with a given name exists.
3899  *  \param [in] locName - the localization name of interest.
3900  *  \return bool - \c true if the localization named \a locName exists.
3901  */
3902 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3903 {
3904   return contentNotNull()->existsLoc(locName);
3905 }
3906
3907 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3908 {
3909   return contentNotNull()->createNewNameOfPfl();
3910 }
3911
3912 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3913 {
3914   return contentNotNull()->createNewNameOfLoc();
3915 }
3916
3917 /*!
3918  * Sets the name of a MED file.
3919  *  \param [inout] fileName - the file name.
3920  */
3921 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3922 {
3923   contentNotNull()->setFileName(fileName);
3924 }
3925
3926 /*!
3927  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3928  * in the same order.
3929  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3930  *          Each item of this sequence is a vector containing ids of equal profiles.
3931  */
3932 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3933 {
3934   return contentNotNull()->whichAreEqualProfiles();
3935 }
3936
3937 /*!
3938  * Finds equal localizations.
3939  *  \param [in] eps - a precision used to compare real values of the localizations.
3940  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3941  *          Each item of this sequence is a vector containing ids of equal localizations.
3942  */
3943 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3944 {
3945   return contentNotNull()->whichAreEqualLocs(eps);
3946 }
3947
3948 /*!
3949  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3950  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3951  *        this sequence is a pair whose 
3952  *        - the first item is a vector of profile names to replace by the second item,
3953  *        - the second item is a profile name to replace every profile name of the first item.
3954  */
3955 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3956 {
3957   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3958 }
3959
3960 /*!
3961  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3962  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3963  *        this sequence is a pair whose 
3964  *        - the first item is a vector of localization names to replace by the second item,
3965  *        - the second item is a localization name to replace every localization name of the first item.
3966  */
3967 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3968 {
3969   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3970 }
3971
3972 /*!
3973  * Replaces references to some profiles (a reference is a profile name) by references
3974  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3975  * them-selves accordingly. <br>
3976  * This method is a generalization of changePflName().
3977  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3978  *        this sequence is a pair whose 
3979  *        - the first item is a vector of profile names to replace by the second item,
3980  *        - the second item is a profile name to replace every profile of the first item.
3981  * \sa changePflsRefsNamesGen()
3982  * \sa changePflName()
3983  */
3984 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3985 {
3986   changePflsRefsNamesGen(mapOfModif);
3987   changePflsNamesInStruct(mapOfModif);
3988 }
3989
3990 /*!
3991  * Replaces references to some localizations (a reference is a localization name) by references
3992  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3993  * them-selves accordingly. <br>
3994  * This method is a generalization of changeLocName().
3995  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3996  *        this sequence is a pair whose 
3997  *        - the first item is a vector of localization names to replace by the second item,
3998  *        - the second item is a localization name to replace every localization of the first item.
3999  * \sa changeLocsRefsNamesGen()
4000  * \sa changeLocName()
4001  */
4002 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4003 {
4004   changeLocsRefsNamesGen(mapOfModif);
4005   changeLocsNamesInStruct(mapOfModif);
4006 }
4007
4008 /*!
4009  * Renames the profile having a given name and updates references to this profile.
4010  *  \param [in] oldName - the name of the profile to rename.
4011  *  \param [in] newName - a new name of the profile.
4012  * \sa changePflsNames().
4013  */
4014 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
4015 {
4016   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4017   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4018   mapOfModif[0]=p;
4019   changePflsNames(mapOfModif);
4020 }
4021
4022 /*!
4023  * Renames the localization having a given name and updates references to this localization.
4024  *  \param [in] oldName - the name of the localization to rename.
4025  *  \param [in] newName - a new name of the localization.
4026  * \sa changeLocsNames().
4027  */
4028 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
4029 {
4030   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4031   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4032   mapOfModif[0]=p;
4033   changeLocsNames(mapOfModif);
4034 }
4035
4036 /*!
4037  * Removes duplicated profiles. Returns a map used to update references to removed 
4038  * profiles via changePflsRefsNamesGen().
4039  * Equal profiles are found using whichAreEqualProfiles().
4040  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4041  *          a sequence describing the performed replacements of profiles. Each element of
4042  *          this sequence is a pair whose
4043  *          - the first item is a vector of profile names replaced by the second item,
4044  *          - the second item is a profile name replacing every profile of the first item.
4045  */
4046 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
4047 {
4048   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
4049   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4050   int i=0;
4051   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4052     {
4053       std::vector< std::string > tmp((*it).size());
4054       int j=0;
4055       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4056         tmp[j]=std::string(getProfileFromId(*it2)->getName());
4057       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4058       ret[i]=p;
4059       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4060       killProfileIds(tmp2);
4061     }
4062   changePflsRefsNamesGen(ret);
4063   return ret;
4064 }
4065
4066 /*!
4067  * Removes duplicated localizations. Returns a map used to update references to removed 
4068  * localizations via changeLocsRefsNamesGen().
4069  * Equal localizations are found using whichAreEqualLocs().
4070  *  \param [in] eps - a precision used to compare real values of the localizations.
4071  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4072  *          a sequence describing the performed replacements of localizations. Each element of
4073  *          this sequence is a pair whose
4074  *          - the first item is a vector of localization names replaced by the second item,
4075  *          - the second item is a localization name replacing every localization of the first item.
4076  */
4077 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
4078 {
4079   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
4080   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4081   int i=0;
4082   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4083     {
4084       std::vector< std::string > tmp((*it).size());
4085       int j=0;
4086       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4087         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
4088       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4089       ret[i]=p;
4090       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4091       killLocalizationIds(tmp2);
4092     }
4093   changeLocsRefsNamesGen(ret);
4094   return ret;
4095 }
4096
4097 /*!
4098  * Returns number of Gauss points per cell in a given localization.
4099  *  \param [in] locId - an id of the localization of interest.
4100  *  \return int - the number of the Gauss points per cell.
4101  */
4102 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
4103 {
4104   return contentNotNull()->getNbOfGaussPtPerCell(locId);
4105 }
4106
4107 /*!
4108  * Returns an id of a localization by its name.
4109  *  \param [in] loc - the localization name of interest.
4110  *  \return int - the id of the localization.
4111  *  \throw If there is no a localization named \a loc.
4112  */
4113 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
4114 {
4115   return contentNotNull()->getLocalizationId(loc);
4116 }
4117
4118 /*!
4119  * Returns the name of the MED file.
4120  *  \return const std::string&  - the MED file name.
4121  */
4122 std::string MEDFileFieldGlobsReal::getFileName() const
4123 {
4124   return contentNotNull()->getFileName();
4125 }
4126
4127 /*!
4128  * Returns a localization object by its name.
4129  *  \param [in] locName - the name of the localization of interest.
4130  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
4131  *  \throw If there is no a localization named \a locName.
4132  */
4133 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
4134 {
4135   return contentNotNull()->getLocalization(locName);
4136 }
4137
4138 /*!
4139  * Returns a localization object by its id.
4140  *  \param [in] locId - the id of the localization of interest.
4141  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
4142  *  \throw If there is no a localization with id \a locId.
4143  */
4144 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
4145 {
4146   return contentNotNull()->getLocalizationFromId(locId);
4147 }
4148
4149 /*!
4150  * Returns a profile array by its name.
4151  *  \param [in] pflName - the name of the profile of interest.
4152  *  \return const DataArrayInt * - the profile array having the name \a pflName.
4153  *  \throw If there is no a profile named \a pflName.
4154  */
4155 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
4156 {
4157   return contentNotNull()->getProfile(pflName);
4158 }
4159
4160 /*!
4161  * Returns a profile array by its id.
4162  *  \param [in] pflId - the id of the profile of interest.
4163  *  \return const DataArrayInt * - the profile array having the id \a pflId.
4164  *  \throw If there is no a profile with id \a pflId.
4165  */
4166 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
4167 {
4168   return contentNotNull()->getProfileFromId(pflId);
4169 }
4170
4171 /*!
4172  * Returns a localization object, apt for modification, by its id.
4173  *  \param [in] locId - the id of the localization of interest.
4174  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4175  *          having the id \a locId.
4176  *  \throw If there is no a localization with id \a locId.
4177  */
4178 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
4179 {
4180   return contentNotNull()->getLocalizationFromId(locId);
4181 }
4182
4183 /*!
4184  * Returns a localization object, apt for modification, by its name.
4185  *  \param [in] locName - the name of the localization of interest.
4186  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4187  *          having the name \a locName.
4188  *  \throw If there is no a localization named \a locName.
4189  */
4190 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
4191 {
4192   return contentNotNull()->getLocalization(locName);
4193 }
4194
4195 /*!
4196  * Returns a profile array, apt for modification, by its name.
4197  *  \param [in] pflName - the name of the profile of interest.
4198  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
4199  *  \throw If there is no a profile named \a pflName.
4200  */
4201 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
4202 {
4203   return contentNotNull()->getProfile(pflName);
4204 }
4205
4206 /*!
4207  * Returns a profile array, apt for modification, by its id.
4208  *  \param [in] pflId - the id of the profile of interest.
4209  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
4210  *  \throw If there is no a profile with id \a pflId.
4211  */
4212 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
4213 {
4214   return contentNotNull()->getProfileFromId(pflId);
4215 }
4216
4217 /*!
4218  * Removes profiles given by their ids. No data is updated to track this removal.
4219  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
4220  */
4221 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
4222 {
4223   contentNotNull()->killProfileIds(pflIds);
4224 }
4225
4226 /*!
4227  * Removes localizations given by their ids. No data is updated to track this removal.
4228  *  \param [in] locIds - a sequence of ids of the localizations to remove.
4229  */
4230 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
4231 {
4232   contentNotNull()->killLocalizationIds(locIds);
4233 }
4234
4235 /*!
4236  * Stores a profile array.
4237  *  \param [in] pfl - the profile array to store.
4238  *  \throw If the name of \a pfl is empty.
4239  *  \throw If a profile with the same name as that of \a pfl already exists but contains
4240  *         different ids.
4241  */
4242 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
4243 {
4244   contentNotNull()->appendProfile(pfl);
4245 }
4246
4247 /*!
4248  * Adds a new localization of Gauss points.
4249  *  \param [in] locName - the name of the new localization.
4250  *  \param [in] geoType - a geometrical type of the reference cell.
4251  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
4252  *         must be \c nbOfNodesPerCell * \c dimOfType.
4253  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
4254  *         must be  _wg_.size() * \c dimOfType.
4255  *  \param [in] w - the weights of Gauss points.
4256  *  \throw If \a locName is empty.
4257  *  \throw If a localization with the name \a locName already exists but is
4258  *         different form the new one.
4259  */
4260 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)
4261 {
4262   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
4263 }
4264
4265 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
4266 {
4267   MEDFileFieldGlobs *g(_globals);
4268   if(!g)
4269     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
4270   return g;
4271 }
4272
4273 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
4274 {
4275   const MEDFileFieldGlobs *g(_globals);
4276   if(!g)
4277     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
4278   return g;
4279 }
4280
4281 //= MEDFileFieldNameScope
4282
4283 MEDFileFieldNameScope::MEDFileFieldNameScope()
4284 {
4285 }
4286
4287 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName, const std::string& meshName):_name(fieldName),_mesh_name(meshName)
4288 {
4289 }
4290
4291 /*!
4292  * Returns the name of \a this field.
4293  *  \return std::string - a string containing the field name.
4294  */
4295 std::string MEDFileFieldNameScope::getName() const
4296 {
4297   return _name;
4298 }
4299
4300 /*!
4301  * Sets name of \a this field
4302  *  \param [in] name - the new field name.
4303  */
4304 void MEDFileFieldNameScope::setName(const std::string& fieldName)
4305 {
4306   _name=fieldName;
4307 }
4308
4309 std::string MEDFileFieldNameScope::getDtUnit() const
4310 {
4311   return _dt_unit;
4312 }
4313
4314 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
4315 {
4316   _dt_unit=dtUnit;
4317 }
4318
4319 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
4320 {
4321   _name=other._name;
4322   _mesh_name=other._mesh_name;
4323   _dt_unit=other._dt_unit;
4324 }
4325
4326 /*!
4327  * Returns the mesh name.
4328  *  \return std::string - a string holding the mesh name.
4329  *  \throw If \c _field_per_mesh.empty()
4330  */
4331 std::string MEDFileFieldNameScope::getMeshName() const
4332 {
4333   return _mesh_name;
4334 }
4335
4336 void MEDFileFieldNameScope::setMeshName(const std::string& meshName)
4337 {
4338   _mesh_name=meshName;
4339 }
4340
4341 //= MEDFileAnyTypeField1TSWithoutSDA
4342
4343 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
4344 {
4345   _field_per_mesh.resize(other._field_per_mesh.size());
4346   std::size_t i=0;
4347   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
4348     {
4349       if((const MEDFileFieldPerMesh *)*it)
4350         _field_per_mesh[i]=(*it)->deepCopy(this);
4351     }
4352 }
4353
4354 void MEDFileAnyTypeField1TSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
4355 {
4356   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4357     if((*it).isNotNull())
4358       {
4359         visitor.newMeshEntry(*it);
4360         (*it)->accept(visitor);
4361         visitor.endMeshEntry(*it);
4362       }
4363 }
4364
4365 /*!
4366  * Prints a string describing \a this field into a stream. This string is outputted 
4367  * by \c print Python command.
4368  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
4369  *  \param [in,out] oss - the out stream.
4370  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
4371  *          info id printed, else, not.
4372  */
4373 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4374 {
4375   std::string startOfLine(bkOffset,' ');
4376   oss << startOfLine << "Field ";
4377   if(bkOffset==0)
4378     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
4379   oss << "on one time Step ";
4380   if(f1tsId>=0)
4381     oss << "(" << f1tsId << ") ";
4382   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
4383   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
4384   const DataArray *arr=getUndergroundDataArray();
4385   if(arr)
4386     {
4387       const std::vector<std::string> &comps=arr->getInfoOnComponents();
4388       if(f1tsId<0)
4389         {
4390           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
4391           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
4392             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
4393         }
4394       if(arr->isAllocated())
4395         {
4396           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
4397         }
4398       else
4399         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
4400     }
4401   else
4402     {
4403       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4404     }
4405   oss << startOfLine << "----------------------" << std::endl;
4406   if(!_field_per_mesh.empty())
4407     {
4408       int i=0;
4409       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4410         {
4411           const MEDFileFieldPerMesh *cur=(*it2);
4412           if(cur)
4413             cur->simpleRepr(bkOffset,oss,i);
4414           else
4415             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4416         }
4417     }
4418   else
4419     {
4420       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4421     }
4422   oss << startOfLine << "----------------------" << std::endl;
4423 }
4424
4425 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4426 {
4427   const DataArray *arr(getUndergroundDataArray());
4428   if(!arr)
4429     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4430   int nbOfCompo=arr->getNumberOfComponents();
4431   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4432   for(int i=0;i<nbOfCompo;i++)
4433     {
4434       ret[i]=deepCopy();
4435       std::vector<int> v(1,i);
4436       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4437       ret[i]->setArray(arr2);
4438     }
4439   return ret;
4440 }
4441
4442 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order):MEDFileFieldNameScope(fieldName,meshName),_iteration(iteration),_order(order),_csit(csit),_nb_of_tuples_to_be_allocated(-2)
4443 {
4444 }
4445
4446 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4447 {
4448 }
4449
4450 /*!
4451  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4452  * empty. Returns -1 if this in on nodes.
4453  *  \return int - the dimension of \a this.
4454  */
4455 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4456 {
4457   int ret=-2;
4458   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4459     (*it)->getDimension(ret);
4460   return ret;
4461 }
4462
4463 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4464 {
4465   bool ret=false;
4466   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4467     {
4468       MEDFileFieldPerMesh *cur(*it);
4469       if(cur)
4470         ret=cur->changeMeshNames(modifTab) || ret;
4471     }
4472   return ret;
4473 }
4474
4475 /*!
4476  * Returns the number of iteration of the state of underlying mesh.
4477  *  \return int - the iteration number.
4478  *  \throw If \c _field_per_mesh.empty()
4479  */
4480 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4481 {
4482   if(_field_per_mesh.empty())
4483     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4484   return _field_per_mesh[0]->getMeshIteration();
4485 }
4486
4487 /*!
4488  * Returns the order number of iteration of the state of underlying mesh.
4489  *  \return int - the order number.
4490  *  \throw If \c _field_per_mesh.empty()
4491  */
4492 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4493 {
4494   if(_field_per_mesh.empty())
4495     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4496   return _field_per_mesh[0]->getMeshOrder();
4497 }
4498
4499 /*!
4500  * Checks if \a this field is tagged by a given iteration number and a given
4501  * iteration order number.
4502  *  \param [in] iteration - the iteration number of interest.
4503  *  \param [in] order - the iteration order number of interest.
4504  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4505  *          \a this->getOrder() == \a order.
4506  */
4507 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4508 {
4509   return iteration==_iteration && order==_order;
4510 }
4511
4512 /*!
4513  * Returns number of iteration and order number of iteration when
4514  * \a this field has been calculated.
4515  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4516  *          order number.
4517  */
4518 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4519 {
4520   std::pair<int,int> p;
4521   fillIteration(p);
4522   return p;
4523 }
4524
4525 /*!
4526  * Returns number of iteration and order number of iteration when
4527  * \a this field has been calculated.
4528  *  \param [in,out] p - a pair returning the iteration number and the iteration
4529  *          order number.
4530  */
4531 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4532 {
4533   p.first=_iteration;
4534   p.second=_order;
4535 }
4536
4537 /*!
4538  * Returns all types of spatial discretization of \a this field.
4539  *  \param [in,out] types - a sequence of types of \a this field.
4540  */
4541 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4542 {
4543   std::set<TypeOfField> types2;
4544   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4545     {
4546       (*it)->fillTypesOfFieldAvailable(types2);
4547     }
4548   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4549   std::copy(types2.begin(),types2.end(),bi);
4550 }
4551
4552 /*!
4553  * Returns all types of spatial discretization of \a this field.
4554  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4555  *          of \a this field.
4556  */
4557 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4558 {
4559   std::vector<TypeOfField> ret;
4560   fillTypesOfFieldAvailable(ret);
4561   return ret;
4562 }
4563
4564 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4565 {
4566   std::vector<std::string> ret;
4567   std::set<std::string> ret2;
4568   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4569     {
4570       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4571       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4572         if(ret2.find(*it2)==ret2.end())
4573           {
4574             ret.push_back(*it2);
4575             ret2.insert(*it2);
4576           }
4577     }
4578   return ret;
4579 }
4580
4581 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4582 {
4583   std::vector<std::string> ret;
4584   std::set<std::string> ret2;
4585   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4586     {
4587       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4588       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4589         if(ret2.find(*it2)==ret2.end())
4590           {
4591             ret.push_back(*it2);
4592             ret2.insert(*it2);
4593           }
4594     }
4595   return ret;
4596 }
4597
4598 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4599 {
4600   std::vector<std::string> ret;
4601   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4602     {
4603       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4604       ret.insert(ret.end(),tmp.begin(),tmp.end());
4605     }
4606   return ret;
4607 }
4608
4609 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4610 {
4611   std::vector<std::string> ret;
4612   std::set<std::string> ret2;
4613   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4614     {
4615       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4616       ret.insert(ret.end(),tmp.begin(),tmp.end());
4617     }
4618   return ret;
4619 }
4620
4621 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4622 {
4623   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4624     (*it)->changePflsRefsNamesGen(mapOfModif);
4625 }
4626
4627 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4628 {
4629   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4630     (*it)->changeLocsRefsNamesGen(mapOfModif);
4631 }
4632
4633 /*!
4634  * Returns all attributes of parts of \a this field lying on a given mesh.
4635  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4636  * item of every of returned sequences refers to the _i_-th part of \a this field.
4637  * Thus all sequences returned by this method are of the same length equal to number
4638  * of different types of supporting entities.<br>
4639  * A field part can include sub-parts with several different spatial discretizations,
4640  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4641  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4642  * of a nested sequence corresponds to a type of spatial discretization.<br>
4643  * This method allows for iteration over MEDFile DataStructure without any overhead.
4644  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4645  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4646  *          not checked if \a mname == \c NULL).
4647  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4648  *          a field part is returned. 
4649  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4650  *          This sequence is of the same length as \a types. 
4651  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4652  *          discretization. A profile name can be empty.
4653  *          Length of this and of nested sequences is the same as that of \a typesF.
4654  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4655  *          discretization. A localization name can be empty.
4656  *          Length of this and of nested sequences is the same as that of \a typesF.
4657  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4658  *          of ids of tuples within the data array, per each type of spatial
4659  *          discretization within one mesh entity type. 
4660  *          Length of this and of nested sequences is the same as that of \a typesF.
4661  *  \throw If no field is lying on \a mname.
4662  */
4663 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
4664 {
4665   if(_field_per_mesh.empty())
4666     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4667   return _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
4668 }
4669
4670 /*!
4671  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4672  * maximal absolute dimension and values returned via the out parameter \a levs are 
4673  * dimensions relative to the maximal absolute dimension. <br>
4674  * This method is designed for MEDFileField1TS instances that have a discretization
4675  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4676  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4677  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4678  * Only these 3 discretizations will be taken into account here. If \a this is
4679  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4680  * This method is useful to make the link between the dimension of the underlying mesh
4681  * and the levels of \a this, because it is possible that the highest dimension of \a this
4682  * field is not equal to the dimension of the underlying mesh.
4683  * 
4684  * Let's consider the following case:
4685  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4686  * TETRA4, HEXA8, TRI3 and SEG2.
4687  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4688  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4689  *
4690  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4691  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4692  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4693  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4694  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4695  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4696  * For example<br>
4697  * to retrieve the highest level of
4698  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4699  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4700  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4701  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4702  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4703  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4704  *          not checked if \a mname == \c NULL).
4705  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4706  *          absolute one. They are in decreasing order. This sequence is cleared before
4707  *          filling it in.
4708  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4709  *  \throw If no field is lying on \a mname.
4710  */
4711 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4712 {
4713   levs.clear();
4714   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4715   std::vector< std::vector<TypeOfField> > typesF;
4716   std::vector< std::vector<std::string> > pfls, locs;
4717   if(_field_per_mesh.empty())
4718     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels : This is empty !");
4719   _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
4720   if(types.empty())
4721     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4722   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4723   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4724     return -1;
4725   st.erase(INTERP_KERNEL::NORM_ERROR);
4726   std::set<int> ret1;
4727   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4728     {
4729       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4730       ret1.insert((int)cm.getDimension());
4731     }
4732   int ret=*std::max_element(ret1.begin(),ret1.end());
4733   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4734   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4735   return ret;
4736 }
4737
4738 void MEDFileAnyTypeField1TSWithoutSDA::convertMedBallIntoClassic()
4739 {
4740   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it<_field_per_mesh.end();it++)
4741     if((*it).isNotNull())
4742       (*it)->convertMedBallIntoClassic();
4743 }
4744
4745 void MEDFileAnyTypeField1TSWithoutSDA::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
4746 {
4747   if(!pfl)
4748     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : null pfl !");
4749   std::string name(pfl->getName());
4750   pfl->checkAllocated();
4751   if(pfl->getNumberOfComponents()!=1)
4752     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : non mono compo array !");
4753   if(name.empty())
4754     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : empty pfl name !");
4755   if(_field_per_mesh.size()!=1)
4756     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single mesh supported !");
4757   MCAuto<MEDFileFieldPerMesh> fpm(_field_per_mesh[0]);
4758   if(fpm.isNull())
4759     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single not null mesh supported !");
4760   MEDFileFieldPerMeshPerTypePerDisc *disc(fpm->getLeafGivenTypeAndLocId(ct,0));
4761   if(disc->getType()!=tof)
4762     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : error !");
4763   int s(disc->getStart()),e(disc->getEnd()),nt(pfl->getNumberOfTuples());
4764   DataArray *arr(getUndergroundDataArray());
4765   int nt2(arr->getNumberOfTuples()),delta((e-s)-nt);
4766   if(delta<0)
4767     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : internal error !");
4768   MCAuto<DataArray> arr0(arr->selectByTupleIdSafeSlice(0,s,1)),arr1(arr->selectByTupleIdSafeSlice(s,e,1)),arr2(arr->selectByTupleIdSafeSlice(e,nt2,1));
4769   MCAuto<DataArray> arr11(arr1->selectByTupleIdSafe(pfl->begin(),pfl->end()));
4770   MCAuto<DataArray> arrOut(arr->buildNewEmptyInstance());
4771   arrOut->alloc(nt2-delta,arr->getNumberOfComponents());
4772   arrOut->copyStringInfoFrom(*arr);
4773   arrOut->setContigPartOfSelectedValuesSlice(0,arr0,0,s,1);
4774   arrOut->setContigPartOfSelectedValuesSlice(s,arr11,0,nt,1);
4775   arrOut->setContigPartOfSelectedValuesSlice(e-delta,arr2,0,nt2-e,1);
4776   setArray(arrOut);
4777   disc->setEnd(e-delta);
4778   disc->setProfile(name);
4779 }
4780
4781 /*!
4782  * \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.
4783  * \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.
4784  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4785  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4786  */
4787 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4788 {
4789   if(_field_per_mesh.empty())
4790     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
4791   return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
4792 }
4793
4794 /*!
4795  * \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.
4796  * \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.
4797  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4798  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4799  */
4800 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4801 {
4802   if(_field_per_mesh.empty())
4803     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
4804   return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
4805 }
4806
4807 /*!
4808  * \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.
4809  */
4810 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4811 {
4812   if(_field_per_mesh.empty())
4813     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4814   if(mName.empty())
4815     return 0;
4816   std::string mName2(mName);
4817   int ret=0;
4818   std::vector<std::string> msg;
4819   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4820     if(mName2==(*it)->getMeshName())
4821       return ret;
4822     else
4823       msg.push_back((*it)->getMeshName());
4824   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4825   oss << "Possible meshes are : ";
4826   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4827     oss << "\"" << (*it2) << "\" ";
4828   throw INTERP_KERNEL::Exception(oss.str());
4829 }
4830
4831 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4832 {
4833   if(!mesh)
4834     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4835   std::string tmp(mesh->getName());
4836   if(tmp.empty())
4837     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4838   setMeshName(tmp);
4839   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4840   int i=0;
4841   for(;it!=_field_per_mesh.end();it++,i++)
4842     {
4843       if((*it)->getMeshName()==tmp)
4844         return i;
4845     }
4846   int sz=_field_per_mesh.size();
4847   _field_per_mesh.resize(sz+1);
4848   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4849   return sz;
4850 }
4851
4852 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4853                                                                    MEDFileFieldGlobsReal& glob)
4854 {
4855   bool ret=false;
4856   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4857     {
4858       MEDFileFieldPerMesh *fpm(*it);
4859       if(fpm)
4860         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4861     }
4862   return ret;
4863 }
4864
4865 /*!
4866  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4867  * splitting that leads to single spatial discretization of this.
4868  *
4869  * \sa splitMultiDiscrPerGeoTypes
4870  */
4871 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4872 {
4873   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4874   std::vector< std::vector<TypeOfField> > typesF;
4875   std::vector< std::vector<std::string> > pfls,locs;
4876   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4877   std::set<TypeOfField> allEnt;
4878   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4879     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4880       allEnt.insert(*it2);
4881   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4882   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4883   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4884     {
4885       std::vector< std::pair<int,int> > its;
4886       ret[i]=shallowCpy();
4887       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4888       ret[i]->updateData(newLgth,its);
4889     }
4890   return ret;
4891 }
4892
4893 /*!
4894  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4895  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4896  *
4897  * \sa splitDiscretizations
4898  */
4899 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4900 {
4901   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4902   std::vector< std::vector<TypeOfField> > typesF;
4903   std::vector< std::vector<std::string> > pfls,locs;
4904   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4905   std::set<TypeOfField> allEnt;
4906   std::size_t nbOfMDPGT(0),ii(0);
4907   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4908     {
4909       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4910       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4911         allEnt.insert(*it2);
4912     }
4913   if(allEnt.size()!=1)
4914     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4915   if(nbOfMDPGT==0)
4916     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4917   if(nbOfMDPGT==1)
4918     {
4919       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4920       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4921       return ret0;
4922     }
4923   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4924   for(std::size_t i=0;i<nbOfMDPGT;i++)
4925     {
4926       std::vector< std::pair<int,int> > its;
4927       ret[i]=shallowCpy();
4928       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4929       ret[i]->updateData(newLgth,its);
4930     }
4931   return ret;
4932 }
4933
4934 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4935 {
4936   int globalCounter(0);
4937   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4938     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4939   return globalCounter;
4940 }
4941
4942 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4943 {
4944   int globalCounter(0);
4945   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4946     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4947   return globalCounter;
4948 }
4949
4950 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4951 {
4952   if(_nb_of_tuples_to_be_allocated>=0)
4953     {
4954       _nb_of_tuples_to_be_allocated=newLgth;
4955       const DataArray *oldArr(getUndergroundDataArray());
4956       if(oldArr)
4957         {
4958           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4959           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4960           setArray(newArr);
4961           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4962         }
4963       return ;
4964     }
4965   if(_nb_of_tuples_to_be_allocated==-1)
4966     return ;
4967   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4968     {
4969       const DataArray *oldArr(getUndergroundDataArray());
4970       if(!oldArr || !oldArr->isAllocated())
4971         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4972       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4973       newArr->alloc(newLgth,getNumberOfComponents());
4974       if(oldArr)
4975         newArr->copyStringInfoFrom(*oldArr);
4976       int pos=0;
4977       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4978         {
4979           if((*it).second<(*it).first)
4980             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4981           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4982           pos+=(*it).second-(*it).first;
4983         }
4984       setArray(newArr);
4985       return ;
4986     }
4987   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4988 }
4989
4990 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4991 {
4992   if(_field_per_mesh.empty())
4993     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4994   if(_field_per_mesh.size()>1)
4995     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4996   _field_per_mesh[0]->copyOptionsFrom(opts);
4997   _field_per_mesh[0]->writeLL(fid,nasc);
4998 }
4999
5000 /*!
5001  * 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.
5002  * If false is returned the memory allocation is not required.
5003  */
5004 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
5005 {
5006   if(_nb_of_tuples_to_be_allocated>=0)
5007     {
5008       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
5009       _nb_of_tuples_to_be_allocated=-2;
5010       return true;
5011     }
5012   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
5013     return false;
5014   if(_nb_of_tuples_to_be_allocated==-1)
5015     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
5016   if(_nb_of_tuples_to_be_allocated<-3)
5017     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5018   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5019 }
5020
5021 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5022 {
5023   med_int numdt,numit;
5024   med_float dt;
5025   med_int meshnumdt,meshnumit;
5026   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
5027   {
5028     med_bool localMesh;
5029     med_int nmesh;
5030     INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
5031     MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit)); // to check with Adrien for legacy MED files
5032   }
5033   //MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt,&meshnumdt,&meshnumit));
5034   if(_iteration!=numdt || _order!=numit)
5035     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
5036   _field_per_mesh.resize(1);
5037   //
5038   MEDFileMesh *mm(0);
5039   if(ms)
5040     {
5041       mm=ms->getMeshWithName(getMeshName());
5042     }
5043   //
5044   _field_per_mesh[0]=MEDFileFieldPerMesh::NewOnRead(fid,this,0,meshnumdt,meshnumit,nasc,mm,entities);
5045   _nb_of_tuples_to_be_allocated=0;
5046   _field_per_mesh[0]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
5047 }
5048
5049 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
5050 {
5051   allocIfNecessaryTheArrayToReceiveDataFromFile();
5052   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5053     (*it)->loadBigArraysRecursively(fid,nasc);
5054 }
5055
5056 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
5057 {
5058   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
5059     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5060       (*it)->loadBigArraysRecursively(fid,nasc);
5061 }
5062
5063 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5064 {
5065   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
5066   loadBigArraysRecursively(fid,nasc);
5067 }
5068
5069 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
5070 {
5071   DataArray *thisArr(getUndergroundDataArray());
5072   if(thisArr && thisArr->isAllocated())
5073     {
5074       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
5075       thisArr->desallocate();
5076     }
5077 }
5078
5079 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
5080 {
5081   return _mesh_name.capacity()+_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
5082 }
5083
5084 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
5085 {
5086   std::vector<const BigMemoryObject *> ret;
5087   if(getUndergroundDataArray())
5088     ret.push_back(getUndergroundDataArray());
5089   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5090     ret.push_back((const MEDFileFieldPerMesh *)*it);
5091   return ret;
5092 }
5093
5094 /*!
5095  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
5096  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
5097  * "Sort By Type"), if not, an exception is thrown. 
5098  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
5099  *  \param [in] arr - the array of values.
5100  *  \param [in,out] glob - the global data where profiles and localization present in
5101  *          \a field, if any, are added.
5102  *  \throw If the name of \a field is empty.
5103  *  \throw If the data array of \a field is not set.
5104  *  \throw If \a this->_arr is already allocated but has different number of components
5105  *         than \a field.
5106  *  \throw If the underlying mesh of \a field has no name.
5107  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
5108  */
5109 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
5110 {
5111   const MEDCouplingMesh *mesh=field->getMesh();
5112   //
5113   TypeOfField type=field->getTypeOfField();
5114   std::vector<DataArrayInt *> dummy;
5115   if(mesh)
5116     setMeshName(mesh->getName());
5117   int start=copyTinyInfoFrom(field,arr);
5118   int pos=addNewEntryIfNecessary(mesh);
5119   if(type!=ON_NODES)
5120     {
5121       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
5122       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
5123     }
5124   else
5125     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
5126 }
5127
5128 /*!
5129  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
5130  * of a given mesh are used as the support of the given field (a real support is not used). 
5131  * Elements of the given mesh must be sorted suitable for writing to MED file. 
5132  * Order of underlying mesh entities of the given field specified by \a profile parameter
5133  * is not prescribed; this method permutes field values to have them sorted by element
5134  * type as required for writing to MED file. A new profile is added only if no equal
5135  * profile is missing. 
5136  *  \param [in] field - the field to add to \a this. The field double values are ignored.
5137  *  \param [in] arrOfVals - the values of the field \a field used.
5138  *  \param [in] mesh - the supporting mesh of \a field.
5139  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
5140  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
5141  *  \param [in,out] glob - the global data where profiles and localization present in
5142  *          \a field, if any, are added.
5143  *  \throw If either \a field or \a mesh or \a profile has an empty name.
5144  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5145  *  \throw If the data array of \a field is not set.
5146  *  \throw If \a this->_arr is already allocated but has different number of components
5147  *         than \a field.
5148  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5149  *  \sa setFieldNoProfileSBT()
5150  */
5151 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
5152 {
5153   if(!field)
5154     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
5155   if(!arrOfVals || !arrOfVals->isAllocated())
5156     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
5157   TypeOfField type=field->getTypeOfField();
5158   std::vector<DataArrayInt *> idsInPflPerType;
5159   std::vector<DataArrayInt *> idsPerType;
5160   std::vector<int> code,code2;
5161   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5162   if(type!=ON_NODES)
5163     {
5164       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
5165       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
5166       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
5167       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
5168       // start of check
5169       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
5170       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
5171       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5172         {
5173           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5174           throw INTERP_KERNEL::Exception(oss.str());
5175         }
5176       // end of check
5177       int start=copyTinyInfoFrom(field,arrOfVals);
5178       code2=m->getDistributionOfTypes();
5179       //
5180       int pos=addNewEntryIfNecessary(m);
5181       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
5182     }
5183   else
5184     {
5185       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
5186         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
5187       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
5188       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
5189       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
5190       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5191         {
5192           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5193           throw INTERP_KERNEL::Exception(oss.str());
5194         }
5195       int start=copyTinyInfoFrom(field,arrOfVals);
5196       int pos=addNewEntryIfNecessary(m);
5197       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
5198     }
5199 }
5200
5201 /*!
5202  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
5203  */
5204 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
5205 {
5206   if(_nb_of_tuples_to_be_allocated>=0)
5207     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 !");
5208   DataArray *arr(getOrCreateAndGetArray());
5209   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
5210   _nb_of_tuples_to_be_allocated=-3;
5211 }
5212
5213 /*!
5214  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
5215  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
5216  * larger by the size of \a field. Returns an id of the first not filled
5217  * tuple of \a this->_arr.
5218  *  \param [in] field - the field to copy the info on components and the name from.
5219  *  \return int - the id of first not initialized tuple of \a this->_arr.
5220  *  \throw If the name of \a field is empty.
5221  *  \throw If the data array of \a field is not set.
5222  *  \throw If \a this->_arr is already allocated but has different number of components
5223  *         than \a field.
5224  */
5225 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
5226 {
5227   if(!field)
5228     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
5229   std::string name(field->getName());
5230   setName(name.c_str());
5231   if(field->getMesh())
5232     setMeshName(field->getMesh()->getName());
5233   setDtUnit(field->getTimeUnit());
5234   if(name.empty())
5235     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
5236   if(!arr)
5237     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
5238   if(!arr->isAllocated())
5239     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
5240   _dt=field->getTime(_iteration,_order);
5241   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
5242   if(!getOrCreateAndGetArray()->isAllocated())
5243     {
5244       allocNotFromFile(arr->getNumberOfTuples());
5245       return 0;
5246     }
5247   else
5248     {
5249       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
5250       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
5251       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
5252       _nb_of_tuples_to_be_allocated=-3;
5253       return oldNbOfTuples;
5254     }
5255 }
5256
5257 /*!
5258  * Returns number of components in \a this field
5259  *  \return int - the number of components.
5260  */
5261 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
5262 {
5263   return getOrCreateAndGetArray()->getNumberOfComponents();
5264 }
5265
5266 /*!
5267  * Change info on components in \a this.
5268  * \throw If size of \a infos is not equal to the number of components already in \a this.
5269  */
5270 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
5271 {
5272   DataArray *arr=getOrCreateAndGetArray();
5273   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
5274 }
5275
5276 /*!
5277  * Returns info on components of \a this field.
5278  *  \return const std::vector<std::string>& - a sequence of strings each being an
5279  *          information on _i_-th component.
5280  */
5281 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
5282 {
5283   const DataArray *arr=getOrCreateAndGetArray();
5284   return arr->getInfoOnComponents();
5285 }
5286
5287 /*!
5288  * Returns a mutable info on components of \a this field.
5289  *  \return std::vector<std::string>& - a sequence of strings each being an
5290  *          information on _i_-th component.
5291  */
5292 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
5293 {
5294   DataArray *arr=getOrCreateAndGetArray();
5295   return arr->getInfoOnComponents();
5296 }
5297
5298 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
5299 {
5300   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5301     {
5302       const MEDFileFieldPerMesh *fpm(*it);
5303       if(!fpm)
5304         continue;
5305       if(fpm->presenceOfMultiDiscPerGeoType())
5306         return true;
5307     }
5308   return false;
5309 }
5310
5311 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const
5312 {
5313   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5314     if((*it).isNotNull())
5315       if((*it)->presenceOfStructureElements())
5316         return true;
5317   return false;
5318 }
5319
5320 bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const
5321 {
5322   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5323     if((*it).isNotNull())
5324       if(!(*it)->onlyStructureElements())
5325         return false;
5326   return true;
5327 }
5328
5329 void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements()
5330 {
5331   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5332     if((*it).isNotNull())
5333       (*it)->killStructureElements();
5334 }
5335
5336 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements()
5337 {
5338   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5339     if((*it).isNotNull())
5340       (*it)->keepOnlyStructureElements();
5341 }
5342
5343 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyOnSE(const std::string& seName)
5344 {
5345   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5346     if((*it).isNotNull())
5347       (*it)->keepOnlyOnSE(seName);
5348 }
5349
5350 void MEDFileAnyTypeField1TSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
5351 {
5352   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5353     if((*it).isNotNull())
5354       (*it)->getMeshSENames(ps);
5355 }
5356
5357 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5358 {
5359   static const char MSG0[]="MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is too complex to be able to be extracted with  \"field\" method ! Call getFieldOnMeshAtLevel method instead to deal with complexity !";
5360   if(_field_per_mesh.empty())
5361     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
5362   if(_field_per_mesh.size()>1)
5363     throw INTERP_KERNEL::Exception(MSG0);
5364   if(_field_per_mesh[0].isNull())
5365     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
5366   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
5367   std::set<TypeOfField> types;
5368   pm->fillTypesOfFieldAvailable(types);
5369   if(types.size()!=1)
5370     throw INTERP_KERNEL::Exception(MSG0);
5371   TypeOfField type(*types.begin());
5372   int meshDimRelToMax(0);
5373   if(type==ON_NODES)
5374     meshDimRelToMax=0;
5375   else
5376     {
5377       int myDim(std::numeric_limits<int>::max());
5378       bool isUnique(pm->isUniqueLevel(myDim));
5379       if(!isUnique)
5380         throw INTERP_KERNEL::Exception(MSG0);
5381       meshDimRelToMax=myDim-mesh->getMeshDimension();
5382       if(meshDimRelToMax>0)
5383         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
5384     }
5385   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
5386 }
5387
5388 /*!
5389  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5390  *  \param [in] type - a spatial discretization of the new field.
5391  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5392  *  \param [in] mName - a name of the supporting mesh.
5393  *  \param [in] renumPol - specifies how to permute values of the result field according to
5394  *          the optional numbers of cells and nodes, if any. The valid values are
5395  *          - 0 - do not permute.
5396  *          - 1 - permute cells.
5397  *          - 2 - permute nodes.
5398  *          - 3 - permute cells and nodes.
5399  *
5400  *  \param [in] glob - the global data storing profiles and localization.
5401  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5402  *          caller is to delete this field using decrRef() as it is no more needed. 
5403  *  \throw If the MED file is not readable.
5404  *  \throw If there is no mesh named \a mName in the MED file.
5405  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5406  *  \throw If no field of \a this is lying on the mesh \a mName.
5407  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5408  */
5409 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5410 {
5411   MCAuto<MEDFileMesh> mm;
5412   if(mName.empty())
5413     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5414   else
5415     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5416   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5417 }
5418
5419 /*!
5420  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5421  *  \param [in] type - a spatial discretization of the new field.
5422  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5423  *  \param [in] renumPol - specifies how to permute values of the result field according to
5424  *          the optional numbers of cells and nodes, if any. The valid values are
5425  *          - 0 - do not permute.
5426  *          - 1 - permute cells.
5427  *          - 2 - permute nodes.
5428  *          - 3 - permute cells and nodes.
5429  *
5430  *  \param [in] glob - the global data storing profiles and localization.
5431  *  \param [in] mesh - the supporting mesh.
5432  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5433  *          caller is to delete this field using decrRef() as it is no more needed. 
5434  *  \throw If the MED file is not readable.
5435  *  \throw If no field of \a this is lying on \a mesh.
5436  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5437  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5438  */
5439 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5440 {
5441   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
5442   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
5443   if(meshDimRelToMax==1)
5444     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
5445   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
5446 }
5447
5448 /*!
5449  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
5450  * given mesh. 
5451  *  \param [in] type - a spatial discretization of the new field.
5452  *  \param [in] mName - a name of the supporting mesh.
5453  *  \param [in] renumPol - specifies how to permute values of the result field according to
5454  *          the optional numbers of cells and nodes, if any. The valid values are
5455  *          - 0 - do not permute.
5456  *          - 1 - permute cells.
5457  *          - 2 - permute nodes.
5458  *          - 3 - permute cells and nodes.
5459  *
5460  *  \param [in] glob - the global data storing profiles and localization.
5461  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5462  *          caller is to delete this field using decrRef() as it is no more needed. 
5463  *  \throw If the MED file is not readable.
5464  *  \throw If there is no mesh named \a mName in the MED file.
5465  *  \throw If there are no mesh entities in the mesh.
5466  *  \throw If no field values of the given \a type are available.
5467  */
5468 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5469 {
5470   MCAuto<MEDFileMesh> mm;
5471   if(mName.empty())
5472     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5473   else
5474     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5475   int absDim=getDimension();
5476   int meshDimRelToMax=absDim-mm->getMeshDimension();
5477   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5478 }
5479
5480 /*!
5481  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5482  *  \param [in] type - a spatial discretization of the new field.
5483  *  \param [in] renumPol - specifies how to permute values of the result field according to
5484  *          the optional numbers of cells and nodes, if any. The valid values are
5485  *          - 0 - do not permute.
5486  *          - 1 - permute cells.
5487  *          - 2 - permute nodes.
5488  *          - 3 - permute cells and nodes.
5489  *
5490  *  \param [in] glob - the global data storing profiles and localization.
5491  *  \param [in] mesh - the supporting mesh.
5492  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5493  *         field according to \a renumPol.
5494  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5495  *         field according to \a renumPol.
5496  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5497  *          caller is to delete this field using decrRef() as it is no more needed. 
5498  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5499  *  \throw If no field of \a this is lying on \a mesh.
5500  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5501  */
5502 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
5503 {
5504   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5505   bool isPfl=false;
5506   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[0]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5507   switch(renumPol)
5508   {
5509     case 0:
5510       {
5511         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5512         return ret.retn();
5513       }
5514     case 3:
5515     case 1:
5516       {
5517         if(isPfl)
5518           throw INTERP_KERNEL::Exception(msg1);
5519         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5520         if(cellRenum)
5521           {
5522             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5523               {
5524                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5525                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5526                 throw INTERP_KERNEL::Exception(oss.str());
5527               }
5528             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5529             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5530             std::vector<DataArray *> arrOut2(1,arrOut);
5531             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5532             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5533             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5534           }
5535         if(renumPol==1)
5536           return ret.retn();
5537       }
5538     case 2:
5539       {
5540         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5541         if(isPfl)
5542           throw INTERP_KERNEL::Exception(msg1);
5543         if(nodeRenum)
5544           {
5545             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5546               {
5547                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5548                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5549                 throw INTERP_KERNEL::Exception(oss.str());
5550               }
5551             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5552             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5553               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5554             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5555           }
5556         return ret.retn();
5557       }
5558     default:
5559       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5560   }
5561 }
5562
5563 /*!
5564  * Returns values and a profile of the field of a given type lying on a given support.
5565  *  \param [in] type - a spatial discretization of the field.
5566  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5567  *  \param [in] mesh - the supporting mesh.
5568  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5569  *          field of interest lies on. If the field lies on all entities of the given
5570  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5571  *          using decrRef() as it is no more needed.  
5572  *  \param [in] glob - the global data storing profiles and localization.
5573  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5574  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5575  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5576  *  \throw If no field of \a this is lying on \a mesh.
5577  *  \throw If no field values of the given \a type are available.
5578  */
5579 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5580 {
5581   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5582   MCAuto<DataArray> ret=_field_per_mesh[0]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5583   ret->setName(nasc.getName().c_str());
5584   return ret.retn();
5585 }
5586
5587 //= MEDFileField1TSWithoutSDA
5588
5589 /*!
5590  * Throws if a given value is not a valid (non-extended) relative dimension.
5591  *  \param [in] meshDimRelToMax - the relative dimension value.
5592  *  \throw If \a meshDimRelToMax > 0.
5593  */
5594 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5595 {
5596   if(meshDimRelToMax>0)
5597     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5598 }
5599
5600 /*!
5601  * Checks if elements of a given mesh are in the order suitable for writing 
5602  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5603  * vector describing types of elements and their number.
5604  *  \param [in] mesh - the mesh to check.
5605  *  \return std::vector<int> - a vector holding for each element type (1) item of
5606  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5607  *          These values are in full-interlace mode.
5608  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5609  */
5610 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5611 {
5612   if(!mesh)
5613     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5614   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5615   int nbOfTypes=geoTypes.size();
5616   std::vector<int> code(3*nbOfTypes);
5617   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5618   arr1->alloc(nbOfTypes,1);
5619   int *arrPtr=arr1->getPointer();
5620   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5621   for(int i=0;i<nbOfTypes;i++,it++)
5622     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5623   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5624   const int *arrPtr2=arr2->getConstPointer();
5625   int i=0;
5626   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5627     {
5628       int pos=arrPtr2[i];
5629       int nbCells=mesh->getNumberOfCellsWithType(*it);
5630       code[3*pos]=(int)(*it);
5631       code[3*pos+1]=nbCells;
5632       code[3*pos+2]=-1;//no profiles
5633     }
5634   std::vector<const DataArrayInt *> idsPerType;//no profiles
5635   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5636   if(da)
5637     {
5638       da->decrRef();
5639       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5640     }
5641   return code;
5642 }
5643
5644 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5645 {
5646   return new MEDFileField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5647 }
5648
5649 /*!
5650  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5651  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5652  * item of every of returned sequences refers to the _i_-th part of \a this field.
5653  * Thus all sequences returned by this method are of the same length equal to number
5654  * of different types of supporting entities.<br>
5655  * A field part can include sub-parts with several different spatial discretizations,
5656  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5657  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5658  * of a nested sequence corresponds to a type of spatial discretization.<br>
5659  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5660  * The overhead is due to selecting values into new instances of DataArrayDouble.
5661  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5662  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5663  *          not checked if \a mname == \c NULL).
5664  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5665  *          a field part is returned. 
5666  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5667  *          A field part can include sub-parts with several different spatial discretizations,
5668  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5669  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5670  *          This sequence is of the same length as \a types. 
5671  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5672  *          discretization. A profile name can be empty.
5673  *          Length of this and of nested sequences is the same as that of \a typesF.
5674  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5675  *          discretization. A localization name can be empty.
5676  *          Length of this and of nested sequences is the same as that of \a typesF.
5677  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5678  *          per each type of spatial discretization within one mesh entity type.
5679  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5680  *          Length of this and of nested sequences is the same as that of \a typesF.
5681  *  \throw If no field is lying on \a mname.
5682  */
5683 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
5684 {
5685   if(mname.empty())
5686     if(_field_per_mesh.empty())
5687       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5688   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
5689   int nbOfRet=ret0.size();
5690   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5691   for(int i=0;i<nbOfRet;i++)
5692     {
5693       const std::vector< std::pair<int,int> >& p=ret0[i];
5694       int nbOfRet1=p.size();
5695       ret[i].resize(nbOfRet1);
5696       for(int j=0;j<nbOfRet1;j++)
5697         {
5698           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5699           ret[i][j]=tmp;
5700         }
5701     }
5702   return ret;
5703 }
5704
5705 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5706 {
5707   return TYPE_STR;
5708 }
5709
5710 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5711 {
5712   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5713   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5714   ret->deepCpyLeavesFrom(*this);
5715   const DataArrayDouble *arr(_arr);
5716   if(arr)
5717     {
5718       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5719       ret->setArray(arr2);
5720     }
5721   return ret.retn();
5722 }
5723
5724 /*!
5725  * Returns a pointer to the underground DataArrayDouble instance and a
5726  * sequence describing parameters of a support of each part of \a this field. The
5727  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5728  * direct access to the field values. This method is intended for the field lying on one
5729  * mesh only.
5730  *  \param [in,out] entries - the sequence describing parameters of a support of each
5731  *         part of \a this field. Each item of this sequence consists of two parts. The
5732  *         first part describes a type of mesh entity and an id of discretization of a
5733  *         current field part. The second part describes a range of values [begin,end)
5734  *         within the returned array relating to the current field part.
5735  *  \return DataArrayDouble * - the pointer to the field values array.
5736  *  \throw If the number of underlying meshes is not equal to 1.
5737  *  \throw If no field values are available.
5738  *  \sa getUndergroundDataArray()
5739  */
5740 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5741 {
5742   if(_field_per_mesh.size()!=1)
5743     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5744   if(_field_per_mesh[0]==0)
5745     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5746   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5747   return getUndergroundDataArrayTemplate();
5748 }
5749
5750 /*!
5751  * Returns a pointer to the underground DataArrayDouble instance and a
5752  * sequence describing parameters of a support of each part of \a this field. The
5753  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5754  * direct access to the field values. This method is intended for the field lying on one
5755  * mesh only.
5756  *  \param [in,out] entries - the sequence describing parameters of a support of each
5757  *         part of \a this field. Each item of this sequence consists of two parts. The
5758  *         first part describes a type of mesh entity and an id of discretization of a
5759  *         current field part. The second part describes a range of values [begin,end)
5760  *         within the returned array relating to the current field part.
5761  *  \return DataArrayDouble * - the pointer to the field values array.
5762  *  \throw If the number of underlying meshes is not equal to 1.
5763  *  \throw If no field values are available.
5764  *  \sa getUndergroundDataArray()
5765  */
5766 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5767 {
5768   return getUndergroundDataArrayDoubleExt(entries);
5769 }
5770
5771 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,meshName,csit,iteration,order)
5772 {
5773   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5774   arr->setInfoAndChangeNbOfCompo(infos);
5775 }
5776
5777 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5778 {
5779 }
5780
5781 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5782 {
5783   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5784   ret->deepCpyLeavesFrom(*this);
5785   return ret.retn();
5786 }
5787
5788 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5789 {
5790   MCAuto<MEDFileField1TSWithoutSDA> ret(shallowCpy());
5791   if(_arr.isNotNull())
5792     ret->_arr=_arr->deepCopy();
5793   return ret.retn();
5794 }
5795
5796 //= MEDFileIntField1TSWithoutSDA
5797
5798 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5799 {
5800   return new MEDFileIntField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5801 }
5802
5803 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA()
5804 {
5805 }
5806
5807 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
5808                                                            const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,meshName,csit,iteration,order)
5809 {
5810   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5811   arr->setInfoAndChangeNbOfCompo(infos);
5812 }
5813
5814 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5815 {
5816   return TYPE_STR;
5817 }
5818
5819 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5820 {
5821   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5822   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5823   ret->deepCpyLeavesFrom(*this);
5824   if(_arr.isNotNull())
5825     {
5826       MCAuto<DataArrayDouble> arr2(_arr->convertToDblArr());
5827       ret->setArray(arr2);
5828     }
5829   return ret.retn();
5830 }
5831
5832 /*!
5833  * Returns a pointer to the underground DataArrayInt instance and a
5834  * sequence describing parameters of a support of each part of \a this field. The
5835  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5836  * direct access to the field values. This method is intended for the field lying on one
5837  * mesh only.
5838  *  \param [in,out] entries - the sequence describing parameters of a support of each
5839  *         part of \a this field. Each item of this sequence consists of two parts. The
5840  *         first part describes a type of mesh entity and an id of discretization of a
5841  *         current field part. The second part describes a range of values [begin,end)
5842  *         within the returned array relating to the current field part.
5843  *  \return DataArrayInt * - the pointer to the field values array.
5844  *  \throw If the number of underlying meshes is not equal to 1.
5845  *  \throw If no field values are available.
5846  *  \sa getUndergroundDataArray()
5847  */
5848 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5849 {
5850   return getUndergroundDataArrayIntExt(entries);
5851 }
5852
5853 /*!
5854  * Returns a pointer to the underground DataArrayInt instance and a
5855  * sequence describing parameters of a support of each part of \a this field. The
5856  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5857  * direct access to the field values. This method is intended for the field lying on one
5858  * mesh only.
5859  *  \param [in,out] entries - the sequence describing parameters of a support of each
5860  *         part of \a this field. Each item of this sequence consists of two parts. The
5861  *         first part describes a type of mesh entity and an id of discretization of a
5862  *         current field part. The second part describes a range of values [begin,end)
5863  *         within the returned array relating to the current field part.
5864  *  \return DataArrayInt * - the pointer to the field values array.
5865  *  \throw If the number of underlying meshes is not equal to 1.
5866  *  \throw If no field values are available.
5867  *  \sa getUndergroundDataArray()
5868  */
5869 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5870 {
5871   if(_field_per_mesh.size()!=1)
5872     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5873   if(_field_per_mesh[0]==0)
5874     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5875   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5876   return getUndergroundDataArrayTemplate();
5877 }
5878
5879 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5880 {
5881   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5882   ret->deepCpyLeavesFrom(*this);
5883   return ret.retn();
5884 }
5885
5886 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5887 {
5888   MCAuto<MEDFileIntField1TSWithoutSDA> ret(shallowCpy());
5889   if(_arr.isNotNull())
5890     ret->_arr=_arr->deepCopy();
5891   return ret.retn();
5892 }
5893
5894 //= MEDFileFloatField1TSWithoutSDA
5895
5896 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5897 {
5898   return new MEDFileFloatField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5899 }
5900
5901 MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA()
5902 {
5903 }
5904
5905 MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
5906                                                                const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<float>(fieldName,meshName,csit,iteration,order)
5907 {
5908   DataArrayFloat *arr(getOrCreateAndGetArrayTemplate());
5909   arr->setInfoAndChangeNbOfCompo(infos);
5910 }
5911
5912 const char *MEDFileFloatField1TSWithoutSDA::getTypeStr() const
5913 {
5914   return TYPE_STR;
5915 }
5916
5917 MEDFileField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::convertToDouble() const
5918 {
5919   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5920   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5921   ret->deepCpyLeavesFrom(*this);
5922   if(_arr.isNotNull())
5923     {
5924       MCAuto<DataArrayDouble> arr2(_arr->convertToDblArr());
5925       ret->setArray(arr2);
5926     }
5927   return ret.retn();
5928 }
5929
5930 /*!
5931  * Returns a pointer to the underground DataArrayFloat instance and a
5932  * sequence describing parameters of a support of each part of \a this field. The
5933  * caller should not decrRef() the returned DataArrayFloat. This method allows for a
5934  * direct access to the field values. This method is intended for the field lying on one
5935  * mesh only.
5936  *  \param [in,out] entries - the sequence describing parameters of a support of each
5937  *         part of \a this field. Each item of this sequence consists of two parts. The
5938  *         first part describes a type of mesh entity and an id of discretization of a
5939  *         current field part. The second part describes a range of values [begin,end)
5940  *         within the returned array relating to the current field part.
5941  *  \return DataArrayFloat * - the pointer to the field values array.
5942  *  \throw If the number of underlying meshes is not equal to 1.
5943  *  \throw If no field values are available.
5944  *  \sa getUndergroundDataArray()
5945  */
5946 DataArray *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5947 {
5948   return getUndergroundDataArrayFloatExt(entries);
5949 }
5950
5951 /*!
5952  * Returns a pointer to the underground DataArrayFloat instance and a
5953  * sequence describing parameters of a support of each part of \a this field. The
5954  * caller should not decrRef() the returned DataArrayFloat. This method allows for a
5955  * direct access to the field values. This method is intended for the field lying on one
5956  * mesh only.
5957  *  \param [in,out] entries - the sequence describing parameters of a support of each
5958  *         part of \a this field. Each item of this sequence consists of two parts. The
5959  *         first part describes a type of mesh entity and an id of discretization of a
5960  *         current field part. The second part describes a range of values [begin,end)
5961  *         within the returned array relating to the current field part.
5962  *  \return DataArrayFloat * - the pointer to the field values array.
5963  *  \throw If the number of underlying meshes is not equal to 1.
5964  *  \throw If no field values are available.
5965  *  \sa getUndergroundDataArray()
5966  */
5967 DataArrayFloat *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayFloatExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5968 {
5969   if(_field_per_mesh.size()!=1)
5970     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5971   if(_field_per_mesh[0]==0)
5972     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5973   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5974   return getUndergroundDataArrayTemplate();
5975 }
5976
5977 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::shallowCpy() const
5978 {
5979   MCAuto<MEDFileFloatField1TSWithoutSDA> ret(new MEDFileFloatField1TSWithoutSDA(*this));
5980   ret->deepCpyLeavesFrom(*this);
5981   return ret.retn();
5982 }
5983
5984 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::deepCopy() const
5985 {
5986   MCAuto<MEDFileFloatField1TSWithoutSDA> ret(shallowCpy());
5987   if(_arr.isNotNull())
5988     ret->_arr=_arr->deepCopy();
5989   return ret.retn();
5990 }
5991
5992 //= MEDFileAnyTypeField1TS
5993
5994 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5995 {
5996 }
5997
5998 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5999 {
6000   med_field_type typcha;
6001   //
6002   std::vector<std::string> infos;
6003   std::string dtunit,fieldName,meshName;
6004   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
6005   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6006   switch(typcha)
6007   {
6008     case MED_FLOAT64:
6009       {
6010         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6011         break;
6012       }
6013     case MED_INT32:
6014       {
6015         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6016         break;
6017       }
6018     case MED_NODE://6432
6019       {
6020         ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6021         break;
6022       }
6023     default:
6024       {
6025         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
6026         throw INTERP_KERNEL::Exception(oss.str());
6027       }
6028   }
6029   ret->setDtUnit(dtunit.c_str());
6030   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6031   //
6032   med_int numdt,numit;
6033   med_float dt;
6034   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
6035   ret->setTime(numdt,numit,dt);
6036   ret->_csit=1;
6037   if(loadAll)
6038     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6039   else
6040     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6041   return ret.retn();
6042 }
6043
6044 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6045 try:MEDFileFieldGlobsReal(fid)
6046 {
6047   _content=BuildContentFrom(fid,loadAll,ms,entities);
6048   loadGlobals(fid);
6049 }
6050 catch(INTERP_KERNEL::Exception& e)
6051 {
6052     throw e;
6053 }
6054
6055 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6056 {
6057   med_field_type typcha;
6058   std::vector<std::string> infos;
6059   std::string dtunit,meshName;
6060   int nbSteps(0);
6061   {
6062     int iii=-1;
6063     nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName);
6064   }
6065   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6066   switch(typcha)
6067   {
6068     case MED_FLOAT64:
6069       {
6070         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6071         break;
6072       }
6073     case MED_INT32:
6074       {
6075         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6076         break;
6077       }
6078     case MED_NODE://6432
6079       {
6080         ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6081         break;
6082       }
6083     default:
6084       {
6085         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
6086         throw INTERP_KERNEL::Exception(oss.str());
6087       }
6088   }
6089   ret->setMeshName(meshName);
6090   ret->setDtUnit(dtunit.c_str());
6091   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6092   //
6093   if(nbSteps<1)
6094     {
6095       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
6096       throw INTERP_KERNEL::Exception(oss.str());
6097     }
6098   //
6099   med_int numdt,numit;
6100   med_float dt;
6101   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
6102   ret->setTime(numdt,numit,dt);
6103   ret->_csit=1;
6104   if(loadAll)
6105     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6106   else
6107     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6108   return ret.retn();
6109 }
6110
6111 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6112 try:MEDFileFieldGlobsReal(fid)
6113 {
6114   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
6115   loadGlobals(fid);
6116 }
6117 catch(INTERP_KERNEL::Exception& e)
6118 {
6119     throw e;
6120 }
6121
6122 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
6123 {
6124   if(!c)
6125     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
6126   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
6127     {
6128       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6129       ret->_content=c; c->incrRef();
6130       return ret.retn();
6131     }
6132   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
6133     {
6134       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
6135       ret->_content=c; c->incrRef();
6136       return ret.retn();
6137     }
6138   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
6139 }
6140
6141 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
6142 {
6143   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
6144   ret->setFileName(FileNameFromFID(fid));
6145   return ret;
6146 }
6147
6148 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
6149 {
6150   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6151   return New(fid,loadAll);
6152 }
6153
6154 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
6155 {
6156   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0,0));
6157   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6158   ret->loadGlobals(fid);
6159   return ret.retn();
6160 }
6161
6162 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6163 {
6164   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6165   return New(fid,fieldName,loadAll);
6166 }
6167
6168 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6169 {
6170   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
6171   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6172   ret->loadGlobals(fid);
6173   return ret.retn();
6174 }
6175
6176 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6177 {
6178   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6179   return New(fid,fieldName,iteration,order,loadAll);
6180 }
6181
6182 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6183 {
6184   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0,0));
6185   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6186   ret->loadGlobals(fid);
6187   return ret.retn();
6188 }
6189
6190 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
6191 {
6192   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6193   return NewAdv(fid,fieldName,iteration,order,loadAll,entities);
6194 }
6195
6196 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
6197 {
6198   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0,entities));
6199   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6200   ret->loadGlobals(fid);
6201   return ret.retn();
6202 }
6203
6204 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6205 {
6206   med_field_type typcha;
6207   std::vector<std::string> infos;
6208   std::string dtunit,meshName;
6209   int iii(-1);
6210   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName));
6211   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6212   switch(typcha)
6213   {
6214     case MED_FLOAT64:
6215       {
6216         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6217         break;
6218       }
6219     case MED_INT32:
6220       {
6221         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6222         break;
6223       }
6224     default:
6225       {
6226         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName,iteration,order) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
6227         throw INTERP_KERNEL::Exception(oss.str());
6228       }
6229   }
6230   ret->setDtUnit(dtunit.c_str());
6231   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6232   //
6233   bool found=false;
6234   std::vector< std::pair<int,int> > dtits(nbOfStep2);
6235   for(int i=0;i<nbOfStep2 && !found;i++)
6236     {
6237       med_int numdt,numit;
6238       med_float dt;
6239       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
6240       if(numdt==iteration && numit==order)
6241         {
6242           found=true;
6243           ret->_csit=i+1;
6244         }
6245       else
6246         dtits[i]=std::pair<int,int>(numdt,numit);
6247     }
6248   if(!found)
6249     {
6250       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
6251       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
6252         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
6253       throw INTERP_KERNEL::Exception(oss.str());
6254     }
6255   if(loadAll)
6256     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6257   else
6258     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6259   return ret.retn();
6260 }
6261
6262 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6263 try:MEDFileFieldGlobsReal(fid)
6264 {
6265   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms,entities);
6266   loadGlobals(fid);
6267 }
6268 catch(INTERP_KERNEL::Exception& e)
6269 {
6270     throw e;
6271 }
6272
6273 /*!
6274  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6275  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6276  *
6277  * \warning this is a shallow copy constructor
6278  */
6279 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
6280 {
6281   if(!shallowCopyOfContent)
6282     {
6283       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
6284       otherPtr->incrRef();
6285       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
6286     }
6287   else
6288     {
6289       _content=other.shallowCpy();
6290     }
6291 }
6292
6293 int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut, std::string& meshName)
6294 {
6295   if(checkFieldId)
6296     {
6297       int nbFields=MEDnField(fid);
6298       if(fieldIdCFormat>=nbFields)
6299         {
6300           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
6301           throw INTERP_KERNEL::Exception(oss.str());
6302         }
6303     }
6304   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
6305   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
6306   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
6307   INTERP_KERNEL::AutoPtr<char> dtunit(MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE));
6308   INTERP_KERNEL::AutoPtr<char> nomcha(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
6309   INTERP_KERNEL::AutoPtr<char> nomMaa(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
6310   med_bool localMesh;
6311   int nbOfStep;
6312   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
6313   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
6314   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
6315   meshName=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
6316   infos.clear(); infos.resize(ncomp);
6317   for(int j=0;j<ncomp;j++)
6318     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
6319   return nbOfStep;
6320 }
6321
6322 /*!
6323  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
6324  * 
6325  * \param [out]
6326  * \return in case of success the number of time steps available for the field with name \a fieldName.
6327  */
6328 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut, std::string& meshName)
6329 {
6330   int nbFields=MEDnField(fid);
6331   bool found=false;
6332   std::vector<std::string> fns(nbFields);
6333   int nbOfStep2(-1);
6334   for(int i=0;i<nbFields && !found;i++)
6335     {
6336       std::string tmp,tmp2;
6337       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut,tmp2);
6338       fns[i]=tmp;
6339       found=(tmp==fieldName);
6340       if(found)
6341         {
6342           posCFormat=i;
6343           meshName=tmp2;
6344         }
6345     }
6346   if(!found)
6347     {
6348       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
6349       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
6350         oss << "\"" << *it << "\" ";
6351       throw INTERP_KERNEL::Exception(oss.str());
6352     }
6353   return nbOfStep2;
6354 }
6355
6356 /*!
6357  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6358  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6359  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6360  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6361  * to keep a valid instance.
6362  * 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.
6363  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
6364  * 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.
6365  *
6366  * \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.
6367  * \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.
6368  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6369  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6370  * \param [in] newLocName is the new localization name.
6371  * \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.
6372  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
6373  */
6374 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
6375 {
6376   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6377   std::string oldPflName=disc->getProfile();
6378   std::vector<std::string> vv=getPflsReallyUsedMulti();
6379   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
6380   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
6381     {
6382       disc->setProfile(newPflName);
6383       DataArrayInt *pfl=getProfile(oldPflName.c_str());
6384       pfl->setName(newPflName);
6385     }
6386   else
6387     {
6388       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
6389       throw INTERP_KERNEL::Exception(oss.str());
6390     }
6391 }
6392
6393 /*!
6394  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6395  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6396  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6397  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6398  * to keep a valid instance.
6399  * 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.
6400  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
6401  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
6402  * 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.
6403  *
6404  * \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.
6405  * \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.
6406  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6407  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6408  * \param [in] newLocName is the new localization name.
6409  * \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.
6410  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
6411  */
6412 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
6413 {
6414   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6415   std::string oldLocName=disc->getLocalization();
6416   std::vector<std::string> vv=getLocsReallyUsedMulti();
6417   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
6418   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
6419     {
6420       disc->setLocalization(newLocName);
6421       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
6422       loc.setName(newLocName);
6423     }
6424   else
6425     {
6426       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
6427       throw INTERP_KERNEL::Exception(oss.str());
6428     }
6429 }
6430
6431 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
6432 {
6433   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6434   if(!ret)
6435     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
6436   return ret;
6437 }
6438
6439 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
6440 {
6441   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6442   if(!ret)
6443     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
6444   return ret;
6445 }
6446
6447 /*!
6448  * This method alloc the arrays and load potentially huge arrays contained in this field.
6449  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
6450  * This method can be also called to refresh or reinit values from a file.
6451  * 
6452  * \throw If the fileName is not set or points to a non readable MED file.
6453  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6454  */
6455 void MEDFileAnyTypeField1TS::loadArrays()
6456 {
6457   if(getFileName().empty())
6458     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
6459   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6460   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
6461 }
6462
6463 /*!
6464  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
6465  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
6466  * this method does not throw if \a this does not come from file read.
6467  * 
6468  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
6469  */
6470 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
6471 {
6472   if(!getFileName().empty())
6473     {
6474       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6475       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
6476     }
6477 }
6478
6479 /*!
6480  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
6481  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
6482  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
6483  * 
6484  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
6485  */
6486 void MEDFileAnyTypeField1TS::unloadArrays()
6487 {
6488   contentNotNullBase()->unloadArrays();
6489 }
6490
6491 /*!
6492  * 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.
6493  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
6494  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
6495  * 
6496  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6497  */
6498 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
6499 {
6500   if(!getFileName().empty())
6501     contentNotNullBase()->unloadArrays();
6502 }
6503
6504 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
6505 {
6506   int nbComp(getNumberOfComponents());
6507   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6508   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6509   for(int i=0;i<nbComp;i++)
6510     {
6511       std::string info=getInfo()[i];
6512       std::string c,u;
6513       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6514       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
6515       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
6516     }
6517   if(getName().empty())
6518     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
6519   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
6520   writeGlobals(fid,*this);
6521   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
6522 }
6523
6524 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
6525 {
6526   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
6527 }
6528
6529 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
6530 {
6531   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
6532   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
6533   return ret;
6534 }
6535
6536 /*!
6537  * Returns a string describing \a this field. This string is outputted 
6538  * by \c print Python command.
6539  */
6540 std::string MEDFileAnyTypeField1TS::simpleRepr() const
6541 {
6542   std::ostringstream oss;
6543   contentNotNullBase()->simpleRepr(0,oss,-1);
6544   simpleReprGlobs(oss);
6545   return oss.str();
6546 }
6547
6548 /*!
6549  * This method returns all profiles whose name is non empty used.
6550  * \b WARNING If profile is used several times it will be reported \b only \b once.
6551  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
6552  */
6553 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
6554 {
6555   return contentNotNullBase()->getPflsReallyUsed2();
6556 }
6557
6558 /*!
6559  * This method returns all localizations whose name is non empty used.
6560  * \b WARNING If localization is used several times it will be reported \b only \b once.
6561  */
6562 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
6563 {
6564   return contentNotNullBase()->getLocsReallyUsed2();
6565 }
6566
6567 /*!
6568  * This method returns all profiles whose name is non empty used.
6569  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
6570  */
6571 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
6572 {
6573   return contentNotNullBase()->getPflsReallyUsedMulti2();
6574 }
6575
6576 /*!
6577  * This method returns all localizations whose name is non empty used.
6578  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
6579  */
6580 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
6581 {
6582   return contentNotNullBase()->getLocsReallyUsedMulti2();
6583 }
6584
6585 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6586 {
6587   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
6588 }
6589
6590 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6591 {
6592   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
6593 }
6594
6595 int MEDFileAnyTypeField1TS::getDimension() const
6596 {
6597   return contentNotNullBase()->getDimension();
6598 }
6599
6600 int MEDFileAnyTypeField1TS::getIteration() const
6601 {
6602   return contentNotNullBase()->getIteration();
6603 }
6604
6605 int MEDFileAnyTypeField1TS::getOrder() const
6606 {
6607   return contentNotNullBase()->getOrder();
6608 }
6609
6610 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6611 {
6612   return contentNotNullBase()->getTime(iteration,order);
6613 }
6614
6615 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6616 {
6617   contentNotNullBase()->setTime(iteration,order,val);
6618 }
6619
6620 std::string MEDFileAnyTypeField1TS::getName() const
6621 {
6622   return contentNotNullBase()->getName();
6623 }
6624
6625 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6626 {
6627   contentNotNullBase()->setName(name);
6628 }
6629
6630 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6631 {
6632   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6633 }
6634
6635 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6636 {
6637   return contentNotNullBase()->getDtUnit();
6638 }
6639
6640 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6641 {
6642   contentNotNullBase()->setDtUnit(dtUnit);
6643 }
6644
6645 std::string MEDFileAnyTypeField1TS::getMeshName() const
6646 {
6647   return contentNotNullBase()->getMeshName();
6648 }
6649
6650 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6651 {
6652   contentNotNullBase()->setMeshName(newMeshName);
6653 }
6654
6655 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6656 {
6657   return contentNotNullBase()->changeMeshNames(modifTab);
6658 }
6659
6660 int MEDFileAnyTypeField1TS::getMeshIteration() const
6661 {
6662   return contentNotNullBase()->getMeshIteration();
6663 }
6664
6665 int MEDFileAnyTypeField1TS::getMeshOrder() const
6666 {
6667   return contentNotNullBase()->getMeshOrder();
6668 }
6669
6670 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6671 {
6672   return contentNotNullBase()->getNumberOfComponents();
6673 }
6674
6675 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6676 {
6677   return contentNotNullBase()->isDealingTS(iteration,order);
6678 }
6679
6680 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6681 {
6682   return contentNotNullBase()->getDtIt();
6683 }
6684
6685 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6686 {
6687   contentNotNullBase()->fillIteration(p);
6688 }
6689
6690 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6691 {
6692   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6693 }
6694
6695 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6696 {
6697   contentNotNullBase()->setInfo(infos);
6698 }
6699
6700 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6701 {
6702   return contentNotNullBase()->getInfo();
6703 }
6704 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6705 {
6706   return contentNotNullBase()->getInfo();
6707 }
6708
6709 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6710 {
6711   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6712 }
6713
6714 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6715 {
6716   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6717 }
6718
6719 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6720 {
6721   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6722 }
6723
6724 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6725 {
6726   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6727 }
6728
6729 void MEDFileAnyTypeField1TS::convertMedBallIntoClassic()
6730 {
6731   return contentNotNullBase()->convertMedBallIntoClassic();
6732 }
6733
6734 void MEDFileAnyTypeField1TS::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
6735 {
6736   return contentNotNullBase()->makeReduction(ct,tof,pfl);
6737 }
6738
6739 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6740 {
6741   return contentNotNullBase()->getTypesOfFieldAvailable();
6742 }
6743
6744 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,
6745                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6746 {
6747   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6748 }
6749
6750 /*!
6751  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6752  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6753  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6754  */
6755 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6756 {
6757   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6758   if(!content)
6759     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6760   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6761   std::size_t sz(contentsSplit.size());
6762   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6763   for(std::size_t i=0;i<sz;i++)
6764     {
6765       ret[i]=shallowCpy();
6766       ret[i]->_content=contentsSplit[i];
6767     }
6768   return ret;
6769 }
6770
6771 /*!
6772  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6773  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6774  */
6775 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6776 {
6777   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6778   if(!content)
6779     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6780   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6781   std::size_t sz(contentsSplit.size());
6782   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6783   for(std::size_t i=0;i<sz;i++)
6784     {
6785       ret[i]=shallowCpy();
6786       ret[i]->_content=contentsSplit[i];
6787     }
6788   return ret;
6789 }
6790
6791 /*!
6792  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6793  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6794  */
6795 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6796 {
6797   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6798   if(!content)
6799     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6800   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6801   std::size_t sz(contentsSplit.size());
6802   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6803   for(std::size_t i=0;i<sz;i++)
6804     {
6805       ret[i]=shallowCpy();
6806       ret[i]->_content=contentsSplit[i];
6807     }
6808   return ret;
6809 }
6810
6811 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6812 {
6813   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6814   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6815     ret->_content=_content->deepCopy();
6816   ret->deepCpyGlobs(*this);
6817   return ret.retn();
6818 }
6819
6820 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6821 {
6822   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6823 }
6824
6825 //= MEDFileField1TS
6826
6827 /*!
6828  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6829  * following the given input policy.
6830  *
6831  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6832  *                            By default (true) the globals are deeply copied.
6833  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6834  */
6835 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6836 {
6837   MCAuto<MEDFileIntField1TS> ret;
6838   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6839   if(content)
6840     {
6841       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6842       if(!contc)
6843         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6844       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6845       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6846     }
6847   else
6848     ret=MEDFileIntField1TS::New();
6849   if(isDeepCpyGlobs)
6850     ret->deepCpyGlobs(*this);
6851   else
6852     ret->shallowCpyGlobs(*this);
6853   return ret.retn();
6854 }
6855
6856 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6857 {
6858   if(!f)
6859     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6860   if(arr.isNull())
6861     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6862   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6863   if(!arrOutC)
6864     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6865   f->setArray(arrOutC);
6866 }
6867
6868 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6869 {
6870   if(arr.isNull())
6871     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6872   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6873   if(!arrOutC)
6874     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6875   arrOutC->incrRef();
6876   return arrOutC;
6877 }
6878
6879 /*!
6880  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6881  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6882  *
6883  * \return A new object that the caller is responsible to deallocate.
6884  * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
6885  */
6886 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6887 {
6888   if(!mm)
6889     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6890   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6891   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6892   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6893     {
6894       if((*it0)!=ON_NODES)
6895         {
6896           std::vector<int> levs;
6897           getNonEmptyLevels(mm->getName(),levs);
6898           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6899             {
6900               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6901               if(it2!=extractDef.end())
6902                 {
6903                   MCAuto<DataArrayInt> t((*it2).second);
6904                   if(t.isNull())
6905                     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6906                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6907                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6908                   ret->setFieldNoProfileSBT(fOut);
6909                 }
6910             }
6911         }
6912       else
6913         {
6914           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6915           if(it2==extractDef.end())
6916             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6917           MCAuto<DataArrayInt> t((*it2).second);
6918           if(t.isNull())
6919             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6920           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6921           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6922           DataArrayDouble *arr(f->getArray());
6923           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6924           fOut->setArray(newArr);
6925           ret->setFieldNoProfileSBT(fOut);
6926         }
6927     }
6928   return ret.retn();
6929 }
6930
6931 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6932 try:MEDFileTemplateField1TS<double>(fid,loadAll,ms)
6933 {
6934 }
6935 catch(INTERP_KERNEL::Exception& e)
6936 { throw e; }
6937
6938 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6939 try:MEDFileTemplateField1TS<double>(fid,fieldName,loadAll,ms)
6940 {
6941 }
6942 catch(INTERP_KERNEL::Exception& e)
6943 { throw e; }
6944
6945 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6946 try:MEDFileTemplateField1TS<double>(fid,fieldName,iteration,order,loadAll,ms)
6947 {
6948 }
6949 catch(INTERP_KERNEL::Exception& e)
6950 { throw e; }
6951
6952 /*!
6953  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6954  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6955  *
6956  * \warning this is a shallow copy constructor
6957  */
6958 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6959 try:MEDFileTemplateField1TS<double>(other,shallowCopyOfContent)
6960 {
6961 }
6962 catch(INTERP_KERNEL::Exception& e)
6963 { throw e; }
6964
6965 /*!
6966  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
6967  * method should be called (getFieldOnMeshAtLevel for example).
6968  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6969  *
6970  * \param [in] mesh - the mesh the field is lying on
6971  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6972  *          caller is to delete this field using decrRef() as it is no more needed. 
6973  */
6974 MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
6975 {
6976   MCAuto<DataArray> arrOut;
6977   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6978   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6979   return ret.retn();
6980 }
6981
6982 /*!
6983  * Returns a new MEDCouplingFieldDouble of a given type lying on
6984  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6985  * has not been constructed via file reading, an exception is thrown.
6986  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6987  *  \param [in] type - a spatial discretization of interest.
6988  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6989  *  \param [in] renumPol - specifies how to permute values of the result field according to
6990  *          the optional numbers of cells and nodes, if any. The valid values are
6991  *          - 0 - do not permute.
6992  *          - 1 - permute cells.
6993  *          - 2 - permute nodes.
6994  *          - 3 - permute cells and nodes.
6995  *
6996  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6997  *          caller is to delete this field using decrRef() as it is no more needed. 
6998  *  \throw If \a this field has not been constructed via file reading.
6999  *  \throw If the MED file is not readable.
7000  *  \throw If there is no mesh in the MED file.
7001  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7002  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7003  *  \sa getFieldOnMeshAtLevel()
7004  */
7005 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
7006 {
7007   if(getFileName().empty())
7008     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7009   MCAuto<DataArray> arrOut;
7010   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
7011   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7012   return ret.retn();
7013 }
7014
7015 /*!
7016  * Returns a new MEDCouplingFieldDouble of a given type lying on
7017  * the top level cells of the first mesh in MED file. If \a this field 
7018  * has not been constructed via file reading, an exception is thrown.
7019  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7020  *  \param [in] type - a spatial discretization of interest.
7021  *  \param [in] renumPol - specifies how to permute values of the result field according to
7022  *          the optional numbers of cells and nodes, if any. The valid values are
7023  *          - 0 - do not permute.
7024  *          - 1 - permute cells.
7025  *          - 2 - permute nodes.
7026  *          - 3 - permute cells and nodes.
7027  *
7028  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7029  *          caller is to delete this field using decrRef() as it is no more needed. 
7030  *  \throw If \a this field has not been constructed via file reading.
7031  *  \throw If the MED file is not readable.
7032  *  \throw If there is no mesh in the MED file.
7033  *  \throw If no field values of the given \a type.
7034  *  \throw If no field values lying on the top level support.
7035  *  \sa getFieldAtLevel()
7036  */
7037 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7038 {
7039   if(getFileName().empty())
7040     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7041   MCAuto<DataArray> arrOut;
7042   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7043   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7044   return ret.retn();
7045 }
7046
7047 /*!
7048  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
7049  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7050  *  \param [in] type - a spatial discretization of the new field.
7051  *  \param [in] mesh - the supporting mesh.
7052  *  \param [in] renumPol - specifies how to permute values of the result field according to
7053  *          the optional numbers of cells and nodes, if any. The valid values are
7054  *          - 0 - do not permute.
7055  *          - 1 - permute cells.
7056  *          - 2 - permute nodes.
7057  *          - 3 - permute cells and nodes.
7058  *
7059  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7060  *          caller is to delete this field using decrRef() as it is no more needed. 
7061  *  \throw If no field of \a this is lying on \a mesh.
7062  *  \throw If the mesh is empty.
7063  *  \throw If no field values of the given \a type are available.
7064  *  \sa getFieldAtLevel()
7065  *  \sa getFieldOnMeshAtLevel() 
7066  */
7067 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7068 {
7069   MCAuto<DataArray> arrOut;
7070   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7071   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7072   return ret.retn();
7073 }
7074
7075 /*!
7076  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7077  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7078  *  \param [in] type - a spatial discretization of interest.
7079  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7080  *  \param [in] mesh - the supporting mesh.
7081  *  \param [in] renumPol - specifies how to permute values of the result field according to
7082  *          the optional numbers of cells and nodes, if any. The valid values are
7083  *          - 0 - do not permute.
7084  *          - 1 - permute cells.
7085  *          - 2 - permute nodes.
7086  *          - 3 - permute cells and nodes.
7087  *
7088  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7089  *          caller is to delete this field using decrRef() as it is no more needed. 
7090  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7091  *  \throw If no field of \a this is lying on \a mesh.
7092  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7093  *  \sa getFieldAtLevel()
7094  *  \sa getFieldOnMeshAtLevel() 
7095  */
7096 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7097 {
7098   MCAuto<DataArray> arrOut;
7099   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7100   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7101   return ret.retn();
7102 }
7103
7104 /*!
7105  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7106  * This method is called "Old" because in MED3 norm a field has only one meshName
7107  * attached, so this method is for readers of MED2 files. If \a this field 
7108  * has not been constructed via file reading, an exception is thrown.
7109  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7110  *  \param [in] type - a spatial discretization of interest.
7111  *  \param [in] mName - a name of the supporting mesh.
7112  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7113  *  \param [in] renumPol - specifies how to permute values of the result field according to
7114  *          the optional numbers of cells and nodes, if any. The valid values are
7115  *          - 0 - do not permute.
7116  *          - 1 - permute cells.
7117  *          - 2 - permute nodes.
7118  *          - 3 - permute cells and nodes.
7119  *
7120  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7121  *          caller is to delete this field using decrRef() as it is no more needed. 
7122  *  \throw If the MED file is not readable.
7123  *  \throw If there is no mesh named \a mName in the MED file.
7124  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7125  *  \throw If \a this field has not been constructed via file reading.
7126  *  \throw If no field of \a this is lying on the mesh named \a mName.
7127  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7128  *  \sa getFieldAtLevel()
7129  */
7130 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7131 {
7132   if(getFileName().empty())
7133     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7134   MCAuto<DataArray> arrOut;
7135   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
7136   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7137   return ret.retn();
7138 }
7139
7140 /*!
7141  * Returns values and a profile of the field of a given type lying on a given support.
7142  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7143  *  \param [in] type - a spatial discretization of the field.
7144  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7145  *  \param [in] mesh - the supporting mesh.
7146  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7147  *          field of interest lies on. If the field lies on all entities of the given
7148  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7149  *          using decrRef() as it is no more needed.  
7150  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
7151  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7152  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7153  *  \throw If no field of \a this is lying on \a mesh.
7154  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7155  */
7156 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7157 {
7158   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7159   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
7160 }
7161
7162 /*!
7163  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
7164  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
7165  * "Sort By Type"), if not, an exception is thrown. 
7166  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7167  *  \param [in] field - the field to add to \a this.
7168  *  \throw If the name of \a field is empty.
7169  *  \throw If the data array of \a field is not set.
7170  *  \throw If the data array is already allocated but has different number of components
7171  *         than \a field.
7172  *  \throw If the underlying mesh of \a field has no name.
7173  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
7174  */
7175 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
7176 {
7177   setFileName("");
7178   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
7179 }
7180
7181 /*!
7182  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
7183  * can be an aggregation of several MEDCouplingFieldDouble instances.
7184  * The mesh support of input parameter \a field is ignored here, it can be NULL.
7185  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
7186  * and \a profile.
7187  *
7188  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
7189  * A new profile is added only if no equal profile is missing.
7190  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7191  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
7192  *  \param [in] mesh - the supporting mesh of \a field.
7193  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
7194  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
7195  *  \throw If either \a field or \a mesh or \a profile has an empty name.
7196  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7197  *  \throw If the data array of \a field is not set.
7198  *  \throw If the data array of \a this is already allocated but has different number of
7199  *         components than \a field.
7200  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7201  *  \sa setFieldNoProfileSBT()
7202  */
7203 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7204 {
7205   setFileName("");
7206   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7207 }
7208
7209 MEDFileField1TS *MEDFileField1TS::shallowCpy() const
7210 {
7211   return new MEDFileField1TS(*this);
7212 }
7213
7214 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
7215 {
7216   return contentNotNull()->getUndergroundDataArrayTemplate();
7217 }
7218
7219 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7220 {
7221   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
7222 }
7223
7224 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
7225                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
7226 {
7227   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7228 }
7229
7230 //= MEDFileIntField1TS
7231
7232 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
7233 try:MEDFileTemplateField1TS<int>(fid,loadAll,ms)
7234 {
7235 }
7236 catch(INTERP_KERNEL::Exception& e)
7237 { throw e; }
7238
7239 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7240 try:MEDFileTemplateField1TS<int>(fid,fieldName,loadAll,ms)
7241 {
7242 }
7243 catch(INTERP_KERNEL::Exception& e)
7244 { throw e; }
7245
7246 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
7247 try:MEDFileTemplateField1TS<int>(fid,fieldName,iteration,order,loadAll,ms)
7248 {
7249 }
7250 catch(INTERP_KERNEL::Exception& e)
7251 { throw e; }
7252
7253 /*!
7254  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7255  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7256  *
7257  * \warning this is a shallow copy constructor
7258  */
7259 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileTemplateField1TS<int>(other,shallowCopyOfContent)
7260 {
7261 }
7262
7263 MEDFileIntField1TS *MEDFileIntField1TS::shallowCpy() const
7264 {
7265   return new MEDFileIntField1TS(*this);
7266 }
7267
7268 /*!
7269  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
7270  * following the given input policy.
7271  *
7272  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
7273  *                            By default (true) the globals are deeply copied.
7274  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
7275  */
7276 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
7277 {
7278   MCAuto<MEDFileField1TS> ret;
7279   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
7280   if(content)
7281     {
7282       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
7283       if(!contc)
7284         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
7285       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
7286       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
7287     }
7288   else
7289     ret=MEDFileField1TS::New();
7290   if(isDeepCpyGlobs)
7291     ret->deepCpyGlobs(*this);
7292   else
7293     ret->shallowCpyGlobs(*this);
7294   return ret.retn();
7295 }
7296
7297 /*!
7298  * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
7299  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
7300  * "Sort By Type"), if not, an exception is thrown. 
7301  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7302  *  \param [in] field - the field to add to \a this.
7303  *  \throw If the name of \a field is empty.
7304  *  \throw If the data array of \a field is not set.
7305  *  \throw If the data array is already allocated but has different number of components
7306  *         than \a field.
7307  *  \throw If the underlying mesh of \a field has no name.
7308  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
7309  */
7310 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
7311 {
7312   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7313   setFileName("");
7314   contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
7315 }
7316
7317 /*!
7318  * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
7319  * can be an aggregation of several MEDCouplingFieldDouble instances.
7320  * The mesh support of input parameter \a field is ignored here, it can be NULL.
7321  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
7322  * and \a profile.
7323  *
7324  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
7325  * A new profile is added only if no equal profile is missing.
7326  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7327  *  \param [in] field - the field to add to \a this.
7328  *  \param [in] mesh - the supporting mesh of \a field.
7329  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
7330  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
7331  *  \throw If either \a field or \a mesh or \a profile has an empty name.
7332  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7333  *  \throw If the data array of \a field is not set.
7334  *  \throw If the data array of \a this is already allocated but has different number of
7335  *         components than \a field.
7336  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7337  *  \sa setFieldNoProfileSBT()
7338  */
7339 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7340 {
7341   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7342   setFileName("");
7343   contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7344 }
7345
7346 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
7347 {
7348   if(arr.isNull())
7349     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
7350   DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
7351   if(!arrC)
7352     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
7353   arrC->incrRef();
7354   return arrC;
7355 }
7356
7357 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
7358 {
7359   if(getFileName().empty())
7360     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7361   MCAuto<DataArray> arrOut;
7362   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
7363   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7364   return ret2.retn();
7365 }
7366
7367 MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
7368 {
7369   int t1,t2;
7370   double t0(f->getTime(t1,t2));
7371   MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
7372   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7373   MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
7374   ret->setTime(t0,t1,t2); ret->setArray(arr2);
7375   return ret.retn();
7376 }
7377
7378 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
7379 {
7380   if(!f)
7381     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
7382   int t1,t2;
7383   double t0(f->getTime(t1,t2));
7384   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7385   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
7386   ret->setTime(t0,t1,t2);
7387   return ret;
7388 }
7389
7390 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
7391 {
7392   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
7393 }
7394
7395 /*!
7396  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
7397  * method should be called (getFieldOnMeshAtLevel for example).
7398  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
7399  *
7400  * \param [in] mesh - the mesh the field is lying on
7401  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
7402  *          caller is to delete this field using decrRef() as it is no more needed. 
7403  */
7404 MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
7405 {
7406   MCAuto<DataArray> arrOut;
7407   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
7408   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7409   return ret2.retn();
7410 }
7411
7412 /*!
7413  * Returns a new MEDCouplingFieldInt of a given type lying on
7414  * the top level cells of the first mesh in MED file. If \a this field 
7415  * has not been constructed via file reading, an exception is thrown.
7416  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7417  *  \param [in] type - a spatial discretization of interest.
7418  *  \param [in] renumPol - specifies how to permute values of the result field according to
7419  *          the optional numbers of cells and nodes, if any. The valid values are
7420  *          - 0 - do not permute.
7421  *          - 1 - permute cells.
7422  *          - 2 - permute nodes.
7423  *          - 3 - permute cells and nodes.
7424  *
7425  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7426  *          caller is to delete this field using decrRef() as it is no more needed. 
7427  *  \throw If \a this field has not been constructed via file reading.
7428  *  \throw If the MED file is not readable.
7429  *  \throw If there is no mesh in the MED file.
7430  *  \throw If no field values of the given \a type.
7431  *  \throw If no field values lying on the top level support.
7432  *  \sa getFieldAtLevel()
7433  */
7434 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7435 {
7436   if(getFileName().empty())
7437     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7438   MCAuto<DataArray> arrOut;
7439   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7440   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7441   return ret2.retn();
7442 }
7443
7444 /*!
7445  * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
7446  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7447  *  \param [in] type - a spatial discretization of the new field.
7448  *  \param [in] mesh - the supporting mesh.
7449  *  \param [in] renumPol - specifies how to permute values of the result field according to
7450  *          the optional numbers of cells and nodes, if any. The valid values are
7451  *          - 0 - do not permute.
7452  *          - 1 - permute cells.
7453  *          - 2 - permute nodes.
7454  *          - 3 - permute cells and nodes.
7455  *
7456  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7457  *          caller is to delete this field using decrRef() as it is no more needed. 
7458  *  \throw If no field of \a this is lying on \a mesh.
7459  *  \throw If the mesh is empty.
7460  *  \throw If no field values of the given \a type are available.
7461  *  \sa getFieldAtLevel()
7462  *  \sa getFieldOnMeshAtLevel() 
7463  */
7464 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7465 {
7466   MCAuto<DataArray> arrOut;
7467   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7468   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7469   return ret2.retn();
7470 }
7471
7472 /*!
7473  * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
7474  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7475  *  \param [in] type - a spatial discretization of interest.
7476  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7477  *  \param [in] mesh - the supporting mesh.
7478  *  \param [in] renumPol - specifies how to permute values of the result field according to
7479  *          the optional numbers of cells and nodes, if any. The valid values are
7480  *          - 0 - do not permute.
7481  *          - 1 - permute cells.
7482  *          - 2 - permute nodes.
7483  *          - 3 - permute cells and nodes.
7484  *
7485  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7486  *          caller is to delete this field using decrRef() as it is no more needed. 
7487  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7488  *  \throw If no field of \a this is lying on \a mesh.
7489  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7490  *  \sa getFieldAtLevel()
7491  *  \sa getFieldOnMeshAtLevel() 
7492  */
7493 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7494 {
7495   MCAuto<DataArray> arrOut;
7496   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7497   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7498   return ret2.retn();
7499 }
7500
7501 /*!
7502  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7503  * This method is called "Old" because in MED3 norm a field has only one meshName
7504  * attached, so this method is for readers of MED2 files. If \a this field 
7505  * has not been constructed via file reading, an exception is thrown.
7506  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7507  *  \param [in] type - a spatial discretization of interest.
7508  *  \param [in] mName - a name of the supporting mesh.
7509  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7510  *  \param [in] renumPol - specifies how to permute values of the result field according to
7511  *          the optional numbers of cells and nodes, if any. The valid values are
7512  *          - 0 - do not permute.
7513  *          - 1 - permute cells.
7514  *          - 2 - permute nodes.
7515  *          - 3 - permute cells and nodes.
7516  *
7517  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7518  *          caller is to delete this field using decrRef() as it is no more needed. 
7519  *  \throw If the MED file is not readable.
7520  *  \throw If there is no mesh named \a mName in the MED file.
7521  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7522  *  \throw If \a this field has not been constructed via file reading.
7523  *  \throw If no field of \a this is lying on the mesh named \a mName.
7524  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7525  *  \sa getFieldAtLevel()
7526  */
7527 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7528 {
7529   if(getFileName().empty())
7530     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7531   MCAuto<DataArray> arrOut;
7532   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
7533   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7534   return ret2.retn();
7535 }
7536
7537 /*!
7538  * Returns values and a profile of the field of a given type lying on a given support.
7539  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7540  *  \param [in] type - a spatial discretization of the field.
7541  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7542  *  \param [in] mesh - the supporting mesh.
7543  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7544  *          field of interest lies on. If the field lies on all entities of the given
7545  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7546  *          using decrRef() as it is no more needed.  
7547  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7548  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7549  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7550  *  \throw If no field of \a this is lying on \a mesh.
7551  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7552  */
7553 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7554 {
7555   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7556   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7557 }
7558
7559 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7560 {
7561   return contentNotNull()->getUndergroundDataArrayTemplate();
7562 }
7563
7564 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7565
7566 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7567 {
7568 }
7569
7570 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileFieldNameScope(fieldName,meshName)
7571 {
7572 }
7573
7574 /*!
7575  * \param [in] fieldId field id in C mode
7576  */
7577 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7578 {
7579   med_field_type typcha;
7580   std::string dtunitOut,meshName;
7581   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut,meshName));
7582   setMeshName(meshName);
7583   setDtUnit(dtunitOut.c_str());
7584   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7585 }
7586
7587 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7588 try:MEDFileFieldNameScope(fieldName,meshName),_infos(infos)
7589 {
7590   setDtUnit(dtunit.c_str());
7591   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7592 }
7593 catch(INTERP_KERNEL::Exception& e)
7594 {
7595     throw e;
7596 }
7597
7598 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7599 {
7600   std::size_t ret(_mesh_name.capacity()+_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7601   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7602     ret+=(*it).capacity();
7603   return ret;
7604 }
7605
7606 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7607 {
7608   std::vector<const BigMemoryObject *> ret;
7609   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7610     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7611   return ret;
7612 }
7613
7614 /*!
7615  * 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
7616  * NULL.
7617  */
7618 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7619 {
7620   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7621   ret->setInfo(_infos);
7622   int sz=(int)_time_steps.size();
7623   for(const int *id=startIds;id!=endIds;id++)
7624     {
7625       if(*id>=0 && *id<sz)
7626         {
7627           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7628           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7629           if(tse)
7630             {
7631               tse->incrRef();
7632               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7633             }
7634           ret->pushBackTimeStep(tse2);
7635         }
7636       else
7637         {
7638           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7639           oss << " ! Should be in [0," << sz << ") !";
7640           throw INTERP_KERNEL::Exception(oss.str());
7641         }
7642     }
7643   if(ret->getNumberOfTS()>0)
7644     ret->synchronizeNameScope();
7645   ret->copyNameScope(*this);
7646   return ret.retn();
7647 }
7648
7649 /*!
7650  * 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
7651  * NULL.
7652  */
7653 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7654 {
7655   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7656   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7657   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7658   ret->setInfo(_infos);
7659   int sz=(int)_time_steps.size();
7660   int j=bg;
7661   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7662     {
7663       if(j>=0 && j<sz)
7664         {
7665           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7666           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7667           if(tse)
7668             {
7669               tse->incrRef();
7670               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7671             }
7672           ret->pushBackTimeStep(tse2);
7673         }
7674       else
7675         {
7676           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7677           oss << " ! Should be in [0," << sz << ") !";
7678           throw INTERP_KERNEL::Exception(oss.str());
7679         }
7680     }
7681   if(ret->getNumberOfTS()>0)
7682     ret->synchronizeNameScope();
7683   ret->copyNameScope(*this);
7684   return ret.retn();
7685 }
7686
7687 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7688 {
7689   int id=0;
7690   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7691   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7692     {
7693       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7694       if(!cur)
7695         continue;
7696       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7697       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7698         ids->pushBackSilent(id);
7699     }
7700   return buildFromTimeStepIds(ids->begin(),ids->end());
7701 }
7702
7703 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7704 {
7705   int id=0;
7706   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7707   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7708     {
7709       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7710       if(!cur)
7711         continue;
7712       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7713       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7714         ids->pushBackSilent(id);
7715     }
7716   return buildFromTimeStepIds(ids->begin(),ids->end());
7717 }
7718
7719 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
7720 {
7721   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7722     if((*it).isNotNull())
7723       if((*it)->presenceOfStructureElements())
7724         return true;
7725   return false;
7726 }
7727
7728 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
7729 {
7730   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7731     if((*it).isNotNull())
7732       if(!(*it)->onlyStructureElements())
7733         return false;
7734   return true;
7735 }
7736
7737 void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
7738 {
7739   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7740   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7741     if((*it).isNotNull())
7742       {
7743         if((*it)->presenceOfStructureElements())
7744           {
7745             if(!(*it)->onlyStructureElements())
7746               {
7747                 (*it)->killStructureElements();
7748                 ret.push_back(*it);
7749               }
7750           }
7751         else
7752           {
7753             ret.push_back(*it);
7754           }
7755       }
7756   _time_steps=ret;
7757 }
7758
7759 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
7760 {
7761   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7762   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7763     if((*it).isNotNull())
7764       {
7765         if((*it)->presenceOfStructureElements())
7766           {
7767             if(!(*it)->onlyStructureElements())
7768               (*it)->keepOnlyStructureElements();
7769             ret.push_back(*it);
7770           }
7771       }
7772   _time_steps=ret;
7773 }
7774
7775 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName)
7776 {
7777   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7778   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7779     if((*it).isNotNull())
7780       (*it)->keepOnlyOnSE(seName);
7781 }
7782
7783 void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
7784 {
7785   std::vector< std::pair<std::string,std::string> > ps2;
7786   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7787     if((*it).isNotNull())
7788       {
7789         (*it)->getMeshSENames(ps2);
7790         break;
7791       }
7792   if(ps2.empty())
7793     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !");
7794   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7795     if((*it).isNotNull())
7796       {
7797         std::vector< std::pair<std::string,std::string> > ps3;
7798         (*it)->getMeshSENames(ps3);
7799         if(ps2!=ps3)
7800           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !");
7801       }
7802   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=ps2.begin();it!=ps2.end();it++)
7803     {
7804       std::vector< std::pair<std::string,std::string> >::iterator it2(std::find(ps.begin(),ps.end(),*it));
7805       if(it2==ps.end())
7806         ps.push_back(*it);
7807     }
7808 }
7809
7810 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7811 {
7812   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7813     {
7814       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7815       if(!cur)
7816         continue;
7817       if(cur->presenceOfMultiDiscPerGeoType())
7818         return true;
7819     }
7820   return false;
7821 }
7822
7823 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7824 {
7825   return _infos;
7826 }
7827
7828 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7829 {
7830   _infos=info;
7831 }
7832
7833 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7834 {
7835   int ret=0;
7836   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7837     {
7838       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7839       if(pt->isDealingTS(iteration,order))
7840         return ret;
7841     }
7842   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7843   std::vector< std::pair<int,int> > vp=getIterations();
7844   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7845     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7846   throw INTERP_KERNEL::Exception(oss.str());
7847 }
7848
7849 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7850 {
7851   return *_time_steps[getTimeStepPos(iteration,order)];
7852 }
7853
7854 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7855 {
7856   return *_time_steps[getTimeStepPos(iteration,order)];
7857 }
7858
7859 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7860 {
7861   bool ret(false);
7862   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
7863     {
7864       if((*it).first==getMeshName())
7865         {
7866           setMeshName((*it).second);
7867           ret=true;
7868         }
7869     }
7870   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7871     {
7872       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7873       if(cur)
7874         ret=cur->changeMeshNames(modifTab) || ret;
7875     }
7876   return ret;
7877 }
7878
7879 /*!
7880  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7881  */
7882 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7883 {
7884   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7885 }
7886
7887 /*!
7888  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7889  */
7890 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7891 {
7892   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7893 }
7894
7895 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7896                                                                        MEDFileFieldGlobsReal& glob)
7897 {
7898   bool ret=false;
7899   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7900     {
7901       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7902       if(f1ts)
7903         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7904     }
7905   return ret;
7906 }
7907
7908 void MEDFileAnyTypeFieldMultiTSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
7909 {
7910   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7911     if((*it).isNotNull())
7912       {
7913         visitor.newTimeStepEntry(*it);
7914         (*it)->accept(visitor);
7915         visitor.endTimeStepEntry(*it);
7916       }
7917 }
7918
7919 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7920 {
7921   std::string startLine(bkOffset,' ');
7922   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7923   if(fmtsId>=0)
7924     oss << " (" << fmtsId << ")";
7925   oss << " has the following name: \"" << _name << "\"." << std::endl;
7926   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7927   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7928     {
7929       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7930     }
7931   int i=0;
7932   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7933     {
7934       std::string chapter(17,'0'+i);
7935       oss << startLine << chapter << std::endl;
7936       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7937       if(cur)
7938         cur->simpleRepr(bkOffset+2,oss,i);
7939       else
7940         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7941       oss << startLine << chapter << std::endl;
7942     }
7943 }
7944
7945 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7946 {
7947   std::size_t sz=_time_steps.size();
7948   std::vector< std::pair<int,int> > ret(sz);
7949   ret1.resize(sz);
7950   for(std::size_t i=0;i<sz;i++)
7951     {
7952       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7953       if(f1ts)
7954         {
7955           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7956         }
7957       else
7958         {
7959           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7960           throw INTERP_KERNEL::Exception(oss.str());
7961         }
7962     }
7963   return ret;
7964 }
7965
7966 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7967 {
7968   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7969   if(!tse2)
7970     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7971   checkCoherencyOfType(tse2);
7972   if(_time_steps.empty())
7973     {
7974       setName(tse2->getName());
7975       setMeshName(tse2->getMeshName());
7976       setInfo(tse2->getInfo());
7977     }
7978   checkThatComponentsMatch(tse2->getInfo());
7979   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7980     setDtUnit(tse->getDtUnit());
7981   _time_steps.push_back(tse);
7982 }
7983
7984 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7985 {
7986   std::size_t nbOfCompo=_infos.size();
7987   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7988     {
7989       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7990       if(cur)
7991         {
7992           if((cur->getInfo()).size()!=nbOfCompo)
7993             {
7994               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7995               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7996               throw INTERP_KERNEL::Exception(oss.str());
7997             }
7998           cur->copyNameScope(*this);
7999         }
8000     }
8001 }
8002
8003 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8004 {
8005   _time_steps.resize(nbPdt);
8006   for(int i=0;i<nbPdt;i++)
8007     {
8008       std::vector< std::pair<int,int> > ts;
8009       med_int numdt=0,numo=0;
8010       med_float dt=0.0;
8011       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
8012       switch(fieldTyp)
8013       {
8014         case MED_FLOAT64:
8015           {
8016             _time_steps[i]=MEDFileField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
8017             break;
8018           }
8019         case MED_INT32:
8020           {
8021             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
8022             break;
8023           }
8024         default:
8025           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
8026       }
8027       if(loadAll)
8028         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
8029       else
8030         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
8031       synchronizeNameScope();
8032     }
8033 }
8034
8035 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
8036 {
8037   if(_time_steps.empty())
8038     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
8039   checkThatNbOfCompoOfTSMatchThis();
8040   std::vector<std::string> infos(getInfo());
8041   int nbComp=infos.size();
8042   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
8043   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
8044   for(int i=0;i<nbComp;i++)
8045     {
8046       std::string info=infos[i];
8047       std::string c,u;
8048       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
8049       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
8050       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
8051     }
8052   if(_name.empty())
8053     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
8054   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
8055   int nbOfTS=_time_steps.size();
8056   for(int i=0;i<nbOfTS;i++)
8057     _time_steps[i]->writeLL(fid,opts,*this);
8058 }
8059
8060 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
8061 {
8062   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8063     {
8064       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8065       if(elt)
8066         elt->loadBigArraysRecursively(fid,nasc);
8067     }
8068 }
8069
8070 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
8071 {
8072   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8073     {
8074       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8075       if(elt)
8076         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
8077     }
8078 }
8079
8080 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
8081 {
8082   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8083     {
8084       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8085       if(elt)
8086         elt->unloadArrays();
8087     }
8088 }
8089
8090 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
8091 {
8092   return _time_steps.size();
8093 }
8094
8095 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
8096 {
8097   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
8098   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8099     {
8100       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
8101       if(tmp)
8102         newTS.push_back(*it);
8103     }
8104   _time_steps=newTS;
8105 }
8106
8107 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
8108 {
8109   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
8110   int maxId=(int)_time_steps.size();
8111   int ii=0;
8112   std::set<int> idsToDel;
8113   for(const int *id=startIds;id!=endIds;id++,ii++)
8114     {
8115       if(*id>=0 && *id<maxId)
8116         {
8117           idsToDel.insert(*id);
8118         }
8119       else
8120         {
8121           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
8122           throw INTERP_KERNEL::Exception(oss.str());
8123         }
8124     }
8125   for(int iii=0;iii<maxId;iii++)
8126     if(idsToDel.find(iii)==idsToDel.end())
8127       newTS.push_back(_time_steps[iii]);
8128   _time_steps=newTS;
8129 }
8130
8131 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
8132 {
8133   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
8134   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
8135   if(nbOfEntriesToKill==0)
8136     return ;
8137   std::size_t sz=_time_steps.size();
8138   std::vector<bool> b(sz,true);
8139   int j=bg;
8140   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
8141     b[j]=false;
8142   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
8143   for(std::size_t i=0;i<sz;i++)
8144     if(b[i])
8145       newTS.push_back(_time_steps[i]);
8146   _time_steps=newTS;
8147 }
8148
8149 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
8150 {
8151   int ret=0;
8152   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
8153   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
8154     {
8155       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
8156       if(tmp)
8157         {
8158           int it2,ord;
8159           tmp->getTime(it2,ord);
8160           if(it2==iteration && order==ord)
8161             return ret;
8162           else
8163             oss << "(" << it2 << ","  << ord << "), ";
8164         }
8165     }
8166   throw INTERP_KERNEL::Exception(oss.str());
8167 }
8168
8169 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
8170 {
8171   int ret=0;
8172   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
8173   oss.precision(15);
8174   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
8175     {
8176       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
8177       if(tmp)
8178         {
8179           int it2,ord;
8180           double ti=tmp->getTime(it2,ord);
8181           if(fabs(time-ti)<eps)
8182             return ret;
8183           else
8184             oss << ti << ", ";
8185         }
8186     }
8187   throw INTERP_KERNEL::Exception(oss.str());
8188 }
8189
8190 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
8191 {
8192   int lgth=_time_steps.size();
8193   std::vector< std::pair<int,int> > ret(lgth);
8194   for(int i=0;i<lgth;i++)
8195     _time_steps[i]->fillIteration(ret[i]);
8196   return ret;
8197 }
8198
8199 /*!
8200  * 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'
8201  * This method returns two things.
8202  * - The absolute dimension of 'this' in first parameter. 
8203  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
8204  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
8205  *
8206  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
8207  * Only these 3 discretizations will be taken into account here.
8208  *
8209  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
8210  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
8211  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
8212  *
8213  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
8214  * 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'.
8215  * 
8216  * Let's consider the typical following case :
8217  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
8218  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
8219  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
8220  *   TETRA4 and SEG2
8221  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
8222  *
8223  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
8224  * 
8225  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
8226  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
8227  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
8228  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
8229  */
8230 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8231 {
8232   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
8233 }
8234
8235 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
8236 {
8237   if(pos<0 || pos>=(int)_time_steps.size())
8238     {
8239       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
8240       throw INTERP_KERNEL::Exception(oss.str());
8241     }
8242   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
8243   if(item==0)
8244     {
8245       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
8246       oss << "\nTry to use following method eraseEmptyTS !";
8247       throw INTERP_KERNEL::Exception(oss.str());
8248     }
8249   return item;
8250 }
8251
8252 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
8253 {
8254   if(pos<0 || pos>=(int)_time_steps.size())
8255     {
8256       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
8257       throw INTERP_KERNEL::Exception(oss.str());
8258     }
8259   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
8260   if(item==0)
8261     {
8262       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
8263       oss << "\nTry to use following method eraseEmptyTS !";
8264       throw INTERP_KERNEL::Exception(oss.str());
8265     }
8266   return item;
8267 }
8268
8269 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
8270 {
8271   std::vector<std::string> ret;
8272   std::set<std::string> ret2;
8273   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8274     {
8275       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
8276       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8277         if(ret2.find(*it2)==ret2.end())
8278           {
8279             ret.push_back(*it2);
8280             ret2.insert(*it2);
8281           }
8282     }
8283   return ret;
8284 }
8285
8286 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
8287 {
8288   std::vector<std::string> ret;
8289   std::set<std::string> ret2;
8290   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8291     {
8292       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8293       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8294         if(ret2.find(*it2)==ret2.end())
8295           {
8296             ret.push_back(*it2);
8297             ret2.insert(*it2);
8298           }
8299     }
8300   return ret;
8301 }
8302
8303 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
8304 {
8305   std::vector<std::string> ret;
8306   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8307     {
8308       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
8309       ret.insert(ret.end(),tmp.begin(),tmp.end());
8310     }
8311   return ret;
8312 }
8313
8314 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
8315 {
8316   std::vector<std::string> ret;
8317   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8318     {
8319       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
8320       ret.insert(ret.end(),tmp.begin(),tmp.end());
8321     }
8322   return ret;
8323 }
8324
8325 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8326 {
8327   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8328     (*it)->changePflsRefsNamesGen2(mapOfModif);
8329 }
8330
8331 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8332 {
8333   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8334     (*it)->changeLocsRefsNamesGen2(mapOfModif);
8335 }
8336
8337 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
8338 {
8339   int lgth=_time_steps.size();
8340   std::vector< std::vector<TypeOfField> > ret(lgth);
8341   for(int i=0;i<lgth;i++)
8342     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
8343   return ret;
8344 }
8345
8346 /*!
8347  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
8348  */
8349 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
8350 {
8351   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
8352 }
8353
8354 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
8355 {
8356   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
8357   std::size_t i=0;
8358   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8359     {
8360       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
8361         ret->_time_steps[i]=(*it)->deepCopy();
8362     }
8363   return ret.retn();
8364 }
8365
8366 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
8367 {
8368   std::size_t sz(_infos.size()),sz2(_time_steps.size());
8369   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
8370   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
8371   for(std::size_t i=0;i<sz;i++)
8372     {
8373       ret[i]=shallowCpy();
8374       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
8375     }
8376   for(std::size_t i=0;i<sz2;i++)
8377     {
8378       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
8379       if(ret1.size()!=sz)
8380         {
8381           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
8382           throw INTERP_KERNEL::Exception(oss.str());
8383         }
8384       ts[i]=ret1;
8385     }
8386   for(std::size_t i=0;i<sz;i++)
8387     for(std::size_t j=0;j<sz2;j++)
8388       ret[i]->_time_steps[j]=ts[j][i];
8389   return ret;
8390 }
8391
8392 /*!
8393  * This method splits into discretization each time steps in \a this.
8394  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
8395  */
8396 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
8397 {
8398   std::size_t sz(_time_steps.size());
8399   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8400   for(std::size_t i=0;i<sz;i++)
8401     {
8402       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8403       if(!timeStep)
8404         {
8405           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
8406           throw INTERP_KERNEL::Exception(oss.str());
8407         }
8408       items[i]=timeStep->splitDiscretizations();  
8409     }
8410   //
8411   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
8412   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
8413   std::vector< TypeOfField > types;
8414   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8415     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8416       {
8417         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
8418         if(ts.size()!=1)
8419           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
8420         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
8421         if(it2==types.end())
8422           types.push_back(ts[0]);
8423       }
8424   ret.resize(types.size()); ret2.resize(types.size());
8425   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8426     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8427       {
8428         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
8429         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
8430         ret2[pos].push_back(*it1);
8431       }
8432   for(std::size_t i=0;i<types.size();i++)
8433     {
8434       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8435       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
8436         elt->pushBackTimeStep(*it1);//also updates infos in elt
8437       ret[i]=elt;
8438       elt->MEDFileFieldNameScope::operator=(*this);
8439     }
8440   return ret;
8441 }
8442
8443 /*!
8444  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
8445  */
8446 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
8447 {
8448   std::size_t sz(_time_steps.size());
8449   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8450   std::size_t szOut(std::numeric_limits<std::size_t>::max());
8451   for(std::size_t i=0;i<sz;i++)
8452     {
8453       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8454       if(!timeStep)
8455         {
8456           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
8457           throw INTERP_KERNEL::Exception(oss.str());
8458         }
8459       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
8460       if(szOut==std::numeric_limits<std::size_t>::max())
8461         szOut=items[i].size();
8462       else
8463         if(items[i].size()!=szOut)
8464           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
8465     }
8466   if(szOut==std::numeric_limits<std::size_t>::max())
8467     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
8468   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
8469   for(std::size_t i=0;i<szOut;i++)
8470     {
8471       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8472       for(std::size_t j=0;j<sz;j++)
8473         elt->pushBackTimeStep(items[j][i]);
8474       ret[i]=elt;
8475       elt->MEDFileFieldNameScope::operator=(*this);
8476     }
8477   return ret;
8478 }
8479
8480 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
8481 {
8482   setName(field->getName());
8483   if(field->getMesh())
8484     setMeshName(field->getMesh()->getName());
8485   if(_name.empty())
8486     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
8487   if(!arr)
8488     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
8489   _infos=arr->getInfoOnComponents();
8490 }
8491
8492 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
8493 {
8494   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
8495   if(_name!=field->getName())
8496     {
8497       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
8498       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
8499       throw INTERP_KERNEL::Exception(oss.str());
8500     }
8501   if(!arr)
8502     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
8503   checkThatComponentsMatch(arr->getInfoOnComponents());
8504 }
8505
8506 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
8507 {
8508   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
8509   if(getInfo().size()!=compos.size())
8510     {
8511       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
8512       oss << " number of components of element to append (" << compos.size() << ") !";
8513       throw INTERP_KERNEL::Exception(oss.str());
8514     }
8515   if(_infos!=compos)
8516     {
8517       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
8518       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
8519       oss << " But compo in input fields are : ";
8520       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
8521       oss << " !";
8522       throw INTERP_KERNEL::Exception(oss.str());
8523     }
8524 }
8525
8526 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
8527 {
8528   std::size_t sz=_infos.size();
8529   int j=0;
8530   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
8531     {
8532       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8533       if(elt)
8534         if(elt->getInfo().size()!=sz)
8535           {
8536             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
8537             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
8538             throw INTERP_KERNEL::Exception(oss.str());
8539           }
8540     }
8541 }
8542
8543 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
8544 {
8545   if(!field)
8546     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8547   if(!_time_steps.empty())
8548     checkCoherencyOfTinyInfo(field,arr);
8549   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8550   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8551   objC->setFieldNoProfileSBT(field,arr,glob,*this);
8552   copyTinyInfoFrom(field,arr);
8553   _time_steps.push_back(obj);
8554 }
8555
8556 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
8557 {
8558   if(!field)
8559     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8560   if(!_time_steps.empty())
8561     checkCoherencyOfTinyInfo(field,arr);
8562   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8563   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8564   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
8565   copyTinyInfoFrom(field,arr);
8566   setMeshName(objC->getMeshName());
8567   _time_steps.push_back(obj);
8568 }
8569
8570 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8571 {
8572   int sz=(int)_time_steps.size();
8573   if(i<0 || i>=sz)
8574     {
8575       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8576       throw INTERP_KERNEL::Exception(oss.str());
8577     }
8578   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8579   if(tsPtr)
8580     {
8581       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8582         {
8583           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8584           throw INTERP_KERNEL::Exception(oss.str());
8585         }
8586     }
8587   _time_steps[i]=ts;
8588 }
8589
8590 //= MEDFileFieldMultiTSWithoutSDA
8591
8592 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8593 {
8594   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8595 }
8596
8597 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
8598 {
8599 }
8600
8601 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName,meshName)
8602 {
8603 }
8604
8605 /*!
8606  * \param [in] fieldId field id in C mode
8607  */
8608 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8609 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8610 {
8611 }
8612 catch(INTERP_KERNEL::Exception& e)
8613 { throw e; }
8614
8615 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8616 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8617 {
8618 }
8619 catch(INTERP_KERNEL::Exception& e)
8620 { throw e; }
8621
8622 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8623 {
8624   return new MEDFileField1TSWithoutSDA;
8625 }
8626
8627 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8628 {
8629   if(!f1ts)
8630     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8631   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8632   if(!f1tsC)
8633     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8634 }
8635
8636 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8637 {
8638   return MEDFileField1TSWithoutSDA::TYPE_STR;
8639 }
8640
8641 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8642 {
8643   return new MEDFileFieldMultiTSWithoutSDA(*this);
8644 }
8645
8646 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8647 {
8648   return new MEDFileFieldMultiTSWithoutSDA;
8649 }
8650
8651 /*!
8652  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8653  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8654  */
8655 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
8656 {
8657   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8658   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8659   if(!myF1TSC)
8660     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8661   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8662 }
8663
8664 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8665 {
8666   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8667   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8668   int i=0;
8669   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8670     {
8671       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8672       if(eltToConv)
8673         {
8674           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8675           if(!eltToConvC)
8676             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8677           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8678           ret->setIteration(i,elt);
8679         }
8680     }
8681   return ret.retn();
8682 }
8683
8684 //= MEDFileAnyTypeFieldMultiTS
8685
8686 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8687 {
8688 }
8689
8690 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8691 try:MEDFileFieldGlobsReal(fid)
8692 {
8693   _content=BuildContentFrom(fid,loadAll,ms);
8694   loadGlobals(fid);
8695 }
8696 catch(INTERP_KERNEL::Exception& e)
8697 {
8698     throw e;
8699 }
8700
8701 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8702 {
8703   med_field_type typcha;
8704   std::vector<std::string> infos;
8705   std::string dtunit;
8706   std::string meshName;
8707   int i(-1);
8708   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit,meshName);
8709   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8710   switch(typcha)
8711   {
8712     case MED_FLOAT64:
8713       {
8714         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8715         break;
8716       }
8717     case MED_INT32:
8718       {
8719         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8720         break;
8721       }
8722     default:
8723       {
8724         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
8725         throw INTERP_KERNEL::Exception(oss.str());
8726       }
8727   }
8728   ret->setMeshName(meshName);
8729   ret->setDtUnit(dtunit.c_str());
8730   return ret.retn();
8731 }
8732
8733 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8734 {
8735   med_field_type typcha;
8736   //
8737   std::vector<std::string> infos;
8738   std::string dtunit,fieldName,meshName;
8739   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
8740   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8741   switch(typcha)
8742   {
8743     case MED_FLOAT64:
8744       {
8745         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8746         break;
8747       }
8748     case MED_INT32:
8749       {
8750         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8751         break;
8752       }
8753     default:
8754       {
8755         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
8756         throw INTERP_KERNEL::Exception(oss.str());
8757       }
8758   }
8759   ret->setMeshName(meshName);
8760   ret->setDtUnit(dtunit.c_str());
8761   return ret.retn();
8762 }
8763
8764 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8765 {
8766   if(!c)
8767     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8768   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8769     {
8770       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8771       ret->_content=c;  c->incrRef();
8772       return ret.retn();
8773     }
8774   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8775     {
8776       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8777       ret->_content=c;  c->incrRef();
8778       return ret.retn();
8779     }
8780   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8781 }
8782
8783 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8784 {
8785   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8786   std::string fileName(FileNameFromFID(fid));
8787   ret->setFileName(fileName);
8788   return ret;
8789 }
8790
8791 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8792 try:MEDFileFieldGlobsReal(fid)
8793 {
8794   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8795   loadGlobals(fid);
8796 }
8797 catch(INTERP_KERNEL::Exception& e)
8798 {
8799     throw e;
8800 }
8801
8802 //= MEDFileIntFieldMultiTSWithoutSDA
8803
8804 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8805 {
8806   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8807 }
8808
8809 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8810 {
8811 }
8812
8813 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName,meshName)
8814 {
8815 }
8816
8817 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8818 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8819 {
8820 }
8821 catch(INTERP_KERNEL::Exception& e)
8822 { throw e; }
8823
8824 /*!
8825  * \param [in] fieldId field id in C mode
8826  */
8827 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8828 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8829 {
8830 }
8831 catch(INTERP_KERNEL::Exception& e)
8832 { throw e; }
8833
8834 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8835 {
8836   return new MEDFileIntField1TSWithoutSDA;
8837 }
8838
8839 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8840 {
8841   if(!f1ts)
8842     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8843   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8844   if(!f1tsC)
8845     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8846 }
8847
8848 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8849 {
8850   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8851 }
8852
8853 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8854 {
8855   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8856 }
8857
8858 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8859 {
8860   return new MEDFileIntFieldMultiTSWithoutSDA;
8861 }
8862
8863 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8864 {
8865   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8866   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8867   int i=0;
8868   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8869     {
8870       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8871       if(eltToConv)
8872         {
8873           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8874           if(!eltToConvC)
8875             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8876           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8877           ret->setIteration(i,elt);
8878         }
8879     }
8880   return ret.retn();
8881 }
8882
8883 //= MEDFileAnyTypeFieldMultiTS
8884
8885 /*!
8886  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8887  * that has been read from a specified MED file.
8888  *  \param [in] fileName - the name of the MED file to read.
8889  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8890  *          is to delete this field using decrRef() as it is no more needed.
8891  *  \throw If reading the file fails.
8892  */
8893 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8894 {
8895   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8896   return New(fid,loadAll);
8897 }
8898
8899 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8900 {
8901   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8902   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8903   ret->loadGlobals(fid);
8904   return ret.retn();
8905 }
8906
8907 /*!
8908  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8909  * that has been read from a specified MED file.
8910  *  \param [in] fileName - the name of the MED file to read.
8911  *  \param [in] fieldName - the name of the field to read.
8912  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8913  *          is to delete this field using decrRef() as it is no more needed.
8914  *  \throw If reading the file fails.
8915  *  \throw If there is no field named \a fieldName in the file.
8916  */
8917 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8918 {
8919   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8920   return New(fid,fieldName,loadAll);
8921 }
8922
8923 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8924 {
8925   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8926   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8927   ret->loadGlobals(fid);
8928   return ret.retn();
8929 }
8930
8931 /*!
8932  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8933  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8934  *
8935  * \warning this is a shallow copy constructor
8936  */
8937 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8938 {
8939   if(!shallowCopyOfContent)
8940     {
8941       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8942       otherPtr->incrRef();
8943       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8944     }
8945   else
8946     {
8947       _content=other.shallowCpy();
8948     }
8949 }
8950
8951 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8952 {
8953   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8954   if(!ret)
8955     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8956   return ret;
8957 }
8958
8959 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8960 {
8961   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8962   if(!ret)
8963     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8964   return ret;
8965 }
8966
8967 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8968 {
8969   return contentNotNullBase()->getPflsReallyUsed2();
8970 }
8971
8972 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8973 {
8974   return contentNotNullBase()->getLocsReallyUsed2();
8975 }
8976
8977 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8978 {
8979   return contentNotNullBase()->getPflsReallyUsedMulti2();
8980 }
8981
8982 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8983 {
8984   return contentNotNullBase()->getLocsReallyUsedMulti2();
8985 }
8986
8987 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8988 {
8989   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8990 }
8991
8992 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8993 {
8994   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8995 }
8996
8997 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8998 {
8999   return contentNotNullBase()->getNumberOfTS();
9000 }
9001
9002 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
9003 {
9004   contentNotNullBase()->eraseEmptyTS();
9005 }
9006
9007 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
9008 {
9009   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
9010 }
9011
9012 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
9013 {
9014   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
9015 }
9016
9017 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
9018 {
9019   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
9020   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9021   ret->_content=c;
9022   return ret.retn();
9023 }
9024
9025 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
9026 {
9027   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
9028   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9029   ret->_content=c;
9030   return ret.retn();
9031 }
9032
9033 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
9034 {
9035   return contentNotNullBase()->getIterations();
9036 }
9037
9038 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
9039 {
9040   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
9041     pushBackTimeStep(*it);
9042 }
9043
9044 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
9045 {
9046   if(!fmts)
9047     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
9048   int nbOfTS(fmts->getNumberOfTS());
9049   for(int i=0;i<nbOfTS;i++)
9050     {
9051       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
9052       pushBackTimeStep(elt);
9053     }
9054 }
9055
9056 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
9057 {
9058   if(!f1ts)
9059     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
9060   checkCoherencyOfType(f1ts);
9061   f1ts->incrRef();
9062   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
9063   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
9064   c->incrRef();
9065   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
9066   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
9067     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
9068   _content->pushBackTimeStep(cSafe);
9069   appendGlobs(*f1ts,1e-12);
9070 }
9071
9072 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
9073 {
9074   contentNotNullBase()->synchronizeNameScope();
9075 }
9076
9077 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
9078 {
9079   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
9080 }
9081
9082 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
9083 {
9084   return contentNotNullBase()->getPosGivenTime(time,eps);
9085 }
9086
9087 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
9088 {
9089   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
9090 }
9091
9092 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
9093 {
9094   return contentNotNullBase()->getTypesOfFieldAvailable();
9095 }
9096
9097 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
9098 {
9099   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
9100 }
9101
9102 std::string MEDFileAnyTypeFieldMultiTS::getName() const
9103 {
9104   return contentNotNullBase()->getName();
9105 }
9106
9107 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
9108 {
9109   contentNotNullBase()->setName(name);
9110 }
9111
9112 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
9113 {
9114   return contentNotNullBase()->getDtUnit();
9115 }
9116
9117 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
9118 {
9119   contentNotNullBase()->setDtUnit(dtUnit);
9120 }
9121
9122 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
9123 {
9124   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
9125 }
9126
9127 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
9128 {
9129   return contentNotNullBase()->getTimeSteps(ret1);
9130 }
9131
9132 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
9133 {
9134   return contentNotNullBase()->getMeshName();
9135 }
9136
9137 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
9138 {
9139   contentNotNullBase()->setMeshName(newMeshName);
9140 }
9141
9142 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9143 {
9144   return contentNotNullBase()->changeMeshNames(modifTab);
9145 }
9146
9147 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
9148 {
9149   return contentNotNullBase()->getInfo();
9150 }
9151
9152 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
9153 {
9154   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
9155 }
9156
9157 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
9158 {
9159   return contentNotNullBase()->setInfo(info);
9160 }
9161
9162 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
9163 {
9164   const std::vector<std::string> ret=getInfo();
9165   return (int)ret.size();
9166 }
9167
9168 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
9169 {
9170   writeGlobals(fid,*this);
9171   contentNotNullBase()->writeLL(fid,*this);
9172 }
9173
9174 /*!
9175  * This method alloc the arrays and load potentially huge arrays contained in this field.
9176  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9177  * This method can be also called to refresh or reinit values from a file.
9178  * 
9179  * \throw If the fileName is not set or points to a non readable MED file.
9180  */
9181 void MEDFileAnyTypeFieldMultiTS::loadArrays()
9182 {
9183   if(getFileName().empty())
9184     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
9185   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9186   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
9187 }
9188
9189 /*!
9190  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9191  * But once data loaded once, this method does nothing.
9192  * 
9193  * \throw If the fileName is not set or points to a non readable MED file.
9194  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
9195  */
9196 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
9197 {
9198   if(!getFileName().empty())
9199     {
9200       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9201       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
9202     }
9203 }
9204
9205 /*!
9206  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9207  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9208  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
9209  * 
9210  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
9211  */
9212 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
9213 {
9214   contentNotNullBase()->unloadArrays();
9215 }
9216
9217 /*!
9218  * 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.
9219  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
9220  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9221  * 
9222  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
9223  */
9224 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
9225 {
9226   if(!getFileName().empty())
9227     contentNotNullBase()->unloadArrays();
9228 }
9229
9230 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
9231 {
9232   std::ostringstream oss;
9233   contentNotNullBase()->simpleRepr(0,oss,-1);
9234   simpleReprGlobs(oss);
9235   return oss.str();
9236 }
9237
9238 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
9239 {
9240   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
9241 }
9242
9243 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
9244 {
9245   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
9246   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
9247   return ret;
9248 }
9249
9250 /*!
9251  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
9252  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
9253  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
9254  */
9255 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
9256 {
9257   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9258   if(!content)
9259     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
9260   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
9261   std::size_t sz(contentsSplit.size());
9262   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9263   for(std::size_t i=0;i<sz;i++)
9264     {
9265       ret[i]=shallowCpy();
9266       ret[i]->_content=contentsSplit[i];
9267     }
9268   return ret;
9269 }
9270
9271 /*!
9272  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
9273  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9274  */
9275 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
9276 {
9277   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9278   if(!content)
9279     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
9280   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
9281   std::size_t sz(contentsSplit.size());
9282   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9283   for(std::size_t i=0;i<sz;i++)
9284     {
9285       ret[i]=shallowCpy();
9286       ret[i]->_content=contentsSplit[i];
9287     }
9288   return ret;
9289 }
9290
9291 /*!
9292  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
9293  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9294  */
9295 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
9296 {
9297   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9298   if(!content)
9299     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
9300   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
9301   std::size_t sz(contentsSplit.size());
9302   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9303   for(std::size_t i=0;i<sz;i++)
9304     {
9305       ret[i]=shallowCpy();
9306       ret[i]->_content=contentsSplit[i];
9307     }
9308   return ret;
9309 }
9310
9311 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
9312 {
9313   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9314   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
9315     ret->_content=_content->deepCopy();
9316   ret->deepCpyGlobs(*this);
9317   return ret.retn();
9318 }
9319
9320 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
9321 {
9322   return _content;
9323 }
9324
9325 /*!
9326  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9327  *  \param [in] iteration - the iteration number of a required time step.
9328  *  \param [in] order - the iteration order number of required time step.
9329  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
9330  *          delete this field using decrRef() as it is no more needed.
9331  *  \throw If there is no required time step in \a this field.
9332  */
9333 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
9334 {
9335   int pos=getPosOfTimeStep(iteration,order);
9336   return getTimeStepAtPos(pos);
9337 }
9338
9339 /*!
9340  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9341  *  \param [in] time - the time of the time step of interest.
9342  *  \param [in] eps - a precision used to compare time values.
9343  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9344  *          delete this field using decrRef() as it is no more needed.
9345  *  \throw If there is no required time step in \a this field.
9346  */
9347 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
9348 {
9349   int pos=getPosGivenTime(time,eps);
9350   return getTimeStepAtPos(pos);
9351 }
9352
9353 /*!
9354  * 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.
9355  * The float64 value of time attached to the pair of integers are not considered here.
9356  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
9357  *
9358  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
9359  * \throw If there is a null pointer in \a vectFMTS.
9360  */
9361 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
9362 {
9363   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
9364   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9365   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9366   while(!lstFMTS.empty())
9367     {
9368       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9369       MEDFileAnyTypeFieldMultiTS *curIt(*it);
9370       if(!curIt)
9371         throw INTERP_KERNEL::Exception(msg);
9372       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
9373       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9374       elt.push_back(curIt); it=lstFMTS.erase(it);
9375       while(it!=lstFMTS.end())
9376         {
9377           curIt=*it;
9378           if(!curIt)
9379             throw INTERP_KERNEL::Exception(msg);
9380           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
9381           if(refIts==curIts)
9382             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9383           else
9384             it++;
9385         }
9386       ret.push_back(elt);
9387     }
9388   return ret;
9389 }
9390
9391 /*!
9392  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
9393  * All returned instances in a subvector can be safely loaded, rendered along time
9394  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
9395  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
9396  * 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).
9397  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
9398  * 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.
9399  *
9400  * \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().
9401  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
9402  * \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.
9403  * \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.
9404  *
9405  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
9406  * \throw If an element in \a vectFMTS change of spatial discretization along time.
9407  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
9408  * \thorw If some elements in \a vectFMTS do not have the same times steps.
9409  * \throw If mesh is null.
9410  * \throw If an element in \a vectFMTS is null.
9411  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
9412  */
9413 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
9414 {
9415   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
9416   if(!mesh)
9417     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
9418   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9419   if(vectFMTS.empty())
9420     return ret;
9421   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
9422   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
9423   if(!frstElt)
9424     throw INTERP_KERNEL::Exception(msg);
9425   std::size_t i=0;
9426   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
9427   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
9428   for(;it!=vectFMTS.end();it++,i++)
9429     {
9430       if(!(*it))
9431         throw INTERP_KERNEL::Exception(msg);
9432       TypeOfField tof0,tof1;
9433       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
9434         {
9435           if(tof1!=ON_NODES)
9436             vectFMTSNotNodes.push_back(*it);
9437           else
9438             vectFMTSNodes.push_back(*it);
9439         }
9440       else
9441         vectFMTSNotNodes.push_back(*it);
9442     }
9443   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
9444   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
9445   ret=retCell;
9446   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
9447     {
9448       i=0;
9449       bool isFetched(false);
9450       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
9451         {
9452           if((*it0).empty())
9453             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
9454           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
9455             { ret[i].push_back(*it2); isFetched=true; }
9456         }
9457       if(!isFetched)
9458         {
9459           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
9460           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
9461           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
9462         }
9463     }
9464   fsc=cmps;
9465   return ret;
9466 }
9467
9468 /*!
9469  * 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.
9470  * \param [out] cmps - same size than the returned vector.
9471  */
9472 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
9473 {
9474   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9475   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9476   while(!lstFMTS.empty())
9477     {
9478       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9479       MEDFileAnyTypeFieldMultiTS *ref(*it);
9480       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9481       elt.push_back(ref); it=lstFMTS.erase(it);
9482       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
9483       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
9484       while(it!=lstFMTS.end())
9485         {
9486           MEDFileAnyTypeFieldMultiTS *curIt(*it);
9487           if(cmp->isEqual(curIt))
9488             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9489           else
9490             it++;
9491         }
9492       ret.push_back(elt); cmps.push_back(cmp);
9493     }
9494   return ret;
9495 }
9496
9497 /*!
9498  * 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.
9499  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
9500  *
9501  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
9502  * \throw If \a f0 or \a f1 change of spatial discretization along time.
9503  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
9504  * \thorw If \a f0 and \a f1 do not have the same times steps.
9505  * \throw If mesh is null.
9506  * \throw If \a f0 or \a f1 is null.
9507  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
9508  */
9509 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
9510 {
9511   if(!mesh)
9512     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
9513   if(!f0 || !f1)
9514     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
9515   if(f0->getMeshName()!=mesh->getName())
9516     {
9517       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9518       throw INTERP_KERNEL::Exception(oss.str());
9519     }
9520   if(f1->getMeshName()!=mesh->getName())
9521     {
9522       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9523       throw INTERP_KERNEL::Exception(oss.str());
9524     }
9525   int nts=f0->getNumberOfTS();
9526   if(nts!=f1->getNumberOfTS())
9527     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
9528   if(nts==0)
9529     return nts;
9530   for(int i=0;i<nts;i++)
9531     {
9532       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
9533       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
9534       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
9535       if(tofs0.size()!=1 || tofs1.size()!=1)
9536         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
9537       if(i!=0)
9538         {
9539           if(tof0!=tofs0[0] || tof1!=tofs1[0])
9540             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
9541         }
9542       else
9543         { tof0=tofs0[0]; tof1=tofs1[0]; }
9544       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
9545         {
9546           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() << ") !";
9547           throw INTERP_KERNEL::Exception(oss.str());
9548         }
9549       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
9550         {
9551           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() << ") !";
9552           throw INTERP_KERNEL::Exception(oss.str());
9553         }
9554       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
9555         {
9556           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() << ") !";
9557           throw INTERP_KERNEL::Exception(oss.str());
9558         }
9559     }
9560   return nts;
9561 }
9562
9563 /*!
9564  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9565  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9566  *
9567  * \return A new object that the caller is responsible to deallocate.
9568  */
9569 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9570 {
9571   if(!mm)
9572     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9573   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
9574   int nbTS(getNumberOfTS());
9575   for(int i=0;i<nbTS;i++)
9576     {
9577       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
9578       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9579       fmtsOut->pushBackTimeStep(f1tsOut);
9580     }
9581   return fmtsOut.retn();
9582 }
9583
9584 template<class T>
9585 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9586 {
9587   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
9588   if(f1tss.empty())
9589     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
9590   std::size_t sz(f1tss.size()),i(0);
9591   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
9592   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
9593     {
9594       typename MLFieldTraits<T>::F1TSType const *elt(*it);
9595       if(!elt)
9596         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
9597       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
9598     }
9599   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
9600   if(!retc)
9601     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
9602   retc->aggregate(f1tsw,dts);
9603   ret->setDtUnit(f1tss[0]->getDtUnit());
9604   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
9605 }
9606
9607 template<class T>
9608 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9609 {
9610   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
9611   if(fmtss.empty())
9612     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
9613   std::size_t sz(fmtss.size());
9614   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9615     {
9616       typename MLFieldTraits<T>::FMTSType const *elt(*it);
9617       if(!elt)
9618         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
9619     }
9620   int nbTS(fmtss[0]->getNumberOfTS());
9621   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9622     if((*it)->getNumberOfTS()!=nbTS)
9623       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
9624   for(int iterTS=0;iterTS<nbTS;iterTS++)
9625     {
9626       std::size_t i(0);
9627       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
9628       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
9629       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
9630         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
9631       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
9632       ret->pushBackTimeStep(f1ts);
9633       ret->setDtUnit(f1ts->getDtUnit());
9634     }
9635   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
9636 }
9637
9638 /*!
9639  * \a dts and \a ftmss are expected to have same size.
9640  */
9641 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9642 {
9643   if(fmtss.empty())
9644     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
9645   std::size_t sz(fmtss.size());
9646   std::vector<const MEDFileFieldMultiTS *> fmtss1;
9647   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
9648   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9649     {
9650       if(!(*it))
9651         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
9652       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
9653       if(elt1)
9654         {
9655           fmtss1.push_back(elt1);
9656           continue;
9657         }
9658       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
9659       if(elt2)
9660         {
9661           fmtss2.push_back(elt2);
9662           continue;
9663         }
9664       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
9665     }
9666   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
9667     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
9668   if(fmtss1.size()==sz)
9669     return AggregateHelperFMTS<double>(fmtss1,dts);
9670   if(fmtss2.size()!=sz)
9671     return AggregateHelperFMTS<int>(fmtss2,dts);
9672   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9673 }
9674
9675 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9676 {
9677   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9678 }
9679
9680 //= MEDFileFieldMultiTS
9681
9682 /*!
9683  * Returns a new empty instance of MEDFileFieldMultiTS.
9684  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9685  *          is to delete this field using decrRef() as it is no more needed.
9686  */
9687 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9688 {
9689   return new MEDFileFieldMultiTS;
9690 }
9691
9692 /*!
9693  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9694  * that has been read from a specified MED file.
9695  *  \param [in] fileName - the name of the MED file to read.
9696  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9697  *          is to delete this field using decrRef() as it is no more needed.
9698  *  \throw If reading the file fails.
9699  */
9700 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9701 {
9702   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9703   return New(fid,loadAll);
9704 }
9705
9706 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, bool loadAll)
9707 {
9708   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,loadAll,0));
9709   ret->contentNotNull();//to check that content type matches with \a this type.
9710   return ret.retn();
9711 }
9712
9713 /*!
9714  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9715  * that has been read from a specified MED file.
9716  *  \param [in] fileName - the name of the MED file to read.
9717  *  \param [in] fieldName - the name of the field to read.
9718  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9719  *          is to delete this field using decrRef() as it is no more needed.
9720  *  \throw If reading the file fails.
9721  *  \throw If there is no field named \a fieldName in the file.
9722  */
9723 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9724 {
9725   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9726   return New(fid,fieldName,loadAll);
9727 }
9728
9729 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9730 {
9731   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0));
9732   ret->contentNotNull();//to check that content type matches with \a this type.
9733   return ret.retn();
9734 }
9735
9736 /*!
9737  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9738  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9739  *
9740  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9741  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9742  * \warning this is a shallow copy constructor
9743  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9744  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9745  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9746  *          is to delete this field using decrRef() as it is no more needed.
9747  */
9748 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9749 {
9750   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9751 }
9752
9753 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9754 {
9755   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9756   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9757   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0,ent));
9758   ret->contentNotNull();//to check that content type matches with \a this type.
9759   return ret.retn();
9760 }
9761
9762 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9763 {
9764   return new MEDFileFieldMultiTS(*this);
9765 }
9766
9767 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9768 {
9769   if(!f1ts)
9770     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9771   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9772   if(!f1tsC)
9773     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9774 }
9775
9776 /*!
9777  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9778  * following the given input policy.
9779  *
9780  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9781  *                            By default (true) the globals are deeply copied.
9782  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9783  */
9784 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9785 {
9786   MCAuto<MEDFileIntFieldMultiTS> ret;
9787   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9788   if(content)
9789     {
9790       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9791       if(!contc)
9792         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9793       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9794       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
9795     }
9796   else
9797     ret=MEDFileIntFieldMultiTS::New();
9798   if(isDeepCpyGlobs)
9799     ret->deepCpyGlobs(*this);
9800   else
9801     ret->shallowCpyGlobs(*this);
9802   return ret.retn();
9803 }
9804
9805 /*!
9806  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9807  *  \param [in] pos - a time step id.
9808  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9809  *          delete this field using decrRef() as it is no more needed.
9810  *  \throw If \a pos is not a valid time step id.
9811  */
9812 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9813 {
9814   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9815   if(!item)
9816     {
9817       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9818       throw INTERP_KERNEL::Exception(oss.str());
9819     }
9820   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9821   if(itemC)
9822     {
9823       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9824       ret->shallowCpyGlobs(*this);
9825       return ret.retn();
9826     }
9827   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9828   throw INTERP_KERNEL::Exception(oss.str());
9829 }
9830
9831 /*!
9832  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9833  * mesh entities of a given dimension of the first mesh in MED file.
9834  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9835  *  \param [in] type - a spatial discretization of interest.
9836  *  \param [in] iteration - the iteration number of a required time step.
9837  *  \param [in] order - the iteration order number of required time step.
9838  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9839  *  \param [in] renumPol - specifies how to permute values of the result field according to
9840  *          the optional numbers of cells and nodes, if any. The valid values are
9841  *          - 0 - do not permute.
9842  *          - 1 - permute cells.
9843  *          - 2 - permute nodes.
9844  *          - 3 - permute cells and nodes.
9845  *
9846  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9847  *          caller is to delete this field using decrRef() as it is no more needed. 
9848  *  \throw If the MED file is not readable.
9849  *  \throw If there is no mesh in the MED file.
9850  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9851  *  \throw If no field values of the required parameters are available.
9852  */
9853 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9854 {
9855   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9856   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9857   if(!myF1TSC)
9858     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9859   MCAuto<DataArray> arrOut;
9860   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9861   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9862   return ret.retn();
9863 }
9864
9865 /*!
9866  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9867  * the top level cells of the first mesh in MED file.
9868  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9869  *  \param [in] type - a spatial discretization of interest.
9870  *  \param [in] iteration - the iteration number of a required time step.
9871  *  \param [in] order - the iteration order number of required time step.
9872  *  \param [in] renumPol - specifies how to permute values of the result field according to
9873  *          the optional numbers of cells and nodes, if any. The valid values are
9874  *          - 0 - do not permute.
9875  *          - 1 - permute cells.
9876  *          - 2 - permute nodes.
9877  *          - 3 - permute cells and nodes.
9878  *
9879  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9880  *          caller is to delete this field using decrRef() as it is no more needed. 
9881  *  \throw If the MED file is not readable.
9882  *  \throw If there is no mesh in the MED file.
9883  *  \throw If no field values of the required parameters are available.
9884  */
9885 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9886 {
9887   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9888   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9889   if(!myF1TSC)
9890     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9891   MCAuto<DataArray> arrOut;
9892   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9893   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9894   return ret.retn();
9895 }
9896
9897 /*!
9898  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
9899  * method should be called (getFieldOnMeshAtLevel for example).
9900  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9901  *
9902  * \param [in] iteration - the iteration number of a required time step.
9903  * \param [in] order - the iteration order number of required time step.
9904  * \param [in] mesh - the mesh the field is lying on
9905  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9906  *          caller is to delete this field using decrRef() as it is no more needed. 
9907  */
9908 MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9909 {
9910   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9911   MCAuto<DataArray> arrOut;
9912   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9913   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9914   return ret.retn();
9915 }
9916
9917 /*!
9918  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9919  * a given support.
9920  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9921  *  \param [in] type - a spatial discretization of interest.
9922  *  \param [in] iteration - the iteration number of a required time step.
9923  *  \param [in] order - the iteration order number of required time step.
9924  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9925  *  \param [in] mesh - the supporting mesh.
9926  *  \param [in] renumPol - specifies how to permute values of the result field according to
9927  *          the optional numbers of cells and nodes, if any. The valid values are
9928  *          - 0 - do not permute.
9929  *          - 1 - permute cells.
9930  *          - 2 - permute nodes.
9931  *          - 3 - permute cells and nodes.
9932  *
9933  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9934  *          caller is to delete this field using decrRef() as it is no more needed. 
9935  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9936  *  \throw If no field of \a this is lying on \a mesh.
9937  *  \throw If no field values of the required parameters are available.
9938  */
9939 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9940 {
9941   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9942   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9943   if(!myF1TSC)
9944     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9945   MCAuto<DataArray> arrOut;
9946   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9947   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9948   return ret.retn();
9949 }
9950
9951 /*!
9952  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9953  * given support. 
9954  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9955  *  \param [in] type - a spatial discretization of the new field.
9956  *  \param [in] iteration - the iteration number of a required time step.
9957  *  \param [in] order - the iteration order number of required time step.
9958  *  \param [in] mesh - the supporting mesh.
9959  *  \param [in] renumPol - specifies how to permute values of the result field according to
9960  *          the optional numbers of cells and nodes, if any. The valid values are
9961  *          - 0 - do not permute.
9962  *          - 1 - permute cells.
9963  *          - 2 - permute nodes.
9964  *          - 3 - permute cells and nodes.
9965  *
9966  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9967  *          caller is to delete this field using decrRef() as it is no more needed. 
9968  *  \throw If no field of \a this is lying on \a mesh.
9969  *  \throw If no field values of the required parameters are available.
9970  */
9971 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9972 {
9973   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9974   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9975   if(!myF1TSC)
9976     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9977   MCAuto<DataArray> arrOut;
9978   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9979   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9980   return ret.retn();
9981 }
9982
9983 /*!
9984  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9985  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9986  * This method is useful for MED2 file format when field on different mesh was autorized.
9987  */
9988 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9989 {
9990   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9991   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9992   if(!myF1TSC)
9993     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9994   MCAuto<DataArray> arrOut;
9995   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9996   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9997   return ret.retn();
9998 }
9999
10000 /*!
10001  * Returns values and a profile of the field of a given type, of a given time step,
10002  * lying on a given support.
10003  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10004  *  \param [in] type - a spatial discretization of the field.
10005  *  \param [in] iteration - the iteration number of a required time step.
10006  *  \param [in] order - the iteration order number of required time step.
10007  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10008  *  \param [in] mesh - the supporting mesh.
10009  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
10010  *          field of interest lies on. If the field lies on all entities of the given
10011  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
10012  *          using decrRef() as it is no more needed.  
10013  *  \param [in] glob - the global data storing profiles and localization.
10014  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
10015  *          field. The caller is to delete this array using decrRef() as it is no more needed.
10016  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10017  *  \throw If no field of \a this is lying on \a mesh.
10018  *  \throw If no field values of the required parameters are available.
10019  */
10020 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
10021 {
10022   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10023   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
10024   if(!myF1TSC)
10025     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
10026   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
10027   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
10028 }
10029
10030 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
10031 {
10032   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10033   if(!pt)
10034     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
10035   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
10036   if(!ret)
10037     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 !");
10038   return ret;
10039 }
10040
10041 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
10042 {
10043   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10044   if(!pt)
10045     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
10046   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
10047   if(!ret)
10048     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 !");
10049   return ret;
10050 }
10051
10052 /*!
10053  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
10054  * the given field is checked if its elements are sorted suitable for writing to MED file
10055  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10056  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10057  *  \param [in] field - the field to add to \a this.
10058  *  \throw If the name of \a field is empty.
10059  *  \throw If the data array of \a field is not set.
10060  *  \throw If existing time steps have different name or number of components than \a field.
10061  *  \throw If the underlying mesh of \a field has no name.
10062  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10063  */
10064 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
10065 {
10066   const DataArrayDouble *arr=0;
10067   if(field)
10068     arr=field->getArray();
10069   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
10070 }
10071
10072 /*!
10073  * Adds a MEDCouplingFieldDouble to \a this as another time step.
10074  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10075  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10076  * and \a profile.
10077  *
10078  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10079  * A new profile is added only if no equal profile is missing.
10080  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10081  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
10082  *  \param [in] mesh - the supporting mesh of \a field.
10083  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10084  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10085  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10086  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10087  *  \throw If the data array of \a field is not set.
10088  *  \throw If the data array of \a this is already allocated but has different number of
10089  *         components than \a field.
10090  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10091  *  \sa setFieldNoProfileSBT()
10092  */
10093 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10094 {
10095   const DataArrayDouble *arr=0;
10096   if(field)
10097     arr=field->getArray();
10098   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
10099 }
10100
10101 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
10102 {
10103   _content=new MEDFileFieldMultiTSWithoutSDA;
10104 }
10105
10106 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10107 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10108 {
10109 }
10110 catch(INTERP_KERNEL::Exception& e)
10111 { throw e; }
10112
10113 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10114 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10115 {
10116 }
10117 catch(INTERP_KERNEL::Exception& e)
10118 { throw e; }
10119
10120 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10121 {
10122 }
10123
10124 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
10125 {
10126   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
10127 }
10128
10129 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10130 {
10131   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10132 }
10133
10134 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
10135 {
10136   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
10137 }
10138
10139 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
10140 {
10141   return MEDFileFieldMultiTS::New();
10142 }
10143
10144 //= MEDFileAnyTypeFieldMultiTSIterator
10145
10146 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
10147 {
10148   if(fmts)
10149     {
10150       fmts->incrRef();
10151       _nb_iter=fmts->getNumberOfTS();
10152     }
10153 }
10154
10155 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
10156 {
10157 }
10158
10159 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
10160 {
10161   if(_iter_id<_nb_iter)
10162     {
10163       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
10164       if(fmts)
10165         return fmts->getTimeStepAtPos(_iter_id++);
10166       else
10167         return 0;
10168     }
10169   else
10170     return 0;
10171 }
10172
10173 //= MEDFileIntFieldMultiTS
10174
10175 /*!
10176  * Returns a new empty instance of MEDFileFieldMultiTS.
10177  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10178  *          is to delete this field using decrRef() as it is no more needed.
10179  */
10180 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
10181 {
10182   return new MEDFileIntFieldMultiTS;
10183 }
10184
10185 /*!
10186  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
10187  * that has been read from a specified MED file.
10188  *  \param [in] fileName - the name of the MED file to read.
10189  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10190  *          is to delete this field using decrRef() as it is no more needed.
10191  *  \throw If reading the file fails.
10192  */
10193 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
10194 {
10195   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10196   return New(fid,loadAll);
10197 }
10198
10199 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, bool loadAll)
10200 {
10201   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,loadAll,0));
10202   ret->contentNotNull();//to check that content type matches with \a this type.
10203   return ret.retn();
10204 }
10205
10206 /*!
10207  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
10208  * that has been read from a specified MED file.
10209  *  \param [in] fileName - the name of the MED file to read.
10210  *  \param [in] fieldName - the name of the field to read.
10211  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10212  *          is to delete this field using decrRef() as it is no more needed.
10213  *  \throw If reading the file fails.
10214  *  \throw If there is no field named \a fieldName in the file.
10215  */
10216 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
10217 {
10218   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10219   return New(fid,fieldName,loadAll);
10220 }
10221
10222 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
10223 {
10224   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0));
10225   ret->contentNotNull();//to check that content type matches with \a this type.
10226   return ret.retn();
10227 }
10228
10229 /*!
10230  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
10231  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
10232  *
10233  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
10234  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
10235  * \warning this is a shallow copy constructor
10236  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
10237  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
10238  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10239  *          is to delete this field using decrRef() as it is no more needed.
10240  */
10241 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
10242 {
10243   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
10244 }
10245
10246 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10247 {
10248   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10249   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10250   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0,ent));
10251   ret->contentNotNull();//to check that content type matches with \a this type.
10252   return ret.retn();
10253 }
10254
10255 /*!
10256  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
10257  * following the given input policy.
10258  *
10259  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
10260  *                            By default (true) the globals are deeply copied.
10261  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
10262  */
10263 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
10264 {
10265   MCAuto<MEDFileFieldMultiTS> ret;
10266   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
10267   if(content)
10268     {
10269       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
10270       if(!contc)
10271         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
10272       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
10273       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
10274     }
10275   else
10276     ret=MEDFileFieldMultiTS::New();
10277   if(isDeepCpyGlobs)
10278     ret->deepCpyGlobs(*this);
10279   else
10280     ret->shallowCpyGlobs(*this);
10281   return ret.retn();
10282 }
10283
10284 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
10285 {
10286   return new MEDFileIntFieldMultiTS(*this);
10287 }
10288
10289 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
10290 {
10291   if(!f1ts)
10292     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
10293   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
10294   if(!f1tsC)
10295     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
10296 }
10297
10298 /*!
10299  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
10300  * method should be called (getFieldOnMeshAtLevel for example).
10301  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
10302  *
10303  * \param [in] iteration - the iteration number of a required time step.
10304  * \param [in] order - the iteration order number of required time step.
10305  * \param [in] mesh - the mesh the field is lying on
10306  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
10307  *          caller is to delete this field using decrRef() as it is no more needed. 
10308  */
10309 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
10310 {
10311   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10312   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10313   if(!myF1TSC)
10314     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
10315   MCAuto<DataArray> arrOut;
10316   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
10317   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
10318   return ret2.retn();
10319 }
10320
10321 /*!
10322  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10323  * mesh entities of a given dimension of the first mesh in MED file.
10324  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10325  *  \param [in] type - a spatial discretization of interest.
10326  *  \param [in] iteration - the iteration number of a required time step.
10327  *  \param [in] order - the iteration order number of required time step.
10328  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10329  *  \param [in] renumPol - specifies how to permute values of the result field according to
10330  *          the optional numbers of cells and nodes, if any. The valid values are
10331  *          - 0 - do not permute.
10332  *          - 1 - permute cells.
10333  *          - 2 - permute nodes.
10334  *          - 3 - permute cells and nodes.
10335  *
10336  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10337  *          caller is to delete this field using decrRef() as it is no more needed. 
10338  *  \throw If the MED file is not readable.
10339  *  \throw If there is no mesh in the MED file.
10340  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10341  *  \throw If no field values of the required parameters are available.
10342  */
10343 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
10344 {
10345   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10346   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10347   if(!myF1TSC)
10348     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
10349   MCAuto<DataArray> arr;
10350   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
10351   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10352   return ret2.retn();
10353 }
10354
10355 /*!
10356  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10357  * the top level cells of the first mesh in MED file.
10358  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10359  *  \param [in] type - a spatial discretization of interest.
10360  *  \param [in] iteration - the iteration number of a required time step.
10361  *  \param [in] order - the iteration order number of required time step.
10362  *  \param [in] renumPol - specifies how to permute values of the result field according to
10363  *          the optional numbers of cells and nodes, if any. The valid values are
10364  *          - 0 - do not permute.
10365  *          - 1 - permute cells.
10366  *          - 2 - permute nodes.
10367  *          - 3 - permute cells and nodes.
10368  *
10369  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10370  *          caller is to delete this field using decrRef() as it is no more needed. 
10371  *  \throw If the MED file is not readable.
10372  *  \throw If there is no mesh in the MED file.
10373  *  \throw If no field values of the required parameters are available.
10374  */
10375 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
10376 {
10377   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10378   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10379   if(!myF1TSC)
10380     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
10381   MCAuto<DataArray> arr;
10382   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
10383   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10384   return ret2.retn();
10385 }
10386
10387 /*!
10388  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10389  * a given support.
10390  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10391  *  \param [in] type - a spatial discretization of interest.
10392  *  \param [in] iteration - the iteration number of a required time step.
10393  *  \param [in] order - the iteration order number of required time step.
10394  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10395  *  \param [in] mesh - the supporting mesh.
10396  *  \param [in] renumPol - specifies how to permute values of the result field according to
10397  *          the optional numbers of cells and nodes, if any. The valid values are
10398  *          - 0 - do not permute.
10399  *          - 1 - permute cells.
10400  *          - 2 - permute nodes.
10401  *          - 3 - permute cells and nodes.
10402  *
10403  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10404  *          caller is to delete this field using decrRef() as it is no more needed. 
10405  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10406  *  \throw If no field of \a this is lying on \a mesh.
10407  *  \throw If no field values of the required parameters are available.
10408  */
10409 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
10410 {
10411   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10412   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10413   if(!myF1TSC)
10414     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10415   MCAuto<DataArray> arr;
10416   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
10417   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10418   return ret2.retn();
10419 }
10420
10421 /*!
10422  * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
10423  * given support. 
10424  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10425  *  \param [in] type - a spatial discretization of the new field.
10426  *  \param [in] iteration - the iteration number of a required time step.
10427  *  \param [in] order - the iteration order number of required time step.
10428  *  \param [in] mesh - the supporting mesh.
10429  *  \param [out] arrOut - the DataArrayInt containing values of field.
10430  *  \param [in] renumPol - specifies how to permute values of the result field according to
10431  *          the optional numbers of cells and nodes, if any. The valid values are
10432  *          - 0 - do not permute.
10433  *          - 1 - permute cells.
10434  *          - 2 - permute nodes.
10435  *          - 3 - permute cells and nodes.
10436  *
10437  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10438  *          caller is to delete this field using decrRef() as it is no more needed. 
10439  *  \throw If no field of \a this is lying on \a mesh.
10440  *  \throw If no field values of the required parameters are available.
10441  */
10442 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
10443 {
10444   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10445   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10446   if(!myF1TSC)
10447     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10448   MCAuto<DataArray> arr;
10449   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
10450   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10451   return ret2.retn();
10452 }
10453
10454 /*!
10455  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
10456  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
10457  * This method is useful for MED2 file format when field on different mesh was autorized.
10458  */
10459 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
10460 {
10461   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10462   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10463   if(!myF1TSC)
10464     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10465   MCAuto<DataArray> arr;
10466   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
10467   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10468   return ret2.retn();
10469 }
10470
10471 /*!
10472  * Returns values and a profile of the field of a given type, of a given time step,
10473  * lying on a given support.
10474  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10475  *  \param [in] type - a spatial discretization of the field.
10476  *  \param [in] iteration - the iteration number of a required time step.
10477  *  \param [in] order - the iteration order number of required time step.
10478  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10479  *  \param [in] mesh - the supporting mesh.
10480  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
10481  *          field of interest lies on. If the field lies on all entities of the given
10482  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
10483  *          using decrRef() as it is no more needed.  
10484  *  \param [in] glob - the global data storing profiles and localization.
10485  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
10486  *          field. The caller is to delete this array using decrRef() as it is no more needed.
10487  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10488  *  \throw If no field of \a this is lying on \a mesh.
10489  *  \throw If no field values of the required parameters are available.
10490  */
10491 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
10492 {
10493   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10494   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
10495   if(!myF1TSC)
10496     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
10497   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
10498   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
10499 }
10500
10501 /*!
10502  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
10503  *  \param [in] pos - a time step id.
10504  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
10505  *          delete this field using decrRef() as it is no more needed.
10506  *  \throw If \a pos is not a valid time step id.
10507  */
10508 MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
10509 {
10510   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
10511   if(!item)
10512     {
10513       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
10514       throw INTERP_KERNEL::Exception(oss.str());
10515     }
10516   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
10517   if(itemC)
10518     {
10519       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
10520       ret->shallowCpyGlobs(*this);
10521       return ret.retn();
10522     }
10523   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
10524   throw INTERP_KERNEL::Exception(oss.str());
10525 }
10526
10527 /*!
10528  * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
10529  * the given field is checked if its elements are sorted suitable for writing to MED file
10530  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10531  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10532  *  \param [in] field - the field to add to \a this.
10533  *  \throw If the name of \a field is empty.
10534  *  \throw If the data array of \a field is not set.
10535  *  \throw If existing time steps have different name or number of components than \a field.
10536  *  \throw If the underlying mesh of \a field has no name.
10537  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10538  */
10539 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
10540 {
10541   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10542   contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
10543 }
10544
10545 /*!
10546  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
10547  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10548  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10549  * and \a profile.
10550  *
10551  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10552  * A new profile is added only if no equal profile is missing.
10553  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10554  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
10555  *  \param [in] arrOfVals - the values of the field \a field used.
10556  *  \param [in] mesh - the supporting mesh of \a field.
10557  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10558  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10559  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10560  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10561  *  \throw If the data array of \a field is not set.
10562  *  \throw If the data array of \a this is already allocated but has different number of
10563  *         components than \a field.
10564  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10565  *  \sa setFieldNoProfileSBT()
10566  */
10567 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10568 {
10569   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10570   contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
10571 }
10572
10573 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
10574 {
10575   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10576   if(!pt)
10577     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
10578   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10579   if(!ret)
10580     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 !");
10581   return ret;
10582 }
10583
10584 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
10585 {
10586   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10587   if(!pt)
10588     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
10589   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10590   if(!ret)
10591     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 !");
10592   return ret;
10593 }
10594
10595 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
10596 {
10597   _content=new MEDFileIntFieldMultiTSWithoutSDA;
10598 }
10599
10600 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10601 {
10602 }
10603
10604 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10605 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10606 {
10607 }
10608 catch(INTERP_KERNEL::Exception& e)
10609 { throw e; }
10610
10611 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10612 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10613 {
10614 }
10615 catch(INTERP_KERNEL::Exception& e)
10616 { throw e; }
10617
10618 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10619 {
10620   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10621 }
10622
10623 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
10624 {
10625   return MEDFileIntFieldMultiTS::New();
10626 }
10627
10628 //= MEDFileFields
10629
10630 MEDFileFields *MEDFileFields::New()
10631 {
10632   return new MEDFileFields;
10633 }
10634
10635 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
10636 {
10637   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10638   return New(fid,loadAll);
10639 }
10640
10641 MEDFileFields *MEDFileFields::NewAdv(const std::string& fileName, bool loadAll, const MEDFileEntities *entities)
10642 {
10643   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10644   return NewAdv(fid,loadAll,entities);
10645 }
10646
10647 MEDFileFields *MEDFileFields::NewAdv(med_idt fid, bool loadAll, const MEDFileEntities *entities)
10648 {
10649   return new MEDFileFields(fid,loadAll,0,entities);
10650 }
10651
10652 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
10653 {
10654   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10655   return NewWithDynGT(fid,se,loadAll);
10656 }
10657
10658 MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll)
10659 {
10660   if(!se)
10661     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
10662   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
10663   return new MEDFileFields(fid,loadAll,0,entities);
10664 }
10665
10666 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
10667 {
10668   return new MEDFileFields(fid,loadAll,0,0);
10669 }
10670
10671 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10672 {
10673   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10674   return new MEDFileFields(fid,loadAll,ms,0);
10675 }
10676
10677 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10678 {
10679   MEDFileUtilities::CheckFileForRead(fileName);
10680   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10681   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10682   return new MEDFileFields(fid,loadAll,0,ent);
10683 }
10684
10685 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
10686 {
10687   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
10688   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
10689   return ret;
10690 }
10691
10692 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
10693 {
10694   std::vector<const BigMemoryObject *> ret;
10695   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10696     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
10697   return ret;
10698 }
10699
10700 MEDFileFields *MEDFileFields::deepCopy() const
10701 {
10702   MCAuto<MEDFileFields> ret(shallowCpy());
10703   std::size_t i(0);
10704   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10705     {
10706       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10707         ret->_fields[i]=(*it)->deepCopy();
10708     }
10709   ret->deepCpyGlobs(*this);
10710   return ret.retn();
10711 }
10712
10713 MEDFileFields *MEDFileFields::shallowCpy() const
10714 {
10715   return new MEDFileFields(*this);
10716 }
10717
10718 /*!
10719  * 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
10720  * 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.
10721  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
10722  *
10723  * \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.
10724  * \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.
10725  * 
10726  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10727  */
10728 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
10729 {
10730   std::set< std::pair<int,int> > s;
10731   bool firstShot=true;
10732   areThereSomeForgottenTS=false;
10733   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10734     {
10735       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10736         continue;
10737       std::vector< std::pair<int,int> > v=(*it)->getIterations();
10738       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
10739       if(firstShot)
10740         { s=s1; firstShot=false; }
10741       else
10742         {
10743           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
10744           if(s!=s2)
10745             areThereSomeForgottenTS=true;
10746           s=s2;
10747         }
10748     }
10749   std::vector< std::pair<int,int> > ret;
10750   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
10751   return ret;
10752 }
10753
10754 int MEDFileFields::getNumberOfFields() const
10755 {
10756   return _fields.size();
10757 }
10758
10759 std::vector<std::string> MEDFileFields::getFieldsNames() const
10760 {
10761   std::vector<std::string> ret(_fields.size());
10762   int i(0);
10763   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10764     {
10765       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
10766       if(f)
10767         {
10768           ret[i]=f->getName();
10769         }
10770       else
10771         {
10772           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
10773           throw INTERP_KERNEL::Exception(oss.str());
10774         }
10775     }
10776   return ret;
10777 }
10778
10779 std::vector<std::string> MEDFileFields::getMeshesNames() const
10780 {
10781   std::vector<std::string> ret;
10782   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10783     {
10784       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10785       if(cur)
10786         ret.push_back(cur->getMeshName());
10787     }
10788   return ret;
10789 }
10790
10791 std::string MEDFileFields::simpleRepr() const
10792 {
10793   std::ostringstream oss;
10794   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10795   simpleRepr(0,oss);
10796   return oss.str();
10797 }
10798
10799 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10800 {
10801   int nbOfFields(getNumberOfFields());
10802   std::string startLine(bkOffset,' ');
10803   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10804   int i=0;
10805   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10806     {
10807       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10808       if(cur)
10809         {
10810           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10811         }
10812       else
10813         {
10814           oss << startLine << "  - not defined !" << std::endl;
10815         }
10816     }
10817   i=0;
10818   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10819     {
10820       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10821       std::string chapter(17,'0'+i);
10822       oss << startLine << chapter << std::endl;
10823       if(cur)
10824         {
10825           cur->simpleRepr(bkOffset+2,oss,i);
10826         }
10827       else
10828         {
10829           oss << startLine << "  - not defined !" << std::endl;
10830         }
10831       oss << startLine << chapter << std::endl;
10832     }
10833   simpleReprGlobs(oss);
10834 }
10835
10836 MEDFileFields::MEDFileFields()
10837 {
10838 }
10839
10840 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10841 try:MEDFileFieldGlobsReal(fid)
10842 {
10843   int nbFields(MEDnField(fid));
10844   _fields.resize(nbFields);
10845   med_field_type typcha;
10846   for(int i=0;i<nbFields;i++)
10847     {
10848       std::vector<std::string> infos;
10849       std::string fieldName,dtunit,meshName;
10850       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit,meshName));
10851       switch(typcha)
10852       {
10853         case MED_FLOAT64:
10854           {
10855             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10856             break;
10857           }
10858         case MED_INT32:
10859           {
10860             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10861             break;
10862           }
10863         default:
10864           {
10865             std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << FileNameFromFID(fid) << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
10866             throw INTERP_KERNEL::Exception(oss.str());
10867           }
10868       }
10869     }
10870   loadAllGlobals(fid,entities);
10871 }
10872 catch(INTERP_KERNEL::Exception& e)
10873 {
10874     throw e;
10875 }
10876
10877 void MEDFileFields::writeLL(med_idt fid) const
10878 {
10879   int i=0;
10880   writeGlobals(fid,*this);
10881   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10882     {
10883       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10884       if(!elt)
10885         {
10886           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10887           throw INTERP_KERNEL::Exception(oss.str());
10888         }
10889       elt->writeLL(fid,*this);
10890     }
10891 }
10892
10893 /*!
10894  * This method alloc the arrays and load potentially huge arrays contained in this field.
10895  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10896  * This method can be also called to refresh or reinit values from a file.
10897  * 
10898  * \throw If the fileName is not set or points to a non readable MED file.
10899  */
10900 void MEDFileFields::loadArrays()
10901 {
10902   if(getFileName().empty())
10903     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10904   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10905   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10906     {
10907       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10908       if(elt)
10909         elt->loadBigArraysRecursively(fid,*elt);
10910     }
10911 }
10912
10913 /*!
10914  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10915  * But once data loaded once, this method does nothing.
10916  * 
10917  * \throw If the fileName is not set or points to a non readable MED file.
10918  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10919  */
10920 void MEDFileFields::loadArraysIfNecessary()
10921 {
10922   if(!getFileName().empty())
10923     {
10924       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10925       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10926         {
10927           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10928           if(elt)
10929             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10930         }
10931     }
10932 }
10933
10934 /*!
10935  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10936  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10937  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10938  * 
10939  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10940  */
10941 void MEDFileFields::unloadArrays()
10942 {
10943   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10944     {
10945       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10946       if(elt)
10947         elt->unloadArrays();
10948     }
10949 }
10950
10951 /*!
10952  * 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.
10953  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10954  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10955  * 
10956  * \sa MEDFileFields::loadArraysIfNecessary
10957  */
10958 void MEDFileFields::unloadArraysWithoutDataLoss()
10959 {
10960   if(!getFileName().empty())
10961     unloadArrays();
10962 }
10963
10964 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10965 {
10966   std::vector<std::string> ret;
10967   std::set<std::string> ret2;
10968   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10969     {
10970       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10971       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10972         if(ret2.find(*it2)==ret2.end())
10973           {
10974             ret.push_back(*it2);
10975             ret2.insert(*it2);
10976           }
10977     }
10978   return ret;
10979 }
10980
10981 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10982 {
10983   std::vector<std::string> ret;
10984   std::set<std::string> ret2;
10985   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10986     {
10987       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10988       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10989         if(ret2.find(*it2)==ret2.end())
10990           {
10991             ret.push_back(*it2);
10992             ret2.insert(*it2);
10993           }
10994     }
10995   return ret;
10996 }
10997
10998 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10999 {
11000   std::vector<std::string> ret;
11001   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11002     {
11003       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
11004       ret.insert(ret.end(),tmp.begin(),tmp.end());
11005     }
11006   return ret;
11007 }
11008
11009 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
11010 {
11011   std::vector<std::string> ret;
11012   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11013     {
11014       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
11015       ret.insert(ret.end(),tmp.begin(),tmp.end());
11016     }
11017   return ret;
11018 }
11019
11020 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
11021 {
11022   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
11023     (*it)->changePflsRefsNamesGen2(mapOfModif);
11024 }
11025
11026 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
11027 {
11028   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
11029     (*it)->changeLocsRefsNamesGen2(mapOfModif);
11030 }
11031
11032 void MEDFileFields::resize(int newSize)
11033 {
11034   _fields.resize(newSize);
11035 }
11036
11037 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
11038 {
11039   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
11040     pushField(*it);
11041 }
11042
11043 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
11044 {
11045   if(!field)
11046     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
11047   _fields.push_back(field->getContent());
11048   appendGlobs(*field,1e-12);
11049 }
11050
11051 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
11052 {
11053   if(!field)
11054     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
11055   if(i>=(int)_fields.size())
11056     _fields.resize(i+1);
11057   _fields[i]=field->getContent();
11058   appendGlobs(*field,1e-12);
11059 }
11060
11061 void MEDFileFields::destroyFieldAtPos(int i)
11062 {
11063   destroyFieldsAtPos(&i,&i+1);
11064 }
11065
11066 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
11067 {
11068   std::vector<bool> b(_fields.size(),true);
11069   for(const int *i=startIds;i!=endIds;i++)
11070     {
11071       if(*i<0 || *i>=(int)_fields.size())
11072         {
11073           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
11074           throw INTERP_KERNEL::Exception(oss.str());
11075         }
11076       b[*i]=false;
11077     }
11078   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
11079   std::size_t j=0;
11080   for(std::size_t i=0;i<_fields.size();i++)
11081     if(b[i])
11082       fields[j++]=_fields[i];
11083   _fields=fields;
11084 }
11085
11086 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
11087 {
11088   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
11089   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
11090   std::vector<bool> b(_fields.size(),true);
11091   int k=bg;
11092   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
11093     {
11094       if(k<0 || k>=(int)_fields.size())
11095         {
11096           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
11097           throw INTERP_KERNEL::Exception(oss.str());
11098         }
11099       b[k]=false;
11100     }
11101   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
11102   std::size_t j(0);
11103   for(std::size_t i=0;i<_fields.size();i++)
11104     if(b[i])
11105       fields[j++]=_fields[i];
11106   _fields=fields;
11107 }
11108
11109 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
11110 {
11111   bool ret(false);
11112   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11113     {
11114       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11115       if(cur)
11116         ret=cur->changeMeshNames(modifTab) || ret;
11117     }
11118   return ret;
11119 }
11120
11121 /*!
11122  * \param [in] meshName the name of the mesh that will be renumbered.
11123  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
11124  *             This code corresponds to the distribution of types in the corresponding mesh.
11125  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
11126  * \param [in] renumO2N the old to new renumber array.
11127  * \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 
11128  *         field in \a this.
11129  */
11130 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
11131 {
11132   bool ret(false);
11133   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11134     {
11135       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
11136       if(fmts)
11137         {
11138           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
11139         }
11140     }
11141   return ret;
11142 }
11143
11144 /*!
11145  * Return an extraction of \a this using \a extractDef map to specify the extraction.
11146  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
11147  *
11148  * \return A new object that the caller is responsible to deallocate.
11149  */
11150 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
11151 {
11152   if(!mm)
11153     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
11154   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
11155   int nbFields(getNumberOfFields());
11156   for(int i=0;i<nbFields;i++)
11157     {
11158       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
11159       if(!fmts)
11160         {
11161           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
11162           throw INTERP_KERNEL::Exception(oss.str());
11163         }
11164       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
11165       fsOut->pushField(fmtsOut);
11166     }
11167   return fsOut.retn();
11168 }
11169
11170 void MEDFileFields::accept(MEDFileFieldVisitor& visitor) const
11171 {
11172   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11173     if((*it).isNotNull())
11174       {
11175         visitor.newFieldEntry(*it);
11176         (*it)->accept(visitor);
11177         visitor.endFieldEntry(*it);
11178       }
11179 }
11180
11181 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
11182 {
11183   if(i<0 || i>=(int)_fields.size())
11184     {
11185       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
11186       throw INTERP_KERNEL::Exception(oss.str());
11187     }
11188   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
11189   if(!fmts)
11190     return 0;
11191   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
11192   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
11193   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
11194   if(fmtsC)
11195     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
11196   else if(fmtsC2)
11197     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
11198   else
11199     {
11200       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
11201       throw INTERP_KERNEL::Exception(oss.str());
11202     }
11203   ret->shallowCpyGlobs(*this);
11204   return ret.retn();
11205 }
11206
11207 /*!
11208  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
11209  * This method is accessible in python using __getitem__ with a list in input.
11210  * \return a new object that the caller should deal with.
11211  */
11212 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
11213 {
11214   MCAuto<MEDFileFields> ret=shallowCpy();
11215   std::size_t sz=std::distance(startIds,endIds);
11216   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
11217   int j=0;
11218   for(const int *i=startIds;i!=endIds;i++,j++)
11219     {
11220       if(*i<0 || *i>=(int)_fields.size())
11221         {
11222           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
11223           throw INTERP_KERNEL::Exception(oss.str());
11224         }
11225       fields[j]=_fields[*i];
11226     }
11227   ret->_fields=fields;
11228   return ret.retn();
11229 }
11230
11231 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
11232 {
11233   return getFieldAtPos(getPosFromFieldName(fieldName));
11234 }
11235
11236 /*!
11237  * This method removes, if any, fields in \a this having no time steps.
11238  * 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.
11239  * 
11240  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
11241  */
11242 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
11243 {
11244   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
11245   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11246     {
11247       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
11248       if(elt)
11249         {
11250           if(elt->getNumberOfTS()>0)
11251             newFields.push_back(*it);
11252         }
11253     }
11254   if(_fields.size()==newFields.size())
11255     return false;
11256   _fields=newFields;
11257   return true;
11258 }
11259
11260 /*!
11261  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
11262  * This method can be seen as a filter applied on \a this, that returns an object containing
11263  * 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
11264  * shallow copied from \a this.
11265  * 
11266  * \param [in] meshName - the name of the mesh on w
11267  * \return a new object that the caller should deal with.
11268  */
11269 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
11270 {
11271   MCAuto<MEDFileFields> ret(MEDFileFields::New());
11272   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11273     {
11274       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11275       if(!cur)
11276         continue;
11277       if(cur->getMeshName()==meshName)
11278         {
11279           cur->incrRef();
11280           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
11281           ret->_fields.push_back(cur2);
11282         }
11283     }
11284   ret->shallowCpyOnlyUsedGlobs(*this);
11285   return ret.retn();
11286 }
11287
11288 /*!
11289  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
11290  * Input time steps are specified using a pair of integer (iteration, order).
11291  * 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,
11292  * but for each multitimestep only the time steps in \a timeSteps are kept.
11293  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
11294  * 
11295  * The returned object points to shallow copy of elements in \a this.
11296  * 
11297  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
11298  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
11299  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
11300  */
11301 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11302 {
11303   MCAuto<MEDFileFields> ret(MEDFileFields::New());
11304   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11305     {
11306       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11307       if(!cur)
11308         continue;
11309       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
11310       ret->_fields.push_back(elt);
11311     }
11312   ret->shallowCpyOnlyUsedGlobs(*this);
11313   return ret.retn();
11314 }
11315
11316 /*!
11317  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
11318  */
11319 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11320 {
11321   MCAuto<MEDFileFields> ret=MEDFileFields::New();
11322   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11323     {
11324       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11325       if(!cur)
11326         continue;
11327       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
11328       if(elt->getNumberOfTS()!=0)
11329         ret->_fields.push_back(elt);
11330     }
11331   ret->shallowCpyOnlyUsedGlobs(*this);
11332   return ret.retn();
11333 }
11334
11335 bool MEDFileFields::presenceOfStructureElements() const
11336 {
11337   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11338     if((*it).isNotNull())
11339       if((*it)->presenceOfStructureElements())
11340         return true;
11341   return false;
11342 }
11343
11344 void MEDFileFields::killStructureElements()
11345 {
11346   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11347   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11348     if((*it).isNotNull())
11349       {
11350         if((*it)->presenceOfStructureElements())
11351           {
11352             if(!(*it)->onlyStructureElements())
11353               {
11354                 (*it)->killStructureElements();
11355                 ret.push_back(*it);
11356               }
11357           }
11358         else
11359           {
11360             ret.push_back(*it);
11361           }
11362       }
11363   _fields=ret;
11364 }
11365
11366 void MEDFileFields::keepOnlyStructureElements()
11367 {
11368   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11369   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11370     if((*it).isNotNull())
11371       {
11372         if((*it)->presenceOfStructureElements())
11373           {
11374             if(!(*it)->onlyStructureElements())
11375               (*it)->keepOnlyStructureElements();
11376             ret.push_back(*it);
11377           }
11378       }
11379   _fields=ret;
11380 }
11381
11382 void MEDFileFields::keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName)
11383 {
11384   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11385   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11386     if((*it).isNotNull())
11387       {
11388         if((*it)->getMeshName()!=meshName)
11389           continue;
11390         std::vector< std::pair<std::string,std::string> > ps;
11391         (*it)->getMeshSENames(ps);
11392         std::pair<std::string,std::string> p(meshName,seName);
11393         if(std::find(ps.begin(),ps.end(),p)!=ps.end())
11394           (*it)->keepOnlyOnSE(seName);
11395         ret.push_back(*it);
11396       }
11397   _fields=ret;
11398 }
11399
11400 void MEDFileFields::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
11401 {
11402   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11403     if((*it).isNotNull())
11404       (*it)->getMeshSENames(ps);
11405 }
11406
11407 void MEDFileFields::blowUpSE(MEDFileMeshes *ms, const MEDFileStructureElements *ses)
11408 {
11409   MEDFileBlowStrEltUp::DealWithSE(this,ms,ses);
11410 }
11411
11412 MCAuto<MEDFileFields> MEDFileFields::partOfThisOnStructureElements() const
11413 {
11414   MCAuto<MEDFileFields> ret(deepCopy());
11415   ret->keepOnlyStructureElements();
11416   return ret;
11417 }
11418
11419 MCAuto<MEDFileFields> MEDFileFields::partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const
11420 {
11421   MCAuto<MEDFileFields> ret(deepCopy());
11422   ret->keepOnlyOnMeshSE(meshName,seName);
11423   return ret;
11424 }
11425
11426 void MEDFileFields::aggregate(const MEDFileFields& other)
11427 {
11428   int nbFieldsToAdd(other.getNumberOfFields());
11429   std::vector<std::string> fsn(getFieldsNames());
11430   for(int i=0;i<nbFieldsToAdd;i++)
11431     {
11432       MCAuto<MEDFileAnyTypeFieldMultiTS> elt(other.getFieldAtPos(i));
11433       std::string name(elt->getName());
11434       if(std::find(fsn.begin(),fsn.end(),name)!=fsn.end())
11435         {
11436           std::ostringstream oss; oss << "MEDFileFields::aggregate : name \"" << name << "\" already appears !";
11437           throw INTERP_KERNEL::Exception(oss.str());
11438         }
11439       pushField(elt);
11440     }
11441 }
11442
11443 MEDFileFieldsIterator *MEDFileFields::iterator()
11444 {
11445   return new MEDFileFieldsIterator(this);
11446 }
11447
11448 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
11449 {
11450   std::string tmp(fieldName);
11451   std::vector<std::string> poss;
11452   for(std::size_t i=0;i<_fields.size();i++)
11453     {
11454       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
11455       if(f)
11456         {
11457           std::string fname(f->getName());
11458           if(tmp==fname)
11459             return i;
11460           else
11461             poss.push_back(fname);
11462         }
11463     }
11464   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
11465   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
11466   oss << " !";
11467   throw INTERP_KERNEL::Exception(oss.str());
11468 }
11469
11470 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
11471 {
11472   if(fs)
11473     {
11474       fs->incrRef();
11475       _nb_iter=fs->getNumberOfFields();
11476     }
11477 }
11478
11479 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
11480 {
11481 }
11482
11483 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
11484 {
11485   if(_iter_id<_nb_iter)
11486     {
11487       MEDFileFields *fs(_fs);
11488       if(fs)
11489         return fs->getFieldAtPos(_iter_id++);
11490       else
11491         return 0;
11492     }
11493   else
11494     return 0;
11495 }