Skip to content

Commit

Permalink
7d
Browse files Browse the repository at this point in the history
7d

7d

test shapes
  • Loading branch information
scivision committed Dec 26, 2018
1 parent b06118b commit 50e3cf7
Show file tree
Hide file tree
Showing 9 changed files with 343 additions and 33 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ add_executable(testh5 src/test_hdf5_ifc.f90)
target_link_libraries(testh5 PRIVATE hdf5oo)
target_compile_options(testh5 PRIVATE -Wno-compare-reals)
add_test(NAME h5oo COMMAND testh5)
set_tests_properties(h5oo PROPERTIES FIXTURES_SETUP h5files)

add_executable(shaper src/GetShape.f90)
target_link_libraries(shaper PRIVATE hdf5oo)
add_executable(shapes_check src/GetShape.f90)
target_link_libraries(shapes_check PRIVATE hdf5oo)
add_test(NAME ShapeCheck COMMAND shapes_check p5.h5 group69/flux_node)
set_tests_properties(ShapeCheck PROPERTIES FIXTURES_REQUIRED h5files)
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ Straightforward single-file/module access to HDF5.
Uses Fortran 2008 `submodule` for clean, templatable structure.
This thin object-oriented modern Fortran library abstracts away the messy parts of HDF5 so that you can read/write various types/ranks of data with a single command.

Polymorphic API with read/write integer / real32/64:
Polymorphic API with read/write for types integer, real32, real64 with rank:

* scalar
* 1-D .. 6-D
* scalar (0-D)
* 1-D .. 7-D

as well as character (string) variables and attributes.
If you'd like higher-rank arrays, let us know via GitHub Issue.

Tested on systems including

Expand Down
111 changes: 99 additions & 12 deletions src/hdf5_interface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,35 @@ module hdf5_interface

!> add group or dataset integer/real
generic, public :: add => &
hdf_add_group, hdf_add_int, hdf_add_int_1d, hdf_add_int_2d, hdf_add_int_3d, &
hdf_add_real32, hdf_add_real32_1d, hdf_add_real32_2d, hdf_add_real32_3d, hdf_add_real32_4d, hdf_add_real32_5d, hdf_add_real32_6d, &
hdf_add_real64, hdf_add_real64_1d, hdf_add_real64_2d, hdf_add_real64_3d, hdf_add_real64_4d, hdf_add_real64_5d, hdf_add_real64_6d, &
hdf_add_group, hdf_add_int, hdf_add_int_1d, hdf_add_int_2d, hdf_add_int_3d, hdf_add_int_5d, hdf_add_int_6d, hdf_add_int_7d,&
hdf_add_real32, hdf_add_real32_1d, hdf_add_real32_2d, hdf_add_real32_3d, &
hdf_add_real32_4d, hdf_add_real32_5d, hdf_add_real32_6d, hdf_add_real32_7d, &
hdf_add_real64, hdf_add_real64_1d, hdf_add_real64_2d, hdf_add_real64_3d, &
hdf_add_real64_4d, hdf_add_real64_5d, hdf_add_real64_6d, hdf_add_real64_7d, &
hdf_add_string

!> get dataset integer/real
generic, public :: get => &
hdf_get_int, hdf_get_int_1d, hdf_get_int_2d, hdf_get_int_3d,&
hdf_get_real32, hdf_get_real32_1d, hdf_get_real32_2d, hdf_get_real32_3d, hdf_get_real32_4d, hdf_get_real32_5d, hdf_get_real32_6d, &
hdf_get_real64, hdf_get_real64_1d, hdf_get_real64_2d, hdf_get_real64_3d, hdf_get_real64_4d, hdf_get_real64_5d, hdf_get_real64_6d, &
hdf_get_int, hdf_get_int_1d, hdf_get_int_2d, hdf_get_int_3d, hdf_get_int_4d,hdf_get_int_5d, hdf_get_int_6d, hdf_get_int_7d,&
hdf_get_real32, hdf_get_real32_1d, hdf_get_real32_2d, hdf_get_real32_3d, &
hdf_get_real32_4d, hdf_get_real32_5d, hdf_get_real32_6d, hdf_get_real32_7d, &
hdf_get_real64, hdf_get_real64_1d, hdf_get_real64_2d, hdf_get_real64_3d, &
hdf_get_real64_4d, hdf_get_real64_5d, hdf_get_real64_6d, hdf_get_real64_7d, &
hdf_get_string


