Given the path string, if the variable is present, and is a scalar, then update its value. If it is not present, then create it and set its value.
If the variable is not a scalar, an exception will be thrown.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | |||
character(kind=CK,len=*), | intent(in) | :: | path | path to the variable in the structure |
||
logical(kind=LK), | intent(in) | :: | val | the new value |
||
logical(kind=LK), | intent(out) | :: | found | if the variable was found and was a scalar. |
subroutine json_update_logical(json,p,path,val,found)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer :: p
character(kind=CK,len=*),intent(in) :: path !! path to the variable in the structure
logical(LK),intent(in) :: val !! the new value
logical(LK),intent(out) :: found !! if the variable was found and was a scalar.
type(json_value),pointer :: p_var
integer(IK) :: var_type
call json%get(p,path,p_var,found)
if (found) then
call json%info(p_var,var_type)
select case (var_type)
case (json_null,json_logical,json_integer,json_double,json_string)
call json%to_logical(p_var,val) !update the value
case default
found = .false.
call json%throw_exception('Error in json_update_logical: '//&
'the variable is not a scalar value')
end select
else
call json%add_by_path(p,path,val) !add the new element
end if
end subroutine json_update_logical