This routine obtains a vectorial quantity with variable length from a Lua table as a whole.
It is intented to ease the reading of vectors on the Fortran side by capsulating the parsing of the Lua table internally. For the dynamically sized array, which will be allocated, a upper limit to allocate has to be specified.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=quad_k), | intent(out), | allocatable | :: | val(:) | Vector read from the Lua table, will have the same length as the table but not exceed maxlength, if provided. |
|
integer, | intent(out), | allocatable | :: | ErrCode(:) | Error code describing problems encountered in each of the components. Will be allocated with the same length as the returned vector. If the complete vector is not given in the Lua script, and no default is provided, an zerosized array will be returned. |
|
integer, | intent(in) | :: | maxlength | Maximal length to allocate for the vector. |
||
type(flu_State) | :: | L | ||||
integer, | intent(in), | optional | :: | thandle | ||
character(len=*), | intent(in), | optional | :: | key | Name of the variable (vector) to read. |
|
integer, | intent(in), | optional | :: | pos | Position of the (vector) to read. |
|
real(kind=quad_k), | intent(in), | optional | :: | default(:) | A default vector to use, if no proper definition is found. Components will be filled with the help of this default definition. |
subroutine get_table_quadruple_vvect(val, ErrCode, maxlength, L, thandle, &
& key, pos, default)
type(flu_State) :: L !< Handle to the lua script
integer, intent(in), optional :: thandle !< Handle of the parent table
!> Vector read from the Lua table, will have the same length as the table
!! but not exceed maxlength, if provided.
real(kind=quad_k), intent(out), allocatable :: val(:)
!> Error code describing problems encountered in each of the components.
!! Will be allocated with the same length as the returned vector.
!! If the complete vector is not given in the Lua script, and no default
!! is provided, an zerosized array will be returned.
integer, intent(out), allocatable :: ErrCode(:)
!> Maximal length to allocate for the vector.
integer, intent(in) :: maxlength
!> Name of the variable (vector) to read.
character(len=*), intent(in), optional :: key
!> Position of the (vector) to read.
integer, intent(in), optional :: pos
!> A default vector to use, if no proper definition is found.
!! Components will be filled with the help of this default definition.
real(kind=quad_k), intent(in), optional :: default(:)
logical :: valid_args
integer :: toptype
valid_args = .true.
if (present(thandle)) then
! Get the requested value from the provided table
call aot_table_push(L=L, thandle=thandle, &
& key=key, pos=pos)
else
if (present(key)) then
! Get the requeseted global variable
toptype = flu_getglobal(L, key)
else
valid_args = .false.
end if
end if
if (valid_args) then
call aot_top_get_val(val, ErrCode, maxlength, L, default)
else
! In case of invalid arguments return 0-sized arrays.
! (Equivalent of not found Lua tables.)
allocate(Val(0))
allocate(ErrCode(0))
end if
end subroutine get_table_quadruple_vvect