/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 *  This example describes some effects of the 'use latest format' feature
 *  on the files and their sizes.  The example:
 *	- creates 2 files, one with "use latest format,"
 *	- creates 200 empty groups in each file, then
 *	- closes the files
 *
 *  When created with the 'use latest format' feature, a file cannot be 
 *  opened by a library prior to version 1.8. (Elena: #1) In addition, there
 *  is a significant difference in sizes of files with and without the 
 *  "use latest format" feature.  The difference in file sizes can be 
 *  observed using the 'ls -l' command at the command prompt on a UNIX 
 *  system.  The file using the latest format feature is significantly 
 *  smaller than the other (about one quarter.)
 */

/*
Elena: #1 - Please note that the file was not opened at all, not just not
read.  Error:
	h5dump error: unable to open file "h5_latest.h5"
Is that correct?
*/

#include "hdf5.h"

#define TRUE             1

#define FILE_NAME        "h5_oldformat.h5"
#define LATEST_FILE_NAME "h5_latest.h5"
#define NUM_GROUPS	 200  /* number of groups to be created in each file */

int
main (void)
{
    hid_t       file, file_latest;	/* file and file-with-latest handles */
    hid_t	fapl;			/* file access property list */
    herr_t      status;			/* returned status */
    int         i;			/* loop index */

    /* 
     * Create file access property and set the 'use latest format' flag in it.
     */
    fapl = H5Pcreate(H5P_FILE_ACCESS);
    status = H5Pset_latest_format(fapl, TRUE);

    /*
     * Create a new file using H5F_ACC_TRUNC access, default file creation 
     * and default file access properties.
     */
    file = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Create a new file using H5F_ACC_TRUNC access, default file creation 
     * properties, and user-defined file access properties with 'use latest
     * format' flag set.
     */
    file_latest = H5Fcreate(LATEST_FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);

    /*
     * Create NUM_GROUPS groups in each file.
     */
    for (i = 0; i < NUM_GROUPS; i++)
    {
	char  str[4];
	int   istat;
	char  grp_name[11] = "Group #";
	hid_t grp, grp_latest;

	/*
	 * Make the group name using the loop index.
	 */
	istat = sprintf(str, "%d", i);
	strcat(grp_name, str);

	/*
	 * Create a group in each file.
	 */
	grp = H5Gcreate2(file, grp_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	grp_latest = H5Gcreate2(file_latest, grp_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

	/*
	 * Close the groups.
	 */
	H5Gclose(grp);
	H5Gclose(grp_latest);
    }

    /*
     * Close the files.
     */
    H5Fclose(file);
    H5Fclose(file_latest);

    return 0;
}

