json_get_double_vec Subroutine

private subroutine json_get_double_vec(json, me, vec)

Get a double vector from a json_value.


Type IntentOptional AttributesName
class(json_core), intent(inout) :: json
type(json_value), pointer:: me
real(kind=RK), intent(out), dimension(:), allocatable:: vec


Source Code

Source Code

    subroutine json_get_double_vec(json, me, vec)

    implicit none

    class(json_core),intent(inout)                :: json
    type(json_value),pointer                      :: me
    real(RK),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
        end if
    end select

    initialized = .false.

    !the callback function is called for each element of the array:
    call json%get(me, array_callback=get_double_from_array)


        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
            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