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 )
24 // File : HDFdataset.cc
29 #include "HDFdataset.hxx"
30 #include "HDFcontainerObject.hxx"
31 #include "HDFexception.hxx"
35 herr_t dataset_attr(hid_t loc_id, const char *attr_name, void *operator_data)
37 *(char**)operator_data = new char[strlen(attr_name)+1];
38 strcpy(*(char**)operator_data, attr_name);
42 HDFdataset::HDFdataset(const char *name, HDFcontainerObject *father,hdf_type type,
43 hdf_size dim[], int dimsize, hdf_byte_order order)
44 : HDFinternalObject(name)
49 _fid = _father->GetId();
50 _father->AddSon(this);
53 _dim = new hdf_size[dimsize];
57 for (i=0;i<dimsize;i++)
60 _size = _size * _dim[i];
65 HDFdataset::HDFdataset(const char *name,HDFcontainerObject *father)
66 : HDFinternalObject(name)
69 _fid = _father->GetId();
70 _father->AddSon(this);
74 _byte_order = H5T_ORDER_ERROR;
79 HDFdataset::~HDFdataset()
84 void HDFdataset::CreateOnDisk()
86 if ((_id = HDFdatasetCreate(_fid,_name,_type,_dim,_ndim,_byte_order)) < 0)
87 throw HDFexception("Can't create dataset");
90 void HDFdataset::OpenOnDisk()
92 if ((_id = HDFdatasetOpen(_fid,_name)) < 0)
93 throw HDFexception("Can't open dataset");
96 void HDFdataset::CloseOnDisk()
100 if ((ret = HDFdatasetClose(_id)) < 0)
101 throw HDFexception("Can't close dataset");
105 void HDFdataset::WriteOnDisk(void *values)
109 if ((ret = HDFdatasetWrite(_id,values)) < 0)
110 throw HDFexception("Can't write dataset");
114 void HDFdataset::ReadFromDisk(void *values)
118 if ((ret = HDFdatasetRead(_id,values)) < 0)
119 throw HDFexception("Can't read dataset");
122 HDFcontainerObject *HDFdataset::GetFather()
127 hdf_type HDFdataset::GetType()
129 if (_type == HDF_NONE)
130 if ((_type = HDFdatasetGetType(_id)) == HDF_NONE)
131 throw HDFexception("Can't determine the type of data in the dataset");
136 int HDFdataset::nDim()
139 if ((_ndim = HDFdatasetGetnDim(_id)) < 0)
140 throw HDFexception("Can't determine the dataset dimensions number");
145 void HDFdataset::GetDim(hdf_size dim[])
154 ndim = HDFdatasetGetnDim(_id);
157 _dim = new hdf_size[ndim];
158 if ((ret = HDFdatasetGetDim(_id,_dim)) < 0)
159 throw HDFexception("Can't determine the size dimensions of the dataset ");
162 for (i=0;i<_ndim;i++)
166 hdf_size HDFdataset::GetSize()
172 if ((_size = HDFdatasetGetSize(_id)) < 0)
173 throw HDFexception("Can't determine the size of the dataset");
175 if (_type == HDF_NONE)
176 if ((_type = HDFdatasetGetType(_id)) == HDF_NONE)
177 throw HDFexception("Can't determine the size of the dataset");
193 _size = _size / size_type;
199 hdf_byte_order HDFdataset::GetOrder()
201 if (_byte_order < 0 )
202 if ((_byte_order = HDFdatasetGetOrder( _id )) < 0)
203 throw HDFexception("Can't determine the byte order of the dataset");
207 hdf_object_type HDFdataset::GetObjectType()
213 int HDFdataset::nAttributes()
215 int nbAttrs = H5Aget_num_attrs(_id);
216 if(nbAttrs <= 0) nbAttrs = 0;
221 char* HDFdataset::GetAttributeName(unsigned idx)
223 int nbAttrs = nAttributes();
224 if(nbAttrs == 0) return NULL;
225 H5Aiterate(_id, &idx, dataset_attr, &_attribute);