Salome HOME
Remove debug print in PyNode.
[modules/kernel.git] / src / HDFPersist / HDFarray.cc
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
24 //  File   : HDFarray.cc
25 //  Module : SALOME
26 //
27 #include "HDFarray.hxx"
28 #include "HDFexception.hxx"
29 #include "hdfi.h"
30
31
32 HDFarray::HDFarray( HDFobject* father, hdf_type dataType, int ndim, hdf_size *dim )
33   : HDFobject("")
34 {
35   _father = father;
36   _datatype = dataType;
37   _ndim = ndim;
38   _dim = dim;
39 }
40
41 HDFarray::HDFarray( HDFobject* father)
42   : HDFobject("")
43 {
44   _father = father;
45   _datatype = HDF_NONE;
46   _ndim = -1;
47   _dim  = 0;
48
49   if( father )
50     _id = HDFarrayGetTypeId(father->GetId());
51   
52 }
53
54
55 HDFarray::~HDFarray()
56 {
57   if(_dim )
58     delete [] _dim;
59 }
60
61 hdf_type HDFarray::GetDataType() {
62   if (_datatype == HDF_NONE)
63     if ((_datatype = HDFarrayGetType(_id)) == HDF_NONE )
64       throw HDFexception("Can't determine the type of array data");
65   return _datatype;
66 }
67
68
69 void HDFarray::CreateOnDisk() {
70   if( (_id = HDFarrayCreate(_datatype,_ndim, _dim)) < 0 )
71     throw HDFexception("Can't create HDF array");
72 }
73
74 void HDFarray::CloseOnDisk() {
75   if( HDFarrayClose(_id) < 0 )
76     throw HDFexception("Can't close HDF array");
77 }
78
79 int HDFarray::nDim() {
80   if (_ndim == -1)
81     if ((_ndim = HDFarrayGetnDim(_id)) < 0)
82       throw HDFexception("Can't determine the array dimensions number");
83
84   return _ndim;
85
86 }
87
88
89 void HDFarray::GetDim(hdf_size dim[]) {
90   int i;
91   int ndim;
92   hdf_err ret;
93
94   if (_dim == 0)
95     {
96       if (_ndim == -1)
97         ndim = HDFdatasetGetnDim(_id);
98       else
99         ndim = _ndim;
100       _dim = new hdf_size[ndim];
101       if ((ret = HDFarrayGetDim(_id,_dim)) < 0)
102         throw HDFexception("Can't determine the size dimensions of the array ");
103     }
104
105   for (i=0;i<_ndim;i++)
106     dim[i] = _dim[i];
107 }
108
109
110 hdf_object_type HDFarray::GetObjectType() {
111   return HDF_ARRAY_TYPE;
112 }