1 // Copyright (C) 2007-2019 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, or (at your option) any later version.
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_dataset1, *hdf_dataset2;
38 char name[HDF_NAME_MAX_LEN+1];
48 // a new HDFfile object
49 hdf_file = new HDFfile("file_test3.hdf");
50 MESSAGE( ">> A HDFfile object is created" );
52 hdf_file->OpenOnDisk(HDF_RDONLY);
53 MESSAGE(">> The HDF file is opened on Disk with HDF_RDONLY access mode")
54 // It is possible to read the name of all (objects) sons in the file
55 n = hdf_file->nInternalObjects();
58 hdf_file->InternalObjectIndentify(i,name);
59 MESSAGE( "--> First Level Internal Object Name : " << name );
62 // Or it is possible to ask if an object is in the file
63 if (hdf_file->ExistInternalObject("MESH"))
64 MESSAGE( "--> The object naming 'MESH' is in the file " );
66 // it is possible to determine the type of an object
67 type = hdf_file->InternalObjectType("MESH");
71 MESSAGE( "--> Its type is HDF_GROUP" );
75 MESSAGE( "--> Its type is HDF_DATASET" );
79 MESSAGE( "--> !!!! PANIC !!!" );
82 hdf_group = new HDFgroup(name,hdf_file);
83 MESSAGE( ">> A new HDF group object " << name << " is created in memory")
85 hdf_group->OpenOnDisk();
86 MESSAGE( ">> The group " << name << " is opened on disk" );
88 // object inside the group ?
89 n = hdf_group->nInternalObjects();
90 MESSAGE( ">> There are " << n << " objects in this group " );
93 hdf_group->InternalObjectIndentify(i,name);
94 type = hdf_group->InternalObjectType(name);
95 MESSAGE( "--> First Level Internal Object Name : " << name );
99 MESSAGE( "--> Its type is HDF_GROUP" );
103 MESSAGE( "--> Its type is HDF_DATASET" );
107 MESSAGE( "--> !!!! PANIC !!!" );
111 // The first dataset object 'COORDINATES'
112 hdf_dataset1 = new HDFdataset("COORDINATES",hdf_group);
113 MESSAGE( ">> The dataset object 'COORDINATES' is created in memory " );
115 hdf_dataset1->OpenOnDisk();
116 MESSAGE( ">> The dataset object 'COORDINATES' is opened on disk " );
118 data_type = hdf_dataset1->GetType();
122 MESSAGE( "--> Type of data : HDF_INT32 " );
125 MESSAGE( "--> Type of data : HDF_INT64 " );
128 MESSAGE( "--> Type of data : HDF_FLOAT64 " );
131 MESSAGE( "--> Type of data : HDF_STRING " );
134 ndim = hdf_dataset1->nDim();
135 MESSAGE( "--> Number of dimensions : " << ndim );
137 dim = new hdf_size[ndim];
138 hdf_dataset1->GetDim(dim);
140 MESSAGE( "--> Dimension " << i+1 << " of size : " << dim[i] );
143 size = hdf_dataset1->GetSize();
144 val1 = new hdf_float64[size];
145 hdf_dataset1->ReadFromDisk(val1);
146 MESSAGE( "--> The values are : ");
148 MESSAGE( " " << val1[i]);
152 hdf_dataset1->CloseOnDisk();
153 MESSAGE( ">> The dataset object 'COORDINATES' is closed on disk " );
155 // The second dataset 'UNIT'
156 hdf_dataset2 = new HDFdataset("UNIT",hdf_group);
157 MESSAGE( ">> The dataset object 'UNIT' is created in memory " );
159 hdf_dataset2->OpenOnDisk();
160 MESSAGE( ">> The dataset object 'UNIT' is opened on disk " );
162 data_type = hdf_dataset2->GetType();
166 MESSAGE( "--> Type of data : HDF_INT32 " );
169 MESSAGE( "--> Type of data : HDF_INT64 " );
172 MESSAGE( "--> Type of data : HDF_FLOAT64 " );
175 MESSAGE( "--> Type of data : HDF_STRING " );
178 ndim = hdf_dataset2->nDim();
179 MESSAGE( "--> Number of dimensions : " << ndim );
181 dim = new hdf_size[ndim];
182 hdf_dataset2->GetDim(dim);
184 MESSAGE( "--> Dimension " << i+1 << " of size : " << dim[i] );
187 size = hdf_dataset2->GetSize();
188 val2 = new hdf_int32[size];
189 hdf_dataset2->ReadFromDisk(val2);
190 MESSAGE( "--> The values are : ");
192 MESSAGE( " " << val2[i]);
196 hdf_dataset2->CloseOnDisk();
197 MESSAGE( ">> The dataset object 'UNIT' is closed on disk " );
199 hdf_group->CloseOnDisk();
200 MESSAGE( ">> The group is closed on file" );
202 hdf_file->CloseOnDisk();
203 MESSAGE(">> The HDF file is closed on Disk" )
210 MESSAGE( ">> MEMORY CLEAN : all HDF objects have been deleted" );
214 MESSAGE( "!!! HDFexception !!! " )