MED fichier
c/test8.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 : test8.c
*
* - Description : exemple d'ecriture de familles dans un maillage 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
int main (int argc, char **argv)
{
med_idt fid = 0;
char maa[MED_NAME_SIZE+1] ="maa1";
med_int mdim = 2;
char nomfam[MED_NAME_SIZE+1]="";
med_int numfam;
med_int ngro;
char gro[MED_LNAME_SIZE+1]="";
int i;
int nfame = 3;
int nfamn = 2;
char nomcoo[2*MED_SNAME_SIZE+1] = "x y ";
char unicoo[2*MED_SNAME_SIZE+1] = "cm cm ";
/* Creation du fichier "test8.med" */
if ((fid = MEDfileOpen("test8.med",MODE_ACCES)) < 0) {
MESSAGE("Erreur a la creation du fichier test8.med");
return -1;
}
if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH,
"un maillage pour test8","s", MED_SORT_DTIT,
MED_CARTESIAN, nomcoo, unicoo) < 0) {
MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa);
return -1;
}
/* Ecriture des familles */
/* Conventions appliquees dans MED :
- Toujours creer une famille de numero 0 ne comportant aucun attribut
ni groupe (famille de reference pour les noeuds ou les elements
qui ne sont rattaches a aucun groupe ni attribut)
- Les numeros de familles de noeuds sont > 0
- Les numeros de familles des elements sont < 0
- Rien d'imposer sur les noms de familles.
*/
/* Creation de la famille 0 */
strcpy(nomfam,"FAMILLE_0");
numfam = 0;
if (MEDfamilyCr(fid,maa,nomfam,numfam,0,"") < 0) {
MESSAGE("Erreur a la creation de la famille 0");
return -1;
}
/* Creation pour correspondre aux cas test precedent de :
- 3 familles d'elements (-1,-2,-3)
- 2 familles de noeuds (1,2) */
nfame = 3;
for (i=0;i<nfame;i++) {
numfam = -(i+1);
sprintf(nomfam,"%s"IFORMAT,"FAMILLE_ELEMENT_",-numfam);
strcpy(gro,"groupe1");
ngro = 1;
printf("%s - "IFORMAT" - "IFORMAT" \n",nomfam,numfam,
ngro);
if (MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro) < 0) {
MESSAGE("Erreur a la creation de la famille :");
SSCRUTE(nomfam); ISCRUTE(numfam);
return -1;
}
}
nfamn = 2;
for (i=0;i<nfamn;i++) {
numfam = i+1;
sprintf(nomfam,"%s"IFORMAT,"FAMILLE_NOEUD_",numfam);
strcpy(gro,"groupe1");
ngro = 1;
if (MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro) < 0) {
MESSAGE("Erreur a la creation de la famille :");
SSCRUTE(nomfam); ISCRUTE(numfam);
return -1;
}
}
/* Fermeture du fichier */
if (MEDfileClose(fid) < 0) {
MESSAGE("Erreur a la fermeture du fichier :");
return -1;
}
return 0;
}
MED_UNSTRUCTURED_MESH
Definition: med.h:133
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:84
med_idt
hid_t med_idt
Definition: med.h:333
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:344
MED_SORT_DTIT
Definition: med.h:311
ISCRUTE
#define ISCRUTE(entier)
Definition: med_utils.h:313
IFORMAT
#define IFORMAT
Definition: med_utils.h:145
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
MODE_ACCES
#define MODE_ACCES
Definition: 3.0.8/test10.c:34
MEDfamilyCr
MEDC_EXPORT med_err MEDfamilyCr(const med_idt fid, const char *const meshname, const char *const familyname, const med_int familynumber, const med_int ngroup, const char *const groupname)
Cette routine permet la création d'une famille portant sur les entités d'un maillage.
Definition: MEDfamilyCr.c:40
MEDmeshCr
MEDC_EXPORT med_err MEDmeshCr(const med_idt fid, const char *const meshname, const med_int spacedim, const med_int meshdim, const med_mesh_type meshtype, const char *const description, const char *const dtunit, const med_sorting_type sortingtype, const med_axis_type axistype, const char *const axisname, const char *const axisunit)
Cette routine permet de créer un maillage dans un fichier.
Definition: MEDmeshCr.c:45
MED_LNAME_SIZE
#define MED_LNAME_SIZE
Definition: med.h:85
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:83
MED_CARTESIAN
Definition: med.h:260
med_utils.h
med.h
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:42
main
int main(int argc, char **argv)
Definition: 3.0.8/test10.c:50