MED fichier
MEDparFileOpen.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 #include <mpi.h>
24 
25 #ifdef PPRO_NT_CALL
26 #define F_OK 0
27 #else
28 #include <unistd.h>
29 #endif
30 
31 
33 
46 /*#define true 1*/
47 
48 med_idt
49 MEDparFileOpen(const char* const filename,
50  const med_access_mode accessmode,
51  const MPI_Comm comm, const MPI_Info info)
52 {
53  med_idt _fid = -1;
54 
55  /*
56  * On inhibe le gestionnaire d'erreur HDF
57  */
59  /*
60  * On ouvre le fichier MED sous HDF
61  */
62  switch(accessmode)
63  {
64  case MED_ACC_RDONLY :
65  if (_MEDaccess(filename,F_OK)) {
67  goto ERROR;
68 
69  } else {
70  if ((_fid = _MEDparFileOpen((char*) filename, accessmode, comm, info)) < 0) {
72  goto ERROR;
73  }
74  };
75  break;
76 
77  case MED_ACC_RDWR :
78  if (_MEDaccess(filename,F_OK)) {
79  if ((_fid = _MEDparFileCreate((char*) filename,accessmode, comm, info)) < 0) {
81  goto ERROR;
82  }
83  } else
84  if ((_fid = _MEDparFileOpen((char*) filename,accessmode, comm, info)) < 0) {
86  goto ERROR;
87  }
88  break;
89 
90  case MED_ACC_RDEXT :
91  if (_MEDaccess(filename,F_OK))
92  {
93  if ((_fid = _MEDparFileCreate((char*) filename,accessmode, comm, info)) < 0) {
95  goto ERROR;
96  }
97  } else
98 
99  if ((_fid = _MEDparFileOpen((char *) filename, accessmode, comm, info)) < 0) {
101  goto ERROR;
102  }
103  break;
104 
105  case MED_ACC_CREAT :
106  if ((_fid = _MEDparFileCreate((char *) filename,MED_ACC_RDWR, comm, info)) < 0) {
108  goto ERROR;
109  }
110  break;
111 
112  default :
114  ISCRUTE_int(accessmode);
115  goto ERROR;
116  }
117 
118  if (_MEDcheckVersion30(_fid) < 0) {
119  MEDfileClose(_fid);
120  _fid=-1;goto ERROR;
121  }
122 
123  ERROR:
124 
125  return _fid;
126 }
MED_ERR_CREATE
#define MED_ERR_CREATE
Definition: med_err.h:27
MED_ERR_DOESNTEXIST
#define MED_ERR_DOESNTEXIST
Definition: med_err.h:38
ISCRUTE_int
#define ISCRUTE_int(entier)
Definition: med_utils.h:314
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
_MEDaccess
MEDC_EXPORT int _MEDaccess(const char *const file, int mode)
MED_ERR_OPEN
#define MED_ERR_OPEN
Definition: med_err.h:37
MED_ERR_FILE
#define MED_ERR_FILE
Definition: med_err.h:82
MED_ACC_RDWR
Definition: med.h:121
MED_ACCESS_MODE
med_access_mode MED_ACCESS_MODE
Definition: MEDparFileOpen.c:32
med.h
med_access_mode
med_access_mode
Definition: med.h:120
MEDparFileOpen
med_idt MEDparFileOpen(const char *const filename, const med_access_mode accessmode, const MPI_Comm comm, const MPI_Info info)
Ouverture d'un fichier MED pour une utilisation parallèle.
Definition: MEDparFileOpen.c:49
filename
#define filename
Definition: test10.c:72
MED_ACC_CREAT
Definition: med.h:123
_MEDcheckVersion30
MEDC_EXPORT med_err _MEDcheckVersion30(med_idt fid)
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
med_outils.h
med_config.h
MED_ACC_RDEXT
Definition: med.h:122
MED_ERR_RANGE
#define MED_ERR_RANGE
Definition: med_err.h:34
MED_ERR_PARAMETER
#define MED_ERR_PARAMETER
Definition: med_err.h:103
_MEDmodeErreurVerrouiller
MEDC_EXPORT void _MEDmodeErreurVerrouiller(void)