soa_read_prologue Subroutine

public subroutine soa_read_prologue(unit, schema, n, swapped, err)

Read and validate the prologue, returning the element count.

Fails with ERROR_VALIDATION when the schema in the stream is not exactly schema, naming both, and when the element count record is malformed or does not fit this build’s default_int. The envelope itself – magic, byte order, version – is validated by pic_serialize.

Arguments

Type IntentOptional Attributes Name
integer(kind=default_int), intent(in) :: unit

Stream unit opened for unformatted stream reading.

character(len=*), intent(in) :: schema

Schema the calling container expects.

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

Number of elements the stream holds, 0 when the prologue is rejected.

logical, intent(out) :: swapped

True when the stream came from the opposite byte order; pass it on to every soa_read_field call.

type(error_t), intent(inout) :: err

Error state.


Calls

proc~~soa_read_prologue~~CallsGraph proc~soa_read_prologue soa_read_prologue interface~read_array read_array proc~soa_read_prologue->interface~read_array interface~to_char to_char proc~soa_read_prologue->interface~to_char proc~error_has_error error_t%error_has_error proc~soa_read_prologue->proc~error_has_error proc~error_set error_t%error_set proc~soa_read_prologue->proc~error_set proc~read_header read_header proc~soa_read_prologue->proc~read_header proc~read_char_record read_char_record interface~read_array->proc~read_char_record proc~read_int32_array read_int32_array interface~read_array->proc~read_int32_array proc~read_int64_array read_int64_array interface~read_array->proc~read_int64_array proc~read_real_dp_array read_real_dp_array interface~read_array->proc~read_real_dp_array proc~read_real_sp_array read_real_sp_array interface~read_array->proc~read_real_sp_array proc~to_char_char to_char_char interface~to_char->proc~to_char_char proc~to_char_dp to_char_dp interface~to_char->proc~to_char_dp proc~to_char_int32 to_char_int32 interface~to_char->proc~to_char_int32 proc~to_char_int64 to_char_int64 interface~to_char->proc~to_char_int64 proc~to_char_logical to_char_logical interface~to_char->proc~to_char_logical proc~to_char_matrix_dp to_char_matrix_dp interface~to_char->proc~to_char_matrix_dp proc~to_char_matrix_int32 to_char_matrix_int32 interface~to_char->proc~to_char_matrix_int32 proc~to_char_matrix_int64 to_char_matrix_int64 interface~to_char->proc~to_char_matrix_int64 proc~to_char_matrix_sp to_char_matrix_sp interface~to_char->proc~to_char_matrix_sp proc~to_char_sp to_char_sp interface~to_char->proc~to_char_sp proc~to_char_vector_dp to_char_vector_dp interface~to_char->proc~to_char_vector_dp proc~to_char_vector_int32 to_char_vector_int32 interface~to_char->proc~to_char_vector_int32 proc~to_char_vector_int64 to_char_vector_int64 interface~to_char->proc~to_char_vector_int64 proc~to_char_vector_sp to_char_vector_sp interface~to_char->proc~to_char_vector_sp proc~read_header->interface~to_char proc~read_header->proc~error_set proc~bswap_int32 bswap_int32 proc~read_header->proc~bswap_int32 proc~check_io check_io proc~read_header->proc~check_io proc~check_io->interface~to_char proc~check_io->proc~error_set proc~read_char_record->proc~check_io proc~error_get_code error_t%error_get_code proc~read_char_record->proc~error_get_code proc~error_wrap error_t%error_wrap proc~read_char_record->proc~error_wrap proc~read_record_header read_record_header proc~read_char_record->proc~read_record_header proc~read_int32_array->proc~bswap_int32 proc~read_int32_array->proc~check_io proc~read_int32_array->proc~error_get_code proc~read_int32_array->proc~error_wrap proc~read_int32_array->proc~read_record_header proc~read_int64_array->proc~check_io proc~bswap_int64 bswap_int64 proc~read_int64_array->proc~bswap_int64 proc~read_int64_array->proc~error_get_code proc~read_int64_array->proc~error_wrap proc~read_int64_array->proc~read_record_header proc~read_real_dp_array->proc~check_io proc~bits_to_real_dp bits_to_real_dp proc~read_real_dp_array->proc~bits_to_real_dp proc~read_real_dp_array->proc~bswap_int64 proc~read_real_dp_array->proc~error_get_code proc~read_real_dp_array->proc~error_wrap proc~read_real_dp_array->proc~read_record_header proc~read_real_sp_array->proc~bswap_int32 proc~read_real_sp_array->proc~check_io proc~bits_to_real_sp bits_to_real_sp proc~read_real_sp_array->proc~bits_to_real_sp proc~read_real_sp_array->proc~error_get_code proc~read_real_sp_array->proc~error_wrap proc~read_real_sp_array->proc~read_record_header proc~error_wrap->proc~error_has_error proc~clip_tail clip_tail proc~error_wrap->proc~clip_tail proc~read_record_header->interface~to_char proc~read_record_header->proc~error_set proc~read_record_header->proc~bswap_int32 proc~read_record_header->proc~check_io proc~read_record_header->proc~bswap_int64 proc~element_bytes element_bytes proc~read_record_header->proc~element_bytes

