read_real_sp_array Subroutine

private subroutine read_real_sp_array(unit, values, swapped, err)

Read a real(sp) array record.

On the native path the values are read straight into values. On the foreign endian path the same bytes are read into an int32 buffer, reversed with integer arithmetic, and only then reinterpreted.

Arguments

Type IntentOptional Attributes Name
integer(kind=default_int), intent(in) :: unit
real(kind=sp), intent(out), allocatable :: values(:)
logical, intent(in) :: swapped
type(error_t), intent(inout) :: err

Calls

proc~~read_real_sp_array~~CallsGraph proc~read_real_sp_array read_real_sp_array proc~bits_to_real_sp bits_to_real_sp proc~read_real_sp_array->proc~bits_to_real_sp proc~bswap_int32 bswap_int32 proc~read_real_sp_array->proc~bswap_int32 proc~check_io check_io proc~read_real_sp_array->proc~check_io proc~error_get_code error_t%error_get_code proc~read_real_sp_array->proc~error_get_code proc~error_wrap error_t%error_wrap proc~read_real_sp_array->proc~error_wrap proc~read_record_header read_record_header proc~read_real_sp_array->proc~read_record_header interface~to_char to_char proc~check_io->interface~to_char proc~error_set error_t%error_set proc~check_io->proc~error_set proc~clip_tail clip_tail proc~error_wrap->proc~clip_tail proc~error_has_error error_t%error_has_error proc~error_wrap->proc~error_has_error proc~read_record_header->proc~bswap_int32 proc~read_record_header->proc~check_io proc~read_record_header->interface~to_char proc~bswap_int64 bswap_int64 proc~read_record_header->proc~bswap_int64 proc~element_bytes element_bytes proc~read_record_header->proc~element_bytes proc~read_record_header->proc~error_set 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

Called by

proc~~read_real_sp_array~~CalledByGraph proc~read_real_sp_array read_real_sp_array interface~read_array read_array interface~read_array->proc~read_real_sp_array proc~soa_read_int32_field soa_read_int32_field proc~soa_read_int32_field->interface~read_array proc~soa_read_int64_field soa_read_int64_field proc~soa_read_int64_field->interface~read_array proc~soa_read_logical_field soa_read_logical_field proc~soa_read_logical_field->interface~read_array proc~soa_read_prologue soa_read_prologue proc~soa_read_prologue->interface~read_array proc~soa_read_real_dp_field soa_read_real_dp_field proc~soa_read_real_dp_field->interface~read_array proc~soa_read_real_sp_field soa_read_real_sp_field proc~soa_read_real_sp_field->interface~read_array interface~soa_read_field soa_read_field interface~soa_read_field->proc~soa_read_int32_field interface~soa_read_field->proc~soa_read_int64_field interface~soa_read_field->proc~soa_read_logical_field interface~soa_read_field->proc~soa_read_real_dp_field interface~soa_read_field->proc~soa_read_real_sp_field proc~particle_soa_deserialize particle_soa_t%particle_soa_deserialize proc~particle_soa_deserialize->proc~soa_read_prologue proc~particle_soa_deserialize->interface~soa_read_field

Variables

Type Visibility Attributes Name Initial
integer(kind=int32), private, allocatable :: bits(:)
integer(kind=default_int), private :: code
integer(kind=int64), private :: count
integer(kind=int64), private :: i
integer(kind=default_int), private :: ios
logical, private :: ok

Source Code

   subroutine read_real_sp_array(unit, values, swapped, err)
      !! Read a `real(sp)` array record.
      !!
      !! On the native path the values are read straight into `values`. On the
      !! foreign endian path the same bytes are read into an `int32` buffer,
      !! reversed with integer arithmetic, and only then reinterpreted.
      integer(default_int), intent(in) :: unit
      real(sp), allocatable, intent(out) :: values(:)
      logical, intent(in) :: swapped
      type(error_t), intent(inout) :: err

      integer(default_int) :: ios, code
      logical :: ok
      integer(int64) :: count, i
      integer(int32), allocatable :: bits(:)

      call read_record_header(unit, PIC_TAG_REAL_SP, swapped, count, ok, err)
      if (.not. ok) then
         code = err%get_code()
         call err%wrap(code, "failed to read real(sp) record")
         allocate (values(0))
         return
      end if

      allocate (values(count))
      if (count > 0_int64) then
         if (swapped) then
            allocate (bits(count))
            read (unit, iostat=ios) bits
         else
            read (unit, iostat=ios) values
         end if
         call check_io(ios, "short read on real(sp) payload", err)
         if (swapped .and. ios == 0) then
            do i = 1_int64, count
               values(i) = bits_to_real_sp(bswap_int32(bits(i)))
            end do
         end if
      end if
   end subroutine read_real_sp_array