MED fichier
medconforme.c
Aller à la documentation de ce fichier.
1/* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2020 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_utils.h>
22#include <stdlib.h>
23
24
25
26int main(int argc, char *argv[]) {
27 med_idt fid =0;
28 med_int majeur =0, mineur=0, release=0;
29 med_err ret =-1;
30 med_bool hdfok =MED_FALSE;
31 med_bool medok =MED_FALSE;
32 med_bool fileexist =MED_FALSE;
33 med_bool accessok =MED_FALSE;
34
35 if (argc != 2) {
36 fprintf(stdout,">> Utilisation : medconforme <nom_de_fichier_med> \n");
37 return 0;
38 }
39
40 /*
41 * Quelle version de la bibliotheque MED est utilisee ?
42 */
43 ret=MEDlibraryNumVersion(&majeur, &mineur, &release);
44 EXIT_IF( ret<0 , "Erreur d'appel de la routine MEDlibraryNumVersion.", NULL);
45 fprintf(stdout,"- Version de MED-fichier utilisée par medconforme : "IFORMAT"."IFORMAT"."IFORMAT" \n",majeur,mineur,release);
46
47 /*
48 * Le fichier à lire est-il accessible ?
49 */
50 ret = MEDfileExist(argv[1],MED_ACC_RDONLY,&fileexist,&accessok );
51 MED_ERR_EXIT_IF(ret < 0 , MED_ERR_CALL,MED_ERR_API,"MEDfileExist");
52 if ( !fileexist ) { fprintf(stdout,"- Le fichier [%s] n'existe pas \n",argv[1]); goto SORTIE; }
53 if ( !accessok ) { fprintf(stdout,"- Le fichier [%s] n'est pas accessible en lecture \n",argv[1]); goto SORTIE; }
54
55 /*
56 * Le fichier à lire est-il au bon format de fichier HDF ?
57 */
58 ret=MEDfileCompatibility(argv[1],&hdfok,&medok);
59 MED_ERR_EXIT_IF(ret < 0 , MED_ERR_CALL,MED_ERR_API,"MEDfileCompatibility");
60 if ( hdfok ) fprintf(stdout,"- Format HDF du fichier MED [%s] conforme au format HDF utilisé par la bibliothèque \n",argv[1]);
61 else { fprintf(stdout,"- Format HDF du fichier MED [%s] non conforme au format HDF utilisé par la bibliothèque \n",argv[1]); goto SORTIE; }
62
63 /*
64 * Le fichier à lire a-t-il été créé avec une version de la bilbiothèque MED conforme avec celle utilisée ?
65 * (Numéros majeur identique et mineur de la bibliothèque supérieur à celui du fichier).
66 */
67 if ( medok ) {
68 fprintf(stdout,"- Version MED du fichier [%s] conforme a la bibliothèque MED utilisée \n",argv[1]);
69
70 if ((fid = MEDfileOpen(argv[1],MED_ACC_RDONLY)) < 0) {
72 goto ERROR;
73 }
74
75 /*
76 * Une fois le fichier ouvert on peut avoir acces au numero de version complet
77 */
78 if ( MEDfileNumVersionRd(fid, &majeur, &mineur, &release) < 0 ) {
79 MED_ERR_(ret,MED_ERR_CALL,MED_ERR_API,"MEDfileNumVersionRd");
80 goto ERROR;
81 }
82 fprintf(stdout,"- Ce fichier a ete créé avec MED-fichier V"IFORMAT"."IFORMAT"."IFORMAT" \n",majeur,mineur,release);
83
84 }
85 else
86 fprintf(stdout,"- Version MED du fichier [%s] non conforme avec celle de la bibliothèque utilisée \n",argv[1]);
87
88 SORTIE:
89 ret = 0;
90 ERROR:
91
92 if (fid > 0)
93 if (MEDfileClose(fid) < 0) {
95 ret = -1;
96 }
97
98 return ret;
99}
#define MED_ERR_(rt, r1, r2, r3)
#define EXIT_IF(expression, message, arg)
#define MED_ERR_EXIT_IF(expression, r1, r2, arg)
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition MEDfileOpen.c:42
MEDC_EXPORT med_err MEDfileCompatibility(const char *const filename, med_bool *const hdfok, med_bool *const medok)
Vérification de la compatibilité d'un fichier avec HDF et MED.
MEDC_EXPORT med_err MEDfileExist(const char *const filename, const med_access_mode accessmode, med_bool *const fileexist, med_bool *const accessok)
Interroge l'existence d'un fichier de nom filename et la possibilité de l'ouvrir selon le mode d'accè...
MEDC_EXPORT med_err MEDfileNumVersionRd(const med_idt fid, med_int *const major, med_int *const minor, med_int *const release)
Lecture du numéro de version de la bibliothèque MED utilisée pour créer le fichier.
MEDC_EXPORT med_err MEDlibraryNumVersion(med_int *const major, med_int *const minor, med_int *const release)
Renvoie les 3 numéros de version de la librairie MED.
#define MED_ERR_OPEN
Definition med_err.h:37
#define MED_ERR_CALL
Definition med_err.h:48
#define MED_ERR_CLOSE
Definition med_err.h:30
#define MED_ERR_FILE
Definition med_err.h:82
#define MED_ERR_API
Definition med_err.h:111
int main(int argc, char *argv[])
Definition medconforme.c:26