soa_write_logical_field Subroutine

private 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.

Arguments

Type IntentOptional 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

Calls

proc~~soa_write_logical_field~~CallsGraph proc~soa_write_logical_field soa_write_logical_field interface~write_array write_array proc~soa_write_logical_field->interface~write_array proc~error_has_error error_t%error_has_error proc~soa_write_logical_field->proc~error_has_error proc~soa_check_alloc soa_check_alloc proc~soa_write_logical_field->proc~soa_check_alloc proc~soa_check_live_count soa_check_live_count proc~soa_write_logical_field->proc~soa_check_live_count proc~write_char_record write_char_record interface~write_array->proc~write_char_record proc~write_int32_array write_int32_array interface~write_array->proc~write_int32_array proc~write_int64_array write_int64_array interface~write_array->proc~write_int64_array proc~write_real_dp_array write_real_dp_array interface~write_array->proc~write_real_dp_array proc~write_real_sp_array write_real_sp_array interface~write_array->proc~write_real_sp_array interface~to_char to_char proc~soa_check_alloc->interface~to_char proc~error_set error_t%error_set proc~soa_check_alloc->proc~error_set proc~soa_check_live_count->interface~to_char proc~soa_check_live_count->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 proc~check_io check_io proc~write_char_record->proc~check_io proc~error_get_code error_t%error_get_code proc~write_char_record->proc~error_get_code proc~error_wrap error_t%error_wrap proc~write_char_record->proc~error_wrap proc~write_record_header write_record_header proc~write_char_record->proc~write_record_header proc~write_int32_array->proc~check_io proc~write_int32_array->proc~error_get_code proc~write_int32_array->proc~error_wrap proc~write_int32_array->proc~write_record_header proc~write_int64_array->proc~check_io proc~write_int64_array->proc~error_get_code proc~write_int64_array->proc~error_wrap proc~write_int64_array->proc~write_record_header proc~write_real_dp_array->proc~check_io proc~write_real_dp_array->proc~error_get_code proc~write_real_dp_array->proc~error_wrap proc~write_real_dp_array->proc~write_record_header proc~write_real_sp_array->proc~check_io proc~write_real_sp_array->proc~error_get_code proc~write_real_sp_array->proc~error_wrap proc~write_real_sp_array->proc~write_record_header proc~check_io->interface~to_char proc~check_io->proc~error_set proc~error_wrap->proc~error_has_error proc~clip_tail clip_tail proc~error_wrap->proc~clip_tail proc~write_record_header->proc~check_io

Called by

proc~~soa_write_logical_field~~CalledByGraph proc~soa_write_logical_field soa_write_logical_field interface~soa_write_field soa_write_field interface~soa_write_field->proc~soa_write_logical_field proc~particle_soa_serialize particle_soa_t%particle_soa_serialize proc~particle_soa_serialize->interface~soa_write_field

Variables

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

Source Code

   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