/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

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

#define FNAME                 "linktst.h5"
#define MAX_COMPACT           4
#define MIN_DENSE             3
#define EST_NUM_ENTRIES       4
#define EST_NAME_LEN          8

#define AT()        printf ("    at %s:%d in %s()...\n",          \
                __FILE__, __LINE__, __FUNCTION__);
#define H5_FAILED()    {puts("*FAILED*");fflush(stdout);AT(); goto error;}



/*
 *  this example demonstrates the usage of the following API functions:
 *
 *  H5Pset_link_creation_order
 *  
H5Pget_link_creation_ordr
 *  
H5Pset_est_link_ifo
 *  
H5Pget_est_link_ino
 *  H5Pset_link_phase_change
 *  
H5Pget_link_phase_chang
 */


/*
 *  main program
 *
 */
int main (void)
{
    hid_t          file_id = (-1);                      /* File ID */
    hid_t          group_id = (-1), group_id2 = (-1);   /* Group IDs */
    hid_t          gcpl_id = (-1);                      /* Group creation property list ID */
    unsigned       max_compact;                         /* Maximum # of links to store in group compactly */
    unsigned       min_dense;                           /* Minimum # of links to store in group "densely" */
    unsigned       est_num_entries;                     /* Estimated # of entries in group */
    unsigned       est_name_len;                        /* Estimated length of entry name */
    unsigned       crt_order_flags;                     /* Status of creation order info for GCPL */


    if((file_id = H5Fcreate(FNAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) H5_FAILED();

    /* Create group creation property list */
    if((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0) H5_FAILED();

    /* Set/get creation order tracking & indexing on group */
    if(H5Pset_link_creation_order(gcpl_id, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED)) < 0) H5_FAILED();
    if(H5Pget_link_creation_order(gcpl_id, &crt_order_flags) < 0) H5_FAILED();
    if(crt_order_flags != (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED)) H5_FAILED();
    printf("\nLink create order is set to \"(H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED)\"");

    /* Set/get the group creation properties */
    if(H5Pset_link_phase_change(gcpl_id, MAX_COMPACT, MIN_DENSE) < 0) H5_FAILED();
    if(H5Pget_link_phase_change(gcpl_id, &max_compact, &min_dense) < 0) H5_FAILED();
    if( (max_compact != MAX_COMPACT) || (min_dense != MIN_DENSE) ) H5_FAILED();
    printf("\nMax compact is set to %d", max_compact);
    printf("\nMin dense is set to %d", min_dense);

    /* Set/get H5Pset_est_link_info */
    if(H5Pset_est_link_info(gcpl_id, EST_NUM_ENTRIES, EST_NAME_LEN) < 0) H5_FAILED();
    if(H5Pget_est_link_info(gcpl_id, &est_num_entries, &est_name_len) < 0) H5_FAILED();
    if( (est_num_entries != EST_NUM_ENTRIES) || (est_name_len != EST_NAME_LEN) ) H5_FAILED();
    printf("\nEstimated number of entries is %d", est_num_entries);
    printf("\nEstimated name length is %d", est_name_len);

    /* Create group with creation order indexing & tracking on */
    if((group_id = H5Gcreate2(file_id, "group", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) H5_FAILED();

    /* close IDs */
    puts("\n");
    if(H5Pclose(gcpl_id) < 0) H5_FAILED();
    if(H5Gclose(group_id) < 0) H5_FAILED();
    if(H5Fclose(file_id) < 0) H5_FAILED();

    return 0;

error:
    H5E_BEGIN_TRY {
        H5Pclose(gcpl_id);
        H5Gclose(group_id);
        H5Fclose(file_id);
    } H5E_END_TRY;
    return 1;
} /* main */



