Skip to content

Commit 499e7c7

Browse files
committed
updated interface to json_file info routines to match the ones in json_core.
1 parent 40bf94b commit 499e7c7

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

src/json_file_module.F90

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -648,57 +648,45 @@ end subroutine json_file_print_to_string
648648
! date: 2/3/2014
649649
!
650650
! Returns information about a variable in a [[json_file(type)]].
651+
!
652+
!@note If `found` is present, no exceptions will be thrown if an
653+
! error occurs. Otherwise, an exception will be thrown if the
654+
! variable is not found.
651655

652-
subroutine json_file_variable_info(me,path,found,var_type,n_children)
656+
subroutine json_file_variable_info(me,path,found,var_type,n_children,name)
653657

654658
implicit none
655659

656660
class(json_file),intent(inout) :: me
657661
character(kind=CK,len=*),intent(in) :: path !! path to the variable
658-
logical(LK),intent(out) :: found !! the variable exists in the structure
659-
integer(IK),intent(out) :: var_type !! variable type
660-
integer(IK),intent(out) :: n_children !! number of children
661-
662-
type(json_value),pointer :: p
663-
664-
!initialize:
665-
nullify(p)
666-
667-
!get a pointer to the variable (if it is there):
668-
call me%get(path,p,found)
669-
670-
if (found) then
671-
672-
!get info:
673-
call me%core%info(p,var_type,n_children)
674-
675-
else
676-
677-
!set to dummy values:
678-
var_type = json_unknown
679-
n_children = 0
680-
681-
end if
662+
logical(LK),intent(out),optional :: found !! the variable exists in the structure
663+
integer(IK),intent(out),optional :: var_type !! variable type
664+
integer(IK),intent(out),optional :: n_children !! number of children
665+
character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name
682666

683-
!cleanup:
684-
nullify(p)
667+
call me%core%info(me%p,path,found,var_type,n_children,name)
685668

686669
end subroutine json_file_variable_info
687670
!*****************************************************************************************
688671

689672
!*****************************************************************************************
690673
!>
691674
! Alternate version of [[json_file_variable_info]], where "path" is kind=CDK.
675+
!
676+
!@note If `found` is present, no exceptions will be thrown if an
677+
! error occurs. Otherwise, an exception will be thrown if the
678+
! variable is not found.
692679

693-
subroutine wrap_json_file_variable_info(me,path,found,var_type,n_children)
680+
subroutine wrap_json_file_variable_info(me,path,found,var_type,n_children,name)
694681

695682
implicit none
696683

697684
class(json_file),intent(inout) :: me
698685
character(kind=CDK,len=*),intent(in) :: path
699-
logical(LK),intent(out) :: found
700-
integer(IK),intent(out) :: var_type
701-
integer(IK),intent(out) :: n_children
686+
logical(LK),intent(out),optional :: found
687+
integer(IK),intent(out),optional :: var_type
688+
integer(IK),intent(out),optional :: n_children
689+
character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name
702690

703691
call me%info(to_unicode(path),found,var_type,n_children)
704692

src/json_value_module.F90

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,10 @@ end subroutine json_info
990990
!
991991
!### See also
992992
! * [[json_info]]
993+
!
994+
!@note If `found` is present, no exceptions will be thrown if an
995+
! error occurs. Otherwise, an exception will be thrown if the
996+
! variable is not found.
993997

994998
subroutine json_info_by_path(json,p,path,found,var_type,n_children,name)
995999

@@ -1006,18 +1010,26 @@ subroutine json_info_by_path(json,p,path,found,var_type,n_children,name)
10061010
type(json_value),pointer :: p_var
10071011
logical(LK) :: p_var_found
10081012

1009-
call json%get(p,path,p_var,found)
1013+
nullify(p_var)
1014+
call json%get(p,path,p_var,p_var_found)
10101015

10111016
!check if it was found:
10121017
if (present(found)) then
1018+
found = p_var_found
10131019
if (.not. found) then
10141020
if (present(var_type)) var_type = json_unknown
10151021
if (present(n_children)) n_children = 0
10161022
if (present(name)) name = ''
1023+
call json%clear_exceptions()
10171024
return
10181025
end if
10191026
else
1020-
if (json%failed()) return
1027+
if (json%failed()) then
1028+
if (present(var_type)) var_type = json_unknown
1029+
if (present(n_children)) n_children = 0
1030+
if (present(name)) name = ''
1031+
return
1032+
end if
10211033
end if
10221034

10231035
!get info:

0 commit comments

Comments
 (0)