1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
36 HDFdataset *hdf_dataset;
37 HDFdataset *hdf_dataset2;
38 HDFattribute *hdf_attribute;
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;
47 system("rm file_test3.hdf");
51 // a new HDFfile object
52 hdf_file = new HDFfile("file_test3.hdf");
53 MESSAGE( ">> A HDFfile object is created" );
55 hdf_file->CreateOnDisk();
56 MESSAGE( ">> The HDF file is created on Disk " );
58 // Inside the HDF file
60 // A new HDF group object
61 hdf_group = new HDFgroup("MESH",hdf_file);
62 MESSAGE( ">> A HDFgroup object 'MESH' is created" );
64 hdf_group->CreateOnDisk();
65 MESSAGE( ">> The HDF group is created on Disk " );
67 // Inside the HDF group
69 // A new HDF dataset object
70 // size of each dimension, only one in the example
72 hdf_dataset = new HDFdataset("COORDINATES",hdf_group,HDF_FLOAT64,size,1);
73 MESSAGE( ">> A HDFdataset object 'COORDINATES' is created" );
75 hdf_dataset->CreateOnDisk();
76 MESSAGE( ">> The HDF dataset is created on Disk " );
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 " );
82 hdf_dataset->WriteOnDisk(coordinates);
83 MESSAGE( ">> The HDF dataset is written on Disk " );
85 hdf_attribute->CreateOnDisk();
86 MESSAGE( ">> The HDF attribute is created on Disk " );
88 hdf_attribute->WriteOnDisk(&attribute);
89 MESSAGE( ">> The HDF attribute is written on Disk " );
91 hdf_attribute->CloseOnDisk();
92 MESSAGE( ">> The HDF attribute closed on Disk " );
94 hdf_dataset->CloseOnDisk();
95 MESSAGE( ">> The HDF dataset is closed on Disk " );
97 // A new dataset is created
99 hdf_dataset2 = new HDFdataset("UNIT",hdf_group,HDF_INT32,size,1);
100 MESSAGE( ">> A second HDFdataset object 'UNIT' is created" );
102 hdf_dataset2->CreateOnDisk();
103 MESSAGE( ">> The HDF dataset is created on Disk " );
105 hdf_dataset2->WriteOnDisk(unit);
106 MESSAGE( ">> The HDF dataset is written on Disk " );
108 hdf_dataset2->CloseOnDisk();
109 MESSAGE( ">> The HDF dataset is closed on Disk " );
111 // The HDF group is built, it can be closed
112 hdf_group->CloseOnDisk();
113 MESSAGE( ">> The HDF group is closed on Disk " );
115 // The HDF file is built, it can be closed
116 hdf_file->CloseOnDisk();
117 MESSAGE( ">> The HDF file is closed on disk" );
120 explorer = new HDFexplorer(hdf_file);
121 MESSAGE( ">> A HDF explorer object is created" );
123 MESSAGE( ">> File Exploration " );
124 for (explorer->Init();explorer->More();explorer->Next())
126 object = explorer->Value();
127 MESSAGE( "--> Name of the object : " << object->GetName() );
128 switch (object->GetObjectType())
131 MESSAGE( "--> Type of the object : HDF_FILE : " );
135 MESSAGE( "--> Type of the object : HDF_GROUP : " );
139 MESSAGE( "--> Type of the object : HDF_DATASET : " );
143 MESSAGE( "--> PANIC !!! : " );
147 MESSAGE( ">> Group exploration" );
148 explorer->Reset(hdf_group);
149 for (explorer->Init();explorer->More();explorer->Next())
151 object = explorer->Value();
152 MESSAGE( "--> Name of the object : " << object->GetName() );
153 switch (object->GetObjectType())
156 MESSAGE( "--> Type of the object : HDF_FILE : " );
160 MESSAGE( "--> Type of the object : HDF_GROUP : " );
164 MESSAGE( "--> Type of the object : HDF_DATASET : " );
168 MESSAGE( "--> !!! PANIC !!! : " );
173 MESSAGE( ">> MEMORY CLEAN " );
175 MESSAGE( ">> The HDF eplorer object is deleted" );
176 delete hdf_attribute;
177 MESSAGE( ">> The HDF attribute object is deleted" );
179 MESSAGE( ">> The first HDF dataset object is deleted" );
181 MESSAGE( ">> The second HDF dataset object is deleted" );
183 MESSAGE( ">> The HDF group object is deleted" );
185 MESSAGE( ">> The HDF file object is deleted" );
189 MESSAGE( "!!!! HDFexception" )