1 // SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
37 HDFdataset *hdf_dataset;
38 HDFdataset *hdf_dataset2;
39 HDFattribute *hdf_attribute;
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;
48 system("rm file_test3.hdf");
52 // a new HDFfile object
53 hdf_file = new HDFfile("file_test3.hdf");
54 MESSAGE( ">> A HDFfile object is created" );
56 hdf_file->CreateOnDisk();
57 MESSAGE( ">> The HDF file is created on Disk " );
59 // Inside the HDF file
61 // A new HDF group object
62 hdf_group = new HDFgroup("MESH",hdf_file);
63 MESSAGE( ">> A HDFgroup object 'MESH' is created" );
65 hdf_group->CreateOnDisk();
66 MESSAGE( ">> The HDF group is created on Disk " );
68 // Inside the HDF group
70 // A new HDF dataset object
71 // size of each dimension, only one in the example
73 hdf_dataset = new HDFdataset("COORDINATES",hdf_group,HDF_FLOAT64,size,1);
74 MESSAGE( ">> A HDFdataset object 'COORDINATES' is created" );
76 hdf_dataset->CreateOnDisk();
77 MESSAGE( ">> The HDF dataset is created on Disk " );
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 " );
83 hdf_dataset->WriteOnDisk(coordinates);
84 MESSAGE( ">> The HDF dataset is written on Disk " );
86 hdf_attribute->CreateOnDisk();
87 MESSAGE( ">> The HDF attribute is created on Disk " );
89 hdf_attribute->WriteOnDisk(&attribute);
90 MESSAGE( ">> The HDF attribute is written on Disk " );
92 hdf_attribute->CloseOnDisk();
93 MESSAGE( ">> The HDF attribute closed on Disk " );
95 hdf_dataset->CloseOnDisk();
96 MESSAGE( ">> The HDF dataset is closed on Disk " );
98 // A new dataset is created
100 hdf_dataset2 = new HDFdataset("UNIT",hdf_group,HDF_INT32,size,1);
101 MESSAGE( ">> A second HDFdataset object 'UNIT' is created" );
103 hdf_dataset2->CreateOnDisk();
104 MESSAGE( ">> The HDF dataset is created on Disk " );
106 hdf_dataset2->WriteOnDisk(unit);
107 MESSAGE( ">> The HDF dataset is written on Disk " );
109 hdf_dataset2->CloseOnDisk();
110 MESSAGE( ">> The HDF dataset is closed on Disk " );
112 // The HDF group is built, it can be closed
113 hdf_group->CloseOnDisk();
114 MESSAGE( ">> The HDF group is closed on Disk " );
116 // The HDF file is built, it can be closed
117 hdf_file->CloseOnDisk();
118 MESSAGE( ">> The HDF file is closed on disk" );
121 explorer = new HDFexplorer(hdf_file);
122 MESSAGE( ">> A HDF explorer object is created" );
124 MESSAGE( ">> File Exploration " );
125 for (explorer->Init();explorer->More();explorer->Next())
127 object = explorer->Value();
128 MESSAGE( "--> Name of the object : " << object->GetName() );
129 switch (object->GetObjectType())
132 MESSAGE( "--> Type of the object : HDF_FILE : " );
136 MESSAGE( "--> Type of the object : HDF_GROUP : " );
140 MESSAGE( "--> Type of the object : HDF_DATASET : " );
144 MESSAGE( "--> PANIC !!! : " );
148 MESSAGE( ">> Group exploration" );
149 explorer->Reset(hdf_group);
150 for (explorer->Init();explorer->More();explorer->Next())
152 object = explorer->Value();
153 MESSAGE( "--> Name of the object : " << object->GetName() );
154 switch (object->GetObjectType())
157 MESSAGE( "--> Type of the object : HDF_FILE : " );
161 MESSAGE( "--> Type of the object : HDF_GROUP : " );
165 MESSAGE( "--> Type of the object : HDF_DATASET : " );
169 MESSAGE( "--> !!! PANIC !!! : " );
174 MESSAGE( ">> MEMORY CLEAN " );
176 MESSAGE( ">> The HDF eplorer object is deleted" );
177 delete hdf_attribute;
178 MESSAGE( ">> The HDF attribute object is deleted" );
180 MESSAGE( ">> The first HDF dataset object is deleted" );
182 MESSAGE( ">> The second HDF dataset object is deleted" );
184 MESSAGE( ">> The HDF group object is deleted" );
186 MESSAGE( ">> The HDF file object is deleted" );
190 MESSAGE( "!!!! HDFexception" )