Write the first n elements of a default logical field as an
int32 record of 0/1 codes.
The envelope has no logical tag, and the storage size of a Fortran
logical is not fixed by the standard, so an explicit 0/1 encoding is
the only portable thing to put in a file.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=default_int), | intent(in) | :: | unit | |||
| logical, | intent(in), | allocatable | :: | values(:) | ||
| integer(kind=default_int), | intent(in) | :: | n | |||
| type(error_t), | intent(inout) | :: | err |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=int32), | private, | allocatable | :: | coded(:) | |||
| integer(kind=default_int), | private | :: | i | ||||
| integer(kind=default_int), | private | :: | nalloc | ||||
| integer(kind=default_int), | private | :: | stat |
subroutine soa_write_logical_field(unit, values, n, err) !! Write the first `n` elements of a default `logical` field as an !! `int32` record of 0/1 codes. !! !! The envelope has no logical tag, and the storage size of a Fortran !! `logical` is not fixed by the standard, so an explicit 0/1 encoding is !! the only portable thing to put in a file. integer(default_int), intent(in) :: unit logical, allocatable, intent(in) :: values(:) integer(default_int), intent(in) :: n type(error_t), intent(inout) :: err integer(int32), allocatable :: coded(:) integer(default_int) :: i, nalloc, stat nalloc = -1 if (allocated(values)) nalloc = size(values, kind=default_int) call soa_check_live_count(n, nalloc, err) if (err%has_error()) return allocate (coded(max(n, 0_default_int)), stat=stat) call soa_check_alloc(stat, "encoding a logical field", err) if (err%has_error()) return do i = 1, n if (values(i)) then coded(i) = 1_int32 else coded(i) = 0_int32 end if end do call write_array(unit, coded, err) end subroutine soa_write_logical_field