Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_Compatibility21_22.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "MEDMEM_Compatibility21_22.hxx"
23
24 using namespace MEDMEM;
25 using namespace MED_EN;
26
27 //================================================================================
28 /*!
29  * \brief return file mode access corresponding to MED_EN::med_mode_acces in given med version
30   * \param mode - either MED_LECT, MED_ECRI or MED_REMP
31   * \param medVersion - V21 or V22 or ??
32   * \retval int - file mode access
33   *
34   * To be used in MEDouvrir() call
35  */
36 //================================================================================
37
38 int MEDMEM::getMedAccessMode(MED_EN::med_mode_acces mode,
39                              MED_EN::medFileVersion medVersion)
40   throw (MEDEXCEPTION)
41 {
42   switch ( medVersion ) {
43   case V21:
44 /*
45   from MEDouvrir.c:
46      switch(mode_acces)
47     {
48     case MED_LECT :
49       if (access(nom,F_OK))
50         return -1;
51       else 
52         if ((fid = _MEDfichierOuvrir(nom,mode_acces)) < 0)
53           return -1;
54       break;
55
56     case MED_ECRI :
57       if (access(nom,F_OK))
58         {
59           if ((fid = _MEDfichierCreer(nom)) < 0)
60             return -1;
61         }
62       else
63         if ((fid = _MEDfichierOuvrir(nom,mode_acces)) < 0)
64           return -1;
65       break;
66
67     case MED_REMP :
68       if ((fid = _MEDfichierCreer(nom)) < 0)
69         return -1;
70       break;
71 */
72     switch ( mode ) {
73     case MED_EN::WRONLY: return med_2_1::MED_ECRI;
74     case MED_EN::RDONLY: return med_2_1::MED_LECT;
75     case MED_EN::RDWR:   return med_2_1::MED_ECRI; //REMP; -- pb with RDWR drivers
76     default:
77       throw MEDEXCEPTION("getMedAccessMode(): Wrong access mode");
78     }
79   case V22:
80 /*
81   from med.h:
82    MED_LECTURE          : Ouverture en lecture seule
83    MED_LECTURE_ECRITURE : Ouverture en lecture/ecriture, si un élément existe il est écrasé
84    MED_LECTURE_AJOUT    : Ouverture en lecture/ecriture, si un élément existe une erreur est générée
85    MED_CREATION         : Créer le fichier s'il n'existe pas, l'écrase sinon
86 */
87     switch ( mode ) {
88     case MED_EN::WRONLY: return med_2_3::MED_LECTURE_ECRITURE;// be coherent with V21 /*MED_CREATION;*/
89     case MED_EN::RDONLY: return med_2_3::MED_LECTURE;
90     case MED_EN::RDWR:   return med_2_3::MED_LECTURE_ECRITURE;
91     default:
92       throw MEDEXCEPTION("getMedAccessMode(): Wrong access mode");
93     }
94   default:;
95   }
96   throw MEDEXCEPTION("getMedAccessMode(): Unknown med version");
97 }