Infers the variable type and adds it to the namelist JSON structure.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p_namelist | |||
character(len=*), | intent(in) | :: | path | |||
character(len=*), | intent(in) | :: | str |
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