1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MEDMEM_MedVersion.hxx"
23 #include "MEDMEM_Utilities.hxx"
24 #include "MEDMEM_Compatibility21_22.hxx"
26 using namespace MEDMEM;
27 using namespace MED_EN;
29 medFileVersion MEDMEM::getMedFileVersion(const string & fileName)
32 medFileVersion version;
34 med_2_1::med_idt fid21;
35 med_2_3::med_idt fid22;
37 med_2_1::med_err ret21;
38 med_2_3::med_err ret22;
40 med_2_1::med_int major21;
41 med_2_1::med_int minor21;
42 med_2_1::med_int release21;
44 med_2_3::med_int major22;
45 med_2_3::med_int minor22;
46 med_2_3::med_int release22;
48 med_2_3::med_mode_acces access22 = med_2_3::MED_LECTURE;
49 med_2_1::med_mode_acces access21 = med_2_1::MED_LECT;
52 Med Version 2.1 access to the file
55 fid21 = med_2_1::MEDouvrir((const_cast <char *> (fileName.c_str())),
59 throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.1 access");
61 ret21 = med_2_1::MEDversionLire(fid21,&major21,&minor21,&release21);
64 throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.1 version numbers reading");
66 if ((minor21 == -1) || (release21 == -1))
68 MESSAGE_MED("getMedFileVersion the file may have been produced by a version 2.1.x x<5");
73 ret21 = med_2_1::MEDfermer(fid21);
76 throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.1 file closing");
79 Med Version 2.3 access to the file
82 fid22 = med_2_3::MEDouvrir((const_cast <char *> (fileName.c_str())),
86 throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.2 access");
88 ret22 = med_2_3::MEDversionLire(fid22,&major22,&minor22,&release22);
91 throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.2 version numbers reading");
93 if ((minor22 == -1) || (release22 == -1))
95 MESSAGE_MED("getMedFileVersion the file may have been produced by a version 2.1.x x<5");
100 ret22 = med_2_3::MEDfermer(fid22);
103 throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.2 file closing");
105 if ((major21 != major22) || (minor21 != minor22) || (release21 != release22))
106 throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V21 and V22 version numbers are different");
108 MESSAGE_MED("getMedFileVersion: status version 21 of the file major " << major21 << " minor " << minor21 << " release " << release21);
110 MESSAGE_MED("getMedFileVersion: status version 22 of the file major " << major22 << " minor " << minor22 << " release " << release22);
116 else if (minor21 > 1)
122 MESSAGE_MED("getMedFileVersion the version of the file is " << version);
127 //================================================================================
129 * \brief return file mode access corresponding to MED_EN::med_mode_acces in given med version
130 * \param mode - either MED_LECT, MED_ECRI or MED_REMP
131 * \param medVersion - V21 or V22 or ??
132 * \retval int - file mode access
134 * To be used in MEDouvrir() call
136 //================================================================================
138 //int MEDMEM::getMedAccessMode(MED_EN::med_mode_acces mode,
139 // MED_EN::medFileVersion medVersion)
140 // throw (MEDEXCEPTION)
142 // switch ( medVersion ) {
149 if (access(nom,F_OK))
152 if ((fid = _MEDfichierOuvrir(nom,mode_acces)) < 0)
157 if (access(nom,F_OK))
159 if ((fid = _MEDfichierCreer(nom)) < 0)
163 if ((fid = _MEDfichierOuvrir(nom,mode_acces)) < 0)
168 if ((fid = _MEDfichierCreer(nom)) < 0)
173 // case MED_EN::MED_LECT: return med_2_1::MED_LECT;
174 // case MED_EN::MED_ECRI: return med_2_1::MED_ECRI;
175 // case MED_EN::MED_REMP: return med_2_1::MED_ECRI;
177 // throw MEDEXCEPTION("getMedAccessMode(): Wrong access mode");
182 MED_LECTURE : Ouverture en lecture seule
183 MED_LECTURE_ECRITURE : Ouverture en lecture/ecriture, si un élément existe il est écrasé
184 MED_LECTURE_AJOUT : Ouverture en lecture/ecriture, si un élément existe une erreur est générée
185 MED_CREATION : Créer le fichier s'il n'existe pas, l'écrase sinon
188 // case MED_EN::MED_LECT: return med_2_3::MED_LECTURE;
189 // case MED_EN::MED_ECRI: return med_2_3::MED_LECTURE_ECRITURE;
190 // case MED_EN::MED_REMP: return med_2_3::MED_LECTURE_ECRITURE;
191 // case MED_EN::MED_CREA: return med_2_3::MED_CREATION;
193 // throw MEDEXCEPTION("getMedAccessMode(): Wrong access mode");
197 // throw MEDEXCEPTION("getMedAccessMode(): Unknown med version");