@@ -50,23 +50,15 @@ module subroutine get_hdf5_dataset_real32_1d(filename, object_name, values)
50
50
51
51
character (* ), intent (in ) :: filename
52
52
character (* ), intent (in ) :: object_name
53
- real (real32), allocatable , intent (in out ) :: values(:)
53
+ real (real32), allocatable , intent (out ) :: values(:)
54
54
55
55
type (hdf5_file) :: f
56
56
integer (int64), allocatable :: dims(:)
57
57
58
58
call f % open (filename, ' r' )
59
59
call f % shape (object_name, dims)
60
60
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 )))
70
62
71
63
call f % read (object_name, values)
72
64
call f % close ()
@@ -78,27 +70,42 @@ module subroutine get_hdf5_dataset_real32_2d(filename, object_name, values)
78
70
79
71
character (* ), intent (in ) :: filename
80
72
character (* ), intent (in ) :: object_name
81
- real (real32), allocatable , intent (in out ) :: values(:,:)
73
+ real (real32), allocatable , intent (out ) :: values(:,:)
82
74
83
75
type (hdf5_file) :: f
84
76
integer (int64), allocatable :: dims(:)
85
77
86
78
call f % open (filename, ' r' )
87
79
call f % shape (object_name, dims)
88
80
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 )))
98
82
99
83
call f % read (object_name, values)
100
84
call f % close ()
101
85
86
+ ! Transpose the array to respect Keras's storage order
87
+ values = transpose (values)
88
+
102
89
end subroutine get_hdf5_dataset_real32_2d
103
90
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
+
104
111
end submodule nf_io_hdf5_submodule
0 commit comments