!> private methods
procedure,private :: hdf_add_group, &
hdf_add_int, hdf_add_int_1d, hdf_add_int_2d, hdf_add_int_3d, &
hdf_get_int, hdf_get_int_1d, hdf_get_int_2d, hdf_get_int_3d, &
hdf_add_real32, hdf_add_real32_1d, hdf_add_real32_2d, hdf_add_real32_3d, hdf_add_real32_4d, hdf_add_real32_5d, hdf_add_real32_6d, &
hdf_add_real64, hdf_add_real64_1d, hdf_add_real64_2d, hdf_add_real64_3d, hdf_add_real64_4d, hdf_add_real64_5d, hdf_add_real64_6d, &
hdf_get_real32, hdf_get_real32_1d, hdf_get_real32_2d, hdf_get_real32_3d, hdf_get_real32_4d, hdf_get_real32_5d, hdf_get_real32_6d, &
hdf_get_real64, hdf_get_real64_1d, hdf_get_real64_2d, hdf_get_real64_3d, hdf_get_real64_4d, hdf_get_real64_5d, hdf_get_real64_6d, &
hdf_add_int, hdf_add_int_1d, hdf_add_int_2d, hdf_add_int_3d, hdf_add_int_4d, hdf_add_int_5d, hdf_add_int_6d, hdf_add_int_7d, &
hdf_get_int, hdf_get_int_1d, hdf_get_int_2d, hdf_get_int_3d, hdf_get_int_4d, hdf_get_int_5d, hdf_get_int_6d, hdf_get_int_7d, &
hdf_add_real32, hdf_add_real32_1d, hdf_add_real32_2d, hdf_add_real32_3d, &
hdf_add_real32_4d, hdf_add_real32_5d, hdf_add_real32_6d, hdf_add_real32_7d, &
hdf_add_real64, hdf_add_real64_1d, hdf_add_real64_2d, hdf_add_real64_3d, &
hdf_add_real64_4d, hdf_add_real64_5d, hdf_add_real64_6d, hdf_add_real64_7d, &
hdf_get_real32, hdf_get_real32_1d, hdf_get_real32_2d, hdf_get_real32_3d, &
hdf_get_real32_4d, hdf_get_real32_5d, hdf_get_real32_6d, hdf_get_real32_7d, &
hdf_get_real64, hdf_get_real64_1d, hdf_get_real64_2d, hdf_get_real64_3d, &
hdf_get_real64_4d, hdf_get_real64_5d, hdf_get_real64_6d, hdf_get_real64_7d, &
hdf_add_string, hdf_get_string

end type hdf5_file
Expand Down Expand Up @@ -104,6 +112,34 @@ module subroutine hdf_add_int_3d(self,dname,value, chunk_size)
integer, intent(in), optional :: chunk_size(:)
end subroutine hdf_add_int_3d

module subroutine hdf_add_int_4d(self,dname,value, chunk_size)
class(hdf5_file), intent(inout) :: self
character(*), intent(in) :: dname
integer, intent(in) :: value(:,:,:,:)
integer, intent(in), optional :: chunk_size(:)
end subroutine hdf_add_int_4d

module subroutine hdf_add_int_5d(self,dname,value, chunk_size)
class(hdf5_file), intent(inout) :: self
character(*), intent(in) :: dname
integer, intent(in) :: value(:,:,:,:,:)
integer, intent(in), optional :: chunk_size(:)
end subroutine hdf_add_int_5d

module subroutine hdf_add_int_6d(self,dname,value, chunk_size)
class(hdf5_file), intent(inout) :: self
character(*), intent(in) :: dname
integer, intent(in) :: value(:,:,:,:,:,:)
integer, intent(in), optional :: chunk_size(:)
end subroutine hdf_add_int_6d

module subroutine hdf_add_int_7d(self,dname,value, chunk_size)
class(hdf5_file), intent(inout) :: self
character(*), intent(in) :: dname
integer, intent(in) :: value(:,:,:,:,:,:,:)
integer, intent(in), optional :: chunk_size(:)
end subroutine hdf_add_int_7d

module subroutine hdf_add_real64(self,dname,value)
class(hdf5_file), intent(in) :: self
character(*), intent(in) :: dname
Expand Down Expand Up @@ -151,6 +187,13 @@ module subroutine hdf_add_real64_6d(self,dname,value, chunk_size)
integer, intent(in), optional :: chunk_size(:)
end subroutine hdf_add_real64_6d

module subroutine hdf_add_real64_7d(self,dname,value, chunk_size)
class(hdf5_file), intent(inout) :: self
character(*), intent(in) :: dname
real(real64), intent(in) :: value(:,:,:,:,:,:,:)
integer, intent(in), optional :: chunk_size(:)
end subroutine hdf_add_real64_7d

module subroutine hdf_add_real32(self,dname,value)
class(hdf5_file), intent(in) :: self
character(*), intent(in) :: dname
Expand Down Expand Up @@ -198,6 +241,13 @@ module subroutine hdf_add_real32_6d(self,dname,value, chunk_size)
integer, intent(in), optional :: chunk_size(:)
end subroutine hdf_add_real32_6d

