get_int_array_in_struct Subroutine

private subroutine get_int_array_in_struct(this, path, subpath, array)

Arguments

Type IntentOptional AttributesName
type(fson_value), pointer:: this
character(len=*) :: path
character(len=*) :: subpath
integer, intent(out), dimension(:):: array

Contents


Source Code

  subroutine get_int_array_in_struct(this, path, subpath, array)
    use fson_value_m, only: fson_value_count, fson_value_get, fson_value, &
      TYPE_ARRAY
    implicit none

    type(fson_value), pointer :: this, p, element
    character(len=*) :: path, subpath
    integer, dimension(:), intent(out) :: array
    integer :: index, count

    nullify(p)

    ! resolve the path to the value
    call get_by_path(this=this, path=path, p=p)

    if (.not.associated(p)) then
       print *, "Unable to resolve path: ", path
       call exit(1)
    end if

    if (p % value_type == TYPE_ARRAY) then
       count = fson_value_count(p)
       do index = 1, count
          element => fson_value_get(p, index)
          call get_integer(element, subpath, array(index))
       end do
    else
       print *, "Resolved value is not an array. ", path
       call exit(1)
    end if

  end subroutine get_int_array_in_struct