/* ############################################################################## # # Copyright by The HDF Group. # All rights reserved. # # This file is part of the hl_region High-Level HDF5 APIs. The full copyright # notice, including terms governing use, modification, and redistribution, # is contained in the file COPYING, which can be found at the root of the # source code distribution tree and in the documentation directory (doc/html/). # If you do not have access to this file, you may request a copy of # "the hl_region High-Level HDF5 APIs copyright and license statement" from # help@hdfgroup.org. # ############################################################################## */ /* This example shows how to read and write bitfield datatypes to a dataset. The program first writes bit fields to a dataset with a dataspace of DIM0xDIM1, then closes the file. Next, it reopens the file, and extracts the bit field using a given starting bit and number of bits in the bit-field. The values are returned as a base-10 integer. Main illustrative function: H5LTread_bitfield_value */ #include #include "hdf5.h" #include "hdf5_hl.h" #include "h5hl_region.h" #define filename "ex_bitfield.h5" #define DIM0 4 #define DIM1 7 #define num_flags 4 int main(void) { int qf_data[DIM0][DIM1][num_flags]; /* Read buffer */ unsigned int offset[4] = {0,2,4,6}; /* Starting bits to be extracted from element */ unsigned int length[4] = {2,2,2,2}; /* Number of bits to be extracted for each value */ hid_t file, space; /* Handles */ hid_t qf_dset; herr_t status; int rank = 2; hsize_t dims[2] = {DIM0,DIM1}; hid_t file_id; unsigned char wdata[DIM0][DIM1]; /* Write buffer */ int i, j, k; /* * Initialize data. We will manually fill four 2-bit integers into * each unsigned char data element. */ for (i=0; i