MED fichier
UsesCase_MEDfield_15.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  * Field use case 15 : write a field in a MED file with
20  * values defined on struct elements
21  */
22 
23 #include <med.h>
24 #define MESGERR 1
25 #include <med_utils.h>
26 
27 #include <string.h>
28 
29 
30 int main (int argc, char **argv) {
31  med_idt fid=0,mfid=0;
32  const char meshname[MED_NAME_SIZE+1] = "COMPUT_MESH";
33  const char fieldname[MED_NAME_SIZE+1] = "SPEED";
34  const med_int ncomponent = 3;
35  /* 123456789012345612345678901234561234567890123456 */
36  const char componentname[3*MED_SNAME_SIZE+1] = "Vx Vy Vz";
37  const char componentunit[3*MED_SNAME_SIZE+1] = "m/s m/s m/s";
39  const med_int npart = 3;
40  char structelementname[MED_NAME_SIZE+1]="";
41  const med_float part_speed1[3*3] = { 1.1, 2.2, 3.3,
42  4.4, 5.5, 6.6,
43  7.7, 8.8, 9.9 };
44  int ret=-1;
45 
46 
47  /* File creation to write the field */
48  fid = MEDfileOpen("UsesCase_MEDfield_15.med",MED_ACC_CREAT);
49  if (fid < 0) {
50  MESSAGE("ERROR : file creation ...");
51  goto ERROR;
52  }
53 
54  /* Create mesh link */
55  if (MEDlinkWr(fid,meshname,"./UsesCase_MEDstructElement_1.med") < 0) {
56  MESSAGE("ERROR : create mesh link ...");
57  goto ERROR;
58  }
59 
60  /*
61  * Read struct element geometric type
62  */
63  if (( mfid=MEDfileObjectsMount(fid, "UsesCase_MEDstructElement_1.med",MED_ELSTRUCT)) < 0 ) {
64  MESSAGE("ERROR : file mounting ...");
65  goto ERROR;
66  }
67 
68  strcpy(structelementname,MED_PARTICLE_NAME);
69  geotype = MEDstructElementGeotype(fid,structelementname);
70 
71 
72  /*
73  * Speed field creation for particles :
74  * - 3 component
75  * - component unit : m/s
76  * - mesh is the 3D computation mesh of UsesCase_MEDstructElement_1 use case.
77  * - computation step unit in 'ms'
78  */
79  if (MEDfieldCr(fid, fieldname, MED_FLOAT64,
80  ncomponent, componentname, componentunit,
81  "ms", meshname) < 0) {
82  MESSAGE("ERROR : create field");
83  goto ERROR;
84  }
85 
89  npart, (unsigned char*) part_speed1) < 0) {
90  MESSAGE("ERROR : write field values on MED_PARTICLE ");
91  goto ERROR;
92  }
93 
94  if ( MEDfileObjectsUnmount(fid, mfid, MED_ELSTRUCT) < 0 ) {
95  MESSAGE("ERROR : file unmounting ...");
96  goto ERROR;
97  }
98 
99  ret=0;
100  ERROR:
101 
102  /* close file */
103  if (MEDfileClose(fid) < 0) {
104  MESSAGE("ERROR : close file ...");
105  ret=-1;
106  }
107 
108  return ret;
109 }
110 
main
int main(int argc, char **argv)
Definition: UsesCase_MEDfield_15.c:30
med_geometry_type
int med_geometry_type
Definition: med.h:196
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:84
MED_COMPACT_STMODE
Definition: med.h:112
MED_ELSTRUCT
Definition: med.h:191
MED_PARTICLE_NAME
#define MED_PARTICLE_NAME
Definition: med.h:456
med_idt
hid_t med_idt
Definition: med.h:333
MEDfileObjectsMount
MEDC_EXPORT med_idt MEDfileObjectsMount(const med_idt fid, const char *const filename, const med_class medclass)
Cette routine permet de monter dans le fichier courant un type de données (exemples les maillages,...
Definition: MEDfileObjectsMount.c:40
MED_NO_LOCALIZATION
#define MED_NO_LOCALIZATION
Definition: med.h:277
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
MED_FULL_INTERLACE
Definition: med.h:98
med_int
int med_int
Definition: med.h:344
MED_STRUCT_ELEMENT
Definition: med.h:146
MEDfieldValueWithProfileWr
MEDC_EXPORT med_err MEDfieldValueWithProfileWr(const med_idt fid, const char *const fieldname, const med_int numdt, const med_int numit, const med_float dt, const med_entity_type entitype, const med_geometry_type geotype, const med_storage_mode storagemode, const char *const profilename, const char *const localizationname, const med_switch_mode switchmode, const med_int componentselect, const med_int nentity, const unsigned char *const value)
Cette fonction permet d'écrire les valeurs d'un champ définies sur des entités d'un maillage pour une...
Definition: MEDfieldValueWithProfileWr.c:48
med_float
double med_float
Definition: med.h:338
MED_NO_DT
#define MED_NO_DT
Definition: med.h:322
MED_NONE
#define MED_NONE
Definition: med.h:233
MEDstructElementGeotype
MEDC_EXPORT med_geometry_type MEDstructElementGeotype(const med_idt fid, const char *const modelname)
Cette routine renvoie le type géométrique mgeotype associé au modèle d'éléments de structure de nom m...
Definition: MEDstructElementGeotype.c:38
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_FLOAT64
Definition: med.h:168
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:83
MED_ALL_CONSTITUENT
#define MED_ALL_CONSTITUENT
Definition: med.h:301
med_utils.h
MEDfileObjectsUnmount
MEDC_EXPORT med_err MEDfileObjectsUnmount(const med_idt fid, const med_idt mid, const med_class medclass)
Une fois le démontage effectué, les données précédemment montées ne sont plus accessibles.
Definition: MEDfileObjectsUnmount.c:33
MED_NO_PROFILE
#define MED_NO_PROFILE
Definition: med.h:283
MEDfieldCr
MEDC_EXPORT med_err MEDfieldCr(const med_idt fid, const char *const fieldname, const med_field_type fieldtype, const med_int ncomponent, const char *const componentname, const char *const componentunit, const char *const dtunit, const char *const meshname)
Cette fonction crée un champ dans un fichier.
Definition: MEDfieldCr.c:44
MED_UNDEF_DT
#define MED_UNDEF_DT
Definition: med.h:324
med.h
MED_NO_IT
#define MED_NO_IT
Definition: med.h:323
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_ACC_CREAT
Definition: med.h:125
MEDlinkWr
MEDC_EXPORT med_err MEDlinkWr(const med_idt fid, const char *const meshname, const char *const link)
Cette routine permet d'écrire un lien dans un fichier MED.
Definition: MEDlinkWr.c:36