MED fichier: Fichier source de UsesCase_MEDmesh_14.c

MED fichier

- Documentation MED
- Guides d'utilisation
- Guides de référence

UsesCase_MEDmesh_14.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 * Use case 14 : read a 2D unstructured mesh with 2 polygons
20 */
21
22 #include <med.h>
23 #define MESGERR 1
24 #include <med_utils.h>
25
26 #include <string.h>
27
28 int main (int argc, char **argv) {
29
30 med_idt fid;
31 const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
32 char meshdescription[MED_COMMENT_SIZE+1]="";
33 med_int meshdim;
34 med_int spacedim;
35 med_sorting_type sortingtype;
36 med_int nstep;
37 med_mesh_type meshtype;
38 med_axis_type axistype;
39 char axisname[2*MED_SNAME_SIZE+1]="";
40 char unitname[2*MED_SNAME_SIZE+1]="";
41 char dtunit[MED_SNAME_SIZE+1]="";
42 med_float *coordinates = NULL;
43 med_int nnodes = 0;
44 med_int npoly = 0;
45 med_int indexsize;
46 med_int *index = NULL;
47 med_int *connectivity = NULL;
48 med_int connectivitysize;
49 med_bool coordinatechangement;
50 med_bool geotransformation;
51 int i, k, ind1, ind2;
52 int ret=-1;
53
54 /* open MED file with READ ONLY access mode */
55 fid = MEDfileOpen("UsesCase_MEDmesh_13.med",MED_ACC_RDONLY);
56 if (fid < 0) {
57 MESSAGE("ERROR : open file in READ ONLY ACCESS mode ...");
58 goto ERROR;
59 }
60
61 /*
62 * ... we know that the MED file has only one mesh,
63 * a real code would check ...
64 */
65
66 /* read mesh informations : mesh dimension, space dimension ... */
67 if (MEDmeshInfoByName(fid, meshname, &spacedim, &meshdim, &meshtype, meshdescription,
68 dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) {
69 MESSAGE("ERROR : mesh info ...");
70 goto ERROR;
71 }
72
73 /* read how many nodes in the mesh */
74 if ((nnodes = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_POINT1,
75 MED_COORDINATE, MED_NO_CMODE,&coordinatechangement, &geotransformation)) < 0)
76 { MESSAGE("ERROR : number of nodes ...");
77 goto ERROR;
78 }
79
80 /*
81 * ... we know that we only have MED_POLYGON celles in the mesh,
82 * a real code would check all MED geometry cell types ...
83 */
84
85 /* How many polygon in the mesh in nodal connectivity mode */
86 /* For the polygons, we get the size of array index */
87 if ((indexsize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
88 MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,
89 &coordinatechangement, &geotransformation)) < 0)
90 { MESSAGE("ERROR : read number of polygon ...");
91 goto ERROR;
92 }
93 npoly = indexsize-1;
94
95 /* how many nodes for the polygon connectivity ? */
96 if ((connectivitysize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
97 MED_CELL,MED_POLYGON,MED_CONNECTIVITY,MED_NODAL,
98 &coordinatechangement, &geotransformation)) < 0)
99 { MESSAGE("ERROR : read connevity size ...");
100 goto ERROR;
101 }
102
103 /* read mesh nodes coordinates */
104 if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) {
105 MESSAGE("ERROR : memory allocation ...");
106 goto ERROR;
107 }
108
109 if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE, coordinates) < 0)
110 { MESSAGE("ERROR : nodes coordinates ...");
111 free(coordinates);
112 goto ERROR;
113 }
114 free(coordinates);
115
116 /* read polygons connectivity */
117 index = (med_int *) malloc(sizeof(med_int)*indexsize);
118 connectivity = (med_int *) malloc(sizeof(med_int)*connectivitysize);
119
120 if (MEDmeshPolygonRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL, MED_NODAL, index, connectivity) < 0)
121 { MESSAGE("ERROR : read polygon connectivity ...");
122 free(index);
123 free(connectivity);
124 goto ERROR;
125 }
126 free(index);
127 free(connectivity);
128
129 /*
130 * ... we know that the family number of nodes and elements is 0, a real code would check ...
131 */
132
133 ret=0;
134 ERROR:
135
136 /* close MED file */
137 if (MEDfileClose(fid) < 0) {
138 MESSAGE("ERROR : close file");
139 ret=-1;
140 }
141
142 return ret;
143 }
144
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_NODE
Definition: med.h:139
MED_FULL_INTERLACE
Definition: med.h:92
MED_POLYGON
#define MED_POLYGON
Definition: med.h:218
MED_NO_IT
#define MED_NO_IT
Definition: med.h:314
MED_COORDINATE
Definition: med.h:145
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:316
med_float
double med_float
Definition: med.h:329
med_mesh_type
med_mesh_type
Definition: med.h:127
MEDmeshPolygonRd
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.
Definition: MEDmeshPolygonRd.c:44
MED_ACC_RDONLY
Definition: med.h:116
MED_CELL
Definition: med.h:139
med_sorting_type
med_sorting_type
Definition: med.h:304
med.h
MED_NO_CMODE
Definition: med.h:250
MED_NODAL
Definition: med.h:250
med_axis_type
med_axis_type
Definition: med.h:253
med_int
int med_int
Definition: med.h:335
main
int main(int argc, char **argv)
Definition: UsesCase_MEDmesh_14.c:28
MED_POINT1
#define MED_POINT1
Definition: med.h:193
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition: med.h:75
MED_CONNECTIVITY
Definition: med.h:145
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:41
med_idt
hid_t med_idt
Definition: med.h:324
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 séquence de calcul donnée...
Definition: MEDmeshnEntity.c:44
MEDmeshNodeCoordinateRd
MEDC_EXPORT med_err MEDmeshNodeCoordinateRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_switch_mode switchmode, med_float *const coordinates)
Cette routine permet de lire dans un maillage le tableau des coordonnées des noeuds, selon une séquence de calcul donnée.
Definition: MEDmeshNodeCoordinateRd.c:37
MED_NO_DT
#define MED_NO_DT
Definition: med.h:313
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:77
med_utils.h
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:78
med_bool
med_bool
Definition: med.h:255
MEDmeshInfoByName
MEDC_EXPORT med_err MEDmeshInfoByName(const med_idt fid, const 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 en précisant son nom...
Definition: MEDmeshInfoByName.c:42
MED_INDEX_NODE
Definition: med.h:147