Commit 92d35881 authored by Victor Yu's avatar Victor Yu
Browse files

Update Json-Fortran to 8.2.1

Now it compiles with PGI 19.10. Two API changes to the previous
version are relevant to West:

* load_file --> load
* print_file --> print
parent 9cdb9297
...@@ -160,7 +160,7 @@ MODULE pdep_db ...@@ -160,7 +160,7 @@ MODULE pdep_db
CALL json%add("dielectric_matrix.pdep",jval) CALL json%add("dielectric_matrix.pdep",jval)
! !
OPEN(NEWUNIT= iunit, FILE= summary_file ) OPEN(NEWUNIT= iunit, FILE= summary_file )
CALL json%print_file( iunit ) CALL json%print( iunit )
CLOSE( iunit ) CLOSE( iunit )
! !
CALL json%destroy() CALL json%destroy()
...@@ -173,7 +173,7 @@ MODULE pdep_db ...@@ -173,7 +173,7 @@ MODULE pdep_db
IF ( mpime == root ) THEN IF ( mpime == root ) THEN
! !
CALL json%initialize() CALL json%initialize()
CALL json%load_file( filename = summary_file ) CALL json%load( filename = summary_file )
! !
CALL json%info('dielectric_matrix.pdep',n_children=n_elements) CALL json%info('dielectric_matrix.pdep',n_children=n_elements)
write_element = n_elements + 1 write_element = n_elements + 1
...@@ -193,7 +193,7 @@ MODULE pdep_db ...@@ -193,7 +193,7 @@ MODULE pdep_db
CALL json%add('dielectric_matrix.pdep('//TRIM(ADJUSTL(label_i))//').eigenvec' , eigenpot_filename(1:n_pdep_eigen)) CALL json%add('dielectric_matrix.pdep('//TRIM(ADJUSTL(label_i))//').eigenvec' , eigenpot_filename(1:n_pdep_eigen))
! !
OPEN( NEWUNIT=iunit, FILE=summary_file ) OPEN( NEWUNIT=iunit, FILE=summary_file )
CALL json%print_file( iunit ) CALL json%print( iunit )
CLOSE( iunit ) CLOSE( iunit )
CALL json%destroy() CALL json%destroy()
! !
...@@ -321,7 +321,7 @@ MODULE pdep_db ...@@ -321,7 +321,7 @@ MODULE pdep_db
IF ( mpime == root ) THEN IF ( mpime == root ) THEN
! !
CALL json%initialize() CALL json%initialize()
CALL json%load_file( filename = TRIM(ADJUSTL(wstat_save_dir)) // "/summary.json" ) CALL json%load( filename = TRIM(ADJUSTL(wstat_save_dir)) // "/summary.json" )
IF( json%failed() ) THEN IF( json%failed() ) THEN
CALL errore("", "Cannot open: " // TRIM(ADJUSTL(wstat_save_dir)) // "/summary.json", 1 ) CALL errore("", "Cannot open: " // TRIM(ADJUSTL(wstat_save_dir)) // "/summary.json", 1 )
ENDIF ENDIF
......
...@@ -72,7 +72,7 @@ MODULE wfreq_db ...@@ -72,7 +72,7 @@ MODULE wfreq_db
! !
CALL json%initialize() CALL json%initialize()
! !
CALL json%load_file(filename=TRIM(logfile)) CALL json%load(filename=TRIM(logfile))
! !
l_generate_plot = .FALSE. l_generate_plot = .FALSE.
l_optics = .FALSE. l_optics = .FALSE.
...@@ -157,7 +157,7 @@ MODULE wfreq_db ...@@ -157,7 +157,7 @@ MODULE wfreq_db
ENDDO ENDDO
! !
OPEN( NEWUNIT=iunit, FILE=TRIM( logfile ) ) OPEN( NEWUNIT=iunit, FILE=TRIM( logfile ) )
CALL json%print_file( iunit ) CALL json%print( iunit )
CLOSE( iunit ) CLOSE( iunit )
CALL json%destroy() CALL json%destroy()
! !
......
========================================== ==========================================
Based on the library: json-fortran v 6.3.0 Based on the library: json-fortran v 8.2.1
========================================== ==========================================
JSON-Fortran: A Fortran 2008 JSON API JSON-Fortran: A Fortran 2008 JSON API
<https://github.com/jacobwilliams/json-fortran> <https://github.com/jacobwilliams/json-fortran>
Copyright (c) 2014-2018, Jacob Williams Copyright (c) 2014-2020, Jacob Williams
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
......
This diff is collapsed.
type(json_value),pointer :: p
if (present(default)) then
value = default
else
value = default_if_not_specified
end if
if ( json%exception_thrown ) then
call flag_not_found(found)
return
end if
nullify(p)
call json%get(me=me, path=path, p=p)
if (.not. associated(p)) then
call json%throw_exception('Error in '//routine//':'//&
' Unable to resolve path: '// trim(path),found)
else
call json%get(p,value)
end if
if ( json%exception_thrown ) then
if ( present(found) .or. present(default)) then
call flag_not_found(found)
if (present(default)) value = default
call json%clear_exceptions()
end if
else
if ( present(found) ) found = .true.
end if
type(json_value),pointer :: p
if ( json%exception_thrown ) then
if (present(default)) vec = default
call flag_not_found(found)
return
end if
nullify(p)
call json%get(me=me, path=path, p=p)
if (.not. associated(p)) then
call json%throw_exception('Error in '//routine//':'//&
' Unable to resolve path: '// trim(path),found)
else
call json%get(p,vec)
end if
if ( json%exception_thrown ) then
if ( present(found) .or. present(default)) then
call flag_not_found(found)
if (present(default)) vec = default
call json%clear_exceptions()
end if
else
if ( present(found) ) found = .true.
end if
type(json_value),pointer :: p
if ( json%exception_thrown ) then
if (present(default)) then
vec = default
if (present(default_ilen)) then
ilen = default_ilen
else
allocate(ilen(size(default)))
ilen = len(default)
end if
end if
call flag_not_found(found)
return
end if
nullify(p)
call json%get(me=me, path=path, p=p)
if (.not. associated(p)) then
call json%throw_exception('Error in '//routine//':'//&
' Unable to resolve path: '// trim(path),found)
else
call json%get(p,vec,ilen)
end if
if ( json%exception_thrown ) then
if ( present(found) .or. present(default)) then
call flag_not_found(found)
if (present(default)) then
vec = default
if (present(default_ilen)) then
ilen = default_ilen
else
allocate(ilen(size(default)))
ilen = len(default)
end if
end if
call json%clear_exceptions()
end if
else
if ( present(found) ) found = .true.
end if
! The argument list for the various `initialize` subroutines. ! The argument list for the various `initialize` subroutines.
!
! See also: json_initialize_dummy_arguments.inc
logical(LK),intent(in),optional :: verbose logical(LK),intent(in),optional :: verbose
!! mainly useful for debugging (default is false) !! mainly useful for debugging (default is false)
...@@ -13,7 +15,7 @@ integer(IK),intent(in),optional :: spaces_per_tab ...@@ -13,7 +15,7 @@ integer(IK),intent(in),optional :: spaces_per_tab
logical(LK),intent(in),optional :: strict_type_checking logical(LK),intent(in),optional :: strict_type_checking
!! if true, no integer, double, or logical type !! if true, no integer, double, or logical type
!! conversions are done for the `get` routines !! conversions are done for the `get` routines
!! (default is false) !! (default is false).
logical(LK),intent(in),optional :: trailing_spaces_significant logical(LK),intent(in),optional :: trailing_spaces_significant
!! for name and path comparisons, is trailing !! for name and path comparisons, is trailing
!! space to be considered significant. !! space to be considered significant.
...@@ -30,20 +32,21 @@ logical(LK),intent(in),optional :: unescape_strings ...@@ -30,20 +32,21 @@ logical(LK),intent(in),optional :: unescape_strings
!! string is returned from [[json_get_string]] !! string is returned from [[json_get_string]]
!! and similar routines. If true [default], !! and similar routines. If true [default],
!! then the string is returned unescaped. !! then the string is returned unescaped.
character(kind=CK,len=1),intent(in),optional :: comment_char character(kind=CK,len=*),intent(in),optional :: comment_char
!! If present, this character is used !! If present, these characters are used
!! to denote comments in the JSON file, !! to denote comments in the JSON file,
!! which will be ignored if present. !! which will be ignored if present.
!! Example: `!` or `#`. Setting this !! Example: `!`, `#`, or `/!#`. Setting this
!! to a blank string disables the !! to a blank string disables the
!! ignoring of comments. (Default is `!`). !! ignoring of comments. (Default is `/!#`).
integer(IK),intent(in),optional :: path_mode integer(IK),intent(in),optional :: path_mode
!! How the path strings are interpreted in the !! How the path strings are interpreted in the
!! `get_by_path` routines: !! `get_by_path` routines:
!! * 1 -- Default mode (see [[json_get_by_path_default]]) !!
!! * 2 -- as RFC 6901 "JSON Pointer" paths !! * 1 : Default mode (see [[json_get_by_path_default]])
!! * 2 : as RFC 6901 "JSON Pointer" paths
!! (see [[json_get_by_path_rfc6901]]) !! (see [[json_get_by_path_rfc6901]])
!! * 3 -- JSONPath "bracket-notation" !! * 3 : JSONPath "bracket-notation"
!! see [[json_get_by_path_jsonpath_bracket]]) !! see [[json_get_by_path_jsonpath_bracket]])
character(kind=CK,len=1),intent(in),optional :: path_separator character(kind=CK,len=1),intent(in),optional :: path_separator
!! The `path` separator to use !! The `path` separator to use
...@@ -71,10 +74,41 @@ logical(LK),intent(in),optional :: escape_solidus ...@@ -71,10 +74,41 @@ logical(LK),intent(in),optional :: escape_solidus
!! * If True then the solidus "`/`" is always escaped !! * If True then the solidus "`/`" is always escaped
!! "`\/`" when serializing JSON !! "`\/`" when serializing JSON
!! * If False [default], then it is not escaped. !! * If False [default], then it is not escaped.
!!
!! Note that this option does not affect parsing !! Note that this option does not affect parsing
!! (both escaped and unescaped are still valid in !! (both escaped and unescaped are still valid in
!! all cases). !! all cases).
logical(LK),intent(in),optional :: stop_on_error logical(LK),intent(in),optional :: stop_on_error
!! If an exception is raised, then immediately quit. !! If an exception is raised, then immediately quit.
!! (Default is False). !! (Default is False).
integer(IK),intent(in),optional :: null_to_real_mode
!! if `strict_type_checking=false`:
!!
!! * 1 : an exception will be raised if
!! try to retrieve a `null` as a real.
!! * 2 : a `null` retrieved as a real
!! will return a NaN. [default]
!! * 3 : a `null` retrieved as a real
!! will return 0.0.
integer(IK),intent(in),optional :: non_normal_mode
!! How to serialize NaN, Infinity, and
!! -Infinity real values:
!!
!! * 1 : as strings (e.g., "NaN",
!! "Infinity", "-Infinity") [default]
!! * 2 : as JSON `null` values
logical(LK),intent(in),optional :: use_quiet_nan
!! * If true [default], `null_to_real_mode=2`
!! and [[string_to_real]] will use
!! `ieee_quiet_nan` for NaN values.
!! * If false,
!! `ieee_signaling_nan` will be used.
logical(LK),intent(in),optional :: strict_integer_type_checking
!! * If false, when parsing JSON, if an integer numeric value
!! cannot be converted to an integer (`integer(IK)`),
!! then an attempt is then make to convert it
!! to a real (`real(RK)`).
!! * If true, an exception will be raised if the integer
!! value cannot be read.
!!
!! (default is true)
\ No newline at end of file
! The dummy argument list for the various `initialize` subroutines.
!
! See also: json_initialize_argument.inc
verbose,&
compact_reals,&
print_signs,&
real_format,&
spaces_per_tab,&
strict_type_checking,&
trailing_spaces_significant,&
case_sensitive_keys,&
no_whitespace,&
unescape_strings,&
comment_char,&
path_mode,&
path_separator,&
compress_vectors,&
allow_duplicate_keys,&
escape_solidus,&
stop_on_error,&
null_to_real_mode,&
non_normal_mode,&
use_quiet_nan, &
strict_integer_type_checking &
\ No newline at end of file
...@@ -59,6 +59,10 @@ ...@@ -59,6 +59,10 @@
! integer(kind=int32) [4 bytes] ! integer(kind=int32) [4 bytes]
#endif #endif
! . ! .
!
!@note In addition to the real kind specified by `RK`, interfaces for
! the real kinds with less precision are also provided in the library,
! but all are converted to `real(RK)` variables internally.
module json_kinds module json_kinds
...@@ -68,6 +72,15 @@ ...@@ -68,6 +72,15 @@
private private
! used for the reals with less precision
! than the default precision:
#ifndef REAL32
public :: real32
#endif
#ifdef REAL128
public :: real64
#endif
#ifdef REAL32 #ifdef REAL32
integer,parameter,public :: RK = real32 !! Default real kind [4 bytes] integer,parameter,public :: RK = real32 !! Default real kind [4 bytes]
#elif REAL64 #elif REAL64
...@@ -92,7 +105,7 @@ ...@@ -92,7 +105,7 @@
!********************************************************* !*********************************************************
!> !>
! Processor dependendant 'DEFAULT' character kind. ! Processor dependent 'DEFAULT' character kind.
! This is 1 byte for the Intel and Gfortran compilers. ! This is 1 byte for the Intel and Gfortran compilers.
integer,parameter,public :: CDK = selected_char_kind('DEFAULT') integer,parameter,public :: CDK = selected_char_kind('DEFAULT')
!********************************************************* !*********************************************************
......
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
json_array, & json_array, &
json_logical,& json_logical,&
json_integer,& json_integer,&
json_real, &
json_double, & json_double, &
json_string json_string
use json_value_module use json_value_module
......
...@@ -29,13 +29,16 @@ ...@@ -29,13 +29,16 @@
!! (see [[json_file_variable_info]] and [[json_info]]) !! (see [[json_file_variable_info]] and [[json_info]])
integer(IK),parameter :: json_array = 3 !! Array JSON data type integer(IK),parameter :: json_array = 3 !! Array JSON data type
!! (see [[json_file_variable_info]] and [[json_info]]) !! (see [[json_file_variable_info]] and [[json_info]])
integer(IK),parameter :: json_logical = 4 !! Logical JSON data type integer(IK),parameter :: json_logical = 4 !! Logical JSON data type (`logical(LK)`)
!! (see [[json_file_variable_info]] and [[json_info]]) !! (see [[json_file_variable_info]] and [[json_info]])
integer(IK),parameter :: json_integer = 5 !! Integer JSON data type integer(IK),parameter :: json_integer = 5 !! Integer JSON data type (`integer(IK)`)
!! (see [[json_file_variable_info]] and [[json_info]]).
integer(IK),parameter :: json_real = 6 !! Real number JSON data type (`real(RK)`)
!! (see [[json_file_variable_info]] and [[json_info]]) !! (see [[json_file_variable_info]] and [[json_info]])
integer(IK),parameter :: json_double = 6 !! Double JSON data type integer(IK),parameter :: json_string = 7 !! String JSON data type (`character(kind=CK)`)
!! (see [[json_file_variable_info]] and [[json_info]]) !! (see [[json_file_variable_info]] and [[json_info]])
integer(IK),parameter :: json_string = 7 !! String JSON data type integer(IK),parameter :: json_double = json_real !! Equivalent to `json_real` for
!! backward compatibility.
!special JSON characters !special JSON characters
character(kind=CK,len=*),parameter :: space = CK_' ' !! space character character(kind=CK,len=*),parameter :: space = CK_' ' !! space character
...@@ -45,9 +48,11 @@ ...@@ -45,9 +48,11 @@
character(kind=CK,len=*),parameter :: end_array = CK_']' !! end of a JSON array character(kind=CK,len=*),parameter :: end_array = CK_']' !! end of a JSON array
character(kind=CK,len=*),parameter :: delimiter = CK_',' !! delimiter for JSON character(kind=CK,len=*),parameter :: delimiter = CK_',' !! delimiter for JSON
character(kind=CK,len=*),parameter :: colon_char = CK_':' !! colon character for JSON character(kind=CK,len=*),parameter :: colon_char = CK_':' !! colon character for JSON
character(kind=CK,len=*),parameter :: start_array_alt = CK_'(' !! alternate start of JSON array for [[json_get_by_path_default]] character(kind=CK,len=*),parameter :: start_array_alt = CK_'(' !! alternate start of JSON array for
character(kind=CK,len=*),parameter :: end_array_alt = CK_')' !! alternate end of JSON array for [[json_get_by_path_default]] !! [[json_get_by_path_default]]
character(kind=CK,len=*),parameter :: root = CK_'$' !! root for [[json_get_by_path_default]] character(kind=CK,len=*),parameter :: end_array_alt = CK_')' !! alternate end of JSON array for
!! [[json_get_by_path_default]]
character(kind=CK,len=*),parameter :: root = achar(36, kind=CK) !! (`$`) root for [[json_get_by_path_default]]
character(kind=CK,len=*),parameter :: this = CK_'@' !! 'this' for [[json_get_by_path_default]] character(kind=CK,len=*),parameter :: this = CK_'@' !! 'this' for [[json_get_by_path_default]]
character(kind=CK,len=*),parameter :: dot = CK_'.' !! path separator for [[json_get_by_path_default]] character(kind=CK,len=*),parameter :: dot = CK_'.' !! path separator for [[json_get_by_path_default]]
character(kind=CK,len=*),parameter :: tilde = CK_'~' !! RFC 6901 escape character character(kind=CK,len=*),parameter :: tilde = CK_'~' !! RFC 6901 escape character
...@@ -62,9 +67,17 @@ ...@@ -62,9 +67,17 @@
character(kind=CK,len=*),parameter :: slash = achar(47, kind=CK) !! JSON special character character(kind=CK,len=*),parameter :: slash = achar(47, kind=CK) !! JSON special character
character(kind=CK,len=*),parameter :: backslash = achar(92, kind=CK) !! JSON special character character(kind=CK,len=*),parameter :: backslash = achar(92, kind=CK) !! JSON special character
!> default real number format statement (for writing real values to strings and files).
! Note that this can be overridden by calling [[json_initialize]].
#ifdef REAL32
character(kind=CDK,len=*),parameter :: default_real_fmt = '(ss,E17.8E3)'
#elif REAL128
character(kind=CDK,len=*),parameter :: default_real_fmt = '(ss,E46.35E5)'
#else
character(kind=CDK,len=*),parameter :: default_real_fmt = '(ss,E27.17E4)' character(kind=CDK,len=*),parameter :: default_real_fmt = '(ss,E27.17E4)'
!! default real number format statement (for writing real values to strings and files). #endif
!! Note that this can be overridden by calling [[json_initialize]].
character(kind=CK,len=*),parameter :: star = CK_'*' !! for invalid numbers and character(kind=CK,len=*),parameter :: star = CK_'*' !! for invalid numbers and
!! list-directed real output !! list-directed real output
...@@ -111,17 +124,22 @@ ...@@ -111,17 +124,22 @@
!! 6 = sign + leading 0 + decimal + 'E' + exponent sign + 1 extra !! 6 = sign + leading 0 + decimal + 'E' + exponent sign + 1 extra
character(kind=CDK,len=*),parameter :: int_fmt = '(ss,I0)' !! minimum width format for integers character(kind=CDK,len=*),parameter :: int_fmt = '(ss,I0)' !! minimum width format for integers
integer(IK),parameter :: max_integer_str_len = 256 !! maximum string length of an integer. integer(IK),parameter :: max_integer_str_len = 256_IK !! maximum string length of an integer.
!! This is totally arbitrary (any way !! This is totally arbitrary (any way
!! to get the compiler to tell us this?) !! to get the compiler to tell us this?)
integer(IK),parameter :: chunk_size = 100_IK !! for allocatable strings: allocate chunks of this size integer(IK),parameter :: chunk_size = 256_IK !! for allocatable strings: allocate chunks of this size
integer(IK),parameter :: unit2str = -1_IK !! unit number to cause stuff to be integer(IK),parameter :: unit2str = -1_IK !! unit number to cause stuff to be
!! output to strings rather than files. !! output to strings rather than files.
!! See 9.5.6.12 in the F2003/08 standard !! See 9.5.6.12 in the F2003/08 standard
character(kind=CK,len=*),parameter :: blank_chunk = repeat(space, chunk_size) !! a blank string
integer(IK),parameter :: seq_chunk_size = 256_IK !! chunk size for reading sequential files integer(IK),parameter :: seq_chunk_size = 256_IK !! chunk size for reading sequential files
integer(IK),parameter :: stream_chunk_size = 256_IK !! chunk size for reading stream files
integer(IK),parameter :: print_str_chunk_size = 1000_IK !! chunk size for writing JSON to a string
integer(IK),parameter :: pushed_char_size = 10_IK !! size for `pushed_char` integer(IK),parameter :: pushed_char_size = 10_IK !! size for `pushed_char`
!! array in [[json_core(type)]] !! array in [[json_core(type)]]
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
module json_string_utilities module json_string_utilities
use,intrinsic :: ieee_arithmetic
use json_kinds use json_kinds
use json_parameters use json_parameters
...@@ -120,21 +121,22 @@ ...@@ -120,21 +121,22 @@
integer(IK),intent(out) :: ival !! the integer value integer(IK),intent(out) :: ival !! the integer value
logical(LK),intent(out) :: status_ok !! true if there were no errors logical(LK),intent(out) :: status_ok !! true if there were no errors
!character(kind=CDK,len=:),allocatable :: digits character(kind=CDK,len=:),allocatable :: digits
character(len=:),allocatable :: digits
integer(IK) :: ndigits_digits,ndigits,ierr integer(IK) :: ndigits_digits,ndigits,ierr
! Compute how many digits we need to read ! Compute how many digits we need to read
ndigits = 2*len_trim(str) ndigits = 2*len_trim(str)
ndigits_digits = floor(log10(real(ndigits)))+1 if (ndigits/=0) then
!allocate(character(kind=CK,len=ndigits_digits) :: digits) ndigits_digits = floor(log10(real(ndigits)))+1
allocate(character(len=ndigits_digits) :: digits) allocate(character(kind=CDK,len=ndigits_digits) :: digits)
write(digits,'(I0)') ndigits !gfortran will have a runtime error with * edit descriptor here write(digits,'(I0)') ndigits !gfortran will have a runtime error with * edit descriptor here
! gfortran bug: '*' edit descriptor for ISO_10646 strings does bad stuff. ! gfortran bug: '*' edit descriptor for ISO_10646 strings does bad stuff.
read(str,'(I'//trim(digits)//')',iostat=ierr) ival !string to integer read(str,'(I'//trim(digits)//')',iostat=ierr) ival !string to integer
! error check:
! error check: status_ok = (ierr==0)
status_ok = (ierr==0) else
status_ok = .false.
end if
if (.not. status_ok) ival = 0_IK if (.not. status_ok) ival = 0_IK
end subroutine string_to_integer end subroutine string_to_integer
...@@ -147,10 +149,11 @@ ...@@ -147,10 +149,11 @@
! Convert a real value to a string. ! Convert a real value to a string.
! !
!### Modified !### Modified
! * Izaak Beekman : 02/24/2015 : added the compact option. ! * Izaak Beekman : 02/24/2015 : added the compact option.
! * Jacob Williams : 10/27/2015 : added the star option. ! * Jacob Williams : 10/27/2015 : added the star option.