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