/****h* H5Rf/H5Rf * PURPOSE * This file contains C stubs for H5R Fortran APIs * * COPYRIGHT * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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 COPYING file, which can be found at the root of the source code * * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * * If you do not have access to either file, you may request a copy from * * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ****** */ #include "H5f90.h" #include "H5Eprivate.h" /****if* H5Rf/h5rcreate_region_c * NAME * h5rcreate_region_c * PURPOSE * Call H5Rcreate to create a reference to dataset region * region * INPUTS * loc_id - file or group identifier * name - name of the dataset * namelen - name length * space_id - dataset space identifier * OUTPUTS * ref - reference to the dataset region * RETURNS * 0 on success, -1 on failure * AUTHOR * Elena Pourmal * Wednesday, December 1, 1999 * HISTORY * * SOURCE */ int_f h5rcreate_region_c(int_f *ref, hid_t_f *loc_id, _fcd name, int_f *namelen, hid_t_f *space_id) /******/ { char *c_name = NULL; hdset_reg_ref_t ref_c; int_f ret_value = 0; /* * Convert FORTRAN name to C name */ if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen))) HGOTO_DONE(FAIL) /* * Call H5Rcreate function. */ if(H5Rcreate(&ref_c, (hid_t)*loc_id, c_name, H5R_DATASET_REGION, (hid_t)*space_id) < 0) HGOTO_DONE(FAIL) /* Copy the reference created */ HDmemcpy(ref, &ref_c, H5R_DSET_REG_REF_BUF_SIZE); done: if(c_name) HDfree(c_name); return ret_value; } /* end h5rcreate_region_c() */ /****if* H5Rf/h5rcreate_ptr_c * NAME * h5rcreate_ptr_c * PURPOSE * Call H5Rcreate to create a reference to dataset region * INPUTS * loc_id - file or group identifier * name - name of the dataset * namelen - name length * space_id - dataset space identifier * OUTPUTS * ref - reference to the dataset region * RETURNS * 0 on success, -1 on failure * AUTHOR * M. Scot Breitenfeld * June 20, 2008 * * SOURCE */ int_f h5rcreate_ptr_c (void *ref, hid_t_f *loc_id, _fcd name, int_f *namelen, int_f *ref_type, hid_t_f *space_id) /******/ { int ret_value = -1; char *c_name; /* * Convert FORTRAN name to C name */ c_name = (char *)HD5f2cstring(name, (size_t)*namelen); if (c_name == NULL) return ret_value; /* * Call H5Rcreate function. */ if(H5Rcreate(ref, (hid_t)*loc_id, c_name, (H5R_type_t)*ref_type, (hid_t)*space_id) >= 0) ret_value = 0; HDfree(c_name); return ret_value; } /****if* H5Rf/h5rdereference_ptr_c * NAME * h5rdereference_ptr_c * PURPOSE * Call H5Rdereference * INPUTS * obj_id - Valid identifier for the file containing the * referenced object or any object in that file. * ref_typ - The reference type of ref. * ref - Object reference * OUTPUTS * ref_obj_id - Identifier of referenced object * RETURNS * 0 on success, -1 on failure * AUTHOR * M. Scot Breitenfeld * June 20, 2008 * HISTORY * * SOURCE */ int_f h5rdereference_ptr_c (hid_t_f *obj_id, int_f *ref_type, void *ref, hid_t_f *ref_obj_id) /******/ { int ret_value = -1; hid_t c_ref_obj_id; /* * Call H5Rdereference function. */ c_ref_obj_id = H5Rdereference2((hid_t)*obj_id, H5P_DEFAULT, (H5R_type_t)*ref_type, ref); if(c_ref_obj_id < 0) return ret_value; *ref_obj_id = (hid_t_f)c_ref_obj_id; ret_value = 0; return ret_value; } /****if* H5Rf/h5rget_region_region_object_c * NAME * h5rget_region_region_object_c * PURPOSE * Call H5Rget_region to dereference dataspace region * INPUTS * dset_id - dataset identifier * ref - reference to the dataset region * OUTPUTS * space_id - dereferenced dataset dataspace identifier * RETURNS * 0 on success, -1 on failure * AUTHOR * Elena Pourmal * Wednesday, December 1, 1999 * HISTORY * * SOURCE */ int_f h5rget_region_region_c(hid_t_f *dset_id, int_f *ref, hid_t_f *space_id) /******/ { hid_t c_space_id; hdset_reg_ref_t ref_c; int_f ret_value = 0; /* Copy the reference to dereference */ HDmemcpy(&ref_c, ref, H5R_DSET_REG_REF_BUF_SIZE); /* * Call H5Rget_region function. */ if((c_space_id = H5Rget_region((hid_t)*dset_id, H5R_DATASET_REGION, &ref_c)) < 0) HGOTO_DONE(FAIL) /* Copy the dataspace ID */ *space_id = (hid_t_f)c_space_id; done: return ret_value; } /* end h5rget_region_region_c() */ /****if* H5Rf/h5rget_region_ptr_c * NAME * h5rget_region_ptr_c * PURPOSE * Call H5Rget_region to dereference dataspace region * INPUTS * dset_id - dataset identifier * ref - reference to the dataset region * OUTPUTS * space_id - dereferenced dataset dataspace identifier * RETURNS * 0 on success, -1 on failure * AUTHOR * M. Scot Breitenfeld * August 4, 2012 * HISTORY * * SOURCE */ int_f h5rget_region_ptr_c(hid_t_f *dset_id, void *ref, hid_t_f *space_id) /******/ { hid_t c_space_id; int_f ret_value = 0; /* * Call H5Rget_region function. */ if((c_space_id = H5Rget_region((hid_t)*dset_id, H5R_DATASET_REGION, ref)) < 0) HGOTO_DONE(FAIL) /* Copy the dataspace ID */ *space_id = (hid_t_f)c_space_id; done: return ret_value; } /* end h5rget_region_ptr_c() */ /****if* H5Rf/h5rget_object_type_obj_c * NAME * h5rget_object_type_obj_c * PURPOSE * Call H5Rget_object_type to retrieve the type of the object reference points * to * INPUTS * dset_id - dataset identifier * ref - reference to the dataset region * OUTPUTS * obj_type - type of dereferenced object * RETURNS * 0 on success, -1 on failure * AUTHOR * Elena Pourmal * Wednesday, December 1, 1999 * HISTORY * * SOURCE */ int_f h5rget_object_type_obj_c(hid_t_f *dset_id, haddr_t_f *ref, int_f *obj_type) /******/ { H5O_type_t c_obj_type; hobj_ref_t ref_c = (hobj_ref_t)*ref; int_f ret_value = 0; /* * Call H5Rget_object_type function. */ if(H5Rget_obj_type2((hid_t)*dset_id, H5R_OBJECT, &ref_c, &c_obj_type) < 0) HGOTO_DONE(FAIL) /* Copy the object type */ *obj_type = (int_f)c_obj_type; done: return ret_value; } /* end h5rget_object_type_obj_c() */ /****if* H5Rf/h5rget_name_ptr_c * NAME * h5rget_name_ptr_c * PURPOSE * Call H5Rget_name * INPUTS * * loc_id - Identifier for the dataset containing the reference or for the group that dataset is in. * ref_type - Type of reference. * ref - An object or dataset region reference. * * OUTPUTS * name - A name associated with the referenced object or dataset region. * size - The size of the name buffer. * * RETURNS * 0 on success, -1 on failure * AUTHOR * M. Scot Breitenfeld * June 20, 2008 * HISTORY * * SOURCE */ int_f h5rget_name_ptr_c (hid_t_f *loc_id, int_f *ref_type, void *ref, _fcd name, size_t_f *name_len, size_t_f *size_default) /******/ { int_f ret_value = -1; ssize_t c_size; size_t c_bufsize; char *c_buf= NULL; /* Buffer to hold C string */ c_bufsize = (size_t)*name_len+1; /* * Allocate buffer to hold name of an attribute */ if ((c_buf = (char *)HDmalloc(c_bufsize)) == NULL) return ret_value; /* * Call H5Rget_name function. */ if((c_size=H5Rget_name((hid_t)*loc_id, (H5R_type_t)*ref_type, ref, c_buf, c_bufsize)) < 0){ if(c_buf) HDfree(c_buf); return ret_value; } /* * Convert C name to FORTRAN and place it in the given buffer */ HD5packFstring(c_buf, _fcdtocp(name), c_bufsize-1); *size_default = (size_t_f)c_size; ret_value = 0; if(c_buf) HDfree(c_buf); return ret_value; } /****if* H5Rf/h5rget_obj_type_c * NAME * h5rget_obj_type_c * PURPOSE * Call H5Rget_obj_type * INPUTS * loc_id - Identifier for the dataset containing the reference or * for the group that dataset is in. * ref_type - Type of reference to query. * ref - Reference to query. * * OUTPUTS * obj_type - Type of referenced object. These are defined in H5Opublic.h, * enum H5O_type_t * * RETURNS * 0 on success, -1 on failure * AUTHOR * M. Scot Breitenfeld * December 17, 2008 * * SOURCE */ int_f h5rget_obj_type_c (hid_t_f *loc_id, int_f *ref_type, void *ref, int_f *obj_type) /******/ { int_f ret_value = -1; H5O_type_t obj_type_c; /* * Call H5Rget_obj_type function. */ if((H5Rget_obj_type2((hid_t)*loc_id, (H5R_type_t)*ref_type, ref, &obj_type_c)) < 0) return ret_value; *obj_type = (int_f)obj_type_c; ret_value = 0; return ret_value; } 3' href='#n13'>13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * 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 COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************

  This example illustrates the concept of the virtual dataset.
  Percival use case. Every fifth 10x10 plane in VDS is stored in 
  the corresponding 3D unlimited dataset. 
  There are 4 source datasets total.
  This file is intended for use with HDF5 Library version 1.10

 ************************************************************/
