Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | a JSON linked list |
|
character(kind=CK,len=*), | intent(in) | :: | path | path to the variable |
||
logical(kind=LK), | intent(out), | optional | :: | found | true if it was found |
|
integer(kind=IK), | intent(out), | optional | :: | var_type | variable type |
|
integer(kind=IK), | intent(out), | optional | :: | n_children | number of children |
|
character(kind=CK,len=:), | intent(out), | optional | allocatable | :: | name | variable name |
subroutine json_info_by_path(json,p,path,found,var_type,n_children,name)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer,intent(in) :: p !! a JSON linked list
character(kind=CK,len=*),intent(in) :: path !! path to the variable
logical(LK),intent(out),optional :: found !! true if it was found
integer(IK),intent(out),optional :: var_type !! variable type
integer(IK),intent(out),optional :: n_children !! number of children
character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name
type(json_value),pointer :: p_var !! temporary pointer
logical(LK) :: ok !! if the variable was found
#if defined __GFORTRAN__
character(kind=CK,len=:),allocatable :: p_name !! temporary variable for getting name
#endif
call json%get(p,path,p_var,found)
!check if it was found:
if (present(found)) then
ok = found
else
ok = .not. json%exception_thrown
end if
if (.not. ok) then
if (present(var_type)) var_type = json_unknown
if (present(n_children)) n_children = 0
if (present(name)) name = CK_''
else
!get info:
#if defined __GFORTRAN__
call json%info(p_var,var_type,n_children)
if (present(name)) then !workaround for gfortran bug
if (allocated(p_var%name)) then
p_name = p_var%name
name = p_name
else
name = CK_''
end if
end if
#else
call json%info(p_var,var_type,n_children,name)
#endif
end if
end subroutine json_info_by_path