Called by

proc~~soa_read_prologue~~CalledByGraph proc~soa_read_prologue soa_read_prologue proc~particle_soa_deserialize particle_soa_t%particle_soa_deserialize proc~particle_soa_deserialize->proc~soa_read_prologue

Variables

Type Visibility Attributes Name Initial
integer(kind=int64), private, allocatable :: counts(:)
character(len=:), private, allocatable :: found
integer(kind=int32), private :: version

Source Code

   subroutine soa_read_prologue(unit, schema, n, swapped, err)
      !! Read and validate the prologue, returning the element count.
      !!
      !! Fails with `ERROR_VALIDATION` when the schema in the stream is not
      !! exactly `schema`, naming both, and when the element count record is
      !! malformed or does not fit this build's `default_int`. The envelope
      !! itself -- magic, byte order, version -- is validated by
      !! `pic_serialize`.
      integer(default_int), intent(in) :: unit
         !! Stream unit opened for unformatted stream reading.
      character(len=*), intent(in) :: schema
         !! Schema the calling container expects.
      integer(default_int), intent(out) :: n
         !! Number of elements the stream holds, 0 when the prologue is
         !! rejected.
      logical, intent(out) :: swapped
         !! True when the stream came from the opposite byte order; pass it on
         !! to every `soa_read_field` call.
      type(error_t), intent(inout) :: err
         !! Error state.

      integer(int32) :: version
      character(len=:), allocatable :: found
      integer(int64), allocatable :: counts(:)

      n = 0
      swapped = .false.

      call read_header(unit, version, swapped, err)
      if (err%has_error()) return

      call read_array(unit, found, swapped, err)
      if (err%has_error()) return

      ! Length is compared as well as content because Fortran character
      ! comparison blank-pads the shorter operand, which would let a schema
      ! with trailing blanks masquerade as this one.
      if (len(found) /= len(schema) .or. found /= schema) then
         call err%set(ERROR_VALIDATION, "soa layout mismatch: stream declares '"//found// &
                      "', this container is '"//schema//"'")
         return
      end if

      call read_array(unit, counts, swapped, err)
      if (err%has_error()) return

      if (size(counts, kind=default_int) /= 1) then
         call err%set(ERROR_VALIDATION, "soa: element count record holds "// &
                      to_char(int(size(counts, kind=default_int), int64))//" values, expected 1")
         return
      end if
      if (counts(1) < 0_int64 .or. counts(1) > int(huge(0_default_int), int64)) then
         call err%set(ERROR_VALIDATION, "soa: element count "//to_char(counts(1))// &
                      " is out of range for this build")
         return
      end if

      n = int(counts(1), default_int)
   end subroutine soa_read_prologue