@@ -50,23 +50,15 @@ module subroutine get_hdf5_dataset_real32_1d(filename, object_name, values)
5050
5151 character (* ), intent (in ) :: filename
5252 character (* ), intent (in ) :: object_name
53- real (real32), allocatable , intent (in out ) :: values(:)
53+ real (real32), allocatable , intent (out ) :: values(:)
5454
5555 type (hdf5_file) :: f
5656 integer (int64), allocatable :: dims(:)
5757
5858 call f % open (filename, ' r' )
5959 call f % shape (object_name, dims)
6060
61- ! If values is already allocated, re-allocate only if incorrect shape
62- if (allocated (values)) then
63- if (.not. all (shape (values) == dims)) then
64- deallocate (values)
65- allocate (values(dims(1 )))
66- end if
67- else
68- allocate (values(dims(1 )))
69- end if
61+ allocate (values(dims(1 )))
7062
7163 call f % read (object_name, values)
7264 call f % close ()
@@ -78,27 +70,42 @@ module subroutine get_hdf5_dataset_real32_2d(filename, object_name, values)
7870
7971 character (* ), intent (in ) :: filename
8072 character (* ), intent (in ) :: object_name
81- real (real32), allocatable , intent (in out ) :: values(:,:)
73+ real (real32), allocatable , intent (out ) :: values(:,:)
8274
8375 type (hdf5_file) :: f
8476 integer (int64), allocatable :: dims(:)
8577
8678 call f % open (filename, ' r' )
8779 call f % shape (object_name, dims)
8880
89- ! If values is already allocated, re-allocate only if incorrect shape
90- if (allocated (values)) then
91- if (.not. all (shape (values) == dims)) then
92- deallocate (values)
93- allocate (values(dims(1 ), dims(2 )))
94- end if
95- else
96- allocate (values(dims(1 ), dims(2 )))
97- end if
81+ allocate (values(dims(1 ), dims(2 )))
9882
9983 call f % read (object_name, values)
10084 call f % close ()
10185
86+ ! Transpose the array to respect Keras's storage order
87+ values = transpose (values)
88+
10289 end subroutine get_hdf5_dataset_real32_2d
10390
91+
92+ module subroutine get_hdf5_dataset_real32_4d (filename , object_name , values )
93+
94+ character (* ), intent (in ) :: filename
95+ character (* ), intent (in ) :: object_name
96+ real (real32), allocatable , intent (out ) :: values(:,:,:,:)
97+
98+ type (hdf5_file) :: f
99+ integer (int64), allocatable :: dims(:)
100+
101+ call f % open (filename, ' r' )
102+ call f % shape (object_name, dims)
103+
104+ allocate (values(dims(1 ), dims(2 ), dims(3 ), dims(4 )))
105+
106+ call f % read (object_name, values)
107+ call f % close ()
108+
109+ end subroutine get_hdf5_dataset_real32_4d
110+
104111end submodule nf_io_hdf5_submodule
0 commit comments