MED fichier
test8.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  * - Nom du fichier : test8.c
20  *
21  * - Description : exemple d'ecriture de familles dans un maillage MED
22  *
23  *****************************************************************************/
24 
25 #include <med.h>
26 #define MESGERR 1
27 #include "med_utils.h"
28 #include <string.h>
29 
30 #ifdef DEF_LECT_ECR
31 #define MODE_ACCES MED_ACC_RDWR
32 #elif DEF_LECT_AJOUT
33 #define MODE_ACCES MED_ACC_RDEXT
34 #else
35 #define MODE_ACCES MED_ACC_CREAT
36 #endif
37 
38 int main (int argc, char **argv)
39 
40 
41 {
42  med_idt fid = 0;
43  char maa[MED_NAME_SIZE+1] ="maa1";
44  med_int mdim = 2;
45  char nomfam[MED_NAME_SIZE+1]="";
46  med_int numfam;
47  med_int ngro;
48  char gro[MED_LNAME_SIZE+1]="";
49  int i;
50  int nfame = 3;
51  int nfamn = 2;
52  char nomcoo[2*MED_SNAME_SIZE+1] = "x y ";
53  char unicoo[2*MED_SNAME_SIZE+1] = "cm cm ";
54 
55  /* Creation du fichier "test8.med" */
56  if ((fid = MEDfileOpen("test8.med",MODE_ACCES)) < 0) {
57  MESSAGE("Erreur a la creation du fichier test8.med");
58  return -1;
59  }
60 
61  if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH,
62  "un maillage pour test8","s", MED_SORT_DTIT,
63  MED_CARTESIAN, nomcoo, unicoo) < 0) {
64  MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa);
65  return -1;
66  }
67 
68  /* Ecriture des familles */
69  /* Conventions appliquees dans MED :
70  - Toujours creer une famille de numero 0 ne comportant aucun attribut
71  ni groupe (famille de reference pour les noeuds ou les elements
72  qui ne sont rattaches a aucun groupe ni attribut)
73  - Les numeros de familles de noeuds sont > 0
74  - Les numeros de familles des elements sont < 0
75  - Rien d'imposer sur les noms de familles.
76  */
77 
78  /* Creation de la famille 0 */
79  strcpy(nomfam,"FAMILLE_0");
80  numfam = 0;
81  if (MEDfamilyCr(fid,maa,nomfam,numfam,0,"") < 0) {
82  MESSAGE("Erreur a la creation de la famille 0");
83  return -1;
84  }
85 
86  /* Creation pour correspondre aux cas test precedent de :
87  - 3 familles d'elements (-1,-2,-3)
88  - 2 familles de noeuds (1,2) */
89  nfame = 3;
90  for (i=0;i<nfame;i++) {
91  numfam = -(i+1);
92  sprintf(nomfam,"%s"IFORMAT,"FAMILLE_ELEMENT_",-numfam);
93  strcpy(gro,"groupe1");
94  ngro = 1;
95  printf("%s - "IFORMAT" - "IFORMAT" \n",nomfam,numfam,
96  ngro);
97  if (MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro) < 0) {
98  MESSAGE("Erreur a la creation de la famille :");
99  SSCRUTE(nomfam); ISCRUTE(numfam);
100  return -1;
101  }
102  }
103 
104  nfamn = 2;
105  for (i=0;i<nfamn;i++) {
106  numfam = i+1;
107  sprintf(nomfam,"%s"IFORMAT,"FAMILLE_NOEUD_",numfam);
108  strcpy(gro,"groupe1");
109  ngro = 1;
110  if (MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro) < 0) {
111  MESSAGE("Erreur a la creation de la famille :");
112  SSCRUTE(nomfam); ISCRUTE(numfam);
113  return -1;
114  }
115  }
116 
117 
118  /* Fermeture du fichier */
119  if (MEDfileClose(fid) < 0) {
120  MESSAGE("Erreur a la fermeture du fichier :");
121  return -1;
122  }
123 
124  return 0;
125 }
126 
127 
128 
129 
MED_CARTESIAN
Definition: med.h:258
MED_SORT_DTIT
Definition: med.h:309
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
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_idt
hid_t med_idt
Definition: med.h:331
MODE_ACCES
#define MODE_ACCES
Definition: test8.c:34
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:342
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
med.h
ISCRUTE
#define ISCRUTE(entier)
Definition: med_utils.h:313
IFORMAT
#define IFORMAT
Definition: med_utils.h:145
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
main
int main(int argc, char **argv)
Definition: test8.c:37
MED_LNAME_SIZE
#define MED_LNAME_SIZE
Definition: med.h:83
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
MED_UNSTRUCTURED_MESH
Definition: med.h:131
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
med_utils.h