Salome HOME
Base implementation of Notebook
[modules/kernel.git] / src / HDFPersist / test2.c
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*----------------------------------------------------------------------------
23 SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
24   File   : test2.c
25   Module : SALOME
26 ----------------------------------------------------------------------------*/
27
28 #include"hdfi.h"
29 #include<stdlib.h>
30
31 int main() {
32   hdf_idt fid,gid,did,atid;
33   hdf_err ret;
34   hdf_size size[1];
35   hdf_int32 data[10];
36   int attr_val;
37   int i;
38
39   HDFerrorModeLock();
40   
41   if  ((fid = HDFfileOpen("titi.HDF",HDF_RDONLY)) < 0)
42     return -1;
43   MESSAGE("Ouverture du fichier")
44
45   if ((gid = HDFgroupOpen(fid,"GROUP")) < 0)
46     return -1;
47   MESSAGE("Ouverture du goupe")
48
49   if ((atid = HDFattrOpen(gid,"ATTR"))< 0)
50     return -1;
51   MESSAGE("Ouverture de l'attribut du goupe")
52
53   if ((ret = HDFattrRead(atid,&attr_val)) < 0) 
54     return -1;
55   MESSAGE("Lecture de l'attribut du goupe : " << attr_val)
56
57   if ((ret = HDFattrClose(atid))  < 0)
58     return -1;
59   MESSAGE("Fermeture de l'attribut du goupe")
60
61   if ((did = HDFdatasetOpen(gid,"DATASET")) < 0)
62     return -1;
63   MESSAGE("Ouverture du dataset")
64
65   if ((ret = HDFdatasetRead(did,data)) < 0)
66     return -1;
67   MESSAGE("Lecture du dataset")
68   for (i=0;i<10;i++)
69     MESSAGE(data[i])
70
71   if ((ret = HDFdatasetClose(did)) < 0)
72     return -1;
73   MESSAGE("Fermeture du dataset")
74
75   if ((ret = HDFgroupClose(gid)) < 0)
76     return -1;
77   MESSAGE("Fermeture du groupe")
78   
79   if ((ret = HDFfileClose(fid)) < 0)
80     return ret;
81   MESSAGE("Fermeture du fichier")
82   
83   return 0;
84 }