MED fichier
test3.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2017 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 : test3.c
21  *
22  * - Description : lecture des informations sur les maillages d'un fichier MED.
23  *
24  *****************************************************************************/
25 
26 #include <med.h>
27 #define MESGERR 1
28 #include "med_utils.h"
29 #include <string.h>
30 
31 #ifdef DEF_LECT_ECR
32 #define MODE_ACCES MED_ACC_RDWR
33 #elif DEF_LECT_AJOUT
34 #define MODE_ACCES MED_ACC_RDEXT
35 #else
36 #define MODE_ACCES MED_ACC_CREAT
37 #endif
38 
39 
40 #define OBJEXIST(oname)\
41  if ( MEDfileObjectExist(fid,MED_MESH, #oname ,& oname##exist) < 0) { \
42  MESSAGE("Erreur de test de présence du maillage "#oname); \
43  return -1; \
44  } \
45  if ( oname##exist) { MESSAGE("Le maillage "#oname" existe."); } else \
46  { MESSAGE("Le maillage "#oname" n'existe pas.");}
47 
48 
49 int main (int argc, char **argv)
50 
51 
52 {
53  med_err ret = 0;
54  med_idt fid = 0;
55  med_int nmaa=0,mdim=0,sdim=0,nstep=0;
56  int i=0;
57  /*Pour les outils de type memchecker */
58 /* char maa[MED_NAME_SIZE+1]=""; */
59 /* char nomu[MED_LNAME_SIZE+1]=""; */
60 /* char des [MED_COMMENT_SIZE+1]=""; */
61 /* char dtunit[MED_SNAME_SIZE+1]=""; */
62  char *maa ;
63  char *nomu ;
64  char *des ;
65  char *dtunit;
66  char *axisname=0,*axisunit=0;
67  med_mesh_type meshtype;
68  med_err inomu;
69  med_sorting_type sortingtype;
70  med_axis_type axistype;
71  med_bool maa1exist=MED_FALSE,maa2exist=MED_FALSE;
72  med_bool maa3exist=MED_FALSE,maa4exist=MED_FALSE;
73 
74  /*Pour les outils de type memchecker */
75  maa = (char *) malloc(sizeof(char)*(MED_NAME_SIZE+1 ));
76  nomu = (char *) malloc(sizeof(char)*(MED_LNAME_SIZE+1 ));
77  des = (char *) malloc(sizeof(char)*(MED_COMMENT_SIZE+1));
78  dtunit = (char *) malloc(sizeof(char)*(MED_SNAME_SIZE+1 ));
79 
80  /* Ouverture du fichier "test2.med" en lecture seule */
81  fid = MEDfileOpen("test2.med",MED_ACC_RDONLY);
82  if (fid < 0) {
83  MESSAGE("Erreur a l'ouverture du fichier test2.med");
84  return -1;
85  }
86 
87  /* Teste la présence des maillages */
88  OBJEXIST(maa1); OBJEXIST(maa2); OBJEXIST(maa3); OBJEXIST(maa4);
89 
90  /* Lecture du nombre de maillage dans le fichier */
91  nmaa = MEDnMesh(fid);
92  if (nmaa < 0) {
93  MESSAGE("Erreur a la lecture du nombre de maillage");
94  return -1;
95  }
96 
97 
98  /* Boucle sur tous les maillages, pour chaque maillage, on lit :
99  - Le nom.
100  - Le type
101  - La dimension
102  - La description
103  - La dimension de l'espace si elle existe
104  - Le nom universel s'il existe
105  */
106  printf("- Nombre de maillage dans test2.med = "IFORMAT"\n",nmaa);
107 
108  for (i=0;i< nmaa;i++) {
109  /* lecture des informations */
110 
111  if ((sdim=MEDmeshnAxis(fid, i+1)) <0) {
112  MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :");
113  SSCRUTE(maa);
114  ret = -1;
115  }
116  axisname = (char*) malloc(MED_SNAME_SIZE*sdim+1);
117  axisunit = (char*) malloc(MED_SNAME_SIZE*sdim+1);
118 
119  if (MEDmeshInfo(fid,i+1, maa, &sdim, &mdim, &meshtype, des, dtunit, &sortingtype, &nstep,
120  &axistype, axisname, axisunit) < 0) {
121  MESSAGE("Erreur a la lecture des informations du maillage :"); SSCRUTE(maa);
122  ret = -1;
123  }
124  /* lecture du nom universel */
125  inomu = MEDmeshUniversalNameRd(fid,maa,nomu);
126  /* affichage des donnees lues */
127  if (inomu < 0)
128  printf("maillage %d de nom %s, de dimension "IFORMAT" \n",i+1,maa,mdim);
129  else
130  printf("maillage %d de nom %s, de dimension "IFORMAT" et de nom univ. %s\n",i+1,maa,mdim,nomu);
131 
132  printf("La dimension de l'espace est "IFORMAT" \n",sdim);
133  if (meshtype == MED_STRUCTURED_MESH)
134  printf("Il s'agit d'un maillage structure \n");
135  else
136  printf("Il s'agit d'un maillage non structure \n");
137  printf("Description associee au maillage : %s \n\n",des);
138  printf("\t -Noms des axes : %s\n", axisname);
139  printf("\t -Unités des axes : %s\n",axisunit);
140  printf("\t -Type de repère : %d\n", axistype);
141  printf("\t -Nombre d'étape de calcul : "IFORMAT"\n",nstep);
142  printf("\t -Unité des dates : %s\n",dtunit);
143 
144  free(axisname);
145  free(axisunit);
146  }
147 
148  free( maa );
149  free( nomu );
150  free( des );
151  free( dtunit );
152 
153 
154  /* Fermeture du fichier */
155  if ( MEDfileClose(fid) < 0) {
156  MESSAGE("Erreur a la fermeture du fichier test2.med");
157  return -1;
158  }
159 
160  return ret;
161 }
162 
163 
164 
165 
int med_int
Definition: med.h:335
#define MED_LNAME_SIZE
Definition: med.h:79
#define MED_SNAME_SIZE
Definition: med.h:78
MEDC_EXPORT med_err MEDmeshInfo(const med_idt fid, const int meshit, char *const meshname, med_int *const spacedim, med_int *const meshdim, med_mesh_type *const meshtype, char *const description, char *const dtunit, med_sorting_type *const sortingtype, med_int *const nstep, med_axis_type *const axistype, char *const axisname, char *const axisunit)
Cette routine permet de lire les informations relatives à un maillage dans un fichier.
Definition: MEDmeshInfo.c:43
hid_t med_idt
Definition: med.h:324
#define MED_NAME_SIZE
Definition: med.h:77
med_sorting_type
Definition: med.h:304
#define MED_COMMENT_SIZE
Definition: med.h:75
int main(int argc, char **argv)
Definition: test3.c:49
Definition: med.h:255
herr_t med_err
Definition: med.h:325
med_axis_type
Definition: med.h:253
med_mesh_type
Definition: med.h:127
#define SSCRUTE(chaine)
Definition: med_utils.h:315
MEDC_EXPORT med_int MEDnMesh(const med_idt fid)
Cette routine permet de lire le nombre de maillages dans un fichier.
Definition: MEDnMesh.c:34
MEDC_EXPORT med_err MEDmeshUniversalNameRd(const med_idt fid, const char *const meshname, char *const univname)
Cette routine permet la lecture du nom universel d&#39;un maillage.
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d&#39;un fichier MED.
Definition: MEDfileOpen.c:41
#define OBJEXIST(oname)
Definition: test3.c:40
med_bool
Definition: med.h:255
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d&#39;un fichier MED.
Definition: MEDfileClose.c:30
#define MESSAGE(chaine)
Definition: med_utils.h:316
#define IFORMAT
Definition: med_utils.h:144
MEDC_EXPORT med_int MEDmeshnAxis(const med_idt fid, const int meshit)
Cette routine permet de lire dans un maillage le nombre d&#39;axes du repère des coordonnées des noeuds...
Definition: MEDmeshnAxis.c:35