module subroutine hdf_add_real32_7d(self,dname,value, chunk_size)
class(hdf5_file), intent(inout) :: self
character(*), intent(in) :: dname
real(real32), intent(in) :: value(:,:,:,:,:,:,:)
integer, intent(in), optional :: chunk_size(:)
end subroutine hdf_add_real32_7d

module subroutine hdf_get_shape(self, dname, dims)
class(hdf5_file), intent(in) :: self
character(*), intent(in) :: dname
Expand Down Expand Up @@ -234,6 +284,31 @@ module subroutine hdf_get_int_3d(self, dname, value)
integer, intent(out),allocatable :: value(:,:,:)
end subroutine hdf_get_int_3d

module subroutine hdf_get_int_4d(self, dname, value)
class(hdf5_file), intent(in) :: self
character(*), intent(in) :: dname
integer, intent(out),allocatable :: value(:,:,:,:)
end subroutine hdf_get_int_4d

module subroutine hdf_get_int_5d(self, dname, value)
class(hdf5_file), intent(in) :: self
character(*), intent(in) :: dname
integer, intent(out),allocatable :: value(:,:,:,:,:)
end subroutine hdf_get_int_5d

module subroutine hdf_get_int_6d(self, dname, value)
class(hdf5_file), intent(in) :: self
character(*), intent(in) :: dname
integer, intent(out),allocatable :: value(:,:,:,:,:,:)
end subroutine hdf_get_int_6d

module subroutine hdf_get_int_7d(self, dname, value)
class(hdf5_file), intent(in) :: self
character(*), intent(in) :: dname
integer, intent(out),allocatable :: value(:,:,:,:,:,:,:)
end subroutine hdf_get_int_7d


module subroutine hdf_get_real32(self, dname, value)
class(hdf5_file), intent(in) :: self
character(*), intent(in) :: dname
Expand Down Expand Up @@ -276,6 +351,12 @@ module subroutine hdf_get_real32_6d(self, dname, value)
real(real32), intent(out),allocatable :: value(:,:,:,:,:,:)
end subroutine hdf_get_real32_6d

module subroutine hdf_get_real32_7d(self, dname, value)
class(hdf5_file), intent(in) :: self
character(*), intent(in) :: dname
real(real32), intent(out),allocatable :: value(:,:,:,:,:,:,:)
end subroutine hdf_get_real32_7d

module subroutine hdf_get_real64(self, dname, value)
class(hdf5_file), intent(in) :: self
character(*), intent(in) :: dname
Expand Down Expand Up @@ -318,6 +399,12 @@ module subroutine hdf_get_real64_6d(self, dname, value)
real(real64), intent(out),allocatable :: value(:,:,:,:,:,:)
end subroutine hdf_get_real64_6d

module subroutine hdf_get_real64_7d(self, dname, value)
class(hdf5_file), intent(in) :: self
character(*), intent(in) :: dname
real(real64), intent(out),allocatable :: value(:,:,:,:,:,:,:)
end subroutine hdf_get_real64_7d

module subroutine hdf_open_group(self, gname)
class(hdf5_file), intent(inout) :: self
character(*), intent(in) :: gname
Expand Down
72 changes: 70 additions & 2 deletions src/read_int.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
call h5dopen_f(self%lid, dname, dsid, ierr)
if (ierr /= 0) error stop 'error open dataset '//dname//' read '//self%filename

! read dataset
call h5dread_f(dsid, h5kind_to_type(kind(value),H5_INTEGER_KIND), value,int(shape(value),HSIZE_T), ierr)
!> read dataset
call h5dread_f(dsid, h5kind_to_type(kind(value),H5_REAL_KIND), value,int(shape(value),HSIZE_T), ierr)
if (ierr /= 0) error stop 'error read dataset '//dname//' read '//self%filename

!> close dataset
Expand Down Expand Up @@ -75,4 +75,72 @@
end procedure hdf_get_int_3d


module procedure hdf_get_int_4d

integer(HSIZE_T) :: dims(rank(value))
integer(SIZE_T) :: dsize
integer :: ierr, dtype

call h5ltget_dataset_info_f(self%lid, dname, dims, dtype, dsize, ierr)
if (ierr /= 0) error stop 'error open dataset '//dname//' read '//self%filename

allocate(value(dims(1),dims(2),dims(3),dims(4)))

call h5ltread_dataset_f(self%lid, dname, h5kind_to_type(kind(value),H5_INTEGER_KIND), value, dims, ierr)
if (ierr /= 0) error stop 'error read dataset '//dname//' read '//self%filename

