/************************************************************ This example shows how to read and write bitfield datatypes to an attribute. The program first writes bit fields to an attribute with a dataspace of DIM0xDIM1, then closes the file. Next, it reopens the file, reads back the data, and outputs it to the screen. This file is intended for use with HDF5 Library version 1.8 ************************************************************/ #include "hdf5.h" #include #include #define FILE "h5ex_t_bitatt.h5" #define DATASET "DS1" #define ATTRIBUTE "A1" #define DIM0 4 #define DIM1 7 int main (void) { hid_t file, space, dset, attr; /* Handles */ herr_t status; hsize_t dims[2] = {DIM0, DIM1}; unsigned char wdata[DIM0][DIM1], /* Write buffer */ **rdata; /* Read buffer */ int ndims, A, B, C, D, i, j; /* * Initialize data. We will manually pack 4 2-bit integers into * each unsigned char data element. */ for (i=0; i> 2) & 0x03; /* Retrieve field "B" */ C = (rdata[i][j] >> 4) & 0x03; /* Retrieve field "C" */ D = (rdata[i][j] >> 6) & 0x03; /* Retrieve field "D" */ printf (" {%d, %d, %d, %d}", A, B, C, D); } printf (" ]\n"); } /* * Close and release resources. */ free (rdata[0]); free (rdata); status = H5Aclose (attr); status = H5Dclose (dset); status = H5Sclose (space); status = H5Fclose (file); return 0; }