11program test_io_hdf5
22
3- use iso_fortran_env, only: stderr = > error_unit
3+ use iso_fortran_env, only: int64, stderr = > error_unit
44 use nf_datasets, only: download_and_unpack, keras_model_dense_mnist_url
55 use nf_io_hdf5, only: get_hdf5_attribute_string
6+ use h5fortran, only: hdf5_file
67
78 implicit none
89
910 character (:), allocatable :: attr
1011 character (* ), parameter :: test_data_path = ' keras_dense_mnist.h5'
12+ type (hdf5_file) :: f
13+ real , allocatable :: bias(:), weights(:,:)
14+ integer (int64), allocatable :: dims(:)
15+
1116 logical :: file_exists
1217 logical :: ok = .true.
1318
@@ -19,9 +24,34 @@ program test_io_hdf5
1924 if (.not. attr == ' tensorflow' ) then
2025 ok = .false.
2126 write (stderr, ' (a)' ) &
22- ' HDF5 variable length string attribute not read correctly.. failed'
27+ ' HDF5 variable length string attribute was read correctly.. failed'
28+ end if
29+
30+ call f % open (test_data_path, ' r' )
31+
32+ call f % shape (' /model_weights/dense/dense/bias:0' , dims)
33+ allocate (bias(dims(1 )))
34+ bias = 0
35+ call f % read (' /model_weights/dense/dense/bias:0' , bias)
36+
37+ if (.not. all (dims == [30 ])) then
38+ ok = .false.
39+ write (stderr, ' (a)' ) ' HDF5 1-d dataset dims inquiry is correct.. failed'
2340 end if
2441
42+ call f % shape (' /model_weights/dense/dense/kernel:0' , dims)
43+ allocate (weights(dims(1 ), dims(2 )))
44+ weights = 0
45+ call f % read (' /model_weights/dense/dense/kernel:0' , weights)
46+
47+ if (.not. all (dims == [30 , 784 ])) then
48+ ok = .false.
49+ print * , dims
50+ write (stderr, ' (a)' ) ' HDF5 2-d dataset dims inquiry is correct.. failed'
51+ end if
52+
53+ call f % close ()
54+
2555 if (ok) then
2656 print ' (a)' , ' test_io_hdf5: All tests passed.'
2757 else
0 commit comments