Get a double vector from a json_value, given the path.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
character(kind=CK,len=*), | intent(in) | :: | path | |||
real(kind=RK), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found |
subroutine json_get_double_vec_with_path(json, me, path, vec, found)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer :: me
character(kind=CK,len=*),intent(in) :: path
real(RK),dimension(:),allocatable,intent(out) :: vec
logical(LK),intent(out),optional :: found
logical(LK) :: initialized
initialized = .false.
!the callback function is called for each element of the array:
call json%get(me, path=path, array_callback=get_double_from_array, found=found)
contains
subroutine get_double_from_array(json, element, i, count)
!! callback function for double
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer,intent(in) :: element
integer(IK),intent(in) :: i !! index
integer(IK),intent(in) :: count !! size of array
!size the output array:
if (.not. initialized) then
allocate(vec(count))
initialized = .true.
end if
!populate the elements:
call json%get(element, value=vec(i))
end subroutine get_double_from_array
end subroutine json_get_double_vec_with_path