/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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 illustrates how to read/write a subset of data (a slab) * from/to a dataset in an HDF5 file. It is used in the HDF5 Tutorial. */ #include "hdf5.h" #define FILE "subsetcmp.h5" #define DATASETNAME "Compressed Dataset" #define RANK 2 #define DIM0_SUB 3 /* subset dimensions */ #define DIM1_SUB 4 #define DIM0 8 /* size of dataset */ #define DIM1 10 int main (void) { hsize_t dims[2], dimsm[2]; int data[DIM0][DIM1]; /* data to write */ int sdata[DIM0_SUB][DIM1_SUB]; /* subset to write */ int rdata[DIM0][DIM1]; /* buffer for read */ hid_t file_id, dataset_id; /* handles */ hid_t dataspace_id, memspace_id; herr_t status; hsize_t count[2]; /* size of subset in the file */ hsize_t offset[2]; /* subset offset in the file */ hsize_t stride[2]; hsize_t block[2]; int i, j; hsize_t cdims[2]; hid_t plist_id; /***************************************************************** * Create a new file with default creation and access properties.* * Then create a dataset and write data to it and close the file * * and dataset. * *****************************************************************/ file_id = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); dims[0] = DIM0; dims[1] = DIM1; dataspace_id = H5Screate_simple (RANK, dims, NULL); plist_id = H5Pcreate (H5P_DATASET_CREATE); /* Dataset must be chunked for compression */ cdims[0] = 4; cdims[1] = 5; status = H5Pset_chunk (plist_id, 2, cdims); /* Set ZLIB / DEFLATE Compression using compression level 6. * * To use SZIP Compression comment out these lines. * */ status = H5Pset_deflate (plist_id, 2); dataset_id = H5Dcreate2 (file_id, DATASETNAME, H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, plist_id, H5P_DEFAULT); for (j = 0; j < DIM0; j++) { for (i = 0; i < DIM1; i++) if (i< (DIM1/2)) data[j][i] = 1; else data[j][i] = 2; } status = H5Dwrite (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data); printf ("\nData Written to File:\n"); for (i = 0; i