diff --git a/build.sh b/build.sh index 44e3dbd152..3e8662043d 100755 --- a/build.sh +++ b/build.sh @@ -31,7 +31,7 @@ # --compiler : gnu or gfortran for gfortran, intel or ifort for intel compiler # A custom compiler may also be specified here, e.g. ftn # -# --cflags : Enter any aditiol/custom compiler flags here and make sure they are +# --cflags : Enter any additional/custom compiler flags here and make sure they are # properly quoted # # --help : Print a usage message and exit. diff --git a/src/json_file_module.F90 b/src/json_file_module.F90 index 8aba64c8d3..0a71f11b88 100644 --- a/src/json_file_module.F90 +++ b/src/json_file_module.F90 @@ -169,6 +169,11 @@ module json_file_module json_file_update_string_val_ascii #endif + !> + ! Remove a variable from a [[json_file(type)]] + ! by specifying the path. + generic,public :: remove => MAYBEWRAP(json_file_remove) + !traverse procedure,public :: traverse => json_file_traverse @@ -244,6 +249,9 @@ module json_file_module procedure :: json_file_update_string_val_ascii #endif + !remove: + procedure :: MAYBEWRAP(json_file_remove) + !print_file: procedure :: json_file_print_to_console procedure :: json_file_print_1 @@ -2192,6 +2200,42 @@ subroutine json_file_traverse(me,traverse_callback) end subroutine json_file_traverse !***************************************************************************************** +!***************************************************************************************** +!> author: Jacob Williams +! date: 7/7/2018 +! +! Remove a variable from a JSON file. +! +!@note This is just a wrapper to [[remove_if_present]]. + + subroutine json_file_remove(me,path) + + implicit none + + class(json_file),intent(inout) :: me + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + + call me%core%remove_if_present(me%p,path) + + end subroutine json_file_remove +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_file_remove]], where "path" is kind=CDK. + + subroutine wrap_json_file_remove(me,path) + + implicit none + + class(json_file),intent(inout) :: me + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + + call me%remove(to_unicode(path)) + + end subroutine wrap_json_file_remove +!***************************************************************************************** + !***************************************************************************************** end module json_file_module !***************************************************************************************** diff --git a/src/json_value_module.F90 b/src/json_value_module.F90 index 5977edbdcf..dea7a6cfac 100644 --- a/src/json_value_module.F90 +++ b/src/json_value_module.F90 @@ -168,7 +168,7 @@ module json_value_module logical(LK) :: is_verbose = .false. !! if true, all exceptions are !! immediately printed to console. - logical(LK) :: stop_on_error = .false. !! if true, then the program is + logical(LK) :: stop_on_error = .false. !! if true, then the program is !! stopped immediately when an !! exception is raised. @@ -6308,8 +6308,9 @@ end subroutine json_get_by_path_default ! are user-specified. To fully conform to the RFC 6901 standard, ! should probably set (via `initialize`): ! -! * `trailing_spaces_significant` = .true. [this is not the default setting] -! * `case_sensitive_keys` = .true. [this is the default setting] +! * `case_sensitive_keys = .true.` [this is the default setting] +! * `trailing_spaces_significant = .true.` [this is *not* the default setting] +! * `allow_duplicate_keys = .false.` [this is *not* the default setting] ! !### Example ! @@ -6454,7 +6455,7 @@ subroutine json_get_by_path_rfc6901(json, me, path, p, found) end if if (status_ok) then ! if we make it this far, it should be - ! convertable to an integer, so do it. + ! convertible to an integer, so do it. call string_to_integer(token,ival,status_ok) end if end if @@ -6753,6 +6754,7 @@ subroutine json_get_by_path_jsonpath_bracket(json,me,path,p,found,create_it,was_ ! verify that there are no spaces or other ! characters in the string: + status_ok = .true. do i=1,len(token) ! It must only contain (0..9) characters ! (it must be unsigned) @@ -9889,7 +9891,7 @@ subroutine parse_string(json, unit, str, string) ! start accumulating the hex string (should be the next 4 characters) if (escape) then escape = .false. - is_hex = (c=='u') !the next four characters are the hex string + is_hex = (c==CK_'u') !the next four characters are the hex string else escape = (c==backslash) end if diff --git a/src/tests/jf_test_01.F90 b/src/tests/jf_test_01.F90 index 005a721e9b..233a071c54 100644 --- a/src/tests/jf_test_01.F90 +++ b/src/tests/jf_test_01.F90 @@ -72,7 +72,7 @@ subroutine test_1(error_cnt) ! print the parsed data to the console write(error_unit,'(A)') '' write(error_unit,'(A)') 'printing the file...' - call json%print_file() + call json%print_file(error_unit) if (json%failed()) then call json%print_error_message(error_unit) error_cnt = error_cnt + 1 @@ -326,9 +326,17 @@ subroutine test_1(error_cnt) end if end if + ! remove a variable using the remove method: + call json%remove(json_CK_'version.patch') + call json%remove(json_CDK_'version.minor') + if (json%failed()) then + call json%print_error_message(error_unit) + error_cnt = error_cnt + 1 + end if + write(error_unit,'(A)') '' write(error_unit,'(A)') 'printing the modified structure...' - call json%print_file() + call json%print_file(error_unit) if (json%failed()) then call json%print_error_message(error_unit) error_cnt = error_cnt + 1 @@ -362,7 +370,7 @@ subroutine test_1(error_cnt) write(error_unit,'(A)') '' write(error_unit,'(A)') 'printing the modified structure...' - call json%print_file() + call json%print_file(error_unit) if (json%failed()) then call json%print_error_message(error_unit) error_cnt = error_cnt + 1 @@ -371,7 +379,7 @@ subroutine test_1(error_cnt) write(error_unit,'(A)') '' write(error_unit,'(A)') 'printing the modified structure (compact mode)...' call json%initialize(no_whitespace=.true.) - call json%print_file() + call json%print_file(error_unit) if (json%failed()) then call json%print_error_message(error_unit) error_cnt = error_cnt + 1 diff --git a/src/tests/jf_test_05.F90 b/src/tests/jf_test_05.F90 index a524493c9f..0c7cba340b 100644 --- a/src/tests/jf_test_05.F90 +++ b/src/tests/jf_test_05.F90 @@ -60,7 +60,7 @@ subroutine test_5(error_cnt) ! print the parsed data to the console: write(error_unit,'(A)') 'print file...' - call json%print_file() + call json%print_file(error_unit) if (json%failed()) then call json%print_error_message(error_unit) error_cnt = error_cnt + 1 diff --git a/src/tests/jf_test_18.F90 b/src/tests/jf_test_18.F90 index 26ba2f3bb3..04f610d14d 100644 --- a/src/tests/jf_test_18.F90 +++ b/src/tests/jf_test_18.F90 @@ -30,6 +30,7 @@ subroutine test_18(error_cnt) integer :: ival logical :: found logical,dimension(4) :: ok + integer,dimension(4) :: iresult write(error_unit,'(A)') '' write(error_unit,'(A)') '=================================' @@ -53,19 +54,23 @@ subroutine test_18(error_cnt) call json%initialize(trailing_spaces_significant=.true.,& case_sensitive_keys=.true.) - call go([1,2,3,4]) + iresult = [1,2,3,4] + call go(iresult) call json%initialize(trailing_spaces_significant=.false.,& case_sensitive_keys=.true.) - call go([1,2,1,2]) + iresult = [1,2,1,2] + call go(iresult) call json%initialize(trailing_spaces_significant=.true.,& case_sensitive_keys=.false.) - call go([1,1,3,3]) + iresult = [1,1,3,3] + call go(iresult) call json%initialize(trailing_spaces_significant=.false.,& case_sensitive_keys=.false.) - call go([1,1,1,1]) + iresult = [1,1,1,1] + call go(iresult) !cleanup: call json%destroy(p) diff --git a/src/tests/jf_test_22.F90 b/src/tests/jf_test_22.F90 index dc0f7c06a1..908fafc2de 100644 --- a/src/tests/jf_test_22.F90 +++ b/src/tests/jf_test_22.F90 @@ -57,7 +57,7 @@ subroutine test_22(error_cnt) ! print the parsed data to the console write(error_unit,'(A)') '' write(error_unit,'(A)') 'printing the file...' - call json%print_file() + call json%print_file(error_unit) if (json%failed()) then call json%print_error_message(error_unit) error_cnt = error_cnt + 1 diff --git a/src/tests/jf_test_23.F90 b/src/tests/jf_test_23.F90 index ff3e2016a1..92736fed82 100644 --- a/src/tests/jf_test_23.F90 +++ b/src/tests/jf_test_23.F90 @@ -68,7 +68,7 @@ subroutine test_23(error_cnt) ! print the parsed data to the console write(error_unit,'(A)') '' write(error_unit,'(A)') 'printing the file...' - call json%print_file() + call json%print_file(error_unit) if (json%failed()) then call json%print_error_message(error_unit) error_cnt = error_cnt + 1 diff --git a/src/tests/jf_test_30.F90 b/src/tests/jf_test_30.F90 index d23cde1aa8..c57cd8099b 100644 --- a/src/tests/jf_test_30.F90 +++ b/src/tests/jf_test_30.F90 @@ -44,7 +44,7 @@ subroutine test_30(error_cnt) call json%initialize(escape_solidus=(i==1), stop_on_error=.true.) call json%load_from_string(str) - call json%print_file() + call json%print_file(error_unit) if (json%failed()) then call json%print_error_message(error_unit)