subroutine read_integer_column(file_id, column, array, default, index, skip, range)
! Read column of integer values to fill a 1d array
!
! Optional arguments: see read_real_column
integer, intent(in) :: file_id
character(len=*), intent(in), optional :: column
integer, dimension(:), intent(out) :: array
integer, intent(in), optional :: default, range(2)
integer, intent(in), optional :: index, skip
integer i, column_ix, ios
character(len=read_line_buffer_size) str_value
if (present(column)) then
! Find column index
column_ix = header_column_index(column, file_id)
else if (present(index)) then
column_ix = index
else
call log_error("read_integer_column", "column or index argument required.")
end if
! Skip lines after the header
if (present(skip)) call move_lines(file_id, skip)
! Set default or error if not found
if (column_ix == 0 .and. present(default)) then
array = default
return
else if (column_ix == 0) then
call input_error_column_not_found(column, file_id)
end if
! Fill array
do i = 1, size(array)
str_value = read_csv_item(column_ix, file_id)
! Accept fewer items, as newlines at the end of a csv file will break the reader
if (len(trim(adjustl(str_value))) .eq. 0) then
return
end if
read(str_value, *, iostat=ios) array(i)
if (ios /= 0) &
call input_type_conversion_error(file_id, str_value, "integer", i+1, column_ix)
end do
! Check ranges
if (present(range) .and. present(column)) then
call check_int_range(array, trim(column), range)
end if
end subroutine read_integer_column