/* EIP Add link to the picture */

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

#define VFILE        "vds-percival-unlim.h5"
#define DATASET      "VDS-Percival-unlim"
#define VDSDIM0       H5S_UNLIMITED 
#define VDSDIM1       10 
#define VDSDIM2       10 

#define DIM0          H5S_UNLIMITED 
#define DIM0_1        10  /* Initial size of the datasets */
#define DIM1          10 
#define DIM2          10 
#define RANK          3 
#define PLANE_STRIDE  4

const char *SRC_FILE[] = {
    "a.h5",
    "b.h5",
    "c.h5",
    "d.h5"
};

const char *SRC_DATASET[] = {
    "A",
    "B",
    "C",
    "D"
};

int
main (void)
{
    hid_t        vfile, file, src_space, mem_space, vspace,
                 vdset, dset;                       /* Handles */
    hid_t        dcpl;
    herr_t       status;
    hsize_t      vdsdims[3] = {4*DIM0_1, VDSDIM1, VDSDIM2},
                 vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2}, 
                 dims[3] = {DIM0_1, DIM1, DIM2},
                 extdims[3] = {2*DIM0_1, DIM1, DIM2},
                 chunk_dims[3] = {DIM0_1, DIM1, DIM2},
                 dims_max[3] = {DIM0, DIM1, DIM2},
                 vdsdims_out[3],
                 vdsdims_max_out[3],
                 start[3],                   /* Hyperslab parameters */
                 stride[3],
                 count[3],
                 src_count[3],
                 block[3];
    hsize_t      start_out[3],               /* Hyperslab parameter out */
                 stride_out[3],
                 count_out[3],
                 block_out[3];
    int          i, j, k;
    H5D_layout_t layout;                     /* Storage layout */
    size_t       num_map;                    /* Number of mappings */
    ssize_t      len;                        /* Length of the string; also a return value */
    char         *filename;
    char         *dsetname;
    int          wdata[DIM0_1*DIM1*DIM2];
    int          rdata[80][10][10];
    int          a_rdata[20][10][10];

    /*
     * Create source files and datasets. This step is optional.
     */
    for (i=0; i < PLANE_STRIDE; i++) {
        /*
         * Initialize data for i-th source dataset.
         */
        for (j = 0; j < DIM0_1*DIM1*DIM2; j++) wdata[j] = i+1;

        /*
         * Create the source files and  datasets. Write data to each dataset and 
         * close all resources.
         */

        file = H5Fcreate (SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
        src_space = H5Screate_simple (RANK, dims, dims_max);
        dcpl = H5Pcreate(H5P_DATASET_CREATE);
        status = H5Pset_chunk (dcpl, RANK, chunk_dims);
        dset = H5Dcreate2 (file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT,
                    dcpl, H5P_DEFAULT);
        status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                    wdata);
        status = H5Sclose (src_space);
        status = H5Pclose (dcpl);
        status = H5Dclose (dset);
        status = H5Fclose (file);
    }    

    vfile = H5Fcreate (VFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /* Create VDS dataspace.  */
    vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max);

    /* Create dataspaces for the source dataset. */
    src_space = H5Screate_simple (RANK, dims, dims_max);

    /* Create VDS creation property */
    dcpl = H5Pcreate (H5P_DATASET_CREATE);
     
    /* Initialize hyperslab values */

    start[0] = 0;
    start[1] = 0;
    start[2] = 0;
    stride[0] = PLANE_STRIDE; /* we will select every fifth plane in VDS */
    stride[1] = 1;
    stride[2] = 1;
    count[0] = H5S_UNLIMITED;
    count[1] = 1;
    count[2] = 1;
    src_count[0] = H5S_UNLIMITED;
    src_count[1] = 1;
    src_count[2] = 1;
    block[0] = 1;
    block[1] = DIM1;
    block[2] = DIM2;

    /* 
     * Build the mappings 
     *
     */
    status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, src_count, block);
    for (i=0; i < PLANE_STRIDE; i++) {
        status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block);
        status = H5Pset_virtual (dcpl, vspace, SRC_FILE[i], SRC_DATASET[i], src_space);
        start[0]++; 
    } 

    H5Sselect_none(vspace); 

    /* Create a virtual dataset */
    vdset = H5Dcreate2 (vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
                dcpl, H5P_DEFAULT);
    status = H5Sclose (vspace);
    status = H5Sclose (src_space);
    status = H5Pclose (dcpl);
    /* Let's get space of the VDS and its dimension; we should get 40x10x10 */
    vspace = H5Dget_space (vdset);
    H5Sget_simple_extent_dims (vspace, vdsdims_out, vdsdims_max_out);
    printf ("VDS dimensions first time \n");
    printf (" Current: ");
    for (i=0; i<RANK; i++)
        printf (" %d ", (int)vdsdims_out[i]);
    printf ("\n");

    /* Let's add data to the source datasets and check new dimensions for VDS */

    for (i=0; i < PLANE_STRIDE; i++) {
        /*
         * Initialize data for i-th source dataset.
         */
        for (j = 0; j < DIM0_1*DIM1*DIM2; j++) wdata[j] = 10*(i+1);

        /*
         * Create the source files and  datasets. Write data to each dataset and 
         * close all resources.
         */

        file = H5Fopen (SRC_FILE[i], H5F_ACC_RDWR, H5P_DEFAULT);
        dset = H5Dopen2 (file, SRC_DATASET[i], H5P_DEFAULT);
        status = H5Dset_extent (dset, extdims);       
        src_space = H5Dget_space (dset);
        start[0] = DIM0_1;
        start[1] = 0;
        start[2] = 0;
        count[0] = 1;
        count[1] = 1;
        count[2] = 1;
        block[0] = DIM0_1;
        block[1] = DIM1;
        block[2] = DIM2;

        mem_space = H5Screate_simple(RANK, dims, NULL); 
        status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, count, block);
        status = H5Dwrite (dset, H5T_NATIVE_INT, mem_space, src_space, H5P_DEFAULT,
                    wdata);
        status = H5Sclose (src_space);
        status = H5Dclose (dset);
        status = H5Fclose (file);
      }

    status = H5Dclose (vdset);
    status = H5Fclose (vfile);    
     
    /*
     * Now we begin the read section of this example.
     */

    /*
     * Open file and dataset using the default properties.
     */
    vfile = H5Fopen (VFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
    vdset = H5Dopen2 (vfile, DATASET, H5P_DEFAULT);

    /*
     * Get creation property list and mapping properties.
     */
    dcpl = H5Dget_create_plist (vdset);

    /*
     * Get storage layout.
     */
    layout = H5Pget_layout (dcpl);

    if (H5D_VIRTUAL == layout) 
        printf(" Dataset has a virtual layout \n");
    else
        printf(" Wrong layout found \n");

     /*
      * Find number of mappings.
      */
     status = H5Pget_virtual_count (dcpl, &num_map);
     printf(" Number of mappings is %lu\n", (unsigned long)num_map);

     /* 
      * Get mapping parameters for each mapping.
      */
      for (i = 0; i < (int)num_map; i++) {   
      printf(" Mapping %d \n", i);
      printf("         Selection in the virtual dataset \n");
      /* Get selection in the virttual  dataset */
          vspace = H5Pget_virtual_vspace (dcpl, (size_t)i);
          if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) { 
              if (H5Sis_regular_hyperslab(vspace)) {
                   status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out);
                   printf("         start  = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
                   printf("         stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
                   printf("         count  = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);
                   printf("         block  = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]);
               }
          }
      /* Get source file name */
          len = H5Pget_virtual_filename (dcpl, (size_t)i, NULL, 0);
          filename = (char *)malloc((size_t)len*sizeof(char)+1);
          H5Pget_virtual_filename (dcpl, (size_t)i, filename, len+1);
          printf("         Source filename %s\n", filename);

      /* Get source dataset name */
          len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0);
          dsetname = (char *)malloc((size_t)len*sizeof(char)+1);
          H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1);
          printf("         Source dataset name %s\n", dsetname);

      /* Get selection in the source dataset */
          printf("         Selection in the source dataset \n");
          src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i);
          if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
              if (H5Sis_regular_hyperslab(src_space)) {
                   status = H5Sget_regular_hyperslab (src_space, start_out, stride_out, count_out, block_out);
                   printf("         start  = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
                   printf("         stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
                   printf("         count  = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);