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