1 // Copyright (C) 2007-2008 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
22 // SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
23 // File : HDFdataset.cc
31 #include "HDFdataset.hxx"
32 #include "HDFcontainerObject.hxx"
33 #include "HDFexception.hxx"
38 herr_t dataset_attr(hid_t loc_id, const char *attr_name, void *operator_data)
40 *(char**)operator_data = new char[strlen(attr_name)+1];
41 strcpy(*(char**)operator_data, attr_name);
45 HDFdataset::HDFdataset(const char *name, HDFcontainerObject *father,hdf_type type,
46 hdf_size dim[], int dimsize, hdf_byte_order order)
47 : HDFinternalObject(name)
52 _fid = _father->GetId();
53 _father->AddSon(this);
56 _dim = new hdf_size[dimsize];
60 for (i=0;i<dimsize;i++)
63 _size = _size * _dim[i];
68 HDFdataset::HDFdataset(const char *name,HDFcontainerObject *father)
69 : HDFinternalObject(name)
72 _fid = _father->GetId();
73 _father->AddSon(this);
77 _byte_order = H5T_ORDER_ERROR;
82 HDFdataset::~HDFdataset()
87 void HDFdataset::CreateOnDisk()
89 if ((_id = HDFdatasetCreate(_fid,_name,_type,_dim,_ndim,_byte_order)) < 0)
90 throw HDFexception("Can't create dataset");
93 void HDFdataset::OpenOnDisk()
95 if ((_id = HDFdatasetOpen(_fid,_name)) < 0)
96 throw HDFexception("Can't open dataset");
99 void HDFdataset::CloseOnDisk()
103 if ((ret = HDFdatasetClose(_id)) < 0)
104 throw HDFexception("Can't close dataset");
108 void HDFdataset::WriteOnDisk(void *values)
112 if ((ret = HDFdatasetWrite(_id,values)) < 0)
113 throw HDFexception("Can't write dataset");
117 void HDFdataset::ReadFromDisk(void *values)
121 if ((ret = HDFdatasetRead(_id,values)) < 0)
122 throw HDFexception("Can't read dataset");
125 HDFcontainerObject *HDFdataset::GetFather()
130 hdf_type HDFdataset::GetType()
132 if (_type == HDF_NONE)
133 if ((_type = HDFdatasetGetType(_id)) == HDF_NONE)
134 throw HDFexception("Can't determine the type of data in the dataset");
139 int HDFdataset::nDim()
142 if ((_ndim = HDFdatasetGetnDim(_id)) < 0)
143 throw HDFexception("Can't determine the dataset dimensions number");
148 void HDFdataset::GetDim(hdf_size dim[])
157 ndim = HDFdatasetGetnDim(_id);
160 _dim = new hdf_size[ndim];
161 if ((ret = HDFdatasetGetDim(_id,_dim)) < 0)
162 throw HDFexception("Can't determine the size dimensions of the dataset ");
165 for (i=0;i<_ndim;i++)
169 int HDFdataset::GetSize()
175 if ((_size = HDFdatasetGetSize(_id)) < 0)
176 throw HDFexception("Can't determine the size of the dataset");
178 if (_type == HDF_NONE)
179 if ((_type = HDFdatasetGetType(_id)) == HDF_NONE)
180 throw HDFexception("Can't determine the size of the dataset");
196 _size = _size / size_type;
202 hdf_byte_order HDFdataset::GetOrder()
204 if (_byte_order < 0 )
205 if ((_byte_order = HDFdatasetGetOrder( _id )) < 0)
206 throw HDFexception("Can't determine the byte order of the dataset");
210 hdf_object_type HDFdataset::GetObjectType()
216 int HDFdataset::nAttributes()
218 int nbAttrs = H5Aget_num_attrs(_id);
219 if(nbAttrs <= 0) nbAttrs = 0;
224 char* HDFdataset::GetAttributeName(unsigned idx)
226 int nbAttrs = nAttributes();
227 if(nbAttrs == 0) return NULL;
228 H5Aiterate(_id, &idx, dataset_attr, &_attribute);