MED fichier

test7.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2021 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 : test7.c
20 *
21 * - Description : lecture des elements du maillage MED crees par test6
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 {
42 med_err ret = 0;
43 med_idt fid;
44 med_int nse2;
45 med_int *se2_1;
46 med_int *se2_2;
47 char *nomse2;
48 med_int *numse2;
49 med_int *nufase2;
50 med_int ntr3;
51 med_int *tr3;
52 char *nomtr3;
53 med_int *numtr3;
54 med_int *nufatr3;
55 char maa[MED_NAME_SIZE+1] ="maa1";
56 med_int mdim=0,sdim=0;
57 med_bool inoele=MED_FALSE,inuele=MED_FALSE,chgt=MED_FALSE,trsf=MED_FALSE;
58 med_bool inoele3=MED_FALSE,inuele3=MED_FALSE;
59 med_int tse2,ttr3;
60 char str[MED_SNAME_SIZE+1];
61 med_int flt[2] = { 2, 3 }, fltsize=2;
62 char desc[MED_COMMENT_SIZE+1];
63 char dtunit[MED_SNAME_SIZE+1]="";
64 char nomcoo[2*MED_SNAME_SIZE+1];
65 char unicoo[2*MED_SNAME_SIZE+1];
66 med_mesh_type type;
67 med_sorting_type sort;
68 med_int nstep=0,i=0;
69 med_filter filter=MED_FILTER_INIT;
70 med_axis_type rep;
71 med_int nname=0;
72
73 /* Ouverture du fichier en mode lecture seule */
74 if ((fid = MEDfileOpen("test6.med",MED_ACC_RDONLY)) < 0) {
75 MESSAGE("Erreur a l'ouverture du fichier test6.med");
76 return -1;
77 }
78 if ((sdim=MEDmeshnAxis(fid, 1)) <0) {
79 MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :");
80 SSCRUTE(maa);
81 return -1;
82 }
83
84 /* Lecture des infos concernant le premier maillage */
85 if ( MEDmeshInfo( fid, 1, maa, &sdim, &mdim, &type, desc, dtunit, &sort,
86 &nstep, &rep, nomcoo,unicoo) < 0 ) {
87 MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
88 return -1;
89 } else {
90 printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,type);
91 printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
92 printf("\t -Description du maillage : %s\n",desc);
93 printf("\t -Noms des axes : |%s|\n",nomcoo);
94 printf("\t -Unités des axes : |%s|\n",unicoo);
95 printf("\t -Type de repère : %d\n",rep);
96 printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep);
97 printf("\t -Unité des dates : |%s|\n",dtunit);
98 }
99
100 /* Combien de triangles et de segments */
101 if ((nse2 = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
102 MED_DESCENDING_EDGE, MED_SEG2,MED_CONNECTIVITY, MED_DESCENDING,
103 &chgt, &trsf)) < 0) {
104 MESSAGE("Erreur a la lecture du nombre de faces MED_SEG2");
105 return -1;
106 }
107
108 if ((ntr3 = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
109 MED_CELL,MED_TRIA3,MED_CONNECTIVITY, MED_DESCENDING,
110 &chgt, &trsf))<0) {
111 MESSAGE("Erreur a la lecture du nombre de mailles MED_TRIA3");
112 return -1;
113 }
114 printf("Nombre de MED_SEG2 : "IFORMAT" - nombre de MED_TRIA3 : "IFORMAT"\n",nse2,ntr3);
115
116
117 /* Allocations memoire */
118 tse2 = 2;
119 se2_1 = (med_int*) calloc(tse2*nse2,sizeof(med_int));
120 se2_2 = (med_int*) malloc(sizeof(med_int)*tse2*nse2);
121 nomse2 = (char*) malloc(MED_SNAME_SIZE*nse2+1);
122 numse2 = (med_int*) malloc(sizeof(med_int)*nse2);
123 nufase2 = (med_int*) malloc(sizeof(med_int)*nse2);
124
125 ttr3 = 3;
126 tr3 = (med_int*) malloc(sizeof(med_int)*ntr3*ttr3);
127 nomtr3 = (char*) malloc(MED_SNAME_SIZE*ntr3+1);
128 numtr3 = (med_int*) malloc(sizeof(med_int)*ntr3);
129 nufatr3 = (med_int*) malloc(sizeof(med_int)*ntr3);
130
131 if ( MEDfilterEntityCr( fid, nse2, 1, sdim, 2,
132 MED_FULL_INTERLACE, MED_GLOBAL_STMODE,
133 MED_NO_PROFILE, fltsize,
134 flt, &filter) < 0 ) {
135 MESSAGE("Erreur à la crétion du filtre 1.");
136 }
137
138
139 /* Lecture des connectivites des segments avec flt */
140 if (MEDmeshElementConnectivityAdvancedRd(fid, maa, MED_NO_DT, MED_NO_IT,
141 MED_DESCENDING_EDGE, MED_SEG2, MED_DESCENDING, &filter,
142 se2_1) < 0) {
143 MESSAGE("Erreur a la lecture de la connectivite des segments");
144 return -1;
145 }
146
147 MEDfilterClose(&filter);
148
149 /* Lecture de la connectivite des segments */
150 if (MEDmeshElementConnectivityRd(fid, maa, MED_NO_DT, MED_NO_IT,
151 MED_DESCENDING_EDGE, MED_SEG2, MED_DESCENDING,
152 MED_FULL_INTERLACE, se2_2) < 0) {
153 MESSAGE("Erreur a la lecture de la connectivite des segments");
154 return -1;
155 }
156
157 /* Lecture (optionnelle) des noms des segments */
158 if (MEDmeshEntityNameRd(fid, maa, MED_NO_DT, MED_NO_IT,
159 MED_DESCENDING_EDGE, MED_SEG2,nomse2) < 0)
160 inoele = MED_FALSE;
161 else
162 inoele = MED_TRUE;
163
164 /* Test complémentaire */
165 if ((nname = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
166 MED_DESCENDING_EDGE,MED_SEG2,MED_NAME, MED_NO_CMODE,
167 &chgt, &trsf))<0) {
168 MESSAGE("Erreur a la lecture du nombre de nom de mailles MED_SEG2");
169 return -1;
170 }
171 printf("Nombre de nom de MED_SEG2 : "IFORMAT" \n",nname);
172
173 /* Lecture (optionnelle) des numeros des segments */
174 if ( MEDmeshEntityNumberRd(fid, maa, MED_NO_DT, MED_NO_IT,
175 MED_DESCENDING_EDGE, MED_SEG2, numse2) < 0)
176 inuele = MED_FALSE;
177 else
178 inuele = MED_TRUE;
179
180 /* Lecture des numeros des familles des segments */
181 if (MEDmeshEntityFamilyNumberRd(fid,maa, MED_NO_DT, MED_NO_IT,
182 MED_DESCENDING_EDGE, MED_SEG2,nufase2) < 0) {
183 MESSAGE("Erreur a la lecture des numéros de famille des segments");
184 return -1;
185 }
186
187 /* Lecture de la connectivite des triangles */
188 if (MEDmeshElementConnectivityRd(fid, maa, MED_NO_DT, MED_NO_IT,
189 MED_CELL, MED_TRIA3, MED_DESCENDING,
190 MED_FULL_INTERLACE, tr3) < 0) {
191 MESSAGE("Erreur a la lecture de la connectivite des triangles");
192 return -1;
193 }
194
195 /* Lecture (optionnelle) des noms des triangles */
196 if (MEDmeshEntityNameRd(fid, maa, MED_NO_DT, MED_NO_IT,
197 MED_CELL, MED_TRIA3, nomtr3) < 0)
198 inoele3 = MED_FALSE;
199 else
200 inoele3 = MED_TRUE;
201
202 /* Lecture (optionnelle) des numeros des triangles */
203 if (MEDmeshEntityNumberRd(fid, maa, MED_NO_DT, MED_NO_IT,
204 MED_CELL, MED_TRIA3, numtr3) < 0)
205 inuele3 = MED_FALSE;
206 else
207 inuele3 = MED_TRUE;
208
209 /* Lecture des numeros des familles des triangles */
210 if ( (ret = MEDmeshEntityFamilyNumberRd(fid,maa, MED_NO_DT, MED_NO_IT,
211 MED_CELL, MED_TRIA3,nufatr3)) < 0) {
212 MESSAGE("Erreur a la lecture des numeros de famille des segments");
213 return -1;
214 }
215
216 /* Fermeture du fichier */
217 if (MEDfileClose(fid) < 0) {
218 MESSAGE("Erreur a la fermeture du fichier");
219 return -1;
220 }
221
222 /* Affichage */
223 if (ret == 0) {
224 printf("Connectivite des segments (1): \n");
225 for (i=0;i<nse2*tse2;i++)
226 printf(IFORMAT" ",*(se2_1+i));
227 printf("\n");
228 printf("Connectivite des segments (2): \n");
229 for (i=0;i<nse2*tse2;i++)
230 printf(IFORMAT" ",*(se2_2+i));
231 if (inoele) {
232 printf("\nNoms des segments :\n");
233 for (i=0;i<nse2;i++) {
234 strncpy(str,nomse2+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
235 str[MED_SNAME_SIZE] = '\0';
236 printf("|%s| ",str);
237 }
238 }
239 if (inuele) {
240 printf("\nNumeros des segments :\n");
241 for (i=0;i<nse2;i++)
242 printf(IFORMAT" ",*(numse2+i));
243 }
244 printf("\nNumeros des familles des segments :\n");
245 for (i=0;i<nse2;i++)
246 printf(IFORMAT" ",*(nufase2+i));
247
248 printf("\nConnectivite des triangles : \n");
249 for (i=0;i<ntr3*ttr3;i++)
250 printf(IFORMAT" ",*(tr3+i));
251 if (inoele3) {
252 printf("\nNoms des triangles :\n");
253 for (i=0;i<ntr3;i++) {
254 strncpy(str,nomtr3+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
255 str[MED_SNAME_SIZE] = '\0';
256 printf("|%s| ",str);
257 }
258 }
259 if (inuele3) {
260 printf("\nNumeros des triangles :\n");
261 for (i=0;i<ntr3;i++)
262 printf(IFORMAT" ",*(numtr3+i));
263 }
264 printf("\nNumeros des familles des triangles :\n");
265 for (i=0;i<ntr3;i++)
266 printf(IFORMAT" ",*(nufatr3+i));
267
268 printf("\n");
269 }
270
271 /* Nettoyage memoire */
272 free(se2_1);
273 free(se2_2);
274 free(nomse2);
275 free(numse2);
276 free(nufase2);
277
278 free(tr3);
279 free(nomtr3);
280 free(numtr3);
281 free(nufatr3);
282
283 return ret;
284 }
285
MEDfilterEntityCr
MEDC_EXPORT med_err MEDfilterEntityCr(const med_idt fid, const med_int nentity, const med_int nvaluesperentity, const med_int nconstituentpervalue, const med_int constituentselect, const med_switch_mode switchmode, const med_storage_mode storagemode, const char *const profilename, const med_int filterarraysize, const med_int *const filterarray, med_filter *const filter)
Definition: MEDfilterEntityCr.c:55
MED_TRIA3
#define MED_TRIA3
Definition: med.h:203
MED_FULL_INTERLACE
Definition: med.h:96
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition: med.h:79
med_filter
Filtre de sélection.
Definition: med.h:355
MED_FILTER_INIT
#define MED_FILTER_INIT
Definition: med.h:374
MEDmeshnEntity
MEDC_EXPORT med_int MEDmeshnEntity(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, const med_data_type datatype, const med_connectivity_mode cmode, med_bool *const changement, med_bool *const transformation)
Cette routine permet de lire le nombre d'entités dans un maillage pour une étape de calcul donnée.
Definition: MEDmeshnEntity.c:44
MEDmeshEntityNumberRd
MEDC_EXPORT med_err MEDmeshEntityNumberRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, med_int *const number)
Cette routine permet de lire les numéros d'un type d'entité d'un maillage.
Definition: MEDmeshEntityNumberRd.c:38
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:42
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:82
med_idt
hid_t med_idt
Definition: med.h:331
MED_SEG2
#define MED_SEG2
Definition: med.h:200
MED_ACC_RDONLY
Definition: med.h:120
med_err
herr_t med_err
Definition: med.h:332
med_sorting_type
med_sorting_type
Definition: med.h:309
MED_TRUE
Definition: med.h:260
MED_NO_CMODE
Definition: med.h:255
MED_FALSE
Definition: med.h:260
MED_CELL
Definition: med.h:143
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:342
MED_DESCENDING
Definition: med.h:255
med.h
med_bool
med_bool
Definition: med.h:260
MEDmeshEntityNameRd
MEDC_EXPORT med_err MEDmeshEntityNameRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, char *const name)
Cette routine permet de lire les noms d'un type d'entité d'un maillage.
Definition: MEDmeshEntityNameRd.c:38
IFORMAT
#define IFORMAT
Definition: med_utils.h:145
MED_NO_DT
#define MED_NO_DT
Definition: med.h:320
MEDfilterClose
MEDC_EXPORT med_err MEDfilterClose(med_filter *const filter)
Désalloue les ressources hdf détenues par un filtre.
Definition: MEDfilterClose.c:35
MED_CONNECTIVITY
Definition: med.h:149
MEDmeshElementConnectivityRd
MEDC_EXPORT med_err MEDmeshElementConnectivityRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, const med_connectivity_mode cmode, const med_switch_mode switchmode, med_int *const connectivity)
Cette routine permet de lire dans un maillage le tableau des connectivités pour un type géométrique d...
Definition: MEDmeshElementConnectivityRd.c:40
MEDmeshElementConnectivityAdvancedRd
MEDC_EXPORT med_err MEDmeshElementConnectivityAdvancedRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, const med_connectivity_mode cmode, const med_filter *const filter, med_int *const connectivity)
Cette routine permet de lire dans un maillage le tableau des connectivités pour un type géométrique d...
Definition: MEDmeshElementConnectivityAdvancedRd.c:40
MEDmeshnAxis
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.
Definition: MEDmeshnAxis.c:35
med_mesh_type
med_mesh_type
Definition: med.h:131
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
MED_GLOBAL_STMODE
Definition: med.h:109
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
main
int main(int argc, char **argv)
Definition: test7.c:37
MED_NO_PROFILE
#define MED_NO_PROFILE
Definition: med.h:281
med_axis_type
med_axis_type
Definition: med.h:258
MEDmeshInfo
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
MED_NO_IT
#define MED_NO_IT
Definition: med.h:321
str
#define str(s)
Definition: mdump2.c:126
MEDmeshEntityFamilyNumberRd
MEDC_EXPORT med_err MEDmeshEntityFamilyNumberRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, med_int *const number)
Cette routine permet la lecture des numéros de famille d'un type d'entité d'un maillage.
Definition: MEDmeshEntityFamilyNumberRd.c:39
med_utils.h
MED_NAME
Definition: med.h:149
MED_DESCENDING_EDGE
Definition: med.h:143