From: eap Date: Mon, 7 Nov 2005 15:12:02 +0000 (+0000) Subject: PAL6948 (Persistence in MED). Get byte order of dataset and store it in ASCII format X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1872cf261f59cb2849835260f43cc2c62dac9edf;p=modules%2Fkernel.git PAL6948 (Persistence in MED). Get byte order of dataset and store it in ASCII format --- diff --git a/src/HDFPersist/HDFascii.cc b/src/HDFPersist/HDFascii.cc index 54577e068..3e5d386e5 100644 --- a/src/HDFPersist/HDFascii.cc +++ b/src/HDFPersist/HDFascii.cc @@ -220,7 +220,8 @@ void SaveDatasetInASCIIfile(HDFdataset *hdf_dataset, FILE* fp, int ident) 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'); @@ -247,7 +248,8 @@ void SaveDatasetInASCIIfile(HDFdataset *hdf_dataset, FILE* fp, int ident) 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]; @@ -507,6 +509,7 @@ bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp) { char name[HDF_NAME_MAX_LEN+1]; hdf_type type; + hdf_byte_order order; int nbDim, nbAttr; long i, size; @@ -522,15 +525,22 @@ bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp) 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); diff --git a/src/HDFPersist/HDFdataset.cc b/src/HDFPersist/HDFdataset.cc index 84a2f5ae6..789f6e1a6 100644 --- a/src/HDFPersist/HDFdataset.cc +++ b/src/HDFPersist/HDFdataset.cc @@ -44,7 +44,7 @@ herr_t dataset_attr(hid_t loc_id, const char *attr_name, void *operator_data) } 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; @@ -55,6 +55,7 @@ HDFdataset::HDFdataset(char *name, HDFcontainerObject *father,hdf_type type, _type = type; _ndim = dimsize; _dim = new hdf_size[dimsize]; + _byte_order = order; _size = 1; _attribute = NULL; for (i=0;i + +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; +} diff --git a/src/HDFPersist/hdfi.h b/src/HDFPersist/hdfi.h index e1810953d..dec0560df 100644 --- a/src/HDFPersist/hdfi.h +++ b/src/HDFPersist/hdfi.h @@ -67,7 +67,7 @@ hdf_err HDFdatasetClose(hdf_idt id); 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); @@ -87,6 +87,9 @@ hdf_err HDFdatasetGetDim(hdf_idt id,hdf_size dim[]); 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);