From: rnv Date: Wed, 20 Apr 2011 10:25:35 +0000 (+0000) Subject: RNV: Added support of the H5T_ARRAY. X-Git-Tag: V6_3_0b1~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fc58caf72d389405a6e0037cfcf899dd5cbf1549;p=modules%2Fkernel.git RNV: Added support of the H5T_ARRAY. --- diff --git a/src/HDFPersist/HDFOI.hxx b/src/HDFPersist/HDFOI.hxx index 134aca9d8..e6a4be94a 100644 --- a/src/HDFPersist/HDFOI.hxx +++ b/src/HDFPersist/HDFOI.hxx @@ -40,3 +40,5 @@ #include "HDFconvert.hxx" #include "HDFascii.hxx" + +#include "HDFarray.hxx" diff --git a/src/HDFPersist/HDFarray.cc b/src/HDFPersist/HDFarray.cc new file mode 100644 index 000000000..311c36edc --- /dev/null +++ b/src/HDFPersist/HDFarray.cc @@ -0,0 +1,112 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// SALOME HDFPersist : implementation of HDF persitent ( save/ restore ) +// File : HDFarray.cc +// Module : SALOME +// +#include "HDFarray.hxx" +#include "HDFexception.hxx" +#include "hdfi.h" + + +HDFarray::HDFarray( HDFobject* father, hdf_type dataType, int ndim, hdf_size *dim ) + : HDFobject("") +{ + _father = father; + _datatype = dataType; + _ndim = ndim; + _dim = dim; +} + +HDFarray::HDFarray( HDFobject* father) + : HDFobject("") +{ + _father = father; + _datatype = HDF_NONE; + _ndim = -1; + _dim = 0; + + if( father ) + _id = HDFarrayGetTypeId(father->GetId()); + +} + + +HDFarray::~HDFarray() +{ + if(_dim ) + delete [] _dim; +} + +hdf_type HDFarray::GetDataType() { + if (_datatype == HDF_NONE) + if ((_datatype = HDFarrayGetType(_id)) == HDF_NONE ) + throw HDFexception("Can't determine the type of array data"); + return _datatype; +} + + +void HDFarray::CreateOnDisk() { + if( (_id = HDFarrayCreate(_datatype,_ndim, _dim)) < 0 ) + throw HDFexception("Can't create HDF array"); +} + +void HDFarray::CloseOnDisk() { + if( HDFarrayClose(_id) < 0 ) + throw HDFexception("Can't close HDF array"); +} + +int HDFarray::nDim() { + if (_ndim == -1) + if ((_ndim = HDFarrayGetnDim(_id)) < 0) + throw HDFexception("Can't determine the array dimensions number"); + + return _ndim; + +} + + +void HDFarray::GetDim(hdf_size dim[]) { + int i; + int ndim; + hdf_err ret; + + if (_dim == 0) + { + if (_ndim == -1) + ndim = HDFdatasetGetnDim(_id); + else + ndim = _ndim; + _dim = new hdf_size[ndim]; + if ((ret = HDFarrayGetDim(_id,_dim)) < 0) + throw HDFexception("Can't determine the size dimensions of the array "); + } + + for (i=0;i<_ndim;i++) + dim[i] = _dim[i]; +} + + +hdf_object_type HDFarray::GetObjectType() { + return HDF_ARRAY_TYPE; +} diff --git a/src/HDFPersist/HDFarray.hxx b/src/HDFPersist/HDFarray.hxx new file mode 100644 index 000000000..6ade39359 --- /dev/null +++ b/src/HDFPersist/HDFarray.hxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// SALOME HDFPersist : implementation of HDF persitent ( save/ restore ) +// File : HDFarray.hxx +// Module : SALOME +// +#ifndef HDFARRAY_HXX +#define HDFARRAY_HXX + +#include "HDFobject.hxx" +#include "HDFexport.hxx" + +class HDFPERSIST_EXPORT HDFarray : public HDFobject { +protected: + HDFobject* _father; + hdf_type _datatype; + hdf_size* _dim; + int _ndim; + +public : + HDFarray( HDFobject* father, hdf_type dataType, int ndim, hdf_size *dim); + + HDFarray( HDFobject* father); + + virtual ~HDFarray(); + + virtual hdf_type GetDataType(); + + virtual hdf_object_type GetObjectType(); + + void CreateOnDisk(); + void CloseOnDisk(); + + int nDim(); + void GetDim(hdf_size dim[]); +}; + +#endif /* HDFARRAY_HXX */ + diff --git a/src/HDFPersist/HDFarrayClose.c b/src/HDFPersist/HDFarrayClose.c new file mode 100644 index 000000000..edf414f14 --- /dev/null +++ b/src/HDFPersist/HDFarrayClose.c @@ -0,0 +1,50 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +/*---------------------------------------------------------------------------- + SALOME HDFPersist : implementation of HDF persitent ( save/ restore ) + File : HDFarrayClose.c + Module : SALOME +----------------------------------------------------------------------------*/ + +#include "hdfi.h" + +/* + * - Name : HDFarrayClose + * - Description : close a HDF array + * - Parameters : + * - id (IN) : array ID + * - Result : + * - if success : returns 0 + * - if failure : returns -1 + */ + +hdf_err +HDFarrayClose(hdf_idt id) +{ + hdf_err ret; + + if ((ret = H5Tclose(id)) < 0) + return -1; + + return 0; +} diff --git a/src/HDFPersist/HDFarrayCreate.c b/src/HDFPersist/HDFarrayCreate.c new file mode 100644 index 000000000..772d10fa7 --- /dev/null +++ b/src/HDFPersist/HDFarrayCreate.c @@ -0,0 +1,76 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +/*---------------------------------------------------------------------------- +SALOME HDFPersist : implementation of HDF persitent ( save/ restore ) + File : HDFarrayCreate.c + Module : SALOME +----------------------------------------------------------------------------*/ + +#include "hdfi.h" + +/* + * - Name : HDFarrayCreate + * - Description : creates a HDF array + * - Parameters : + * - dataType (IN) : type of the data in the array (HDF_INT32, HDF_INT64, HDF_FLOAT64, HDF_CHAR). + * - ndim (IN) : is the number of dimensions and the size of each dimension is specified in the array dims. + * - dim (IN) : size of each array dimension. + * - Result : + * - if success : returns array ID + * - if failure : -1 + */ + +hdf_idt HDFarrayCreate(hdf_type dataType, int ndim, hdf_size *dim) +{ + hdf_idt type_hdf; + switch(dataType) + { + case HDF_FLOAT64 : +#if defined (PCLINUX) || defined (PCLINUX64) + type_hdf = H5T_IEEE_F64BE; +#else + type_hdf = H5T_IEEE_F64LE; +#endif + break; + + case HDF_INT32 : +#if defined (PCLINUX) || defined (PCLINUX64) + type_hdf = H5T_STD_I32BE; +#else + type_hdf = H5T_NATIVE_INT; +#endif + break; + + case HDF_INT64 : + type_hdf = H5T_NATIVE_LONG; + break; + case HDF_CHAR : + type_hdf = H5T_NATIVE_CHAR; + break; + default: + return -1; + break; + } + + return H5Tarray_create2( type_hdf, ndim, dim ); +} diff --git a/src/HDFPersist/HDFarrayGetDim.c b/src/HDFPersist/HDFarrayGetDim.c new file mode 100644 index 000000000..e9f95f9af --- /dev/null +++ b/src/HDFPersist/HDFarrayGetDim.c @@ -0,0 +1,53 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +/*---------------------------------------------------------------------------- + SALOME HDFPersist : implementation of HDF persitent ( save/ restore ) + File : HDFarrayGetDim.c + Module : SALOME +----------------------------------------------------------------------------*/ + +#include +#include "hdfi.h" +#include + +hdf_err +HDFarrayGetDim(hdf_idt id,hdf_size dim[]) +{ + hdf_err ret = 0; + hdf_size *tmp; + int ndim, i; + + if ( (ndim = H5Tget_array_ndims(id)) < 0 ) + return -1; + + tmp = (hdf_size *) malloc(sizeof(hdf_size)*ndim); + + ret = H5Tget_array_dims2(id, tmp); + + for( i=0 ; i < ndim ; i++) + dim[i] = tmp[i]; + + free (tmp); + + return ret; +} diff --git a/src/HDFPersist/HDFarrayGetType.c b/src/HDFPersist/HDFarrayGetType.c new file mode 100644 index 000000000..b96cb7868 --- /dev/null +++ b/src/HDFPersist/HDFarrayGetType.c @@ -0,0 +1,71 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +/*---------------------------------------------------------------------------- + SALOME HDFPersist : implementation of HDF persitent ( save/ restore ) + File : HDFarrayGetType.c + Module : SALOME +----------------------------------------------------------------------------*/ + +#include "hdfi.h" +#include + +hdf_type +HDFarrayGetType(hdf_idt type_id) +{ + hdf_idt super; + hdf_type type; + hdf_size_type size; + + if(type_id < 0 ) + return HDF_NONE; + + if((super = H5Tget_super(type_id)) < 0 ) + return HDF_NONE; + + switch (H5Tget_class(super)) + { + case H5T_INTEGER : + size = H5Tget_size(super); + if(size == 1) + type = HDF_CHAR; + else if (size == 4) + type = HDF_INT32; + else + type = HDF_INT64; + break; + + case H5T_FLOAT : + type = HDF_FLOAT64; + break; + + case H5T_STRING : + type = HDF_STRING; + break; + + default : + type = HDF_NONE; + } + + H5Tclose(super); + return type; +} diff --git a/src/HDFPersist/HDFarrayGetTypeId.c b/src/HDFPersist/HDFarrayGetTypeId.c new file mode 100644 index 000000000..2673e0b61 --- /dev/null +++ b/src/HDFPersist/HDFarrayGetTypeId.c @@ -0,0 +1,35 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +/*---------------------------------------------------------------------------- + SALOME HDFPersist : implementation of HDF persitent ( save/ restore ) + File : HDFarrayGetTypeId.c + Module : SALOME +----------------------------------------------------------------------------*/ + +#include "hdfi.h" +#include + +hdf_idt +HDFarrayGetTypeId(hdf_idt id) { + return H5Dget_type(id); +} diff --git a/src/HDFPersist/HDFarrayGetnDim.c b/src/HDFPersist/HDFarrayGetnDim.c new file mode 100644 index 000000000..377395afd --- /dev/null +++ b/src/HDFPersist/HDFarrayGetnDim.c @@ -0,0 +1,41 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +/*---------------------------------------------------------------------------- + SALOME HDFPersist : implementation of HDF persitent ( save/ restore ) + File : HDFarrayGetnDim.c + Module : SALOME +----------------------------------------------------------------------------*/ + +#include "hdfi.h" +#include + +int +HDFarrayGetnDim(hdf_idt id) +{ + int ndim; + + if ((ndim = H5Tget_array_ndims(id)) < 0) + return -1; + + return ndim; +} diff --git a/src/HDFPersist/HDFascii.cc b/src/HDFPersist/HDFascii.cc index 53b344272..05ea1bcb9 100644 --- a/src/HDFPersist/HDFascii.cc +++ b/src/HDFPersist/HDFascii.cc @@ -62,6 +62,8 @@ char* restoreName(char* name); void write_float64(FILE* fp, hdf_float64* value); void read_float64(FILE* fp, hdf_float64* value); +void WriteSimpleData( FILE* fp, HDFdataset *hdf_dataset, hdf_type type, long size ); + #define MAX_STRING_SIZE 65535 #define MAX_ID_SIZE 20 #define NB_FLOAT_IN_ROW 3 @@ -256,49 +258,26 @@ void SaveDatasetInASCIIfile(HDFdataset *hdf_dataset, FILE* fp, int ident) delete [] dim; fprintf(fp, "%li %i:", size, order); - - if (type == HDF_STRING) { - char* val = new char[size]; - hdf_dataset->ReadFromDisk(val); - fwrite(val, 1, size, fp); - delete [] val; - } else if (type == HDF_FLOAT64) { - hdf_float64* val = new hdf_float64[size]; - hdf_dataset->ReadFromDisk(val); - fprintf(fp, "\n"); - for (int i = 0, j = 0; i < size; i++) { - write_float64(fp, &val[i]); - if(++j == NB_FLOAT_IN_ROW) { - fprintf(fp, "\n"); - j = 0; - } - else fprintf(fp," "); - } - delete [] val; - } else if(type == HDF_INT64) { - hdf_int64* val = new hdf_int64[size]; - hdf_dataset->ReadFromDisk(val); - fprintf(fp, "\n"); - for (int i = 0, j = 0; i < size; i++) { - fprintf(fp, " %li", val[i]); - if(++j == NB_INTEGER_IN_ROW) { - fprintf(fp, "\n"); - j = 0; - } - } - delete [] val; - } else if(type == HDF_INT32) { - hdf_int32* val = new hdf_int32[size]; - hdf_dataset->ReadFromDisk(val); - fprintf(fp, "\n"); - for (int i = 0, j = 0; i < size; i++) { - fprintf(fp, " %i", val[i]); - if(++j == NB_INTEGER_IN_ROW) { - fprintf(fp, "\n"); - j = 0; - } + if( type == HDF_ARRAY ) { + HDFarray *array = new HDFarray(hdf_dataset); + hdf_type data_type = array->GetDataType(); + fprintf(fp, "\n" ); + fprintf(fp, " %i\n", data_type ); //Write array data type + + //Write nDim of the array + int arr_ndim = array->nDim(); + fprintf(fp, " %i\n", arr_ndim); + hdf_size *arr_dim = new hdf_size[arr_ndim]; + array->GetDim(arr_dim); + + for( int i = 0;i < arr_ndim; i++ ) { + fprintf(fp, " %i", arr_dim[i]); } - delete [] val; + + //And write the data array + WriteSimpleData( fp, hdf_dataset, data_type, size); + } else { + WriteSimpleData( fp, hdf_dataset, type, size); } fprintf(fp, "\n"); @@ -534,7 +513,7 @@ bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp) sizeArray[i] = dim; } - // order (2-d member) was not written in earlier versions + // order (2-d member) was not written in earlier versions char tmp; int nbRead = fscanf(fp, "%li %i%c", &size, &order, &tmp); if ( nbRead < 2 ) { // fscanf stops before ":" @@ -544,7 +523,34 @@ bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp) if ( type != HDF_FLOAT64 ) // use order only for FLOAT64 order = H5T_ORDER_NONE; - HDFdataset* hdf_dataset = new HDFdataset(new_name, father,type, sizeArray, nbDim, order); + + HDFarray* anArray = 0; + if( type == HDF_ARRAY ){ + //Get array information + hdf_type arr_data_type; + int arr_ndim; + fscanf(fp, "%c", &tmp); + fscanf(fp, " %i\n", &arr_data_type ); //Get array data type + fscanf(fp, " %i\n", &arr_ndim ); //Get array nDim + hdf_size *arr_dim = new hdf_size[arr_ndim]; + + int tdim = 0; + for( int i = 0;i < arr_ndim; i++ ) { + fscanf(fp, " %i", &tdim); + arr_dim[i] = tdim; + } + anArray = new HDFarray(0, arr_data_type, arr_ndim, arr_dim); + anArray->CreateOnDisk(); + + type = arr_data_type; + delete [] arr_dim; + } + + HDFdataset* hdf_dataset = new HDFdataset(new_name, father, anArray ? HDF_ARRAY : type, sizeArray, nbDim, order); + + if(anArray) + hdf_dataset->SetArrayId(anArray->GetId()); + delete [] new_name; delete [] sizeArray; @@ -576,6 +582,13 @@ bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp) } hdf_dataset->WriteOnDisk(val); delete [] val; + } else if(type == HDF_CHAR) { + hdf_char* val = new hdf_char[size]; + for(i=0; iWriteOnDisk(val); + delete [] val; } char token[MAX_ID_SIZE]; @@ -604,6 +617,11 @@ bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp) hdf_dataset->CloseOnDisk(); hdf_dataset = 0; //will be deleted by father destructor + if(anArray) { + anArray->CloseOnDisk(); + anArray = 0; //will be deleted by father destructor + } + return true; } @@ -790,3 +808,60 @@ void Move(const std::string& fName, const std::string& fNameDst) #endif } +void WriteSimpleData( FILE* fp, HDFdataset *hdf_dataset, hdf_type type, long size ) { + if (type == HDF_STRING) { + char* val = new char[size]; + hdf_dataset->ReadFromDisk(val); + fwrite(val, 1, size, fp); + delete [] val; + } else if (type == HDF_FLOAT64) { + hdf_float64* val = new hdf_float64[size]; + hdf_dataset->ReadFromDisk(val); + fprintf(fp, "\n"); + for (int i = 0, j = 0; i < size; i++) { + write_float64(fp, &val[i]); + if(++j == NB_FLOAT_IN_ROW) { + fprintf(fp, "\n"); + j = 0; + } + else fprintf(fp," "); + } + delete [] val; + } else if(type == HDF_INT64) { + hdf_int64* val = new hdf_int64[size]; + hdf_dataset->ReadFromDisk(val); + fprintf(fp, "\n"); + for (int i = 0, j = 0; i < size; i++) { + fprintf(fp, " %li", val[i]); + if(++j == NB_INTEGER_IN_ROW) { + fprintf(fp, "\n"); + j = 0; + } + } + delete [] val; + } else if(type == HDF_INT32) { + hdf_int32* val = new hdf_int32[size]; + hdf_dataset->ReadFromDisk(val); + fprintf(fp, "\n"); + for (int i = 0, j = 0; i < size; i++) { + fprintf(fp, " %i", val[i]); + if(++j == NB_INTEGER_IN_ROW) { + fprintf(fp, "\n"); + j = 0; + } + } + delete [] val; + }else if(type == HDF_CHAR) { + hdf_char* val = new hdf_char[size]; + hdf_dataset->ReadFromDisk(val); + fprintf(fp, "\n"); + for (int i = 0, j = 0; i < size; i++) { + fprintf(fp, " %i", val[i]); + if(++j == NB_INTEGER_IN_ROW) { + fprintf(fp, "\n"); + j = 0; + } + } + delete [] val; + } +} diff --git a/src/HDFPersist/HDFdataset.cc b/src/HDFPersist/HDFdataset.cc index e3ff8fe45..155b8ff1f 100644 --- a/src/HDFPersist/HDFdataset.cc +++ b/src/HDFPersist/HDFdataset.cc @@ -59,6 +59,7 @@ HDFdataset::HDFdataset(const char *name, HDFcontainerObject *father,hdf_type typ _dim[i] = dim[i]; _size = _size * _dim[i]; } + _arrayId = -1; } @@ -74,6 +75,7 @@ HDFdataset::HDFdataset(const char *name,HDFcontainerObject *father) _byte_order = H5T_ORDER_ERROR; _size = -1; _attribute = NULL; + _arrayId = -1; } HDFdataset::~HDFdataset() @@ -83,7 +85,7 @@ HDFdataset::~HDFdataset() void HDFdataset::CreateOnDisk() { - if ((_id = HDFdatasetCreate(_fid,_name,_type,_dim,_ndim,_byte_order)) < 0) + if ((_id = HDFdatasetCreate(_fid,_name,_type,_dim,_ndim,_byte_order,_arrayId)) < 0) throw HDFexception("Can't create dataset"); } @@ -226,3 +228,6 @@ char* HDFdataset::GetAttributeName(unsigned idx) return _attribute; } +void HDFdataset::SetArrayId(hdf_idt arrayId) { + _arrayId = arrayId; +} diff --git a/src/HDFPersist/HDFdataset.hxx b/src/HDFPersist/HDFdataset.hxx index d85778dd5..bc51939f2 100644 --- a/src/HDFPersist/HDFdataset.hxx +++ b/src/HDFPersist/HDFdataset.hxx @@ -43,6 +43,7 @@ private : hdf_size _size; int _ndim; char* _attribute; + hdf_idt _arrayId; public: HDFdataset(const char *name, HDFcontainerObject *father,hdf_type type, @@ -66,6 +67,8 @@ public: hdf_object_type GetObjectType(); hdf_byte_order GetOrder(); + void SetArrayId(hdf_idt arrayId); + int nAttributes(); char* GetAttributeName(unsigned idx); }; diff --git a/src/HDFPersist/HDFdatasetCreate.c b/src/HDFPersist/HDFdatasetCreate.c index 7bbd5f295..7fe7eeb17 100644 --- a/src/HDFPersist/HDFdatasetCreate.c +++ b/src/HDFPersist/HDFdatasetCreate.c @@ -43,7 +43,7 @@ SALOME HDFPersist : implementation of HDF persitent ( save/ restore ) */ hdf_idt HDFdatasetCreate(hdf_idt pid,char *name,hdf_type type, - hdf_size *dimd, int ndim, hdf_byte_order order) + hdf_size *dimd, int ndim, hdf_byte_order order, hdf_idt arrayId) { hdf_idt dataset, dataspace = 0; hdf_err ret; @@ -76,8 +76,12 @@ hdf_idt HDFdatasetCreate(hdf_idt pid,char *name,hdf_type type, return -1; if((ret = H5Tset_size(new_type_hdf,1)) < 0) return -1; - break; + break; + case HDF_ARRAY : + type_hdf = arrayId; + break; + default : return -1; } diff --git a/src/HDFPersist/HDFdatasetGetType.c b/src/HDFPersist/HDFdatasetGetType.c index b782b45f5..34a0b71c4 100644 --- a/src/HDFPersist/HDFdatasetGetType.c +++ b/src/HDFPersist/HDFdatasetGetType.c @@ -56,6 +56,10 @@ HDFdatasetGetType(hdf_idt id) case H5T_STRING : type = HDF_STRING; break; + + case H5T_ARRAY : + type = HDF_ARRAY; + break; default : type = HDF_NONE; diff --git a/src/HDFPersist/HDFtypes.h b/src/HDFPersist/HDFtypes.h index 2d5549468..aac136c5d 100644 --- a/src/HDFPersist/HDFtypes.h +++ b/src/HDFPersist/HDFtypes.h @@ -43,6 +43,7 @@ typedef herr_t hdf_err; typedef hbool_t hdf_bool; typedef H5T_order_t hdf_byte_order; +typedef char hdf_char; typedef int hdf_int32; typedef long hdf_int64; typedef double hdf_float64; @@ -51,15 +52,16 @@ typedef double hdf_float64; typedef enum {HDF_RDONLY,HDF_RDWR} hdf_access_mode; /* Values types for HDF datasets and attributes */ -typedef enum {HDF_NONE,HDF_STRING, HDF_INT32, HDF_INT64, HDF_FLOAT64} hdf_type; +typedef enum {HDF_NONE,HDF_STRING, HDF_INT32, HDF_INT64, HDF_FLOAT64, HDF_CHAR, HDF_ARRAY} hdf_type; /* - HDF_STRING : C string - HDF_INT32 : 32 bits integer - HDF_INT64 : 64 bits integer - HDF_FLOAT64 : IEEE 64 bits float + - HDF_ARRAY : Array */ /* HDF object types */ typedef enum {HDF_OBJECT,HDF_FILE,HDF_GROUP,HDF_DATASET, - HDF_ATTRIBUTE} hdf_object_type; + HDF_ATTRIBUTE, HDF_ARRAY_TYPE } hdf_object_type; #endif /* HDFTYPES_H */ diff --git a/src/HDFPersist/Makefile.am b/src/HDFPersist/Makefile.am index 80e8fd0f3..6001519d6 100644 --- a/src/HDFPersist/Makefile.am +++ b/src/HDFPersist/Makefile.am @@ -38,6 +38,7 @@ salomeinclude_HEADERS = \ HDFgroup.hxx \ HDFinternalObject.hxx \ HDFobject.hxx \ + HDFarray.hxx \ HDFOI.hxx \ HDFtypes.h \ HDFconvert.hxx \ @@ -66,6 +67,12 @@ libSalomeHDFPersist_la_SOURCES =\ HDFdatasetGetType.c \ HDFdatasetGetnDim.c \ HDFdatasetGetOrder.c \ + HDFarrayGetType.c \ + HDFarrayGetTypeId.c \ + HDFarrayCreate.c \ + HDFarrayClose.c \ + HDFarrayGetnDim.c \ + HDFarrayGetDim.c \ HDFattrOpen.c \ HDFattrClose.c \ HDFattrWrite.c \ @@ -78,6 +85,7 @@ libSalomeHDFPersist_la_SOURCES =\ HDFobjectIdentify.c \ HDFobjectType.c \ HDFobject.cc \ + HDFarray.cc \ HDFinternalObject.cc \ HDFattribute.cc \ HDFcontainerObject.cc \ diff --git a/src/HDFPersist/hdfi.h b/src/HDFPersist/hdfi.h index 9c9e3c2fc..ad4878e68 100644 --- a/src/HDFPersist/hdfi.h +++ b/src/HDFPersist/hdfi.h @@ -70,8 +70,8 @@ extern hdf_err HDFdatasetClose(hdf_idt id); extern -hdf_idt HDFdatasetCreate(hdf_idt pid,char *name,hdf_type type, - hdf_size *dimd, int ndim, hdf_byte_order order); +hdf_idt HDFdatasetCreate(hdf_idt pid,char *name, hdf_type type, + hdf_size *dimd, int ndim, hdf_byte_order order, hdf_idt arrayId); extern hdf_err HDFdatasetWrite(hdf_idt id, void *val); @@ -82,6 +82,25 @@ hdf_err HDFdatasetRead(hdf_idt id, void *val); extern hdf_type HDFdatasetGetType(hdf_idt id); +extern +hdf_type HDFarrayGetType(hdf_idt id); + +extern +hdf_idt HDFarrayGetTypeId(hdf_idt type_id); + +extern +hdf_err HDFarrayClose(hdf_idt id); + +extern +int HDFarrayGetnDim(hdf_idt id); + +extern +hdf_err HDFarrayGetDim(hdf_idt id, hdf_size dim[]); + + +extern +hdf_idt HDFarrayCreate(hdf_type dataType,int ndim,hdf_size *dim); + extern int HDFdatasetGetnDim(hdf_idt id);