MED fichier
test3.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 : 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
49int 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 ret = -1;
114 }
115 axisname = (char*) malloc(MED_SNAME_SIZE*sdim+1);
116 axisunit = (char*) malloc(MED_SNAME_SIZE*sdim+1);
117
118 if (MEDmeshInfo(fid,i+1, maa, &sdim, &mdim, &meshtype, des, dtunit, &sortingtype, &nstep,
119 &axistype, axisname, axisunit) < 0) {
120 MESSAGE("Erreur a la lecture des informations du maillage :"); SSCRUTE(maa);
121 ret = -1;
122 }
123 /* lecture du nom universel */
124 inomu = MEDmeshUniversalNameRd(fid,maa,nomu);
125 /* affichage des donnees lues */
126 if (inomu < 0)
127 printf("maillage %d de nom %s, de dimension "IFORMAT" \n",i+1,maa,mdim);
128 else
129 printf("maillage %d de nom %s, de dimension "IFORMAT" et de nom univ. %s\n",i+1,maa,mdim,nomu);
130
131 printf("La dimension de l'espace est "IFORMAT" \n",sdim);
132 if (meshtype == MED_STRUCTURED_MESH)
133 printf("Il s'agit d'un maillage structure \n");
134 else
135 printf("Il s'agit d'un maillage non structure \n");
136 printf("Description associee au maillage : %s \n\n",des);
137 printf("\t -Noms des axes : %s\n", axisname);
138 printf("\t -Unités des axes : %s\n",axisunit);
139 printf("\t -Type de repère : %d\n", axistype);
140 printf("\t -Nombre d'étape de calcul : "IFORMAT"\n",nstep);
141 printf("\t -Unité des dates : %s\n",dtunit);
142
143 free(axisname);
144 free(axisunit);
145 }
146
147 free( maa );
148 free( nomu );
149 free( des );
150 free( dtunit );
151
152
153 /* Fermeture du fichier */
154 if ( MEDfileClose(fid) < 0) {
155 MESSAGE("Erreur a la fermeture du fichier test2.med");
156 return -1;
157 }
158
159 return ret;
160}
161
162
163
164
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_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 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
MEDC_EXPORT med_int MEDmeshnAxis(const med_idt fid, const int meshit)
Cette routine permet de lire dans un maillage le nombre d'axes du repère des coordonnées des noeuds.
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'un maillage.
#define MED_NAME_SIZE
Definition med.h:81
#define MED_LNAME_SIZE
Definition med.h:83
#define MED_SNAME_SIZE
Definition med.h:82
med_bool
Definition med.h:260
@ MED_FALSE
Definition med.h:260
med_axis_type
Definition med.h:258
med_sorting_type
Definition med.h:300
med_mesh_type
Definition med.h:131
@ MED_STRUCTURED_MESH
Definition med.h:131
int med_int
Definition med.h:333
#define MED_COMMENT_SIZE
Definition med.h:79
herr_t med_err
Definition med.h:323
@ MED_ACC_RDONLY
Definition med.h:120
hid_t med_idt
Definition med.h:322
#define SSCRUTE(chaine)
Definition med_utils.h:323
#define MESSAGE(chaine)
Definition med_utils.h:324
#define IFORMAT
Definition med_utils.h:145
#define OBJEXIST(oname)
Definition test3.c:40
int main(int argc, char **argv)
Definition test3.c:49