Back to index

salome-med  6.5.0
MEDFileMesh.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDFileMesh.hxx"
00021 #include "MEDFileUtilities.hxx"
00022 #include "MEDLoader.hxx"
00023 #include "MEDLoaderBase.hxx"
00024 
00025 #include "MEDCouplingUMesh.hxx"
00026 
00027 #include "InterpKernelAutoPtr.hxx"
00028 
00029 #include <limits>
00030 #include <cmath>
00031 
00032 using namespace ParaMEDMEM;
00033 
00034 const char MEDFileMesh::DFT_FAM_NAME[]="FAMILLE_ZERO";
00035 
00036 MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.)
00037 {
00038 }
00039 
00040 MEDFileMesh *MEDFileMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
00041 {
00042   std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
00043   if(ms.empty())
00044     {
00045       std::ostringstream oss; oss << "MEDFileMesh::New : no meshes in file \"" << fileName << "\" !";
00046       throw INTERP_KERNEL::Exception(oss.str().c_str());
00047     }
00048   MEDFileUtilities::CheckFileForRead(fileName);
00049   ParaMEDMEM::MEDCouplingMeshType meshType;
00050   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00051   int dt,it;
00052   std::string dummy2;
00053   MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
00054   switch(meshType)
00055     {
00056     case UNSTRUCTURED:
00057       {
00058         MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
00059         ret->loadUMeshFromFile(fid,ms.front().c_str(),dt,it);
00060         ret->incrRef();
00061         return (MEDFileUMesh *)ret;
00062       }
00063     case CARTESIAN:
00064       {
00065         MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
00066         ret->loadCMeshFromFile(fid,ms.front().c_str(),dt,it);
00067         ret->incrRef();
00068         return (MEDFileCMesh *)ret;
00069       }
00070     default:
00071       {
00072         std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << ms.front() << "' exists but unsupported type yet !";
00073         throw INTERP_KERNEL::Exception(oss.str().c_str());
00074       }
00075     }
00076 }
00077 
00078 MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
00079 {
00080   MEDFileUtilities::CheckFileForRead(fileName);
00081   ParaMEDMEM::MEDCouplingMeshType meshType;
00082   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00083   int dummy0,dummy1;
00084   std::string dummy2;
00085   MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
00086   switch(meshType)
00087     {
00088     case UNSTRUCTURED:
00089       {
00090         MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
00091         ret->loadUMeshFromFile(fid,mName,dt,it);
00092         ret->incrRef();
00093         return (MEDFileUMesh *)ret;
00094       }
00095     case CARTESIAN:
00096       {
00097         MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
00098         ret->loadCMeshFromFile(fid,mName,dt,it);
00099         ret->incrRef();
00100         return (MEDFileCMesh *)ret;
00101       }
00102     default:
00103       {
00104         std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << mName << "' exists but unsupported type yet !";
00105         throw INTERP_KERNEL::Exception(oss.str().c_str());
00106       }
00107     }
00108 }
00109 
00110 void MEDFileMesh::write(med_idt fid) const throw(INTERP_KERNEL::Exception)
00111 {
00112   if(!existsFamily(0))
00113     const_cast<MEDFileMesh *>(this)->addFamily(DFT_FAM_NAME,0);
00114   if(_name.empty())
00115     throw INTERP_KERNEL::Exception("MEDFileMesh : name is empty. MED file ask for a NON EMPTY name !");
00116   writeLL(fid);
00117 }
00118 
00119 void MEDFileMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
00120 {
00121   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
00122   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
00123   std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\""; 
00124   MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
00125   write(fid);
00126 }
00127 
00128 bool MEDFileMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
00129 {
00130   if(_order!=other->_order)
00131     {
00132       what="Orders differ !";
00133       return false;
00134     }
00135   if(_iteration!=other->_iteration)
00136     {
00137       what="Iterations differ !";
00138       return false;
00139     }
00140   if(fabs(_time-other->_time)>eps)
00141     {
00142       what="Time values differ !";
00143       return false;
00144     }
00145   if(_dt_unit!=other->_dt_unit)
00146     {
00147       what="Time units differ !";
00148       return false;
00149     }
00150   if(_name!=other->_name)
00151     {
00152       what="Names differ !";
00153       return false;
00154     }
00155   if(_univ_name!=other->_univ_name)
00156     {
00157       what="Univ names differ !";
00158       return false;
00159     }
00160   if(_desc_name!=other->_desc_name)
00161     {
00162       what="Description names differ !";
00163       return false;
00164     }
00165   if(!areGrpsEqual(other,what))
00166     return false;
00167   if(!areFamsEqual(other,what))
00168     return false;
00169   return true;
00170 }
00171 
00172 void MEDFileMesh::clearNonDiscrAttributes() const
00173 {
00174   
00175 }
00176 
00177 void MEDFileMesh::copyFamGrpMapsFrom(const MEDFileMesh& other)
00178 {
00179   _groups=other._groups;
00180   _families=other._families;
00181 }
00182 
00183 std::vector<std::string> MEDFileMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception)
00184 {
00185   std::string oname(name);
00186   std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.find(oname);
00187   std::vector<std::string> grps=getGroupsNames();
00188   if(it==_groups.end())
00189     {
00190       std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
00191       std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
00192       throw INTERP_KERNEL::Exception(oss.str().c_str());
00193     }
00194   return (*it).second;
00195 }
00196 
00197 std::vector<std::string> MEDFileMesh::getFamiliesOnGroups(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception)
00198 {
00199   std::set<std::string> fams;
00200   for(std::vector<std::string>::const_iterator it=grps.begin();it!=grps.end();it++)
00201     {
00202       std::map<std::string, std::vector<std::string> >::const_iterator it2=_groups.find(*it);
00203       if(it2==_groups.end())
00204         {
00205           std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it; 
00206           throw INTERP_KERNEL::Exception(oss.str().c_str());
00207         }
00208       fams.insert((*it2).second.begin(),(*it2).second.end());
00209     }
00210   std::vector<std::string> fams2(fams.begin(),fams.end());
00211   return fams2;
00212 }
00213 
00214 std::vector<int> MEDFileMesh::getFamiliesIdsOnGroup(const char *name) const throw(INTERP_KERNEL::Exception)
00215 {
00216   std::string oname(name);
00217   std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.find(oname);
00218   std::vector<std::string> grps=getGroupsNames();
00219   if(it==_groups.end())
00220     {
00221       std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
00222       std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
00223       throw INTERP_KERNEL::Exception(oss.str().c_str());
00224     }
00225   return getFamiliesIds((*it).second);
00226 }
00227 
00232 void MEDFileMesh::setFamiliesOnGroup(const char *name, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception)
00233 {
00234   std::string oname(name);
00235   _groups[oname]=fams;
00236   for(std::vector<std::string>::const_iterator it1=fams.begin();it1!=fams.end();it1++)
00237     {
00238       std::map<std::string,int>::iterator it2=_families.find(*it1);
00239       if(it2==_families.end())
00240         _families[*it1]=0;
00241     }
00242 }
00243 
00248 void MEDFileMesh::setFamiliesIdsOnGroup(const char *name, const std::vector<int>& famIds) throw(INTERP_KERNEL::Exception)
00249 {
00250   std::string oname(name);
00251   std::vector<std::string> fams(famIds.size());
00252   int i=0;
00253   for(std::vector<int>::const_iterator it1=famIds.begin();it1!=famIds.end();it1++,i++)
00254     {
00255       std::string name2=getFamilyNameGivenId(*it1);
00256       fams[i]=name2;
00257     }
00258   _groups[oname]=fams;
00259 }
00260 
00261 std::vector<std::string> MEDFileMesh::getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception)
00262 {
00263   std::vector<std::string> ret;
00264   for(std::map<std::string, std::vector<std::string> >::const_iterator it1=_groups.begin();it1!=_groups.end();it1++)
00265     {
00266       for(std::vector<std::string>::const_iterator it2=(*it1).second.begin();it2!=(*it1).second.end();it2++)
00267         if((*it2)==name)
00268           {
00269             ret.push_back((*it1).first);
00270             break;
00271           }
00272     }
00273   return ret;
00274 }
00275 
00279 void MEDFileMesh::setGroupsOnFamily(const char *famName, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception)
00280 {
00281   std::string fName(famName);
00282   const std::map<std::string,int>::const_iterator it=_families.find(fName);
00283   if(it==_families.end())
00284     {
00285       std::vector<std::string> fams=getFamiliesNames();
00286       std::ostringstream oss; oss << "No such familyname \"" << fName << "\" !\nAvailable families are :";
00287       std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
00288       throw INTERP_KERNEL::Exception(oss.str().c_str());
00289     }
00290   for(std::vector<std::string>::const_iterator it3=grps.begin();it3!=grps.end();it3++)
00291     {
00292       std::map< std::string, std::vector<std::string> >::iterator it2=_groups.find(*it3);
00293       if(it2!=_groups.end())
00294         (*it2).second.push_back(fName);
00295       else
00296         {
00297           std::vector<std::string> grps2(1,fName);
00298           _groups[*it3]=grps2;
00299         }
00300     }
00301 }
00302 
00303 std::vector<std::string> MEDFileMesh::getGroupsNames() const
00304 {
00305   std::vector<std::string> ret(_groups.size());
00306   int i=0;
00307   for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++,i++)
00308     ret[i]=(*it).first;
00309   return ret;
00310 }
00311 
00312 std::vector<std::string> MEDFileMesh::getFamiliesNames() const
00313 {
00314   std::vector<std::string> ret(_families.size());
00315   int i=0;
00316   for(std::map<std::string, int >::const_iterator it=_families.begin();it!=_families.end();it++,i++)
00317     ret[i]=(*it).first;
00318   return ret;
00319 }
00320 
00324 void MEDFileMesh::assignFamilyNameWithGroupName() throw(INTERP_KERNEL::Exception)
00325 {
00326   std::map<std::string, std::vector<std::string> > groups(_groups);
00327   std::map<std::string,int> newFams;
00328   for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
00329     {
00330       std::vector<std::string> grps=getGroupsOnFamily((*it).first.c_str());
00331       if(grps.size()==1 && groups[grps[0]].size()==1)
00332         {
00333           if(newFams.find(grps[0])!=newFams.end())
00334             {
00335               std::ostringstream oss; oss << "MEDFileMesh::assignFamilyNameWithGroupName : Family \"" << grps[0] << "\" already exists !";
00336               throw INTERP_KERNEL::Exception(oss.str().c_str());
00337             }
00338           newFams[grps[0]]=(*it).second;
00339           std::vector<std::string>& grps2=groups[grps[0]];
00340           std::size_t pos=std::distance(grps2.begin(),std::find(grps2.begin(),grps2.end(),(*it).first));
00341           grps2[pos]=grps[0];
00342         }
00343       else
00344         {
00345           if(newFams.find((*it).first)!=newFams.end())
00346             {
00347               std::ostringstream oss; oss << "MEDFileMesh::assignFamilyNameWithGroupName : Family \"" << (*it).first << "\" already exists !";
00348               throw INTERP_KERNEL::Exception(oss.str().c_str());
00349             }
00350           newFams[(*it).first]=(*it).second;
00351         }
00352     }
00353   _families=newFams;
00354   _groups=groups;
00355 }
00356 
00357 void MEDFileMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception)
00358 {
00359   std::string oname(name);
00360   std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
00361   std::vector<std::string> grps=getGroupsNames();
00362   if(it==_groups.end())
00363     {
00364       std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
00365       std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
00366       throw INTERP_KERNEL::Exception(oss.str().c_str());
00367     }
00368   _groups.erase(it);
00369 }
00370 
00371 void MEDFileMesh::removeFamily(const char *name) throw(INTERP_KERNEL::Exception)
00372 {
00373   std::string oname(name);
00374   std::map<std::string, int >::iterator it=_families.find(oname);
00375   std::vector<std::string> fams=getFamiliesNames();
00376   if(it==_families.end())
00377     {
00378       std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :";
00379       std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
00380       throw INTERP_KERNEL::Exception(oss.str().c_str());
00381     }
00382   _families.erase(it);
00383   for(std::map<std::string, std::vector<std::string> >::iterator it3=_groups.begin();it3!=_groups.end();it3++)
00384     {
00385       std::vector<std::string>& v=(*it3).second;
00386       std::vector<std::string>::iterator it4=std::find(v.begin(),v.end(),oname);
00387       if(it4!=v.end())
00388         v.erase(it4);
00389     }
00390 }
00391 
00392 void MEDFileMesh::changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
00393 {
00394   std::string oname(oldName);
00395   std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
00396   std::vector<std::string> grps=getGroupsNames();
00397   if(it==_groups.end())
00398     {
00399       std::ostringstream oss; oss << "No such groupname \"" << oldName << "\" !\nAvailable groups are :";
00400       std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
00401       throw INTERP_KERNEL::Exception(oss.str().c_str());
00402     }
00403   std::string nname(newName);
00404   it=_groups.find(nname);
00405   if(it!=_groups.end())
00406     {
00407       std::ostringstream oss; oss << "Such groupname \"" << newName << "\" already exists ! Kill it before !";
00408       throw INTERP_KERNEL::Exception(oss.str().c_str());
00409     }
00410   std::vector<std::string> cpy=(*it).second;
00411   _groups.erase(it);
00412   _groups[newName]=cpy;
00413 }
00414 
00419 void MEDFileMesh::changeFamilyId(int oldId, int newId) throw(INTERP_KERNEL::Exception)
00420 {
00421   changeFamilyIdArr(oldId,newId);
00422   std::map<std::string,int> fam2;
00423   for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
00424     {
00425       if((*it).second==oldId)
00426         fam2[(*it).first]=newId;
00427       else
00428         fam2[(*it).first]=(*it).second;
00429     }
00430   _families=fam2;
00431 }
00432 
00433 void MEDFileMesh::changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
00434 {
00435   std::string oname(oldName);
00436   std::map<std::string, int >::iterator it=_families.find(oname);
00437   std::vector<std::string> fams=getFamiliesNames();
00438   if(it==_families.end())
00439     {
00440       std::ostringstream oss; oss << "No such familyname \"" << oldName << "\" !\nAvailable families are :";
00441       std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
00442       throw INTERP_KERNEL::Exception(oss.str().c_str());
00443     }
00444   std::string nname(newName);
00445   std::map<std::string, int >::iterator it2=_families.find(nname);
00446   if(it2!=_families.end())
00447     {
00448       std::ostringstream oss; oss << "Such familyname \"" << newName << " already exists ! Kill it before !";
00449       throw INTERP_KERNEL::Exception(oss.str().c_str());
00450     }
00451   int cpy=(*it).second;
00452   _families.erase(it);
00453   _families[newName]=cpy;
00454   for(std::map<std::string, std::vector<std::string> >::iterator it3=_groups.begin();it3!=_groups.end();it3++)
00455     {
00456       std::vector<std::string>& v=(*it3).second;
00457       std::vector<std::string>::iterator it4=std::find(v.begin(),v.end(),oname);
00458       if(it4!=v.end())
00459         (*it4)=nname;
00460     }
00461 }
00462 
00463 bool MEDFileMesh::areFamsEqual(const MEDFileMesh *other, std::string& what) const
00464 {
00465   if(_families==other->_families)
00466     return true;
00467   std::map<std::string,int> fam0;
00468   std::map<std::string,int> fam1;
00469   for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
00470     if((*it).second!=0)
00471       fam0[(*it).first]=(*it).second;
00472   for(std::map<std::string,int>::const_iterator it=other->_families.begin();it!=other->_families.end();it++)
00473     if((*it).second!=0)
00474       fam1[(*it).first]=(*it).second;
00475   return fam0==fam1;
00476 }
00477 
00478 bool MEDFileMesh::areGrpsEqual(const MEDFileMesh *other, std::string& what) const
00479 {
00480   if(_groups==other->_groups)
00481     return true;
00482   bool ret=true;
00483   std::size_t sz=_groups.size();
00484   if(sz!=other->_groups.size())
00485     {
00486       what="Groups differ because not same number !\n";
00487       ret=false;
00488     }
00489   if(ret)
00490     {
00491       std::map<std::string, std::vector<std::string> >::const_iterator it1=_groups.begin();
00492       for(std::size_t i=0;i<sz && ret;i++,it1++)
00493         {
00494           std::map<std::string, std::vector<std::string> >::const_iterator it2=other->_groups.find((*it1).first);
00495           if(it2!=other->_groups.end())
00496             {
00497               std::set<std::string> s1((*it1).second.begin(),(*it1).second.end());
00498               std::set<std::string> s2((*it2).second.begin(),(*it2).second.end());
00499               ret=(s1==s2);
00500             }
00501           else
00502             {
00503               ret=false;
00504               what="A group in first mesh exists not in other !\n";
00505             }
00506         }
00507     }
00508   if(!ret)
00509     {
00510       std::ostringstream oss; oss << "Groups description differs :\n";
00511       oss << "First group description :\n";
00512       for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++)
00513         {
00514           oss << " Group \"" << (*it).first << "\" on following families :\n";
00515           for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
00516         oss << "    \"" << *it2 << "\n";
00517         }
00518       oss << "Second group description :\n";
00519       for(std::map<std::string, std::vector<std::string> >::const_iterator it=other->_groups.begin();it!=other->_groups.end();it++)
00520         {
00521           oss << " Group \"" << (*it).first << "\" on following families :\n";
00522           for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
00523             oss << "    \"" << *it2 << "\n";
00524         }
00525       what+=oss.str();
00526     }
00527   return ret;
00528 }
00529 
00530 bool MEDFileMesh::existsGroup(const char *groupName) const
00531 {
00532   std::string grpName(groupName);
00533   return _groups.find(grpName)!=_groups.end();
00534 }
00535 
00536 bool MEDFileMesh::existsFamily(int famId) const
00537 {
00538   for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
00539     if((*it2).second==famId)
00540       return true;
00541   return false;
00542 }
00543 
00544 bool MEDFileMesh::existsFamily(const char *familyName) const
00545 {
00546   std::string fname(familyName);
00547   return _families.find(fname)!=_families.end();
00548 }
00549 
00550 void MEDFileMesh::setFamilyId(const char *familyName, int id)
00551 {
00552   std::string fname(familyName);
00553   _families[fname]=id;
00554 }
00555 
00560 void MEDFileMesh::addFamily(const char *familyName, int famId) throw(INTERP_KERNEL::Exception)
00561 {
00562   std::string fname(familyName);
00563   std::map<std::string,int>::const_iterator it=_families.find(fname);
00564   if(it==_families.end())
00565     {
00566        for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
00567          if((*it2).second==famId)
00568            {
00569              std::ostringstream oss;
00570              oss << "MEDFileMesh::addFamily : Family \"" << (*it2).first << "\" already exists with specified id : " << famId << " !";
00571              throw INTERP_KERNEL::Exception(oss.str().c_str());
00572            }
00573        _families[fname]=famId;
00574     }
00575   else
00576     {
00577       if((*it).second!=famId)
00578         {
00579           std::ostringstream oss;
00580           oss << "MEDFileMesh::addFamily : Family \"" << fname << "\" already exists but has id set to " << (*it).second << " different from asked famId " << famId << " !";
00581           throw INTERP_KERNEL::Exception(oss.str().c_str());
00582         }
00583     }
00584 }
00585 
00594 void MEDFileMesh::createGroupOnAll(int meshDimRelToMaxExt, const char *groupName) throw(INTERP_KERNEL::Exception)
00595 {
00596   std::string grpName(groupName);
00597   std::vector<int> levs=getNonEmptyLevelsExt();
00598   if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)==levs.end())
00599     {
00600       std::ostringstream oss; oss << "MEDFileMesh::createGroupOnAll : The relative ext dimension " << meshDimRelToMaxExt << " is not available !" << std::endl;
00601       oss << "Available relative ext levels are : ";
00602       std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," "));
00603       throw INTERP_KERNEL::Exception(oss.str().c_str());
00604     }
00605   if(existsGroup(groupName))
00606     {
00607       std::ostringstream oss; oss << "MEDFileMesh::createGroupOnAll : The groups \"" << grpName << "\" already exists in this !" << std::endl;
00608       oss << "Already existing groups are : ";
00609       std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," "));
00610       oss << std::endl << "Please choose an another group name or call removeGroup(\"" << grpName << "\") method !";
00611       throw INTERP_KERNEL::Exception(oss.str().c_str());
00612     }
00613   const DataArrayInt *fieldFamIds=getFamilyFieldAtLevel(meshDimRelToMaxExt);
00614   if(fieldFamIds==0)
00615     throw INTERP_KERNEL::Exception("MEDFileMesh::createGroupOnAll : Family field arr ids is not defined for this level !");
00616   std::set<int> famIds=fieldFamIds->getDifferentValues();
00617   std::vector<std::string> familiesOnWholeGroup;
00618   for(std::set<int>::const_iterator it=famIds.begin();it!=famIds.end();it++)
00619     {
00620       bool tmp;
00621       familiesOnWholeGroup.push_back(findOrCreateAndGiveFamilyWithId(*it,tmp));
00622     }
00623   _groups[grpName]=familiesOnWholeGroup;
00624 }
00625 
00632 bool MEDFileMesh::keepFamIdsOnlyOnLevs(const std::vector<int>& famIds, const std::vector<int>& vMeshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
00633 {
00634   std::set<int> levsInput(vMeshDimRelToMaxExt.begin(),vMeshDimRelToMaxExt.end());
00635   std::vector<int> levs=getNonEmptyLevelsExt();
00636   std::set<int> levs2(levs.begin(),levs.end());
00637   std::vector<int> levsToTest;
00638   std::set_difference(levs2.begin(),levs2.end(),levsInput.begin(),levsInput.end(),std::back_insert_iterator< std::vector<int> >(levsToTest));
00639   std::set<int> famIds2(famIds.begin(),famIds.end());
00640   bool ret=true;
00641   int maxFamId=1;
00642   if(!_families.empty())
00643     maxFamId=getMaxFamilyId()+1;
00644   std::vector<std::string> allFams=getFamiliesNames();
00645   for(std::vector<int>::const_iterator it=levsToTest.begin();it!=levsToTest.end();it++)
00646     {
00647       const DataArrayInt *fieldFamIds=getFamilyFieldAtLevel(*it);
00648       if(fieldFamIds)
00649         {
00650           std::set<int> famIds3=fieldFamIds->getDifferentValues();
00651           std::vector<int> tmp;
00652           std::set_intersection(famIds3.begin(),famIds3.end(),famIds2.begin(),famIds2.end(),std::back_insert_iterator< std::vector<int> >(tmp));
00653           for(std::vector<int>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
00654             {
00655               ret=false;
00656               std::string famName=getFamilyNameGivenId(*it2);
00657               std::ostringstream oss; oss << "Family_" << maxFamId;
00658               std::string zeName=CreateNameNotIn(oss.str(),allFams);
00659               addFamilyOnAllGroupsHaving(famName.c_str(),zeName.c_str());
00660               _families[zeName]=maxFamId;
00661               (const_cast<DataArrayInt *>(fieldFamIds))->changeValue(*it2,maxFamId);
00662               maxFamId++;
00663             }
00664         }
00665     }
00666   return ret;
00667 }
00668 
00675 void MEDFileMesh::addFamilyOnGrp(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception)
00676 {
00677   std::string grpn(grpName);
00678   std::string famn(famName);
00679   if(grpn.empty() || famn.empty())
00680     throw INTERP_KERNEL::Exception("MEDFileMesh::addFamilyOnGrp : input strings must be non null !");
00681   std::vector<std::string> fams=getFamiliesNames();
00682   if(std::find(fams.begin(),fams.end(),famn)==fams.end())
00683     {
00684       std::ostringstream oss; oss << "MEDFileMesh::addFamilyOnGrp : Family \"" << famn << "\" does not exist !" << std::endl;
00685       oss << "Create this family or choose an existing one ! Existing fams are : ";
00686       std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," ")); oss << ".";
00687       throw INTERP_KERNEL::Exception(oss.str().c_str());
00688     }
00689   std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(grpn);
00690   if(it==_groups.end())
00691     {
00692       _groups[grpn].push_back(famn);
00693     }
00694   else
00695     {
00696       std::vector<std::string>::iterator it2=std::find((*it).second.begin(),(*it).second.end(),famn);
00697       if(it2==(*it).second.end())
00698         (*it).second.push_back(famn);
00699     }
00700 }
00701 
00707 void MEDFileMesh::addFamilyOnAllGroupsHaving(const char *famName, const char *otherFamName) throw(INTERP_KERNEL::Exception)
00708 {
00709   std::string famNameCpp(famName);
00710   std::string otherCpp(otherFamName);
00711   for(std::map<std::string, std::vector<std::string> >::iterator it=_groups.begin();it!=_groups.end();it++)
00712     {
00713       std::vector<std::string>& v=(*it).second;
00714       if(std::find(v.begin(),v.end(),famNameCpp)!=v.end())
00715         {
00716           v.push_back(otherCpp);
00717         }
00718     }
00719 }
00720 
00729 std::string MEDFileMesh::findOrCreateAndGiveFamilyWithId(int id, bool& created) throw(INTERP_KERNEL::Exception)
00730 {
00731   std::vector<std::string> famAlreadyExisting(_families.size());
00732   int ii=0;
00733   for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++,ii++)
00734     {
00735       if((*it).second!=id)
00736         {
00737           famAlreadyExisting[ii]=(*it).first;
00738         }
00739       else
00740         {
00741           created=false;
00742           return (*it).first;
00743         }
00744     }
00745   created=true;
00746   std::ostringstream oss; oss << "Family_" << id;
00747   std::string ret=CreateNameNotIn(oss.str(),famAlreadyExisting);
00748   _families[ret]=id;
00749   return ret;
00750 }
00751 
00752 void MEDFileMesh::setFamilyInfo(const std::map<std::string,int>& info)
00753 {
00754   _families=info;
00755 }
00756 
00757 void MEDFileMesh::setGroupInfo(const std::map<std::string, std::vector<std::string> >&info)
00758 {
00759   _groups=info;
00760 }
00761 
00762 int MEDFileMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception)
00763 {
00764   std::string oname(name);
00765   std::map<std::string, int>::const_iterator it=_families.find(oname);
00766   std::vector<std::string> fams=getFamiliesNames();
00767   if(it==_families.end())
00768     {
00769       std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :";
00770       std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
00771       throw INTERP_KERNEL::Exception(oss.str().c_str());
00772     }
00773   return (*it).second;
00774 }
00775 
00776 std::vector<int> MEDFileMesh::getFamiliesIds(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
00777 {
00778   std::vector<int> ret(fams.size());
00779   int i=0;
00780   for(std::vector<std::string>::const_iterator it=fams.begin();it!=fams.end();it++,i++)
00781     {
00782       std::map<std::string, int>::const_iterator it2=_families.find(*it);
00783       if(it2==_families.end())
00784         {
00785           std::vector<std::string> fams2=getFamiliesNames();
00786           std::ostringstream oss; oss << "No such familyname \"" << *it << "\" in input list !\nAvailable families are :";
00787           std::copy(fams2.begin(),fams2.end(),std::ostream_iterator<std::string>(oss," "));
00788           throw INTERP_KERNEL::Exception(oss.str().c_str());
00789         }
00790       ret[i]=(*it2).second;
00791     }
00792   return ret;
00793 }
00794 
00795 int MEDFileMesh::getMaxFamilyId() const throw(INTERP_KERNEL::Exception)
00796 {
00797   if(_families.empty())
00798     throw INTERP_KERNEL::Exception("MEDFileUMesh::getMaxFamilyId : no families set !");
00799   int ret=-std::numeric_limits<int>::max();
00800   for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
00801     {
00802       ret=std::max((*it).second,ret);
00803     }
00804   return ret;
00805 }
00806 
00810 std::string MEDFileMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception)
00811 {
00812   for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
00813     if((*it).second==id)
00814       return (*it).first;
00815   std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id;
00816   throw INTERP_KERNEL::Exception(oss.str().c_str());
00817 }
00818 
00819 std::string MEDFileMesh::simpleRepr() const
00820 {
00821   std::ostringstream oss;
00822   oss << "(*************************************)\n(* GENERAL INFORMATION ON THE MESH : *)\n(*************************************)\n";
00823   oss << "- Name of the mesh : <<" << getName() << ">>\n";
00824   oss << "- Description associated to the mesh : " << getDescription() << std::endl;
00825   return oss.str();
00826 }
00827 
00828 DataArrayInt *MEDFileMesh::getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
00829 {
00830   std::vector<std::string> tmp(1);
00831   tmp[0]=grp;
00832   DataArrayInt *ret=getGroupsArr(meshDimRelToMaxExt,tmp,renum);
00833   ret->setName(grp);
00834   return ret;
00835 }
00836 
00837 DataArrayInt *MEDFileMesh::getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
00838 {
00839   std::vector<std::string> fams2=getFamiliesOnGroups(grps);
00840   return getFamiliesArr(meshDimRelToMaxExt,fams2,renum);
00841 }
00842 
00843 DataArrayInt *MEDFileMesh::getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
00844 {
00845   std::vector<std::string> tmp(1);
00846   tmp[0]=fam;
00847   DataArrayInt *ret=getFamiliesArr(meshDimRelToMaxExt,tmp,renum);
00848   ret->setName(fam);
00849   return ret;
00850 }
00851 
00852 DataArrayInt *MEDFileMesh::getNodeGroupArr(const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
00853 {
00854   std::vector<std::string> tmp(1);
00855   tmp[0]=grp;
00856   DataArrayInt *ret=getNodeGroupsArr(tmp,renum);
00857   ret->setName(grp);
00858   return ret;
00859 }
00860 
00861 DataArrayInt *MEDFileMesh::getNodeGroupsArr(const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
00862 {
00863   return getGroupsArr(1,grps,renum);
00864 }
00865 
00866 DataArrayInt *MEDFileMesh::getNodeFamilyArr(const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
00867 {
00868   std::vector<std::string> tmp(1);
00869   tmp[0]=fam;
00870   DataArrayInt *ret=getNodeFamiliesArr(tmp,renum);
00871   ret->setName(fam);
00872   return ret;
00873 }
00874 
00875 DataArrayInt *MEDFileMesh::getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
00876 {
00877   return getFamiliesArr(1,fams,renum);
00878 }
00879 
00880 void MEDFileMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum) throw(INTERP_KERNEL::Exception)
00881 {
00882   if(grps.empty())
00883     return ;
00884   std::set<std::string> grpsName;
00885   std::vector<std::string> grpsName2(grps.size());
00886   int i=0;
00887 
00888   for(std::vector<const DataArrayInt *>::const_iterator it=grps.begin();it!=grps.end();it++,i++)
00889     {
00890       grpsName.insert((*it)->getName());
00891       grpsName2[i]=(*it)->getName();
00892     }
00893   if(grpsName.size()!=grps.size())
00894     throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different each other !");
00895   if(grpsName.find(std::string(""))!=grpsName.end())
00896     throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different empty string !");
00897   int sz=getSizeAtLevel(meshDimRelToMaxExt);
00898   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam;
00899   std::vector< std::vector<int> > fidsOfGroups;
00900   if(!renum)
00901     {
00902       fam=DataArrayInt::MakePartition(grps,sz,fidsOfGroups);
00903     }
00904   else
00905     {
00906       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > grps2(grps.size());
00907       for(unsigned int ii=0;ii<grps.size();ii++)
00908         {
00909           grps2[ii]=MEDFileUMeshSplitL1::Renumber(getRevNumberFieldAtLevel(meshDimRelToMaxExt),grps[ii]);
00910           grps2[ii]->setName(grps[ii]->getName().c_str());
00911         }
00912       std::vector<const DataArrayInt *> grps3(grps2.begin(),grps2.end());
00913       fam=DataArrayInt::MakePartition(grps3,sz,fidsOfGroups);
00914     }
00915   int offset=1;
00916   if(!_families.empty())
00917     offset=getMaxFamilyId()+1;
00918   TranslateFamilyIds(offset,fam,fidsOfGroups);
00919   std::set<int> ids=fam->getDifferentValues();
00920   appendFamilyEntries(ids,fidsOfGroups,grpsName2);
00921   setFamilyFieldArr(meshDimRelToMaxExt,fam);
00922 }
00923 
00929 void MEDFileMesh::appendFamilyEntries(const std::set<int>& famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames)
00930 {
00931   std::map<int,std::string> famInv;
00932   for(std::set<int>::const_iterator it=famIds.begin();it!=famIds.end();it++)
00933     {
00934       std::ostringstream oss;
00935       oss << "Family_" << (*it);
00936       _families[oss.str()]=(*it);
00937       famInv[*it]=oss.str();
00938     }
00939   int i=0;
00940   for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGrps.begin();it1!=fidsOfGrps.end();it1++,i++)
00941     {
00942       for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
00943         {
00944           _groups[grpNames[i]].push_back(famInv[*it2]);
00945         }
00946     }
00947 }
00948 
00949 void MEDFileMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp)
00950 {
00951   famArr->applyLin(1,offset,0);
00952   for(std::vector< std::vector<int> >::iterator it1=famIdsPerGrp.begin();it1!=famIdsPerGrp.end();it1++)
00953     std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus<int>(),offset));
00954 }
00955 
00961 std::string MEDFileMesh::CreateNameNotIn(const std::string& nameTry, const std::vector<std::string>& namesToAvoid) throw(INTERP_KERNEL::Exception)
00962 {
00963   //attempt #0
00964   if(std::find(namesToAvoid.begin(),namesToAvoid.end(),nameTry)==namesToAvoid.end())
00965     return nameTry;
00966   //attempt #1
00967   std::size_t len=nameTry.length();
00968   for(std::size_t ii=1;ii<len;ii++)
00969     {
00970       std::string tmp=nameTry.substr(ii,len-ii);
00971       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp)==namesToAvoid.end())
00972         return tmp;
00973     }
00974   //attempt #2
00975   if(len>=1)
00976     {
00977       for(std::size_t i=1;i<30;i++)
00978         {
00979           std::string tmp1(nameTry.at(0),i);
00980           tmp1+=nameTry;
00981           if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp1)==namesToAvoid.end())
00982             return tmp1;
00983         }
00984     }
00985   //attempt #3
00986   std::string tmp2;
00987   for(std::vector<std::string>::const_iterator it2=namesToAvoid.begin();it2!=namesToAvoid.end();it2++)
00988     tmp2+=(*it2);
00989   if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp2)==namesToAvoid.end())
00990     return tmp2;
00991   throw INTERP_KERNEL::Exception("MEDFileMesh::CreateNameNotIn : impossible to find a not already used name !");
00992 }
00993 
01000 void MEDFileMesh::dealWithTinyInfo(const MEDCouplingMesh *m) throw(INTERP_KERNEL::Exception)
01001 {
01002   if(_name.empty())
01003     _name=m->getName();
01004   else
01005     {
01006       std::string name(m->getName());
01007       if(!name.empty())
01008         {
01009           if(_name!=name)
01010             {
01011               std::ostringstream oss; oss << "MEDFileMesh::dealWithTinyInfo : name of current MEDfile mesh is '" << _name << "' whereas name of input mesh is : '";
01012               oss << name << "' ! Names must match !";
01013               throw INTERP_KERNEL::Exception(oss.str().c_str());
01014             }
01015         }
01016     }
01017 }
01018 
01019 void MEDFileMesh::getFamilyRepr(std::ostream& oss) const
01020 {
01021   oss << "(**************************)\n(* FAMILIES OF THE MESH : *)\n(**************************)\n";
01022   for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
01023     {
01024       oss << "- Family with name \"" << (*it).first << "\" with number " << (*it).second << std::endl;
01025       oss << "  - Groups lying on this family : ";
01026       std::vector<std::string> grps=getGroupsOnFamily((*it).first.c_str());
01027       std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
01028       oss << std::endl << std::endl;
01029     }
01030 }
01031 
01032 MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
01033 {
01034   MEDFileUtilities::CheckFileForRead(fileName);
01035   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
01036   return new MEDFileUMesh(fid,mName,dt,it);
01037 }
01038 
01039 MEDFileUMesh *MEDFileUMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
01040 {
01041   std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
01042   if(ms.empty())
01043     {
01044       std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
01045       throw INTERP_KERNEL::Exception(oss.str().c_str());
01046     }
01047   MEDFileUtilities::CheckFileForRead(fileName);
01048   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
01049   int dt,it;
01050   ParaMEDMEM::MEDCouplingMeshType meshType;
01051   std::string dummy2;
01052   MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
01053   return new MEDFileUMesh(fid,ms.front().c_str(),dt,it);
01054 }
01055 
01056 MEDFileUMesh *MEDFileUMesh::New()
01057 {
01058   return new MEDFileUMesh;
01059 }
01060 
01061 bool MEDFileUMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
01062 {
01063   if(!MEDFileMesh::isEqual(other,eps,what))
01064     return false;
01065   const MEDFileUMesh *otherC=dynamic_cast<const MEDFileUMesh *>(other);
01066   if(!otherC)
01067     {
01068       what="Mesh types differ ! This is unstructured and other is NOT !";
01069       return false;
01070     }
01071   clearNonDiscrAttributes();
01072   otherC->clearNonDiscrAttributes();
01073   const DataArrayDouble *coo1=_coords;
01074   const DataArrayDouble *coo2=otherC->_coords;
01075   if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
01076     {
01077       what="Mismatch of coordinates ! One is defined and not other !";
01078       return false;
01079     }
01080   if(coo1)
01081     {
01082       bool ret=coo1->isEqual(*coo2,eps);
01083       if(!ret)
01084         {
01085           what="Coords differ !";
01086           return false;
01087         }
01088     }
01089   const DataArrayInt *famc1=_fam_coords;
01090   const DataArrayInt *famc2=otherC->_fam_coords;
01091   if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
01092     {
01093       what="Mismatch of families arr on nodes ! One is defined and not other !";
01094       return false;
01095     }
01096   if(famc1)
01097     {
01098       bool ret=famc1->isEqual(*famc2);
01099       if(!ret)
01100         {
01101           what="Families arr on node differ !";
01102           return false;
01103         }
01104     }
01105   const DataArrayInt *numc1=_num_coords;
01106   const DataArrayInt *numc2=otherC->_num_coords;
01107   if((numc1==0 && numc2!=0) || (numc1!=0 && numc2==0))
01108     {
01109       what="Mismatch of numbering arr on nodes ! One is defined and not other !";
01110       return false;
01111     }
01112   if(numc1)
01113     {
01114       bool ret=numc1->isEqual(*numc2);
01115       if(!ret)
01116         {
01117           what="Numbering arr on node differ !";
01118           return false;
01119         }
01120     }
01121   if(_ms.size()!=otherC->_ms.size())
01122     {
01123       what="Number of levels differs !";
01124       return false;
01125     }
01126   std::size_t sz=_ms.size();
01127   for(std::size_t i=0;i<sz;i++)
01128     {
01129       const MEDFileUMeshSplitL1 *s1=_ms[i];
01130       const MEDFileUMeshSplitL1 *s2=otherC->_ms[i];
01131       if((s1==0 && s2!=0) || (s1!=0 && s2==0))
01132         {
01133           what="Mismatch of presence of sub levels !";
01134           return false;
01135         }
01136       if(s1)
01137         {
01138           bool ret=s1->isEqual(s2,eps,what);
01139           if(!ret)
01140             return false;
01141         }
01142     }
01143   //std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> > _ms;
01144   return true;
01145 }
01146 
01147 void MEDFileUMesh::clearNonDiscrAttributes() const
01148 {
01149   MEDFileMesh::clearNonDiscrAttributes();
01150   const DataArrayDouble *coo1=_coords;
01151   if(coo1)
01152     (const_cast<DataArrayDouble *>(coo1))->setName("");//This parameter is not discriminant for comparison
01153   const DataArrayInt *famc1=_fam_coords;
01154   if(famc1)
01155     (const_cast<DataArrayInt *>(famc1))->setName("");//This parameter is not discriminant for comparison
01156   const DataArrayInt *numc1=_num_coords;
01157   if(numc1)
01158     (const_cast<DataArrayInt *>(numc1))->setName("");//This parameter is not discriminant for comparison
01159   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
01160     {
01161       const MEDFileUMeshSplitL1 *tmp=(*it);
01162       if(tmp)
01163         tmp->clearNonDiscrAttributes();
01164     }
01165 }
01166 
01167 MEDFileUMesh::MEDFileUMesh()
01168 {
01169 }
01170 
01171 MEDFileUMesh::MEDFileUMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
01172 try
01173   {
01174     loadUMeshFromFile(fid,mName,dt,it);
01175   }
01176 catch(INTERP_KERNEL::Exception& e)
01177   {
01178     throw e;
01179   }
01180 
01181 void MEDFileUMesh::loadUMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
01182 {
01183   MEDFileUMeshL2 loaderl2;
01184   ParaMEDMEM::MEDCouplingMeshType meshType;
01185   int dummy0,dummy1;
01186   std::string dummy2;
01187   int mid=MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
01188   if(meshType!=UNSTRUCTURED)
01189     {
01190       std::ostringstream oss; oss << "Trying to load as unstructured an existing mesh with name '" << mName << "' !";
01191       throw INTERP_KERNEL::Exception(oss.str().c_str());
01192     }
01193   loaderl2.loadAll(fid,mid,mName,dt,it);
01194   int lev=loaderl2.getNumberOfLevels();
01195   _ms.resize(lev);
01196   for(int i=0;i<lev;i++)
01197     {
01198       if(!loaderl2.emptyLev(i))
01199         _ms[i]=new MEDFileUMeshSplitL1(loaderl2,mName,i);
01200       else
01201         _ms[i]=0;
01202     }
01203   MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups);
01204   //
01205   setName(loaderl2.getName());
01206   setDescription(loaderl2.getDescription());
01207   setIteration(loaderl2.getIteration());
01208   setOrder(loaderl2.getOrder());
01209   setTimeValue(loaderl2.getTime());
01210   setTimeUnit(loaderl2.getTimeUnit());
01211   _coords=loaderl2.getCoords();
01212   _fam_coords=loaderl2.getCoordsFamily();
01213   _num_coords=loaderl2.getCoordsNum();
01214   computeRevNum();
01215 }
01216 
01217 MEDFileUMesh::~MEDFileUMesh()
01218 {
01219 }
01220 
01221 void MEDFileUMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
01222 {
01223   const DataArrayDouble *coo=_coords;
01224   INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
01225   INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
01226   MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
01227   MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
01228   int spaceDim=coo?coo->getNumberOfComponents():0;
01229   int mdim=getMeshDimension();
01230   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
01231   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
01232   for(int i=0;i<spaceDim;i++)
01233     {
01234       std::string info=coo->getInfoOnComponent(i);
01235       std::string c,u;
01236       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
01237       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
01238       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
01239     }
01240   MEDmeshCr(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
01241   MEDFileUMeshL2::WriteCoords(fid,maa,_iteration,_order,_time,_coords,_fam_coords,_num_coords);
01242   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
01243     if((const MEDFileUMeshSplitL1 *)(*it)!=0)
01244       (*it)->write(fid,maa,mdim);
01245   MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str);
01246 }
01247 
01248 std::vector<int> MEDFileUMesh::getNonEmptyLevels() const
01249 {
01250   std::vector<int> ret;
01251   int lev=0;
01252   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--)
01253     if((const MEDFileUMeshSplitL1 *)(*it)!=0)
01254       if(!(*it)->empty())
01255         ret.push_back(lev);
01256   return ret;
01257 }
01258 
01259 std::vector<int> MEDFileUMesh::getNonEmptyLevelsExt() const
01260 {
01261   std::vector<int> ret0=getNonEmptyLevels();
01262   if((const DataArrayDouble *) _coords)
01263     {
01264       std::vector<int> ret(ret0.size()+1);
01265       ret[0]=1;
01266       std::copy(ret0.begin(),ret0.end(),ret.begin()+1);
01267       return ret;
01268     }
01269   return ret0;
01270 }
01271 
01276 std::vector<int> MEDFileUMesh::getGrpNonEmptyLevels(const char *grp) const throw(INTERP_KERNEL::Exception)
01277 {
01278   std::vector<std::string> fams=getFamiliesOnGroup(grp);
01279   return getFamsNonEmptyLevels(fams);
01280 }
01281 
01285 std::vector<int> MEDFileUMesh::getGrpNonEmptyLevelsExt(const char *grp) const throw(INTERP_KERNEL::Exception)
01286 {
01287   std::vector<std::string> fams=getFamiliesOnGroup(grp);
01288   return getFamsNonEmptyLevelsExt(fams);
01289 }
01290 
01295 std::vector<int> MEDFileUMesh::getFamNonEmptyLevels(const char *fam) const throw(INTERP_KERNEL::Exception)
01296 {
01297   std::vector<std::string> fams(1,std::string(fam));
01298   return getFamsNonEmptyLevels(fams);
01299 }
01300 
01304 std::vector<int> MEDFileUMesh::getFamNonEmptyLevelsExt(const char *fam) const throw(INTERP_KERNEL::Exception)
01305 {
01306   std::vector<std::string> fams(1,std::string(fam));
01307   return getFamsNonEmptyLevelsExt(fams);
01308 }
01309 
01314 std::vector<int> MEDFileUMesh::getGrpsNonEmptyLevels(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception)
01315 {
01316   std::vector<std::string> fams=getFamiliesOnGroups(grps);
01317   return getFamsNonEmptyLevels(fams);
01318 }
01319 
01323 std::vector<int> MEDFileUMesh::getGrpsNonEmptyLevelsExt(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception)
01324 {
01325   std::vector<std::string> fams=getFamiliesOnGroups(grps);
01326   return getFamsNonEmptyLevelsExt(fams);
01327 }
01328 
01333 std::vector<int> MEDFileUMesh::getFamsNonEmptyLevels(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
01334 {
01335   std::vector<int> ret;
01336   std::vector<int> levs=getNonEmptyLevels();
01337   std::vector<int> famIds=getFamiliesIds(fams);
01338   for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
01339     if(_ms[-(*it)]->presenceOfOneFams(famIds))
01340       ret.push_back(*it);
01341   return ret;
01342 }
01343 
01347 std::vector<int> MEDFileUMesh::getFamsNonEmptyLevelsExt(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
01348 {
01349   std::vector<int> ret0=getFamsNonEmptyLevels(fams);
01350   const DataArrayInt *famCoords=_fam_coords;
01351   if(!famCoords)
01352     return ret0;
01353   std::vector<int> famIds=getFamiliesIds(fams);
01354   if(famCoords->presenceOfValue(famIds))
01355     {
01356       std::vector<int> ret(ret0.size()+1);
01357       ret[0]=1;
01358       std::copy(ret0.begin(),ret0.end(),ret.begin()+1);
01359       return ret;
01360     }
01361   else
01362     return ret0;
01363 }
01364 
01368 std::vector<std::string> MEDFileUMesh::getGroupsOnSpecifiedLev(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
01369 {
01370   std::vector<std::string> ret;
01371   std::vector<std::string> allGrps=getGroupsNames();
01372   for(std::vector<std::string>::const_iterator it=allGrps.begin();it!=allGrps.end();it++)
01373     {
01374       std::vector<int> levs=getGrpNonEmptyLevelsExt((*it).c_str());
01375       if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)!=levs.end())
01376         ret.push_back(*it);
01377     }
01378   return ret;
01379 }
01380 
01381 int MEDFileUMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception)
01382 {
01383   int lev=0;
01384   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev++)
01385     if((const MEDFileUMeshSplitL1 *)(*it)!=0)
01386       return (*it)->getMeshDimension()+lev;
01387   throw INTERP_KERNEL::Exception("MEDFileUMesh::getMeshDimension : impossible to find a mesh dimension !");
01388 }
01389 
01390 int MEDFileUMesh::getSpaceDimension() const throw(INTERP_KERNEL::Exception)
01391 {
01392   const DataArrayDouble *coo=_coords;
01393   if(!coo)
01394     throw INTERP_KERNEL::Exception(" MEDFileUMesh::getSpaceDimension : no coords set !");
01395   return coo->getNumberOfComponents();
01396 }
01397 
01398 std::string MEDFileUMesh::simpleRepr() const
01399 {
01400   std::ostringstream oss;
01401   oss << MEDFileMesh::simpleRepr();
01402   const DataArrayDouble *coo=_coords;
01403   oss << "- The dimension of the space is ";
01404   static const char MSG1[]= "*** NO COORDS SET ***";
01405   static const char MSG2[]= "*** NO CONNECTIVITY SET FOR THIS LEVEL***";
01406   if(coo)
01407     oss << _coords->getNumberOfComponents() << std::endl;
01408   else
01409     oss << MSG1 << std::endl;
01410   oss << "- Type of the mesh : UNSTRUCTURED\n";
01411   oss << "- Number of nodes : ";
01412   if(coo)
01413     oss << _coords->getNumberOfTuples() << std::endl;
01414   else
01415     oss << MSG1 << std::endl;
01416   std::size_t nbOfLev=_ms.size();
01417   oss << "- Number of levels allocated : " << nbOfLev << std::endl;
01418   for(std::size_t i=0;i<nbOfLev;i++)
01419     {
01420       const MEDFileUMeshSplitL1 *lev=_ms[i];
01421       oss << "  - Level #" << -((int) i) << " has dimension : ";
01422       if(lev)
01423         {
01424           oss << lev->getMeshDimension() << std::endl;
01425           lev->simpleRepr(oss);
01426         }
01427       else
01428         oss << MSG2 << std::endl;
01429     }
01430   oss << "- Number of families : " << _families.size() << std::endl << std::endl;
01431   if(coo)
01432     {
01433       oss << "(***********************)\n(* NODES OF THE MESH : *)\n(***********************)\n";
01434       oss << "- Names of coordinates :" << std::endl;
01435       std::vector<std::string> vars=coo->getVarsOnComponent();
01436       std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
01437       oss << std::endl << "- Units of coordinates : " << std::endl;
01438       std::vector<std::string> units=coo->getUnitsOnComponent();
01439       std::copy(units.begin(),units.end(),std::ostream_iterator<std::string>(oss," "));
01440     }
01441   oss << std::endl << std::endl;
01442   getFamilyRepr(oss);
01443   return oss.str();
01444 }
01445 
01446 std::string MEDFileUMesh::advancedRepr() const
01447 {
01448   return simpleRepr();
01449 }
01450 
01451 int MEDFileUMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
01452 {
01453   if(meshDimRelToMaxExt==1)
01454     {
01455       if(!((const DataArrayDouble *)_coords))
01456         throw INTERP_KERNEL::Exception("MEDFileUMesh::getSizeAtLevel : no coordinates specified !");
01457       return _coords->getNumberOfTuples();
01458     }
01459   return getMeshAtLevSafe(meshDimRelToMaxExt)->getSize();
01460 }
01461 
01462 const DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
01463 {
01464   if(meshDimRelToMaxExt==1)
01465     {
01466       if(!((const DataArrayInt *)_fam_coords))
01467         throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamilyFieldAtLevel : no coordinates specified !");
01468       return _fam_coords;
01469     }
01470   const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
01471   return l1->getFamilyField();
01472 }
01473 
01474 const DataArrayInt *MEDFileUMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
01475 {
01476   if(meshDimRelToMaxExt==1)
01477     return _num_coords;
01478   const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
01479   return l1->getNumberField();
01480 }
01481 
01482 const DataArrayInt *MEDFileUMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
01483 {
01484   if(meshDimRelToMaxExt==1)
01485     {
01486       if(!((const DataArrayInt *)_num_coords))
01487         throw INTERP_KERNEL::Exception("MEDFileUMesh::getRevNumberFieldAtLevel : no coordinates renum specified !");
01488       return _rev_num_coords;
01489     }
01490   const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
01491   return l1->getRevNumberField();
01492 }
01493 
01497 DataArrayDouble *MEDFileUMesh::getCoords() const
01498 {
01499   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(_coords);
01500   if((DataArrayDouble *)tmp)
01501     {
01502       return tmp;
01503     }
01504   return 0;
01505 }
01506 
01507 MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
01508 {
01509   synchronizeTinyInfoOnLeaves();
01510   std::vector<std::string> tmp(1);
01511   tmp[0]=grp;
01512   MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum);
01513   ret->setName(grp);
01514   return ret;
01515 }
01516 
01517 MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
01518 {
01519   synchronizeTinyInfoOnLeaves();
01520   std::vector<std::string> fams2=getFamiliesOnGroups(grps);
01521   return getFamilies(meshDimRelToMaxExt,fams2,renum);
01522 }
01523 
01524 MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
01525 {
01526   synchronizeTinyInfoOnLeaves();
01527   std::vector<std::string> tmp(1);
01528   tmp[0]=fam;
01529   MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum);
01530   ret->setName(fam);
01531   return ret;
01532 }
01533 
01534 MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
01535 {
01536   synchronizeTinyInfoOnLeaves();
01537   if(meshDimRelToMaxExt==1)
01538     {
01539       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=getFamiliesArr(1,fams,renum);
01540       MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New();
01541       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> c=_coords->selectByTupleId(arr->getConstPointer(),arr->getConstPointer()+arr->getNbOfElems());
01542       ret->setCoords(c);
01543       ret->incrRef();
01544       return ret;
01545     }
01546   std::vector<int> famIds=getFamiliesIds(fams);
01547   const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
01548   return l1->getFamilyPart(famIds,renum);
01549 }
01550 
01551 DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
01552 {
01553   std::vector<int> famIds=getFamiliesIds(fams);
01554   if(meshDimRelToMaxExt==1)
01555     {
01556       if((const DataArrayInt *)_fam_coords)
01557         {
01558           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam_coords->getIdsEqualList(famIds);
01559           if(renum)
01560             return MEDFileUMeshSplitL1::Renumber(_num_coords,da);
01561           else
01562             {
01563               da->incrRef();
01564               return da;
01565             }
01566         }
01567       else
01568         throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamiliesArr : no family array specified on nodes !");
01569     }
01570   const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
01571   return l1->getFamilyPartArr(famIds,renum);
01572 }
01573 
01574 MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const throw(INTERP_KERNEL::Exception)
01575 {
01576   synchronizeTinyInfoOnLeaves();
01577   if(meshDimRelToMaxExt==1)
01578     {
01579       if(!renum)
01580         {
01581           MEDCouplingUMesh *umesh=MEDCouplingUMesh::New();
01582           MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> cc=_coords->deepCpy();
01583           umesh->setCoords(cc);
01584           MEDFileUMeshSplitL1::ClearNonDiscrAttributes(umesh);
01585           umesh->setName(getName());
01586           return umesh;
01587         }
01588     }
01589   const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
01590   return l1->getWholeMesh(renum);
01591 }
01592 
01593 MEDCouplingMesh *MEDFileUMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const throw(INTERP_KERNEL::Exception)
01594 {
01595   return getMeshAtLevel(meshDimRelToMax,renum);
01596 }
01597 
01598 MEDCouplingUMesh *MEDFileUMesh::getLevel0Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
01599 {
01600   return getMeshAtLevel(0,renum);
01601 }
01602 
01603 MEDCouplingUMesh *MEDFileUMesh::getLevelM1Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
01604 {
01605   return getMeshAtLevel(-1,renum);
01606 }
01607 
01608 MEDCouplingUMesh *MEDFileUMesh::getLevelM2Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
01609 {
01610   return getMeshAtLevel(-2,renum);
01611 }
01612 
01613 MEDCouplingUMesh *MEDFileUMesh::getLevelM3Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
01614 {
01615   return getMeshAtLevel(-3,renum);
01616 }
01617 
01618 const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
01619 {
01620   if(meshDimRelToMaxExt==1)
01621     throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !");
01622   if(meshDimRelToMaxExt>1)
01623     throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !");
01624   int tracucedRk=-meshDimRelToMaxExt;
01625   if(tracucedRk>=(int)_ms.size())
01626     throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
01627   if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0)
01628     throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
01629   return _ms[tracucedRk];
01630 }
01631 
01632 MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
01633 {
01634    if(meshDimRelToMaxExt==1)
01635     throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !");
01636   if(meshDimRelToMaxExt>1)
01637     throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !");
01638   int tracucedRk=-meshDimRelToMaxExt;
01639   if(tracucedRk>=(int)_ms.size())
01640     throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
01641   if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0)
01642     throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
01643   return _ms[tracucedRk];
01644 }
01645 
01646 void MEDFileUMesh::checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception)
01647 {
01648   if(-meshDimRelToMax>=(int)_ms.size())
01649     throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : The meshdim of mesh is not managed by 'this' !");
01650   int i=0;
01651   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++)
01652     {
01653       if(((const MEDFileUMeshSplitL1*) (*it))!=0)
01654         {
01655           int ref=(*it)->getMeshDimension();
01656           if(ref+i!=meshDim-meshDimRelToMax)
01657             throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : no coherency between levels !");
01658         }
01659     }
01660 }
01661 
01662 void MEDFileUMesh::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception)
01663 {
01664   coords->checkAllocated();
01665   int nbOfTuples=coords->getNumberOfTuples();
01666   _coords=coords;
01667   coords->incrRef();
01668   _fam_coords=DataArrayInt::New();
01669   _fam_coords->alloc(nbOfTuples,1);
01670   _fam_coords->fillWithZero();
01671 }
01672 
01673 void MEDFileUMesh::eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
01674 {
01675   if(meshDimRelToMaxExt==1)
01676     {
01677       if((DataArrayInt *)_fam_coords)
01678         _fam_coords->fillWithZero();
01679       return ;
01680     }
01681   MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
01682   l1->eraseFamilyField();
01683   optimizeFamilies();
01684 }
01685 
01686 void MEDFileUMesh::optimizeFamilies() throw(INTERP_KERNEL::Exception)
01687 {
01688   std::vector<int> levs=getNonEmptyLevelsExt();
01689   std::set<int> allFamsIds;
01690   for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
01691     {
01692       const DataArrayInt *ffield=getFamilyFieldAtLevel(*it);
01693       std::set<int> ids=ffield->getDifferentValues();
01694       std::set<int> res;
01695       std::set_union(ids.begin(),ids.end(),allFamsIds.begin(),allFamsIds.end(),std::inserter(res,res.begin()));
01696       allFamsIds=res;
01697     }
01698   std::set<std::string> famNamesToKill;
01699   for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
01700     {
01701       if(allFamsIds.find((*it).second)!=allFamsIds.end())
01702         famNamesToKill.insert((*it).first);
01703     }
01704   for(std::set<std::string>::const_iterator it=famNamesToKill.begin();it!=famNamesToKill.end();it++)
01705     _families.erase(*it);
01706   std::vector<std::string> grpNamesToKill;
01707   for(std::map<std::string, std::vector<std::string> >::iterator it=_groups.begin();it!=_groups.end();it++)
01708     {
01709       std::vector<std::string> tmp;
01710       for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
01711         {
01712           if(famNamesToKill.find(*it2)==famNamesToKill.end())
01713             tmp.push_back(*it2);
01714         }
01715       if(!tmp.empty())
01716         (*it).second=tmp;
01717       else
01718         tmp.push_back((*it).first);
01719     }
01720   for(std::vector<std::string>::const_iterator it=grpNamesToKill.begin();it!=grpNamesToKill.end();it++)
01721     _groups.erase(*it);
01722 }
01723 
01724 void MEDFileUMesh::addNodeGroup(const std::string& name, const std::vector<int>& ids) throw(INTERP_KERNEL::Exception)
01725 {
01726   const DataArrayDouble *coords=_coords;
01727   if(!coords)
01728     throw INTERP_KERNEL::Exception("addNodeGroup : no coords set !");
01729   DataArrayInt *sub=_fam_coords->selectByTupleIdSafe(&ids[0],&ids[0]+ids.size());
01730   std::set<int> ssub(sub->getConstPointer(),sub->getConstPointer()+sub->getNumberOfTuples());
01731   
01732 }
01733 
01734 void MEDFileUMesh::setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception)
01735 {
01736   std::string oldName=getFamilyNameGivenId(id);
01737   _families.erase(oldName);
01738   _families[newFamName]=id;
01739 }
01740 
01741 void MEDFileUMesh::removeMeshAtLevel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
01742 {
01743   std::vector<int> levSet=getNonEmptyLevels();
01744   std::vector<int>::const_iterator it=std::find(levSet.begin(),levSet.end(),meshDimRelToMax);
01745   if(it==levSet.end())
01746     throw INTERP_KERNEL::Exception("MEDFileUMesh::removeMeshAtLevel : the requested level is not existing !");
01747   int pos=(-meshDimRelToMax);
01748   _ms[pos]=0;
01749 }
01750 
01751 void MEDFileUMesh::setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception)
01752 {
01753   setMeshAtLevelGen(meshDimRelToMax,m,newOrOld);
01754 }
01755 
01756 void MEDFileUMesh::setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception)
01757 {
01758   dealWithTinyInfo(m);
01759   std::vector<int> levSet=getNonEmptyLevels();
01760   if(std::find(levSet.begin(),levSet.end(),meshDimRelToMax)==levSet.end())
01761     {
01762       if((DataArrayDouble *)_coords==0)
01763         {
01764           DataArrayDouble *c=m->getCoords();
01765           if(c)
01766             c->incrRef();
01767           _coords=c;
01768         }
01769       if(m->getCoords()!=_coords)
01770         throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshAtLevel : Invalid Given Mesh ! The coordinates are not the same ! try to use tryToShareSameCoords !");
01771       int sz=(-meshDimRelToMax)+1;
01772       if(sz>=(int)_ms.size())
01773         _ms.resize(sz);
01774       checkMeshDimCoherency(m->getMeshDimension(),meshDimRelToMax);
01775       _ms[sz-1]=new MEDFileUMeshSplitL1(m,newOrOld);
01776     }
01777   else
01778     _ms[-meshDimRelToMax]=new MEDFileUMeshSplitL1(m,newOrOld);
01779 }
01780 
01781 void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception)
01782 {
01783   if(ms.empty())
01784     throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : expecting a non empty vector !");
01785   int sz=(-meshDimRelToMax)+1;
01786   if(sz>=(int)_ms.size())
01787     _ms.resize(sz);
01788   checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax);
01789   DataArrayDouble *coo=checkMultiMesh(ms);
01790   if((DataArrayDouble *)_coords==0)
01791     {
01792       coo->incrRef();
01793       _coords=coo;
01794     }
01795   else
01796     if((DataArrayDouble *)_coords!=coo)
01797       throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : coordinates mismatches !");
01798   std::vector<DataArrayInt *> corr;
01799   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,_zipconn_pol,corr);
01800   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corr3(corr.begin(),corr.end());
01801   setMeshAtLevel(meshDimRelToMax,m);
01802   std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
01803   setGroupsAtLevel(meshDimRelToMax,corr2,true);
01804 }
01805 
01806 void MEDFileUMesh::setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum) throw(INTERP_KERNEL::Exception)
01807 {
01808   if(ms.empty())
01809     throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : expecting a non empty vector !");
01810   int sz=(-meshDimRelToMax)+1;
01811   if(sz>=(int)_ms.size())
01812     _ms.resize(sz);
01813   checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax);
01814   DataArrayDouble *coo=checkMultiMesh(ms);
01815   if((DataArrayDouble *)_coords==0)
01816     {
01817       coo->incrRef();
01818       _coords=coo;
01819     }
01820   else
01821     if((DataArrayDouble *)_coords!=coo)
01822       throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : coordinates mismatches !");
01823   MEDCouplingUMesh *m=getMeshAtLevel(meshDimRelToMax,renum);
01824   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corr(ms.size());
01825   int i=0;
01826   for(std::vector<const MEDCouplingUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++,i++)
01827     {
01828       DataArrayInt *arr=0;
01829       bool test=m->areCellsIncludedIn(*it,_zipconn_pol,arr);
01830       corr[i]=arr;
01831       if(!test)
01832         {
01833           std::ostringstream oss; oss << "MEDFileUMesh::setGroupsOnSetMesh : mesh #" << i << " is not part of whole mesh !";
01834           throw INTERP_KERNEL::Exception(oss.str().c_str());
01835         }
01836     }
01837   std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
01838   setGroupsAtLevel(meshDimRelToMax,corr2,renum);
01839 }
01840 
01841 DataArrayDouble *MEDFileUMesh::checkMultiMesh(const std::vector<const MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception)
01842 {
01843   const DataArrayDouble *ret=ms[0]->getCoords();
01844   int mdim=ms[0]->getMeshDimension();
01845   for(unsigned int i=1;i<ms.size();i++)
01846     {
01847       ms[i]->checkCoherency();
01848       if(ms[i]->getCoords()!=ret)
01849         throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes must share the same coords !");
01850       if(ms[i]->getMeshDimension()!=mdim)
01851         throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes have not same mesh dimension !");
01852     }
01853   return const_cast<DataArrayDouble *>(ret);
01854 }
01855 
01856 void MEDFileUMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception)
01857 {
01858   if(meshDimRelToMaxExt==1)
01859     {
01860       famArr->incrRef();
01861       _fam_coords=famArr;
01862       return ;
01863     }
01864   if(meshDimRelToMaxExt>1)
01865     throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyFieldArr : Dimension request is invalid (>1) !");
01866   int traducedRk=-meshDimRelToMaxExt;
01867   if(traducedRk>=(int)_ms.size())
01868     throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
01869   if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
01870     throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
01871   return _ms[traducedRk]->setFamilyArr(famArr);
01872 }
01873 
01874 void MEDFileUMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception)
01875 {
01876   if(meshDimRelToMaxExt==1)
01877     {
01878       if(renumArr)
01879         renumArr->incrRef();
01880       _num_coords=renumArr;
01881       computeRevNum();
01882       return ;
01883     }
01884   if(meshDimRelToMaxExt>1)
01885     throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumArr : Dimension request is invalid (>1) !");
01886   int traducedRk=-meshDimRelToMaxExt;
01887   if(traducedRk>=(int)_ms.size())
01888     throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
01889   if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
01890     throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
01891   return _ms[traducedRk]->setRenumArr(renumArr);
01892 }
01893 
01894 void MEDFileUMesh::synchronizeTinyInfoOnLeaves() const
01895 {
01896   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
01897     if((const MEDFileUMeshSplitL1 *)(*it))
01898       (*it)->synchronizeTinyInfo(*this);
01899 }
01900 
01904 void MEDFileUMesh::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception)
01905 {
01906   DataArrayInt *arr=_fam_coords;
01907   if(arr)
01908     arr->changeValue(oldId,newId);
01909   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();it!=_ms.end();it++)
01910     {
01911       MEDFileUMeshSplitL1 *sp=(*it);
01912       if(sp)
01913         {
01914           sp->changeFamilyIdArr(oldId,newId);
01915         }
01916     }
01917 }
01918 
01919 void MEDFileUMesh::computeRevNum() const
01920 {
01921   if((const DataArrayInt *)_num_coords)
01922     {
01923       int pos;
01924       int maxValue=_num_coords->getMaxValue(pos);
01925       _rev_num_coords=_num_coords->invertArrayN2O2O2N(maxValue+1);
01926     }
01927 }
01928 
01929 MEDFileCMesh *MEDFileCMesh::New()
01930 {
01931   return new MEDFileCMesh;
01932 }
01933 
01934 MEDFileCMesh *MEDFileCMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
01935 {
01936   std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
01937   if(ms.empty())
01938     {
01939       std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
01940       throw INTERP_KERNEL::Exception(oss.str().c_str());
01941     }
01942   MEDFileUtilities::CheckFileForRead(fileName);
01943   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
01944   int dt,it;
01945   ParaMEDMEM::MEDCouplingMeshType meshType;
01946   std::string dummy2;
01947   MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
01948   return new MEDFileCMesh(fid,ms.front().c_str(),dt,it);
01949 }
01950 
01951 MEDFileCMesh *MEDFileCMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
01952 {
01953   MEDFileUtilities::CheckFileForRead(fileName);
01954   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
01955   return new MEDFileCMesh(fid,mName,dt,it);
01956 }
01957 
01958 int MEDFileCMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception)
01959 {
01960   if(!((const MEDCouplingCMesh*)_cmesh))
01961     throw INTERP_KERNEL::Exception("MEDFileCMesh::getMeshDimension : unable to get meshdimension because no mesh set !");
01962   return _cmesh->getMeshDimension();
01963 }
01964 
01965 std::string MEDFileCMesh::simpleRepr() const
01966 {
01967   return MEDFileMesh::simpleRepr();
01968 }
01969 
01970 std::string MEDFileCMesh::advancedRepr() const
01971 {
01972   return simpleRepr();
01973 }
01974 
01975 bool MEDFileCMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
01976 {
01977   if(!MEDFileMesh::isEqual(other,eps,what))
01978     return false;
01979   const MEDFileCMesh *otherC=dynamic_cast<const MEDFileCMesh *>(other);
01980   if(!otherC)
01981     {
01982       what="Mesh types differ ! This is cartesian and other is NOT !";
01983       return false;
01984     }
01985   clearNonDiscrAttributes();
01986   otherC->clearNonDiscrAttributes();
01987   const MEDCouplingCMesh *coo1=_cmesh;
01988   const MEDCouplingCMesh *coo2=otherC->_cmesh;
01989   if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
01990     {
01991       what="Mismatch of cartesian meshes ! One is defined and not other !";
01992       return false;
01993     }
01994   if(coo1)
01995     {
01996       bool ret=coo1->isEqual(coo2,eps);
01997       if(!ret)
01998         {
01999           what="cartesian meshes differ !";
02000           return false;
02001         }
02002     }
02003   const DataArrayInt *famc1=_fam_nodes;
02004   const DataArrayInt *famc2=otherC->_fam_nodes;
02005   if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
02006     {
02007       what="Mismatch of families arr on nodes ! One is defined and not other !";
02008       return false;
02009     }
02010   if(famc1)
02011     {
02012       bool ret=famc1->isEqual(*famc2);
02013       if(!ret)
02014         {
02015           what="Families arr on nodes differ !";
02016           return false;
02017         }
02018     }
02019   famc1=_fam_cells;
02020   famc2=otherC->_fam_cells;
02021   if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
02022     {
02023       what="Mismatch of families arr on cells ! One is defined and not other !";
02024       return false;
02025     }
02026   if(famc1)
02027     {
02028       bool ret=famc1->isEqual(*famc2);
02029       if(!ret)
02030         {
02031           what="Families arr on cells differ !";
02032           return false;
02033         }
02034     }
02035   famc1=_num_nodes;
02036   famc2=otherC->_num_nodes;
02037   if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
02038     {
02039       what="Mismatch of numbering arr on nodes ! One is defined and not other !";
02040       return false;
02041     }
02042   if(famc1)
02043     {
02044       bool ret=famc1->isEqual(*famc2);
02045       if(!ret)
02046         {
02047           what="Numbering arr on nodes differ !";
02048           return false;
02049         }
02050     }
02051   famc1=_num_cells;
02052   famc2=otherC->_num_cells;
02053   if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
02054     {
02055       what="Mismatch of numbering arr on cells ! One is defined and not other !";
02056       return false;
02057     }
02058   if(famc1)
02059     {
02060       bool ret=famc1->isEqual(*famc2);
02061       if(!ret)
02062         {
02063           what="Numbering arr on cells differ !";
02064           return false;
02065         }
02066     }
02067   return true;
02068 }
02069 
02070 void MEDFileCMesh::clearNonDiscrAttributes() const
02071 {
02072   MEDFileMesh::clearNonDiscrAttributes();
02073   MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_cmesh);
02074   const DataArrayInt *tmp=_fam_nodes;
02075   if(tmp)
02076     (const_cast<DataArrayInt *>(tmp))->setName("");
02077   tmp=_num_nodes;
02078   if(tmp)
02079     (const_cast<DataArrayInt *>(tmp))->setName("");
02080   tmp=_fam_cells;
02081   if(tmp)
02082     (const_cast<DataArrayInt *>(tmp))->setName("");
02083   tmp=_num_cells;
02084   if(tmp)
02085     (const_cast<DataArrayInt *>(tmp))->setName("");
02086 }
02087 
02088 MEDFileCMesh::MEDFileCMesh()
02089 {
02090 }
02091 
02092 MEDFileCMesh::MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
02093 try
02094   {
02095     loadCMeshFromFile(fid,mName,dt,it);
02096   }
02097 catch(INTERP_KERNEL::Exception& e)
02098   {
02099     throw e;
02100   }
02101 
02102 void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
02103 {
02104   MEDFileCMeshL2 loaderl2;
02105   ParaMEDMEM::MEDCouplingMeshType meshType;
02106   int dummy0,dummy1;
02107   std::string dtunit;
02108   int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit);
02109   if(meshType!=CARTESIAN)
02110     {
02111       std::ostringstream oss; oss << "Trying to load as cartesian an existing mesh with name '" << mName << "' that is NOT cartesian !";
02112       throw INTERP_KERNEL::Exception(oss.str().c_str());
02113     }
02114   loaderl2.loadAll(fid,mid,mName,dt,it);
02115   MEDCouplingCMesh *mesh=loaderl2.getMesh();
02116   mesh->incrRef();
02117   _cmesh=mesh;
02118   setName(loaderl2.getName());
02119   setDescription(loaderl2.getDescription());
02120   setIteration(loaderl2.getIteration());
02121   setOrder(loaderl2.getOrder());
02122   setTimeValue(loaderl2.getTime());
02123   setTimeUnit(loaderl2.getTimeUnit());
02124   MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups);
02125   med_bool chgt=MED_FALSE,trsf=MED_FALSE;
02126   int nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf);
02127   if(nbOfElt>0)
02128     {
02129       _fam_nodes=DataArrayInt::New();
02130       _fam_nodes->alloc(nbOfElt,1);
02131       MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_fam_nodes->getPointer());
02132     }
02133   nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_NUMBER,MED_NODAL,&chgt,&trsf);
02134   if(nbOfElt>0)
02135     {
02136       _num_nodes=DataArrayInt::New();
02137       _num_nodes->alloc(nbOfElt,1);
02138       MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_num_nodes->getPointer());
02139     }
02140   int spaceDim=mesh->getSpaceDimension();
02141   med_geometry_type geoTypeReq=MED_NONE;
02142   switch(spaceDim)
02143     {
02144     case 3:
02145       geoTypeReq=MED_HEXA8;
02146       break;
02147     case 2:
02148       geoTypeReq=MED_QUAD4;
02149       break;
02150     case 1:
02151       geoTypeReq=MED_SEG2;
02152       break;
02153     case 0:
02154       geoTypeReq=MED_POINT1;
02155       break;
02156     default:
02157       throw INTERP_KERNEL::Exception("Invalid spacedim detected for cartesian mesh ! Must be in (1,2,3) !");
02158     }
02159   nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf);
02160   if(nbOfElt>0)
02161     {
02162       _fam_cells=DataArrayInt::New();
02163       _fam_cells->alloc(nbOfElt,1);
02164       MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_fam_cells->getPointer());
02165     }
02166   nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_NUMBER,MED_NODAL,&chgt,&trsf);
02167   if(nbOfElt>0)
02168     {
02169       _num_cells=DataArrayInt::New();
02170       _num_cells->alloc(nbOfElt,1);
02171       MEDmeshEntityNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_num_cells->getPointer());
02172     }
02173 }
02174 
02175 void MEDFileCMesh::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception)
02176 {
02177   DataArrayInt *arr=_fam_nodes;
02178   if(arr)
02179     arr->changeValue(oldId,newId);
02180   arr=_fam_cells;
02181   if(arr)
02182     arr->changeValue(oldId,newId);
02183 }
02184 
02185 const MEDCouplingCMesh *MEDFileCMesh::getMesh() const
02186 {
02187   synchronizeTinyInfoOnLeaves();
02188   return _cmesh;
02189 }
02190 
02191 MEDCouplingMesh *MEDFileCMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const throw(INTERP_KERNEL::Exception)
02192 {
02193   if(renum)
02194     throw INTERP_KERNEL::Exception("MEDFileCMesh does not support renumbering ! To do it perform request of renum array directly !");
02195   if(meshDimRelToMax!=0)
02196     throw INTERP_KERNEL::Exception("MEDFileCMesh does not support multi level for mesh 0 expected as input !");
02197   const MEDCouplingCMesh *m=getMesh();
02198   if(m)
02199     m->incrRef();
02200   return const_cast<MEDCouplingCMesh *>(m);
02201 }
02202 
02203 void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception)
02204 {
02205   dealWithTinyInfo(m);
02206   if(m)
02207     m->incrRef();
02208   _cmesh=m;
02209 }
02210 
02211 void MEDFileCMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
02212 {
02213   INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02214   INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
02215   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
02216   MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
02217   MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
02218   MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str);
02219   int spaceDim=_cmesh->getSpaceDimension();
02220   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
02221   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
02222   for(int i=0;i<spaceDim;i++)
02223     {
02224       std::string info(_cmesh->getCoordsAt(i)->getInfoOnComponent(0));
02225       std::string c,u;
02226       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
02227       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
02228       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
02229     }
02230   MEDmeshCr(fid,maa,spaceDim,spaceDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
02231   MEDmeshGridTypeWr(fid,maa,MED_CARTESIAN_GRID);
02232   for(int i=0;i<spaceDim;i++)
02233     {
02234       const DataArrayDouble *da=_cmesh->getCoordsAt(i);
02235       MEDmeshGridIndexCoordinateWr(fid,maa,_iteration,_order,_time,i+1,da->getNumberOfTuples(),da->getConstPointer());
02236     }
02237   //
02238   med_geometry_type geoTypeReq=MED_NONE;
02239   switch(spaceDim)
02240     {
02241     case 3:
02242       geoTypeReq=MED_HEXA8;
02243       break;
02244     case 2:
02245       geoTypeReq=MED_QUAD4;
02246       break;
02247     case 1:
02248       geoTypeReq=MED_SEG2;
02249       break;
02250     case 0:
02251       geoTypeReq=MED_POINT1;
02252       break;
02253     default:
02254       throw INTERP_KERNEL::Exception("Invalid spacedim detected for cartesian mesh ! Must be in (1,2,3) !");
02255     }
02256   //
02257   if((const DataArrayInt *)_fam_cells)
02258     MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_CELL,geoTypeReq,_fam_cells->getNumberOfTuples(),_fam_cells->getConstPointer());
02259   if((const DataArrayInt *)_fam_nodes)
02260     MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_NODE,MED_NONE,_fam_nodes->getNumberOfTuples(),_fam_nodes->getConstPointer());
02261   //
02262   MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str);
02263 }
02264 
02265 int MEDFileCMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
02266 {
02267   if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
02268     throw INTERP_KERNEL::Exception("MEDFileCMesh::getSizeAtLevel : Only available for levels 0 or 1 !");
02269   if(!((const MEDCouplingCMesh *)_cmesh))
02270     throw INTERP_KERNEL::Exception("MEDFileCMesh::getSizeAtLevel : No cartesian mesh set !");
02271   if(meshDimRelToMaxExt==0)
02272     return _cmesh->getNumberOfCells();
02273   else
02274     return _cmesh->getNumberOfNodes();
02275 }
02276 
02277 void MEDFileCMesh::synchronizeTinyInfoOnLeaves() const
02278 {
02279   const MEDCouplingCMesh *cmesh=_cmesh;
02280   (const_cast<MEDCouplingCMesh *>(cmesh))->setName(_name.c_str());
02281   (const_cast<MEDCouplingCMesh *>(cmesh))->setDescription(_desc_name.c_str());
02282   (const_cast<MEDCouplingCMesh *>(cmesh))->setTime(_time,_iteration,_order);
02283   (const_cast<MEDCouplingCMesh *>(cmesh))->setTimeUnit(_dt_unit.c_str());
02284 }
02285 
02286 std::vector<int> MEDFileCMesh::getNonEmptyLevels() const
02287 {
02288   std::vector<int> ret(1);
02289   return ret;
02290 }
02291 
02292 std::vector<int> MEDFileCMesh::getNonEmptyLevelsExt() const
02293 {
02294   std::vector<int> ret(2);
02295   ret[0]=1;
02296   return ret;
02297 }
02298 
02299 DataArrayInt *MEDFileCMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
02300 {
02301   if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
02302     throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : Only available for levels 0 or 1 !");
02303   std::vector<int> famIds=getFamiliesIds(fams);
02304   if(meshDimRelToMaxExt==1)
02305     {
02306       if((const DataArrayInt *)_fam_nodes)
02307         {
02308           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam_nodes->getIdsEqualList(famIds);
02309           if(renum)
02310             return MEDFileUMeshSplitL1::Renumber(_num_nodes,da);
02311           else
02312             {
02313               da->incrRef();
02314               return da;
02315             }
02316         }
02317       else
02318         throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : no family array specified on nodes !");
02319     }
02320   else
02321     {
02322       if((const DataArrayInt *)_fam_cells)
02323         {
02324           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam_cells->getIdsEqualList(famIds);
02325           if(renum)
02326             return MEDFileUMeshSplitL1::Renumber(_num_cells,da);
02327           else
02328             {
02329               da->incrRef();
02330               return da;
02331             }
02332         }
02333       else
02334         throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : no family array specified on cells !");
02335     }
02336 }
02337 
02338 void MEDFileCMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception)
02339 {
02340   if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
02341     throw INTERP_KERNEL::Exception("MEDFileCMesh::setRenumFieldArr : Only available for levels 0 or 1 !");
02342   if(famArr)
02343     famArr->incrRef();
02344   if(meshDimRelToMaxExt==0)
02345     _fam_cells=famArr;
02346   else
02347     _fam_nodes=famArr;
02348 }
02349 
02350 void MEDFileCMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception)
02351 {
02352   if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
02353     throw INTERP_KERNEL::Exception("MEDFileCMesh::setRenumFieldArr : Only available for levels 0 or 1 !");
02354   if(renumArr)
02355     renumArr->incrRef();
02356   if(meshDimRelToMaxExt==0)
02357     _num_cells=renumArr;
02358   else
02359     _num_nodes=renumArr;
02360 }
02361 
02362 const DataArrayInt *MEDFileCMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
02363 {
02364   if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
02365     throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamilyFieldAtLevel : Only available for levels 0 or 1 !");
02366   if(meshDimRelToMaxExt==0)
02367     return _fam_cells;
02368   else
02369     return _fam_nodes;
02370 }
02371 
02372 const DataArrayInt *MEDFileCMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
02373 {
02374   if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
02375     throw INTERP_KERNEL::Exception("MEDFileCMesh::getNumberFieldAtLevel : Only available for levels 0 or 1 !");
02376   if(meshDimRelToMaxExt==0)
02377     return _num_cells;
02378   else
02379     return _num_nodes;
02380 }
02381 
02382 const DataArrayInt *MEDFileCMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
02383 {
02384   if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
02385     throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : Only available for levels 0 or 1 !");
02386   if(meshDimRelToMaxExt==0)
02387     {
02388       if((const DataArrayInt *)_num_cells)
02389         {
02390           int pos;
02391           int maxValue=_num_cells->getMaxValue(pos);
02392           _rev_num_cells=_num_cells->invertArrayN2O2O2N(maxValue+1);
02393           return _rev_num_cells;
02394         }
02395       else
02396         throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no cell renumbering for a request on reverse numbering !");
02397     }
02398   else
02399     {
02400       if((const DataArrayInt *)_num_nodes)
02401         {
02402           int pos;
02403           int maxValue=_num_nodes->getMaxValue(pos);
02404           _rev_num_nodes=_num_nodes->invertArrayN2O2O2N(maxValue+1);
02405           return _rev_num_nodes;
02406         }
02407       else
02408         throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no node renumbering for a request on reverse numbering !");
02409     }
02410 }
02411 
02412 
02413 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New()
02414 {
02415   return new MEDFileMeshMultiTS;
02416 }
02417 
02418 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
02419 {
02420   return new MEDFileMeshMultiTS(fileName);
02421 }
02422 
02423 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
02424 {
02425   return new MEDFileMeshMultiTS(fileName,mName);
02426 }
02427 
02428 const char *MEDFileMeshMultiTS::getName() const throw(INTERP_KERNEL::Exception)
02429 {
02430   if(_mesh_one_ts.empty())
02431     throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getName : no time steps set !");
02432   return _mesh_one_ts[0]->getName();
02433 }
02434 
02435 MEDFileMesh *MEDFileMeshMultiTS::getOneTimeStep() const throw(INTERP_KERNEL::Exception)
02436 {
02437   if(_mesh_one_ts.empty())
02438     throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getOneTimeStep : empty time step set !");
02439   return const_cast<MEDFileMesh *>(static_cast<const MEDFileMesh *>(_mesh_one_ts[0]));
02440 }
02441 
02442 void MEDFileMeshMultiTS::setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception)
02443 {
02444   if(!mesh1TimeStep)
02445     throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::setOneTimeStep : input pointer should be different from 0 !");
02446   _mesh_one_ts.resize(1);
02447   mesh1TimeStep->incrRef();
02448   //MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> toto=mesh1TimeStep;
02449   _mesh_one_ts[0]=mesh1TimeStep;
02450 }
02451 
02452 void MEDFileMeshMultiTS::write(med_idt fid) const throw(INTERP_KERNEL::Exception)
02453 {
02454   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
02455     {
02456       (*it)->copyOptionsFrom(*this);
02457       (*it)->write(fid);
02458     }
02459 }
02460 
02461 void MEDFileMeshMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
02462 {
02463   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
02464   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
02465   std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\""; 
02466   MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
02467   write(fid);
02468 }
02469 
02470 void MEDFileMeshMultiTS::loadFromFile(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
02471 {//for the moment to be improved
02472   _mesh_one_ts.resize(1);
02473   _mesh_one_ts[0]=MEDFileMesh::New(fileName,mName,-1,-1);
02474 }
02475 
02476 MEDFileMeshMultiTS::MEDFileMeshMultiTS()
02477 {
02478 }
02479 
02480 MEDFileMeshMultiTS::MEDFileMeshMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
02481 try
02482   {
02483     std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
02484     if(ms.empty())
02485     {
02486       std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
02487       throw INTERP_KERNEL::Exception(oss.str().c_str());
02488     }
02489     MEDFileUtilities::CheckFileForRead(fileName);
02490     MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
02491     int dt,it;
02492     ParaMEDMEM::MEDCouplingMeshType meshType;
02493     std::string dummy2;
02494     MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
02495     loadFromFile(fileName,ms.front().c_str());
02496   }
02497 catch(INTERP_KERNEL::Exception& e)
02498   {
02499     throw e;
02500   }
02501 
02502 MEDFileMeshMultiTS::MEDFileMeshMultiTS(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
02503 try
02504   {
02505     loadFromFile(fileName,mName);
02506   }
02507 catch(INTERP_KERNEL::Exception& e)
02508   {
02509     throw e;
02510   }
02511 
02512 MEDFileMeshes *MEDFileMeshes::New()
02513 {
02514   return new MEDFileMeshes;
02515 }
02516 
02517 MEDFileMeshes *MEDFileMeshes::New(const char *fileName) throw(INTERP_KERNEL::Exception)
02518 {
02519   return new MEDFileMeshes(fileName);
02520 }
02521 
02522 void MEDFileMeshes::write(med_idt fid) const throw(INTERP_KERNEL::Exception)
02523 {
02524   checkCoherency();
02525   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++)
02526     {
02527       (*it)->copyOptionsFrom(*this);
02528       (*it)->write(fid);
02529     }
02530 }
02531 
02532 void MEDFileMeshes::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
02533 {
02534   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
02535   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
02536   std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\""; 
02537   MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
02538   checkCoherency();
02539   write(fid);
02540 }
02541 
02542 int MEDFileMeshes::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception)
02543 {
02544   return _meshes.size();
02545 }
02546 
02547 MEDFileMesh *MEDFileMeshes::getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception)
02548 {
02549   if(i<0 || i>=(int)_meshes.size())
02550     {
02551       std::ostringstream oss; oss << "MEDFileMeshes::getMeshAtPos : invalid mesh id given in parameter ! Should be in [0;" << _meshes.size() << ") !";
02552       throw INTERP_KERNEL::Exception(oss.str().c_str());
02553     }
02554   return _meshes[i]->getOneTimeStep();
02555 }
02556 
02557 MEDFileMesh *MEDFileMeshes::getMeshWithName(const char *mname) const throw(INTERP_KERNEL::Exception)
02558 {
02559   std::vector<std::string> ms=getMeshesNames();
02560   std::vector<std::string>::iterator it=std::find(ms.begin(),ms.end(),mname);
02561   if(it==ms.end())
02562     {
02563       std::ostringstream oss; oss << "MEDFileMeshes::getMeshWithName : Mesh  \"" << mname << "\" does not exist in this ! Existing are : ";
02564       std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss," "));
02565       throw INTERP_KERNEL::Exception(oss.str().c_str());
02566     }
02567   return getMeshAtPos((int)std::distance(ms.begin(),it));
02568 }
02569 
02570 std::vector<std::string> MEDFileMeshes::getMeshesNames() const throw(INTERP_KERNEL::Exception)
02571 {
02572   std::vector<std::string> ret(_meshes.size());
02573   int i=0;
02574   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
02575     {
02576       const MEDFileMeshMultiTS *f=(*it);
02577       if(f)
02578         {
02579           ret[i]=f->getName();
02580         }
02581       else
02582         {
02583           std::ostringstream oss; oss << "MEDFileMeshes::getMeshesNames : At rank #" << i << " mesh is not defined !";
02584           throw INTERP_KERNEL::Exception(oss.str().c_str());
02585         }
02586     }
02587   return ret;
02588 }
02589 
02590 void MEDFileMeshes::resize(int newSize) throw(INTERP_KERNEL::Exception)
02591 {
02592   _meshes.resize(newSize);
02593 }
02594 
02595 void MEDFileMeshes::pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception)
02596 {
02597   if(!mesh)
02598     throw INTERP_KERNEL::Exception("MEDFileMeshes::pushMesh : invalid input pointer ! should be different from 0 !");
02599   MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New();
02600   elt->setOneTimeStep(mesh);
02601   _meshes.push_back(elt);
02602 }
02603 
02604 void MEDFileMeshes::setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception)
02605 {
02606   if(!mesh)
02607     throw INTERP_KERNEL::Exception("MEDFileMeshes::setMeshAtPos : invalid input pointer ! should be different from 0 !");
02608   if(i>=(int)_meshes.size())
02609     _meshes.resize(i+1);
02610   MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New();
02611   elt->setOneTimeStep(mesh);
02612   _meshes[i]=elt;
02613 }
02614 
02615 void MEDFileMeshes::destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception)
02616 {
02617   if(i<0 || i>=(int)_meshes.size())
02618     {
02619       std::ostringstream oss; oss << "MEDFileMeshes::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _meshes.size() << ") !";
02620       throw INTERP_KERNEL::Exception(oss.str().c_str());
02621     }
02622   _meshes.erase(_meshes.begin()+i);
02623 }
02624 
02625 void MEDFileMeshes::loadFromFile(const char *fileName) throw(INTERP_KERNEL::Exception)
02626 {
02627   std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
02628   int i=0;
02629   _meshes.resize(ms.size());
02630   for(std::vector<std::string>::const_iterator it=ms.begin();it!=ms.end();it++,i++)
02631     _meshes[i]=MEDFileMeshMultiTS::New(fileName,(*it).c_str());
02632 }
02633 
02634 MEDFileMeshes::MEDFileMeshes()
02635 {
02636 }
02637 
02638 MEDFileMeshes::MEDFileMeshes(const char *fileName) throw(INTERP_KERNEL::Exception)
02639 try
02640   {
02641     loadFromFile(fileName);
02642   }
02643 catch(INTERP_KERNEL::Exception& e)
02644   {
02645   }
02646 
02647 std::string MEDFileMeshes::simpleRepr() const
02648 {
02649   std::ostringstream oss;
02650   oss << "(*****************)\n(* MEDFileMeshes *)\n(*****************)\n\n";
02651   simpleReprWithoutHeader(oss);
02652   return oss.str();
02653 }
02654 
02655 void MEDFileMeshes::simpleReprWithoutHeader(std::ostream& oss) const
02656 {
02657   int nbOfMeshes=getNumberOfMeshes();
02658   oss << "There are " << nbOfMeshes << " meshes with the following names : \n";
02659   std::vector<std::string> mns=getMeshesNames();
02660   for(int i=0;i<nbOfMeshes;i++)
02661     oss << "  - #" << i << " \"" << mns[i] << "\"\n";
02662 }
02663 
02664 void MEDFileMeshes::checkCoherency() const throw(INTERP_KERNEL::Exception)
02665 {
02666   static const char MSG[]="MEDFileMeshes::checkCoherency : mesh at rank ";
02667   int i=0;
02668   std::set<std::string> s;
02669   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
02670     {
02671       const MEDFileMeshMultiTS *elt=(*it);
02672       if(!elt)
02673         {
02674           std::ostringstream oss; oss << MSG << i << "/" << _meshes.size() << " is empty !";
02675           throw INTERP_KERNEL::Exception(oss.str().c_str());
02676         }
02677       std::size_t sz=s.size();
02678       s.insert(std::string((*it)->getName()));
02679       if(s.size()==sz)
02680         {
02681           std::ostringstream oss; oss << MSG << i << " has a name (\"" << (*it)->getName() << "\") already used by an another mesh in list !";
02682           throw INTERP_KERNEL::Exception(oss.str().c_str());
02683         }
02684     }
02685 }