MED fichier

usecases/c/UsesCase_MEDmesh_5.c
/* This file is part of MED.
*
* COPYRIGHT (C) 1999 - 2021 EDF R&D, CEA/DEN
* MED is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MED is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MED. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Mesh Use case 5 : read a 2D structured mesh
* 5x3 cartesian grid
*
*/
#include <med.h>
#define MESGERR 1
#include <med_utils.h>
#include <string.h>
int main (int argc, char **argv) {
med_idt fid;
const char meshname[MED_NAME_SIZE+1]="2D structured mesh";
med_int spacedim;
med_int meshdim;
char meshdescription[MED_COMMENT_SIZE+1];
char axisname[2*MED_SNAME_SIZE+1];
char unitname[2*MED_SNAME_SIZE+1];
char dtunit[MED_SNAME_SIZE+1];
med_mesh_type meshtype;
med_axis_type axistype;
med_grid_type gridtype;
med_int axis, size ;
med_float *cooXaxis = NULL;
med_float *cooYaxis = NULL;
med_bool coordinatechangement;
med_bool geotransformation;
med_int nstep;
med_sorting_type sortingtype;
int j;
int ret=-1;
int ncell=0;
char *cellsname=NULL;
/* open MED file */
fid = MEDfileOpen("UsesCase_MEDmesh_4.med",MED_ACC_RDONLY);
if (fid < 0) {
MESSAGE("ERROR : open file ...");
goto ERROR;
}
/* read mesh informations : meshname, mesh dimension, space dimension ... */
if (MEDmeshInfoByName(fid, meshname, &spacedim, &meshdim, &meshtype, meshdescription,
dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) {
MESSAGE("ERROR : mesh info ...");
goto ERROR;
}
/* read the grid type : MED_CARTESIAN_GRID or MED_CURVILINEAR_GRID */
if (MEDmeshGridTypeRd(fid, meshname, &gridtype) < 0) {
MESSAGE("ERROR : read grid type ...");
}
/*
* ... we know that the mesh is a cartesian grid,
* a real code would check ...
*/
/* read the axis coordinates (MED_CARTESIAN coordinates system */
/* X */
axis = 1;
if ((size = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT,
MED_NODE, MED_NONE, MED_COORDINATE_AXIS1, MED_NO_CMODE,
&coordinatechangement, &geotransformation)) < 0) {
MESSAGE("ERROR : number of coordinates on X axis ...");
goto ERROR;
}
ncell = size-1;
if ((cooXaxis = (med_float *) malloc(sizeof(med_float)*size)) == NULL) {
MESSAGE("ERROR : memory allocation ...");
goto ERROR;
}
if (MEDmeshGridIndexCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT,
axis, cooXaxis) < 0) {
MESSAGE("ERROR : read axis X coordinates ...");
free(cooXaxis);
goto ERROR;
}
free(cooXaxis);
/* Y */
axis = 2;
if ((size = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT,
MED_NODE, MED_NONE, MED_COORDINATE_AXIS2, MED_NO_CMODE,
&coordinatechangement, &geotransformation)) < 0) {
MESSAGE("ERROR : number of coordinates on Y axis ...");
goto ERROR;
}
ncell = ncell * (size-1);
if ((cooYaxis = (med_float *) malloc(sizeof(med_float)*size)) == NULL) {
MESSAGE("ERROR : memory allocation ...");
goto ERROR;
}
if (MEDmeshGridIndexCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT,
axis, cooYaxis) < 0) {
MESSAGE("ERROR : read axis Y coordinates ...");
free(cooYaxis);
goto ERROR;
}
free(cooYaxis);
/* read cells name */
cellsname = (char *) malloc((sizeof(char))*ncell*MED_SNAME_SIZE+1);
if (MEDmeshEntityNameRd(fid, meshname, MED_NO_DT, MED_NO_IT,
MED_CELL, MED_QUAD4, cellsname) < 0) {
MESSAGE("ERROR : read cells name ...");
free(cellsname);
goto ERROR;
}
free(cellsname);
ret=0;
ERROR:
/* close MED file */
if (MEDfileClose(fid) < 0) {
MESSAGE("ERROR : close file ...");
ret = -1;
}
return ret;
}
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
main
int main(int argc, char **argv)
Definition: 3.0.8/test10.c:50
med_utils.h
MED_COORDINATE_AXIS1
Definition: med.h:150
MED_QUAD4
#define MED_QUAD4
Definition: med.h:204