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