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
24 // File : HDFdataset.cc
32 #include "HDFdataset.hxx"
33 #include "HDFcontainerObject.hxx"
34 #include "HDFexception.hxx"
39 herr_t dataset_attr(hid_t loc_id, const char *attr_name, void *operator_data)
41 *(char**)operator_data = new char[strlen(attr_name)+1];
42 strcpy(*(char**)operator_data, attr_name);
46 HDFdataset::HDFdataset(char *name, HDFcontainerObject *father,hdf_type type,
47 hdf_size dim[], int dimsize, hdf_byte_order order)
48 : HDFinternalObject(name)
53 _fid = _father->GetId();
54 _father->AddSon(this);
57 _dim = new hdf_size[dimsize];
61 for (i=0;i<dimsize;i++)
64 _size = _size * _dim[i];
69 HDFdataset::HDFdataset(char *name,HDFcontainerObject *father)
70 : HDFinternalObject(name)
73 _fid = _father->GetId();
74 _father->AddSon(this);
78 _byte_order = H5T_ORDER_ERROR;
83 HDFdataset::~HDFdataset()
88 void HDFdataset::CreateOnDisk()
90 if ((_id = HDFdatasetCreate(_fid,_name,_type,_dim,_ndim,_byte_order)) < 0)
91 throw HDFexception("Can't create dataset");
94 void HDFdataset::OpenOnDisk()
96 if ((_id = HDFdatasetOpen(_fid,_name)) < 0)
97 throw HDFexception("Can't open dataset");
100 void HDFdataset::CloseOnDisk()
104 if ((ret = HDFdatasetClose(_id)) < 0)
105 throw HDFexception("Can't close dataset");
109 void HDFdataset::WriteOnDisk(void *values)
113 if ((ret = HDFdatasetWrite(_id,values)) < 0)
114 throw HDFexception("Can't write dataset");
118 void HDFdataset::ReadFromDisk(void *values)
122 if ((ret = HDFdatasetRead(_id,values)) < 0)
123 throw HDFexception("Can't read dataset");
126 HDFcontainerObject *HDFdataset::GetFather()
131 hdf_type HDFdataset::GetType()
133 if (_type == HDF_NONE)
134 if ((_type = HDFdatasetGetType(_id)) == HDF_NONE)
135 throw HDFexception("Can't determine the type of data in the dataset");
140 int HDFdataset::nDim()
143 if ((_ndim = HDFdatasetGetnDim(_id)) < 0)
144 throw HDFexception("Can't determine the dataset dimensions number");
149 void HDFdataset::GetDim(hdf_size dim[])
158 ndim = HDFdatasetGetnDim(_id);
161 _dim = new hdf_size[ndim];
162 if ((ret = HDFdatasetGetDim(_id,_dim)) < 0)
163 throw HDFexception("Can't determine the size dimensions of the dataset ");
166 for (i=0;i<_ndim;i++)
170 int HDFdataset::GetSize()
176 if ((_size = HDFdatasetGetSize(_id)) < 0)
177 throw HDFexception("Can't determine the size of the dataset");
179 if (_type == HDF_NONE)
180 if ((_type = HDFdatasetGetType(_id)) == HDF_NONE)
181 throw HDFexception("Can't determine the size of the dataset");
197 _size = _size / size_type;
203 hdf_byte_order HDFdataset::GetOrder()
205 if (_byte_order < 0 )
206 if ((_byte_order = HDFdatasetGetOrder( _id )) < 0)
207 throw HDFexception("Can't determine the byte order of the dataset");
211 hdf_object_type HDFdataset::GetObjectType()
217 int HDFdataset::nAttributes()
219 int nbAttrs = H5Aget_num_attrs(_id);
220 if(nbAttrs <= 0) nbAttrs = 0;
225 char* HDFdataset::GetAttributeName(unsigned idx)
227 int nbAttrs = nAttributes();
228 if(nbAttrs == 0) return NULL;
229 H5Aiterate(_id, &idx, dataset_attr, &_attribute);