MED fichier

test17.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 : test17.c
20 *
21 * - Description : lecture d'elements de maillages MED ecrits par test16
22 * via les routines de niveau 2
23 * - equivalent a test7.c
24 *
25 *****************************************************************************/
26
27 #include <med.h>
28 #define MESGERR 1
29 #include "med_utils.h"
30 #include <string.h>
31
32 #ifdef DEF_LECT_ECR
33 #define MODE_ACCES MED_ACC_RDWR
34 #elif DEF_LECT_AJOUT
35 #define MODE_ACCES MED_ACC_RDEXT
36 #else
37 #define MODE_ACCES MED_ACC_CREAT
38 #endif
39
40
41 int main (int argc, char **argv)
42
43
44 {
45 med_err ret = 0;
46 med_idt fid;
47 med_int nse2;
48 med_int *se2;
49 char *nomse2;
50 med_int *numse2;
51 med_int *nufase2;
52 med_int ntr3;
53 med_int *tr3;
54 char *nomtr3;
55 med_int *numtr3;
56 med_int *nufatr3;
57 char maa[MED_NAME_SIZE+1] ="maa1";
58 med_int mdim=0,sdim=0;
59 med_bool inoele1,inoele2,inuele1,inuele2,infele1,infele2;
60 med_int tse2,ttr3;
61 med_bool chgt=MED_FALSE, trsf=MED_FALSE;
62 char str [MED_SNAME_SIZE+1] ="";
63 char desc [MED_COMMENT_SIZE+1]="";
64 char dtunit[MED_SNAME_SIZE+1] ="";
65 char nomcoo[3*MED_SNAME_SIZE+1]="";
66 char unicoo[3*MED_SNAME_SIZE+1]="";
67 med_mesh_type type;
68 med_sorting_type sort;
69 med_axis_type rep;
70 med_int nstep=0;
71 med_int i;
72
73
74 /* Ouverture du fichier en mode lecture seule */
75 if ((fid = MEDfileOpen("test16.med",MED_ACC_RDONLY)) < 0) {
76 MESSAGE("Erreur a l'ouverture du fichier test16.med .");
77 return -1;
78 }
79 if ((sdim=MEDmeshnAxis(fid, 1)) <0) {
80 MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :");
81 SSCRUTE(maa);
82 return -1;
83 }
84
85 /* Lecture des infos concernant le premier maillage */
86 if ( MEDmeshInfo( fid, 1, maa, &sdim, &mdim, &type, desc, dtunit, &sort,
87 &nstep, &rep, nomcoo,unicoo) < 0 ) {
88 MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
89 return -1;
90 } else {
91 printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,type);
92 printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
93 printf("\t -Description du maillage : |%s|\n",desc);
94 printf("\t -Noms des axes : |%s|\n",nomcoo);
95 printf("\t -Unités des axes : |%s|\n",unicoo);
96 printf("\t -Type de repère : %d\n",rep);
97 printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep);
98 printf("\t -Unité des dates : |%s|\n",dtunit);
99 }
100
101 /* Combien de triangles et de segments */
102 if ((nse2 = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
103 MED_DESCENDING_EDGE, MED_SEG2,MED_CONNECTIVITY, MED_DESCENDING,
104 &chgt, &trsf)) < 0) {
105 MESSAGE("Erreur a la lecture du nombre de segments");
106 return -1;
107 }
108
109 if ((ntr3 = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
110 MED_CELL, MED_TRIA3,MED_CONNECTIVITY, MED_DESCENDING,
111 &chgt, &trsf)) < 0) {
112 MESSAGE("Erreur a la lecture du nombre de segments");
113 return -1;
114 }
115 printf("Nombre de MED_SEG2 : "IFORMAT" - nombre de MED_TRIA3 :"IFORMAT"\n",nse2,ntr3);
116
117 /* Allocations memoire */
118 tse2 = 2;
119 se2 = (med_int*) malloc(sizeof(med_int)*tse2*nse2);
120 nomse2 = (char*) malloc(MED_SNAME_SIZE*nse2+1);
121 numse2 = (med_int*) malloc(sizeof(med_int)*nse2);
122 nufase2 = (med_int*) calloc(nse2,sizeof(med_int));
123
124 ttr3 = 3;
125 tr3 = (med_int*) malloc(sizeof(med_int)*ntr3*ttr3);
126 nomtr3 = (char*) malloc(MED_SNAME_SIZE*ntr3+1);
127 numtr3 = (med_int*) malloc(sizeof(med_int)*ntr3);
128 nufatr3 = (med_int*) calloc(ntr3,sizeof(med_int));
129
130 /* Lecture des aretes segments MED_SEG2 :
131 - Connectivite,
132 - Noms (optionnel)
133 - Numeros (optionnel)
134 - Numeros de familles */
135 if (MEDmeshElementRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_DESCENDING_EDGE,MED_SEG2,MED_DESCENDING,MED_NO_INTERLACE,
136 se2,&inoele1,nomse2,&inuele1,numse2,&infele1,nufase2) < 0) {
137 MESSAGE("Erreur a la lecture des segments");
138 ret = -1;
139 }
140
141 /* Lecture des mailles triangles MED_TRIA3 :
142 - Connectivite,
143 - Noms (optionnel)
144 - Numeros (optionnel)
145 - Numeros de familles */
146 if (MEDmeshElementRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,MED_DESCENDING,MED_NO_INTERLACE,
147 tr3,&inoele2,nomtr3,&inuele2,numtr3,&infele2,nufatr3) < 0) {
148 MESSAGE("Erreur a la lecture des triangles");
149 ret = -1;
150 }
151
152 /* Fermeture du fichier */
153 if (MEDfileClose(fid) < 0) {
154 MESSAGE("Erreur a la fermeture du fichier");
155 ret = -1;
156 }
157
158 /* Affichage */
159 if (ret == 0) {
160 if (nse2 > 0) {
161 printf("Connectivite des segments : \n");
162 for (i=0;i<nse2*tse2;i++)
163 printf(IFORMAT" ",*(se2+i));
164 if (inoele1) {
165 printf("\nNoms des segments :\n");
166 for (i=0;i<nse2;i++) {
167 strncpy(str,nomse2+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
168 str[MED_SNAME_SIZE] = '\0';
169 printf("|%s| ",str);
170 }
171 }
172 if (inuele1) {
173 printf("\nNumeros des segments :\n");
174 for (i=0;i<nse2;i++)
175 printf(IFORMAT" ",*(numse2+i));
176 }
177 printf("\nPrésence de numeros des familles des segments : %d\n",infele1);
178 printf("\nNumeros des familles des segments :\n");
179 for (i=0;i<nse2;i++)
180 printf(IFORMAT" ",*(nufase2+i));
181 }
182
183 if (ntr3 > 0) {
184 printf("\nConnectivite des triangles : \n");
185 for (i=0;i<ntr3*ttr3;i++)
186 printf(IFORMAT" ",*(tr3+i));
187 if (inoele2) {
188 printf("\nNoms des triangles :\n");
189 for (i=0;i<ntr3;i++) {
190 strncpy(str,nomtr3+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
191 str[MED_SNAME_SIZE] = '\0';
192 printf("|%s| ",str);
193 }
194 }
195 if (inuele2) {
196 printf("\nNumeros des triangles :\n");
197 for (i=0;i<ntr3;i++)
198 printf(IFORMAT" ",*(numtr3+i));
199 }
200 printf("\nPrésence de numeros des familles des triangles : %d\n",infele2);
201 printf("\nNumeros des familles des triangles :\n");
202 for (i=0;i<ntr3;i++)
203 printf(IFORMAT" ",*(nufatr3+i));
204
205 printf("\n");
206 }
207 }
208
209 /* Nettoyage memoire */
210 free(se2);
211 free(nomse2);
212 free(numse2);
213 free(nufase2);
214
215 free(tr3);
216 free(nomtr3);
217 free(numtr3);
218 free(nufatr3);
219
220 return ret;
221 }
222
223
224
225
MED_TRIA3
#define MED_TRIA3
Definition: med.h:203
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition: med.h:79
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
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_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
main
int main(int argc, char **argv)
Definition: test17.c:40
IFORMAT
#define IFORMAT
Definition: med_utils.h:145
MED_NO_DT
#define MED_NO_DT
Definition: med.h:320
MED_CONNECTIVITY
Definition: med.h:149
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_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
MEDmeshElementRd
MEDC_EXPORT med_err MEDmeshElementRd(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, med_bool *const withelementname, char *const elementname, med_bool *const withelementnumber, med_int *const elementnumber, med_bool *const withfamnumber, med_int *const famnumber)
Cette routine permet la lecture d'un type d'élément d'un maillage non structuré pour une étape de cal...
Definition: MEDmeshElementRd.c:47
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_NO_INTERLACE
Definition: med.h:98
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
med_utils.h
MED_DESCENDING_EDGE
Definition: med.h:143