Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.git] / src / HDFPersist / test6.cxx
1 //  SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : test6.cxx
25 //  Module : SALOME
26
27 using namespace std;
28 #include <iostream.h>
29 #include "HDFOI.hxx"
30 #include <stdlib.h>
31
32 int main()
33 {
34   HDFfile *study;
35   HDFgroup *geom, *mesh;
36   HDFgroup *geom1, *geom2, *mesh1, *mesh2;
37   int n,m,i;
38   char name[HDF_NAME_MAX_LEN+1];
39
40   try
41     {
42       // the groups 'GEOM' and 'MESH' become mounted points for
43       // the files 'geom.hdf' and 'mesh.hdf' in the 'study.hdf' file
44
45       study = new HDFfile("study.hdf");
46       MESSAGE( ">> The HDFfile object for 'study.hdf' is created" );
47
48       study->OpenOnDisk(HDF_RDONLY);
49       MESSAGE( "--> The file is opened" );
50
51       geom = new HDFgroup("GEOM",study);
52       MESSAGE( ">> The HDFgroup object for 'GEOM' is created" );
53
54       geom->FileMount("geom.hdf",HDF_RDONLY);
55       MESSAGE( ">> 'GEOM' becomes a mounted point for the file 'geom.hdf'" );
56
57       geom->OpenOnDisk();
58       MESSAGE( "--> The group is opened" );
59
60       m = geom->nInternalObjects();
61       MESSAGE( "--> There are " << m << " objects in the group" );
62       
63       for (i=0;i<m;i++) 
64         {
65           geom->InternalObjectIndentify(i,name);
66           MESSAGE( "--> First Level Internal Object Name : " << name );
67         }        
68
69       geom1 = new HDFgroup("GEOM_1",geom);
70       MESSAGE( ">> The HDF group object is created for 'GEOM_1' with 'GEOM' as father" );
71       MESSAGE( "--> This group is in fact in the file 'geom.hdf'");
72
73       geom1->OpenOnDisk();
74       MESSAGE( "-> The group 'GEOM_1' is opened" );
75
76       geom1->CloseOnDisk();
77       MESSAGE( "-> The group 'GEOM_1' is closed" );
78
79       geom2 = new HDFgroup("GEOM_2",geom);
80       MESSAGE( ">> The HDF group object is created for 'GEOM_2' with 'GEOM' as father" );
81       MESSAGE( "--> This group is in fact in the file 'geom.hdf'");      
82
83       geom2->OpenOnDisk();
84       MESSAGE( "-> The group 'GEOM_2' is opened" );
85
86       geom2->CloseOnDisk();
87       MESSAGE( "-> The group 'GEOM_2' is closed" );
88
89       geom->CloseOnDisk();
90       MESSAGE( "-> The group 'GEOM' is closed" );
91
92       geom->FileUnMount();
93       MESSAGE( ">> The file 'geom.hdf' is unmounted from 'GEOM' " ); 
94
95       mesh = new HDFgroup("MESH",study);
96
97       mesh->FileMount("mesh.hdf",HDF_RDONLY);
98
99       mesh->OpenOnDisk();
100
101       mesh1 = new HDFgroup("MESH_1",mesh);
102
103       mesh1->OpenOnDisk();
104
105       mesh1->CloseOnDisk();
106
107       mesh2 = new HDFgroup("MESH_2",mesh);
108
109       mesh2->OpenOnDisk();
110
111       mesh2->CloseOnDisk();
112
113       mesh->CloseOnDisk();
114
115       mesh->FileUnMount();
116
117       MESSAGE( ">> The same operations have been done for the file 'mesh.hdf'" )
118       MESSAGE( "   and the groups MESH_1 and MESH_2" )
119       MESSAGE( "--> This file has been mounted on the group 'MESH' of the file 'study.hdf' ")
120               
121       study->CloseOnDisk();
122       MESSAGE( ">> The study.hdf file is closed" );
123
124       MESSAGE( ">> Memory clean" );
125       delete mesh1;
126       delete mesh2;
127       delete mesh;
128       delete geom1;
129       delete geom2;
130       delete geom;
131       delete study;
132     }
133   catch(HDFexception)
134     {
135       MESSAGE( "!!! HDFexception !!! ")
136     }
137   return 0;
138 }