MED fichier: Fichier source de UsesCase_MEDmesh_5.c

MED fichier

UsesCase_MEDmesh_5.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 * Mesh Use case 5 : read a 2D structured mesh
20 * 5x3 cartesian grid
21 *
22 */
23
24 #include <med.h>
25 #define MESGERR 1
26 #include <med_utils.h>
27
28 #include <string.h>
29
30 int main (int argc, char **argv) {
31 med_idt fid;
32 const char meshname[MED_NAME_SIZE+1]="2D structured mesh";
33 med_int spacedim;
34 med_int meshdim;
35 char meshdescription[MED_COMMENT_SIZE+1];
36 char axisname[2*MED_SNAME_SIZE+1];
37 char unitname[2*MED_SNAME_SIZE+1];
38 char dtunit[MED_SNAME_SIZE+1];
39 med_mesh_type meshtype;
40 med_axis_type axistype;
41 med_grid_type gridtype;
42 med_int axis, size ;
43 med_float *cooXaxis = NULL;
44 med_float *cooYaxis = NULL;
45 med_bool coordinatechangement;
46 med_bool geotransformation;
47 med_int nstep;
48 med_sorting_type sortingtype;
49 int j;
50 int ret=-1;
51 int ncell=0;
52 char *cellsname=NULL;
53
54 /* open MED file */
55 fid = MEDfileOpen("UsesCase_MEDmesh_4.med",MED_ACC_RDONLY);
56 if (fid < 0) {
57 MESSAGE("ERROR : open file ...");
58 goto ERROR;
59 }
60
61 /* read mesh informations : meshname, mesh dimension, space dimension ... */
62 if (MEDmeshInfoByName(fid, meshname, &spacedim, &meshdim, &meshtype, meshdescription,
63 dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) {
64 MESSAGE("ERROR : mesh info ...");
65 goto ERROR;
66 }
67
68 /* read the grid type : MED_CARTESIAN_GRID or MED_CURVILINEAR_GRID */
69 if (MEDmeshGridTypeRd(fid, meshname, &gridtype) < 0) {
70 MESSAGE("ERROR : read grid type ...");
71 }
72
73 /*
74 * ... we know that the mesh is a cartesian grid,
75 * a real code would check ...
76 */
77
78 /* read the axis coordinates (MED_CARTESIAN coordinates system */
79 /* X */
80 axis = 1;
81 if ((size = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT,
82 MED_NODE, MED_NONE, MED_COORDINATE_AXIS1, MED_NO_CMODE,
83 &coordinatechangement, &geotransformation)) < 0) {
84 MESSAGE("ERROR : number of coordinates on X axis ...");
85 goto ERROR;
86 }
87 ncell = size-1;
88
89 if ((cooXaxis = (med_float *) malloc(sizeof(med_float)*size)) == NULL) {
90 MESSAGE("ERROR : memory allocation ...");
91 goto ERROR;
92 }
93 if (MEDmeshGridIndexCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT,
94 axis, cooXaxis) < 0) {
95 MESSAGE("ERROR : read axis X coordinates ...");
96 free(cooXaxis);
97 goto ERROR;
98 }
99
100 free(cooXaxis);
101
102 /* Y */
103 axis = 2;
104 if ((size = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT,
105 MED_NODE, MED_NONE, MED_COORDINATE_AXIS2, MED_NO_CMODE,
106 &coordinatechangement, &geotransformation)) < 0) {
107 MESSAGE("ERROR : number of coordinates on Y axis ...");
108 goto ERROR;
109 }
110 ncell = ncell * (size-1);
111
112 if ((cooYaxis = (med_float *) malloc(sizeof(med_float)*size)) == NULL) {
113 MESSAGE("ERROR : memory allocation ...");
114 goto ERROR;
115 }
116 if (MEDmeshGridIndexCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT,
117 axis, cooYaxis) < 0) {
118 MESSAGE("ERROR : read axis Y coordinates ...");
119 free(cooYaxis);
120 goto ERROR;
121 }
122
123 free(cooYaxis);
124
125 /* read cells name */
126
127 cellsname = (char *) malloc((sizeof(char))*ncell*MED_SNAME_SIZE+1);
128 if (MEDmeshEntityNameRd(fid, meshname, MED_NO_DT, MED_NO_IT,
129 MED_CELL, MED_QUAD4, cellsname) < 0) {
130 MESSAGE("ERROR : read cells name ...");
131 free(cellsname);
132 goto ERROR;
133 }
134 free(cellsname);
135
136 ret=0;
137 ERROR:
138
139 /* close MED file */
140 if (MEDfileClose(fid) < 0) {
141 MESSAGE("ERROR : close file ...");
142 ret = -1;
143 }
144
145 return ret;
146 }
main
int main(int argc, char **argv)
Definition: UsesCase_MEDmesh_5.c:30
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition: med.h:79
med_grid_type
med_grid_type
Definition: med.h:137
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_COORDINATE_AXIS2
Definition: med.h:150
med_idt
hid_t med_idt
Definition: med.h:331
MED_ACC_RDONLY
Definition: med.h:120
med_sorting_type
med_sorting_type
Definition: med.h:309
MED_NO_CMODE
Definition: med.h:255
MEDmeshGridTypeRd
MEDC_EXPORT med_err MEDmeshGridTypeRd(const med_idt fid, const char *const meshname, med_grid_type *const gridtype)
Cette routine permet de lire le type d'un maillage structuré (MED_STRUCTURED_MESH).
Definition: MEDmeshGridTypeRd.c:36
MED_CELL
Definition: med.h:143
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:342
MEDmeshGridIndexCoordinateRd
MEDC_EXPORT med_err MEDmeshGridIndexCoordinateRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_int axis, med_float *const gridindex)
Cette routine permet la lecture des coordonnées des noeuds d'un maillage structuré selon un axe du re...
Definition: MEDmeshGridIndexCoordinateRd.c:39
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
med_float
double med_float
Definition: med.h:336
MED_NO_DT
#define MED_NO_DT
Definition: med.h:320
MED_NONE
#define MED_NONE
Definition: med.h:231
MED_NODE
Definition: med.h:143
med_mesh_type
med_mesh_type
Definition: med.h:131
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
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_axis_type
med_axis_type
Definition: med.h:258
MED_NO_IT
#define MED_NO_IT
Definition: med.h:321
med_utils.h
MED_COORDINATE_AXIS1
Definition: med.h:150
MED_QUAD4
#define MED_QUAD4
Definition: med.h:204