end procedure hdf_get_int_4d


module procedure hdf_get_int_5d

integer(HSIZE_T) :: dims(rank(value))
integer(SIZE_T) :: dsize
integer :: ierr, dtype

call h5ltget_dataset_info_f(self%lid, dname, dims, dtype, dsize, ierr)
if (ierr /= 0) error stop 'error open dataset '//dname//' read '//self%filename

allocate(value(dims(1),dims(2),dims(3),dims(4),dims(5)))

call h5ltread_dataset_f(self%lid, dname, h5kind_to_type(kind(value),H5_INTEGER_KIND), value, dims, ierr)
if (ierr /= 0) error stop 'error read dataset '//dname//' read '//self%filename

end procedure hdf_get_int_5d


module procedure hdf_get_int_6d

integer(HSIZE_T) :: dims(rank(value))
integer(SIZE_T) :: dsize
integer :: ierr, dtype

call h5ltget_dataset_info_f(self%lid, dname, dims, dtype, dsize, ierr)
if (ierr /= 0) error stop 'error open dataset '//dname//' read '//self%filename

allocate(value(dims(1),dims(2),dims(3),dims(4),dims(5),dims(6)))

call h5ltread_dataset_f(self%lid, dname, h5kind_to_type(kind(value),H5_INTEGER_KIND), value, dims, ierr)
if (ierr /= 0) error stop 'error read dataset '//dname//' read '//self%filename

end procedure hdf_get_int_6d


module procedure hdf_get_int_7d

integer(HSIZE_T) :: dims(rank(value))
integer(SIZE_T) :: dsize
integer :: ierr, dtype

call h5ltget_dataset_info_f(self%lid, dname, dims, dtype, dsize, ierr)
if (ierr /= 0) error stop 'error open dataset '//dname//' read '//self%filename

allocate(value(dims(1),dims(2),dims(3),dims(4),dims(5),dims(6),dims(7)))

call h5ltread_dataset_f(self%lid, dname, h5kind_to_type(kind(value),H5_INTEGER_KIND), value, dims, ierr)
if (ierr /= 0) error stop 'error read dataset '//dname//' read '//self%filename

end procedure hdf_get_int_7d


end submodule read_int
29 changes: 23 additions & 6 deletions src/read_real32.f90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

module procedure hdf_get_real32_1d

integer(HSIZE_T) :: dims(1)
integer(HSIZE_T) :: dims(rank(value))
integer(SIZE_T) :: dsize
integer :: ierr, dtype

Expand All @@ -43,7 +43,7 @@

module procedure hdf_get_real32_2d

integer(HSIZE_T) :: dims(2)
integer(HSIZE_T) :: dims(rank(value))
integer(SIZE_T) :: dsize
integer :: ierr, dtype

Expand All @@ -60,7 +60,7 @@

module procedure hdf_get_real32_3d

integer(HSIZE_T) :: dims(3)
integer(HSIZE_T) :: dims(rank(value))
integer(SIZE_T) :: dsize
integer :: ierr, dtype

Expand All @@ -77,7 +77,7 @@

module procedure hdf_get_real32_4d

integer(HSIZE_T) :: dims(4)
integer(HSIZE_T) :: dims(rank(value))
integer(SIZE_T) :: dsize
integer :: ierr, dtype

Expand All @@ -94,7 +94,7 @@

module procedure hdf_get_real32_5d

integer(HSIZE_T) :: dims(5)
integer(HSIZE_T) :: dims(rank(value))
integer(SIZE_T) :: dsize
integer :: ierr, dtype

Expand All @@ -111,7 +111,7 @@

module procedure hdf_get_real32_6d

integer(HSIZE_T) :: dims(6)
integer(HSIZE_T) :: dims(rank(value))
integer(SIZE_T) :: dsize
integer :: ierr, dtype

Expand All @@ -126,4 +126,21 @@
end procedure hdf_get_real32_6d


module procedure hdf_get_real32_7d

integer(HSIZE_T) :: dims(rank(value))
integer(SIZE_T) :: dsize
integer :: ierr, dtype

call h5ltget_dataset_info_f(self%lid, dname, dims, dtype, dsize, ierr)
if (ierr /= 0) error stop 'error open dataset '//dname//' read '//self%filename

allocate(value(dims(1),dims(2),dims(3),dims(4),dims(5),dims(6),dims(7)))

call h5ltread_dataset_f(self%lid, dname, h5kind_to_type(kind(value),H5_REAL_KIND), value, dims, ierr)
if (ierr /= 0) error stop 'error read dataset '//dname//' read '//self%filename

end procedure hdf_get_real32_7d


end submodule read_real32
Loading

0 comments on commit 50e3cf7

Please sign in to comment.