From a3251c08ad9628ec92a308d85f6c16987de8fe75 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Tue, 12 May 2015 14:27:04 -0600 Subject: [PATCH] Testing for [NCF-331] in pure-hdf5 form. --- h5_test/CMakeLists.txt | 4 +--- h5_test/tst_endian_float.c | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 h5_test/tst_endian_float.c diff --git a/h5_test/CMakeLists.txt b/h5_test/CMakeLists.txt index 23e3d618f..af8a2d5b4 100644 --- a/h5_test/CMakeLists.txt +++ b/h5_test/CMakeLists.txt @@ -1,4 +1,4 @@ -SET(H5TESTS tst_h_files tst_h_files2 tst_h_files4 tst_h_atts tst_h_atts3 tst_h_atts4 tst_h_vars tst_h_vars2 tst_h_vars3 tst_h_grps tst_h_compounds tst_h_compounds2 tst_h_wrt_cmp tst_h_rd_cmp tst_h_vl tst_h_opaques tst_h_strings tst_h_strings1 tst_h_strings2 tst_h_ints tst_h_dimscales tst_h_dimscales1 tst_h_dimscales2 tst_h_dimscales3 tst_h_enums tst_h_dimscales4) +SET(H5TESTS tst_h_files tst_h_files2 tst_h_files4 tst_h_atts tst_h_atts3 tst_h_atts4 tst_h_vars tst_h_vars2 tst_h_vars3 tst_h_grps tst_h_compounds tst_h_compounds2 tst_h_wrt_cmp tst_h_rd_cmp tst_h_vl tst_h_opaques tst_h_strings tst_h_strings1 tst_h_strings2 tst_h_ints tst_h_dimscales tst_h_dimscales1 tst_h_dimscales2 tst_h_dimscales3 tst_h_enums tst_h_dimscales4 tst_endian_float) FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h5 ${CMAKE_CURRENT_SOURCE_DIR}/*.nc) FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) @@ -18,5 +18,3 @@ FILE(GLOB CUR_EXTRA_DIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SO SET(CUR_EXTRA_DIST ${CUR_EXTRA_DIST} ref_tst_h_compounds.h5 ref_tst_h_compounds2.h5 ref_tst_compounds.nc CMakeLists.txt Makefile.am) ADD_EXTRA_DIST("${CUR_EXTRA_DIST}") - - diff --git a/h5_test/tst_endian_float.c b/h5_test/tst_endian_float.c new file mode 100644 index 000000000..bfd8a4173 --- /dev/null +++ b/h5_test/tst_endian_float.c @@ -0,0 +1,48 @@ +/* Test introduced May 12, 2015 as part of debugging NCF-331, + found in the Undiata JIRA system. We are investigating + how endianness is stored to a file. +*/ + +#include "hdf5.h" +#include +#define FILE_NAME "tst_endian_float.h5" +int main() { + + hid_t file_id, dataset_id, attribute_id, dataspace_id; /* identifiers */ + hsize_t dims; + int attr_data[2]; + herr_t status; + + /* Initialize the attribute data. */ + attr_data[0] = 100; + attr_data[1] = 200; + + /* Open an existing file. */ + file_id = H5Fcreate(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT, H5P_DEFAULT); + + /* Open an existing dataset. */ + dataset_id = H5Dopen(file_id, "/dset", H5P_DEFAULT); + + /* Create the data space for the attribute. */ + dims = 2; + dataspace_id = H5Screate_simple(1, &dims, NULL); + + /* Create a dataset attribute. */ + attribute_id = H5Acreate (dataset_id, "Units", H5T_STD_I32BE, dataspace_id, + H5P_DEFAULT, H5P_DEFAULT); + + /* Write the attribute data. */ + status = H5Awrite(attribute_id, H5T_NATIVE_INT, attr_data); + + /* Close the attribute. */ + status = H5Aclose(attribute_id); + + /* Close the dataspace. */ + status = H5Sclose(dataspace_id); + + /* Close to the dataset. */ + status = H5Dclose(dataset_id); + + /* Close the file. */ + status = H5Fclose(file_id); +}