MED fichier: Fichier source de Test_MEDfieldInterpWr.c

MED fichier

- Documentation MED
- Guides d'utilisation
- Guides de référence

Test_MEDfieldInterpWr.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2017 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 #include <med.h>
19 #define MESGERR 1
20 #include <med_utils.h>
21 #include <string.h>
22
23 #ifdef DEF_LECT_ECR
24 #define MODE_ACCES MED_ACC_RDWR
25 #elif DEF_LECT_AJOUT
26 #define MODE_ACCES MED_ACC_RDEXT
27 #else
28 #define MODE_ACCES MED_ACC_CREAT
29 #endif
30
31 int main (int argc, char **argv)
32
33 {
34 med_err _ret=-1;
35 med_idt _fid=0;
36
37 char _meshname1[MED_NAME_SIZE+1] = "meshname1";
38 char _axisname[3*MED_SNAME_SIZE+1] = "x y z ";
39 char _unitname[3*MED_SNAME_SIZE+1] = "cm cm cm ";
40
41 char _fieldname1[MED_NAME_SIZE+1] = "champ reel";
42 char _componentname1[2*MED_SNAME_SIZE+1] = "comp1 comp2 ";
43 /*12345678901234561234567890123456*/
44 char _unitname1[2*MED_SNAME_SIZE+1] = "unit1 unit2 ";
45 char _dtunit[MED_SNAME_SIZE+1] = "s";
46 med_int _ncomponentname1 = 2;
47
48
49 /*Exemple 1 :
50
51 - Elément de référence de type géométrique MED_TRIA3
52 - Point X(X1,X2) quelconque dans le plan de l'élément de référence
53 - Fonctions de base : P1(X)=1-X1-X2 ; P2(X)=X1; P3(X)=X2;
54 (issu du choix de la base polynomiale (1,X1,X2)
55 et des trois noeuds de la maille de référence pour
56 construire l'interpolation)
57 */
58 const char _interpname1[] ="interpname1";
59 med_geometry_type _geotype1 =MED_TRIA3;
60
61
62 /* Ouverture en mode creation du fichier "current.med" */
63 _fid = MEDfileOpen("current.med",MODE_ACCES);
64 if (_fid < 0) {
65 MESSAGE("Erreur a la creation du fichier current.med");
66 return -1;
67 }
68
69 /* Creation de _meshname1 de dimension 2 dans un espace de dimension 3*/
70 if (MEDmeshCr( _fid, _meshname1, 3, 2, MED_UNSTRUCTURED_MESH,
71 "Maillage vide","s", MED_SORT_DTIT,
72 MED_CARTESIAN, _axisname, _unitname) < 0) {
73 MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(_meshname1);
74 goto ERROR;
75 }
76
77
78 /* Creation du champ réel n°1 */
79 if ( MEDfieldCr(_fid,_fieldname1,MED_FLOAT64,
80 _ncomponentname1,_componentname1,_unitname1,_dtunit,_meshname1 ) < 0) {
81 MESSAGE("Erreur à la création du champ : ");SSCRUTE(_fieldname1);
82 goto ERROR;
83 };
84
85
86 if ( (_ret = MEDfieldInterpWr(_fid,
87 _fieldname1,
88 _interpname1) <0) ) {
89 MESSAGE("Erreur à l'écriture de la fonction d'interpolation n°1 sur le champ : ");SSCRUTE(_fieldname1);
90 }
91
92
93 ERROR:
94 if (MEDfileClose(_fid) < 0) {
95 MESSAGE("ERROR : file closing");
96 return -1;
97 }
98
99
100 return _ret;
101
102 }
103
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_TRIA3
#define MED_TRIA3
Definition: med.h:198
MED_CARTESIAN
Definition: med.h:253
med_err
herr_t med_err
Definition: med.h:325
MED_SORT_DTIT
Definition: med.h:304
MODE_ACCES
#define MODE_ACCES
Definition: Test_MEDfieldInterpWr.c:28
MEDfieldInterpWr
MEDC_EXPORT med_err MEDfieldInterpWr(const med_idt fid, const char *const fieldname, const char *const interpname)
Cette routine associe une fonction d'interpolation interpname au champ résultat fieldname.
Definition: MEDfieldInterpWr.c:36
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:316
MED_UNSTRUCTURED_MESH
Definition: med.h:127
med.h
med_int
int med_int
Definition: med.h:335
MED_FLOAT64
Definition: med.h:161
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
main
int main(int argc, char **argv)
Definition: Test_MEDfieldInterpWr.c:31
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:41
med_idt
hid_t med_idt
Definition: med.h:324
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:77
med_utils.h
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:78
med_geometry_type
int med_geometry_type
Definition: med.h:189
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:315
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