soa_stream_bytes Function

public pure function soa_stream_bytes(schema, n, field_kinds) result(nbytes)

Exact size in bytes of the stream a container of n elements writes.

Returns -1 when n is negative or a field kind is unknown. Useful to reserve space up front, and it lets a test pin the on-disk layout against the real file size.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: schema

The container’s schema string.

integer(kind=default_int), intent(in) :: n

Number of live elements.

integer(kind=int32), intent(in) :: field_kinds(:)

One SOA_FIELD_* code per field, in declaration order.

Return Value integer(kind=int64)


Calls

proc~~soa_stream_bytes~~CallsGraph proc~soa_stream_bytes soa_stream_bytes proc~record_bytes record_bytes proc~soa_stream_bytes->proc~record_bytes proc~soa_field_tag soa_field_tag proc~soa_stream_bytes->proc~soa_field_tag proc~element_bytes element_bytes proc~record_bytes->proc~element_bytes

Called by

proc~~soa_stream_bytes~~CalledByGraph proc~soa_stream_bytes soa_stream_bytes proc~particle_soa_serialized_bytes particle_soa_t%particle_soa_serialized_bytes proc~particle_soa_serialized_bytes->proc~soa_stream_bytes

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: i
integer(kind=int32), private :: tag

Source Code

   pure function soa_stream_bytes(schema, n, field_kinds) result(nbytes)
      !! Exact size in bytes of the stream a container of `n` elements writes.
      !!
      !! Returns -1 when `n` is negative or a field kind is unknown. Useful to
      !! reserve space up front, and it lets a test pin the on-disk layout
      !! against the real file size.
      character(len=*), intent(in) :: schema
         !! The container's schema string.
      integer(default_int), intent(in) :: n
         !! Number of live elements.
      integer(int32), intent(in) :: field_kinds(:)
         !! One `SOA_FIELD_*` code per field, in declaration order.
      integer(int64) :: nbytes

      integer(default_int) :: i
      integer(int32) :: tag

      if (n < 0) then
         nbytes = -1_int64
         return
      end if

      nbytes = PIC_HEADER_BYTES + record_bytes(PIC_TAG_CHAR, int(len(schema), int64)) &
               + record_bytes(PIC_TAG_INT64, 1_int64)

      do i = 1, size(field_kinds, kind=default_int)
         tag = soa_field_tag(field_kinds(i))
         if (tag < 0_int32) then
            nbytes = -1_int64
            return
         end if
         nbytes = nbytes + record_bytes(tag, int(n, int64))
      end do
   end function soa_stream_bytes