Debian Codegraph @

tests/unittests/c/Test_MEDmeshStructElementVarAttRd.c

raw
1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2020 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 #include <med.h>
20 #define MESGERR 1
21 #include <med_utils.h>
22 #include <string.h>
23
24 #ifdef DEF_LECT_ECR
25 #define MODE_ACCES MED_ACC_RDWR
26 #elif DEF_LECT_AJOUT
27 #define MODE_ACCES MED_ACC_RDEXT
28 #else
29 #define MODE_ACCES MED_ACC_CREAT
30 #endif
31
32 int main (int argc, char **argv)
33
34 {
35 med_err _ret=0;
36 med_idt _fid=0;
37 med_geometry_type _geotype=MED_NONE;
38 int _i=0;
39
40 const char _elementname1[]="MED_BILLE";
41 /* med_int _elementdim1=3; */
42 /* const char _supportmeshname1[]="MED_BILLE_SUPPORT"; */
43 /* med_entity_type _entitytype1=MED_NODE; */
44 /* med_int _nnode1=1; */
45 /* med_int _ncell1=0; */
46 /* med_int _geocelltype1=MED_NONE; */
47
48 const char _varattname1_1[MED_NAME_SIZE+1]="MED_VFOO_ATR1_1";
49 /* const med_attribute_type _varatttype1_1=MED_ATT_INT; */
50 /* const med_int _ncomponent1_1=1; */
51 const med_int _varatrvalue1_1[3]={ 22 , 24, 25 };
52 med_int _read_varatrvalue1_1[3];
53
54 /* const char _varattname1_2[MED_NAME_SIZE+1]="MED_VFOO_ATR1_2"; */
55 /* const med_attribute_type _varatttype1_2=MED_ATT_FLOAT64; */
56 /* const med_int _ncomponent1_2=2; */
57
58 /* const char _varattname1_3[MED_NAME_SIZE+1]="MED_VFOO_ATR1_3"; */
59 /* const med_attribute_type _varatttype1_3=MED_ATT_NAME; */
60 /* const med_int _ncomponent1_3=1; */
61
62 const char _meshname[]="maa1";
63 const med_int _nentity = 3;
64
65 const med_int _con[3]={ 2, 4 ,5}; /* (3 billes dont les centres sont les noeuds 2, 4 et 5 du maillage maa1 )*/
66 med_int _read_con[3];
67
68 /* Ouverture en mode lecture du fichier Test_MEDstructuElement.med */
69 _fid = MEDfileOpen("current.med",MED_ACC_RDONLY);
70 if (_fid < 0) {
71 MESSAGE("Erreur à l'ouverture du fichier current.med");
72 return -1;
73 }
74
75 _geotype = MEDstructElementGeotype(_fid,_elementname1);
76
77 /* lecture des connectivites des éléments de structure */
78 if ( MEDmeshElementConnectivityRd(_fid,_meshname, MED_NO_DT, MED_NO_IT,
79 MED_STRUCT_ELEMENT, _geotype, MED_NODAL,
80 MED_FULL_INTERLACE, _read_con) < 0 ) {
81 MESSAGE("Impossible de lire la connectivité des billes: ");
82 return -1;
83 }
84 for ( _i=0; _i < _nentity; ++_i ) {
85 fprintf(stdout,"Connectivité[%d]=%d.\n",_i,_read_con[_i]);
86 if ( _read_con[_i]!=_con[_i] ) {fprintf(stderr,"Erreur de cohérence de la connectivité lue.\n");return -1;}
87 }
88
89 if (MEDmeshStructElementVarAttRd(_fid,
90 _meshname,
91 MED_NO_DT,
92 MED_NO_IT,
93 _geotype,
94 _varattname1_1,
95 _read_varatrvalue1_1
96 ) < 0 ) {
97 return -1;
98 }
99
100 for ( _i=0; _i < _nentity; ++_i ) {
101 fprintf(stdout,"Vattr[%d]=%d.\n",_i,_read_varatrvalue1_1[_i]);
102 if ( _read_varatrvalue1_1[_i]!=_varatrvalue1_1[_i] ) {
103 fprintf(stderr,"Erreur de cohérence des valeurs"
104 " de l'attribut variable %s.\n",_varattname1_1);
105 return -1;}
106 }
107
108 return _ret;
109
110 }
111