1 // Copyright (C) 2007-2013 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];
66 HDFdataset::HDFdataset(const char *name,HDFcontainerObject *father)
67 : HDFinternalObject(name)
70 _fid = _father->GetId();
71 _father->AddSon(this);
75 _byte_order = H5T_ORDER_ERROR;
81 HDFdataset::~HDFdataset()
86 void HDFdataset::CreateOnDisk()
88 if ((_id = HDFdatasetCreate(_fid,_name,_type,_dim,_ndim,_byte_order,_arrayId)) < 0)
89 throw HDFexception("Can't create dataset");
92 void HDFdataset::OpenOnDisk()
94 if ((_id = HDFdatasetOpen(_fid,_name)) < 0)
95 throw HDFexception("Can't open dataset");
98 void HDFdataset::CloseOnDisk()
102 if ((ret = HDFdatasetClose(_id)) < 0)
103 throw HDFexception("Can't close dataset");
107 void HDFdataset::WriteOnDisk(void *values)
111 if ((ret = HDFdatasetWrite(_id,values)) < 0)
112 throw HDFexception("Can't write dataset");
116 void HDFdataset::ReadFromDisk(void *values)
120 if ((ret = HDFdatasetRead(_id,values)) < 0)
121 throw HDFexception("Can't read dataset");
124 HDFcontainerObject *HDFdataset::GetFather()
129 hdf_type HDFdataset::GetType()
131 if (_type == HDF_NONE)
132 if ((_type = HDFdatasetGetType(_id)) == HDF_NONE)
133 throw HDFexception("Can't determine the type of data in the dataset");
138 int HDFdataset::nDim()
141 if ((_ndim = HDFdatasetGetnDim(_id)) < 0)
142 throw HDFexception("Can't determine the dataset dimensions number");
147 void HDFdataset::GetDim(hdf_size dim[])
156 ndim = HDFdatasetGetnDim(_id);
159 _dim = new hdf_size[ndim];
160 if ((ret = HDFdatasetGetDim(_id,_dim)) < 0)
161 throw HDFexception("Can't determine the size dimensions of the dataset ");
164 for (i=0;i<_ndim;i++)
168 hdf_size HDFdataset::GetSize()
174 if ((_size = HDFdatasetGetSize(_id)) < 0)
175 throw HDFexception("Can't determine the size of the dataset");
177 if (_type == HDF_NONE)
178 if ((_type = HDFdatasetGetType(_id)) == HDF_NONE)
179 throw HDFexception("Can't determine the size of the dataset");
195 _size = _size / size_type;
201 hdf_byte_order HDFdataset::GetOrder()
203 if (_byte_order < 0 )
204 if ((_byte_order = HDFdatasetGetOrder( _id )) < 0)
205 throw HDFexception("Can't determine the byte order of the dataset");
209 hdf_object_type HDFdataset::GetObjectType()
215 int HDFdataset::nAttributes()
217 int nbAttrs = H5Aget_num_attrs(_id);
218 if(nbAttrs <= 0) nbAttrs = 0;
223 char* HDFdataset::GetAttributeName(unsigned idx)
225 int nbAttrs = nAttributes();
226 if(nbAttrs == 0) return NULL;
227 H5Aiterate(_id, &idx, dataset_attr, &_attribute);
231 void HDFdataset::SetArrayId(hdf_idt arrayId) {