Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK,len=*), | intent(in) | :: | path | |||
character(kind=CK,len=*), | intent(out), | dimension(:), allocatable | :: | vec | ||
logical(kind=LK), | intent(out), | optional | :: | found |
Get a string vector from a json_file, given the path.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical(kind=LK), | public | :: | initialized |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(json_value), | intent(in), | pointer | :: | element | ||
integer(kind=IK), | intent(in) | :: | i | |||
integer(kind=IK), | intent(in) | :: | count |
subroutine json_get_string_vec_with_path(me, path, vec, found)
implicit none
type(json_value),pointer,intent(in) :: me
character(kind=CK,len=*),intent(in) :: path
character(kind=CK,len=*),dimension(:),allocatable,intent(out) :: vec
logical(LK),intent(out),optional :: found
logical(LK) :: initialized
initialized = .false.
if (allocated(vec)) deallocate(vec)
!the callback function is called for each element of the array:
call json_get(me, path=path, array_callback=get_chars_from_array, found=found)
contains
! callback function for chars
subroutine get_chars_from_array(element, i, count)
implicit none
type(json_value),pointer,intent(in) :: element
integer(IK),intent(in) :: i !index
integer(IK),intent(in) :: count !size of array
character(kind=CK,len=:),allocatable :: cval
!size the output array:
if (.not. initialized) then
allocate(vec(count))
initialized = .true.
end if
!populate the elements:
call json_get(element, value=cval)
if (allocated(cval)) then
vec(i) = cval
deallocate(cval)
else
vec(i) = ''
end if
end subroutine get_chars_from_array
end subroutine json_get_string_vec_with_path