Get an integer vector from a json_value, given the path string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
character(kind=CK,len=*), | intent(in) | :: | path | |||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found |
subroutine json_get_integer_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
integer(IK),dimension(:),allocatable,intent(out) :: vec
logical(LK),intent(out),optional :: found
logical(LK) :: initialized
initialized = .false.
call json%get(me, path=path, array_callback=get_int_from_array, found=found)
! need to duplicate callback function, no other way
contains
subroutine get_int_from_array(json, element, i, count)
!! callback function for integer
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_int_from_array
end subroutine json_get_integer_vec_with_path