add_variable Subroutine

private subroutine add_variable(json, p_namelist, path, str)

Infers the variable type and adds it to the namelist JSON structure.

Arguments

Type IntentOptional Attributes Name
type(json_core), intent(inout) :: json
type(json_value), pointer :: p_namelist
character(len=*), intent(in) :: path
character(len=*), intent(in) :: str

Calls

proc~~add_variable~~CallsGraph proc~add_variable namelist_parser_module::add_variable add_by_path add_by_path proc~add_variable->add_by_path create_double create_double proc~add_variable->create_double create_integer create_integer proc~add_variable->create_integer create_logical create_logical proc~add_variable->create_logical create_string create_string proc~add_variable->create_string proc~to_integer namelist_parser_module::to_integer proc~add_variable->proc~to_integer proc~to_logical namelist_parser_module::to_logical proc~add_variable->proc~to_logical proc~to_real namelist_parser_module::to_real proc~add_variable->proc~to_real proc~lowercase_string namelist_parser_module::lowercase_string proc~to_logical->proc~lowercase_string

Called by

proc~~add_variable~~CalledByGraph proc~add_variable namelist_parser_module::add_variable proc~parse_namelist namelist_parser_module::parse_namelist proc~parse_namelist->proc~add_variable

Source Code

    subroutine add_variable(json,p_namelist,path,str)

    implicit none

    type(json_core),intent(inout) :: json
    type(json_value),pointer      :: p_namelist
    character(len=*),intent(in)   :: path
    character(len=*),intent(in)   :: str

    real(wp) :: rval      !! a real value
    integer  :: ival      !! an integer value
    logical  :: lval      !! a logical value
    logical  :: status_ok !! status flag
    type(json_value),pointer :: p !! for the value

    call to_integer(str,ival,status_ok)
    if (status_ok) then
        call json%create_integer(p,ival,'')
        call json%add_by_path(p_namelist,path,p)
        return
    end if

    call to_real(str,rval,status_ok)
    if (status_ok) then
        call json%create_double(p,rval,'')
        call json%add_by_path(p_namelist,path,p)
        return
    end if

    call to_logical(str,lval,status_ok)
    if (status_ok) then
        call json%create_logical(p,lval,'')
        call json%add_by_path(p_namelist,path,p)
        return
    end if

    ! default is string:
    call json%create_string(p,str,'')
    call json%add_by_path(p_namelist,path,p)

    end subroutine add_variable