MED fichier

MEDfileVersionOpen.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2021 EDF R&D, CEA/DEN
4 * MED is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * MED is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with MED. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19 #include <med.h>
20 #include <med_config.h>
21 #include <med_outils.h>
22
23 #ifdef PPRO_NT
24 #define F_OK 0
25 #else
26 #include <unistd.h>
27 #endif
28
29
44 med_idt
45 MEDfileVersionOpen(const char* const filename,
46 const med_access_mode accessmode,
47 const med_int major,
48 const med_int minor,
49 const med_int release)
50
51 {
52 med_idt _fid = 0;
53 med_err _ret = -1;
54
55 /*
56 * On inhibe le gestionnaire d'erreur HDF
57 */
58 _MEDmodeErreurVerrouiller();
59
60 /*
61 * On ouvre le fichier MED sous HDF
62 */
63 switch(accessmode)
64 {
65 case MED_ACC_RDONLY :
66 if (_MEDaccess(filename,F_OK)) {
67 MED_ERR_(_ret,MED_ERR_EXIST,MED_ERR_FILE,filename);
68 goto ERROR;
69
70 } else {
71 if ((_fid = _MEDfileOpen((char*) filename,accessmode)) < 0) {
72 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,filename);
73 goto ERROR;
74 }
75 };
76 break;
77
78 case MED_ACC_RDWR :
79 if (_MEDaccess(filename,F_OK)) {
80 if ((_fid = _MEDfileCreate((char*) filename,accessmode,major,minor,release)) < 0) {
81 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILE,filename);
82 goto ERROR;
83 }
84 } else
85 if ((_fid = _MEDfileOpen((char*) filename,accessmode)) < 0) {
86 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,filename);
87 goto ERROR;
88 }
89 break;
90
91 case MED_ACC_RDEXT :
92 if (_MEDaccess(filename,F_OK))
93 {
94 if ((_fid = _MEDfileCreate((char*) filename,accessmode,major,minor,release)) < 0) {
95 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILE,filename);
96 goto ERROR;
97 }
98 }
99 else
100 if ((_fid = _MEDfileOpen((char *) filename,accessmode)) < 0) {
101 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,filename);
102 goto ERROR;
103 }
104 break;
105
106 case MED_ACC_CREAT :
107 if ((_fid = _MEDfileCreate((char *) filename,MED_ACC_RDWR,major,minor,release)) < 0) {
108 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILE,filename);
109 goto ERROR;
110 }
111 break;
112
113 default :
114 MED_ERR_(_ret,MED_ERR_INIT,MED_ERR_FILE,filename);
115 goto ERROR;
116 }
117
118 _ret=0;
119 ERROR:
120
121 if (_ret < 0)
122 _fid = (med_idt) _ret;
123
124 return _fid;
125 }
126
MED_ERR_CREATE
#define MED_ERR_CREATE
Definition: med_err.h:27
med_idt
hid_t med_idt
Definition: med.h:331
MED_ERR_
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:160
MED_ACC_RDONLY
Definition: med.h:120
_MEDfileOpen
MEDC_EXPORT med_idt _MEDfileOpen(const char *const filename, const med_access_mode accessmode)
med_err
herr_t med_err
Definition: med.h:332
_MEDaccess
MEDC_EXPORT int _MEDaccess(const char *const file, int mode)
MED_ERR_OPEN
#define MED_ERR_OPEN
Definition: med_err.h:37
med_int
int med_int
Definition: med.h:342
MED_ERR_FILE
#define MED_ERR_FILE
Definition: med_err.h:82
MED_ACC_RDWR
Definition: med.h:121
med.h
med_access_mode
med_access_mode
Definition: med.h:120
filename
#define filename
Definition: test10.c:72
MEDfileVersionOpen
med_idt MEDfileVersionOpen(const char *const filename, const med_access_mode accessmode, const med_int major, const med_int minor, const med_int release)
Ouverture d'un fichier MED en indiquant la version du modèle à utiliser en cas de création d'un nouve...
Definition: MEDfileVersionOpen.c:45
MED_ACC_CREAT
Definition: med.h:123
MED_ERR_EXIST
#define MED_ERR_EXIST
Definition: med_err.h:43
med_outils.h
med_config.h
MED_ACC_RDEXT
Definition: med.h:122
_MEDfileCreate
MEDC_EXPORT med_idt _MEDfileCreate(const char *const filename, const med_access_mode accessmode, const med_int major, const med_int minor, const med_int release)
MED_ERR_INIT
#define MED_ERR_INIT
Definition: med_err.h:33
_MEDmodeErreurVerrouiller
MEDC_EXPORT void _MEDmodeErreurVerrouiller(void)