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