@@ -98,10 +98,18 @@ module json_module
9898 integer ,parameter ,public :: wp = selected_real_kind (15 ,307 ) ! double precision reals
9999 character (len=* ),parameter ,public :: json_ext = ' .json' ! JSON file extension
100100
101- character (len= 1 ),parameter :: space = ' '
102- character (len= 1 ),parameter :: newline = ACHAR (10 ) ! new line character
103- character (len=* ),parameter :: real_fmt = ' (E30.16E3)' ! format for real numbers
104- character (len=* ),parameter :: int_fmt = ' (I10)' ! format for integers
101+ character (len= 1 ),parameter :: space = ' ' ! special characters
102+ character (len= 1 ),parameter :: bspace = achar (8 )
103+ character (len= 1 ),parameter :: horizontal_tab = achar (9 )
104+ character (len= 1 ),parameter :: newline = achar (10 )
105+ character (len= 1 ),parameter :: formfeed = achar (12 )
106+ character (len= 1 ),parameter :: carriage_return = achar (13 )
107+ character (len= 1 ),parameter :: quotation_mark = achar (34 )
108+ character (len= 1 ),parameter :: slash = achar (47 )
109+ character (len= 1 ),parameter :: backslash = achar (92 )
110+
111+ character (len=* ),parameter :: real_fmt = ' (E30.16E3)' ! format for real numbers
112+ character (len=* ),parameter :: int_fmt = ' (I10)' ! format for integers
105113
106114 logical ,parameter :: debug = .false. ! for printing the debug messages
107115
@@ -1442,19 +1450,20 @@ subroutine escape_string(str_in, str_out)
14421450
14431451 select case (c)
14441452
1445- case (' "' ,ACHAR (92 ),' /' ,ACHAR (8 ),ACHAR (12 ),ACHAR (10 ),ACHAR (13 ),ACHAR (9 )) ! special characters
1453+ case (quotation_mark,backslash,slash,bspace,&
1454+ formfeed,newline,carriage_return,horizontal_tab) ! special characters
14461455 select case (c)
1447- case (' " ' , ACHAR ( 92 ), ' / ' )
1448- str_out = str_out// ACHAR ( 92 ) // c ! add escape char
1449- case (ACHAR ( 8 ) )
1456+ case (quotation_mark,backslash,slash )
1457+ str_out = str_out// backslash // c ! add escape char
1458+ case (bspace )
14501459 str_out = str_out// ' \b' ! backspace
1451- case (ACHAR ( 12 ) )
1460+ case (formfeed )
14521461 str_out = str_out// ' \f' ! formfeed
1453- case (ACHAR ( 10 ) )
1462+ case (newline )
14541463 str_out = str_out// ' \n' ! new line
1455- case (ACHAR ( 13 ) )
1464+ case (carriage_return )
14561465 str_out = str_out// ' \r' ! carriage return
1457- case (ACHAR ( 9 ) )
1466+ case (horizontal_tab )
14581467 str_out = str_out// ' \t' ! horizontal tab
14591468 end select
14601469 case default
@@ -2208,7 +2217,7 @@ subroutine json_get_integer(this, path, value, found)
22082217 case (json_integer)
22092218 value = p% data % int_value
22102219 case (json_real)
2211- value = p% data % dbl_value
2220+ value = int ( p% data % dbl_value)
22122221 case (json_logical)
22132222 if (p% data % log_value) then
22142223 value = 1
@@ -2631,7 +2640,7 @@ subroutine json_get_chars(this, path, value, found)
26312640 do
26322641
26332642 jprev = j ! initialize
2634- j = index (s(j:n),ACHAR ( 92 ) ) ! look for an escape character
2643+ j = index (s(j:n),backslash ) ! look for an escape character
26352644
26362645 if (j> 0 ) then ! an escape character was found
26372646
@@ -2650,7 +2659,7 @@ subroutine json_get_chars(this, path, value, found)
26502659 c = s( j+1 : j+1 )
26512660
26522661 select case (c)
2653- case (' " ' , ACHAR ( 92 ), ' / ' ,' b' ,' f' ,' n' ,' r' ,' t' )
2662+ case (quotation_mark,backslash,slash ,' b' ,' f' ,' n' ,' r' ,' t' )
26542663
26552664 ! save the bit after the escape characters:
26562665 if (j+2 < n) then
@@ -2660,18 +2669,18 @@ subroutine json_get_chars(this, path, value, found)
26602669 end if
26612670
26622671 select case (c)
2663- case (' " ' , ACHAR ( 92 ), ' / ' )
2672+ case (quotation_mark,backslash,slash )
26642673 ! use c as is
26652674 case (' b' )
2666- c = ACHAR ( 8 ) ! backspace
2675+ c = bspace
26672676 case (' f' )
2668- c = ACHAR ( 12 ) ! formfeed
2677+ c = formfeed
26692678 case (' n' )
2670- c = ACHAR ( 10 ) ! new line
2679+ c = newline
26712680 case (' r' )
2672- c = ACHAR ( 13 ) ! carriage return
2681+ c = carriage_return
26732682 case (' t' )
2674- c = ACHAR ( 9 ) ! horizontal tab
2683+ c = horizontal_tab
26752684 end select
26762685
26772686 s = pre// c// post
@@ -2694,7 +2703,7 @@ subroutine json_get_chars(this, path, value, found)
26942703 case default
26952704 ! unknown escape character
26962705 call throw_exception(' Error in json_get_chars: unknown escape sequence in string "' // &
2697- trim (s)// ' " [' // ACHAR ( 92 ) // c// ' ]' )
2706+ trim (s)// ' " [' // backslash // c// ' ]' )
26982707 exit
26992708 end select
27002709
@@ -3626,7 +3635,7 @@ subroutine parse_string(unit, string)
36263635 call throw_exception(' Error in parse_string: Expecting end of string' )
36273636 return
36283637
3629- else if (' "' == c .and. last /= ACHAR ( 92 ) ) then
3638+ else if (' "' == c .and. last /= backslash ) then
36303639
36313640 if (is_hex) call throw_exception(' Error in parse_string: incomplete hex string: \u' // trim (hex))
36323641 exit
@@ -3660,7 +3669,7 @@ subroutine parse_string(unit, string)
36603669 escape = .false.
36613670 is_hex = (c==' u' ) ! the next four characters are the hex string
36623671 else
3663- escape = (c== ACHAR ( 92 ) )
3672+ escape = (c== backslash )
36643673 end if
36653674
36663675 end if
0 commit comments