Verify that n live elements really exist in a field array.
Pass allocated_size = -1 for a field that is not allocated at all,
which is only consistent with n == 0; a container that has never
been allocated is in exactly that state and must still be
serializable.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=default_int), | intent(in) | :: | n |
Number of live elements the container claims to have. |
||
| integer(kind=default_int), | intent(in) | :: | allocated_size |
Allocated length of the field array, or -1 if it is unallocated. |
||
| type(error_t), | intent(inout) | :: | err |
Error state, |
subroutine soa_check_live_count(n, allocated_size, err) !! Verify that `n` live elements really exist in a field array. !! !! Pass `allocated_size = -1` for a field that is not allocated at all, !! which is only consistent with `n == 0`; a container that has never !! been allocated is in exactly that state and must still be !! serializable. integer(default_int), intent(in) :: n !! Number of live elements the container claims to have. integer(default_int), intent(in) :: allocated_size !! Allocated length of the field array, or -1 if it is unallocated. type(error_t), intent(inout) :: err !! Error state, `ERROR_VALIDATION` when the claim cannot hold. if (n < 0) then call err%set(ERROR_VALIDATION, "soa: live element count "//to_char(int(n, int64))// & " is negative") return end if if (allocated_size < 0) then if (n > 0) then call err%set(ERROR_VALIDATION, "soa: "//to_char(int(n, int64))// & " live elements requested from an unallocated field") end if return end if if (n > allocated_size) then call err%set(ERROR_VALIDATION, "soa: "//to_char(int(n, int64))// & " live elements requested from a field holding "// & to_char(int(allocated_size, int64))) end if end subroutine soa_check_live_count