Salome HOME
To avoid compilation pb on RedHat 8.0.
[modules/kernel.git] / src / HDFPersist / HDFattrCreate.c
1 // Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
2 //           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 // 
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 // 
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 // 
19 /*----------------------------------------------------------------------------
20 SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
21   File   : HDFattrCreate.c
22   Module : SALOME
23 ----------------------------------------------------------------------------*/
24
25 #include "hdfi.h"
26
27 /*
28  * - Name : HDFattrCreate
29  * - Description : create a HDF attribute
30  * - Parameters :
31  *     - pid (IN) : father ID
32  *     - name (IN) : attribute name
33  *     - type (IN) : attribute type
34  * - Result: 
35  *     - if success : attribute ID 
36  *     - if failure : -1
37  */
38 hdf_idt HDFattrCreate(hdf_idt pid,char *name,hdf_type type, size_t size)
39 {
40   hdf_idt aid,attr;
41   hdf_err ret;
42   int type_hdf;
43
44   switch(type) {
45   case HDF_FLOAT64 :
46 #ifdef PCLINUX
47     type_hdf = H5T_IEEE_F64BE;
48 #else 
49     type_hdf = H5T_IEEE_F64LE;
50 #endif
51     break;
52     
53   case HDF_INT32 :
54 #ifdef PCLINUX
55     type_hdf = H5T_STD_I32BE;  
56 #else
57     type_hdf = H5T_NATIVE_INT;
58 #endif
59     break;
60     
61   case HDF_INT64 :
62     type_hdf = H5T_NATIVE_LONG;
63     break;
64
65   case HDF_STRING :           
66     if((type_hdf = H5Tcopy(H5T_C_S1)) < 0)
67       return -1;
68     if((ret = H5Tset_size(type_hdf, size)) < 0)
69       return -1;
70     break;
71     
72   default :
73     return -1;
74   }
75
76   if ((aid = H5Screate(H5S_SCALAR)) < 0)
77     return -1;
78   
79   if ((attr = H5Acreate(pid,name,type_hdf,aid,H5P_DEFAULT)) < 0)
80     return -1;
81   
82   if ((ret = H5Sclose(aid)) < 0)
83     return -1;
84   
85   return attr;
86 }