Skip to content

Commit

Permalink
Bugfix: Fix rank for scalar of float and double type (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
phmarti authored and havogt committed Dec 15, 2017
1 parent d5bd489 commit d62313f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/serialbox-fortran/m_serialize.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ SUBROUTINE fs_read_float_0d(serializer, savepoint, fieldname, field)
! This workaround is needed for gcc < 4.9
padd=>field

CALL fs_check_size(serializer, fieldname, "float", fs_floatsize(), 1, 1, 1, 1)
CALL fs_check_size(serializer, fieldname, "float", fs_floatsize(), 1, 0, 0, 0)
CALL fs_compute_strides(serializer%serializer_ptr, TRIM(fieldname)//C_NULL_CHAR, &
C_LOC(padd), C_LOC(padd), C_LOC(padd), C_LOC(padd), C_LOC(padd), &
istride, jstride, kstride, lstride)
Expand Down Expand Up @@ -2514,7 +2514,7 @@ SUBROUTINE fs_read_double_0d(serializer, savepoint, fieldname, field)
! This workaround is needed for gcc < 4.9
padd=>field

CALL fs_check_size(serializer, fieldname, "double", fs_doublesize(), 1, 1, 1, 1)
CALL fs_check_size(serializer, fieldname, "double", fs_doublesize(), 1, 0, 0, 0)
CALL fs_compute_strides(serializer%serializer_ptr, TRIM(fieldname)//C_NULL_CHAR, &
C_LOC(padd), C_LOC(padd), C_LOC(padd), C_LOC(padd), C_LOC(padd), &
istride, jstride, kstride, lstride)
Expand Down
14 changes: 14 additions & 0 deletions test/serialbox-fortran/serialbox_test.pf
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ CONTAINS
LOGICAL :: w_testfield_l1(1), r_testfield_l1(1)
INTEGER(8) :: w_testfield_long0, r_testfield_long0
INTEGER(8) :: w_testfield_long1(1), r_testfield_long1(1)
REAL(KIND=C_FLOAT) :: w_testfield_f0, r_testfield_f0
REAL(KIND=C_DOUBLE) :: w_testfield_d0, r_testfield_d0

CHARACTER(len=*), PARAMETER :: base_name = 'test_scalars'

Expand All @@ -194,6 +196,8 @@ CONTAINS
w_testfield_l1 = (/ .FALSE. /)
w_testfield_long0 = 999888777666555_8
w_testfield_long1 = (/ -1234567890123_8 /)
w_testfield_f0 = 3.14159274
w_testfield_d0 = 3.1415926535897931

CALL fs_create_serializer(dir, base_name, 'w', serializer)
CALL fs_write_field(serializer, savepoint, "testfield_i0", w_testfield_i0)
Expand All @@ -202,6 +206,8 @@ CONTAINS
CALL fs_write_field(serializer, savepoint, "testfield_l1", w_testfield_l1)
CALL fs_write_field(serializer, savepoint, "testfield_long0", w_testfield_long0)
CALL fs_write_field(serializer, savepoint, "testfield_long1", w_testfield_long1)
CALL fs_write_field(serializer, savepoint, "testfield_f0", w_testfield_f0)
CALL fs_write_field(serializer, savepoint, "testfield_d0", w_testfield_d0)
CALL fs_destroy_serializer(serializer)

CALL fs_create_serializer(dir, base_name, 'r', serializer)
Expand All @@ -212,20 +218,26 @@ CONTAINS
@assertTrue(fs_field_exists(serializer, "testfield_l1"))
@assertTrue(fs_field_exists(serializer, "testfield_long0"))
@assertTrue(fs_field_exists(serializer, "testfield_long1"))
@assertTrue(fs_field_exists(serializer, "testfield_f0"))
@assertTrue(fs_field_exists(serializer, "testfield_d0"))

@assertEqual(exp_size_scalar, fs_get_size(serializer, "testfield_i0"))
@assertEqual(exp_size(SHAPE(w_testfield_i1)), fs_get_size(serializer, "testfield_i1"))
@assertEqual(exp_size_scalar, fs_get_size(serializer, "testfield_l0"))
@assertEqual(exp_size(SHAPE(w_testfield_l1)), fs_get_size(serializer, "testfield_l1"))
@assertEqual(exp_size_scalar, fs_get_size(serializer, "testfield_long0"))
@assertEqual(exp_size(SHAPE(w_testfield_long1)), fs_get_size(serializer, "testfield_long1"))
@assertEqual(exp_size_scalar, fs_get_size(serializer, "testfield_f0"))
@assertEqual(exp_size_scalar, fs_get_size(serializer, "testfield_d0"))

CALL fs_read_field(serializer, savepoint, "testfield_i0", r_testfield_i0)
CALL fs_read_field(serializer, savepoint, "testfield_i1", r_testfield_i1)
CALL fs_read_field(serializer, savepoint, "testfield_l0", r_testfield_l0)
CALL fs_read_field(serializer, savepoint, "testfield_l1", r_testfield_l1)
CALL fs_read_field(serializer, savepoint, "testfield_long0", r_testfield_long0)
CALL fs_read_field(serializer, savepoint, "testfield_long1", r_testfield_long1)
CALL fs_read_field(serializer, savepoint, "testfield_f0", r_testfield_f0)
CALL fs_read_field(serializer, savepoint, "testfield_d0", r_testfield_d0)

CALL fs_destroy_serializer(serializer)

Expand All @@ -235,6 +247,8 @@ CONTAINS
@assertEquivalent(w_testfield_l1, r_testfield_l1)
@assertEqual(w_testfield_long0, r_testfield_long0)
@assertEqual(w_testfield_long1, r_testfield_long1)
@assertEqual(w_testfield_f0, r_testfield_f0)
@assertEqual(w_testfield_d0, r_testfield_d0)

END SUBROUTINE testScalars

Expand Down

0 comments on commit d62313f

Please sign in to comment.