80
80
81
81
module json_value_module
82
82
83
- use ,intrinsic :: iso_fortran_env, only: iostat_end
83
+ use ,intrinsic :: iso_fortran_env, only: iostat_end,error_unit,output_unit
84
84
use json_kinds
85
+ use json_parameters
85
86
use json_string_utilities
86
87
87
88
implicit none
@@ -577,89 +578,30 @@ end subroutine traverse_callback_func
577
578
public :: json_update ! update a value in a JSON structure
578
579
public :: json_traverse ! to traverse all elements of a JSON structure
579
580
public :: json_print_error_message !
580
-
581
- ! ... so it can be used in json_file_module ...
582
- ! public :: json_value_print
583
581
public :: throw_exception
584
582
585
- character (kind= CDK,len=* ),parameter ,public :: json_ext = ' .json' ! ! JSON file extension
586
-
587
- ! special JSON characters
588
- character (kind= CK,len=* ),parameter :: space = ' '
589
- character (kind= CK,len=* ),parameter :: start_object = ' {'
590
- character (kind= CK,len=* ),parameter :: end_object = ' }'
591
- character (kind= CK,len=* ),parameter :: start_array = ' ['
592
- character (kind= CK,len=* ),parameter :: end_array = ' ]'
593
- character (kind= CK,len=* ),parameter :: delimiter = ' ,'
594
- character (kind= CK,len=* ),parameter :: colon_char = ' :'
595
- character (kind= CK,len=* ),parameter :: bspace = achar (8 )
596
- character (kind= CK,len=* ),parameter :: horizontal_tab = achar (9 )
597
- character (kind= CK,len=* ),parameter :: newline = achar (10 )
598
- character (kind= CK,len=* ),parameter :: formfeed = achar (12 )
599
- character (kind= CK,len=* ),parameter :: carriage_return = achar (13 )
600
- character (kind= CK,len=* ),parameter :: quotation_mark = achar (34 )
601
- character (kind= CK,len=* ),parameter :: slash = achar (47 )
602
- character (kind= CK,len=* ),parameter :: backslash = achar (92 )
603
-
604
- ! These were parameters, but gfortran bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65141)
605
- ! necessitates moving them here to be variables
606
- character (kind= CK,len= 4 ) :: null_str = ' null'
607
- character (kind= CK,len= 4 ) :: true_str = ' true'
608
- character (kind= CK,len= 5 ) :: false_str = ' false'
609
-
610
- ! Control characters, possibly in unicode
611
- integer , private :: i_
612
- character (kind= CK,len=* ),parameter :: control_chars(32 ) = [(achar (i_),i_= 1 ,31 ), achar (127 )]
613
-
614
- ! for indenting (Note: jsonlint.com uses 4 spaces)
615
- integer (IK),parameter :: spaces_per_tab = 2
583
+ !
584
+ ! Note: the following global variables make this module non thread safe.
585
+ !
616
586
617
587
! Variables for real string printing:
618
-
619
588
logical (LK) :: compact_real = .true. ! ! to use the "compact" form of real numbers for output
620
-
621
- ! find out the precision of the floating point number system
622
- ! and set safety factors
623
- integer (IK),parameter :: rp_safety_factor = 1
624
- integer (IK),parameter :: rp_addl_safety = 1
625
- integer (IK),parameter :: real_precision = rp_safety_factor* precision (1.0_RK ) + &
626
- rp_addl_safety
627
-
628
- ! Get the number of possible digits in the exponent when using decimal number system
629
- integer (IK),parameter :: maxexp = maxexponent (1.0_RK )
630
- integer (IK),parameter :: minexp = minexponent (1.0_RK )
631
- integer (IK),parameter :: real_exponent_digits = floor ( 1 + log10 ( &
632
- real (max (maxexp,abs (maxexp)),&
633
- kind= RK) ) )
634
-
635
- integer (IK),parameter :: max_numeric_str_len = real_precision + real_exponent_digits + 6
636
- ! ! 6 = sign + leading 0 + decimal + 'E' + exponent sign + 1 extra
637
- character (kind= CDK,len=* ),parameter :: int_fmt = ' (ss,I0)' ! ! minimum width format for integers
638
589
character (kind= CDK,len= :),allocatable :: real_fmt ! ! the format string to use for real numbers
639
590
! ! it is set in [[json_initialize]]
640
591
641
- !
642
- ! Note: the following global variables make this module non thread safe.
643
- !
644
-
645
592
! exception handling [private variables]
646
- logical (LK) :: is_verbose = .false. ! ! if true, all exceptions are immediately printed to console
647
- logical (LK),public :: exception_thrown = .true. ! ! the error flag (by default, this is true to
648
- ! ! make sure that [[json_initialize]] is called.
593
+ logical (LK) :: is_verbose = .false. ! ! if true, all exceptions are immediately printed to console
594
+ logical (LK),public :: exception_thrown = .true. ! ! the error flag (by default, this is true to
595
+ ! ! make sure that [[json_initialize]] is called.
649
596
character (kind= CK,len= :),allocatable :: err_message ! ! the error message
650
597
651
598
! temp vars used when parsing lines in file [private variables]
652
- integer (IK) :: char_count = 0 ! character position in the current line
653
- integer (IK) :: line_count = 1 ! lines read counter
599
+ integer (IK) :: char_count = 0 ! ! character position in the current line
600
+ integer (IK) :: line_count = 1 ! ! lines read counter
654
601
integer (IK) :: pushed_index = 0
655
602
character (kind= CK,len= 10 ) :: pushed_char = ' ' ! JW : what is this magic number 10??
656
603
657
- integer (IK),parameter :: chunk_size = 100 ! ! for allocatable strings: allocate chunks of this size
658
- integer (IK) :: ipos = 1 ! ! for allocatable strings: next character to read
659
-
660
- integer (IK),parameter ,public :: unit2str = - 1 ! ! unit number to cause stuff to be
661
- ! ! output to strings rather than files.
662
- ! ! See 9.5.6.12 in the F2003/08 standard
604
+ integer (IK) :: ipos = 1 ! ! for allocatable strings: next character to read
663
605
664
606
contains
665
607
! *****************************************************************************************
@@ -842,6 +784,7 @@ subroutine json_initialize(verbose,compact_reals,print_signs,real_format)
842
784
! clear any errors from previous runs:
843
785
call json_clear_exceptions()
844
786
787
+ ! JW note: do we need this?.....
845
788
! Ensure gfortran bug work around "parameters" are set properly
846
789
null_str = ' null'
847
790
true_str = ' true'
@@ -945,18 +888,24 @@ end subroutine json_clear_exceptions
945
888
946
889
subroutine json_throw_exception (msg )
947
890
891
+ #ifdef __INTEL_COMPILER
892
+ use ifcore, only: tracebackqq
893
+ #endif
894
+
948
895
implicit none
949
896
950
- character (kind= CK,len=* ),intent (in ) :: msg ! the error message
897
+ character (kind= CK,len=* ),intent (in ) :: msg ! ! the error message
951
898
952
899
exception_thrown = .true.
953
900
err_message = trim (msg)
954
901
955
902
if (is_verbose) then
956
903
write (* ,' (A)' ) ' ***********************'
957
- write (* ,' (A)' ) ' JSON-Fortran EXCEPTION : ' // trim (msg)
904
+ write (* ,' (A)' ) ' JSON-Fortran Exception : ' // trim (msg)
958
905
! call backtrace() ! gfortran (use -fbacktrace -fall-intrinsics flags)
959
- ! call tracebackqq(-1) ! intel (requires "use ifcore" in this routine)
906
+ #ifdef __INTEL_COMPILER
907
+ call tracebackqq(- 1 ) ! print a traceback and return
908
+ #endif
960
909
write (* ,' (A)' ) ' ***********************'
961
910
end if
962
911
@@ -971,7 +920,7 @@ subroutine wrap_json_throw_exception(msg)
971
920
972
921
implicit none
973
922
974
- character (kind= CDK,len=* ),intent (in ) :: msg ! the error message
923
+ character (kind= CDK,len=* ),intent (in ) :: msg ! ! the error message
975
924
976
925
call json_throw_exception(to_unicode(msg))
977
926
0 commit comments