json_update_real Subroutine

private subroutine json_update_real(json, p, path, val, found)

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.

Arguments

Type IntentOptional AttributesName
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

real(kind=RK), intent(in) :: val

the new value

logical(kind=LK), intent(out) :: found

if the variable was found and was a scalar.


Contents

Source Code


Source Code

    subroutine json_update_real(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
    real(RK),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_real,json_string)
            call json%to_real(p_var,val)    !update the value
        case default
            found = .false.
            call json%throw_exception('Error in json_update_real: '//&
                                      'the variable is not a scalar value',found)
        end select

    else
        call json%add_by_path(p,path,val)   !add the new element
    end if

    end subroutine json_update_real