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_dataset1, *hdf_dataset2;
39 char name[HDF_NAME_MAX_LEN+1];
49 // a new HDFfile object
50 hdf_file = new HDFfile("file_test3.hdf");
51 MESSAGE( ">> A HDFfile object is created" );
53 hdf_file->OpenOnDisk(HDF_RDONLY);
54 MESSAGE(">> The HDF file is opened on Disk with HDF_RDONLY access mode")
55 // It is possible to read the name of all (objects) sons in the file
56 n = hdf_file->nInternalObjects();
59 hdf_file->InternalObjectIndentify(i,name);
60 MESSAGE( "--> First Level Internal Object Name : " << name );
63 // Or it is possible to ask if an object is in the file
64 if (hdf_file->ExistInternalObject("MESH"))
65 MESSAGE( "--> The object naming 'MESH' is in the file " );
67 // it is possible to determine the type of an object
68 type = hdf_file->InternalObjectType("MESH");
72 MESSAGE( "--> Its type is HDF_GROUP" );
76 MESSAGE( "--> Its type is HDF_DATASET" );
80 MESSAGE( "--> !!!! PANIC !!!" );
83 hdf_group = new HDFgroup(name,hdf_file);
84 MESSAGE( ">> A new HDF group object " << name << " is created in memory")
86 hdf_group->OpenOnDisk();
87 MESSAGE( ">> The group " << name << " is opened on disk" );
89 // object inside the group ?
90 n = hdf_group->nInternalObjects();
91 MESSAGE( ">> There are " << n << " objects in this group " );
94 hdf_group->InternalObjectIndentify(i,name);
95 type = hdf_group->InternalObjectType(name);
96 MESSAGE( "--> First Level Internal Object Name : " << name );
100 MESSAGE( "--> Its type is HDF_GROUP" );
104 MESSAGE( "--> Its type is HDF_DATASET" );
108 MESSAGE( "--> !!!! PANIC !!!" );
112 // The first dataset object 'COORDINATES'
113 hdf_dataset1 = new HDFdataset("COORDINATES",hdf_group);
114 MESSAGE( ">> The dataset object 'COORDINATES' is created in memory " );
116 hdf_dataset1->OpenOnDisk();
117 MESSAGE( ">> The dataset object 'COORDINATES' is opened on disk " );
119 data_type = hdf_dataset1->GetType();
123 MESSAGE( "--> Type of data : HDF_INT32 " );
126 MESSAGE( "--> Type of data : HDF_INT64 " );
129 MESSAGE( "--> Type of data : HDF_FLOAT64 " );
132 MESSAGE( "--> Type of data : HDF_STRING " );
135 ndim = hdf_dataset1->nDim();
136 MESSAGE( "--> Number of dimensions : " << ndim );
138 dim = new hdf_size[ndim];
139 hdf_dataset1->GetDim(dim);
141 MESSAGE( "--> Dimension " << i+1 << " of size : " << dim[i] );
144 size = hdf_dataset1->GetSize();
145 val1 = new hdf_float64[size];
146 hdf_dataset1->ReadFromDisk(val1);
147 MESSAGE( "--> The values are : ");
149 MESSAGE( " " << val1[i]);
153 hdf_dataset1->CloseOnDisk();
154 MESSAGE( ">> The dataset object 'COORDINATES' is closed on disk " );
156 // The second dataset 'UNIT'
157 hdf_dataset2 = new HDFdataset("UNIT",hdf_group);
158 MESSAGE( ">> The dataset object 'UNIT' is created in memory " );
160 hdf_dataset2->OpenOnDisk();
161 MESSAGE( ">> The dataset object 'UNIT' is opened on disk " );
163 data_type = hdf_dataset2->GetType();
167 MESSAGE( "--> Type of data : HDF_INT32 " );
170 MESSAGE( "--> Type of data : HDF_INT64 " );
173 MESSAGE( "--> Type of data : HDF_FLOAT64 " );
176 MESSAGE( "--> Type of data : HDF_STRING " );
179 ndim = hdf_dataset2->nDim();
180 MESSAGE( "--> Number of dimensions : " << ndim );
182 dim = new hdf_size[ndim];
183 hdf_dataset2->GetDim(dim);
185 MESSAGE( "--> Dimension " << i+1 << " of size : " << dim[i] );
188 size = hdf_dataset2->GetSize();
189 val2 = new hdf_int32[size];
190 hdf_dataset2->ReadFromDisk(val2);
191 MESSAGE( "--> The values are : ");
193 MESSAGE( " " << val2[i]);
197 hdf_dataset2->CloseOnDisk();
198 MESSAGE( ">> The dataset object 'UNIT' is closed on disk " );
200 hdf_group->CloseOnDisk();
201 MESSAGE( ">> The group is closed on file" );
203 hdf_file->CloseOnDisk();
204 MESSAGE(">> The HDF file is closed on Disk" )
211 MESSAGE( ">> MEMORY CLEAN : all HDF objects have been deleted" );
215 MESSAGE( "!!! HDFexception !!! " )