c/test28.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/>.
*/
/******************************************************************************
* - Nom du fichier : test28.c
*
* - Description : lecture d'un maillage structure (grille cartesienne |
* grille curvilinéaire) dans le fichier test27.med
*
*****************************************************************************/
#include <med.h>
#define MESGERR 1
#include "med_utils.h"
#include <string.h>
#ifdef DEF_LECT_ECR
#define MODE_ACCES MED_ACC_RDWR
#elif DEF_LECT_AJOUT
#define MODE_ACCES MED_ACC_RDEXT
#else
#define MODE_ACCES MED_ACC_CREAT
#endif
#define MAXDIM 3
int main (int argc, char **argv)
{
med_err ret = 0;
med_idt fid = 0;
med_int mdim= 0, sdim=0, axe=0, j=0;
med_float *indices=NULL;
med_int nind=0,nmaa=0, nnoeuds=0;
med_bool chgt=MED_FALSE,trsf=MED_FALSE;
char maa [MED_NAME_SIZE+1] ="";
char axisname[MAXDIM*MED_SNAME_SIZE+1]="";
char axisunit[MAXDIM*MED_SNAME_SIZE+1]="";
char dtunit[MED_SNAME_SIZE+1]="";
char desc[MED_COMMENT_SIZE+1]="";
med_mesh_type meshtype;
med_grid_type gridtype;
med_data_type quoi;
med_sorting_type sort;
med_axis_type repere;
med_float *coo;
med_int *structure_grille;
med_int nstep=0,i=0;
/* Ouverture du fichier test17.med en lecture seule */
fid = MEDfileOpen("test27.med",MED_ACC_RDONLY);
if (fid < 0) {
MESSAGE("Erreur a l'ouverture du fichier test27.med");
return -1;
}
/* Lecture du nombre de maillage */
nmaa = MEDnMesh(fid);
if (nmaa < 0) {
MESSAGE("Erreur a la lecture du nombre de maillage");
return -1;
}
/* On boucle sur les maillages et on ne lit que la grille cartesienne
et la grille destructuree */
for (i=0;i<nmaa;i++) {
if ((sdim=MEDmeshnAxis(fid, i+1)) <0) {
MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :");
SSCRUTE(maa);
return -1;
}
/* On repere le maillage qui nous interesse */
if ( MEDmeshInfo( fid, i+1, maa, &sdim, &mdim, &meshtype, desc, dtunit, &sort,
&nstep, &repere, axisname,axisunit) < 0 ) {
MESSAGE("Erreur a la lecture des infos sur le maillage");
return -1;
}
printf("\nMaillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,meshtype);
printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
printf("\t -Description du maillage : |%s|\n",desc);
printf("\t -Noms des axes : |%s|\n",axisname);
printf("\t -Unités des axes : |%s|\n",axisunit);
printf("\t -Type de repère : %d\n",repere);
printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep);
printf("\t -Unité des dates : |%s|\n",dtunit);
if (meshtype == MED_STRUCTURED_MESH)
printf("\t - Type : Maillage structure \n");
else
printf("\t - Type : Maillage non structure \n");
/* On regarde le type de la grille */
if (meshtype == MED_STRUCTURED_MESH) {
if (MEDmeshGridTypeRd(fid,maa, &gridtype) < 0) {
MESSAGE("Erreur a la lecture de la nature d'une grille");
return -1;
}
if (gridtype == MED_CARTESIAN_GRID)
printf("\t - Grille cartesienne \n");
if (gridtype == MED_CURVILINEAR_GRID)
printf("\t - Grille de-structureee \n");
}
/* On regarde les coordonnees de la grille standard */
if (meshtype == MED_STRUCTURED_MESH && gridtype == MED_CURVILINEAR_GRID) {
nnoeuds = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
MED_NODE, MED_NONE, MED_COORDINATE, MED_NO_CMODE, &chgt, &trsf);
if (nnoeuds < 0) {
MESSAGE("Erreur a la lecture du nombre de noeuds");
return -1;
}
printf("Nombre de noeuds : "IFORMAT" \n",nnoeuds);
structure_grille = (med_int *) malloc(sizeof(med_int)*mdim);
if ( MEDmeshGridStructRd(fid,maa,MED_NO_DT,MED_NO_IT, structure_grille ) < 0) {
MESSAGE("Erreur a la lecture de la structure de la grille");
ret = -1;
}
if (ret == 0) {
printf("Structure des noeuds de la grille : [ ");
for (j=0;j<mdim;j++)
printf(" "IFORMAT" ",*(structure_grille+j));
printf(" ] \n");
free(structure_grille);
}
if (ret == 0) {
coo = (med_float *) malloc(sizeof(med_float)*nnoeuds*mdim);
if ( MEDmeshNodeCoordinateRd(fid, maa, MED_NO_DT, MED_NO_IT,
MED_FULL_INTERLACE, coo) < 0 ) {
MESSAGE("Erreur a la lecture des coordonnees des noeuds");
ret = -1;
}
}
if (ret == 0) {
printf("Coordonnees : [ ");
for (j=0;j<nnoeuds*mdim;j++) printf(" %f ",*(coo+j));
printf(" ] \n");
free(coo);
}
}
/* On regarde les coordonnees des indices de la grille cartesienne */
if (meshtype == MED_STRUCTURED_MESH && gridtype == MED_CARTESIAN_GRID)
for (axe=1;axe<=mdim;axe++) {
switch(axe) {
case 1 :
quoi = MED_COORDINATE_AXIS1;
break;
case 2 :
quoi = MED_COORDINATE_AXIS2;
break;
case 3 :
quoi = MED_COORDINATE_AXIS3;
break;
default :
return -1;
}
nind = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
MED_NODE, MED_NONE, quoi, MED_NO_CMODE, &chgt, &trsf);
if (nind < 0) {
MESSAGE("Erreur a la lecture de la taille de l'indice");
return -1;
}
printf("Lecture de la taille de l'indice : "IFORMAT" \n",nind);
/* on lit le tableau des indices */
indices = (med_float *) malloc(sizeof(med_float)*nind);
if (MEDmeshGridIndexCoordinateRd(fid,maa,MED_NO_DT,MED_NO_IT, axe,indices) < 0) {
MESSAGE("Erreur a lecture de indices de coordonnees");
ret = -1;
}
if (ret == 0) {
printf("Axe %.*s [%.*s] : [ ",MED_SNAME_SIZE, &axisname[(axe-1)*MED_SNAME_SIZE],
MED_SNAME_SIZE,&axisunit[(axe-1)*MED_SNAME_SIZE]);
for (j=0;j<nind;j++) printf(" %f ",indices[j]);
printf(" ] \n");
}
free(indices);
}
}
/* On ferme le fichier */
if (MEDfileClose(fid) < 0) {
MESSAGE("Erreur a la fermeture du fichier");
return -1;
}
printf("Fermeture du fichier \n");
return ret;
}
MED_FULL_INTERLACE
Definition: med.h:96
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_CARTESIAN_GRID
Definition: med.h:137
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_NO_CMODE
Definition: med.h:255
MED_FALSE
Definition: med.h:260
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
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:342
MAXDIM
#define MAXDIM
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
MEDmeshGridStructRd
MEDC_EXPORT med_err MEDmeshGridStructRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, med_int *const gridstruct)
Cette routine permet la lecture de la structure (nombre de points sur chaque axe du repère) d'un mail...
Definition: MEDmeshGridStructRd.c:40
med.h
med_bool
med_bool
Definition: med.h:260
med_float
double med_float
Definition: med.h:336
IFORMAT
#define IFORMAT
Definition: med_utils.h:145
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
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
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,...
Definition: MEDmeshNodeCoordinateRd.c:37
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
med_data_type
med_data_type
Definition: med.h:149
MEDnMesh
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
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
med_axis_type
med_axis_type
Definition: med.h:258
MED_STRUCTURED_MESH
Definition: med.h:131
MED_CURVILINEAR_GRID
Definition: med.h:139
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
MED_COORDINATE_AXIS3
Definition: med.h:150
MED_COORDINATE
Definition: med.h:149
main
int main(int argc, char **argv)
Definition: 3.0.8/test10.c:50
med_utils.h
MED_COORDINATE_AXIS1
Definition: med.h:150