MED fichier
test19.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2023 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 : test19.c
20  *
21  * - Description : conversion groupes => famille
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;
43  char maa[MED_NAME_SIZE+1] = "maillage_test19";
44  char desc[MED_COMMENT_SIZE+1]="un maillage pour test19.med";
45  med_int mdim=2;
46  /* Donnees de tests pour MEDgro2FamCr()
47  Les noeuds/mailles sont numerotes de 1 a 5 et les
48  groupes de 1 a 3.
49  Au depart, on a :
50  - G1 : 1,2
51  - G2 : 3,4,6
52  - G3 : 1,4
53  Au retour, on foit avoir 4 familles de noeuds + 4 familles de mailles
54  + la famille 0 dans le fichier :
55  - F0 : 5 - groupes : aucun groupe par defaut (convention habituelle).
56  - F1 : 1 - groupes : G1,G3
57  - F2 : 2 - groupes : G1
58  - F3 : 3,6 - groupes : G2
59  - F4 : 4 - groupes : G2,G3
60  */
61  med_int ngroup = 3;
62  med_int nent = 6;
63  char nom_groupes[MED_LNAME_SIZE*3+1];
64  /* 0 1 2 3 4 5 6 */
65  med_int entites[7] = { 1,2, 3,4,6, 1,4};
66  med_int index[4] = { 1, 3, 6, 8};
67  int i;
68  char nom_famille0[MED_NAME_SIZE+1] = "FAMILLE0";
69  /* on fait la meme distribution pour des mailles */
70  med_int ngeo = 3;
72  /* MED_SEG2 : M1,M2,M3 - MED_TRI3 : M4,M5 - MED_TETRA4 : M6 */
73  med_int index_geo[4] = {1,4,6,7};
74 
75  /* Creation du fichier test19.med */
76  if ((fid = MEDfileOpen("test19.med",MODE_ACCES)) < 0) {
77  MESSAGE("Erreur a la creation du fichier test19.med");
78  return -1;
79  }
80  printf("Creation du fichier test19.med \n");
81 
82  /* Creation du maillage */
83  if (MEDmaaCr(fid,maa,mdim,MED_UNSTRUCTURED_MESH,desc) < 0) {
84  MESSAGE("Erreur a la creation du maillage");
85  return -1;
86  }
87  printf("Creation du maillage \n");
88 
89  /* on teste la fonction MEDgro2fam() */
90  /* on definit les noms des groupes */
91  strcpy(nom_groupes,"GROUPE 1");
92  for (i=8;i<MED_LNAME_SIZE;i++)
93  nom_groupes[i] = ' ';
94  nom_groupes[MED_LNAME_SIZE] = '\0';
95  strcat(nom_groupes,"GROUPE 2");
96  for (i=8;i<MED_LNAME_SIZE;i++)
97  nom_groupes[MED_LNAME_SIZE+i] = ' ';
98  nom_groupes[2*MED_LNAME_SIZE] = '\0';
99  strcat(nom_groupes,"GROUPE 3");
100  for (i=8;i<MED_LNAME_SIZE;i++)
101  nom_groupes[2*MED_LNAME_SIZE+i] = ' ';
102  nom_groupes[3*MED_LNAME_SIZE] = '\0';
103 
104  /* On cree la famille 0 */
105  if (MEDfamCr(fid,maa,nom_famille0,0,NULL,NULL,NULL,0,NULL,0) < 0) {
106  MESSAGE("Erreur a la creation de la famille 0");
107  return -1;
108  }
109  printf("Creation de la famille 0 \n");
110 
111  /*
112  * On definit et on archive les familles de noeuds dans test.19.med
113  */
114  if (MEDgro2famCr(fid,maa,nom_groupes,index,ngroup,entites,nent,
115  MED_NODE,NULL,NULL,0) < 0) {
116  MESSAGE("Erreur a la creation des familles de noeuds ");
117  return -1;
118  }
119  printf("On constuit les familles de noeuds et on les stocke dans test19.med \n");
120 
121  /*
122  * On fait la meme chose pour des mailles de differents types
123  */
124  if (MEDgro2famCr(fid,maa,nom_groupes,index,ngroup,entites,nent,
125  MED_CELL,geo,index_geo,ngeo) < 0) {
126  MESSAGE("Erreur a la creation des familles d'elements ");
127  return -1;
128  }
129  printf("On constuit les familles d'elements et on les stocke dans test19.med \n");
130 
131  /* Fermeture du fichier */
132  if (MEDfermer(fid) <0) {
133  MESSAGE("Erreur a la fermeture du fichier");
134  return -1;
135  }
136  printf("Fermeture du fichier \n");
137 
138  return 0;
139 }
MED_TRIA3
#define MED_TRIA3
Definition: med.h:205
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition: med.h:81
MED_UNSTRUCTURED_MESH
Definition: med.h:133
med_geometry_type
int med_geometry_type
Definition: med.h:196
med_idt
hid_t med_idt
Definition: med.h:333
MED_SEG2
#define MED_SEG2
Definition: med.h:202
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:344
main
int main(int argc, char **argv)
Definition: test19.c:37
MED_TETRA4
#define MED_TETRA4
Definition: med.h:212
MED_CELL
Definition: med.h:145
MED_LNAME_SIZE
#define MED_LNAME_SIZE
Definition: med.h:85
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:83
MODE_ACCES
#define MODE_ACCES
Definition: test19.c:34
med_utils.h
MED_NODE
Definition: med.h:145
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