Back to index

salome-med  6.5.0
MEDMEM_MedVersion.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "MEDMEM_MedVersion.hxx"
00024 #include "MEDMEM_Utilities.hxx"
00025 
00026 using namespace MEDMEM;
00027 using namespace MED_EN;
00028 
00029 medFileVersion MEDMEM::getMedFileVersion(const string & fileName)
00030   throw (MEDEXCEPTION)
00031 {
00032   medFileVersion version;
00033 
00034   med_2_3::med_idt fid22;
00035 
00036   med_2_3::med_err ret22;
00037 
00038   med_2_3::med_int major22;
00039   med_2_3::med_int minor22;
00040   med_2_3::med_int release22;
00041 
00042   med_2_3::med_access_mode access22 = med_2_3::MED_ACC_RDONLY;
00043 
00044   /*
00045     Med Version 2.3 access to the file
00046   */
00047 
00048   fid22 = med_2_3::MEDfileOpen(fileName.c_str(),access22);
00049 
00050   if (fid22 < 0)
00051     throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.2 access");
00052 
00053   ret22 = med_2_3::MEDfileNumVersionRd(fid22,&major22,&minor22,&release22);
00054 
00055   if (ret22 < 0)
00056     throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.2 version numbers reading");
00057 
00058   if ((minor22 == -1) || (release22 == -1))
00059     {
00060       MESSAGE_MED("getMedFileVersion the file may have been produced by a version 2.1.x x<5");
00061       minor22 = 1;
00062       release22 = 5;
00063     }
00064 
00065   ret22 = med_2_3::MEDfileClose(fid22);
00066 
00067   if (ret22 < 0)
00068     throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.2 file closing");
00069 
00070   if (major22 == 2)
00071     {
00072       if (minor22 == 1)
00073         version = V21;
00074       else if (minor22 > 1)
00075         version = V22;
00076     }
00077   else
00078     version = V22;
00079 
00080   MESSAGE_MED("getMedFileVersion the version of the file is " << version);
00081 
00082   return version;
00083 }
00084 
00085 med_2_3::med_access_mode MEDMEM::getMedAccessMode(MED_EN::med_mode_acces mode)
00086 {
00087   //from med.h:
00088   //    MED_ACC_RDONLY, /**<Ouverture en lecture seule*/
00089   //    MED_ACC_RDWR,   /**<Ouverture en lecture/ecriture, si un élément existe il est écrasé*/
00090   //    MED_ACC_RDEXT,  /**<Ouverture en lecture/ecriture, si un élément existe une erreur est générée*/
00091   //    MED_ACC_CREAT,  /**<Créer le fichier s'il n'existe pas, l'écrase sinon*/
00092   //    MED_ACC_UNDEF   /**<Variable globale interne initialisée au mode d'ouverture*/ 
00093   switch ( mode ) {
00094   case MED_EN::RDONLY: return med_2_3::MED_ACC_RDONLY;
00095   case MED_EN::WRONLY: return med_2_3::MED_ACC_CREAT;
00096   case MED_EN::RDWR:   return med_2_3::MED_ACC_RDWR;
00097   default:
00098     return med_2_3::med_access_mode( mode );
00099   }
00100 }