MED fichier
test2.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  * - Nom du fichier : test2.c
20  *
21  * - Description : exemples de creation de maillages MED.
22  *
23  *****************************************************************************/
24 
25 #include <med.h>
26 #define MESGERR 1
27 #include <med_utils.h>
28 #include <string.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  med_err ret=0;
42  med_idt fid=0;
43  char des[MED_COMMENT_SIZE+1]="";
44  med_bool hdfok=MED_FALSE, medok=MED_FALSE;
45  med_bool fileexist=MED_FALSE, accessok=MED_FALSE;
46  char axisname[3*MED_SNAME_SIZE+1]="";
47  char axisunit[3*MED_SNAME_SIZE+1]="";
48  int cstp = 0;
49 
50  strcat(axisname,"x ");
51  strcat(axisname,"y ");
52  strcat(axisname,"z ");
53  strcat(axisunit,"cm ");
54  strcat(axisunit,"cm ");
55  strcat(axisunit,"cm ");
56 
57  /* Verification de la conformite du format med du fichier test1.med */
58  MEDfileExist( "test1.med", MED_ACC_RDONLY, &fileexist, &accessok );
59  if (!fileexist) {
60  MESSAGE("Le fichier test1.med n'existe pas.");
61  }
62  if (!accessok) {
63  MESSAGE("Le fichier test1.med ne peut pas être ouvert selon le mode d'accès demandé .");
64  }
65 
66  /* Verification de la conformite du format med du fichier test1.med */
67  ret = MEDfileCompatibility("test1.med",&hdfok,&medok);
68  if (!hdfok) {
69  MESSAGE("Format HDF non conforme ou fichier inexistant");
70  return -1;
71  }
72  if (!medok) {
73  MESSAGE("Format MED non conforme ou fichier inexistant");
74  return -1;
75  }
76 
77 /* Ouverture en mode de lecture du fichier "test1.med" */
78  fid = MEDfileOpen("test1.med",MED_ACC_RDONLY);
79  if (fid < 0) {
80  MESSAGE("Erreur a l'ouverture du fichier test1.med en mode MED_LECTURE");
81  return -1;
82  }
83 
84 /* Affiche de l'en-tete du fichier */
85  ret = MEDfileCommentRd(fid, des);
86  if (ret == 0)
87  printf("En-tete du fichier test1.med : %s\n",des);
88  else {
89  MESSAGE("Erreur a la lecture de l'en-tete du fichier test1.med");
90  ret = -1;
91  }
92 
93 /* Fermeture du fichier test1.med */
94  ret = MEDfileClose(fid);
95  if (ret < 0) {
96  MESSAGE("Erreur a la fermeture du fichier test1.med");
97  return -1;
98  }
99 
100  /* Verification de la conformite du format med du fichier test2.med */
101  MEDfileExist( "test2.med", MODE_ACCES, &fileexist, &accessok );
102  if (!fileexist) {
103  MESSAGE("Le fichier test2.med n'existe pas.");
104  }
105  if (!accessok) {
106  MESSAGE("Le fichier test2.med ne peut pas être ouvert selon le mode d'accès demandé .");
107  }
108  /* Ouverture en mode creation du fichier test2.med */
109  fid = MEDfileOpen("test2.med",MODE_ACCES);
110  if (fid < 0) {
111  MESSAGE("Erreur a la creation du fichier test2.med");
112  return -1;
113  }
114 
115  /* Creation du maillage "maa1" de type MED_UNSTRUCTURED_MESH
116  et de dimension 3 */
117  if (MEDmeshCr(fid,"maa1",3,3,MED_UNSTRUCTURED_MESH,
118  "un premier maillage","s",MED_SORT_DTIT,
119  MED_CARTESIAN,axisname,axisunit) < 0) {
120  MESSAGE("Erreur a la creation du maillage maa1");
121  ret = -1;
122  }
123 
124  /* Ecriture du nom universel pour "maa1" */
125  if (MEDmeshUniversalNameWr(fid,"maa1") < 0) {
126  MESSAGE("Erreur a la creation du nom universel de maa1");
127  ret = -1;
128  }
129 
130  /* Creation du maillage "maa2" de type MED_UNSTRUCTURED_MESH
131  et de dimension 2 dans un espace de dimension 3*/
132  if (MEDmeshCr(fid,"maa2",3,2,MED_UNSTRUCTURED_MESH,
133  "un second maillage","s",MED_SORT_DTIT,
134  MED_CARTESIAN,axisname,axisunit) < 0) {
135  MESSAGE("Erreur a la creation du maillage maa2");
136  ret = -1;
137  }
138 
139  cstp = 1;
141  MED_NO_DT,MED_NO_IT,0) < 0) {
142  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
143 /* ret = -1; */
144  }
145 
146  cstp++;
148  1,3,1.1) < 0) {
149  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
150 /* ret = -1; */
151  }
152 
153  cstp++;
155  0,0,1.1) < 0) {
156  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
157 /* ret = -1; */
158  }
159 
160  cstp++;
162  0,-1,1.1) < 0) {
163  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
164 /* ret = -1; */
165  }
166 
167  cstp++;
169  -1,20,1.1) < 0) {
170  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
171 /* ret = -1; */
172  }
173 
174  cstp++;
175  fprintf(stderr,"Erreur attendue : \n");
177  20,-1,1.1) < 0) {
178  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
179 /* ret = -1; */
180  }
181 
182  cstp++;
183  fprintf(stderr,"Erreur attendue : \n");
184  if ( MEDmeshComputationStepCr(fid,"maa2",0,0,
185  20,-1,1.1) < 0) {
186  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
187 /* ret = -1; */
188  }
189 
190  cstp++;
191  if ( MEDmeshComputationStepCr(fid,"maa2",20,-1,
192  20,-1,1.1) < 0) {
193  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
194 /* ret = -1; */
195  }
196 
197  cstp++;
198  fprintf(stderr,"Erreur attendue car l'étape a été crée précedement: \n");
199  if ( MEDmeshComputationStepCr(fid,"maa2",1,3,
200  20,-1,1.1) < 0) {
201  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
202 /* ret = -1; */
203  }
204 
205  cstp++;
206  if ( MEDmeshComputationStepCr(fid,"maa2",20,-1,
207  20,10,1.1) < 0) {
208  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
209 /* ret = -1; */
210  }
211 
212  cstp++;
213  fprintf(stderr,"Erreur attendue car cette étape ne se place pas en dernière position : \n");
214  if ( MEDmeshComputationStepCr(fid,"maa2",20,5,
215  20,5,1.1) < 0) {
216  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
217 /* ret = -1; */
218  }
219 
220  cstp++;
221  fprintf(stderr,"Erreur attendue car la création de cette étape chevauche la (20,10) : \n");
222  if ( MEDmeshComputationStepCr(fid,"maa2",20,-1,
223  20,20,1.1) < 0) {
224  fprintf(stderr,"Erreur à la création de l'étape de calcul n°%d du maillage maa2\n",cstp);
225 /* ret = -1; */
226  }
227 
228 
229  /* Creation du maillage "maa3" de type MED_UNSTRUCTURED_MESH
230  et de dimension 1 un espace de dimension 3*/
231  if (MEDmeshCr(fid,"maa3",3,1,MED_UNSTRUCTURED_MESH,
232  "un troisieme maillage","s",MED_SORT_DTIT,
233  MED_CARTESIAN,axisname,axisunit) < 0) {
234  MESSAGE("Erreur a la creation du maillage maa3");
235  ret = -1;
236  }
237 
238  /* Fermeture du fichier */
239  if ( MEDfileClose(fid) < 0) {
240  MESSAGE("Erreur a la fermeture du fichier");
241  return -1;
242  }
243 
244  return ret;
245 }
246 
247 
248 
249 
MED_ACC_RDONLY
Definition: med.h:122
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition: med.h:81
MEDmeshComputationStepCr
MEDC_EXPORT med_err MEDmeshComputationStepCr(const med_idt fid, const char *const meshname, const med_int numdt1, const med_int numit1, const med_int numdt2, const med_int numit2, const med_float dt2)
Cette routine permet de créer une nouvelle étape de calcul dans un maillage.
Definition: MEDmeshComputationStepCr.c:40
MED_UNSTRUCTURED_MESH
Definition: med.h:133
MEDfileCommentRd
MEDC_EXPORT med_err MEDfileCommentRd(const med_idt fid, char *const comment)
Lecture d'un descripteur dans un fichier MED.
Definition: MEDfileCommentRd.c:33
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:84
MEDfileExist
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è...
Definition: MEDfileExist.c:51
med_idt
hid_t med_idt
Definition: med.h:333
MED_FALSE
Definition: med.h:262
med_err
herr_t med_err
Definition: med.h:334
main
int main(int argc, char **argv)
Definition: test2.c:37
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
MED_SORT_DTIT
Definition: med.h:311
med_bool
med_bool
Definition: med.h:262
MEDmeshUniversalNameWr
MEDC_EXPORT med_err MEDmeshUniversalNameWr(const med_idt fid, const char *const meshname)
Cette routine permet l'écriture du nom universel d'un maillage.
Definition: MEDmeshUniversalNameWr.c:63
MED_NO_DT
#define MED_NO_DT
Definition: med.h:322
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MODE_ACCES
#define MODE_ACCES
Definition: test2.c:34
MEDmeshCr
MEDC_EXPORT med_err MEDmeshCr(const med_idt fid, const char *const meshname, const med_int spacedim, const med_int meshdim, const med_mesh_type meshtype, const char *const description, const char *const dtunit, const med_sorting_type sortingtype, const med_axis_type axistype, const char *const axisname, const char *const axisunit)
Cette routine permet de créer un maillage dans un fichier.
Definition: MEDmeshCr.c:45
MED_CARTESIAN
Definition: med.h:260
med_utils.h
med.h
MED_NO_IT
#define MED_NO_IT
Definition: med.h:323
MEDfileCompatibility
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.
Definition: MEDfileCompatibility.c:34
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:42