MED fichier: c/test17.c

MED fichier

c/test17.c
/* This file is part of MED.
*
* COPYRIGHT (C) 1999 - 2023 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 : test17.c
*
* - Description : lecture d'elements de maillages MED ecrits par test16
* via les routines de niveau 2
* - equivalent a test7.c
*
*****************************************************************************/
#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
int main (int argc, char **argv)
{
med_err ret = 0;
med_idt fid;
med_int nse2;
med_int *se2;
char *nomse2;
med_int *numse2;
med_int *nufase2;
med_int ntr3;
med_int *tr3;
char *nomtr3;
med_int *numtr3;
med_int *nufatr3;
char maa[MED_NAME_SIZE+1] ="maa1";
med_int mdim=0,sdim=0;
med_bool inoele1,inoele2,inuele1,inuele2,infele1,infele2;
med_int tse2,ttr3;
med_bool chgt=MED_FALSE, trsf=MED_FALSE;
char str [MED_SNAME_SIZE+1] ="";
char desc [MED_COMMENT_SIZE+1]="";
char dtunit[MED_SNAME_SIZE+1] ="";
char nomcoo[3*MED_SNAME_SIZE+1]="";
char unicoo[3*MED_SNAME_SIZE+1]="";
med_mesh_type type;
med_sorting_type sort;
med_axis_type rep;
med_int nstep=0;
med_int i;
/* Ouverture du fichier en mode lecture seule */
if ((fid = MEDfileOpen("test16.med",MED_ACC_RDONLY)) < 0) {
MESSAGE("Erreur a l'ouverture du fichier test16.med .");
return -1;
}
if ((sdim=MEDmeshnAxis(fid, 1)) <0) {
MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :");
SSCRUTE(maa);
return -1;
}
/* Lecture des infos concernant le premier maillage */
if ( MEDmeshInfo( fid, 1, maa, &sdim, &mdim, &type, desc, dtunit, &sort,
&nstep, &rep, nomcoo,unicoo) < 0 ) {
MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
return -1;
} else {
printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,type);
printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
printf("\t -Description du maillage : |%s|\n",desc);
printf("\t -Noms des axes : |%s|\n",nomcoo);
printf("\t -Unités des axes : |%s|\n",unicoo);
printf("\t -Type de repère : %d\n",rep);
printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep);
printf("\t -Unité des dates : |%s|\n",dtunit);
}
/* Combien de triangles et de segments */
if ((nse2 = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
MED_DESCENDING_EDGE, MED_SEG2, MED_CONNECTIVITY, MED_DESCENDING,
&chgt, &trsf)) < 0) {
MESSAGE("Erreur a la lecture du nombre de segments");
return -1;
}
if ((ntr3 = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
MED_CELL, MED_TRIA3,MED_CONNECTIVITY, MED_DESCENDING,
&chgt, &trsf)) < 0) {
MESSAGE("Erreur a la lecture du nombre de segments");
return -1;
}
printf("Nombre de MED_SEG2 : "IFORMAT" - nombre de MED_TRIA3 :"IFORMAT"\n",nse2,ntr3);
/* Allocations memoire */
tse2 = 2;
se2 = (med_int*) malloc(sizeof(med_int)*tse2*nse2);
nomse2 = (char*) malloc(MED_SNAME_SIZE*nse2+1);
numse2 = (med_int*) malloc(sizeof(med_int)*nse2);
nufase2 = (med_int*) calloc(nse2,sizeof(med_int));
ttr3 = 3;
tr3 = (med_int*) malloc(sizeof(med_int)*ntr3*ttr3);
nomtr3 = (char*) malloc(MED_SNAME_SIZE*ntr3+1);
numtr3 = (med_int*) malloc(sizeof(med_int)*ntr3);
nufatr3 = (med_int*) calloc(ntr3,sizeof(med_int));
/* Lecture des aretes segments MED_SEG2 :
- Connectivite,
- Noms (optionnel)
- Numeros (optionnel)
- Numeros de familles */
if (MEDmeshElementRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_DESCENDING_EDGE,MED_SEG2,MED_DESCENDING, MED_NO_INTERLACE,
se2,&inoele1,nomse2,&inuele1,numse2,&infele1,nufase2) < 0) {
MESSAGE("Erreur a la lecture des segments");
ret = -1;
}
/* Lecture des mailles triangles MED_TRIA3 :
- Connectivite,
- Noms (optionnel)
- Numeros (optionnel)
- Numeros de familles */
if (MEDmeshElementRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,MED_DESCENDING,MED_NO_INTERLACE,
tr3,&inoele2,nomtr3,&inuele2,numtr3,&infele2,nufatr3) < 0) {
MESSAGE("Erreur a la lecture des triangles");
ret = -1;
}
/* Fermeture du fichier */
if (MEDfileClose(fid) < 0) {
MESSAGE("Erreur a la fermeture du fichier");
ret = -1;
}
/* Affichage */
if (ret == 0) {
if (nse2 > 0) {
printf("Connectivite des segments : \n");
for (i=0;i<nse2*tse2;i++)
printf(IFORMAT" ",*(se2+i));
if (inoele1) {
printf("\nNoms des segments :\n");
for (i=0;i<nse2;i++) {
strncpy(str,nomse2+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
str[MED_SNAME_SIZE] = '\0';
printf("|%s| ",str);
}
}
if (inuele1) {
printf("\nNumeros des segments :\n");
for (i=0;i<nse2;i++)
printf(IFORMAT" ",*(numse2+i));
}
printf("\nPrésence de numeros des familles des segments : %d\n",infele1);
printf("\nNumeros des familles des segments :\n");
for (i=0;i<nse2;i++)
printf(IFORMAT" ",*(nufase2+i));
}
if (ntr3 > 0) {
printf("\nConnectivite des triangles : \n");
for (i=0;i<ntr3*ttr3;i++)
printf(IFORMAT" ",*(tr3+i));
if (inoele2) {
printf("\nNoms des triangles :\n");
for (i=0;i<ntr3;i++) {
strncpy(str,nomtr3+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
str[MED_SNAME_SIZE] = '\0';
printf("|%s| ",str);
}
}
if (inuele2) {
printf("\nNumeros des triangles :\n");
for (i=0;i<ntr3;i++)
printf(IFORMAT" ",*(numtr3+i));
}
printf("\nPrésence de numeros des familles des triangles : %d\n",infele2);
printf("\nNumeros des familles des triangles :\n");
for (i=0;i<ntr3;i++)
printf(IFORMAT" ",*(nufatr3+i));
printf("\n");
}
}
/* Nettoyage memoire */
free(se2);
free(nomse2);
free(numse2);
free(nufase2);
free(tr3);
free(nomtr3);
free(numtr3);
free(nufatr3);
return ret;
}
MED_TRIA3
#define MED_TRIA3
Definition: med.h:205
MED_ACC_RDONLY
Definition: med.h:122
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition: med.h:81
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:84
MED_NO_INTERLACE
Definition: med.h:100
med_idt
hid_t med_idt
Definition: med.h:333
MED_FALSE
Definition: med.h:262
MED_SEG2
#define MED_SEG2
Definition: med.h:202
med_err
herr_t med_err
Definition: med.h:334
MED_DESCENDING_EDGE
Definition: med.h:145
med_sorting_type
med_sorting_type
Definition: med.h:311
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
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:344
med_bool
med_bool
Definition: med.h:262
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
IFORMAT
#define IFORMAT
Definition: med_utils.h:145
MED_NO_DT
#define MED_NO_DT
Definition: med.h:322
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
med_mesh_type
med_mesh_type
Definition: med.h:133
MED_CELL
Definition: med.h:145
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:83
med_utils.h
med_axis_type
med_axis_type
Definition: med.h:260
med.h
MED_CONNECTIVITY
Definition: med.h:151
MED_NO_IT
#define MED_NO_IT
Definition: med.h:323
MED_DESCENDING
Definition: med.h:257
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
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:42
str
#define str(s)
Definition: mdump2.c:126
main
int main(int argc, char **argv)
Definition: 3.0.8/test10.c:50
MEDmeshElementRd
MEDC_EXPORT med_err MEDmeshElementRd(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_connectivity_mode cmode, const med_switch_mode switchmode, med_int *const connectivity, med_bool *const withelementname, char *const elementname, med_bool *const withelementnumber, med_int *const elementnumber, med_bool *const withfamnumber, med_int *const famnumber)
Cette routine permet la lecture d'un type d'élément d'un maillage non structuré pour une étape de cal...
Definition: MEDmeshElementRd.c:47