long ndim = hdf_dataset->nDim(); //Get number of dimesions
hdf_size *dim = new hdf_size[ndim];
hdf_type type = hdf_dataset->GetType();
- int nbAttr = hdf_dataset->nAttributes(), j;
+ hdf_byte_order order = hdf_dataset->GetOrder();
+ int nbAttr = hdf_dataset->nAttributes();
TCollection_AsciiString anIdent(ident, '\t');
TCollection_AsciiString anIdentChild(ident+1, '\t');
delete dim;
/*fprintf(fp, "%s%li:", anIdentChild.ToCString(), size);*/
- fprintf(fp, "%li:", size);
+// fprintf(fp, "%li:", size);
+ fprintf(fp, "%li %i:", size, order);
if (type == HDF_STRING) {
char* val = new char[size];
{
char name[HDF_NAME_MAX_LEN+1];
hdf_type type;
+ hdf_byte_order order;
int nbDim, nbAttr;
long i, size;
sizeArray[i] = dim;
}
- HDFdataset* hdf_dataset = new HDFdataset(new_name, father,type, sizeArray, nbDim);
+ // 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 ":"
+ fscanf(fp, "%c", &tmp);
+ order = H5T_ORDER_NONE;
+ }
+ 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);
delete new_name;
delete sizeArray;
hdf_dataset->CreateOnDisk();
- char tmp;
- fscanf(fp, "%li%c", &size, &tmp);
-
if (type == HDF_STRING) {
char *val = new char[size+1];
fread(val, 1, size, fp);
}
HDFdataset::HDFdataset(char *name, HDFcontainerObject *father,hdf_type type,
- hdf_size dim[], int dimsize)
+ hdf_size dim[], int dimsize, hdf_byte_order order)
: HDFinternalObject(name)
{
int i;
_type = type;
_ndim = dimsize;
_dim = new hdf_size[dimsize];
+ _byte_order = order;
_size = 1;
_attribute = NULL;
for (i=0;i<dimsize;i++)
_type = HDF_NONE;
_ndim = -1;
_dim = 0;
+ _byte_order = H5T_ORDER_ERROR;
_size = -1;
_attribute = NULL;
}
void HDFdataset::CreateOnDisk()
{
- if ((_id = HDFdatasetCreate(_fid,_name,_type,_dim,_ndim)) < 0)
+ if ((_id = HDFdatasetCreate(_fid,_name,_type,_dim,_ndim,_byte_order)) < 0)
throw HDFexception("Can't create dataset");
}
return _size;
}
+hdf_byte_order HDFdataset::GetOrder()
+{
+ if (_byte_order < 0 )
+ if ((_byte_order = HDFdatasetGetOrder( _id )) < 0)
+ throw HDFexception("Can't determine the byte order of the dataset");
+ return _byte_order;
+}
+
hdf_object_type HDFdataset::GetObjectType()
{
return HDF_DATASET;
hdf_idt _fid;
hdf_type _type;
hdf_size *_dim;
+ hdf_byte_order _byte_order;
int _size;
int _ndim;
char* _attribute;
public:
HDFdataset(char *name, HDFcontainerObject *father,hdf_type type,
- hdf_size dim[],int dimsize);
+ hdf_size dim[],int dimsize, hdf_byte_order order = H5T_ORDER_NONE);
HDFdataset(char *name,HDFcontainerObject *father);
virtual ~HDFdataset();
void GetDim(hdf_size dim[]);
int GetSize();
hdf_object_type GetObjectType();
+ hdf_byte_order GetOrder();
int nAttributes();
char* GetAttributeName(unsigned idx);
* - name (IN) : dataset name
* - type (IN) : dataset type (HDF_STRING,HDF_INT32,HDF_INT64,HDF_FLOAT64)
* - dimd (IN) : dataset size
+ * - order(IN) : byte order (H5T_ORDER_NONE, H5T_ORDER_LE, H5T_ORDER_BE)
* - Result :
* - if success : returns dataset ID
* - if failure : -1
*/
hdf_idt HDFdatasetCreate(hdf_idt pid,char *name,hdf_type type,
- hdf_size *dimd, int ndim)
+ hdf_size *dimd, int ndim, hdf_byte_order order)
{
hdf_idt dataset, dataspace = 0;
hdf_err ret;
- int type_hdf;
+ hdf_idt type_hdf, new_type_hdf = -1;
switch(type)
{
break;
case HDF_STRING :
- if((type_hdf = H5Tcopy(H5T_C_S1)) < 0)
+ if((new_type_hdf = H5Tcopy(H5T_C_S1)) < 0)
return -1;
- if((ret = H5Tset_size(type_hdf,1)) < 0)
+ if((ret = H5Tset_size(new_type_hdf,1)) < 0)
return -1;
break;
return -1;
}
+ /* set order */
+ if ( order != H5T_ORDER_ERROR &&
+ order != H5T_ORDER_NONE &&
+ type != HDF_STRING )
+ {
+ if (( new_type_hdf = H5Tcopy( type_hdf )) < 0 )
+ return -1;
+ if (( ret = H5Tset_order (new_type_hdf, order )) < 0 )
+ return -1;
+ }
+
if ((dataset = H5Dopen(pid,name)) < 0)
{
if ((dataspace = H5Screate_simple(ndim, dimd, NULL)) < 0)
return -1;
- if ((dataset = H5Dcreate(pid,name,type_hdf,dataspace, H5P_DEFAULT)) < 0)
+ if ((dataset = H5Dcreate(pid,name,
+ new_type_hdf < 0 ? type_hdf : new_type_hdf,
+ dataspace, H5P_DEFAULT)) < 0)
return -1;
}
else
return -1;
+ if ( ! (new_type_hdf < 0) && (ret = H5Tclose(new_type_hdf)) < 0)
+ return -1;
if ((ret = H5Sclose(dataspace)) < 0)
- return -1;
+ return -1;
return dataset;
}
--- /dev/null
+/*----------------------------------------------------------------------------
+SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
+
+ Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+
+
+
+ File : HDFdatasetGetOrder.c
+Module : SALOME
+----------------------------------------------------------------------------*/
+
+#include "hdfi.h"
+#include <hdf5.h>
+
+hdf_byte_order
+HDFdatasetGetOrder(hdf_idt dataset_id)
+{
+ hdf_idt type_id;
+ hdf_byte_order order;
+
+ if ((type_id = H5Dget_type(dataset_id)) < 0)
+ return -1;
+
+ order = H5Tget_order(type_id);
+
+ H5Tclose(type_id);
+
+ return order;
+}
extern
hdf_idt HDFdatasetCreate(hdf_idt pid,char *name,hdf_type type,
- hdf_size *dimd, int ndim);
+ hdf_size *dimd, int ndim, hdf_byte_order order);
extern
hdf_err HDFdatasetWrite(hdf_idt id, void *val);
extern
int HDFdatasetGetSize(hdf_idt id);
+extern
+hdf_byte_order HDFdatasetGetOrder(hdf_idt id);
+
/* Attribute interface */
extern
hdf_idt HDFattrOpen(hdf_idt pid,char *name);