MED fichier
MEDfileVersionOpen.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2016 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 
43 med_idt
44 MEDfileVersionOpen(const char* const filename,
45  const med_access_mode accessmode,
46  const med_int major,
47  const med_int minor,
48  const med_int release)
49 
50 {
51  med_idt _fid = 0;
52  med_err _ret = -1;
53 
54  /*
55  * On inhibe le gestionnaire d'erreur HDF
56  */
58 
59  /*
60  * On ouvre le fichier MED sous HDF
61  */
62  switch(accessmode)
63  {
64  case MED_ACC_RDONLY :
65  if (access(filename,F_OK)) {
66  MED_ERR_(_ret,MED_ERR_EXIST,MED_ERR_FILE,filename);
67  goto ERROR;
68 
69  } else {
70  if ((_fid = _MEDfileOpen((char*) filename,accessmode)) < 0) {
71  MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,filename);
72  goto ERROR;
73  }
74  };
75  break;
76 
77  case MED_ACC_RDWR :
78  if (access(filename,F_OK)) {
79  if ((_fid = _MEDfileCreate((char*) filename,accessmode,major,minor,release)) < 0) {
80  MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILE,filename);
81  goto ERROR;
82  }
83  } else
84  if ((_fid = _MEDfileOpen((char*) filename,accessmode)) < 0) {
85  MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,filename);
86  goto ERROR;
87  }
88  break;
89 
90  case MED_ACC_RDEXT :
91  if (access(filename,F_OK))
92  {
93  if ((_fid = _MEDfileCreate((char*) filename,accessmode,major,minor,release)) < 0) {
94  MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILE,filename);
95  goto ERROR;
96  }
97  }
98  else
99  if ((_fid = _MEDfileOpen((char *) filename,accessmode)) < 0) {
100  MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,filename);
101  goto ERROR;
102  }
103  break;
104 
105  case MED_ACC_CREAT :
106  if ((_fid = _MEDfileCreate((char *) filename,MED_ACC_RDWR,major,minor,release)) < 0) {
107  MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILE,filename);
108  goto ERROR;
109  }
110  break;
111 
112  default :
113  MED_ERR_(_ret,MED_ERR_INIT,MED_ERR_FILE,filename);
114  goto ERROR;
115  }
116 
117  _ret=0;
118  ERROR:
119 
120  if (_ret < 0)
121  _fid = (med_idt) _ret;
122 
123  return _fid;
124 }
125 
#define MED_ERR_FILE
Definition: med_err.h:81
herr_t med_err
Definition: med.h:310
med_access_mode
Definition: med.h:113
MEDC_EXPORT med_idt _MEDfileOpen(const char *const filename, const med_access_mode accessmode)
int med_int
Definition: med.h:316
#define MED_ERR_CREATE
Definition: med_err.h:24
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)
MEDC_EXPORT void _MEDmodeErreurVerrouiller(void)
hid_t med_idt
Definition: med.h:309
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...
#define MED_ERR_OPEN
Definition: med_err.h:34
#define MED_ERR_EXIST
Definition: med_err.h:40
#define MED_ERR_INIT
Definition: med_err.h:30
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:158