HDF5 utilities
my own Fortran high level interface for HDF5
Data Types | Functions/Subroutines | Variables
hdf5_utils_mpi Module Reference

A set of high level wrapper subroutines for HDF5. More...

Data Types

interface  hdf_get_dims
 
interface  hdf_get_mpi_int
 Get the appropriate mpi integer type. More...
 
interface  hdf_read_attribute
 Generic interface to read attribute. More...
 
interface  hdf_read_dataset
 Generic interface to read a dataset of doubles. More...
 
interface  hdf_read_vector_from_dataset
 Generic interface to read a vector from a dataset. More...
 
interface  hdf_set_even_offset
 
interface  hdf_write_attribute
 Generic interface to write attribute. More...
 
interface  hdf_write_dataset
 Generic interface to write a dataset Supported types. More...
 
interface  hdf_write_vector_to_dataset
 Generic interface to write a vector to dataset. More...
 

Functions/Subroutines

subroutine, public hdf_set_print_messages (val_print_messages)
 Sets the value of hdf_print_messages. More...
 
subroutine, public hdf_set_default_filter (filter, gzip_level, szip_pixels_per_block, szip_options)
 Sets the value of hdf_print_messages. More...
 
subroutine, public hdf_exists (loc_id, obj_name, exists)
 Check if location exists. More...
 
subroutine, public hdf_open_file (file_id, filename, STATUS, ACTION)
 Opens file and return identifier. More...
 
subroutine, public hdf_close_file (file_id)
 Closes a hdf5 file. More...
 
subroutine hdf_preset_file_attribute (file_id)
 Preset some file-level attributes. More...
 
subroutine, private hdf_preset_prop ()
 Preset some properties.
 
subroutine, private hdf_close_prop ()
 Preset some properties.
 
subroutine, public hdf_create_group (loc_id, group_name)
 Create a new group. More...
 
subroutine, public hdf_open_group (loc_id, group_name, group_id)
 Opens a group and returns the identifier. More...
 
subroutine, public hdf_close_group (group_id)
 Close a group by identifier. More...
 
subroutine hdf_set_even_offset_from_dataset (file_id, loc_id, dset_name, offset, new_size)
 Set even offset for read_dataset. More...
 
subroutine, public hdf_get_rank (loc_id, dset_name, rank)
 Get the rank of a dataset. More...
 
subroutine hdf_get_dims_4 (loc_id, dset_name, dims)
 get the dimensions of a dataset More...
 
subroutine hdf_get_dims_8 (loc_id, dset_name, dims)
 get the dimensions of a dataset More...
 
subroutine, public hdf_set_dims (loc_id, dset_name, dims)
 set the dimensions of a dataset
 
subroutine, public hdf_create_dataset (loc_id, dset_name, dset_dims, dset_type)
 create a dataset 'dset_name' with shape 'dset_dims' of type 'dset_type' More...
 

Variables

integer(hid_t) file_plist_id
 parallel file access property
 
integer(hid_t) dplist_independent
 dataset access property
 

Detailed Description

A set of high level wrapper subroutines for HDF5.

Features:
  • opening and closing files
  • creating/opening/closing groups
  • get rank and dimensions of dataset
  • reading and writing dataset (integer, real, double)
    • uses a generic interface to switch on rank and kind
  • writing/reading attributes (integer, real, double, string)
    • uses a generic interface to switch on rank and kind
Todo:
  • reading and writing ( strings )
  • hdf_exists (h5o_exist_by_name or h5l_exists)
  • hdf_get_*
    • hdf_get_obj_name (h5iget_name_f)
    • hdf_get_obj_type (h5iget_type_f)
    • hdf_get_dset_type (H5Dget_type)
    • hdf_get_obj_id (not needed)
  • error checking,
    • check dims when reading
    • check dataset/attribute name when reading
    • check group name when reading/writing
    • stop on error vs return error flag vs global error flag
Note
I might use H5T_STD_I32LE, H5T_IEEE_F32LE, H5T_IEEE_F64LE instead of H5T_NATIVE_DOUBLE when creating a dataset. This would make the hdf5 file more portable?
should I support other integer types (ie 16 and 64)? I am not sure if hdf5 fortran supports these

Function/Subroutine Documentation

◆ hdf_set_print_messages()

subroutine, public hdf5_utils_mpi::hdf_set_print_messages ( logical, intent(in)  val_print_messages)

Sets the value of hdf_print_messages.

By default, hdf_print_messages = .false. By setting it to .true., some messages are printed detailing what hdf_utils is doing.

Parameters
[in]val_print_messagesnew value for hdf_print_messages

◆ hdf_set_default_filter()

subroutine, public hdf5_utils_mpi::hdf_set_default_filter ( character(len=*), intent(in)  filter,
integer, intent(in), optional  gzip_level,
integer, intent(in), optional  szip_pixels_per_block,
character(len=2), intent(in), optional  szip_options 
)

Sets the value of hdf_print_messages.

Parameters
[in]filternew value for hdf_print_messages

◆ hdf_exists()

subroutine, public hdf5_utils_mpi::hdf_exists ( integer(hid_t), intent(in)  loc_id,
character(len=*), intent(in)  obj_name,
logical, intent(out)  exists 
)

