Get an integer vector from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | me | |||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | vec |
subroutine json_get_integer_vec(json, me, vec)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer :: me
integer(IK),dimension(:),allocatable,intent(out) :: vec
logical(LK) :: initialized
! check for 0-length arrays first:
select case (me%var_type)
case (json_array)
if (json%count(me)==0) then
allocate(vec(0))
return
end if
end select
initialized = .false.
!the callback function is called for each element of the array:
call json%get(me, array_callback=get_int_from_array)
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