Back to index

salome-kernel  6.5.0
HDFarray.cc
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
00024 //  File   : HDFarray.cc
00025 //  Module : SALOME
00026 //
00027 #include "HDFarray.hxx"
00028 #include "HDFexception.hxx"
00029 #include "hdfi.h"
00030 
00031 
00032 HDFarray::HDFarray( HDFobject* father, hdf_type dataType, int ndim, hdf_size *dim )
00033   : HDFobject("")
00034 {
00035   _father = father;
00036   _datatype = dataType;
00037   _ndim = ndim;
00038   _dim = dim;
00039 }
00040 
00041 HDFarray::HDFarray( HDFobject* father)
00042   : HDFobject("")
00043 {
00044   _father = father;
00045   _datatype = HDF_NONE;
00046   _ndim = -1;
00047   _dim  = 0;
00048 
00049   if( father )
00050     _id = HDFarrayGetTypeId(father->GetId());
00051   
00052 }
00053 
00054 
00055 HDFarray::~HDFarray()
00056 {
00057   if(_dim )
00058     delete [] _dim;
00059 }
00060 
00061 hdf_type HDFarray::GetDataType() {
00062   if (_datatype == HDF_NONE)
00063     if ((_datatype = HDFarrayGetType(_id)) == HDF_NONE )
00064       throw HDFexception("Can't determine the type of array data");
00065   return _datatype;
00066 }
00067 
00068 
00069 void HDFarray::CreateOnDisk() {
00070   if( (_id = HDFarrayCreate(_datatype,_ndim, _dim)) < 0 )
00071     throw HDFexception("Can't create HDF array");
00072 }
00073 
00074 void HDFarray::CloseOnDisk() {
00075   if( HDFarrayClose(_id) < 0 )
00076     throw HDFexception("Can't close HDF array");
00077 }
00078 
00079 int HDFarray::nDim() {
00080   if (_ndim == -1)
00081     if ((_ndim = HDFarrayGetnDim(_id)) < 0)
00082       throw HDFexception("Can't determine the array dimensions number");
00083 
00084   return _ndim;
00085 
00086 }
00087 
00088 
00089 void HDFarray::GetDim(hdf_size dim[]) {
00090   int i;
00091   int ndim;
00092   hdf_err ret;
00093 
00094   if (_dim == 0)
00095     {
00096       if (_ndim == -1)
00097        ndim = HDFdatasetGetnDim(_id);
00098       else
00099        ndim = _ndim;
00100       _dim = new hdf_size[ndim];
00101       if ((ret = HDFarrayGetDim(_id,_dim)) < 0)
00102        throw HDFexception("Can't determine the size dimensions of the array ");
00103     }
00104 
00105   for (i=0;i<_ndim;i++)
00106     dim[i] = _dim[i];
00107 }
00108 
00109 
00110 hdf_object_type HDFarray::GetObjectType() {
00111   return HDF_ARRAY_TYPE;
00112 }