MED fichier
test21.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/******************************************************************************
20 * - Nom du fichier : test21.c
21 *
22 * - Description : ecriture de valeurs scalaires numeriques dans un fichier MED
23 *
24 *****************************************************************************/
25
26#include <med.h>
27#define MESGERR 1
28#include <med_utils.h>
29
30#ifdef DEF_LECT_ECR
31#define MODE_ACCES MED_ACC_RDWR
32#elif DEF_LECT_AJOUT
33#define MODE_ACCES MED_ACC_RDEXT
34#else
35#define MODE_ACCES MED_ACC_CREAT
36#endif
37
38int main (int argc, char **argv)
39
40
41{
42 med_err ret;
43 med_idt fid;
44 char nom_scalaire1[MED_NAME_SIZE+1] = "VariableEntiere";
45 char description1[MED_COMMENT_SIZE+1] = "Une premiere description";
46 char nom_scalaire2[MED_NAME_SIZE+1] = "VariableFlottante";
47 char description2[MED_COMMENT_SIZE+1] = "Une seconde description";
48 med_int vali1 = 56;
49 med_int vali2 = -789;
50 med_float valr1 = 67.98;
51
52 /* Creation du fichier test21.med */
53 if ((fid = MEDfileOpen("test21.med",MODE_ACCES)) < 0) {
54 MESSAGE("Erreur a la creation du fichier test21.med");
55 return -1;
56 }
57
58 /* Creation d'un variable scalaire entiere */
59 if (MEDparameterCr(fid,nom_scalaire1,MED_INT,description1,"ms") < 0) {
60 MESSAGE("Erreur a la creation d'une variable scalaire enti�re");
61 return -1;
62 }
63 printf("Creation d'une variable scalaire entiere \n");
64
65 /* Ecriture d'un valeur sans pas de temps et sans numero d'ordre*/
66 if (MEDparameterValueWr(fid,nom_scalaire1,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT,(unsigned char*) &vali1) < 0) {
67 MESSAGE("Erreur a l'ecriture d'une valeur entiere");
68 return -1;
69 }
70 printf("Ecriture d'une valeur entiere sans pas de temps \n");
71
72 /* Ecriture d'une valeur entiere avec 1 pas de temps et sans numero d'ordre */
73 if (MEDparameterValueWr(fid,nom_scalaire1,1,MED_NO_IT,5.5,(unsigned char*) &vali2) < 0) {
74 MESSAGE("Erreur a l'ecriture d'une valeur entiere");
75 return -1;
76 }
77 printf("Ecriture d'une valeur entiere avec pas de temps \n");
78
79 /* Creation d'un variable scalaire flottante */
80 if (MEDparameterCr(fid,nom_scalaire2,MED_FLOAT64,description2,"ms") < 0) {
81 MESSAGE("Erreur a la creation d'une variable scalaire flottante");
82 return -1;
83 }
84 printf("Creation d'une variable scalaire flottante \n");
85
86 /* Ecriture d'une valeur reelle avec 1 pas de temps et 1 numero d'ordre */
87 if (MEDparameterValueWr(fid, nom_scalaire2, 1, 2, 5.5, (unsigned char*) &valr1) < 0) {
88 MESSAGE("Erreur a l'ecriture d'une valeur flottante");
89 return -1;
90 }
91 printf("Ecriture d'une valeur reelle avec pas de temps et numero d'ordre \n");
92
93 /* Fermeture du fichier */
94 if (MEDfileClose(fid) < 0) {
95 MESSAGE("Erreur a la fermeture du fichier");
96 return -1;
97 }
98
99 return 0;
100}
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 MEDparameterCr(const med_idt fid, const char *const paramname, const med_parameter_type paramtype, const char *const description, const char *const dtunit)
Cette routine permet la création d'un paramètre numérique scalaire.
MEDC_EXPORT med_err MEDparameterValueWr(const med_idt fid, const char *const paramname, const med_int numdt, const med_int numit, const med_float dt, const unsigned char *const value)
Cette routine permet l'écriture de la valeur d'un paramètre numérique scalaire.
#define MED_NAME_SIZE
Definition med.h:81
@ MED_INT
Definition med.h:170
@ MED_FLOAT64
Definition med.h:166
#define MED_UNDEF_DT
Definition med.h:313
int med_int
Definition med.h:333
#define MED_NO_DT
Definition med.h:311
#define MED_NO_IT
Definition med.h:312
double med_float
Definition med.h:327
#define MED_COMMENT_SIZE
Definition med.h:79
herr_t med_err
Definition med.h:323
hid_t med_idt
Definition med.h:322
#define MESSAGE(chaine)
Definition med_utils.h:324
#define MODE_ACCES
Definition test21.c:35
int main(int argc, char **argv)
Definition test21.c:38