MED fichier
test21.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2023 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 
38 int 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 }
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition: med.h:81
med_idt
hid_t med_idt
Definition: med.h:333
med_err
herr_t med_err
Definition: med.h:334
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:344
med_float
double med_float
Definition: med.h:338
MED_NO_DT
#define MED_NO_DT
Definition: med.h:322
main
int main(int argc, char **argv)
Definition: test21.c:37
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_INT
Definition: med.h:172
MED_FLOAT64
Definition: med.h:168
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:83
med_utils.h
MODE_ACCES
#define MODE_ACCES
Definition: test21.c:34
MED_UNDEF_DT
#define MED_UNDEF_DT
Definition: med.h:324
med.h
MEDparameterCr
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.
Definition: MEDparameterCr.c:38
MED_NO_IT
#define MED_NO_IT
Definition: med.h:323
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:42
MEDparameterValueWr
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.
Definition: MEDparameterValueWr.c:39