/* 
    This example shows how to create a dense attribute greater than
    64K.  

    This code is intended for use with HDF5 library version 1.8
*/

#include "hdf5.h"
#include <stdio.h>

#define FILENAME "h5ex_p_attdense.h5"
#define SIZE 100000000 
double data [SIZE];

int main(){

    hid_t fid, gid, sid, aid, gpid, fpid;
    hsize_t dims[] = {SIZE};
    long int i;
    herr_t status;

    /* Fill a buffer with data values */
    for (i=0; i<dims[0]; i++)
         data[i]=2.2; 

    /* Modify property list to use latest library version when creating objects */ 
    fpid = H5Pcreate (H5P_FILE_ACCESS);
    status = H5Pset_libver_bounds (fpid, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);

    /* Create a new file using the modified property list */
    fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fpid);

    /* Modify property list to always create a dense attribute */
    gpid = H5Pcreate (H5P_GROUP_CREATE);
    status = H5Pset_attr_phase_change (gpid, 0, 0);

    /* Create a group using the modified property list */
    gid = H5Gcreate(fid, "GRP1", H5P_DEFAULT, gpid, H5P_DEFAULT);

    /* Create a dense attribute in the group "GRP1" */
    sid = H5Screate_simple(1, dims, NULL);
    aid = H5Acreate(gid, "Dense Attribute", H5T_NATIVE_DOUBLE, sid, H5P_DEFAULT, H5P_DEFAULT);

    /* Write buffer of data to the attribute */
    status = H5Awrite (aid, H5T_NATIVE_DOUBLE, data);

    /* Close all objects that were opened */
    status = H5Aclose(aid);
    status = H5Pclose (gpid);
    status = H5Pclose (fpid);
    status = H5Gclose(gid);
    status = H5Fclose (fid);
  
    return 0;
}

    

