Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/yacs.git] / src / HDFPersist / test3.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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : test3.cxx
25 //  Module : SALOME
26
27 #include <iostream.h>
28 #include "HDFOI.hxx"
29 #include <stdlib.h>
30 using namespace std;
31
32
33 int main()
34 {
35   HDFfile *hdf_file;
36   HDFgroup *hdf_group;
37   HDFdataset *hdf_dataset;
38   HDFdataset *hdf_dataset2;
39   HDFattribute *hdf_attribute;
40   hdf_size size[1];
41   hdf_float64 coordinates[3] = {5.,-6.9,4.2};
42   hdf_int32 unit[3] = {0,0,0};
43   char message[HDF_NAME_MAX_LEN+1] = "MESSAGE";
44   hdf_int32 attribute = 3;
45   HDFexplorer *explorer;
46   HDFinternalObject *object;
47
48   system("rm file_test3.hdf");
49
50   try
51     {
52       // a new HDFfile object
53       hdf_file = new HDFfile("file_test3.hdf");
54       MESSAGE( ">> A HDFfile object is created" );
55       
56       hdf_file->CreateOnDisk();
57       MESSAGE( ">> The HDF file is created on Disk " );
58
59       // Inside the HDF file 
60
61       // A new HDF group object
62       hdf_group = new HDFgroup("MESH",hdf_file);
63       MESSAGE( ">> A HDFgroup object 'MESH' is created" );
64
65       hdf_group->CreateOnDisk();
66       MESSAGE( ">> The HDF group is created on Disk " );
67
68       // Inside the HDF group  
69       
70       // A new HDF dataset object
71       // size of each dimension, only one in the example
72       size[0] = 3;
73       hdf_dataset = new HDFdataset("COORDINATES",hdf_group,HDF_FLOAT64,size,1);
74       MESSAGE( ">> A HDFdataset object 'COORDINATES' is created" );
75
76       hdf_dataset->CreateOnDisk();
77       MESSAGE( ">> The HDF dataset is created on Disk " );
78
79       // a HDFattribute object inside the dataset
80       hdf_attribute = new HDFattribute("ATTRIBUTE",hdf_dataset,HDF_INT32);
81       MESSAGE( ">> A HDF attribute  object is created for the dataset " );
82
83       hdf_dataset->WriteOnDisk(coordinates);
84       MESSAGE( ">> The HDF dataset is written on Disk " );
85
86       hdf_attribute->CreateOnDisk();
87       MESSAGE( ">> The HDF attribute is created on Disk " );
88
89       hdf_attribute->WriteOnDisk(&attribute); 
90       MESSAGE( ">> The HDF attribute is written on Disk " );
91       
92       hdf_attribute->CloseOnDisk();
93       MESSAGE( ">> The HDF attribute closed on Disk " );  
94
95       hdf_dataset->CloseOnDisk();
96       MESSAGE( ">> The HDF dataset is closed on Disk " );
97
98       // A new dataset is created
99       size[0] = 3;
100       hdf_dataset2 = new HDFdataset("UNIT",hdf_group,HDF_INT32,size,1);
101       MESSAGE( ">> A second HDFdataset object 'UNIT' is created" );
102
103       hdf_dataset2->CreateOnDisk();
104       MESSAGE( ">> The HDF dataset is created on Disk " );
105
106       hdf_dataset2->WriteOnDisk(unit);
107       MESSAGE( ">> The HDF dataset is written on Disk " );
108
109       hdf_dataset2->CloseOnDisk();
110       MESSAGE( ">> The HDF dataset is closed on Disk " );
111
112       // The HDF group is built, it can be closed
113       hdf_group->CloseOnDisk();
114       MESSAGE( ">> The HDF group is closed on Disk " );
115
116       // The HDF file is built, it can be closed
117       hdf_file->CloseOnDisk();
118       MESSAGE( ">> The HDF file is closed on disk" );
119
120       // Explorer
121       explorer = new HDFexplorer(hdf_file);
122       MESSAGE( ">> A HDF explorer object is created" );
123
124       MESSAGE( ">> File Exploration " );
125       for (explorer->Init();explorer->More();explorer->Next())
126         {
127           object = explorer->Value();
128           MESSAGE( "--> Name of the object : " << object->GetName() );
129           switch (object->GetObjectType())
130             {
131             case HDF_FILE :
132               MESSAGE( "--> Type of the object : HDF_FILE : " );
133               break;
134
135             case HDF_GROUP :
136               MESSAGE( "--> Type of the object : HDF_GROUP : " );
137               break;
138
139             case HDF_DATASET :
140               MESSAGE( "--> Type of the object : HDF_DATASET : " );
141               break;
142
143             default :
144               MESSAGE( "--> PANIC !!! : " ); 
145             }
146         }
147       
148       MESSAGE( ">> Group exploration" );
149       explorer->Reset(hdf_group); 
150       for (explorer->Init();explorer->More();explorer->Next())
151         {
152           object = explorer->Value();
153           MESSAGE( "--> Name of the object : " << object->GetName() );
154           switch (object->GetObjectType())
155             {
156             case HDF_FILE :
157               MESSAGE( "--> Type of the object : HDF_FILE : " );
158               break;
159
160             case HDF_GROUP :
161               MESSAGE( "--> Type of the object : HDF_GROUP : " );
162               break;
163
164             case HDF_DATASET :
165               MESSAGE( "--> Type of the object : HDF_DATASET : " );
166               break;
167
168             default :
169               MESSAGE( "--> !!! PANIC !!! : " );
170             }
171         }      
172       
173       // memory clean
174       MESSAGE( ">> MEMORY CLEAN " );
175       delete explorer;
176       MESSAGE( ">> The HDF eplorer object is deleted" );
177       delete hdf_attribute;
178       MESSAGE( ">> The HDF attribute object is deleted" );     
179       delete hdf_dataset;
180       MESSAGE( ">> The first HDF dataset object is deleted" );
181       delete hdf_dataset2;
182       MESSAGE( ">> The second HDF dataset object is deleted" );
183       delete hdf_group;
184       MESSAGE( ">> The HDF group object is deleted" ); 
185       delete hdf_file;
186       MESSAGE( ">> The HDF file object is deleted" );
187     }
188   catch (HDFexception)
189     {
190       MESSAGE( "!!!! HDFexception" )
191     }
192
193   return 0;
194 }