/**********************************************************

   h5_moved  

   Purpose:  Move a Dataset from one group to another

 ***********************************************************/

#include "hdf5.h"
#define FILE "move.h5"

main() {

   hid_t       file_id, group1_id;  /* identifiers */
   hid_t       group_id, dataset_id, dataspace_id;
   herr_t      status;
   hsize_t     dims[2];
   int         i, j, dset_data[3][3];


   /* Create a new file using default properties. */
   file_id = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

   /* Create group "MyGroup" in the root group using absolute name. */
   group_id = H5Gcreate (file_id, "/MyGroup", 0);

   /* Create group "Group_A" in group "MyGroup" using absolute name. */
   group1_id = H5Gcreate (file_id, "/MyGroup/Group_A", 0);

  /* Initialize the first dataset. */
   for (i = 0; i < 3; i++)
      for (j = 0; j < 3; j++)
         dset_data[i][j] = j + 1;

   /* Create the data space for the first dataset. */
   dims[0] = 3;
   dims[1] = 3;
   dataspace_id = H5Screate_simple(2, dims, NULL);

   /* Create a dataset in group "MyGroup". */
   dataset_id = H5Dcreate (file_id, "/MyGroup/dset", H5T_STD_I32BE, 
                           dataspace_id , H5P_DEFAULT);

   /* Write the first dataset. */
   status = H5Dwrite (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                      dset_data);

   /* Close the data space for the first dataset. */
   status = H5Sclose (dataspace_id);

   /* Close the first dataset. */
   status = H5Dclose (dataset_id);

   /* Close groups. */
   status = H5Gclose (group_id);
   status = H5Gclose (group1_id);

/***********************************************************
 If you comment the following code out, then "dset" will be 
 under "/MyGroup".  If this code is not commented out then 
 you will find that "dset" is under "/MyGroup/Group_A".
 ***********************************************************/

   status = H5Glink (file_id, H5G_LINK_HARD, "/MyGroup/dset", 
                     "/MyGroup/Group_A/dset");
 
   status = H5Gunlink (file_id, "/MyGroup/dset");  

/************************************************************
 End of Section to comment out
 ***********************************************************/

   /* Close the file. */
   status = H5Fclose (file_id);
}
