/** @page IntroHDF5 Introduction to HDF5 Navigate back: \ref index "Main" / \ref GettingStarted
\image html fileobj.png |
\image html group.png |
\image html dataset.png |
\image html datatype.png |
\image html cmpnddtype.png |
\image html dataspace1.png |
\image html dataspace.png |
\image html properties.png |
"import h5py / import numpy"
"#include hdf5.h"
"USE HDF5"
and call h5open_f and h5close_f to initialize and close the HDF5 FORTRAN interface
"import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;"
\image html crtf-pic.png |
Python \code import h5py file = h5py.File (‘file.h5’, ‘w’) file.close () \endcode |
C \code #include “hdf5.h” int main() { hid_t file_id; herr_t status; file_id = H5Fcreate ("file.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); status = H5Fclose (file_id); } \endcode |
\image html crtdset.png |
Python \code dataset = file.create_dataset("dset",(4, 6), h5py.h5t.STD_I32BE) \endcode |
C \code // Create the dataspace for the dataset. dims[0] = 4; dims[1] = 6; dataspace_id = H5Screate_simple(2, dims, NULL); // Create the dataset. dataset_id = H5Dcreate (file_id, "/dset", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); // Close the dataset and dataspace status = H5Dclose(dataset_id); status = H5Sclose(dataspace_id); \endcode |
Python \code data = np.zeros((4,6)) for i in range(4): for j in range(6): data[i][j]= i*6+j+1 dataset[...] = data <-- Write data to dataset data_read = dataset[...] <-- Read data from dataset \endcode |
C \code status = H5Dwrite (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); status = H5Dread (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); \endcode |
\image html crtgrp.png |
Python \code import h5py file = h5py.File('dset.h5', 'r+') group = file.create_group ('MyGroup') file.close() \endcode |
C \code group_id = H5Gcreate (file_id, "MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); status = H5Gclose (group_id); \endcode |
\image html crtatt.png |
Python \code dataset.attrs["Units"] = “Meters per second” <-- Create string attr_data = np.zeros((2,)) attr_data[0] = 100 attr_data[1] = 200 dataset.attrs.create("Speed", attr_data, (2,), “i”) <-- Create Integer \endcode |
C \code hid_t attribute_id, dataspace_id; // identifiers hsize_t dims; int attr_data[2]; herr_t status; ... // Initialize the attribute data. attr_data[0] = 100; attr_data[1] = 200; // Create the data space for the attribute. dims = 2; dataspace_id = H5Screate_simple(1, &dims, NULL); // Create a dataset attribute. attribute_id = H5Acreate2 (dataset_id, "Units", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT); // Write the attribute data. status = H5Awrite(attribute_id, H5T_NATIVE_INT, attr_data); // Close the attribute. status = H5Aclose(attribute_id); // Close the dataspace. status = H5Sclose(dataspace_id); \endcode |