Salome HOME
26e77a915869bfb834db86142400e56138b0cc03
[modules/kernel.git] / src / HDFPersist / test1.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   : test1.c
22   Module : SALOME
23 ----------------------------------------------------------------------------*/
24
25 #include"hdfi.h"
26 #include<stdlib.h>
27
28 int main() {
29   hdf_idt fid,gid,did,atid;
30   hdf_err ret;
31   hdf_size size[1];
32   hdf_int32 data[10] = { 1,2,3,4,5,6,7,8,9,10};
33   hdf_int32 attr_val = 2; 
34   
35   system("rm titi.HDF");
36
37   HDFerrorModeLock();
38   
39   if  ((fid = HDFfileCreate("titi.HDF")) < 0)
40     return -1;
41   MESSAGE("Creation du fichier")
42
43   if ((gid = HDFgroupCreate(fid,"GROUP")) < 0)
44     return -1;
45   MESSAGE("Creation d'un groupe")
46
47   if ((atid = HDFattrCreate(gid,"ATTR",HDF_INT32))< 0)
48     return -1;
49   MESSAGE("Creation d'un attribut")
50
51   if ((ret = HDFattrWrite(atid,&attr_val)) < 0)
52     return -1;
53   MESSAGE("Ecriture de l'attribut")
54  
55   if ((ret = HDFattrClose(atid))  < 0)
56     return -1;
57   MESSAGE("Fermeture de l'attribut")
58
59   size[0] = 10;
60   if ((did = HDFdatasetCreate(gid,"DATASET",HDF_INT32,size)) < 0)
61     return -1;
62   MESSAGE("Creation d'un dataset")
63
64   if ((ret = HDFdatasetWrite(did,data)) < 0)
65     return -1;
66   MESSAGE("Ecriture du dataset")
67
68   if ((ret = HDFdatasetClose(did)) < 0)
69     return -1;
70   MESSAGE("Fermeture du datset")
71
72   if ((ret = HDFgroupClose(gid)) < 0)
73     return -1;
74   MESSAGE("Fermeture du groupe")
75
76   if ((ret = HDFfileClose(fid)) < 0)
77     return ret; 
78   MESSAGE("Fermeture du fichier")
79
80   if  ((fid = HDFfileCreate("toto.HDF")) < 0)
81     return -1;
82   MESSAGE("Creation du fichier")
83
84   if ((ret = HDFfileClose(fid)) < 0)
85     return ret; 
86   MESSAGE("Fermeture du fichier")
87   
88   
89   return 0;
90 }