MED fichier
test4.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 /******************************************************************************
20  * - Nom du fichier : test4.c
21  *
22  * - Description : ecriture des noeuds d'un maillage MED.
23  *
24  *****************************************************************************/
25 
26 #include <med.h>
27 #define MESGERR 1
28 #include <med_utils.h>
29 
30 
31 #ifdef DEF_LECT_ECR
32 #define MODE_ACCES MED_ACC_RDWR
33 #elif DEF_LECT_AJOUT
34 #define MODE_ACCES MED_ACC_RDEXT
35 #else
36 #define MODE_ACCES MED_ACC_CREAT
37 #endif
38 
39 
40 int main (int argc, char **argv)
41 
42 
43 {
44  med_err ret = 0;
45  med_idt fid;
46  /* la dimension du maillage */
47  med_int mdim = 2;
48  /* nom du maillage de longueur maxi MED_NAME_SIZE */
49  char maa[MED_NAME_SIZE+1] = "maa1";
50  /* le nombre de noeuds */
51  med_int nnoe = 4;
52  /* table des coordonnees
53  (dimension * nombre de noeuds) */
54  med_float coo[8] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};
55  med_float coo_2[8] = {0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0};
56  /* tables des noms et des unites des coordonnees
57  (dimension*MED_SNAME_SIZE+1) */
58  /* 12345678901234561234567890123456*/
59  char nomcoo[2*MED_SNAME_SIZE+1] = "x y ";
60  char unicoo[2*MED_SNAME_SIZE+1] = "cm cm ";
61  /* tables des noms, numeros, numeros de familles des noeuds
62  autant d'elements que de noeuds - les noms ont pout longueur
63  MED_SNAME_SIZE */
64  /* 1234567890123456123456789012345612345678901234561234567890123456*/
65  char nomnoe[4*MED_SNAME_SIZE+1] = "nom1 nom2 nom3 nom4 ";
66  med_int numnoe[4] = {1,2,3,4};
67  med_int nufano[4] = {0,1,2,2};
68 
69  /* Creation du fichier "test4.med" */
70  /* ouverture du fichier */
71  if ((fid = MEDfileOpen("test4.med",MODE_ACCES)) < 0){
72  MESSAGE("Erreur à l'ouverture du fichier : ");
73  return -1;
74  }
75 
76  /* Creation du maillage "maa" de type MED_NON_STRUCURE
77  et de dimension 2 */
78  if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH,
79  "un maillage pour test4","s", MED_SORT_DTIT,
80  MED_CARTESIAN, nomcoo, unicoo) < 0) {
81  MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa);
82  ret = -1;
83  }
84 
85  /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE :
86  (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */
88  MED_FULL_INTERLACE,nnoe, coo) < 0) {
89  MESSAGE("Erreur a l'ecriture des coordonnees des noeuds");
90  ret = -1;
91  }
92 
93  /* Ecriture des attributs des noeuds du maillage */
94  if (MEDmeshAttributeWr(fid,maa, 0, nnoe, 0) < 0 ) {
95  MESSAGE("Erreur a l'ecriture des attributs des noeuds du maillage");
96  ret = -1;
97  }
98 
99  /* Ecriture des noms des noeuds (optionnel dans un maillage MED) */
100  if (MEDmeshEntityNameWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nomnoe) < 0) {
101  MESSAGE("Erreur a l'ecriture des noms des noeuds");
102  ret = -1;
103  }
104 
105  /* Ecriture des numeros des noeuds (optionnel dans un maillage MED) */
106  if (MEDmeshEntityNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,numnoe) < 0) {
107  MESSAGE("Erreur a l'ecriture des numeros des noeuds");
108  ret = -1;
109  }
110 
111  /* Ecriture des numeros de famille des noeuds */
112  if (MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nufano) < 0) {
113  MESSAGE("Erreur a l'ecriture des numeros de familles des noeuds");
114  ret = -1;
115  }
116 
117  /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE :
118  (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */
119  if (MEDmeshNodeCoordinateWr(fid,maa,0,5,0.5,
120  MED_FULL_INTERLACE,nnoe, coo_2) < 0) {
121  MESSAGE("Erreur a l'ecriture des coordonnees des noeuds");
122  ret = -1;
123  }
124 
125  /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE :
126  (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */
127  if (MEDmeshNodeCoordinateWr(fid,maa,2,0,2.0,
128  MED_FULL_INTERLACE,nnoe, coo) < 0) {
129  MESSAGE("Erreur a l'ecriture des coordonnees des noeuds");
130  ret = -1;
131  }
132 
133  /*TODO : Ecrire un test de comparaison next prev et ordre de découverte itératif */
134  MEDmeshComputationStepCr(fid,maa,-1,-1,0,2,0.25);
135 
136  MEDmeshComputationStepCr(fid,maa,0,2,0,3,0.35);
137 
138  /* Fermeture du fichier */
139  if (MEDfileClose(fid) < 0) {
140  MESSAGE("Erreur a la fermeture du fichier test4.med");
141  return -1;
142  }
143  return ret;
144 }
145 
146 
147 
148 
MED_CARTESIAN
Definition: med.h:258
MEDmeshEntityNumberWr
MEDC_EXPORT med_err MEDmeshEntityNumberWr(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_int nentity, const med_int *const number)
Cette routine permet d'écrire les numéros d'un type d'entité d'un maillage.
Definition: MEDmeshEntityNumberWr.c:39
MED_FULL_INTERLACE
Definition: med.h:96
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: test4.c:35
MEDmeshEntityNameWr
MEDC_EXPORT med_err MEDmeshEntityNameWr(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_int nentity, const char *const name)
Cette routine permet d'écrire les noms d'un type d'entité d'un maillage.
Definition: MEDmeshEntityNameWr.c:39
MEDmeshEntityFamilyNumberWr
MEDC_EXPORT med_err MEDmeshEntityFamilyNumberWr(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_int nentity, const med_int *const number)
Cette routine permet l'écriture des numéros de famille d'un type d'entité d'un maillage.
Definition: MEDmeshEntityFamilyNumberWr.c:39
med_err
herr_t med_err
Definition: med.h:332
MEDmeshComputationStepCr
MEDC_EXPORT med_err MEDmeshComputationStepCr(const med_idt fid, const char *const meshname, const med_int numdt1, const med_int numit1, const med_int numdt2, const med_int numit2, const med_float dt2)
Cette routine permet de créer une nouvelle étape de calcul dans un maillage.
Definition: MEDmeshComputationStepCr.c:40
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:342
med.h
med_float
double med_float
Definition: med.h:336
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
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
MEDmeshNodeCoordinateWr
MEDC_EXPORT med_err MEDmeshNodeCoordinateWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_float dt, const med_switch_mode switchmode, const med_int nentity, const med_float *const coordinates)
Cette routine permet d'écrire dans un maillage le tableau des coordonnées des noeuds,...
Definition: MEDmeshNodeCoordinateWr.c:45
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
MED_UNSTRUCTURED_MESH
Definition: med.h:131
MEDmeshAttributeWr
MEDC_EXPORT med_err MEDmeshAttributeWr(const med_idt fid, const char *const meshname, const med_int isolatednodes, const med_int verticesnodes, const med_int cellmaxnodes)
Cette routine permet l'écriture des attributs optionnels d'un maillage.
Definition: MEDmeshAttributeWr.c:35
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
main
int main(int argc, char **argv)
Definition: test4.c:39
MED_UNDEF_DT
#define MED_UNDEF_DT
Definition: med.h:322
MED_NO_IT
#define MED_NO_IT
Definition: med.h:321
med_utils.h