Read an integer(int32) array record.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=default_int), | intent(in) | :: | unit | |||
| integer(kind=int32), | intent(out), | allocatable | :: | values(:) | ||
| logical, | intent(in) | :: | swapped | |||
| type(error_t), | intent(inout) | :: | err |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| 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_int32_array(unit, values, swapped, err) !! Read an `integer(int32)` array record. integer(default_int), intent(in) :: unit integer(int32), 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 call read_record_header(unit, PIC_TAG_INT32, swapped, count, ok, err) if (.not. ok) then code = err%get_code() call err%wrap(code, "failed to read int32 record") allocate (values(0)) return end if ! The payload was already bounds checked against the size of a file that ! really exists, so this allocation is bounded by that size. allocate (values(count)) if (count > 0_int64) then read (unit, iostat=ios) values call check_io(ios, "short read on int32 payload", err) if (swapped .and. ios == 0) then do i = 1_int64, count values(i) = bswap_int32(values(i)) end do end if end if end subroutine read_int32_array