VDS: Help understanding behaviour of the PRINTF style syntax


#1

Hi folks,
I am trying to understand the new VDS feature by writing test scripts. I am attempting to create a VDS having unlimited dimensions using 5 fixed size source datasets. This requires me to use the printf-style syntax when specifying the mapping. I have uploaded my source HDF5 file containing the datasets and the code below. The comments in the code explain the issue. Would appreciate any help?

Dinesh

srcFile_0.h5 (34.6 KB)

#include "hdf5.h"
#include "stdio.h"

#define FILENAME "fileWithVDSUnlimSizeUsingFixedSource_C.h5"
#define DSETNAME "myVDSdsetUnlimDims_C"

/* Code below creates a virtual dataset having unlimited dimensions using 5 
 * fixed size source datasets using the printf syntax.
 * The source datasets are name /dset_0, /dset_1, /dset_2, /dset_3, /dset_4
 * and have dimensions 9x7x10 each.
 * The VDS has dimensions 9x7xInf.
 * My expection is that the VDS will have dimensions 9x7x50 based on the 
 * mapping specified. However, the resulting VDS is only 9x7x5 and I am 
 * unable to understand why.
 */
int main(int argc, char* argv[]) 
{
    hid_t faplID = H5Pcreate(H5P_FILE_ACCESS);
    H5Pset_libver_bounds(faplID, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
    
    hid_t fileID = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, faplID);

    hid_t dcplID = H5Pcreate(H5P_DATASET_CREATE);

    // Set the fill-value
    hid_t fillTypeID = H5Tcopy(H5T_NATIVE_DOUBLE);
    double fillValue = -9999;
    H5Pset_fill_value(dcplID, fillTypeID, &fillValue);
    H5Pset_fill_time(dcplID, H5D_FILL_TIME_ALLOC);
    
    // Create the VDS Source Dataspace
    hsize_t vdsH5Dims[] = {9, 7, 0};
    hsize_t vdsH5MaxDims[] = {9, 7, H5S_UNLIMITED};
    hid_t vdsSpaceID = H5Screate_simple(3, vdsH5Dims, vdsH5MaxDims);
    
    // Set the chunking
    hsize_t vdsH5ChunkDims[] = {4, 3, 1};
    H5Pset_chunk(dcplID, 3, vdsH5ChunkDims);
    
    // VDS Hyperslab selection
    hsize_t vdsH5Start[] = {0, 0, 0};
    hsize_t vdsH5Stride[] = {1, 1, 1};
    hsize_t vdsH5Count[] = {1, 1, H5S_UNLIMITED};
    hsize_t vdsH5Block[] = {9, 7, 1};
    
    herr_t err = H5Sselect_hyperslab(vdsSpaceID, H5S_SELECT_SET, vdsH5Start, vdsH5Stride, vdsH5Count, vdsH5Block);
    
    // Create source dataspace
    hsize_t srcH5Dims[] = {9, 7, 10};
    hid_t srcSpaceID = H5Screate_simple(3, srcH5Dims, NULL);
    
    // Perform a hyperslab selection on the source. I am doing this because 
    // without this the call the H5Pset_virtual errors with the following 
    // message:
    // H5D_virtual_check_mapping_post    virtual (single block) and source space selections have
    // different numbers of elements
    // H5Pset_virtual                    invalid mapping entry
    //
    hsize_t srcH5Start[] = {0, 0, 0};
    hsize_t srcH5Stride[] = {1, 1, 1};
    hsize_t srcH5Count[] = {1, 1, 1}; // Changing this to {1, 1, 10} also generates same error as above
    hsize_t srcH5Block[] = {9, 7, 1};
    err = H5Sselect_hyperslab(srcSpaceID, H5S_SELECT_SET, srcH5Start, srcH5Stride, srcH5Count, srcH5Block);
    
    err = H5Pset_virtual(dcplID, vdsSpaceID, "srcFile_0.h5", "/dset_%b", srcSpaceID);
    if(err < 0) {
        printf("Virtual mapping failed\n");
        return -1;
    }
    
    // Now that all of the mappings are specified, create the dataset
    H5Sselect_none(vdsSpaceID);

    hid_t typeID = H5Tcopy(H5T_NATIVE_DOUBLE);
    hid_t vdsDsetID = H5Dcreate(fileID, DSETNAME, typeID, vdsSpaceID, H5P_DEFAULT, dcplID, H5P_DEFAULT);
    
    H5Tclose(typeID);
    H5Tclose(fillTypeID);
    H5Sclose(vdsSpaceID);
    H5Sclose(srcSpaceID);
    H5Dclose(vdsDsetID);
    H5Pclose(dcplID);
    H5Pclose(faplID);
    H5Fclose(fileID);
    
    return 0;
}