1
1
program test_cast
2
2
! ! test HDF5 built-in casting
3
3
4
- use h5fortran, only : hdf5_file, &
5
- H5T_INTEGER_F, H5T_FLOAT_F, H5T_STRING_F, &
6
- H5T_NATIVE_REAL, H5T_NATIVE_DOUBLE, H5T_NATIVE_INTEGER, H5T_NATIVE_CHARACTER, H5T_STD_I64LE
4
+ use h5fortran, only : hdf5_file
5
+ use hdf5
7
6
use , intrinsic :: iso_fortran_env, only : real32, real64, int32, int64, stderr= >error_unit
8
7
9
8
implicit none
@@ -38,7 +37,8 @@ subroutine test_cast_write(fn)
38
37
call h% write (' /1d_real32' , [1._real32 , 32._real32 ])
39
38
call h% write (' /1d_int32' , [2_int32 , 4_int32 ])
40
39
call h% write (' /char' , " hello" )
41
- call h% write (' /cast/r64tor32' , real (darr))
40
+ call h% write (' /cast/r64tor32' , real (darr, real32))
41
+ call h% write (' /cast/i64toi32' , int (42_int64 , int32))
42
42
43
43
call h% close ()
44
44
@@ -59,12 +59,27 @@ subroutine test_cast_read(fn)
59
59
call h% open (fn, action= ' r' )
60
60
61
61
! > %class method
62
+ print ' (a)' , ' HDF5 H5T class and dtype values:'
63
+ print ' (a, i0)' , ' H5T_INTEGER_F = ' , H5T_INTEGER_F
64
+ print ' (a, i0)' , ' H5T_FLOAT_F = ' , H5T_FLOAT_F
65
+ print ' (a, i0)' , ' H5T_STRING_F = ' , H5T_STRING_F
66
+ print ' (a, i0)' , ' H5T_NATIVE_REAL = ' , H5T_NATIVE_REAL
67
+ print ' (a, i0)' , ' H5T_NATIVE_DOUBLE = ' , H5T_NATIVE_DOUBLE
68
+ print ' (a, i0)' , ' H5T_NATIVE_INTEGER = ' , H5T_NATIVE_INTEGER
69
+ print ' (a, i0)' , ' H5T_NATIVE_CHARACTER = ' , H5T_NATIVE_CHARACTER
70
+ print ' (a, i0)' , ' H5T_STD_I64LE = ' , H5T_STD_I64LE
71
+
72
+
62
73
if (h% class(" /scalar_int32" ) /= H5T_INTEGER_F) error stop " int32 not integer"
63
74
if (h% class(" /scalar_int64" ) /= H5T_INTEGER_F) error stop " int64 not integer"
64
75
if (h% class(" /1d_real32" ) /= H5T_FLOAT_F) error stop " 1d_real32 not float"
65
76
if (h% class(" /scalar_real32" ) /= H5T_FLOAT_F) error stop " real32 not float"
66
77
if (h% class(" /scalar_real64" ) /= H5T_FLOAT_F) error stop " real64 not float"
67
78
if (h% class(" /char" ) /= H5T_STRING_F) error stop " char not string"
79
+ if (h% class(" /cast/i64toi32" ) /= H5T_INTEGER_F) then
80
+ write (stderr,* ) " expected cast i64toi32 " , H5T_INTEGER_F, " but got " , h% class(' /cast/i64toi32' )
81
+ error stop " cast not integer"
82
+ endif
68
83
if (h% class(' /cast/r64tor32' ) /= H5T_FLOAT_F) then
69
84
write (stderr,* ) " expected cast r64tor32 " , H5T_FLOAT_F, " but got " , h% class(' /cast/r64tor32' )
70
85
error stop " cast not float"
@@ -78,6 +93,7 @@ subroutine test_cast_read(fn)
78
93
if (h% dtype(" /scalar_real32" ) /= H5T_NATIVE_REAL) error stop " real32 type"
79
94
if (h% dtype(" /scalar_real64" ) /= H5T_NATIVE_DOUBLE) error stop " real64 type"
80
95
if (h% dtype(" /char" ) /= H5T_NATIVE_CHARACTER) error stop " char type"
96
+ if (h% dtype(' /cast/i64toi32' ) /= H5T_NATIVE_INTEGER) error stop " cast type"
81
97
if (h% dtype(' /cast/r64tor32' ) /= H5T_NATIVE_REAL) error stop " cast type"
82
98
print * , " OK: dtype method"
83
99
0 commit comments