Skip to content

Commit 9bf78a0

Browse files
committed
test: print cast details
1 parent 44e95c7 commit 9bf78a0

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

test/test_cast.f90

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
program test_cast
22
!! test HDF5 built-in casting
33

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
76
use, intrinsic :: iso_fortran_env, only : real32, real64, int32, int64, stderr=>error_unit
87

98
implicit none
@@ -38,7 +37,8 @@ subroutine test_cast_write(fn)
3837
call h%write('/1d_real32', [1._real32, 32._real32])
3938
call h%write('/1d_int32', [2_int32, 4_int32])
4039
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))
4242

4343
call h%close()
4444

@@ -59,12 +59,27 @@ subroutine test_cast_read(fn)
5959
call h%open(fn, action='r')
6060

6161
!> %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+
6273
if (h%class("/scalar_int32") /= H5T_INTEGER_F) error stop "int32 not integer"
6374
if (h%class("/scalar_int64") /= H5T_INTEGER_F) error stop "int64 not integer"
6475
if (h%class("/1d_real32") /= H5T_FLOAT_F) error stop "1d_real32 not float"
6576
if (h%class("/scalar_real32") /= H5T_FLOAT_F) error stop "real32 not float"
6677
if (h%class("/scalar_real64") /= H5T_FLOAT_F) error stop "real64 not float"
6778
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
6883
if (h%class('/cast/r64tor32') /= H5T_FLOAT_F) then
6984
write(stderr,*) "expected cast r64tor32 ", H5T_FLOAT_F, " but got ", h%class('/cast/r64tor32')
7085
error stop "cast not float"
@@ -78,6 +93,7 @@ subroutine test_cast_read(fn)
7893
if (h%dtype("/scalar_real32") /= H5T_NATIVE_REAL) error stop "real32 type"
7994
if (h%dtype("/scalar_real64") /= H5T_NATIVE_DOUBLE) error stop "real64 type"
8095
if (h%dtype("/char") /= H5T_NATIVE_CHARACTER) error stop "char type"
96+
if (h%dtype('/cast/i64toi32') /= H5T_NATIVE_INTEGER) error stop "cast type"
8197
if (h%dtype('/cast/r64tor32') /= H5T_NATIVE_REAL) error stop "cast type"
8298
print *, "OK: dtype method"
8399

0 commit comments

Comments
 (0)