1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2019 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 #include <med_config.h>
21 #include <med_outils.h>
22 #include <hdf5.h>
23
_MEDattributeStringRdByName(med_idt pid,const char * const path,const char * const attname,const med_size attsize,char * const val)24 med_err _MEDattributeStringRdByName(med_idt pid,
25 const char * const path,
26 const char * const attname,
27 const med_size attsize,
28 char * const val)
29 {
30 med_err _ret=-1;
31 med_idt _attid=0;
32 med_idt type_hdf=0;
33
34 if ( (type_hdf = H5Tcopy(H5T_C_S1)) < 0) {
35 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_HDFTYPE, MED_ERR_NAME_MSG );
36 SSCRUTE("H5T_C_S1"); goto ERROR;
37 }
38
39 if ( H5Tset_size(type_hdf,attsize+1) < 0) {
40 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_HDFTYPE, MED_ERR_NAME_MSG );
41 SSCRUTE("H5T_C_S1"); goto ERROR;
42 }
43
44 if ( (_attid=H5Aopen_by_name( pid, path, attname, H5P_DEFAULT, H5P_DEFAULT )) < 0 ) {
45 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_ATTRIBUTE, MED_ERR_NAME_MSG );
46 SSCRUTE(attname); SSCRUTE(path);goto ERROR;
47 }
48
49 if ( H5Aread(_attid,type_hdf,val) < 0 ) {
50 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE, MED_ERR_NAME_MSG );
51 SSCRUTE(attname); SSCRUTE(path);goto ERROR;
52 }
53
54 _ret=0;
55
56 ERROR:
57
58 if (type_hdf >0) if ( H5Tclose(type_hdf) < 0) {
59 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_HDFTYPE, MED_ERR_ID_MSG );
60 ISCRUTE_id(type_hdf);
61 }
62
63 if (_attid >0) if ( H5Aclose(_attid) < 0) {
64 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_ATTRIBUTE, MED_ERR_ID_MSG );
65 ISCRUTE_id(_attid);
66 }
67
68 return _ret;
69 }
70