Check if location exists.

Also checks is intemediate paths exists in a safe way.

Parameters
[in]loc_idlocal id
[in]obj_namerelative path to object
[out]exists.TRUE. if everything exists, .FALSE. otherwise

◆ hdf_open_file()

subroutine, public hdf5_utils_mpi::hdf_open_file ( integer(hid_t), intent(out)  file_id,
character(len=*), intent(in)  filename,
character(len=*), intent(in), optional  STATUS,
character(len=*), intent(in), optional  ACTION 
)

Opens file and return identifier.

Todo:
  • case insentive STATUS and ACTION
  • delete file for REPLACE case
STATUS ACTION Description
NEW na calls h5fcreate with H5F_ACC_TRUNC_F
REPLACE na calls h5fcreate with H5F_ACC_EXCL_F
OLD READ calls h5fopen with H5F_ACC_RDONLY_F
OLD WRITE calls h5fopen with H5F_ACC_RDWR_F
OLD READWRITE calls h5fopen with H5F_ACC_RDWR_F
Parameters
[out]file_idHDF5 id of the file
[in]filenamethe HDF5 filename
[in]statusfile status (OLD, NEW, REPLACE)
[in]actionfile action (READ, WRITE, READWRITE)

◆ hdf_close_file()

subroutine, public hdf5_utils_mpi::hdf_close_file ( integer(hid_t), intent(in)  file_id)

Closes a hdf5 file.

Parameters
[in]file_idfile id to be closed

◆ hdf_preset_file_attribute()

subroutine hdf5_utils_mpi::hdf_preset_file_attribute ( integer(hid_t), intent(in)  file_id)
private

Preset some file-level attributes.

Parameters
[in]file_idHDF5 id of the file

◆ hdf_create_group()

subroutine, public hdf5_utils_mpi::hdf_create_group ( integer(hid_t), intent(in)  loc_id,
character(len=*), intent(in)  group_name 
)

Create a new group.

Parameters
[in]loc_idlocation id where to put the group
[in]group_namename of the group

◆ hdf_open_group()

subroutine, public hdf5_utils_mpi::hdf_open_group ( integer(hid_t), intent(in)  loc_id,
character(len=*), intent(in)  group_name,
integer(hid_t), intent(out)  group_id 
)

Opens a group and returns the identifier.

Parameters
[in]loc_idlocation id where to put the group
[in]group_namename of the group
[out]group_idid for the group

◆ hdf_close_group()

subroutine, public hdf5_utils_mpi::hdf_close_group ( integer(hid_t), intent(in)  group_id)

Close a group by identifier.

Parameters
[in]group_idid for the group

◆ hdf_set_even_offset_from_dataset()

subroutine hdf5_utils_mpi::hdf_set_even_offset_from_dataset ( integer(hid_t), intent(in)  file_id,
integer(hid_t), intent(in)  loc_id,
character(len=*), intent(in)  dset_name,
integer, dimension(:), intent(inout)  offset,
integer, intent(in), optional  new_size 
)
private

Set even offset for read_dataset.

Parameters
[in]file_idfile id created with hdf_open_file
[in]loc_idlocation id created with hdf_open_group or file_id
[in]dset_namedataset name
[in,out]offsetnew offset to read the dataset appropriately
[in]new_size(optional) new size of data on this processor, used only for consistency check

◆ hdf_get_rank()

subroutine, public hdf5_utils_mpi::hdf_get_rank ( integer(hid_t), intent(in)  loc_id,
character(len=*), intent(in)  dset_name,
integer, intent(out)  rank 
)

Get the rank of a dataset.

Parameters
[in]loc_idlocation id
[in]dset_namedataset name
[out]rankrank of the dataset

◆ hdf_get_dims_4()

subroutine hdf5_utils_mpi::hdf_get_dims_4 ( integer(hid_t), intent(in)  loc_id,
character(len=*), intent(in)  dset_name,
integer, dimension(:), intent(out)  dims 
)
private

get the dimensions of a dataset

Parameters
[in]loc_idlocation id
[in]dset_namename of dataset
[out]dimsdimensions of the dataset

◆ hdf_get_dims_8()

subroutine hdf5_utils_mpi::hdf_get_dims_8 ( integer(hid_t), intent(in)  loc_id,
character(len=*), intent(in)  dset_name,
integer(hsize_t), dimension(:), intent(out)  dims 
)
private

get the dimensions of a dataset

Parameters
[in]loc_idlocation id
[in]dset_namename of dataset
[out]dimsdimensions of the dataset

◆ hdf_create_dataset()

subroutine, public hdf5_utils_mpi::hdf_create_dataset ( integer(hid_t), intent(in)  loc_id,
character(len=*), intent(in)  dset_name,
integer, dimension(:), intent(in)  dset_dims,
character(len=*), intent(in)  dset_type 
)

create a dataset 'dset_name' with shape 'dset_dims' of type 'dset_type'

Parameters
[in]loc_idlocal id in file
[in]dset_namename of dataset
[in]dset_dimsdimensions of the dataset
[in]dset_typetype of dataset (integer or double)