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.
| Type | Intent | Optional | 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 |
| 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 |
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