Salome HOME
Merge from V6_main (04/10/2012)
[modules/med.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2012  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.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileUtilities.hxx"
25
26 #include "MEDCouplingFieldDouble.hxx"
27 #include "MEDCouplingFieldDiscretization.hxx"
28
29 #include "InterpKernelAutoPtr.hxx"
30 #include "CellModel.hxx"
31
32 #include <algorithm>
33 #include <iterator>
34
35 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
36 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
37 extern med_geometry_type typmainoeud[1];
38 extern med_geometry_type typmai3[32];
39
40 using namespace ParaMEDMEM;
41
42 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const char *locName)
43 {
44   return new MEDFileFieldLoc(fid,locName);
45 }
46
47 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
48 {
49   return new MEDFileFieldLoc(fid,id);
50 }
51
52 MEDFileFieldLoc *MEDFileFieldLoc::New(const char *locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
53 {
54   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
55 }
56
57 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const char *locName):_name(locName)
58 {
59   med_geometry_type geotype;
60   med_geometry_type sectiongeotype;
61   int nsectionmeshcell;
62   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
63   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
64   MEDlocalizationInfoByName(fid,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
65   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+32,geotype)));
66   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
67   _nb_node_per_cell=cm.getNumberOfNodes();
68   _ref_coo.resize(_dim*_nb_node_per_cell);
69   _gs_coo.resize(_dim*_nb_gauss_pt);
70   _w.resize(_nb_gauss_pt);
71   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
72 }
73
74 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
75 {
76   med_geometry_type geotype;
77   med_geometry_type sectiongeotype;
78   int nsectionmeshcell;
79   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
80   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
81   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
82   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
83   _name=locName;
84   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+32,geotype)));
85   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
86   _nb_node_per_cell=cm.getNumberOfNodes();
87   _ref_coo.resize(_dim*_nb_node_per_cell);
88   _gs_coo.resize(_dim*_nb_gauss_pt);
89   _w.resize(_nb_gauss_pt);
90   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
91 }
92
93 MEDFileFieldLoc::MEDFileFieldLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType,
94                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_geo_type(geoType),_ref_coo(refCoo),_gs_coo(gsCoo),
95                                                                                                                                     _w(w)
96 {
97   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
98   _dim=cm.getDimension();
99   _nb_node_per_cell=cm.getNumberOfNodes();
100   _nb_gauss_pt=_w.size();
101 }
102
103 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
104 {
105   static const char OFF7[]="\n    ";
106   oss << "\"" << _name << "\"" << OFF7;
107   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
108   oss << "Dimension=" << _dim << OFF7;
109   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
110   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
111   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
112   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
113   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
114 }
115
116 void MEDFileFieldLoc::setName(const char *name)
117 {
118   _name=name;
119 }
120
121 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
122 {
123   if(_name!=other._name)
124     return false;
125   if(_dim!=other._dim)
126     return false;
127   if(_nb_gauss_pt!=other._nb_gauss_pt)
128     return false;
129   if(_nb_node_per_cell!=other._nb_node_per_cell)
130     return false;
131   if(_geo_type!=other._geo_type)
132     return false;
133   if(MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
134     return false;
135   if(MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
136     return false;
137   if(MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
138     return false;
139   
140   return true;
141 }
142
143 void MEDFileFieldLoc::writeLL(med_idt fid) const
144 {
145   MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)_geo_type],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT);
146 }
147
148 std::string MEDFileFieldLoc::repr() const
149 {
150   std::ostringstream oss; oss.precision(15);
151   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
152   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
153   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
154   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
155   oss << "\n  - Ref coords are : ";
156   int sz=_ref_coo.size();
157   if(sz%_dim==0)
158     {
159       int nbOfTuples=sz/_dim;
160       for(int i=0;i<nbOfTuples;i++)
161         {
162           oss << "(";
163           for(int j=0;j<_dim;j++)
164             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
165           oss << ") ";
166         }
167     }
168   else
169     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
170   oss << "\n  - Gauss coords in reference element : ";
171   sz=_gs_coo.size();
172   if(sz%_dim==0)
173     {
174       int nbOfTuples=sz/_dim;
175       for(int i=0;i<nbOfTuples;i++)
176         {
177           oss << "(";
178           for(int j=0;j<_dim;j++)
179             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
180           oss << ") ";
181         }
182     }
183   else
184     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
185   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
186   return oss.str();
187 }
188
189 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
190 {
191   _type=field->getTypeOfField();
192   const DataArrayDouble *da=field->getArray();
193   _start=start;
194   switch(_type)
195     {
196     case ON_CELLS:
197       {
198         getArray()->setContigPartOfSelectedValues2(_start,da,offset,offset+nbOfCells,1);
199         _end=_start+nbOfCells;
200         _nval=nbOfCells;
201         break;
202       }
203     case ON_GAUSS_NE:
204       {
205         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
206         const int *arrPtr=arr->getConstPointer();
207         getArray()->setContigPartOfSelectedValues2(_start,da,arrPtr[offset],arrPtr[offset+nbOfCells],1);
208         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
209         _nval=nbOfCells;
210         break;
211       }
212     case ON_GAUSS_PT:
213       {
214         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
215         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
216         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
217         if(!disc2)
218           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
219         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
220         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
221         const int *dai2Ptr=dai2->getConstPointer();
222         int nbi=gsLoc.getWeights().size();
223         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=dai->selectByTupleId2(offset,offset+nbOfCells,1);
224         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
225         const int *da3Ptr=da3->getConstPointer();
226         if(da3->getNumberOfTuples()!=nbOfCells)
227           {//profile : for gauss even in NoProfile !!!
228             std::ostringstream oss; oss << "Pfl_" << getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
229             _profile=oss.str();
230             da3->setName(_profile.c_str());
231             glob.appendProfile(da3);
232           }
233         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=DataArrayInt::New();
234         _nval=da3->getNbOfElems();
235         da4->alloc(_nval*nbi,1);
236         int *da4Ptr=da4->getPointer();
237         for(int i=0;i<_nval;i++)
238           {
239             int ref=dai2Ptr[offset+da3Ptr[i]];
240             for(int j=0;j<nbi;j++)
241               *da4Ptr++=ref+j;
242           }
243         std::ostringstream oss2; oss2 << "Loc_" << getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
244         _localization=oss2.str();
245         getArray()->setContigPartOfSelectedValues(_start,da,da4);
246         _end=_start+_nval*nbi;
247         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
248         break;
249       }
250     default:
251       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
252     }
253   start=_end;
254 }
255
256 /*!
257  * Leaf method of field with profile assignement.
258  * @param pflName input containing name of profile if any. 0 if no profile.
259  * @param multiTypePfl input containing the profile array \b including \b all \b types. This array is usefull only for GAUSS_NE.
260  * @param idsInPfl input containing the ids in the profile 'multiTypePfl' concerning the current geo type.
261  */
262 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(int& start, const char *pflName, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
263 {
264   if(pflName)
265     _profile=pflName;
266   else
267     _profile.clear();
268   _type=field->getTypeOfField();
269   const DataArrayDouble *da=field->getArray();
270   _start=start;
271   switch(_type)
272     {
273     case ON_NODES:
274       {
275          _nval=idsInPfl->getNumberOfTuples();
276          getArray()->setContigPartOfSelectedValues2(_start,da,0,da->getNumberOfTuples(),1);
277          _end=_start+_nval;
278          break;
279       }
280     case ON_CELLS:
281       {
282         _nval=idsInPfl->getNumberOfTuples();
283         getArray()->setContigPartOfSelectedValues(_start,da,idsInPfl);
284         _end=_start+_nval;
285         break;
286       }
287     case ON_GAUSS_NE:
288       {
289         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
290         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr->deltaShiftIndex();
291         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->getConstPointer(),multiTypePfl->getConstPointer()+multiTypePfl->getNumberOfTuples());
292         arr3->computeOffsets2();
293         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
294         int trueNval=tmp->getNumberOfTuples();
295         _nval=idsInPfl->getNumberOfTuples();
296         getArray()->setContigPartOfSelectedValues(_start,da,tmp);
297         _end=_start+trueNval;
298         break;
299       }
300     case ON_GAUSS_PT:
301       {
302         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for profiles on gauss points !");
303       }
304     default:
305       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
306     }
307   start=_end;
308 }
309
310 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
311 {
312   _start=start;
313   _nval=field->getArray()->getNumberOfTuples();
314   getArray()->setContigPartOfSelectedValues2(_start,field->getArray(),0,_nval,1);
315   _end=_start+_nval;
316   start=_end;
317 }
318
319 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt) throw(INTERP_KERNEL::Exception)
320 {
321   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt);
322 }
323
324 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
325 {
326   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
327 }
328
329 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
330 {
331   return new MEDFileFieldPerMeshPerTypePerDisc(other);
332 }
333
334 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt) throw(INTERP_KERNEL::Exception)
335 try:_type(atype),_father(fath)
336   {
337   }
338 catch(INTERP_KERNEL::Exception& e)
339 {
340   throw e;
341 }
342
343 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
344 {
345 }
346
347 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& 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),_tmp_work1(other._tmp_work1)
348 {
349 }
350
351 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
352                                                                        _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
353 {
354 }
355
356 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
357 {
358   return _father;
359 }
360
361 void MEDFileFieldPerMeshPerTypePerDisc::prepareLoading(med_idt fid, int profileIt, int& start) throw(INTERP_KERNEL::Exception)
362 {
363   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
364   INTERP_KERNEL::AutoPtr<char> pflname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
365   std::string fieldName=getName();
366   std::string meshName=getMeshName();
367   int iteration=getIteration();
368   int order=getOrder();
369   TypeOfField type=getType();
370   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
371   int profilesize,nbi;
372   med_geometry_type mgeoti;
373   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
374   _nval=MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,profileIt,MED_COMPACT_PFLMODE,
375                                   pflname,&profilesize,locname,&nbi);
376   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
377   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
378   _start=start;
379   _end=start+_nval*nbi;
380   start=_end;
381   if(type==ON_CELLS && !_localization.empty())
382     {
383       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
384         setType(ON_GAUSS_PT);
385       else
386         {
387           setType(ON_GAUSS_NE);
388           _localization.clear();
389         }
390     }
391 }
392
393 void MEDFileFieldPerMeshPerTypePerDisc::finishLoading(med_idt fid, int profileIt, int ft) throw(INTERP_KERNEL::Exception)
394 {
395   std::string fieldName=getName();
396   std::string meshName=getMeshName();
397   int iteration=getIteration();
398   int order=getOrder();
399   TypeOfField type=getType();
400   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
401   med_geometry_type mgeoti;
402   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
403   DataArrayDouble *arr=getArray();
404   double *startFeeding=arr->getPointer()+_start*arr->getNumberOfComponents();
405   switch(ft)
406     {
407     case 0:
408       {
409         MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
410                                    _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
411         break;
412       }
413     case 1:
414       {
415         INTERP_KERNEL::AutoPtr<int> tmpp=new int[(_end-_start)*arr->getNumberOfComponents()];
416         MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
417                                    _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>((int *)tmpp));
418         std::copy((const int *)tmpp,(const int *)tmpp+(_end-_start)*arr->getNumberOfComponents(),startFeeding);
419         break;
420       }
421     default:
422       throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
423     }
424 }
425
426 /*!
427  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
428  */
429 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart) throw(INTERP_KERNEL::Exception)
430 {
431   int delta=_end-_start;
432   _start=newValueOfStart;
433   _end=_start+delta;
434 }
435
436 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
437 {
438   return _father->getIteration();
439 }
440
441 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
442 {
443   return _father->getOrder();
444 }
445
446 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
447 {
448   return _father->getTime();
449 }
450
451 std::string MEDFileFieldPerMeshPerTypePerDisc::getName() const
452 {
453   return _father->getName();
454 }
455
456 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
457 {
458   return _father->getMeshName();
459 }
460
461 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
462 {
463   const char startLine[]="    ## ";
464   std::string startLine2(bkOffset,' ');
465   startLine2+=startLine;
466   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
467   oss << startLine2 << "Localization #" << id << "." << std::endl;
468   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
469   delete tmp;
470   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
471   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
472   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
473 }
474
475 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
476 {
477   return _type;
478 }
479
480 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
481 {
482   types.insert(_type);
483 }
484
485 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
486 {
487   _type=newType;
488 }
489
490 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
491 {
492   return _father->getGeoType();
493 }
494
495 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
496 {
497   return _father->getNumberOfComponents();
498 }
499
500 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
501 {
502   return _end-_start;
503 }
504
505 DataArrayDouble *MEDFileFieldPerMeshPerTypePerDisc::getArray()
506 {
507   return _father->getArray();
508 }
509
510 const DataArrayDouble *MEDFileFieldPerMeshPerTypePerDisc::getArray() const
511 {
512   const MEDFileFieldPerMeshPerType *fath=_father;
513   return fath->getArray();
514 }
515
516 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
517 {
518   return _father->getInfo();
519 }
520
521 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
522 {
523   return _profile;
524 }
525
526 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const char *newPflName)
527 {
528   _profile=newPflName;
529 }
530
531 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
532 {
533   return _localization;
534 }
535
536 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const char *newLocName)
537 {
538   _localization=newLocName;
539 }
540
541 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
542 {
543   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
544     {
545       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
546         {
547           _profile=(*it2).second;
548           return;
549         }
550     }
551 }
552
553 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
554 {
555   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
556     {
557       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
558         {
559           _localization=(*it2).second;
560           return;
561         }
562     }
563 }
564
565 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
566 {
567   if(type!=_type)
568     return ;
569   dads.push_back(std::pair<int,int>(_start,_end));
570   geoTypes.push_back(getGeoType());
571   if(_profile.empty())
572     pfls.push_back(0);
573   else
574     {
575       pfls.push_back(glob->getProfile(_profile.c_str()));
576     }
577   if(_localization.empty())
578     locs.push_back(-1);
579   else
580     {
581       locs.push_back(glob->getLocalizationId(_localization.c_str()));
582     }
583 }
584
585 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
586 {
587   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));
588   startEntryId++;
589 }
590
591 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
592 {
593   TypeOfField type=getType();
594   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
595   med_geometry_type mgeoti;
596   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
597   const DataArrayDouble *arr=getArray();
598   const double *locToWrite=arr->getConstPointer()+_start*arr->getNumberOfComponents();
599   MEDfieldValueWithProfileWr(fid,getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
600                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
601                              reinterpret_cast<const unsigned char*>(locToWrite));
602 }
603
604 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const throw(INTERP_KERNEL::Exception)
605 {
606   type=_type;
607   pfl=_profile;
608   loc=_localization;
609   dad.first=_start; dad.second=_end;
610 }
611
612 /*!
613  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
614  *             This code corresponds to the distribution of types in the corresponding mesh.
615  * \param [out] ptToFill memory zone where the output will be stored.
616  * \return the size of data pushed into output param \a ptToFill
617  */
618 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const throw(INTERP_KERNEL::Exception)
619 {
620   _loc_id=offset;
621   std::ostringstream oss;
622   std::size_t nbOfType=codeOfMesh.size()/3;
623   std::size_t found=-1;
624   for(std::size_t i=0;i<nbOfType && found==-1;i++)
625     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
626       found=i;
627   if(found==-1)
628     {
629       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
630       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
631       throw INTERP_KERNEL::Exception(oss.str().c_str());
632     }
633   int *work=ptToFill;
634   if(_profile.empty())
635     {
636       if(_nval!=codeOfMesh[3*found+1])
637         {
638           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
639           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
640           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
641           throw INTERP_KERNEL::Exception(oss.str().c_str());
642         }
643       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
644         *work++=ii;
645     }
646   else
647     {
648       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
649       if(pfl->getNumberOfTuples()!=_nval)
650         {
651           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
652           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
653           oss << _nval;
654           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
655           throw INTERP_KERNEL::Exception(oss.str().c_str());
656         }
657       int offset=codeOfMesh[3*found+2];
658       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
659         {
660           if(*pflId<codeOfMesh[3*found+1])
661             *work++=offset+*pflId;
662         }
663     }
664   return _nval;
665 }
666
667 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const throw(INTERP_KERNEL::Exception)
668 {
669   for(int i=_start;i<_end;i++)
670     *ptToFill++=i;
671   return _end-_start;
672 }
673
674 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId) throw(INTERP_KERNEL::Exception)
675 {
676   switch(type)
677     {
678     case ON_CELLS:
679       return -2;
680     case ON_GAUSS_NE:
681       return -1;
682     case ON_GAUSS_PT:
683       return locId;
684     default:
685       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
686     }
687 }
688
689 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
690 {
691   int id=0;
692   std::map<std::pair<std::string,TypeOfField>,int> m;
693   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
694   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
695     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
696       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
697   ret.resize(id);
698   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
699     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
700   return ret;
701 }
702
703 /*!
704  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
705  * 
706  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
707  * \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.
708  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
709  * \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)
710  * \param [in,out] glob if necessary by the method, new profiles can be added to it
711  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
712  * \param [out] result All new entries will be appended on it.
713  * \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 !)
714  */
715 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
716                                                        const DataArrayInt *explicitIdsInMesh,
717                                                        const std::vector<int>& newCode,
718                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
719                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
720 {
721   if(entriesOnSameDisc.empty())
722     return false;
723   TypeOfField type=entriesOnSameDisc[0]->getType();
724   int szEntities=0,szTuples=0;
725   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
726     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
727   int nbi=szTuples/szEntities;
728   if(szTuples%szEntities!=0)
729     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
730   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
731   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
732   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
733   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
734   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
735   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
736   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
737   int id=0;
738   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
739     {
740       int startOfEltIdOfChunk=(*it)->_start;
741       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
742       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
743       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
744       //
745       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
746       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
747       //
748       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
749       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
750     }
751   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
752   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
753   std::set<int> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
754   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
755   //
756   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
757   //
758   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
759   arrPart->renumberInPlace(renumTupleIds->begin());
760   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
761   bool ret=false;
762   std::set<int>::const_iterator idIt=diffVals.begin();
763   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
764   int offset2=0;
765   for(std::size_t i=0;i<diffVals.size();i++,idIt++)
766     {
767       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
768       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
769       int nbEntityElts=subIds->getNumberOfTuples();
770       bool ret2;
771       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
772         NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
773                                     offset+offset2,
774                                     li,glob,ret2);
775       ret=ret || ret2;
776       result.push_back(eltToAdd);
777       offset2+=nbEntityElts*nbi;
778     }
779   ret=ret || li.empty();
780   return ret;
781 }
782
783 /*!
784  * \param [in] typeF type of field of new chunk
785  * \param [in] geoType the geometric type of the chunk
786  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
787  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
788  * \param [in] nbi number of integration points
789  * \param [in] offset The offset in the **global array of data**.
790  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
791  *                 to the new chunk to create.
792  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
793  * \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
794  *              and corresponding entry erased from \a entriesOnSameDisc.
795  * \return a newly allocated chunk
796  */
797 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
798                                                                                                   bool isPfl, int nbi, int offset,
799                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
800                                                                                                   MEDFileFieldGlobsReal& glob,
801                                                                                                   bool &notInExisting) throw(INTERP_KERNEL::Exception)
802 {
803   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
804   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
805   for(;it!=entriesOnSameDisc.end();it++)
806     {
807       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
808         {
809           if(!isPfl)
810             if((*it)->_profile.empty())
811               break;
812             else
813               if(!(*it)->_profile.empty())
814                 {
815                   const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
816                   if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
817                     break;
818                 }
819         }
820     }
821   if(it==entriesOnSameDisc.end())
822     {
823       notInExisting=true;
824       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
825       ret->_type=typeF;
826       ret->_loc_id=(int)geoType;
827       ret->_nval=nbMeshEntities;
828       ret->_start=offset;
829       ret->_end=ret->_start+ret->_nval*nbi;
830       if(isPfl)
831         {
832           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
833           glob.appendProfile(idsOfMeshElt);
834           ret->_profile=idsOfMeshElt->getName();
835         }
836       //tony treatment of localization
837       return ret;
838     }
839   else
840     {
841       notInExisting=false;
842       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
843       ret->_loc_id=(int)geoType;
844       ret->setNewStart(offset);
845       entriesOnSameDisc.erase(it);
846       return ret;
847     }
848   
849 }
850
851 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
852 {
853   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType);
854 }
855
856 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
857 {
858   return new MEDFileFieldPerMeshPerType(fath,geoType);
859 }
860
861 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
862 {
863   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
864   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
865     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,glob);
866 }
867
868 void MEDFileFieldPerMeshPerType::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
869 {
870   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
871   if(locIds)
872     {
873       //
874       std::string pflName(locIds->getName());
875       if(pflName.empty())
876         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignFieldProfile : existing profile with empty name !");
877       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
878       std::ostringstream oss; oss << pflName << "_" <<  cm.getRepr();
879       locIds->setName(oss.str().c_str());
880       glob.appendProfile(locIds);
881       //
882       for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
883         _field_pm_pt_pd[*it]->assignFieldProfile(start,oss.str().c_str(),multiTypePfl,idsInPfl,field,mesh,glob);
884     }
885   else
886     {
887       for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
888         _field_pm_pt_pd[*it]->assignFieldProfile(start,0,multiTypePfl,idsInPfl,field,mesh,glob);
889     }
890 }
891
892 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
893 {
894   _field_pm_pt_pd.resize(1);
895   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
896   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,glob);
897 }
898
899 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
900 {
901   std::string pflName(pfl->getName());
902   if(pflName.empty())
903     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : existing profile with empty name !");
904   std::ostringstream oss; oss << pflName << "_NODE";
905   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
906   pfl2->setName(oss.str().c_str());
907   glob.appendProfile(pfl2);
908   //
909   _field_pm_pt_pd.resize(1);
910   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
911   _field_pm_pt_pd[0]->assignFieldProfile(start,oss.str().c_str(),pfl,pfl2,field,0,glob);//mesh is not requested so 0 is send.
912 }
913
914 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
915 {
916   TypeOfField type=field->getTypeOfField();
917   if(type!=ON_GAUSS_PT)
918     {
919       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
920       int sz=_field_pm_pt_pd.size();
921       bool found=false;
922       for(int j=0;j<sz && !found;j++)
923         {
924           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
925             {
926               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
927               found=true;
928             }
929         }
930       if(!found)
931         {
932           _field_pm_pt_pd.resize(sz+1);
933           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
934         }
935       std::vector<int> ret(1,0);
936       return ret;
937     }
938   else
939     {
940       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
941       int sz2=ret2.size();
942       std::vector<int> ret3(sz2);
943       int k=0;
944       for(int i=0;i<sz2;i++)
945         {
946           int sz=_field_pm_pt_pd.size();
947           int locIdToFind=ret2[i];
948           bool found=false;
949           for(int j=0;j<sz && !found;j++)
950             {
951               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
952                 {
953                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
954                   ret3[k++]=j;
955                   found=true;
956                 }
957             }
958           if(!found)
959             {
960               _field_pm_pt_pd.resize(sz+1);
961               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
962               ret3[k++]=sz;
963             }
964         }
965       return ret3;
966     }
967 }
968
969 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception)
970 {
971   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
972   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
973   if(!disc2)
974     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
975   const DataArrayInt *da=disc2->getArrayOfDiscIds();
976   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
977   std::set<int> retTmp=da2->getDifferentValues();
978   if(retTmp.find(-1)!=retTmp.end())
979     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
980   std::vector<int> ret(retTmp.begin(),retTmp.end());
981   return ret;
982 }
983
984 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
985 {
986   TypeOfField type=field->getTypeOfField();
987   if(type!=ON_GAUSS_PT)
988     {
989       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
990       int sz=_field_pm_pt_pd.size();
991       bool found=false;
992       for(int j=0;j<sz && !found;j++)
993         {
994           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
995             {
996               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
997               found=true;
998             }
999         }
1000       if(!found)
1001         {
1002           _field_pm_pt_pd.resize(sz+1);
1003           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1004         }
1005       std::vector<int> ret(1,0);
1006       return ret;
1007     }
1008   else
1009     {
1010       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1011       int sz2=ret2.size();
1012       std::vector<int> ret3(sz2);
1013       int k=0;
1014       for(int i=0;i<sz2;i++)
1015         {
1016           int sz=_field_pm_pt_pd.size();
1017           int locIdToFind=ret2[i];
1018           bool found=false;
1019           for(int j=0;j<sz && !found;j++)
1020             {
1021               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1022                 {
1023                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1024                   ret3[k++]=j;
1025                   found=true;
1026                 }
1027             }
1028           if(!found)
1029             {
1030               _field_pm_pt_pd.resize(sz+1);
1031               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1032               ret3[k++]=sz;
1033             }
1034         }
1035       return ret3;
1036     }
1037 }
1038
1039 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception)
1040 {
1041   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1042   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1043   if(!disc2)
1044     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1045   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1046   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1047   std::set<int> retTmp=da2->getDifferentValues();
1048   if(retTmp.find(-1)!=retTmp.end())
1049     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1050   std::vector<int> ret(retTmp.begin(),retTmp.end());
1051   return ret;
1052 }
1053
1054 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1055 {
1056   return _father;
1057 }
1058
1059 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1060 {
1061   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1062   int curDim=(int)cm.getDimension();
1063   dim=std::max(dim,curDim);
1064 }
1065
1066 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1067 {
1068   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1069     {
1070       (*it)->fillTypesOfFieldAvailable(types);
1071     }
1072 }
1073
1074 void MEDFileFieldPerMeshPerType::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const throw(INTERP_KERNEL::Exception)
1075 {
1076   int sz=_field_pm_pt_pd.size();
1077   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1078   for(int i=0;i<sz;i++)
1079     {
1080       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1081     }
1082 }
1083
1084 int MEDFileFieldPerMeshPerType::getIteration() const
1085 {
1086   return _father->getIteration();
1087 }
1088
1089 int MEDFileFieldPerMeshPerType::getOrder() const
1090 {
1091   return _father->getOrder();
1092 }
1093
1094 double MEDFileFieldPerMeshPerType::getTime() const
1095 {
1096   return _father->getTime();
1097 }
1098
1099 std::string MEDFileFieldPerMeshPerType::getName() const
1100 {
1101   return _father->getName();
1102 }
1103
1104 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1105 {
1106   return _father->getMeshName();
1107 }
1108
1109 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1110 {
1111   const char startLine[]="  ## ";
1112   std::string startLine2(bkOffset,' ');
1113   std::string startLine3(startLine2);
1114   startLine3+=startLine;
1115   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1116     {
1117       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1118       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1119     }
1120   else
1121     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1122   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1123   int i=0;
1124   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1125     {
1126       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1127       if(cur)
1128         cur->simpleRepr(bkOffset,oss,i);
1129       else
1130         {
1131           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1132         }
1133     }
1134 }
1135
1136 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1137 {
1138   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1139     {
1140       globalSz+=(*it)->getNumberOfTuples();
1141     }
1142   nbOfEntries+=(int)_field_pm_pt_pd.size();
1143 }
1144
1145 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1146 {
1147   return _geo_type;
1148 }
1149
1150
1151 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1152 {
1153   return _father->getNumberOfComponents();
1154 }
1155
1156 DataArrayDouble *MEDFileFieldPerMeshPerType::getArray()
1157 {
1158   return _father->getArray();
1159 }
1160
1161 const DataArrayDouble *MEDFileFieldPerMeshPerType::getArray() const
1162 {
1163   const MEDFileFieldPerMesh *fath=_father;
1164   return fath->getArray();
1165 }
1166
1167 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1168 {
1169   return _father->getInfo();
1170 }
1171
1172 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1173 {
1174   std::vector<std::string> ret;
1175   std::set<std::string> ret2;
1176   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1177     {
1178       std::string tmp=(*it1)->getProfile();
1179       if(!tmp.empty())
1180         if(ret2.find(tmp)==ret2.end())
1181           {
1182             ret.push_back(tmp);
1183             ret2.insert(tmp);
1184           }
1185     }
1186   return ret;
1187 }
1188
1189 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1190 {
1191   std::vector<std::string> ret;
1192   std::set<std::string> ret2;
1193   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1194     {
1195       std::string tmp=(*it1)->getLocalization();
1196       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1197         if(ret2.find(tmp)==ret2.end())
1198           {
1199             ret.push_back(tmp);
1200             ret2.insert(tmp);
1201           }
1202     }
1203   return ret;
1204 }
1205
1206 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1207 {
1208   std::vector<std::string> ret;
1209   std::set<std::string> ret2;
1210   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1211     {
1212       std::string tmp=(*it1)->getProfile();
1213       if(!tmp.empty())
1214         ret.push_back(tmp);
1215     }
1216   return ret;
1217 }
1218
1219 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1220 {
1221   std::vector<std::string> ret;
1222   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1223     {
1224       std::string tmp=(*it1)->getLocalization();
1225       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1226         ret.push_back(tmp);
1227     }
1228   return ret;
1229 }
1230
1231 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1232 {
1233   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1234     (*it1)->changePflsRefsNamesGen(mapOfModif);
1235 }
1236
1237 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1238 {
1239   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1240     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1241 }
1242
1243 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) throw(INTERP_KERNEL::Exception)
1244 {
1245   if(_field_pm_pt_pd.empty())
1246     {
1247       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1248       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1249       throw INTERP_KERNEL::Exception(oss.str().c_str());
1250     }
1251   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1252     return _field_pm_pt_pd[locId];
1253   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1254   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1255   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1256   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1257   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1258 }
1259
1260 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const throw(INTERP_KERNEL::Exception)
1261 {
1262   if(_field_pm_pt_pd.empty())
1263     {
1264       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1265       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1266       throw INTERP_KERNEL::Exception(oss.str().c_str());
1267     }
1268   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1269     return _field_pm_pt_pd[locId];
1270   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1271   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1272   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1273   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1274   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1275 }
1276
1277 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
1278 {
1279   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1280     {
1281       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1282       if(meshDim!=(int)cm.getDimension())
1283         return ;
1284     }
1285   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1286     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1287 }
1288
1289 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1290 {
1291   int i=0;
1292   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1293     {
1294       (*it)->fillValues(i,startEntryId,entries);
1295     }
1296 }
1297
1298 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1299 {
1300   _field_pm_pt_pd=leaves;
1301   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1302     (*it)->setFather(this);
1303 }
1304
1305 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType)
1306 {
1307 }
1308
1309 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType)
1310 {
1311   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1312   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1313   med_geometry_type mgeoti;
1314   med_entity_type menti=ConvertIntoMEDFileType(type,geoType,mgeoti);
1315   int nbProfiles=MEDfieldnProfile(fid,getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName);
1316   _field_pm_pt_pd.resize(nbProfiles);
1317   for(int i=0;i<nbProfiles;i++)
1318     {
1319       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i+1);
1320     }
1321 }
1322
1323 void MEDFileFieldPerMeshPerType::prepareLoading(med_idt fid, int &start) throw(INTERP_KERNEL::Exception)
1324 {
1325   int pflId=0;
1326   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1327     {
1328       (*it)->prepareLoading(fid,pflId+1,start);
1329     }
1330 }
1331
1332 void MEDFileFieldPerMeshPerType::finishLoading(med_idt fid, int ft) throw(INTERP_KERNEL::Exception)
1333 {
1334   int pflId=0;
1335   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,pflId++)
1336     {
1337       (*it)->finishLoading(fid,pflId+1,ft);
1338     }
1339 }
1340
1341 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
1342 {
1343   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1344     {
1345       (*it)->copyOptionsFrom(*this);
1346       (*it)->writeLL(fid);
1347     }
1348 }
1349
1350 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1351 {
1352   switch(ikType)
1353     {
1354     case ON_CELLS:
1355       medfGeoType=typmai3[(int)ikGeoType];
1356       return MED_CELL;
1357     case ON_NODES:
1358       medfGeoType=MED_NONE;
1359       return MED_NODE;
1360     case ON_GAUSS_NE:
1361       medfGeoType=typmai3[(int)ikGeoType];
1362       return MED_NODE_ELEMENT;
1363     case ON_GAUSS_PT:
1364       medfGeoType=typmai3[(int)ikGeoType];
1365       return MED_CELL;
1366     default:
1367       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1368     }
1369   return MED_UNDEF_ENTITY_TYPE;
1370 }
1371
1372 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder) throw(INTERP_KERNEL::Exception)
1373 {
1374   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder);
1375 }
1376
1377 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1378 {
1379   return new MEDFileFieldPerMesh(fath,mesh);
1380 }
1381
1382 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1383 {
1384   std::string startLine(bkOffset,' ');
1385   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1386   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1387   int i=0;
1388   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1389     {
1390       const MEDFileFieldPerMeshPerType *cur=*it;
1391       if(cur)
1392         cur->simpleRepr(bkOffset,oss,i);
1393       else
1394         {
1395           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1396         }
1397     }
1398 }
1399
1400 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
1401 {
1402   _mesh_name=mesh->getName();
1403   mesh->getTime(_mesh_iteration,_mesh_order);
1404 }
1405
1406 void MEDFileFieldPerMesh::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector<int>& code, const std::vector<DataArrayInt *>& idsInPflPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1407 {
1408   int nbOfTypes=code.size()/3;
1409   bool isProfile=false;
1410   for(int i=0;i<nbOfTypes;i++)
1411     if(code[3*i+2]!=-1)
1412       isProfile=true;
1413   if(!isProfile)
1414     {
1415       if(idsInPflPerType.empty())
1416         assignFieldNoProfileNoRenum(start,code,field,glob);
1417       else
1418         assignFieldProfileGeneral(start,multiTypePfl,code,idsInPflPerType,idsPerType,field,mesh,glob);
1419     }
1420   else
1421     assignFieldProfileGeneral(start,multiTypePfl,code,idsInPflPerType,idsPerType,field,mesh,glob);
1422 }
1423
1424 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1425 {
1426   int nbOfTypes=code.size()/3;
1427   int offset=0;
1428   for(int i=0;i<nbOfTypes;i++)
1429     {
1430       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1431       int nbOfCells=code[3*i+1];
1432       int pos=addNewEntryIfNecessary(type);
1433       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,glob);
1434       offset+=nbOfCells;
1435     }
1436 }
1437
1438 /*!
1439  * This method is the most general one. No optimization is done here.
1440  */
1441 void MEDFileFieldPerMesh::assignFieldProfileGeneral(int& start, const DataArrayInt *multiTypePfl, const std::vector<int>& code, const std::vector<DataArrayInt *>& idsInPflPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1442 {
1443   int nbOfTypes=code.size()/3;
1444   for(int i=0;i<nbOfTypes;i++)
1445     {
1446       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1447       int pos=addNewEntryIfNecessary(type);
1448       DataArrayInt *pfl=0;
1449       if(code[3*i+2]!=-1)
1450         pfl=idsPerType[code[3*i+2]];
1451       _field_pm_pt[pos]->assignFieldProfile(start,multiTypePfl,idsInPflPerType[i],pfl,field,mesh,glob);
1452     }
1453 }
1454
1455 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1456 {
1457   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1458   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,glob);
1459 }
1460
1461 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1462 {
1463   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1464   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,glob);
1465 }
1466
1467 void MEDFileFieldPerMesh::prepareLoading(med_idt fid, int& start) throw(INTERP_KERNEL::Exception)
1468 {
1469   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1470     (*it)->prepareLoading(fid,start);
1471 }
1472
1473 void MEDFileFieldPerMesh::finishLoading(med_idt fid, int ft) throw(INTERP_KERNEL::Exception)
1474 {
1475   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1476     (*it)->finishLoading(fid,ft);
1477 }
1478
1479 void MEDFileFieldPerMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
1480 {
1481   int nbOfTypes=_field_pm_pt.size();
1482   for(int i=0;i<nbOfTypes;i++)
1483     {
1484       _field_pm_pt[i]->copyOptionsFrom(*this);
1485       _field_pm_pt[i]->writeLL(fid);
1486     }
1487 }
1488
1489 void MEDFileFieldPerMesh::getDimension(int& dim) const
1490 {
1491   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1492     (*it)->getDimension(dim);
1493 }
1494
1495 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
1496 {
1497   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1498     (*it)->fillTypesOfFieldAvailable(types);
1499 }
1500
1501 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 throw(INTERP_KERNEL::Exception)
1502 {
1503   int sz=_field_pm_pt.size();
1504   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1505   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1506   for(int i=0;i<sz;i++)
1507     {
1508       types[i]=_field_pm_pt[i]->getGeoType();
1509       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1510     }
1511   return ret;
1512 }
1513
1514 double MEDFileFieldPerMesh::getTime() const
1515 {
1516   int tmp1,tmp2;
1517   return _father->getTime(tmp1,tmp2);
1518 }
1519
1520 int MEDFileFieldPerMesh::getIteration() const
1521 {
1522   return _father->getIteration();
1523 }
1524
1525 const std::string& MEDFileFieldPerMesh::getDtUnit() const
1526 {
1527   return _father->getDtUnit();
1528 }
1529
1530 int MEDFileFieldPerMesh::getOrder() const
1531 {
1532   return _father->getOrder();
1533 }
1534
1535 std::string MEDFileFieldPerMesh::getName() const
1536 {
1537   return _father->getName();
1538 }
1539
1540 int MEDFileFieldPerMesh::getNumberOfComponents() const
1541 {
1542   return _father->getNumberOfComponents();
1543 }
1544
1545 DataArrayDouble *MEDFileFieldPerMesh::getArray()
1546 {
1547   return _father->getOrCreateAndGetArray();
1548 }
1549
1550 const DataArrayDouble *MEDFileFieldPerMesh::getArray() const
1551 {
1552   const MEDFileField1TSWithoutSDA *fath=_father;
1553   return fath->getOrCreateAndGetArray();
1554 }
1555
1556 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1557 {
1558   return _father->getInfo();
1559 }
1560
1561 /*!
1562  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1563  * 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.
1564  * It returns 2 output vectors :
1565  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1566  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1567  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1568  */
1569 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)
1570 {
1571   int notNullPflsSz=0;
1572   int nbOfArrs=geoTypes.size();
1573   for(int i=0;i<nbOfArrs;i++)
1574     if(pfls[i])
1575       notNullPflsSz++;
1576   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1577   int nbOfDiffGeoTypes=geoTypes3.size();
1578   code.resize(3*nbOfDiffGeoTypes);
1579   notNullPfls.resize(notNullPflsSz);
1580   notNullPflsSz=0;
1581   int j=0;
1582   for(int i=0;i<nbOfDiffGeoTypes;i++)
1583     {
1584       int startZone=j;
1585       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1586       std::vector<const DataArrayInt *> notNullTmp;
1587       if(pfls[j])
1588         notNullTmp.push_back(pfls[j]);
1589       j++;
1590       for(;j<nbOfArrs;j++)
1591         if(geoTypes[j]==refType)
1592           {
1593             if(pfls[j])
1594               notNullTmp.push_back(pfls[j]);
1595           }
1596         else
1597           break;
1598       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1599       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1600       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1601       code[3*i]=(int)refType;
1602       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1603       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1604       if(notNullTmp.empty())
1605         code[3*i+2]=-1;
1606       else
1607         {
1608           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1609           code[3*i+2]=notNullPflsSz++;
1610         }
1611     }
1612 }
1613
1614 /*!
1615  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1616  */
1617 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) throw(INTERP_KERNEL::Exception)
1618 {
1619   int sz=dads.size();
1620   int ret=0;
1621   for(int i=0;i<sz;i++)
1622     {
1623       if(locs[i]==-1)
1624         {
1625           if(type!=ON_GAUSS_NE)
1626             ret+=dads[i].second-dads[i].first;
1627           else
1628             {
1629               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1630               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1631             }
1632         }
1633       else
1634         {
1635           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1636           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1637         }
1638     }
1639   return ret;
1640 }
1641
1642 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1643 {
1644   std::vector<std::string> ret;
1645   std::set<std::string> ret2;
1646   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1647     {
1648       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1649       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1650         if(ret2.find(*it2)==ret2.end())
1651           {
1652             ret.push_back(*it2);
1653             ret2.insert(*it2);
1654           }
1655     }
1656   return ret;
1657 }
1658
1659 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1660 {
1661   std::vector<std::string> ret;
1662   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1663     {
1664       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1665       ret.insert(ret.end(),tmp.begin(),tmp.end());
1666     }
1667   return ret;
1668 }
1669
1670 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1671 {
1672   std::vector<std::string> ret;
1673   std::set<std::string> ret2;
1674   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1675     {
1676       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1677       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1678         if(ret2.find(*it2)==ret2.end())
1679           {
1680             ret.push_back(*it2);
1681             ret2.insert(*it2);
1682           }
1683     }
1684   return ret;
1685 }
1686
1687 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1688 {
1689   std::vector<std::string> ret;
1690   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1691     {
1692       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1693       ret.insert(ret.end(),tmp.begin(),tmp.end());
1694     }
1695   return ret;
1696 }
1697
1698 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
1699 {
1700   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1701     {
1702       if((*it).first==_mesh_name)
1703         {
1704           _mesh_name=(*it).second;
1705           return true;
1706         }
1707     }
1708   return false;
1709 }
1710
1711 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1712                                                       MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
1713 {
1714   if(_mesh_name!=meshName)
1715     return false;
1716   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1717   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1718   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1719   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1720   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1721   DataArrayDouble *arr=getUndergroundDataArrayExt(entries);
1722   int sz=0;
1723   if(!arr)
1724     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1725   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1726     {
1727       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1728         {
1729           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1730           sz+=(*it).second.second-(*it).second.first;
1731         }
1732       else
1733         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1734     }
1735   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1736   ////////////////////
1737   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1738   int *workI2=explicitIdsOldInMesh->getPointer();
1739   int sz1=0,sz2=0,sid=1;
1740   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1741   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1742   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1743     {
1744       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1745       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1746       int *workI=explicitIdsOldInArr->getPointer();
1747       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1748         {
1749           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1750           (*itL2)->setLocId(sz2);
1751           (*itL2)->_tmp_work1=(*itL2)->getStart();
1752           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1753         }
1754       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1755     }
1756   explicitIdsOldInMesh->reAlloc(sz2);
1757   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1758   ////////////////////
1759   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1760   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1761   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1762   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1763     {
1764       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1765       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1766       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1767     }
1768   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1769   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1770   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
1771     {
1772       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1773       int newStart=elt->getLocId();
1774       elt->setLocId((*it)->getGeoType());
1775       elt->setNewStart(newStart);
1776       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
1777       entriesKeptNew.push_back(elt);
1778       entriesKeptNew2.push_back(elt);
1779     }
1780   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
1781   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
1782   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
1783   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
1784   bool ret=false;
1785   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
1786     {
1787       sid=0;
1788       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
1789         {
1790           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
1791           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
1792           }*/
1793       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
1794                                                             glob,arr2,otherEntriesNew) || ret;
1795     }
1796   if(!ret)
1797     return false;
1798   // Assign new dispatching
1799   assignNewLeaves(otherEntriesNew);
1800   arr->cpyFrom(*arr2);
1801   return true;
1802 }
1803
1804 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves) throw(INTERP_KERNEL::Exception)
1805 {
1806   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
1807   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
1808     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
1809   //
1810   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
1811   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
1812   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
1813   for(;it1!=types.end();it1++,it2++)
1814     {
1815       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
1816       elt->setLeaves((*it1).second);
1817       *it2=elt;
1818     }
1819   _field_pm_pt=fieldPmPt;
1820 }
1821
1822 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1823 {
1824   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1825     (*it)->changePflsRefsNamesGen(mapOfModif);
1826 }
1827
1828 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
1829 {
1830   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1831     (*it)->changeLocsRefsNamesGen(mapOfModif);
1832 }
1833
1834 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception)
1835 {
1836   if(_field_pm_pt.empty())
1837     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
1838   //
1839   std::vector< std::pair<int,int> > dads;
1840   std::vector<const DataArrayInt *> pfls;
1841   std::vector<DataArrayInt *> notNullPflsPerGeoType;
1842   std::vector<int> locs,code;
1843   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
1844   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1845     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
1846   // Sort by types
1847   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
1848   if(code.empty())
1849     {
1850       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << getName() << "\" exists but not with such spatial discretization or such dimension specified !";
1851       throw INTERP_KERNEL::Exception(oss.str().c_str());
1852     }
1853   //
1854   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
1855   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
1856   if(type!=ON_NODES)
1857     {
1858       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
1859       if(!arr)
1860         return finishField(type,glob,dads,locs,mesh,isPfl);
1861       else
1862         {
1863           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
1864           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl);
1865         }
1866     }
1867   else
1868     {
1869       if(code.size()!=3)
1870         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
1871       int nb=code[1];
1872       if(code[2]==-1)
1873         {
1874           if(nb!=mesh->getNumberOfNodes())
1875             {
1876               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
1877               oss << " nodes in mesh !";
1878               throw INTERP_KERNEL::Exception(oss.str().c_str());
1879             }
1880           return finishField(type,glob,dads,locs,mesh,isPfl);
1881         }
1882       else
1883         return finishField3(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl);
1884     }
1885 }
1886
1887 DataArrayDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
1888 {
1889   if(_field_pm_pt.empty())
1890     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
1891   //
1892   std::vector<std::pair<int,int> > dads;
1893   std::vector<const DataArrayInt *> pfls;
1894   std::vector<DataArrayInt *> notNullPflsPerGeoType;
1895   std::vector<int> locs,code;
1896   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
1897   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1898     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
1899   // Sort by types
1900   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
1901   if(code.empty())
1902     {
1903       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << getName() << "\" exists but not with such spatial discretization or such dimension specified !";
1904       throw INTERP_KERNEL::Exception(oss.str().c_str());
1905     }
1906   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
1907   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
1908   if(type!=ON_NODES)
1909     {
1910       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
1911       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
1912     }
1913   else
1914     {
1915       if(code.size()!=3)
1916         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
1917       int nb=code[1];
1918       if(code[2]==-1)
1919         {
1920           if(nb!=mesh->getNumberOfNodes())
1921             {
1922               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
1923               oss << " nodes in mesh !";
1924               throw INTERP_KERNEL::Exception(oss.str().c_str());
1925             }
1926         }
1927       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
1928     }
1929   //
1930   return 0;
1931 }
1932
1933 DataArrayDouble *MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
1934 {
1935   int globalSz=0;
1936   int nbOfEntries=0;
1937   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1938     {
1939       (*it)->getSizes(globalSz,nbOfEntries);
1940     }
1941   entries.resize(nbOfEntries);
1942   nbOfEntries=0;
1943   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1944     {
1945       (*it)->fillValues(nbOfEntries,entries);
1946     }
1947   return _father->getUndergroundDataArray();
1948 }
1949
1950 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
1951 {
1952   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1953     {
1954       if((*it)->getGeoType()==typ)
1955         return (*it)->getLeafGivenLocId(locId);
1956     }
1957   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
1958   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
1959   oss << "Possiblities are : ";
1960   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1961     {
1962       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
1963       oss << "\"" << cm2.getRepr() << "\", ";
1964     }
1965   throw INTERP_KERNEL::Exception(oss.str().c_str());
1966 }
1967
1968 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
1969 {
1970   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1971     {
1972       if((*it)->getGeoType()==typ)
1973         return (*it)->getLeafGivenLocId(locId);
1974     }
1975   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
1976   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
1977   oss << "Possiblities are : ";
1978   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1979     {
1980       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
1981       oss << "\"" << cm2.getRepr() << "\", ";
1982     }
1983   throw INTERP_KERNEL::Exception(oss.str().c_str());
1984 }
1985
1986 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
1987 {
1988   int i=0;
1989   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
1990   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
1991   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1992     {
1993       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
1994       if(type==curType)
1995         return i;
1996       else
1997         {
1998           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
1999           if(pos>pos2)
2000             it2=it+1;
2001         }
2002     }
2003   int ret=std::distance(_field_pm_pt.begin(),it2);
2004   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2005   return ret;
2006 }
2007
2008 /*!
2009  * 'dads' and 'locs' input parameters have the same number of elements.
2010  */
2011 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2012                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2013                                                          const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception)
2014 {
2015   isPfl=false;
2016   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2017   ret->setMesh(mesh); ret->setName(getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(getDtUnit().c_str());
2018   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=getArray()->selectByTupleRanges(dads);
2019   const std::vector<std::string>& infos=getInfo();
2020   da->setInfoOnComponents(infos);
2021   da->setName("");
2022   ret->setArray(da);
2023   if(type==ON_GAUSS_PT)
2024     {
2025       int offset=0;
2026       int nbOfArrs=dads.size();
2027       for(int i=0;i<nbOfArrs;i++)
2028         {
2029           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2030           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2031           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2032           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2033           di->alloc(nbOfElems,1);
2034           di->iota(offset);
2035           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2036           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2037           offset+=nbOfElems;
2038         }
2039     }
2040   //
2041   ret->incrRef();
2042   return ret;
2043 }
2044
2045 /*!
2046  * 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.
2047  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2048  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2049  * The order of cells in the returned field is those imposed by the profile.
2050  */
2051 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2052                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2053                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2054                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception)
2055 {
2056   if(da->isIdentity())
2057     {
2058       int nbOfTuples=da->getNumberOfTuples();
2059       if(nbOfTuples==mesh->getNumberOfCells())
2060         return finishField(type,glob,dads,locs,mesh,isPfl);
2061     }
2062   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,mesh,isPfl);
2063   isPfl=true;
2064   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2065   m2->setName(mesh->getName());
2066   ret->setMesh(m2);
2067   ret->incrRef();
2068   return ret;
2069 }
2070
2071 /*!
2072  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2073  */
2074 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField3(const MEDFileFieldGlobsReal *glob,
2075                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2076                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception)
2077 {
2078   if(da->isIdentity())
2079     {
2080       int nbOfTuples=da->getNumberOfTuples();
2081       const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2082       if(nbOfTuples==ComputeNbOfElems(glob,ON_NODES,geoTypes2,dads,locs))//No problem for NORM_ERROR because it is in context of node
2083         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl);
2084     }
2085   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2086   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2087   if(meshu)
2088     {
2089       if(meshu->getNodalConnectivity()==0)
2090         {
2091           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl);
2092           int nb=da->getNbOfElems();
2093           const int *ptr=da->getConstPointer();
2094           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2095           meshuc->allocateCells(nb);
2096           for(int i=0;i<nb;i++)
2097             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2098           meshuc->finishInsertingCells();
2099           ret->setMesh(meshuc);
2100           ret->checkCoherency();
2101           ret->incrRef();
2102           return ret;
2103         }
2104     }
2105   //
2106   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl);
2107   isPfl=true;
2108   DataArrayInt *arr2=0;
2109   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2110   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2111   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2112   int nnodes=mesh2->getNumberOfNodes();
2113   if(nnodes==da->getNbOfElems())
2114     {
2115       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->getConstPointer(),arr2->getConstPointer()+arr2->getNbOfElems());
2116       ret->getArray()->renumberInPlace(da3->getConstPointer());
2117       mesh2->setName(mesh->getName());
2118       ret->setMesh(mesh2);
2119       ret->incrRef();
2120       return ret;
2121     }
2122   else
2123     {
2124       std::ostringstream oss; oss << "MEDFileFieldPerMesh::finishField3 : 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 !!!";
2125       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2126       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2127       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2128       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2129       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2130       throw INTERP_KERNEL::Exception(oss.str().c_str());
2131     }
2132   return 0;
2133 }
2134
2135 /*!
2136  * This method is the most light method of field retrieving.
2137  */
2138 DataArrayDouble *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const throw(INTERP_KERNEL::Exception)
2139 {
2140   if(!pflIn)
2141     {
2142       pflOut=DataArrayInt::New();
2143       pflOut->alloc(nbOfElems,1);
2144       pflOut->iota(0);
2145     }
2146   else
2147     {
2148       pflOut=const_cast<DataArrayInt*>(pflIn);
2149       pflOut->incrRef();
2150     }
2151   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2152   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=getArray()->selectByTupleRanges(dads);
2153   const std::vector<std::string>& infos=getInfo();
2154   int nbOfComp=infos.size();
2155   for(int i=0;i<nbOfComp;i++)
2156     da->setInfoOnComponent(i,infos[i].c_str());
2157   safePfl->incrRef();
2158   da->incrRef();
2159   return da;
2160 }
2161
2162 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder) throw(INTERP_KERNEL::Exception):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2163                                                                                                                                                                        _mesh_csit(meshCsit),_father(fath)
2164 {
2165   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2166   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2167   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2168   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2169     {
2170       int nbProfile=MEDfield23nProfile(fid,getName().c_str(),getIteration(),getOrder(),MED_CELL,typmai[i],_mesh_csit,meshName,pflName,locName);
2171       if(nbProfile>0)
2172         {
2173           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i]));
2174           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2175         }
2176       nbProfile=MEDfield23nProfile(fid,getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],_mesh_csit,meshName,pflName,locName);
2177       if(nbProfile>0)
2178         {
2179           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_GAUSS_NE,typmai2[i]));
2180           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2181         }
2182     }
2183   int nbProfile=MEDfield23nProfile(fid,getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,_mesh_csit,meshName,pflName,locName);
2184   if(nbProfile>0)
2185     {
2186       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR));
2187       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2188     }
2189 }
2190
2191 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2192 {
2193   copyTinyInfoFrom(mesh);
2194 }
2195
2196 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
2197 {
2198   if(id>=(int)_pfls.size())
2199     _pfls.resize(id+1);
2200   _pfls[id]=DataArrayInt::New();
2201   int lgth=MEDprofileSizeByName(fid,pflName);
2202   _pfls[id]->setName(pflName);
2203   _pfls[id]->alloc(lgth,1);
2204   MEDprofileRd(fid,pflName,_pfls[id]->getPointer());
2205   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2206 }
2207
2208 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2209 {
2210   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2211   int sz;
2212   MEDprofileInfo(fid,i+1,pflName,&sz);
2213   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2214   if(i>=(int)_pfls.size())
2215     _pfls.resize(i+1);
2216   _pfls[i]=DataArrayInt::New();
2217   _pfls[i]->alloc(sz,1);
2218   _pfls[i]->setName(pflCpp.c_str());
2219   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2220   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2221 }
2222
2223 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
2224 {
2225   int nbOfPfls=_pfls.size();
2226   for(int i=0;i<nbOfPfls;i++)
2227     {
2228       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2229       cpy->applyLin(1,1,0);
2230       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2231       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2232       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2233     }
2234   //
2235   int nbOfLocs=_locs.size();
2236   for(int i=0;i<nbOfLocs;i++)
2237     _locs[i]->writeLL(fid);
2238 }
2239
2240 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps) throw(INTERP_KERNEL::Exception)
2241 {
2242   std::vector<std::string> pfls=getPfls();
2243   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2244     {
2245       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2246       if(it2==pfls.end())
2247         {
2248           _pfls.push_back(*it);
2249         }
2250       else
2251         {
2252           int id=std::distance(pfls.begin(),it2);
2253           if(!(*it)->isEqual(*_pfls[id]))
2254             {
2255               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2256               throw INTERP_KERNEL::Exception(oss.str().c_str());
2257             }
2258         }
2259     }
2260   std::vector<std::string> locs=getLocs();
2261   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2262     {
2263       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2264       if(it2==locs.end())
2265         {
2266           _locs.push_back(*it);
2267         }
2268       else
2269         {
2270           int id=std::distance(locs.begin(),it2);
2271           if(!(*it)->isEqual(*_locs[id],eps))
2272             {
2273               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2274               throw INTERP_KERNEL::Exception(oss.str().c_str());
2275             }
2276         }
2277     }
2278 }
2279
2280 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real) throw(INTERP_KERNEL::Exception)
2281 {
2282   std::vector<std::string> profiles=real.getPflsReallyUsed();
2283   int sz=profiles.size();
2284   _pfls.resize(sz);
2285   for(int i=0;i<sz;i++)
2286     loadProfileInFile(fid,i,profiles[i].c_str());
2287   //
2288   std::vector<std::string> locs=real.getLocsReallyUsed();
2289   sz=locs.size();
2290   _locs.resize(sz);
2291   for(int i=0;i<sz;i++)
2292     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2293 }
2294
2295 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2296 {
2297   int nProfil=MEDnProfile(fid);
2298   for(int i=0;i<nProfil;i++)
2299     loadProfileInFile(fid,i);
2300   int sz=MEDnLocalization(fid);
2301   _locs.resize(sz);
2302   for(int i=0;i<sz;i++)
2303     {
2304       _locs[i]=MEDFileFieldLoc::New(fid,i);
2305     }
2306 }
2307
2308 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const char *fname)
2309 {
2310   return new MEDFileFieldGlobs(fname);
2311 }
2312
2313 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2314 {
2315   return new MEDFileFieldGlobs;
2316 }
2317
2318 MEDFileFieldGlobs::MEDFileFieldGlobs(const char *fname):_file_name(fname)
2319 {
2320 }
2321
2322 MEDFileFieldGlobs::MEDFileFieldGlobs()
2323 {
2324 }
2325
2326 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2327 {
2328 }
2329
2330 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2331 {
2332   oss << "Profiles :\n";
2333   std::size_t n=_pfls.size();
2334   for(std::size_t i=0;i<n;i++)
2335     {
2336       oss << "  - #" << i << " ";
2337       const DataArrayInt *pfl=_pfls[i];
2338       if(pfl)
2339         oss << "\"" << pfl->getName() << "\"\n";
2340       else
2341         oss << "EMPTY !\n";
2342     }
2343   n=_locs.size();
2344   oss << "Localizations :\n";
2345   for(std::size_t i=0;i<n;i++)
2346     {
2347       oss << "  - #" << i << " ";
2348       const MEDFileFieldLoc *loc=_locs[i];
2349       if(loc)
2350         loc->simpleRepr(oss);
2351       else
2352         oss<< "EMPTY !\n";
2353     }
2354 }
2355
2356 void MEDFileFieldGlobs::setFileName(const char *fileName)
2357 {
2358   _file_name=fileName;
2359 }
2360
2361 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2362 {
2363   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2364     {
2365       DataArrayInt *elt(*it);
2366       if(elt)
2367         {
2368           std::string name(elt->getName());
2369           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2370             {
2371               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2372                 {
2373                   elt->setName((*it2).second.c_str());
2374                   return;
2375                 }
2376             }
2377         }
2378     }
2379 }
2380
2381 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2382 {
2383   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2384     {
2385       MEDFileFieldLoc *elt(*it);
2386       if(elt)
2387         {
2388           std::string name(elt->getName());
2389           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2390             {
2391               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2392                 {
2393                   elt->setName((*it2).second.c_str());
2394                   return;
2395                 }
2396             }
2397         }
2398     }
2399 }
2400
2401 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
2402 {
2403   if(locId<0 || locId>=(int)_locs.size())
2404     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2405   return _locs[locId]->getNbOfGaussPtPerCell();
2406 }
2407
2408 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
2409 {
2410   return getLocalizationFromId(getLocalizationId(locName));
2411 }
2412
2413 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
2414 {
2415   if(locId<0 || locId>=(int)_locs.size())
2416     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2417   return *_locs[locId];
2418 }
2419
2420 namespace ParaMEDMEMImpl
2421 {
2422   class LocFinder
2423   {
2424   public:
2425     LocFinder(const char *loc):_loc(loc) { }
2426     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2427   private:
2428     const char *_loc;
2429   };
2430
2431   class PflFinder
2432   {
2433   public:
2434     PflFinder(const std::string& pfl):_pfl(pfl) { }
2435     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2436   private:
2437     const std::string& _pfl;
2438   };
2439 }
2440
2441 int MEDFileFieldGlobs::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
2442 {
2443   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2444   if(it==_locs.end())
2445     {
2446       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2447       for(it=_locs.begin();it!=_locs.end();it++)
2448         oss << "\"" << (*it)->getName() << "\", ";
2449       throw INTERP_KERNEL::Exception(oss.str().c_str());
2450     }
2451   return std::distance(_locs.begin(),it);
2452 }
2453
2454 const DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
2455 {
2456   std::string pflNameCpp(pflName);
2457   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2458   if(it==_pfls.end())
2459     {
2460       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2461       for(it=_pfls.begin();it!=_pfls.end();it++)
2462         oss << "\"" << (*it)->getName() << "\", ";
2463       throw INTERP_KERNEL::Exception(oss.str().c_str());
2464     }
2465   return *it;
2466 }
2467
2468 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
2469 {
2470   if(pflId<0 || pflId>=(int)_pfls.size())
2471     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2472   return _pfls[pflId];
2473 }
2474
2475 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
2476 {
2477   if(locId<0 || locId>=(int)_locs.size())
2478     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2479   return *_locs[locId];
2480 }
2481
2482 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
2483 {
2484   return getLocalizationFromId(getLocalizationId(locName));
2485 }
2486
2487 DataArrayInt *MEDFileFieldGlobs::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
2488 {
2489   std::string pflNameCpp(pflName);
2490   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2491   if(it==_pfls.end())
2492     {
2493       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2494       for(it=_pfls.begin();it!=_pfls.end();it++)
2495         oss << "\"" << (*it)->getName() << "\", ";
2496       throw INTERP_KERNEL::Exception(oss.str().c_str());
2497     }
2498   return *it;
2499 }
2500
2501 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
2502 {
2503   if(pflId<0 || pflId>=(int)_pfls.size())
2504     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2505   return _pfls[pflId];
2506 }
2507
2508 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
2509 {
2510   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2511   int i=0;
2512   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2513     {
2514       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2515         newPfls.push_back(*it);
2516     }
2517   _pfls=newPfls;
2518 }
2519
2520 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
2521 {
2522   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2523   int i=0;
2524   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2525     {
2526       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2527         newLocs.push_back(*it);
2528     }
2529   _locs=newLocs;
2530 }
2531
2532 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2533 {
2534   int sz=_pfls.size();
2535   std::vector<std::string> ret(sz);
2536   for(int i=0;i<sz;i++)
2537     ret[i]=_pfls[i]->getName();
2538   return ret;
2539 }
2540
2541 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2542 {
2543   int sz=_locs.size();
2544   std::vector<std::string> ret(sz);
2545   for(int i=0;i<sz;i++)
2546     ret[i]=_locs[i]->getName();
2547   return ret;
2548 }
2549
2550 bool MEDFileFieldGlobs::existsPfl(const char *pflName) const
2551 {
2552   std::vector<std::string> v=getPfls();
2553   std::string s(pflName);
2554   return std::find(v.begin(),v.end(),s)!=v.end();
2555 }
2556
2557 bool MEDFileFieldGlobs::existsLoc(const char *locName) const
2558 {
2559   std::vector<std::string> v=getLocs();
2560   std::string s(locName);
2561   return std::find(v.begin(),v.end(),s)!=v.end();
2562 }
2563
2564 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2565 {
2566   std::map<int,std::vector<int> > m;
2567   int i=0;
2568   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2569     {
2570       const DataArrayInt *tmp=(*it);
2571       if(tmp)
2572         {
2573           m[tmp->getHashCode()].push_back(i);
2574         }
2575     }
2576   std::vector< std::vector<int> > ret;
2577   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2578     {
2579       if((*it2).second.size()>1)
2580         {
2581           std::vector<int> ret0;
2582           bool equalityOrNot=false;
2583           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2584             {
2585               std::vector<int>::const_iterator it4=it3; it4++;
2586               for(;it4!=(*it2).second.end();it4++)
2587                 {
2588                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2589                     {
2590                       if(!equalityOrNot)
2591                         ret0.push_back(*it3);
2592                       ret0.push_back(*it4);
2593                       equalityOrNot=true;
2594                     }
2595                 }
2596             }
2597           if(!ret0.empty())
2598             ret.push_back(ret0);
2599         }
2600     }
2601   return ret;
2602 }
2603
2604 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2605 {
2606   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2607 }
2608
2609 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
2610 {
2611   std::string name(pfl->getName());
2612   if(name.empty())
2613     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2614   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2615     if(name==(*it)->getName())
2616       {
2617         if(!pfl->isEqual(*(*it)))
2618           {
2619             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2620             throw INTERP_KERNEL::Exception(oss.str().c_str());
2621           }
2622       }
2623   pfl->incrRef();
2624   _pfls.push_back(pfl);
2625 }
2626
2627 void MEDFileFieldGlobs::appendLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w) throw(INTERP_KERNEL::Exception)
2628 {
2629   std::string name(locName);
2630   if(name.empty())
2631     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2632   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2633   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2634     if((*it)->isName(locName))
2635       {
2636         if(!(*it)->isEqual(*obj,1e-12))
2637           {
2638             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
2639             throw INTERP_KERNEL::Exception(oss.str().c_str());
2640           }
2641       }
2642   _locs.push_back(obj);
2643 }
2644
2645 std::string MEDFileFieldGlobs::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
2646 {
2647   std::vector<std::string> names=getPfls();
2648   return CreateNewNameNotIn("NewPfl_",names);
2649 }
2650
2651 std::string MEDFileFieldGlobs::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
2652 {
2653   std::vector<std::string> names=getLocs();
2654   return CreateNewNameNotIn("NewLoc_",names);
2655 }
2656
2657 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const char *prefix, const std::vector<std::string>& namesToAvoid) throw(INTERP_KERNEL::Exception)
2658 {
2659   for(std::size_t sz=0;sz<100000;sz++)
2660     {
2661       std::ostringstream tryName;
2662       tryName << prefix << sz;
2663       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
2664         return tryName.str();
2665     }
2666   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
2667 }
2668
2669 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const char *fname):_globals(MEDFileFieldGlobs::New(fname))
2670 {
2671 }
2672
2673 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
2674 {
2675 }
2676
2677 void MEDFileFieldGlobsReal::simpleRepr(std::ostream& oss) const
2678 {
2679   oss << "Globals information on fields :" << "\n*******************************\n\n";
2680   const MEDFileFieldGlobs *glob=_globals;
2681   if(glob)
2682     glob->simpleRepr(oss);
2683   else
2684     oss << "NO GLOBAL INFORMATION !\n";
2685 }
2686
2687 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
2688 {
2689 }
2690
2691 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
2692 {
2693   _globals=other._globals;
2694 }
2695
2696 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps) throw(INTERP_KERNEL::Exception)
2697 {
2698   _globals->appendGlobs(*other._globals,eps);
2699 }
2700
2701 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception)
2702 {
2703   _globals->loadProfileInFile(fid,id,pflName);
2704 }
2705
2706 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
2707 {
2708   _globals->loadProfileInFile(fid,id);
2709 }
2710
2711 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2712 {
2713   _globals->loadGlobals(fid,*this);
2714 }
2715
2716 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid) throw(INTERP_KERNEL::Exception)
2717 {
2718   _globals->loadAllGlobals(fid);
2719 }
2720
2721 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception)
2722 {
2723   _globals->writeGlobals(fid,opt);
2724 }
2725
2726 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
2727 {
2728   return _globals->getPfls();
2729 }
2730
2731 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
2732 {
2733   return _globals->getLocs();
2734 }
2735
2736 bool MEDFileFieldGlobsReal::existsPfl(const char *pflName) const
2737 {
2738   return _globals->existsPfl(pflName);
2739 }
2740
2741 bool MEDFileFieldGlobsReal::existsLoc(const char *locName) const
2742 {
2743   return _globals->existsLoc(locName);
2744 }
2745
2746 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const throw(INTERP_KERNEL::Exception)
2747 {
2748   return _globals->createNewNameOfPfl();
2749 }
2750
2751 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const throw(INTERP_KERNEL::Exception)
2752 {
2753   return _globals->createNewNameOfLoc();
2754 }
2755
2756 void MEDFileFieldGlobsReal::setFileName(const char *fileName)
2757 {
2758   _globals->setFileName(fileName);
2759 }
2760
2761 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
2762 {
2763   return _globals->whichAreEqualProfiles();
2764 }
2765
2766 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
2767 {
2768   return _globals->whichAreEqualLocs(eps);
2769 }
2770
2771 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2772 {
2773   _globals->changePflsNamesInStruct(mapOfModif);
2774 }
2775
2776 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2777 {
2778   _globals->changeLocsNamesInStruct(mapOfModif);
2779 }
2780
2781 /*!
2782  * This method is a generalization of MEDFileFieldGlobsReal::changePflName.
2783  * This method contrary to abstract method MEDFileFieldGlobsReal::changePflsRefsNamesGen updates in addition of MEDFileFieldGlobsReal::changePflsRefsNamesGen,
2784  * the profiles themselves and not only leaves of field.
2785  */
2786 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2787 {
2788   changePflsRefsNamesGen(mapOfModif);
2789   changePflsNamesInStruct(mapOfModif);
2790 }
2791
2792 /*!
2793  * This method is a generalization of MEDFileFieldGlobsReal::changePflName.
2794  * This method contrary to abstract method MEDFileFieldGlobsReal::changeLocsRefsNamesGen updates in addition of MEDFileFieldGlobsReal::changeLocsRefsNamesGen,
2795  * the localizations themselves and not only leaves of field.
2796  */
2797 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
2798 {
2799   changeLocsRefsNamesGen(mapOfModif);
2800   changeLocsNamesInStruct(mapOfModif);
2801 }
2802
2803 /*!
2804  * This method is a more friendly API but less general method than MEDFileFieldGlobsReal::changePflsNames.
2805  */
2806 void MEDFileFieldGlobsReal::changePflName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
2807 {
2808   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
2809   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
2810   mapOfModif[0]=p;
2811   changePflsNames(mapOfModif);
2812 }
2813
2814 /*!
2815  * This method is a more friendly API but less general method than MEDFileFieldGlobsReal::changeLocsNames.
2816  */
2817 void MEDFileFieldGlobsReal::changeLocName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
2818 {
2819   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
2820   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
2821   mapOfModif[0]=p;
2822   changeLocsNames(mapOfModif);
2823 }
2824
2825 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames() throw(INTERP_KERNEL::Exception)
2826 {
2827   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
2828   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
2829   int i=0;
2830   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
2831     {
2832       std::vector< std::string > tmp((*it).size());
2833       int j=0;
2834       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
2835         tmp[j]=std::string(getProfileFromId(*it2)->getName());
2836       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
2837       ret[i]=p;
2838       std::vector<int> tmp2((*it).begin()+1,(*it).end());
2839       killProfileIds(tmp2);
2840     }
2841   changePflsRefsNamesGen(ret);
2842   return ret;
2843 }
2844
2845 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps) throw(INTERP_KERNEL::Exception)
2846 {
2847   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
2848   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
2849   int i=0;
2850   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
2851     {
2852       std::vector< std::string > tmp((*it).size());
2853       int j=0;
2854       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
2855         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
2856       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
2857       ret[i]=p;
2858       std::vector<int> tmp2((*it).begin()+1,(*it).end());
2859       killLocalizationIds(tmp2);
2860     }
2861   changeLocsRefsNamesGen(ret);
2862   return ret;
2863 }
2864
2865 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception)
2866 {
2867   return _globals->getNbOfGaussPtPerCell(locId);
2868 }
2869
2870 int MEDFileFieldGlobsReal::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception)
2871 {
2872   return _globals->getLocalizationId(loc);
2873 }
2874
2875 const char *MEDFileFieldGlobsReal::getFileName() const
2876 {
2877   return _globals->getFileName();
2878 }
2879
2880 std::string MEDFileFieldGlobsReal::getFileName2() const
2881 {
2882   return _globals->getFileName2();
2883 }
2884
2885 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) const throw(INTERP_KERNEL::Exception)
2886 {
2887   return _globals->getLocalization(locName);
2888 }
2889
2890 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception)
2891 {
2892   return _globals->getLocalizationFromId(locId);
2893 }
2894
2895 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) const throw(INTERP_KERNEL::Exception)
2896 {
2897   return _globals->getProfile(pflName);
2898 }
2899
2900 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const throw(INTERP_KERNEL::Exception)
2901 {
2902   return _globals->getProfileFromId(pflId);
2903 }
2904
2905 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) throw(INTERP_KERNEL::Exception)
2906 {
2907   return _globals->getLocalizationFromId(locId);
2908 }
2909
2910 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const char *locName) throw(INTERP_KERNEL::Exception)
2911 {
2912   return _globals->getLocalization(locName);
2913 }
2914
2915 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const char *pflName) throw(INTERP_KERNEL::Exception)
2916 {
2917   return _globals->getProfile(pflName);
2918 }
2919
2920 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) throw(INTERP_KERNEL::Exception)
2921 {
2922   return _globals->getProfileFromId(pflId);
2923 }
2924
2925 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds) throw(INTERP_KERNEL::Exception)
2926 {
2927   _globals->killProfileIds(pflIds);
2928 }
2929
2930 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds) throw(INTERP_KERNEL::Exception)
2931 {
2932   _globals->killLocalizationIds(locIds);
2933 }
2934
2935 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception)
2936 {
2937   _globals->appendProfile(pfl);
2938 }
2939
2940 void MEDFileFieldGlobsReal::appendLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w) throw(INTERP_KERNEL::Exception)
2941 {
2942   _globals->appendLoc(locName,geoType,refCoo,gsCoo,w);
2943 }
2944
2945 /*!
2946  * This method returns the max dimension of 'this'.
2947  * This method returns -2 if 'this' is empty, -1 if only nodes are defined.
2948  */
2949 int MEDFileField1TSWithoutSDA::getDimension() const
2950 {
2951   int ret=-2;
2952   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
2953     (*it)->getDimension(ret);
2954   return ret;
2955 }
2956
2957 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
2958 {
2959   if(meshDimRelToMax>0)
2960     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
2961 }
2962
2963 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
2964 {
2965   //
2966   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
2967   int nbOfTypes=geoTypes.size();
2968   std::vector<int> code(3*nbOfTypes);
2969   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
2970   arr1->alloc(nbOfTypes,1);
2971   int *arrPtr=arr1->getPointer();
2972   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
2973   for(int i=0;i<nbOfTypes;i++,it++)
2974     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
2975   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
2976   const int *arrPtr2=arr2->getConstPointer();
2977   int i=0;
2978   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
2979     {
2980       int pos=arrPtr2[i];
2981       int nbCells=mesh->getNumberOfCellsWithType(*it);
2982       code[3*pos]=(int)(*it);
2983       code[3*pos+1]=nbCells;
2984       code[3*pos+2]=-1;//no profiles
2985     }
2986   std::vector<const DataArrayInt *> idsPerType;//no profiles
2987   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
2988   if(da)
2989     {
2990       da->decrRef();
2991       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
2992     }
2993   return code;
2994 }
2995
2996 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const char *fieldName, int csit, int fieldtype, int iteration, int order, const std::vector<std::string>& infos)
2997 {
2998   return new MEDFileField1TSWithoutSDA(fieldName,csit,fieldtype,iteration,order,infos);
2999 }
3000
3001 /*!
3002  * This method copyies tiny info but also preallocated the DataArrayDouble instance in this->_arr.
3003  * This not allocated it allocates to the size of 'field' array. If already allocated it grows the array to
3004  * the previous size + the size of the array of the input 'field'.
3005  * This method returns the position (in tuple id) where to start to feed 'this->_arr'
3006  */
3007 int MEDFileField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
3008 {
3009   std::string name(field->getName());
3010   getOrCreateAndGetArray()->setName(name.c_str());
3011   if(name.empty())
3012     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
3013   const DataArrayDouble *arr=field->getArray();
3014   if(!arr)
3015     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
3016   _dt=field->getTime(_iteration,_order);
3017   int nbOfComponents=arr->getNumberOfComponents();
3018   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
3019   if(!getOrCreateAndGetArray()->isAllocated())
3020     {
3021       _arr->alloc(arr->getNumberOfTuples(),arr->getNumberOfComponents());
3022       return 0;
3023     }
3024   else
3025     {
3026       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
3027       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
3028       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp=DataArrayDouble::New();
3029       tmp->alloc(newNbOfTuples,nbOfComponents);
3030       tmp->copyStringInfoFrom(*_arr);
3031       std::copy(_arr->begin(),_arr->end(),tmp->getPointer());
3032       _arr=tmp;
3033       return oldNbOfTuples;
3034     }
3035 }
3036
3037 std::string MEDFileField1TSWithoutSDA::getName() const
3038 {
3039   const DataArrayDouble *arr=getOrCreateAndGetArray();
3040   return arr->getName();
3041 }
3042
3043 void MEDFileField1TSWithoutSDA::setName(const char *name)
3044 {
3045   DataArrayDouble *arr=getOrCreateAndGetArray();
3046   arr->setName(name);
3047 }
3048
3049 void MEDFileField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3050 {
3051   std::string startOfLine(bkOffset,' ');
3052   oss << startOfLine << "Field on One time Step ";
3053   if(f1tsId>=0)
3054     oss << "(" << f1tsId << ") ";
3055   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3056   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3057   const DataArrayDouble *arr=_arr;
3058   if(arr)
3059     {
3060       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3061       if(f1tsId<0)
3062         {
3063           oss << startOfLine << "Field Name : \"" << arr->getName() << "\"." << std::endl;
3064           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3065           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3066             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3067         }
3068       if(arr->isAllocated())
3069         {
3070           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3071         }
3072       else
3073         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3074     }
3075   else
3076     {
3077       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3078     }
3079   oss << startOfLine << "----------------------" << std::endl;
3080   if(!_field_per_mesh.empty())
3081     {
3082       int i=0;
3083       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3084         {
3085           const MEDFileFieldPerMesh *cur=(*it2);
3086           if(cur)
3087             cur->simpleRepr(bkOffset,oss,i);
3088           else
3089             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3090         }
3091     }
3092   else
3093     {
3094       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3095     }
3096   oss << startOfLine << "----------------------" << std::endl;
3097 }
3098
3099 std::string MEDFileField1TSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
3100 {
3101   if(_field_per_mesh.empty())
3102     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3103   return _field_per_mesh[0]->getMeshName();
3104 }
3105
3106 void MEDFileField1TSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
3107 {
3108   std::string oldName(getMeshName());
3109   std::vector< std::pair<std::string,std::string> > v(1);
3110   v[0].first=oldName; v[0].second=newMeshName;
3111   changeMeshNames(v);
3112 }
3113
3114 bool MEDFileField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
3115 {
3116   bool ret=false;
3117   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3118     {
3119       MEDFileFieldPerMesh *cur(*it);
3120       if(cur)
3121         ret=cur->changeMeshNames(modifTab) || ret;
3122     }
3123   return ret;
3124 }
3125
3126 bool MEDFileField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
3127                                                             MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
3128 {
3129   bool ret=false;
3130   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3131     {
3132       MEDFileFieldPerMesh *fpm(*it);
3133       if(fpm)
3134         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
3135     }
3136   return ret;
3137 }
3138
3139 int MEDFileField1TSWithoutSDA::getMeshIteration() const throw(INTERP_KERNEL::Exception)
3140 {
3141   if(_field_per_mesh.empty())
3142     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3143   return _field_per_mesh[0]->getMeshIteration();
3144 }
3145
3146 int MEDFileField1TSWithoutSDA::getMeshOrder() const throw(INTERP_KERNEL::Exception)
3147 {
3148   if(_field_per_mesh.empty())
3149     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3150   return _field_per_mesh[0]->getMeshOrder();
3151 }
3152
3153 int MEDFileField1TSWithoutSDA::getNumberOfComponents() const
3154 {
3155   return getOrCreateAndGetArray()->getNumberOfComponents();
3156 }
3157
3158 bool MEDFileField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3159 {
3160   return iteration==_iteration && order==_order;
3161 }
3162
3163 std::pair<int,int> MEDFileField1TSWithoutSDA::getDtIt() const
3164 {
3165   std::pair<int,int> p;
3166   fillIteration(p);
3167   return p;
3168 }
3169
3170 void MEDFileField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3171 {
3172   p.first=_iteration;
3173   p.second=_order;
3174 }
3175
3176 void MEDFileField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
3177 {
3178   std::set<TypeOfField> types2;
3179   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3180     {
3181       (*it)->fillTypesOfFieldAvailable(types2);
3182     }
3183   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3184   std::copy(types2.begin(),types2.end(),bi);
3185 }
3186
3187 const std::vector<std::string>& MEDFileField1TSWithoutSDA::getInfo() const
3188 {
3189   const DataArrayDouble *arr=getOrCreateAndGetArray();
3190   return arr->getInfoOnComponents();
3191 }
3192
3193 std::vector<std::string>& MEDFileField1TSWithoutSDA::getInfo()
3194 {
3195   DataArrayDouble *arr=getOrCreateAndGetArray();
3196   return arr->getInfoOnComponents();
3197 }
3198
3199 /*!
3200  * This method has one input 'mname'. It can be null if the user is the general case where there is only one meshName lying on 'this'
3201  * This method returns two things.
3202  * - The absolute dimension of 'this' in first parameter. 
3203  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
3204  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
3205  *
3206  * This method is designed for MEDFileField1TS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
3207  * Only these 3 discretizations will be taken into account here.
3208  *
3209  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
3210  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
3211  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
3212  *
3213  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
3214  * 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'.
3215  * 
3216  * Let's consider the typical following case :
3217  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
3218  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
3219  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
3220  *   TETRA4 and SEG2
3221  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
3222  *
3223  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
3224  * 
3225  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
3226  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
3227  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
3228  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
3229  */
3230 int MEDFileField1TSWithoutSDA::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
3231 {
3232   levs.clear();
3233   int meshId=getMeshIdFromMeshName(mname);
3234   std::vector<INTERP_KERNEL::NormalizedCellType> types;
3235   std::vector< std::vector<TypeOfField> > typesF;
3236   std::vector< std::vector<std::string> > pfls, locs;
3237   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3238   if(types.empty())
3239     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
3240   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
3241   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
3242     return -1;
3243   st.erase(INTERP_KERNEL::NORM_ERROR);
3244   std::set<int> ret1;
3245   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
3246     {
3247       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
3248       ret1.insert((int)cm.getDimension());
3249     }
3250   int ret=*std::max_element(ret1.begin(),ret1.end());
3251   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
3252   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
3253   return ret;
3254 }
3255
3256 std::vector<TypeOfField> MEDFileField1TSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
3257 {
3258   std::vector<TypeOfField> ret;
3259   fillTypesOfFieldAvailable(ret);
3260   return ret;
3261 }
3262
3263 /*!
3264  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
3265  */
3266 std::vector< std::vector< std::pair<int,int> > > MEDFileField1TSWithoutSDA::getFieldSplitedByType(const char *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 throw(INTERP_KERNEL::Exception)
3267 {
3268   int meshId=0;
3269   if(mname)
3270     meshId=getMeshIdFromMeshName(mname);
3271   else
3272     if(_field_per_mesh.empty())
3273       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3274   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3275 }
3276
3277 /*!
3278  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
3279  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
3280  */
3281 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TSWithoutSDA::getFieldSplitedByType2(const char *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 throw(INTERP_KERNEL::Exception)
3282 {
3283   int meshId=0;
3284   if(mname)
3285     meshId=getMeshIdFromMeshName(mname);
3286   else
3287     if(_field_per_mesh.empty())
3288       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3289   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3290   int nbOfRet=ret0.size();
3291   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
3292   for(int i=0;i<nbOfRet;i++)
3293     {
3294       const std::vector< std::pair<int,int> >& p=ret0[i];
3295       int nbOfRet1=p.size();
3296       ret[i].resize(nbOfRet1);
3297       for(int j=0;j<nbOfRet1;j++)
3298         {
3299           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
3300           ret[i][j]=tmp;
3301         }
3302     }
3303   return ret;
3304 }
3305
3306 void MEDFileField1TSWithoutSDA::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception)
3307 {
3308   med_int numdt,numit;
3309   med_float dt;
3310   med_int nmesh;
3311   med_bool localMesh;
3312   med_int meshnumdt,meshnumit;
3313   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3314   MEDfieldComputingStepInfo(fid,getName().c_str(),_csit,&numdt,&numit,&_dt);
3315   MEDfield23ComputingStepMeshInfo(fid,getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
3316   if(_iteration!=numdt || _order!=numit)
3317     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::finishLoading : unexpected exception internal error !");
3318   _field_per_mesh.resize(nmesh);
3319   for(int i=0;i<nmesh;i++)
3320     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i+1,meshnumdt,meshnumit);
3321   int start=0;
3322   for(int i=0;i<nmesh;i++)
3323     {
3324       _field_per_mesh[i]->prepareLoading(fid,start);
3325     }
3326   getOrCreateAndGetArray()->alloc(start,getNumberOfComponents());
3327   for(int i=0;i<nmesh;i++)
3328     {
3329       _field_per_mesh[i]->finishLoading(fid,_field_type);
3330     }
3331 }
3332
3333 std::vector<std::string> MEDFileField1TSWithoutSDA::getPflsReallyUsed2() const
3334 {
3335   std::vector<std::string> ret;
3336   std::set<std::string> ret2;
3337   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3338     {
3339       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3340       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3341         if(ret2.find(*it2)==ret2.end())
3342           {
3343             ret.push_back(*it2);
3344             ret2.insert(*it2);
3345           }
3346     }
3347   return ret;
3348 }
3349
3350 std::vector<std::string> MEDFileField1TSWithoutSDA::getLocsReallyUsed2() const
3351 {
3352   std::vector<std::string> ret;
3353   std::set<std::string> ret2;
3354   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3355     {
3356       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3357       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3358         if(ret2.find(*it2)==ret2.end())
3359           {
3360             ret.push_back(*it2);
3361             ret2.insert(*it2);
3362           }
3363     }
3364   return ret;
3365 }
3366
3367 std::vector<std::string> MEDFileField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3368 {
3369   std::vector<std::string> ret;
3370   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3371     {
3372       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3373       ret.insert(ret.end(),tmp.begin(),tmp.end());
3374     }
3375   return ret;
3376 }
3377
3378 std::vector<std::string> MEDFileField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3379 {
3380   std::vector<std::string> ret;
3381   std::set<std::string> ret2;
3382   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3383     {
3384       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3385       ret.insert(ret.end(),tmp.begin(),tmp.end());
3386     }
3387   return ret;
3388 }
3389
3390 void MEDFileField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3391 {
3392   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3393     (*it)->changePflsRefsNamesGen(mapOfModif);
3394 }
3395
3396 void MEDFileField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3397 {
3398   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3399     (*it)->changeLocsRefsNamesGen(mapOfModif);
3400 }
3401
3402 void MEDFileField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception)
3403 {
3404   if(_field_per_mesh.empty())
3405     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
3406   if(_field_per_mesh.size()>1)
3407     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
3408   _field_per_mesh[0]->copyOptionsFrom(opts);
3409   _field_per_mesh[0]->writeLL(fid);
3410 }
3411
3412 /*!
3413  * SBT means Sort By Type.
3414  * This method is the most basic method to assign field in this. Basic in sense that no renumbering is done. Underlying mesh in 'field' is globaly ignored except for type contiguous check.
3415  */
3416 void MEDFileField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
3417 {
3418   const MEDCouplingMesh *mesh=field->getMesh();
3419   //
3420   TypeOfField type=field->getTypeOfField();
3421   std::vector<DataArrayInt *> dummy;
3422   int start=copyTinyInfoFrom(field);
3423   if(type!=ON_NODES)
3424     {
3425       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
3426       //
3427       int pos=addNewEntryIfNecessary(mesh);
3428       _field_per_mesh[pos]->assignFieldProfile(start,0,code,dummy,dummy,field,0,glob);//mesh is set to 0 because no external mesh is needed to be sent because no profile.
3429     }
3430   else
3431     {
3432       int pos=addNewEntryIfNecessary(mesh);
3433       _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,glob);
3434     }
3435 }
3436
3437 /*!
3438  * Generalization of MEDFileField1TSWithoutSDA::setFieldNoProfileSBT method.
3439  */
3440 void MEDFileField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
3441 {
3442   TypeOfField type=field->getTypeOfField();
3443   int start=copyTinyInfoFrom(field);
3444   std::vector<DataArrayInt *> idsInPflPerType;
3445   std::vector<DataArrayInt *> idsPerType;
3446   std::vector<int> code;
3447   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
3448   if(type!=ON_NODES)
3449     {
3450       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
3451       //
3452       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size());
3453       for(std::size_t i=0;i<idsInPflPerType.size();i++)
3454         idsInPflPerType2[i]=idsInPflPerType[i];
3455       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size());
3456       for(std::size_t i=0;i<idsPerType.size();i++)
3457         idsPerType2[i]=idsPerType[i];
3458       //
3459       int pos=addNewEntryIfNecessary(m);
3460       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,idsInPflPerType,idsPerType,field,m,glob);
3461     }
3462   else
3463     {
3464       int pos=addNewEntryIfNecessary(m);
3465       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,glob);
3466     }
3467 }
3468
3469 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
3470 {
3471   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
3472   if(mName==0)
3473     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
3474   else
3475     mm=MEDFileMesh::New(glob->getFileName(),mName,-1,-1);
3476   return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm);
3477 }
3478
3479 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception)
3480 {
3481   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
3482   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
3483   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
3484   if(meshDimRelToMax==1)
3485     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
3486   return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e);
3487 }
3488
3489 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const char *mName, int renumPol, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
3490 {
3491    MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
3492   if(mName==0)
3493     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
3494   else
3495     mm=MEDFileMesh::New(glob->getFileName(),mName,-1,-1);
3496   int absDim=getDimension();
3497   int meshDimRelToMax=absDim-mm->getMeshDimension();
3498   return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm);
3499 }
3500
3501 MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum) const throw(INTERP_KERNEL::Exception)
3502 {
3503   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
3504   int meshId=getMeshIdFromMeshName(mesh->getName());
3505   bool isPfl=false;
3506   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl);
3507   switch(renumPol)
3508     {
3509     case 0:
3510       {
3511         //no need to test _field_per_mesh.empty() because geMeshName has already done it
3512         ret->incrRef();
3513         return ret;
3514       }
3515     case 3:
3516     case 1:
3517       {
3518         if(isPfl)
3519           throw INTERP_KERNEL::Exception(msg1);
3520         //no need to test _field_per_mesh.empty() because geMeshName has already done it
3521         if(cellRenum)
3522           {
3523             if(cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
3524               {
3525                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
3526                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
3527                 throw INTERP_KERNEL::Exception(oss.str().c_str());
3528               }
3529             ret->renumberCells(cellRenum->getConstPointer(),true);
3530           }
3531         if(renumPol==1)
3532           {
3533             ret->incrRef();
3534             return ret;
3535           }
3536       }
3537     case 2:
3538       {
3539         //no need to test _field_per_mesh.empty() because geMeshName has already done it
3540         if(isPfl)
3541           throw INTERP_KERNEL::Exception(msg1);
3542         if(nodeRenum)
3543           {
3544             if(nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
3545               {
3546                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
3547                 oss << "\"" << getName() << "\" not defined on all nodes !";
3548                 throw INTERP_KERNEL::Exception(oss.str().c_str());
3549               }
3550             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
3551             ret->renumberNodes(nodeRenumSafe->getConstPointer());
3552           }
3553         ret->incrRef();
3554         return ret;
3555       }
3556     default:
3557       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
3558     }
3559 }
3560
3561 DataArrayDouble *MEDFileField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception)
3562 {
3563   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
3564   int meshId=getMeshIdFromMeshName(mesh->getName());
3565   return _field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob);
3566 }
3567
3568 /*!
3569  * This method retrieves direct access to the underground ParaMEDMEM::DataArrayDouble instance. The returned array is not a newly
3570  * created array so it should \b not be dealed by the caller.
3571  * This method allows to the user a direct access to the values.
3572  * This method is quite unusable if there is more than a nodal field or a cell field on single geometric cell type.
3573  */
3574 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
3575 {
3576   const DataArrayDouble *ret=_arr;
3577   if(ret)
3578     return const_cast<DataArrayDouble *>(ret);
3579   else
3580     return 0;
3581 }
3582
3583 /*!
3584  * This method returns an array that the caller must deal with (contrary to those returned by MEDFileField1TSWithoutSDA::getUndergroundDataArray method).
3585  * The returned array is the result of the aggregation of all sub arrays stored in the MED file. So to allow the caller to select the output param
3586  * 'entries' is returned. This output param is a vector of a pair of 2 pairs. The first pair of pair informs of the geometric type it refers to and the discretization
3587  * id attached to it. The second pair of pair precise the range [begin,end) into the returned array.
3588  * This method makes the hypothesis that the field lies only on one mesh. If it is not the case an exception will be thrown.
3589  */
3590 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
3591 {
3592   if(_field_per_mesh.size()!=1)
3593     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
3594   if(_field_per_mesh[0]==0)
3595     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
3596   return _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
3597 }
3598
3599 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const char *fieldName, int csit, int fieldtype, int iteration, int order,
3600                                                      const std::vector<std::string>& infos):_csit(csit),_field_type(fieldtype),_iteration(iteration),_order(order)
3601 {
3602   DataArrayDouble *arr=getOrCreateAndGetArray();
3603   arr->setName(fieldName);
3604   arr->setInfoAndChangeNbOfCompo(infos);
3605 }
3606
3607 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():_csit(-1),_field_type(-1)
3608 {
3609 }
3610
3611 int MEDFileField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception)
3612 {
3613   std::string tmp(mesh->getName());
3614   if(tmp.empty())
3615     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
3616   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
3617   int i=0;
3618   for(;it!=_field_per_mesh.end();it++,i++)
3619     {
3620       if((*it)->getMeshName()==tmp)
3621         return i;
3622     }
3623   int sz=_field_per_mesh.size();
3624   _field_per_mesh.resize(sz+1);
3625   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
3626   return sz;
3627 }
3628
3629 /*!
3630  * \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.
3631  */
3632 int MEDFileField1TSWithoutSDA::getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception)
3633 {
3634   if(_field_per_mesh.empty())
3635     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
3636   if(mName==0)
3637     return 0;
3638   std::string mName2(mName);
3639   int ret=0;
3640   std::vector<std::string> msg;
3641   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
3642     if(mName2==(*it)->getMeshName())
3643       return ret;
3644     else
3645       msg.push_back((*it)->getMeshName());
3646   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
3647   oss << "Possible meshes are : ";
3648   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
3649     oss << "\"" << (*it2) << "\" ";
3650   throw INTERP_KERNEL::Exception(oss.str().c_str());
3651 }
3652
3653 /*!
3654  * \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.
3655  * \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.
3656  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3657  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3658  */
3659 MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
3660 {
3661   int mid=getMeshIdFromMeshName(mName);
3662   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3663 }
3664
3665 /*!
3666  * \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.
3667  * \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.
3668  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3669  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3670  */
3671 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
3672 {
3673   int mid=getMeshIdFromMeshName(mName);
3674   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
3675 }
3676
3677 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
3678 {
3679   DataArrayDouble *ret=_arr;
3680   if(ret)
3681     return ret;
3682   _arr=DataArrayDouble::New();
3683   return _arr;
3684 }
3685
3686 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
3687 {
3688   const DataArrayDouble *ret=_arr;
3689   if(ret)
3690     return ret;
3691   DataArrayDouble *ret2=DataArrayDouble::New();
3692   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
3693   return ret2;
3694 }
3695
3696 MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
3697 {
3698   return new MEDFileField1TS(fileName,fieldName,iteration,order);
3699 }
3700
3701 /*!
3702  * \warning this is a shallow copy constructor
3703  */
3704 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool deepCpy)
3705 {
3706   return new MEDFileField1TS(other,deepCpy);
3707 }
3708
3709 MEDFileField1TS *MEDFileField1TS::New()
3710 {
3711   return new MEDFileField1TS;
3712 }
3713
3714 std::string MEDFileField1TS::simpleRepr() const
3715 {
3716   std::ostringstream oss;
3717   _content->simpleRepr(0,oss,-1);
3718   MEDFileFieldGlobsReal::simpleRepr(oss);
3719   return oss.str();
3720 }
3721
3722 void MEDFileField1TS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
3723 {
3724   int nbComp=getNumberOfComponents();
3725   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
3726   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
3727   for(int i=0;i<nbComp;i++)
3728     {
3729       std::string info=getInfo()[i];
3730       std::string c,u;
3731       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
3732       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);
3733       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);
3734     }
3735   if(getName().empty())
3736     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
3737   MEDfieldCr(fid,getName().c_str(),MED_FLOAT64,nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
3738   writeGlobals(fid,*this);
3739   _content->writeLL(fid,*this);
3740 }
3741
3742 void MEDFileField1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
3743 {
3744   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
3745   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
3746   writeLL(fid);
3747 }
3748
3749 MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
3750 try:_content(MEDFileField1TSWithoutSDA::New(fieldName,-1,-1,iteration,order,std::vector<std::string>())),MEDFileFieldGlobsReal(fileName)
3751 {
3752   MEDFileUtilities::CheckFileForRead(fileName);
3753   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
3754   int nbFields=MEDnField(fid);
3755   med_field_type typcha;
3756   bool found=false;
3757   std::vector<std::string> fns(nbFields);
3758   int nbOfStep2=-1;
3759   for(int i=0;i<nbFields && !found;i++)
3760     {
3761       int ncomp=MEDfieldnComponent(fid,i+1);
3762       INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
3763       INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
3764       INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
3765       INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3766       INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3767       med_bool localMesh;
3768       int nbOfStep;
3769       MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
3770       std::string tmp(nomcha);
3771       fns[i]=tmp;
3772       found=(tmp==fieldName);
3773       if(found)
3774         {
3775           nbOfStep2=nbOfStep;
3776           std::string mname=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
3777           std::vector<std::string> infos(ncomp);
3778           for(int j=0;j<ncomp;j++)
3779             infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
3780           _content->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
3781         }
3782     }
3783   if(!found)
3784     {
3785       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
3786       std::copy(fns.begin(),fns.end(),std::ostream_iterator<std::string>(oss," "));
3787       throw INTERP_KERNEL::Exception(oss.str().c_str());
3788     }
3789   found=false;
3790   std::vector< std::pair<int,int> > dtits(nbOfStep2);
3791   for(int i=0;i<nbOfStep2 && !found;i++)
3792     {
3793       med_int numdt,numit;
3794       med_float dt;
3795       MEDfieldComputingStepInfo(fid,fieldName,i+1,&numdt,&numit,&dt);
3796       if(numdt==iteration && numit==order)
3797         {
3798           found=true;
3799           _content->_csit=i+1;
3800           _content->_field_type=MEDFileUtilities::TraduceFieldType(typcha);
3801         }
3802       else
3803         dtits[i]=std::pair<int,int>(numdt,numit);
3804     }
3805   if(!found)
3806     {
3807       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
3808       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
3809         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
3810       throw INTERP_KERNEL::Exception(oss.str().c_str());
3811     }
3812   _content->finishLoading(fid);
3813   //
3814   loadGlobals(fid);
3815 }
3816 catch(INTERP_KERNEL::Exception& e)
3817   {
3818     throw e;
3819   }
3820
3821 /*!
3822  * \warning this is a shallow copy constructor
3823  */
3824 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool deepCpy)
3825 {
3826   if(!deepCpy)
3827     {
3828       const MEDFileField1TSWithoutSDA *otherPtr(&other);
3829       otherPtr->incrRef();
3830       _content=const_cast<MEDFileField1TSWithoutSDA *>(otherPtr);
3831     }
3832   else
3833     {
3834       _content=new MEDFileField1TSWithoutSDA(other);
3835     }
3836 }
3837
3838 MEDFileField1TS::MEDFileField1TS():_content(new MEDFileField1TSWithoutSDA)
3839 {
3840 }
3841
3842 /*!
3843  * This method returns all profiles whose name is non empty used.
3844  * \b WARNING If profile is used several times it will be reported \b only \b once.
3845  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
3846  */
3847 std::vector<std::string> MEDFileField1TS::getPflsReallyUsed() const
3848 {
3849   return _content->getPflsReallyUsed2();
3850 }
3851
3852 /*!
3853  * This method returns all localizations whose name is non empty used.
3854  * \b WARNING If localization is used several times it will be reported \b only \b once.
3855  */
3856 std::vector<std::string> MEDFileField1TS::getLocsReallyUsed() const
3857 {
3858   return _content->getLocsReallyUsed2();
3859 }
3860
3861 /*!
3862  * This method returns all profiles whose name is non empty used.
3863  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
3864  */
3865 std::vector<std::string> MEDFileField1TS::getPflsReallyUsedMulti() const
3866 {
3867   return _content->getPflsReallyUsedMulti2();
3868 }
3869
3870 /*!
3871  * This method returns all localizations whose name is non empty used.
3872  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
3873  */
3874 std::vector<std::string> MEDFileField1TS::getLocsReallyUsedMulti() const
3875 {
3876   return _content->getLocsReallyUsedMulti2();
3877 }
3878
3879 void MEDFileField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3880 {
3881   _content->changePflsRefsNamesGen2(mapOfModif);
3882 }
3883
3884 void MEDFileField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
3885 {
3886   _content->changeLocsRefsNamesGen2(mapOfModif);
3887 }
3888
3889 /*!
3890  * This method requests underlying file to perform the job, for mesh reading. If the current instance is not coming from a file and has been constructed from scratch
3891  * an exception will be thrown. In this case you should use MEDFileField1TS::getFieldOnMeshAtLevel method instead.
3892  * \b WARNING ! Parameter 'meshDimRelToMax' is relative from read mesh in file that can be different from the field in MED file !
3893  * It leads that the returned field of this method is always coherent.
3894  */
3895 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
3896 {
3897   if(getFileName2().empty())
3898     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
3899   return _content->getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this);
3900 }
3901
3902 /*!
3903  * This method is close to MEDFileField1TS::getFieldAtLevel except that here the 'meshDimRelToMax' param is ignored and the maximal dimension is taken
3904  * automatically. If the field lies on different level and that an another level than the maximal is requested MEDFileField1TS::getFieldAtLevel
3905  * should be called instead.
3906  */
3907 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const throw(INTERP_KERNEL::Exception)
3908 {
3909   if(getFileName2().empty())
3910     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
3911   return _content->getFieldAtTopLevel(type,0,renumPol,this);
3912 }
3913
3914 /*!
3915  * \b WARNING, there is a main difference with the two close methods (MEDFileField1TS::getFieldAtLevel and MEDFileField1TS::getFieldOnMeshAtLevel method) !
3916  * Here the mesh-dimension of 'mesh' is used by this to automatically request the right geoTypes regarding 'type'.
3917  * If no such element fufilled the deduced dimension and 'type' an exception will be thrown.
3918  * It leads that the returned field of this method is always coherent.
3919  */
3920 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
3921 {
3922   return _content->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0);
3923 }
3924
3925 /*!
3926  * This method can be called whatever the mode of instance feeding of this (MED file or from scratch).
3927  * But the parameter ''meshDimRelToMax' is applyied on 'mesh' (like MEDFileField1TS::getFieldAtLevel does). \b WARNING the dim of 'this' can be different from those in 'mesh' !
3928  * It leads that the returned field of this method is always coherent.
3929  */
3930 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
3931 {
3932   return _content->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh);
3933 }
3934
3935 /*!
3936  * This method is identical to MEDFileField1TS::getFieldAtLevel method except that meshName 'mname' should be specified.
3937  * This method is called "Old" because in MED3 norm a field has only one meshName attached. This method is only here for reader of MED2 files.
3938  * See MEDFileField1TS::getFieldAtLevel for more information.
3939  */
3940 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
3941 {
3942   if(getFileName2().empty())
3943     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
3944   return _content->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this);
3945 }
3946
3947 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
3948 {
3949   return _content->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this);
3950 }
3951
3952 /*!
3953  * SBT means Sort By Type.
3954  * This method is the most basic method to assign field in this. Basic in sense that no renumbering is done. Underlying mesh in 'field' is globaly ignored except for type contiguous check.
3955  * 
3956  */
3957 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
3958 {
3959   setFileName("");
3960   _content->setFieldNoProfileSBT(field,*this);
3961 }
3962
3963 /*!
3964  * This method is a generalization of MEDFileField1TS::setFieldNoProfileSBT method. Here a profile array is given in input.
3965  * The support of field 'field' is \b not used by this method, so it can be null or incoherent with field.
3966  * This method uses input parameters 'mesh', 'meshDimRelToMax' and 'profile' to determine what is really the support of field 'field'. If field is incoherent regarding this deduced support,
3967  * an exception will be thrown.
3968  * This method is trying to reduce the size of MEDfile file so profile is created only if it is absolutely necessary. If it is necessary the name of 'profile' will be used to create it in 'this'.
3969  * In this case, if this profile name is empty an exception will be thrown.
3970  */
3971 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
3972 {
3973   setFileName("");
3974   _content->setFieldProfile(field,mesh,meshDimRelToMax,profile,*this);
3975 }
3976
3977 /*!
3978  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
3979  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
3980  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
3981  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
3982  * to keep a valid instance.
3983  * 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.
3984  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
3985  * 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.
3986  *
3987  * \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.
3988  * \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.
3989  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
3990  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
3991  * \param [in] newLocName is the new localization name.
3992  * \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.
3993  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
3994  */
3995 void MEDFileField1TS::setProfileNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newPflName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
3996 {
3997   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
3998   std::string oldPflName=disc->getProfile();
3999   std::vector<std::string> vv=getPflsReallyUsedMulti();
4000   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
4001   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
4002     {
4003       disc->setProfile(newPflName);
4004       DataArrayInt *pfl=getProfile(oldPflName.c_str());
4005       pfl->setName(newPflName);
4006     }
4007   else
4008     {
4009       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
4010       throw INTERP_KERNEL::Exception(oss.str().c_str());
4011     }
4012 }
4013
4014 /*!
4015  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
4016  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
4017  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
4018  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
4019  * to keep a valid instance.
4020  * 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.
4021  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
4022  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
4023  * 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.
4024  *
4025  * \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.
4026  * \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.
4027  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4028  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4029  * \param [in] newLocName is the new localization name.
4030  * \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.
4031  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
4032  */
4033 void MEDFileField1TS::setLocNameOnLeaf(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const char *newLocName, bool forceRenameOnGlob) throw(INTERP_KERNEL::Exception)
4034 {
4035   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
4036   std::string oldLocName=disc->getLocalization();
4037   std::vector<std::string> vv=getLocsReallyUsedMulti();
4038   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
4039   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
4040     {
4041       disc->setLocalization(newLocName);
4042       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
4043       loc.setName(newLocName);
4044     }
4045   else
4046     {
4047       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
4048       throw INTERP_KERNEL::Exception(oss.str().c_str());
4049     }
4050 }
4051
4052 int MEDFileField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
4053 {
4054   return _content->copyTinyInfoFrom(field);
4055 }
4056
4057 int MEDFileField1TS::getDimension() const
4058 {
4059   return _content->getDimension();
4060 }
4061
4062 int MEDFileField1TS::getIteration() const
4063 {
4064   return _content->getIteration();
4065 }
4066
4067 int MEDFileField1TS::getOrder() const
4068 {
4069   return _content->getOrder();
4070 }
4071
4072 double MEDFileField1TS::getTime(int& iteration, int& order) const
4073 {
4074   return _content->getTime(iteration,order);
4075 }
4076
4077 void MEDFileField1TS::setTime(int iteration, int order, double val)
4078 {
4079   _content->setTime(iteration,order,val);
4080 }
4081
4082 std::string MEDFileField1TS::getName() const
4083 {
4084   return _content->getName();
4085 }
4086
4087 void MEDFileField1TS::setName(const char *name)
4088 {
4089   _content->setName(name);
4090 }
4091
4092 void MEDFileField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4093 {
4094   _content->simpleRepr(bkOffset,oss,f1tsId);
4095 }
4096
4097 const std::string& MEDFileField1TS::getDtUnit() const
4098 {
4099   return _content->getDtUnit();
4100 }
4101
4102 std::string MEDFileField1TS::getMeshName() const throw(INTERP_KERNEL::Exception)
4103 {
4104   return _content->getMeshName();
4105 }
4106
4107 void MEDFileField1TS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
4108 {
4109   _content->setMeshName(newMeshName);
4110 }
4111
4112 bool MEDFileField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
4113 {
4114   return _content->changeMeshNames(modifTab);
4115 }
4116
4117 int MEDFileField1TS::getMeshIteration() const throw(INTERP_KERNEL::Exception)
4118 {
4119   return _content->getMeshIteration();
4120 }
4121
4122 int MEDFileField1TS::getMeshOrder() const throw(INTERP_KERNEL::Exception)
4123 {
4124   return _content->getMeshOrder();
4125 }
4126
4127 int MEDFileField1TS::getNumberOfComponents() const
4128 {
4129   return _content->getNumberOfComponents();
4130 }
4131
4132 bool MEDFileField1TS::isDealingTS(int iteration, int order) const
4133 {
4134   return _content->isDealingTS(iteration,order);
4135 }
4136
4137 std::pair<int,int> MEDFileField1TS::getDtIt() const
4138 {
4139   return _content->getDtIt();
4140 }
4141
4142 void MEDFileField1TS::fillIteration(std::pair<int,int>& p) const
4143 {
4144   _content->fillIteration(p);
4145 }
4146 void MEDFileField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const throw(INTERP_KERNEL::Exception)
4147 {
4148   _content->fillTypesOfFieldAvailable(types);
4149 }
4150
4151 const std::vector<std::string>& MEDFileField1TS::getInfo() const
4152 {
4153   return _content->getInfo();
4154 }
4155 std::vector<std::string>& MEDFileField1TS::getInfo()
4156 {
4157   return _content->getInfo();
4158 }
4159
4160 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
4161 {
4162   return _content->getUndergroundDataArray();
4163 }
4164
4165 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4166 {
4167   return _content->getUndergroundDataArrayExt(entries);
4168 }
4169
4170 MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception)
4171 {
4172   return _content->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
4173 }
4174
4175 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileField1TS::getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception)
4176 {
4177   return _content->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
4178 }
4179
4180 int MEDFileField1TS::getNonEmptyLevels(const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
4181 {
4182   return _content->getNonEmptyLevels(mname,levs);
4183 }
4184
4185 std::vector<TypeOfField> MEDFileField1TS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
4186 {
4187   return _content->getTypesOfFieldAvailable();
4188 }
4189
4190 std::vector< std::vector<std::pair<int,int> > > MEDFileField1TS::getFieldSplitedByType(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
4191                                                                                        std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
4192 {
4193   return _content->getFieldSplitedByType(mname,types,typesF,pfls,locs);
4194 }
4195 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const char *mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
4196                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
4197 {
4198   return _content->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
4199 }
4200
4201 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const char *fieldName, int id, int ft, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception)
4202 {
4203   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,id,ft,infos,nbOfStep);
4204 }
4205
4206 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA():_field_type(-1)
4207 {
4208 }
4209
4210 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const char *fieldName):_name(fieldName),_field_type(-1)
4211 {
4212 }
4213
4214 /*!
4215  * \param [in] fieldId field id in C mode
4216  */
4217 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId) throw(INTERP_KERNEL::Exception)
4218 try:_name("")
4219 {
4220   med_field_type typcha;
4221   int nbstep2=-1;
4222   //
4223   int ncomp=MEDfieldnComponent(fid,1);
4224   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4225   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4226   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
4227   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4228   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4229   med_bool localMesh;
4230   int nbOfStep;
4231   MEDfieldInfo(fid,fieldId+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
4232   _name=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
4233   _field_type=MEDFileUtilities::TraduceFieldType(typcha);
4234   _infos.resize(ncomp);
4235   for(int j=0;j<ncomp;j++)
4236     _infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
4237   //
4238   finishLoading(fid,nbOfStep);
4239 }
4240 catch(INTERP_KERNEL::Exception& e)
4241   {
4242     throw e;
4243   }
4244
4245 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, int id, int ft, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception)
4246 try:_name(fieldName),_infos(infos),_field_type(ft)
4247 {
4248   finishLoading(fid,nbOfStep);
4249 }
4250 catch(INTERP_KERNEL::Exception& e)
4251   {
4252     throw e;
4253   }
4254
4255 const std::vector<std::string>& MEDFileFieldMultiTSWithoutSDA::getInfo() const throw(INTERP_KERNEL::Exception)
4256 {
4257   if(_time_steps.empty())
4258     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getInfos : not time steps !");
4259   return _time_steps[0]->getInfo();
4260 }
4261
4262 /*!
4263  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
4264  */
4265 DataArrayDouble *MEDFileFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
4266 {
4267   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
4268 }
4269
4270 /*!
4271  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
4272  */
4273 DataArrayDouble *MEDFileFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
4274 {
4275   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
4276 }
4277
4278 std::string MEDFileFieldMultiTSWithoutSDA::getMeshName() const throw(INTERP_KERNEL::Exception)
4279 {
4280   if(_time_steps.empty())
4281     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
4282   return _time_steps[0]->getMeshName();
4283 }
4284
4285 void MEDFileFieldMultiTSWithoutSDA::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
4286 {
4287   std::string oldName(getMeshName());
4288   std::vector< std::pair<std::string,std::string> > v(1);
4289   v[0].first=oldName; v[0].second=newMeshName;
4290   changeMeshNames(v);
4291 }
4292
4293 bool MEDFileFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
4294 {
4295   bool ret=false;
4296   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4297     {
4298       MEDFileField1TSWithoutSDA *cur(*it);
4299       if(cur)
4300         ret=cur->changeMeshNames(modifTab) || ret;
4301     }
4302   return ret;
4303 }
4304
4305 bool MEDFileFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4306                                                                 MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
4307 {
4308   bool ret=false;
4309   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4310     {
4311       MEDFileField1TSWithoutSDA *f1ts(*it);
4312       if(f1ts)
4313         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4314     }
4315   return ret;
4316 }
4317
4318 void MEDFileFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
4319 {
4320   if(_time_steps.empty())
4321     {
4322       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
4323       obj->setFieldNoProfileSBT(field,glob);
4324       copyTinyInfoFrom(field);
4325       _time_steps.push_back(obj);
4326     }
4327   else
4328     {
4329       checkCoherencyOfTinyInfo(field);
4330       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
4331       obj->setFieldNoProfileSBT(field,glob);
4332       _time_steps.push_back(obj);
4333     }
4334 }
4335
4336 void MEDFileFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception)
4337 {
4338   if(_time_steps.empty())
4339     {
4340       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
4341       obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,glob);
4342       copyTinyInfoFrom(field);
4343       _time_steps.push_back(obj);
4344     }
4345   else
4346     {
4347       checkCoherencyOfTinyInfo(field);
4348       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> obj=new MEDFileField1TSWithoutSDA;
4349       obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,glob);
4350       _time_steps.push_back(obj);
4351     }
4352 }
4353
4354 std::string MEDFileFieldMultiTSWithoutSDA::getDtUnit() const throw(INTERP_KERNEL::Exception)
4355 {
4356   if(_time_steps.empty())
4357     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
4358   return _time_steps[0]->getDtUnit();
4359 }
4360
4361 std::string MEDFileFieldMultiTSWithoutSDA::getName() const
4362 {
4363   return _name;
4364 }
4365
4366 void MEDFileFieldMultiTSWithoutSDA::setName(const char *name)
4367 {
4368   _name=name;
4369 }
4370
4371 void MEDFileFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
4372 {
4373   std::string startLine(bkOffset,' ');
4374   oss << startLine << "Field multi time steps";
4375   if(fmtsId>=0)
4376     oss << " (" << fmtsId << ")";
4377   oss << " has the following name: \"" << _name << "\"." << std::endl;
4378   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
4379   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
4380     {
4381       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
4382     }
4383   int i=0;
4384   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
4385     {
4386       std::string chapter(17,'0'+i);
4387       oss << startLine << chapter << std::endl;
4388       const MEDFileField1TSWithoutSDA *cur=(*it);
4389       if(cur)
4390         cur->simpleRepr(bkOffset+2,oss,i);
4391       else
4392         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
4393       oss << startLine << chapter << std::endl;
4394     }
4395 }
4396
4397 std::vector< std::pair<int,int> > MEDFileFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
4398 {
4399   std::size_t sz=_time_steps.size();
4400   std::vector< std::pair<int,int> > ret(sz);
4401   ret1.resize(sz);
4402   for(std::size_t i=0;i<sz;i++)
4403     {
4404       const MEDFileField1TSWithoutSDA *f1ts=_time_steps[i];
4405       if(f1ts)
4406         {
4407           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
4408         }
4409       else
4410         {
4411           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
4412           throw INTERP_KERNEL::Exception(oss.str().c_str());
4413         }
4414     }
4415   return ret;
4416 }
4417
4418 void MEDFileFieldMultiTSWithoutSDA::finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception)
4419 {
4420   _time_steps.resize(nbPdt);
4421   for(int i=0;i<nbPdt;i++)
4422     {
4423       std::vector< std::pair<int,int> > ts;
4424       med_int numdt=0,numo=0;
4425       med_int meshIt=0,meshOrder=0;
4426       med_float dt=0.0;
4427       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
4428       _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,_field_type,numdt,numo,_infos);
4429       _time_steps[i]->finishLoading(fid);
4430     }
4431 }
4432
4433 void MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
4434 {
4435   _name=field->getName();
4436   if(_name.empty())
4437     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4438   const DataArrayDouble *arr=field->getArray();
4439   if(!arr)
4440     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
4441   _infos=arr->getInfoOnComponents();
4442 }
4443
4444 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field) const throw(INTERP_KERNEL::Exception)
4445 {
4446   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
4447   if(_name!=field->getName())
4448     {
4449       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
4450       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
4451       throw INTERP_KERNEL::Exception(oss.str().c_str());
4452     }
4453   const DataArrayDouble *arr=field->getArray();
4454   if(!arr)
4455     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
4456   if(_infos!=arr->getInfoOnComponents())
4457     {
4458       std::ostringstream oss; oss << MSG << "components ! should be \"";
4459       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
4460       oss << " But compo in input fields are : ";
4461       std::vector<std::string> tmp=arr->getInfoOnComponents();
4462       std::copy(tmp.begin(),tmp.end(),std::ostream_iterator<std::string>(oss,", "));
4463       oss << " !";
4464       throw INTERP_KERNEL::Exception(oss.str().c_str());
4465     }
4466 }
4467
4468 void MEDFileFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const throw(INTERP_KERNEL::Exception)
4469 {
4470   if(_time_steps.empty())
4471     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
4472   std::vector<std::string> infos(getInfo());
4473   int nbComp=infos.size();
4474   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
4475   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
4476   for(int i=0;i<nbComp;i++)
4477     {
4478       std::string info=infos[i];
4479       std::string c,u;
4480       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
4481       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
4482       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
4483     }
4484   if(_name.empty())
4485     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
4486   MEDfieldCr(fid,_name.c_str(),MED_FLOAT64,nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
4487   int nbOfTS=_time_steps.size();
4488   for(int i=0;i<nbOfTS;i++)
4489     _time_steps[i]->writeLL(fid,opts);
4490 }
4491
4492 int MEDFileFieldMultiTSWithoutSDA::getNumberOfTS() const
4493 {
4494   return _time_steps.size();
4495 }
4496
4497 void MEDFileFieldMultiTSWithoutSDA::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
4498 {
4499   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  > newTS;
4500   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4501     {
4502       const MEDFileField1TSWithoutSDA *tmp=(*it);
4503       if(tmp)
4504         newTS.push_back(*it);
4505     }
4506   _time_steps=newTS;
4507 }
4508
4509 void MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
4510 {
4511   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  > newTS;
4512   int maxId=(int)_time_steps.size();
4513   int ii=0;
4514   std::set<int> idsToDel;
4515   for(const int *id=startIds;id!=endIds;id++,ii++)
4516     {
4517       if(*id>=0 && *id<maxId)
4518         {
4519           idsToDel.insert(*id);
4520         }
4521       else
4522         {
4523           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
4524           throw INTERP_KERNEL::Exception(oss.str().c_str());
4525         }
4526     }
4527   for(int iii=0;iii<maxId;iii++)
4528     if(idsToDel.find(iii)==idsToDel.end())
4529       newTS.push_back(_time_steps[iii]);
4530   _time_steps=newTS;
4531 }
4532
4533 int MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
4534 {
4535   int ret=0;
4536   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
4537   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
4538     {
4539       const MEDFileField1TSWithoutSDA *tmp(*it);
4540       if(tmp)
4541         {
4542           int it,ord;
4543           tmp->getTime(it,ord);
4544           if(it==iteration && order==ord)
4545             return ret;
4546           else
4547             oss << "(" << it << ","  << ord << "), ";
4548         }
4549     }
4550   throw INTERP_KERNEL::Exception(oss.str().c_str());
4551 }
4552
4553 int MEDFileFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
4554 {
4555   int ret=0;
4556   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
4557   oss.precision(15);
4558   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
4559     {
4560       const MEDFileField1TSWithoutSDA *tmp(*it);
4561       if(tmp)
4562         {
4563           int it,ord;
4564           double ti=tmp->getTime(it,ord);
4565           if(fabs(time-ti)<eps)
4566             return ret;
4567           else
4568             oss << ti << ", ";
4569         }
4570     }
4571   throw INTERP_KERNEL::Exception(oss.str().c_str());
4572 }
4573
4574 std::vector< std::pair<int,int> > MEDFileFieldMultiTSWithoutSDA::getIterations() const
4575 {
4576   int lgth=_time_steps.size();
4577   std::vector< std::pair<int,int> > ret(lgth);
4578   for(int i=0;i<lgth;i++)
4579     _time_steps[i]->fillIteration(ret[i]);
4580   return ret;
4581 }
4582
4583 /*!
4584  * 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'
4585  * This method returns two things.
4586  * - The absolute dimension of 'this' in first parameter. 
4587  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
4588  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
4589  *
4590  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
4591  * Only these 3 discretizations will be taken into account here.
4592  *
4593  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
4594  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
4595  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
4596  *
4597  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
4598  * 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'.
4599  * 
4600  * Let's consider the typical following case :
4601  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
4602  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
4603  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
4604  *   TETRA4 and SEG2
4605  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
4606  *
4607  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
4608  * 
4609  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
4610  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
4611  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
4612  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
4613  */
4614 int MEDFileFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
4615 {
4616   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
4617 }
4618
4619 std::vector< std::vector<TypeOfField> > MEDFileFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
4620 {
4621   int lgth=_time_steps.size();
4622   std::vector< std::vector<TypeOfField> > ret(lgth);
4623   for(int i=0;i<lgth;i++)
4624     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
4625   return ret;
4626 }
4627
4628 /*!
4629  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
4630  */
4631 std::vector< std::vector< std::pair<int,int> > > MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType(int iteration, int order, const char *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 throw(INTERP_KERNEL::Exception)
4632 {
4633   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
4634 }
4635
4636 /*!
4637  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
4638  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
4639  */
4640 std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2(int iteration, int order, const char *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 throw(INTERP_KERNEL::Exception)
4641 {
4642   return getTimeStepEntry(iteration,order).getFieldSplitedByType2(mname,types,typesF,pfls,locs);
4643 }
4644
4645 const MEDFileField1TSWithoutSDA& MEDFileFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const throw(INTERP_KERNEL::Exception)
4646 {
4647   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4648     if((*it)->isDealingTS(iteration,order))
4649       return *(*it);
4650   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepEntry : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
4651   std::vector< std::pair<int,int> > vp=getIterations();
4652   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
4653     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
4654   throw INTERP_KERNEL::Exception(oss.str().c_str());
4655 }
4656
4657 MEDFileField1TSWithoutSDA& MEDFileFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) throw(INTERP_KERNEL::Exception)
4658 {
4659   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>  >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4660     if((*it)->isDealingTS(iteration,order))
4661       return *(*it);
4662   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepEntry : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
4663   std::vector< std::pair<int,int> > vp=getIterations();
4664   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
4665     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
4666   throw INTERP_KERNEL::Exception(oss.str().c_str());
4667 }
4668
4669 const MEDFileField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const throw(INTERP_KERNEL::Exception)
4670 {
4671   if(pos<0 || pos>=(int)_time_steps.size())
4672     {
4673       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
4674       throw INTERP_KERNEL::Exception(oss.str().c_str());
4675     }
4676   const MEDFileField1TSWithoutSDA *item=_time_steps[pos];
4677   if(item==0)
4678     {
4679       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
4680       oss << "\nTry to use following method eraseEmptyTS !";
4681       throw INTERP_KERNEL::Exception(oss.str().c_str());
4682     }
4683   return item;
4684 }
4685
4686 MEDFileField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) throw(INTERP_KERNEL::Exception)
4687 {
4688   if(pos<0 || pos>=(int)_time_steps.size())
4689     {
4690       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
4691       throw INTERP_KERNEL::Exception(oss.str().c_str());
4692     }
4693   MEDFileField1TSWithoutSDA *item=_time_steps[pos];
4694   if(item==0)
4695     {
4696       std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
4697       oss << "\nTry to use following method eraseEmptyTS !";
4698       throw INTERP_KERNEL::Exception(oss.str().c_str());
4699     }
4700   return item;
4701 }
4702
4703 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
4704 {
4705   std::vector<std::string> ret;
4706   std::set<std::string> ret2;
4707   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4708     {
4709       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
4710       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4711         if(ret2.find(*it2)==ret2.end())
4712           {
4713             ret.push_back(*it2);
4714             ret2.insert(*it2);
4715           }
4716     }
4717   return ret;
4718 }
4719
4720 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
4721 {
4722   std::vector<std::string> ret;
4723   std::set<std::string> ret2;
4724   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4725     {
4726       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
4727       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4728         if(ret2.find(*it2)==ret2.end())
4729           {
4730             ret.push_back(*it2);
4731             ret2.insert(*it2);
4732           }
4733     }
4734   return ret;
4735 }
4736
4737 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
4738 {
4739   std::vector<std::string> ret;
4740   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4741     {
4742       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
4743       ret.insert(ret.end(),tmp.begin(),tmp.end());
4744     }
4745   return ret;
4746 }
4747
4748 std::vector<std::string> MEDFileFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
4749 {
4750   std::vector<std::string> ret;
4751   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4752     {
4753       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
4754       ret.insert(ret.end(),tmp.begin(),tmp.end());
4755     }
4756   return ret;
4757 }
4758
4759 void MEDFileFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
4760 {
4761   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4762     (*it)->changePflsRefsNamesGen2(mapOfModif);
4763 }
4764
4765 void MEDFileFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
4766 {
4767   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
4768     (*it)->changeLocsRefsNamesGen2(mapOfModif);
4769 }
4770
4771 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
4772 {
4773   return new MEDFileFieldMultiTS;
4774 }
4775
4776 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
4777 {
4778   return new MEDFileFieldMultiTS(fileName);
4779 }
4780
4781 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
4782 {
4783   return new MEDFileFieldMultiTS(fileName,fieldName);
4784 }
4785
4786 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool deepCpy)
4787 {
4788   return new MEDFileFieldMultiTS(other,deepCpy);
4789 }
4790
4791 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception)
4792 {
4793   const MEDFileField1TSWithoutSDA *item=_content->getTimeStepAtPos2(pos);
4794   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*item,false);
4795   ret->shallowCpyGlobs(*this);
4796   ret->incrRef();
4797   return ret;
4798 }
4799
4800 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
4801 {
4802   int pos=getPosOfTimeStep(iteration,order);
4803   return getTimeStepAtPos(pos);
4804 }
4805
4806 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
4807 {
4808   int pos=getPosGivenTime(time,eps);
4809   return getTimeStepAtPos(pos);
4810 }
4811
4812 MEDFileFieldMultiTSIterator *MEDFileFieldMultiTS::iterator() throw(INTERP_KERNEL::Exception)
4813 {
4814   return new MEDFileFieldMultiTSIterator(this);
4815 }
4816
4817 std::string MEDFileFieldMultiTS::simpleRepr() const
4818 {
4819   std::ostringstream oss;
4820   _content->simpleRepr(0,oss,-1);
4821   MEDFileFieldGlobsReal::simpleRepr(oss);
4822   return oss.str();
4823 }
4824
4825 void MEDFileFieldMultiTS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
4826 {
4827   writeGlobals(fid,*this);
4828   _content->writeLL(fid,*this);
4829 }
4830
4831 void MEDFileFieldMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
4832 {
4833   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
4834   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
4835   writeLL(fid);
4836 }
4837
4838 /*!
4839  * Performs the job than MEDFileField1TS::getFieldAtLevel except that (iteration,order) couple should be specified !
4840  * If such couple does not exist an exception is thrown.
4841  */
4842 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
4843 {
4844   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
4845   return myF1TS.getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this);
4846 }
4847
4848 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const throw(INTERP_KERNEL::Exception)
4849 {
4850   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
4851   return myF1TS.getFieldAtTopLevel(type,0,renumPol,this);
4852 }
4853
4854 /*!
4855  * Performs the job than MEDFileField1TS::getFieldOnMeshAtLevel except that (iteration,order) couple should be specified !
4856  * If such couple does not exist an exception is thrown.
4857  */
4858 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
4859 {
4860   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
4861   return myF1TS.getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh);
4862 }
4863
4864 /*!
4865  * Performs the job than MEDFileField1TS::getFieldOnMeshAtLevel except that (iteration,order) couple should be specified !
4866  * If such couple does not exist an exception is thrown.
4867  */
4868 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const throw(INTERP_KERNEL::Exception)
4869 {
4870   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
4871   return myF1TS.getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0);
4872 }
4873
4874 /*!
4875  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
4876  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
4877  * This method is useful for MED2 file format when field on different mesh was autorized.
4878  */
4879 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception)
4880 {
4881   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
4882   return myF1TS.getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this);
4883 }
4884
4885 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception)
4886 {
4887   const MEDFileField1TSWithoutSDA& myF1TS=_content->getTimeStepEntry(iteration,order);
4888   return myF1TS.getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this);
4889 }
4890
4891 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception)
4892 {
4893   _content->appendFieldNoProfileSBT(field,*this);
4894 }
4895
4896 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception)
4897 {
4898   _content->appendFieldProfile(field,mesh,meshDimRelToMax,profile,*this);
4899 }
4900
4901 MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> MEDFileFieldMultiTS::getContent()
4902 {
4903   return _content;
4904 }
4905
4906 MEDFileFieldMultiTS::MEDFileFieldMultiTS():_content(new MEDFileFieldMultiTSWithoutSDA)
4907 {
4908 }
4909
4910
4911
4912 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
4913 try:MEDFileFieldGlobsReal(fileName)
4914 {
4915   MEDFileUtilities::CheckFileForRead(fileName);
4916   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
4917   int nbFields=MEDnField(fid);
4918   if(nbFields<1)
4919     {
4920       std::ostringstream oss; oss << "MEDFileFieldMultiTS(const char *fileName) constructor : no fields in file \"" << fileName << "\" !";
4921       throw INTERP_KERNEL::Exception(oss.str().c_str());
4922     }
4923   _content=new MEDFileFieldMultiTSWithoutSDA(fid,0);
4924   //
4925   loadGlobals(fid);
4926 }
4927 catch(INTERP_KERNEL::Exception& e)
4928   {
4929     throw e;
4930   }
4931
4932 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
4933 try:MEDFileFieldGlobsReal(fileName)
4934 {
4935   MEDFileUtilities::CheckFileForRead(fileName);
4936   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
4937   int nbFields=MEDnField(fid);
4938   med_field_type typcha;
4939   bool found=false;
4940   std::vector<std::string> fns(nbFields);
4941   for(int i=0;i<nbFields && !found;i++)
4942     {
4943       int ncomp=MEDfieldnComponent(fid,i+1);
4944       INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4945       INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
4946       INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
4947       INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4948       INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4949       med_bool localMesh;
4950       int nbOfStep;
4951       MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
4952       std::string tmp(nomcha);
4953       fns[i]=tmp;
4954       found=(tmp==fieldName);
4955       if(found)
4956         _content=new MEDFileFieldMultiTSWithoutSDA(fid,i);
4957     }
4958   if(!found)
4959     {
4960       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
4961       std::copy(fns.begin(),fns.end(),std::ostream_iterator<std::string>(oss," "));
4962       throw INTERP_KERNEL::Exception(oss.str().c_str());
4963     }
4964   //
4965   loadGlobals(fid);
4966 }
4967 catch(INTERP_KERNEL::Exception& e)
4968   {
4969     throw e;
4970   }
4971
4972 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool deepCpy)
4973 {
4974   if(!deepCpy)
4975     {
4976       const MEDFileFieldMultiTSWithoutSDA *otherPtr(&other);
4977       otherPtr->incrRef();
4978       _content=const_cast<MEDFileFieldMultiTSWithoutSDA *>(otherPtr);
4979     }
4980   else
4981     {
4982       _content=new MEDFileFieldMultiTSWithoutSDA(other);
4983     }
4984 }
4985
4986 std::vector<std::string> MEDFileFieldMultiTS::getPflsReallyUsed() const
4987 {
4988   return _content->getPflsReallyUsed2();
4989 }
4990
4991 std::vector<std::string> MEDFileFieldMultiTS::getLocsReallyUsed() const
4992 {
4993   return _content->getLocsReallyUsed2();
4994 }
4995
4996 std::vector<std::string> MEDFileFieldMultiTS::getPflsReallyUsedMulti() const
4997 {
4998   return _content->getPflsReallyUsedMulti2();
4999 }
5000
5001 std::vector<std::string> MEDFileFieldMultiTS::getLocsReallyUsedMulti() const
5002 {
5003   return _content->getLocsReallyUsedMulti2();
5004 }
5005
5006 void MEDFileFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5007 {
5008   _content->changePflsRefsNamesGen2(mapOfModif);
5009 }
5010
5011 void MEDFileFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5012 {
5013   _content->changeLocsRefsNamesGen2(mapOfModif);
5014 }
5015
5016 int MEDFileFieldMultiTS::getNumberOfTS() const
5017 {
5018   return _content->getNumberOfTS();
5019 }
5020
5021 void MEDFileFieldMultiTS::eraseEmptyTS() throw(INTERP_KERNEL::Exception)
5022 {
5023   _content->eraseEmptyTS();
5024 }
5025
5026 void MEDFileFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception)
5027 {
5028   _content->eraseTimeStepIds(startIds,endIds);
5029 }
5030
5031 std::vector< std::pair<int,int> > MEDFileFieldMultiTS::getIterations() const
5032 {
5033   return _content->getIterations();
5034 }
5035
5036 int MEDFileFieldMultiTS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception)
5037 {
5038   return _content->getPosOfTimeStep(iteration,order);
5039 }
5040
5041 int MEDFileFieldMultiTS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception)
5042 {
5043   return _content->getPosGivenTime(time,eps);
5044 }
5045
5046 int MEDFileFieldMultiTS::getNonEmptyLevels(int iteration, int order, const char *mname, std::vector<int>& levs) const throw(INTERP_KERNEL::Exception)
5047 {
5048   return _content->getNonEmptyLevels(iteration,order,mname,levs);
5049 }
5050
5051 std::vector< std::vector<TypeOfField> > MEDFileFieldMultiTS::getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception)
5052 {
5053   return _content->getTypesOfFieldAvailable();
5054 }
5055
5056 std::vector< std::vector< std::pair<int,int> > > MEDFileFieldMultiTS::getFieldSplitedByType(int iteration, int order, const char *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 throw(INTERP_KERNEL::Exception)
5057 {
5058   return _content->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
5059 }
5060
5061 std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTS::getFieldSplitedByType2(int iteration, int order, const char *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 throw(INTERP_KERNEL::Exception)
5062 {
5063   return _content->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
5064 }
5065
5066 std::string MEDFileFieldMultiTS::getName() const
5067 {
5068   return _content->getName();
5069 }
5070
5071 void MEDFileFieldMultiTS::setName(const char *name)
5072 {
5073   _content->setName(name);
5074 }
5075
5076 void MEDFileFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
5077 {
5078   _content->simpleRepr(bkOffset,oss,fmtsId);
5079 }
5080
5081 std::vector< std::pair<int,int> > MEDFileFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception)
5082 {
5083   return _content->getTimeSteps(ret1);
5084 }
5085
5086 std::string MEDFileFieldMultiTS::getMeshName() const throw(INTERP_KERNEL::Exception)
5087 {
5088   return _content->getMeshName();
5089 }
5090
5091 void MEDFileFieldMultiTS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
5092 {
5093   _content->setMeshName(newMeshName);
5094 }
5095
5096 bool MEDFileFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
5097 {
5098   return _content->changeMeshNames(modifTab);
5099 }
5100
5101 const std::vector<std::string>& MEDFileFieldMultiTS::getInfo() const throw(INTERP_KERNEL::Exception)
5102 {
5103   return _content->getInfo();
5104 }
5105
5106 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception)
5107 {
5108   return _content->getUndergroundDataArray(iteration,order);
5109 }
5110
5111 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const throw(INTERP_KERNEL::Exception)
5112 {
5113   return _content->getUndergroundDataArrayExt(iteration,order,entries);
5114 }
5115
5116 MEDFileFieldMultiTSIterator::MEDFileFieldMultiTSIterator(MEDFileFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
5117 {
5118   if(fmts)
5119     {
5120       fmts->incrRef();
5121       _nb_iter=fmts->getNumberOfTS();
5122     }
5123 }
5124
5125 MEDFileFieldMultiTSIterator::~MEDFileFieldMultiTSIterator() 
5126 {
5127 }
5128
5129 MEDFileField1TS *MEDFileFieldMultiTSIterator::nextt()
5130 {
5131   if(_iter_id<_nb_iter)
5132     {
5133       MEDFileFieldMultiTS *fmts(_fmts);
5134       if(fmts)
5135         return fmts->getTimeStepAtPos(_iter_id++);
5136       else
5137         return 0;
5138     }
5139   else
5140     return 0;
5141 }
5142
5143 MEDFileFields *MEDFileFields::New()
5144 {
5145   return new MEDFileFields;
5146 }
5147
5148 MEDFileFields *MEDFileFields::New(const char *fileName) throw(INTERP_KERNEL::Exception)
5149 {
5150   return new MEDFileFields(fileName);
5151 }
5152
5153 int MEDFileFields::getNumberOfFields() const
5154 {
5155   return _fields.size();
5156 }
5157
5158 std::vector<std::string> MEDFileFields::getFieldsNames() const throw(INTERP_KERNEL::Exception)
5159 {
5160   std::vector<std::string> ret(_fields.size());
5161   int i=0;
5162   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
5163     {
5164       const MEDFileFieldMultiTSWithoutSDA *f=(*it);
5165       if(f)
5166         {
5167           ret[i]=f->getName();
5168         }
5169       else
5170         {
5171           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
5172           throw INTERP_KERNEL::Exception(oss.str().c_str());
5173         }
5174     }
5175   return ret;
5176 }
5177
5178 std::vector<std::string> MEDFileFields::getMeshesNames() const throw(INTERP_KERNEL::Exception)
5179 {
5180   std::vector<std::string> ret;
5181   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
5182     {
5183       const MEDFileFieldMultiTSWithoutSDA *cur(*it);
5184       if(cur)
5185         ret.push_back(cur->getMeshName());
5186     }
5187   return ret;
5188 }
5189
5190 std::string MEDFileFields::simpleRepr() const
5191 {
5192   std::ostringstream oss;
5193   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
5194   simpleRepr(0,oss);
5195   return oss.str();
5196 }
5197
5198 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
5199 {
5200   int nbOfFields=getNumberOfFields();
5201   std::string startLine(bkOffset,' ');
5202   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
5203   int i=0;
5204   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
5205     {
5206       const MEDFileFieldMultiTSWithoutSDA *cur=(*it);
5207       if(cur)
5208         {
5209           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
5210         }
5211       else
5212         {
5213           oss << startLine << "  - not defined !" << std::endl;
5214         }
5215     }
5216   i=0;
5217   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
5218     {
5219       const MEDFileFieldMultiTSWithoutSDA *cur=(*it);
5220       std::string chapter(17,'0'+i);
5221       oss << startLine << chapter << std::endl;
5222       if(cur)
5223         {
5224           cur->simpleRepr(bkOffset+2,oss,i);
5225         }
5226       else
5227         {
5228           oss << startLine << "  - not defined !" << std::endl;
5229         }
5230       oss << startLine << chapter << std::endl;
5231     }
5232   MEDFileFieldGlobsReal::simpleRepr(oss);
5233 }
5234
5235 MEDFileFields::MEDFileFields()
5236 {
5237 }
5238
5239 MEDFileFields::MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception)
5240 try:MEDFileFieldGlobsReal(fileName)
5241   {
5242     MEDFileUtilities::CheckFileForRead(fileName);
5243     MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
5244     int nbFields=MEDnField(fid);
5245     _fields.resize(nbFields);
5246     med_field_type typcha;
5247     for(int i=0;i<nbFields;i++)
5248       {
5249         int ncomp=MEDfieldnComponent(fid,i+1);
5250         INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5251         INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5252         INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5253         INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5254         INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5255         med_bool localMesh;
5256         int nbOfStep;
5257         MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5258         int ft=MEDFileUtilities::TraduceFieldType(typcha);
5259         std::vector<std::string> infos(ncomp);
5260         for(int j=0;j<ncomp;j++)
5261           infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5262         _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,nomcha,i+1,ft,infos,nbOfStep);
5263       }
5264     loadAllGlobals(fid);
5265   }
5266 catch(INTERP_KERNEL::Exception& e)
5267   {
5268     throw e;
5269   }
5270
5271 void MEDFileFields::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
5272 {
5273   int i=0;
5274   writeGlobals(fid,*this);
5275   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
5276     {
5277       const MEDFileFieldMultiTSWithoutSDA *elt=*it;
5278       if(!elt)
5279         {
5280           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
5281           throw INTERP_KERNEL::Exception(oss.str().c_str());
5282         }
5283       elt->writeLL(fid,*this);
5284     }
5285 }
5286
5287 void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
5288 {
5289   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5290   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
5291   writeLL(fid);
5292 }
5293
5294 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
5295 {
5296   std::vector<std::string> ret;
5297   std::set<std::string> ret2;
5298   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
5299     {
5300       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
5301       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
5302         if(ret2.find(*it2)==ret2.end())
5303           {
5304             ret.push_back(*it2);
5305             ret2.insert(*it2);
5306           }
5307     }
5308   return ret;
5309 }
5310
5311 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
5312 {
5313   std::vector<std::string> ret;
5314   std::set<std::string> ret2;
5315   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
5316     {
5317       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
5318       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
5319         if(ret2.find(*it2)==ret2.end())
5320           {
5321             ret.push_back(*it2);
5322             ret2.insert(*it2);
5323           }
5324     }
5325   return ret;
5326 }
5327
5328 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
5329 {
5330   std::vector<std::string> ret;
5331   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
5332     {
5333       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
5334       ret.insert(ret.end(),tmp.begin(),tmp.end());
5335     }
5336   return ret;
5337 }
5338
5339 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
5340 {
5341   std::vector<std::string> ret;
5342   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
5343     {
5344       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
5345       ret.insert(ret.end(),tmp.begin(),tmp.end());
5346     }
5347   return ret;
5348 }
5349
5350 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5351 {
5352   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
5353     (*it)->changePflsRefsNamesGen2(mapOfModif);
5354 }
5355
5356 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception)
5357 {
5358   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
5359     (*it)->changeLocsRefsNamesGen2(mapOfModif);
5360 }
5361
5362 void MEDFileFields::resize(int newSize) throw(INTERP_KERNEL::Exception)
5363 {
5364   _fields.resize(newSize);
5365 }
5366
5367 void MEDFileFields::pushField(MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
5368 {
5369   if(!field)
5370     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
5371   _fields.push_back(field->getContent());
5372   appendGlobs(*field,1e-12);
5373 }
5374
5375 void MEDFileFields::setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
5376 {
5377   if(!field)
5378     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
5379   if(i>=(int)_fields.size())
5380     _fields.resize(i+1);
5381   _fields[i]=field->getContent();
5382   appendGlobs(*field,1e-12);
5383 }
5384
5385 void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception)
5386 {
5387   if(i<0 || i>=(int)_fields.size())
5388     {
5389       std::ostringstream oss; oss << "MEDFileFields::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
5390       throw INTERP_KERNEL::Exception(oss.str().c_str());
5391     }
5392   _fields.erase(_fields.begin()+i);
5393 }
5394
5395 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
5396 {
5397   bool ret=false;
5398   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
5399     {
5400       MEDFileFieldMultiTSWithoutSDA *cur(*it);
5401       if(cur)
5402         ret=cur->changeMeshNames(modifTab) || ret;
5403     }
5404   return ret;
5405 }
5406
5407 /*!
5408  * \param [in] meshName the name of the mesh that will be renumbered.
5409  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
5410  *             This code corresponds to the distribution of types in the corresponding mesh.
5411  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
5412  * \param [in] renumO2N the old to new renumber array.
5413  * \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 
5414  *         field in \a this.
5415  */
5416 bool MEDFileFields::renumberEntitiesLyingOnMesh(const char *meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N) throw(INTERP_KERNEL::Exception)
5417 {
5418   bool ret=false;
5419   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
5420     {
5421       MEDFileFieldMultiTSWithoutSDA *fmts(*it);
5422       if(fmts)
5423         {
5424           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
5425         }
5426     }
5427   return ret;
5428 }
5429
5430 MEDFileFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception)
5431 {
5432   if(i<0 || i>=(int)_fields.size())
5433     {
5434       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
5435       throw INTERP_KERNEL::Exception(oss.str().c_str());
5436     }
5437   const MEDFileFieldMultiTSWithoutSDA *fmts=_fields[i];
5438   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New(*fmts,false);
5439   ret->shallowCpyGlobs(*this);
5440   ret->incrRef();
5441   return ret;
5442 }
5443
5444 MEDFileFieldMultiTS *MEDFileFields::getFieldWithName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
5445 {
5446   return getFieldAtPos(getPosFromFieldName(fieldName));
5447 }
5448
5449 MEDFileFieldsIterator *MEDFileFields::iterator() throw(INTERP_KERNEL::Exception)
5450 {
5451   return new MEDFileFieldsIterator(this);
5452 }
5453
5454 int MEDFileFields::getPosFromFieldName(const char *fieldName) const throw(INTERP_KERNEL::Exception)
5455 {
5456   std::string tmp(fieldName);
5457   std::vector<std::string> poss;
5458   for(std::size_t i=0;i<_fields.size();i++)
5459     {
5460       const MEDFileFieldMultiTSWithoutSDA *f=_fields[i];
5461       if(f)
5462         {
5463           std::string fname(f->getName());
5464           if(tmp==fname)
5465             return i;
5466           else
5467             poss.push_back(fname);
5468         }
5469     }
5470   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
5471   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
5472   oss << " !";
5473   throw INTERP_KERNEL::Exception(oss.str().c_str());
5474 }
5475
5476 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
5477 {
5478   if(fs)
5479     {
5480       fs->incrRef();
5481       _nb_iter=fs->getNumberOfFields();
5482     }
5483 }
5484
5485 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
5486 {
5487 }
5488
5489 MEDFileFieldMultiTS *MEDFileFieldsIterator::nextt()
5490 {
5491   if(_iter_id<_nb_iter)
5492     {
5493       MEDFileFields *fs(_fs);
5494       if(fs)
5495         return fs->getFieldAtPos(_iter_id++);
5496       else
5497         return 0;
5498     }
5499   else
5500     return 0;
5501 }