Salome HOME
Split MEDFileField implementation into several parts to make eclipse and developper...
[tools/medcoupling.git] / src / MEDLoader / MEDFileFieldGlobs.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (EDF R&D)
20
21 #include "MEDFileFieldGlobs.hxx"
22 #include "MEDFileField.txx"
23 #include "MEDFileMesh.hxx"
24 #include "MEDLoaderBase.hxx"
25 #include "MEDLoaderTraits.hxx"
26 #include "MEDFileSafeCaller.txx"
27 #include "MEDFileFieldOverView.hxx"
28 #include "MEDFileBlowStrEltUp.hxx"
29 #include "MEDFileFieldVisitor.hxx"
30
31 #include "MEDCouplingFieldDiscretization.hxx"
32 #include "MCType.hxx"
33
34 #include "InterpKernelAutoPtr.hxx"
35 #include "CellModel.hxx"
36
37 #include <algorithm>
38 #include <iterator>
39
40 using namespace MEDCoupling;
41
42 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
43 {
44   if(id>=(int)_pfls.size())
45     _pfls.resize(id+1);
46   _pfls[id]=DataArrayInt::New();
47   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
48   _pfls[id]->setName(pflName);
49   _pfls[id]->alloc(lgth,1);
50   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
51   _pfls[id]->applyLin(1,-1,0);//Converting into C format
52 }
53
54 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
55 {
56   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
57   int sz;
58   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
59   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
60   if(i>=(int)_pfls.size())
61     _pfls.resize(i+1);
62   _pfls[i]=DataArrayInt::New();
63   _pfls[i]->alloc(sz,1);
64   _pfls[i]->setName(pflCpp.c_str());
65   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
66   _pfls[i]->applyLin(1,-1,0);//Converting into C format
67 }
68
69 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
70 {
71   int nbOfPfls=_pfls.size();
72   for(int i=0;i<nbOfPfls;i++)
73     {
74       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
75       cpy->applyLin(1,1,0);
76       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
77       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
78       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
79     }
80   //
81   int nbOfLocs=_locs.size();
82   for(int i=0;i<nbOfLocs;i++)
83     _locs[i]->writeLL(fid);
84 }
85
86 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
87 {
88   std::vector<std::string> pfls=getPfls();
89   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
90     {
91       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
92       if(it2==pfls.end())
93         {
94           _pfls.push_back(*it);
95         }
96       else
97         {
98           int id=std::distance(pfls.begin(),it2);
99           if(!(*it)->isEqual(*_pfls[id]))
100             {
101               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
102               throw INTERP_KERNEL::Exception(oss.str());
103             }
104         }
105     }
106   std::vector<std::string> locs=getLocs();
107   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
108     {
109       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
110       if(it2==locs.end())
111         {
112           _locs.push_back(*it);
113         }
114       else
115         {
116           int id=std::distance(locs.begin(),it2);
117           if(!(*it)->isEqual(*_locs[id],eps))
118             {
119               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
120               throw INTERP_KERNEL::Exception(oss.str());
121             }
122         }
123     }
124 }
125
126 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
127 {
128   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
129     getProfile((*it).c_str());
130 }
131
132 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
133 {
134   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
135     getLocalization((*it).c_str());
136 }
137
138 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
139 {
140   std::vector<std::string> profiles=real.getPflsReallyUsed();
141   int sz=profiles.size();
142   _pfls.resize(sz);
143   for(int i=0;i<sz;i++)
144     loadProfileInFile(fid,i,profiles[i].c_str());
145   //
146   std::vector<std::string> locs=real.getLocsReallyUsed();
147   sz=locs.size();
148   _locs.resize(sz);
149   for(int i=0;i<sz;i++)
150     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
151 }
152
153 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
154 {
155   int nProfil=MEDnProfile(fid);
156   for(int i=0;i<nProfil;i++)
157     loadProfileInFile(fid,i);
158   int sz=MEDnLocalization(fid);
159   _locs.resize(sz);
160   for(int i=0;i<sz;i++)
161     {
162       _locs[i]=MEDFileFieldLoc::New(fid,i,entities);
163     }
164 }
165
166 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
167 {
168   return new MEDFileFieldGlobs(fid);
169 }
170
171 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
172 {
173   return new MEDFileFieldGlobs;
174 }
175
176 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
177 {
178   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
179 }
180
181 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
182 {
183   std::vector<const BigMemoryObject *> ret;
184   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
185     ret.push_back((const DataArrayInt *)*it);
186   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
187     ret.push_back((const MEDFileFieldLoc *)*it);
188   return ret;
189 }
190
191 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
192 {
193   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
194   std::size_t i=0;
195   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
196     {
197       if((const DataArrayInt *)*it)
198         ret->_pfls[i]=(*it)->deepCopy();
199     }
200   i=0;
201   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
202     {
203       if((const MEDFileFieldLoc*)*it)
204         ret->_locs[i]=(*it)->deepCopy();
205     }
206   return ret.retn();
207 }
208
209 /*!
210  * \throw if a profile in \a pfls in not in \a this.
211  * \throw if a localization in \a locs in not in \a this.
212  * \sa MEDFileFieldGlobs::deepCpyPart
213  */
214 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
215 {
216   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
217   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
218     {
219       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
220       if(!pfl)
221         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
222       pfl->incrRef();
223       MCAuto<DataArrayInt> pfl2(pfl);
224       ret->_pfls.push_back(pfl2);
225     }
226   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
227     {
228       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
229       if(!loc)
230         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
231       loc->incrRef();
232       MCAuto<MEDFileFieldLoc> loc2(loc);
233       ret->_locs.push_back(loc2);
234     }
235   ret->setFileName(getFileName());
236   return ret.retn();
237 }
238
239 /*!
240  * \throw if a profile in \a pfls in not in \a this.
241  * \throw if a localization in \a locs in not in \a this.
242  * \sa MEDFileFieldGlobs::shallowCpyPart
243  */
244 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
245 {
246   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
247   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
248     {
249       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
250       if(!pfl)
251         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
252       ret->_pfls.push_back(pfl->deepCopy());
253     }
254   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
255     {
256       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
257       if(!loc)
258         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
259       ret->_locs.push_back(loc->deepCopy());
260     }
261   ret->setFileName(getFileName());
262   return ret.retn();
263 }
264
265 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
266 {
267 }
268
269 MEDFileFieldGlobs::MEDFileFieldGlobs()
270 {
271 }
272
273 MEDFileFieldGlobs::~MEDFileFieldGlobs()
274 {
275 }
276
277 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
278 {
279   oss << "Profiles :\n";
280   std::size_t n=_pfls.size();
281   for(std::size_t i=0;i<n;i++)
282     {
283       oss << "  - #" << i << " ";
284       const DataArrayInt *pfl=_pfls[i];
285       if(pfl)
286         oss << "\"" << pfl->getName() << "\"\n";
287       else
288         oss << "EMPTY !\n";
289     }
290   n=_locs.size();
291   oss << "Localizations :\n";
292   for(std::size_t i=0;i<n;i++)
293     {
294       oss << "  - #" << i << " ";
295       const MEDFileFieldLoc *loc=_locs[i];
296       if(loc)
297         loc->simpleRepr(oss);
298       else
299         oss<< "EMPTY !\n";
300     }
301 }
302
303 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
304 {
305   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
306     {
307       DataArrayInt *elt(*it);
308       if(elt)
309         {
310           std::string name(elt->getName());
311           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
312             {
313               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
314                 {
315                   elt->setName((*it2).second.c_str());
316                   return;
317                 }
318             }
319         }
320     }
321 }
322
323 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
324 {
325   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
326     {
327       MEDFileFieldLoc *elt(*it);
328       if(elt)
329         {
330           std::string name(elt->getName());
331           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
332             {
333               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
334                 {
335                   elt->setName((*it2).second.c_str());
336                   return;
337                 }
338             }
339         }
340     }
341 }
342
343 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
344 {
345   if(locId<0 || locId>=(int)_locs.size())
346     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
347   return _locs[locId]->getNbOfGaussPtPerCell();
348 }
349
350 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
351 {
352   return getLocalizationFromId(getLocalizationId(locName));
353 }
354
355 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
356 {
357   if(locId<0 || locId>=(int)_locs.size())
358     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
359   return *_locs[locId];
360 }
361
362 /// @cond INTERNAL
363 namespace MEDCouplingImpl
364 {
365   class LocFinder
366   {
367   public:
368     LocFinder(const std::string& loc):_loc(loc) { }
369     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
370   private:
371     const std::string &_loc;
372   };
373
374   class PflFinder
375   {
376   public:
377     PflFinder(const std::string& pfl):_pfl(pfl) { }
378     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
379   private:
380     const std::string& _pfl;
381   };
382 }
383 /// @endcond
384
385 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
386 {
387   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
388   if(it==_locs.end())
389     {
390       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
391       for(it=_locs.begin();it!=_locs.end();it++)
392         oss << "\"" << (*it)->getName() << "\", ";
393       throw INTERP_KERNEL::Exception(oss.str());
394     }
395   return std::distance(_locs.begin(),it);
396 }
397
398 /*!
399  * The returned value is never null.
400  */
401 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
402 {
403   std::string pflNameCpp(pflName);
404   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
405   if(it==_pfls.end())
406     {
407       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
408       for(it=_pfls.begin();it!=_pfls.end();it++)
409         oss << "\"" << (*it)->getName() << "\", ";
410       throw INTERP_KERNEL::Exception(oss.str());
411     }
412   return *it;
413 }
414
415 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
416 {
417   if(pflId<0 || pflId>=(int)_pfls.size())
418     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
419   return _pfls[pflId];
420 }
421
422 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
423 {
424   if(locId<0 || locId>=(int)_locs.size())
425     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
426   return *_locs[locId];
427 }
428
429 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
430 {
431   return getLocalizationFromId(getLocalizationId(locName));
432 }
433
434 /*!
435  * The returned value is never null.
436  */
437 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
438 {
439   std::string pflNameCpp(pflName);
440   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
441   if(it==_pfls.end())
442     {
443       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
444       for(it=_pfls.begin();it!=_pfls.end();it++)
445         oss << "\"" << (*it)->getName() << "\", ";
446       throw INTERP_KERNEL::Exception(oss.str());
447     }
448   return *it;
449 }
450
451 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
452 {
453   if(pflId<0 || pflId>=(int)_pfls.size())
454     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
455   return _pfls[pflId];
456 }
457
458 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
459 {
460   std::vector< MCAuto<DataArrayInt> > newPfls;
461   int i=0;
462   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
463     {
464       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
465         newPfls.push_back(*it);
466     }
467   _pfls=newPfls;
468 }
469
470 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
471 {
472   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
473   int i=0;
474   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
475     {
476       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
477         newLocs.push_back(*it);
478     }
479   _locs=newLocs;
480 }
481
482 void MEDFileFieldGlobs::killStructureElementsInGlobs()
483 {
484   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
485   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
486     {
487       if((*it).isNull())
488         continue;
489       if(!(*it)->isOnStructureElement())
490         newLocs.push_back(*it);
491     }
492   _locs=newLocs;
493 }
494
495 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
496 {
497   int sz=_pfls.size();
498   std::vector<std::string> ret(sz);
499   for(int i=0;i<sz;i++)
500     ret[i]=_pfls[i]->getName();
501   return ret;
502 }
503
504 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
505 {
506   int sz=_locs.size();
507   std::vector<std::string> ret(sz);
508   for(int i=0;i<sz;i++)
509     ret[i]=_locs[i]->getName();
510   return ret;
511 }
512
513 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
514 {
515   std::vector<std::string> v=getPfls();
516   std::string s(pflName);
517   return std::find(v.begin(),v.end(),s)!=v.end();
518 }
519
520 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
521 {
522   std::vector<std::string> v=getLocs();
523   std::string s(locName);
524   return std::find(v.begin(),v.end(),s)!=v.end();
525 }
526
527 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
528 {
529   std::map<int,std::vector<int> > m;
530   int i=0;
531   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
532     {
533       const DataArrayInt *tmp=(*it);
534       if(tmp)
535         {
536           m[tmp->getHashCode()].push_back(i);
537         }
538     }
539   std::vector< std::vector<int> > ret;
540   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
541     {
542       if((*it2).second.size()>1)
543         {
544           std::vector<int> ret0;
545           bool equalityOrNot=false;
546           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
547             {
548               std::vector<int>::const_iterator it4=it3; it4++;
549               for(;it4!=(*it2).second.end();it4++)
550                 {
551                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
552                     {
553                       if(!equalityOrNot)
554                         ret0.push_back(*it3);
555                       ret0.push_back(*it4);
556                       equalityOrNot=true;
557                     }
558                 }
559             }
560           if(!ret0.empty())
561             ret.push_back(ret0);
562         }
563     }
564   return ret;
565 }
566
567 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
568 {
569   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
570 }
571
572 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
573 {
574   std::string name(pfl->getName());
575   if(name.empty())
576     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
577   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
578     if(name==(*it)->getName())
579       {
580         if(!pfl->isEqual(*(*it)))
581           {
582             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
583             throw INTERP_KERNEL::Exception(oss.str());
584           }
585       }
586   pfl->incrRef();
587   _pfls.push_back(pfl);
588 }
589
590 void MEDFileFieldGlobs::appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
591 {
592   std::string name(locName);
593   if(name.empty())
594     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
595   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
596   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
597     if((*it)->isName(locName))
598       {
599         if(!(*it)->isEqual(*obj,1e-12))
600           {
601             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
602             throw INTERP_KERNEL::Exception(oss.str());
603           }
604       }
605   _locs.push_back(obj);
606 }
607
608 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
609 {
610   std::vector<std::string> names=getPfls();
611   return CreateNewNameNotIn("NewPfl_",names);
612 }
613
614 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
615 {
616   std::vector<std::string> names=getLocs();
617   return CreateNewNameNotIn("NewLoc_",names);
618 }
619
620 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
621 {
622   for(std::size_t sz=0;sz<100000;sz++)
623     {
624       std::ostringstream tryName;
625       tryName << prefix << sz;
626       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
627         return tryName.str();
628     }
629   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
630 }
631
632 /*!
633  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
634  *  \param [in] fname - the file name.
635  */
636 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
637 {
638 }
639
640 /*!
641  * Creates an empty MEDFileFieldGlobsReal.
642  */
643 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
644 {
645 }
646
647 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
648 {
649   return 0;
650 }
651
652 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
653 {
654   std::vector<const BigMemoryObject *> ret;
655   ret.push_back((const MEDFileFieldGlobs *)_globals);
656   return ret;
657 }
658
659 /*!
660  * Returns a string describing profiles and Gauss points held in \a this.
661  *  \return std::string - the description string.
662  */
663 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
664 {
665   const MEDFileFieldGlobs *glob=_globals;
666   std::ostringstream oss2; oss2 << glob;
667   std::string stars(oss2.str().length(),'*');
668   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
669   if(glob)
670     glob->simpleRepr(oss);
671   else
672     oss << "NO GLOBAL INFORMATION !\n";
673 }
674
675 void MEDFileFieldGlobsReal::resetContent()
676 {
677   _globals=MEDFileFieldGlobs::New();
678 }
679
680 void MEDFileFieldGlobsReal::killStructureElementsInGlobs()
681 {
682   contentNotNull()->killStructureElementsInGlobs();
683 }
684
685 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
686 {
687 }
688
689 /*!
690  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
691  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
692  */
693 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
694 {
695   _globals=other._globals;
696 }
697
698 /*!
699  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
700  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
701  */
702 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
703 {
704   const MEDFileFieldGlobs *otherg(other._globals);
705   if(!otherg)
706     return ;
707   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
708 }
709
710 /*!
711  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
712  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
713  */
714 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
715 {
716   const MEDFileFieldGlobs *otherg(other._globals);
717   if(!otherg)
718     return ;
719   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
720 }
721
722 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
723 {
724   _globals=other._globals;
725   if((const MEDFileFieldGlobs *)_globals)
726     _globals=other._globals->deepCopy();
727 }
728
729 /*!
730  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
731  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
732  *  \param [in] eps - a precision used to compare Gauss points with same name held by
733  *         \a this and \a other MEDFileFieldGlobsReal.
734  *  \throw If \a this and \a other hold profiles with equal names but different ids.
735  *  \throw If  \a this and \a other hold different Gauss points with equal names.
736  */
737 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
738 {
739   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
740   if(thisGlobals==otherGlobals)
741     return ;
742   if(!thisGlobals)
743     {
744       _globals=other._globals;
745       return ;
746     }
747   _globals->appendGlobs(*other._globals,eps);
748 }
749
750 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
751 {
752   checkGlobsPflsPartCoherency();
753   checkGlobsLocsPartCoherency();
754 }
755
756 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
757 {
758   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
759 }
760
761 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
762 {
763   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
764 }
765
766 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
767 {
768   contentNotNull()->loadProfileInFile(fid,id,pflName);
769 }
770
771 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
772 {
773   contentNotNull()->loadProfileInFile(fid,id);
774 }
775
776 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
777 {
778   contentNotNull()->loadGlobals(fid,*this);
779 }
780
781 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
782 {
783   contentNotNull()->loadAllGlobals(fid,entities);
784 }
785
786 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
787 {
788   contentNotNull()->writeGlobals(fid,opt);
789 }
790
791 /*!
792  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
793  * or getPflsReallyUsedMulti().
794  *  \return std::vector<std::string> - a sequence of names of all profiles.
795  */
796 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
797 {
798   return contentNotNull()->getPfls();
799 }
800
801 /*!
802  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
803  * or getLocsReallyUsedMulti().
804  *  \return std::vector<std::string> - a sequence of names of all localizations.
805  */
806 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
807 {
808   return contentNotNull()->getLocs();
809 }
810
811 /*!
812  * Checks if the profile with a given name exists.
813  *  \param [in] pflName - the profile name of interest.
814  *  \return bool - \c true if the profile named \a pflName exists.
815  */
816 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
817 {
818   return contentNotNull()->existsPfl(pflName);
819 }
820
821 /*!
822  * Checks if the localization with a given name exists.
823  *  \param [in] locName - the localization name of interest.
824  *  \return bool - \c true if the localization named \a locName exists.
825  */
826 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
827 {
828   return contentNotNull()->existsLoc(locName);
829 }
830
831 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
832 {
833   return contentNotNull()->createNewNameOfPfl();
834 }
835
836 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
837 {
838   return contentNotNull()->createNewNameOfLoc();
839 }
840
841 /*!
842  * Sets the name of a MED file.
843  *  \param [inout] fileName - the file name.
844  */
845 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
846 {
847   contentNotNull()->setFileName(fileName);
848 }
849
850 /*!
851  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
852  * in the same order.
853  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
854  *          Each item of this sequence is a vector containing ids of equal profiles.
855  */
856 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
857 {
858   return contentNotNull()->whichAreEqualProfiles();
859 }
860
861 /*!
862  * Finds equal localizations.
863  *  \param [in] eps - a precision used to compare real values of the localizations.
864  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
865  *          Each item of this sequence is a vector containing ids of equal localizations.
866  */
867 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
868 {
869   return contentNotNull()->whichAreEqualLocs(eps);
870 }
871
872 /*!
873  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
874  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
875  *        this sequence is a pair whose 
876  *        - the first item is a vector of profile names to replace by the second item,
877  *        - the second item is a profile name to replace every profile name of the first item.
878  */
879 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
880 {
881   contentNotNull()->changePflsNamesInStruct(mapOfModif);
882 }
883
884 /*!
885  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
886  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
887  *        this sequence is a pair whose 
888  *        - the first item is a vector of localization names to replace by the second item,
889  *        - the second item is a localization name to replace every localization name of the first item.
890  */
891 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
892 {
893   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
894 }
895
896 /*!
897  * Replaces references to some profiles (a reference is a profile name) by references
898  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
899  * them-selves accordingly. <br>
900  * This method is a generalization of changePflName().
901  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
902  *        this sequence is a pair whose 
903  *        - the first item is a vector of profile names to replace by the second item,
904  *        - the second item is a profile name to replace every profile of the first item.
905  * \sa changePflsRefsNamesGen()
906  * \sa changePflName()
907  */
908 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
909 {
910   changePflsRefsNamesGen(mapOfModif);
911   changePflsNamesInStruct(mapOfModif);
912 }
913
914 /*!
915  * Replaces references to some localizations (a reference is a localization name) by references
916  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
917  * them-selves accordingly. <br>
918  * This method is a generalization of changeLocName().
919  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
920  *        this sequence is a pair whose 
921  *        - the first item is a vector of localization names to replace by the second item,
922  *        - the second item is a localization name to replace every localization of the first item.
923  * \sa changeLocsRefsNamesGen()
924  * \sa changeLocName()
925  */
926 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
927 {
928   changeLocsRefsNamesGen(mapOfModif);
929   changeLocsNamesInStruct(mapOfModif);
930 }
931
932 /*!
933  * Renames the profile having a given name and updates references to this profile.
934  *  \param [in] oldName - the name of the profile to rename.
935  *  \param [in] newName - a new name of the profile.
936  * \sa changePflsNames().
937  */
938 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
939 {
940   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
941   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
942   mapOfModif[0]=p;
943   changePflsNames(mapOfModif);
944 }
945
946 /*!
947  * Renames the localization having a given name and updates references to this localization.
948  *  \param [in] oldName - the name of the localization to rename.
949  *  \param [in] newName - a new name of the localization.
950  * \sa changeLocsNames().
951  */
952 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
953 {
954   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
955   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
956   mapOfModif[0]=p;
957   changeLocsNames(mapOfModif);
958 }
959
960 /*!
961  * Removes duplicated profiles. Returns a map used to update references to removed 
962  * profiles via changePflsRefsNamesGen().
963  * Equal profiles are found using whichAreEqualProfiles().
964  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
965  *          a sequence describing the performed replacements of profiles. Each element of
966  *          this sequence is a pair whose
967  *          - the first item is a vector of profile names replaced by the second item,
968  *          - the second item is a profile name replacing every profile of the first item.
969  */
970 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
971 {
972   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
973   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
974   int i=0;
975   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
976     {
977       std::vector< std::string > tmp((*it).size());
978       int j=0;
979       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
980         tmp[j]=std::string(getProfileFromId(*it2)->getName());
981       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
982       ret[i]=p;
983       std::vector<int> tmp2((*it).begin()+1,(*it).end());
984       killProfileIds(tmp2);
985     }
986   changePflsRefsNamesGen(ret);
987   return ret;
988 }
989
990 /*!
991  * Removes duplicated localizations. Returns a map used to update references to removed 
992  * localizations via changeLocsRefsNamesGen().
993  * Equal localizations are found using whichAreEqualLocs().
994  *  \param [in] eps - a precision used to compare real values of the localizations.
995  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
996  *          a sequence describing the performed replacements of localizations. Each element of
997  *          this sequence is a pair whose
998  *          - the first item is a vector of localization names replaced by the second item,
999  *          - the second item is a localization name replacing every localization of the first item.
1000  */
1001 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
1002 {
1003   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
1004   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
1005   int i=0;
1006   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
1007     {
1008       std::vector< std::string > tmp((*it).size());
1009       int j=0;
1010       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
1011         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
1012       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
1013       ret[i]=p;
1014       std::vector<int> tmp2((*it).begin()+1,(*it).end());
1015       killLocalizationIds(tmp2);
1016     }
1017   changeLocsRefsNamesGen(ret);
1018   return ret;
1019 }
1020
1021 /*!
1022  * Returns number of Gauss points per cell in a given localization.
1023  *  \param [in] locId - an id of the localization of interest.
1024  *  \return int - the number of the Gauss points per cell.
1025  */
1026 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
1027 {
1028   return contentNotNull()->getNbOfGaussPtPerCell(locId);
1029 }
1030
1031 /*!
1032  * Returns an id of a localization by its name.
1033  *  \param [in] loc - the localization name of interest.
1034  *  \return int - the id of the localization.
1035  *  \throw If there is no a localization named \a loc.
1036  */
1037 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
1038 {
1039   return contentNotNull()->getLocalizationId(loc);
1040 }
1041
1042 /*!
1043  * Returns the name of the MED file.
1044  *  \return const std::string&  - the MED file name.
1045  */
1046 std::string MEDFileFieldGlobsReal::getFileName() const
1047 {
1048   return contentNotNull()->getFileName();
1049 }
1050
1051 /*!
1052  * Returns a localization object by its name.
1053  *  \param [in] locName - the name of the localization of interest.
1054  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
1055  *  \throw If there is no a localization named \a locName.
1056  */
1057 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
1058 {
1059   return contentNotNull()->getLocalization(locName);
1060 }
1061
1062 /*!
1063  * Returns a localization object by its id.
1064  *  \param [in] locId - the id of the localization of interest.
1065  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
1066  *  \throw If there is no a localization with id \a locId.
1067  */
1068 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
1069 {
1070   return contentNotNull()->getLocalizationFromId(locId);
1071 }
1072
1073 /*!
1074  * Returns a profile array by its name.
1075  *  \param [in] pflName - the name of the profile of interest.
1076  *  \return const DataArrayInt * - the profile array having the name \a pflName.
1077  *  \throw If there is no a profile named \a pflName.
1078  */
1079 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
1080 {
1081   return contentNotNull()->getProfile(pflName);
1082 }
1083
1084 /*!
1085  * Returns a profile array by its id.
1086  *  \param [in] pflId - the id of the profile of interest.
1087  *  \return const DataArrayInt * - the profile array having the id \a pflId.
1088  *  \throw If there is no a profile with id \a pflId.
1089  */
1090 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
1091 {
1092   return contentNotNull()->getProfileFromId(pflId);
1093 }
1094
1095 /*!
1096  * Returns a localization object, apt for modification, by its id.
1097  *  \param [in] locId - the id of the localization of interest.
1098  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
1099  *          having the id \a locId.
1100  *  \throw If there is no a localization with id \a locId.
1101  */
1102 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
1103 {
1104   return contentNotNull()->getLocalizationFromId(locId);
1105 }
1106
1107 /*!
1108  * Returns a localization object, apt for modification, by its name.
1109  *  \param [in] locName - the name of the localization of interest.
1110  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
1111  *          having the name \a locName.
1112  *  \throw If there is no a localization named \a locName.
1113  */
1114 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
1115 {
1116   return contentNotNull()->getLocalization(locName);
1117 }
1118
1119 /*!
1120  * Returns a profile array, apt for modification, by its name.
1121  *  \param [in] pflName - the name of the profile of interest.
1122  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
1123  *  \throw If there is no a profile named \a pflName.
1124  */
1125 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
1126 {
1127   return contentNotNull()->getProfile(pflName);
1128 }
1129
1130 /*!
1131  * Returns a profile array, apt for modification, by its id.
1132  *  \param [in] pflId - the id of the profile of interest.
1133  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
1134  *  \throw If there is no a profile with id \a pflId.
1135  */
1136 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
1137 {
1138   return contentNotNull()->getProfileFromId(pflId);
1139 }
1140
1141 /*!
1142  * Removes profiles given by their ids. No data is updated to track this removal.
1143  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
1144  */
1145 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
1146 {
1147   contentNotNull()->killProfileIds(pflIds);
1148 }
1149
1150 /*!
1151  * Removes localizations given by their ids. No data is updated to track this removal.
1152  *  \param [in] locIds - a sequence of ids of the localizations to remove.
1153  */
1154 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
1155 {
1156   contentNotNull()->killLocalizationIds(locIds);
1157 }
1158
1159 /*!
1160  * Stores a profile array.
1161  *  \param [in] pfl - the profile array to store.
1162  *  \throw If the name of \a pfl is empty.
1163  *  \throw If a profile with the same name as that of \a pfl already exists but contains
1164  *         different ids.
1165  */
1166 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
1167 {
1168   contentNotNull()->appendProfile(pfl);
1169 }
1170
1171 /*!
1172  * Adds a new localization of Gauss points.
1173  *  \param [in] locName - the name of the new localization.
1174  *  \param [in] geoType - a geometrical type of the reference cell.
1175  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
1176  *         must be \c nbOfNodesPerCell * \c dimOfType.
1177  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
1178  *         must be  _wg_.size() * \c dimOfType.
1179  *  \param [in] w - the weights of Gauss points.
1180  *  \throw If \a locName is empty.
1181  *  \throw If a localization with the name \a locName already exists but is
1182  *         different form the new one.
1183  */
1184 void MEDFileFieldGlobsReal::appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
1185 {
1186   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
1187 }
1188
1189 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
1190 {
1191   MEDFileFieldGlobs *g(_globals);
1192   if(!g)
1193     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
1194   return g;
1195 }
1196
1197 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
1198 {
1199   const MEDFileFieldGlobs *g(_globals);
1200   if(!g)
1201     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
1202   return g;
1203 }
1204
1205 //= MEDFileFieldNameScope
1206
1207 MEDFileFieldNameScope::MEDFileFieldNameScope()
1208 {
1209 }
1210
1211 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName, const std::string& meshName):_name(fieldName),_mesh_name(meshName)
1212 {
1213 }
1214
1215 /*!
1216  * Returns the name of \a this field.
1217  *  \return std::string - a string containing the field name.
1218  */
1219 std::string MEDFileFieldNameScope::getName() const
1220 {
1221   return _name;
1222 }
1223
1224 /*!
1225  * Sets name of \a this field
1226  *  \param [in] name - the new field name.
1227  */
1228 void MEDFileFieldNameScope::setName(const std::string& fieldName)
1229 {
1230   _name=fieldName;
1231 }
1232
1233 std::string MEDFileFieldNameScope::getDtUnit() const
1234 {
1235   return _dt_unit;
1236 }
1237
1238 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
1239 {
1240   _dt_unit=dtUnit;
1241 }
1242
1243 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
1244 {
1245   _name=other._name;
1246   _mesh_name=other._mesh_name;
1247   _dt_unit=other._dt_unit;
1248 }
1249
1250 /*!
1251  * Returns the mesh name.
1252  *  \return std::string - a string holding the mesh name.
1253  *  \throw If \c _field_per_mesh.empty()
1254  */
1255 std::string MEDFileFieldNameScope::getMeshName() const
1256 {
1257   return _mesh_name;
1258 }
1259
1260 void MEDFileFieldNameScope::setMeshName(const std::string& meshName)
1261 {
1262   _mesh_name=meshName;
1263 }
1264