@@ -260,19 +260,19 @@ module json_module
260
260
! The types of JSON data.
261
261
!
262
262
integer (IK),parameter ,public :: json_unknown = 0 ! ! Unknown JSON data type
263
- ! ! (see [[json_file_variable_info]] and [[json_info]])
263
+ ! ! (see [[json_file_variable_info]] and [[json_info]])
264
264
integer (IK),parameter ,public :: json_null = 1 ! ! Null JSON data type
265
- ! ! (see [[json_file_variable_info]] and [[json_info]])
265
+ ! ! (see [[json_file_variable_info]] and [[json_info]])
266
266
integer (IK),parameter ,public :: json_object = 2 ! ! Object JSON data type
267
- ! ! (see [[json_file_variable_info]] and [[json_info]])
267
+ ! ! (see [[json_file_variable_info]] and [[json_info]])
268
268
integer (IK),parameter ,public :: json_array = 3 ! ! Array JSON data type
269
- ! ! (see [[json_file_variable_info]] and [[json_info]])
269
+ ! ! (see [[json_file_variable_info]] and [[json_info]])
270
270
integer (IK),parameter ,public :: json_logical = 4 ! ! Logical JSON data type
271
- ! ! (see [[json_file_variable_info]] and [[json_info]])
271
+ ! ! (see [[json_file_variable_info]] and [[json_info]])
272
272
integer (IK),parameter ,public :: json_integer = 5 ! ! Integer JSON data type
273
- ! ! (see [[json_file_variable_info]] and [[json_info]])
273
+ ! ! (see [[json_file_variable_info]] and [[json_info]])
274
274
integer (IK),parameter ,public :: json_double = 6 ! ! Double JSON data type
275
- ! ! (see [[json_file_variable_info]] and [[json_info]])
275
+ ! ! (see [[json_file_variable_info]] and [[json_info]])
276
276
integer (IK),parameter ,public :: json_string = 7 ! ! String JSON data type
277
277
! *********************************************************
278
278
@@ -914,7 +914,7 @@ end subroutine traverse_callback_func
914
914
integer (IK),parameter :: max_numeric_str_len = real_precision + real_exponent_digits + 6
915
915
! ! 6 = sign + leading 0 + decimal + 'E' + exponent sign + 1 extra
916
916
character (kind= CDK,len=* ),parameter :: int_fmt = ' (ss,I0)' ! ! minimum width format for integers
917
- character (kind= CK, len=* ),parameter :: star = ' *' ! ! for invalid numbers
917
+ character (kind= CK, len=* ),parameter :: star = ' *' ! ! for invalid numbers and list-directed real output
918
918
character (kind= CDK,len= :),allocatable :: real_fmt ! ! the format string to use for real numbers
919
919
! ! it is set in [[json_initialize]]
920
920
@@ -925,7 +925,7 @@ end subroutine traverse_callback_func
925
925
! exception handling [private variables]
926
926
logical (LK) :: is_verbose = .false. ! ! if true, all exceptions are immediately printed to console
927
927
logical (LK) :: exception_thrown = .true. ! ! the error flag (by default, this is true to
928
- ! ! make sure that [[json_initialize]] is called.
928
+ ! ! make sure that [[json_initialize]] is called.
929
929
character (kind= CK,len= :),allocatable :: err_message ! ! the error message
930
930
931
931
! temp vars used when parsing lines in file [private variables]
@@ -1717,6 +1717,16 @@ subroutine json_initialize(verbose,compact_reals,print_signs,real_format)
1717
1717
present (compact_reals) .or. &
1718
1718
present (print_signs) .or. &
1719
1719
present (real_format) ) then
1720
+
1721
+ ! allow the special case where real format is '*':
1722
+ ! [this overrides the other options]
1723
+ if (present (real_format)) then
1724
+ if (real_format== star) then
1725
+ compact_real = .false.
1726
+ real_fmt = star
1727
+ return
1728
+ end if
1729
+ end if
1720
1730
1721
1731
if (present (compact_reals)) compact_real = compact_reals
1722
1732
@@ -3971,6 +3981,11 @@ end function string_to_integer
3971
3981
! date: 1/19/2014
3972
3982
!
3973
3983
! Convert a string into a double.
3984
+ !
3985
+ ! # History
3986
+ ! * Jacob Williams, 10/27/2015 : Now using fmt=*, rather than
3987
+ ! fmt=real_fmt, since it doesn't work for some unusual cases
3988
+ ! (e.g., when str='1E-5').
3974
3989
3975
3990
function string_to_double (str ) result(rval)
3976
3991
@@ -3982,15 +3997,16 @@ function string_to_double(str) result(rval)
3982
3997
integer (IK) :: ierr
3983
3998
3984
3999
if (.not. exception_thrown) then
3985
-
3986
- read (str,fmt= real_fmt,iostat= ierr) rval ! string to double
3987
-
4000
+
4001
+ ! string to double
4002
+ read (str,fmt=* ,iostat= ierr) rval
4003
+
3988
4004
if (ierr/= 0 ) then ! if there was an error
3989
4005
rval = 0.0_RK
3990
4006
call throw_exception(' Error in string_to_double:' // &
3991
4007
' string cannot be converted to a double: ' // trim (str))
3992
4008
end if
3993
-
4009
+
3994
4010
end if
3995
4011
3996
4012
end function string_to_double
@@ -6652,6 +6668,7 @@ end subroutine integer_to_string
6652
6668
!
6653
6669
! # Modified
6654
6670
! * Izaak Beekman : 02/24/2015 : added the compact option.
6671
+ ! * Jacob Williams : 10/27/2015 : added the star option.
6655
6672
6656
6673
subroutine real_to_string (rval ,str )
6657
6674
@@ -6662,8 +6679,11 @@ subroutine real_to_string(rval,str)
6662
6679
6663
6680
integer (IK) :: istat
6664
6681
6665
- ! default format:
6666
- write (str,fmt= real_fmt,iostat= istat) rval
6682
+ if (real_fmt== star) then
6683
+ write (str,fmt=* ,iostat= istat) rval
6684
+ else
6685
+ write (str,fmt= real_fmt,iostat= istat) rval
6686
+ end if
6667
6687
6668
6688
if (istat== 0 ) then
6669
6689
0 commit comments