Skip to content

Commit 728f45e

Browse files
committed
Adding support for real kinds with precision up to and including the one specified by the user.
See #386. Note that for a default compilation, which would now produce real32 and real64 interfaces. Added interfaces to json_value_module but not yet json_file_module. Updated the default format statements for reals to account for the specified real kind.
1 parent 5a80c57 commit 728f45e

File tree

3 files changed

+865
-37
lines changed

3 files changed

+865
-37
lines changed

src/json_kinds.F90

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
! integer(kind=int32) [4 bytes]
6060
#endif
6161
! .
62+
!
63+
!@note In addition to the real kind specified by `RK`, interfaces for
64+
! the real kinds with less precision are also provided in the library,
65+
! but all are converted to `real(RK)` variables internally.
6266

6367
module json_kinds
6468

@@ -68,6 +72,15 @@ module json_kinds
6872

6973
private
7074

75+
! used for the reals with less precision
76+
! than the default precision:
77+
#ifndef REAL32
78+
public :: real32
79+
#endif
80+
#ifdef REAL128
81+
public :: real64
82+
#endif
83+
7184
#ifdef REAL32
7285
integer,parameter,public :: RK = real32 !! Default real kind [4 bytes]
7386
#elif REAL64
@@ -92,7 +105,7 @@ module json_kinds
92105

93106
!*********************************************************
94107
!>
95-
! Processor dependendant 'DEFAULT' character kind.
108+
! Processor dependent 'DEFAULT' character kind.
96109
! This is 1 byte for the Intel and Gfortran compilers.
97110
integer,parameter,public :: CDK = selected_char_kind('DEFAULT')
98111
!*********************************************************

src/json_parameters.F90

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ module json_parameters
6464
character(kind=CK,len=*),parameter :: slash = achar(47, kind=CK) !! JSON special character
6565
character(kind=CK,len=*),parameter :: backslash = achar(92, kind=CK) !! JSON special character
6666

67+
!> default real number format statement (for writing real values to strings and files).
68+
! Note that this can be overridden by calling [[json_initialize]].
69+
#ifdef REAL32
70+
character(kind=CDK,len=*),parameter :: default_real_fmt = '(ss,E17.8E3)'
71+
#elif REAL128
72+
character(kind=CDK,len=*),parameter :: default_real_fmt = '(ss,E46.35E5)'
73+
#else
6774
character(kind=CDK,len=*),parameter :: default_real_fmt = '(ss,E27.17E4)'
68-
!! default real number format statement (for writing real values to strings and files).
69-
!! Note that this can be overridden by calling [[json_initialize]].
75+
#endif
7076

7177
character(kind=CK,len=*),parameter :: star = CK_'*' !! for invalid numbers and
7278
!! list-directed real output

0 commit comments

Comments
 (0)