MED fichier
test24.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 : test24.c
21 *
22 * - Description : lecture de mailles/faces de type MED_POLYGONE
23 * dans le maillage MED du fichier test23.med
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
40int main (int argc, char **argv)
41
42#define MAXDIM 3
43
44{
45 med_err ret = 0;
46 med_idt fid;
47 char maa[MED_NAME_SIZE+1];
48 med_int nmaa,i,mdim,nindex,npoly,j,nind,nnoe;
49 char desc[MED_COMMENT_SIZE+1];
50 med_int *con, *index, *num, *fam;
51 char *nom;
52 char tmp[MED_SNAME_SIZE+1];
53 int ind1, ind2,k;
54 char dtunit[MED_SNAME_SIZE+1]="";
55 char nomcoo[MAXDIM*MED_SNAME_SIZE+1];
56 char unicoo[MAXDIM*MED_SNAME_SIZE+1];
57 med_mesh_type type;
59 med_axis_type rep;
60 med_int nstep=0,spacedim=0;
61 med_bool inoele=MED_FALSE,inuele=MED_FALSE,chgt=MED_FALSE,trsf=MED_FALSE;
62
63 /* Ouverture du fichier test23.med en lecture seule */
64 fid = MEDfileOpen("test23.med",MED_ACC_RDONLY);
65 if (fid < 0) {
66 MESSAGE("Erreur a l'ouverture du fichier test23.med");
67 return -1;
68 }
69 printf("Ouverture du fichier test23.med \n");
70
71 /* Lecture du nombre de maillages */
72 nmaa = MEDnMesh(fid);
73 if (nmaa < 0) {
74 MESSAGE("Erreur a la lecture du nombre de maillage");
75 return -1;
76 }
77 printf("Nombre de maillages = "IFORMAT"\n",nmaa);
78
79 for (i=0;i<nmaa;i++) {
80
81 /* Infos sur le maillage */
82 if ( MEDmeshInfo( fid, i+1, maa, &spacedim, &mdim, &type, desc, dtunit, &sort,
83 &nstep, &rep, nomcoo,unicoo) < 0 ) {
84 MESSAGE("Erreur a la lecture des infos sur le maillage");
85 return -1;
86 } else {
87 printf("maillage "IFORMAT" de nom [%s] et de dimension : "IFORMAT" , et de type %d\n",i+1,maa,mdim,type);
88 printf("\t -Dimension de l'espace : "IFORMAT"\n",spacedim);
89 printf("\t -Description du maillage : |%s|\n",desc);
90 printf("\t -Noms des axes : |%s|\n",nomcoo);
91 printf("\t -Unités des axes : |%s|\n",unicoo);
92 printf("\t -Type de repère : %d\n",rep);
93 printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep);
94 printf("\t -Unité des dates : |%s|\n",dtunit);
95 }
96
97 /* Combien de mailles polygones en mode nodal */
98 if ((nind = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
100 &chgt,&trsf)) < 0) {
101 MESSAGE("Erreur a la lecture du nombre de mailles MED_POLYGONE");
102 return -1;
103 }
104 npoly = nind-1;
105 printf("Nombre de mailles polygones en mode nodal : "IFORMAT" \n",npoly);
106
107 /* Quelle taille pour le tableau des connectivites, nombre de noeuds
108 tous polygones confondus*/
109 if ((nnoe = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
111 &chgt,&trsf)) < 0) {
112 MESSAGE("Erreur a la lecture du nombre de mailles MED_POLYGONE");
113 return -1;
114 }
115
116 printf("Taille a allouer pour la connectivite des polygones : "IFORMAT" \n",nnoe);
117
118 /* Allocation memoire :
119 * - tableau d'index : npoly + 1
120 * - tableau des connectivites : nnoe
121 * - tableaux numeros et numeros de familles : npoly
122 * - tableau des noms : MED_SNAME_SIZE*npoly + 1
123 */
124 index = (med_int *) malloc(sizeof(med_int)*nind);
125 con = (med_int *) malloc(sizeof(med_int)*nnoe);
126 num = (med_int *) malloc(sizeof(med_int)*npoly);
127 fam = (med_int *) malloc(sizeof(med_int)*npoly);
128 nom = (char *) malloc(sizeof(char)*MED_SNAME_SIZE*npoly+1);
129
130 /* Lecture de la connectivite des mailles polygones */
132 index,con) < 0) {
133 MESSAGE("Erreur a la lecture de la connectivite des mailles MED_POLYGONE");
134 return -1;
135 }
136 printf("Lecture de la connectivite des mailles MED_POLYGONE en mode nodal \n");
137
138 /* Lecture (optionnelle) des noms des polygones */
140 MED_CELL, MED_POLYGON,nom) < 0)
141 inoele = MED_FALSE;
142 else
143 inoele = MED_TRUE;
144
145 /* Lecture (optionnelle) des numeros des polygones */
147 MED_CELL, MED_POLYGON, num) < 0)
148 inuele = MED_FALSE;
149 else
150 inuele = MED_TRUE;
151
152 /* Lecture des numeros des familles des segments */
154 MED_CELL, MED_POLYGON,fam) < 0) {
155 MESSAGE("Erreur a la lecture des numéros de famille des segments");
156 /*TODO : Considérer famille 0 */
157 return -1;
158 }
159
160
161 if (ret == 0) {
162 printf("Affichage des resultats \n");
163 for (j=0;j<npoly;j++) {
164 printf(">> Maille MED_POLYGONE "IFORMAT" : \n",j+1);
165 printf("---- Connectivite ----- : [ ");
166 ind1 = *(index+j)-1;
167 ind2 = *(index+j+1)-1;
168 for (k=ind1;k<ind2;k++)
169 printf(IFORMAT" ",*(con+k));
170 printf(" ] \n");
171 strncpy(tmp,nom+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
172 tmp[MED_SNAME_SIZE] = '\0';
173 if (inoele) printf("---- Nom ----- : |%s| \n",tmp);
174 if (inuele) printf("---- Numero ----- : "IFORMAT" \n",*(num+j));
175 printf("---- Numero de famille ----- : "IFORMAT" \n",*(fam+j));
176 }
177 }
178
179 /* Liberation de la memoire */
180 free(index);
181 free(con);
182 free(num);
183 free(fam);
184 free(nom);
185 }
186
187 /* Fermeture du fichier */
188 if (MEDfileClose(fid) < 0) {
189 MESSAGE("Erreur a la fermeture du fichier");
190 return -1;
191 }
192 printf("Fermeture du fichier \n");
193
194 return ret;
195}
#define MED_NAME_SIZE
#define MED_SNAME_SIZE
#define MED_POLYGON
#define MED_COMMENT_SIZE
#define MESSAGE(chaine)
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_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.
MEDC_EXPORT med_err MEDmeshPolygonRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_connectivity_mode cmode, med_int *const polyindex, med_int *const connectivity)
Cette routine permet la lecture des connectivités de polygones.
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.
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_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.
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.
int main(int argc, char **argv)
Definition test24.c:40
#define MAXDIM