Read a character scalar record into a deferred length string.
Characters are single bytes so swapped never changes the payload,
but it is still needed to decode the record header itself.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=default_int), | intent(in) | :: | unit | |||
| character(len=:), | intent(out), | allocatable | :: | text | ||
| 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=default_int), | private | :: | ios | ||||
| logical, | private | :: | ok |
subroutine read_char_record(unit, text, swapped, err) !! Read a character scalar record into a deferred length string. !! !! Characters are single bytes so `swapped` never changes the payload, !! but it is still needed to decode the record header itself. integer(default_int), intent(in) :: unit character(len=:), allocatable, intent(out) :: text logical, intent(in) :: swapped type(error_t), intent(inout) :: err integer(default_int) :: ios, code logical :: ok integer(int64) :: count call read_record_header(unit, PIC_TAG_CHAR, swapped, count, ok, err) if (.not. ok) then code = err%get_code() call err%wrap(code, "failed to read character record") text = "" return end if allocate (character(len=count) :: text) if (count > 0_int64) then read (unit, iostat=ios) text call check_io(ios, "short read on character payload", err) end if end subroutine read_char_record