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 
24 /*
25  * - Nom de la fonction : _MEDattrStringEcrire
26  * - Description : ecriture d'un attribut chaine de caracteres
27  * - Parametres :
28  *     - pere (IN)     : l'ID de l'objet HDF pere ou placer l'attribut
29  *     - nom  (IN)     : le nom de l'attribut
30  *     - longueur (IN) : strlen(val)
31  *     - val  (IN)     : la valeur de l'attribut
32  * - Resultat : 0 en cas de succes, -1 sinon
33  */
_MEDattrStringEcrire(med_idt pere,char * nom,int longueur,char * val)34 med_err _MEDattrStringEcrire(med_idt pere,char * nom,int longueur, char * val)
35 {
36   med_idt aid,attr, datatype;
37   med_err ret;
38   med_mode_acces MED_MODE_ACCES;
39 
40  if ( (MED_MODE_ACCES = _MEDmodeAcces(pere) ) == MED_UNDEF_MODE_ACCES ) {
41     MESSAGE("Impossible de déterminer le mode d'acces au fichier.");
42     return -1;
43   }
44 
45   if ((aid = H5Screate(H5S_SCALAR)) < 0)
46     return -1;
47   if((datatype = H5Tcopy(H5T_C_S1)) < 0)
48     return -1;
49   if((ret = H5Tset_size(datatype,longueur+1)) < 0)
50     return -1;
51 
52   if ( ((attr = H5Aopen_name(pere,nom)) >= 0)
53        && ( MED_MODE_ACCES == MED_LECTURE_AJOUT) )
54     return -1;
55   else
56     if ( attr < 0)
57       if ((attr = H5Acreate(pere,nom,datatype,aid,H5P_DEFAULT)) < 0) return -1;
58 
59   if ((ret = H5Awrite(attr, datatype, val)) < 0)
60     return -1;
61 
62   if ((ret = H5Sclose(aid)) < 0)
63     return -1;
64   if ((ret = H5Tclose(datatype)) < 0)
65     return -1;
66   if ((ret = H5Aclose(attr)) < 0)
67     return -1;
68 
69   return 0;
70 }
71