/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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 create a dataset that is a 4 x 6 * array. It is used in the HDF5 Tutorial. */ #include "hdf5.h" #define FILE "rafal.h5" int main() { hid_t file_id, dataset_id, dataspace_id; /* identifiers */ hsize_t dims[2]; herr_t status; /* Create a new file using default properties. */ if ((file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) printf ("H5Fcreate Failed!\n"); else printf ("H5Fcreate: OK\n"); /* Create the data space for the dataset. */ dims[0] = 0; dims[1] = 0; if ((dataspace_id = H5Screate_simple(2, dims, NULL)) < 0) printf ("H5Screate_simple fails!\n"); else printf ("H5Screate_simple: OK\n"); /* Create the dataset. */ if ((dataset_id = H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) printf ("H5Dcreate2 Failed!\n"); else printf ("H5Dcreate2: OK\n"); /* End access to the dataset and release resources used by it. */ if ((status = H5Dclose(dataset_id)) < 0) printf ("H5Dclose Failed!\n"); else printf ("H5Dclose: OK\n"); if ((status = H5Sclose(dataspace_id)) < 0) printf ("H5Sclose Failed!\n"); else printf ("H5Sclose: OK\n"); if ((status = H5Fclose(file_id)) < 0) printf ("H5Fclose Failed!\n"); else printf ("H5Fclose: OK\n"); if ((file_id = H5Fopen (FILE, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) printf ("H5Fopen Failed!\n"); else printf ("H5Fopen: OK\n"); if ((dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT)) < 0) printf ("H5Dopen2 Failed!\n"); else printf ("H5Dopen2: OK\n"); if ((dataspace_id = H5Dget_space (dataset_id)) < 0) printf ("H5Dget_space Failed!\n"); else printf ("H5Dget_space: OK\n"); if ((status = H5Dclose(dataset_id)) < 0) printf ("H5Dclose Failed!\n"); else printf ("H5Dclose: OK\n"); /* Terminate access to the data space. */ if ((status = H5Sclose(dataspace_id)) < 0) printf ("H5Sclose Failed!\n"); else printf ("H5Sclose: OK\n"); /* Close the file. */ if ((status = H5Fclose(file_id)) < 0) printf ("H5Fclose Failed!\n"); else printf ("H5Fclose: OK\n"); }