Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | file_id | |||
character(len=*), | intent(in), | optional | :: | column | ||
character(len=*), | intent(out), | dimension(:) | :: | array | ||
character(len=*), | intent(in), | optional | :: | default | ||
integer, | intent(in), | optional | :: | index | ||
integer, | intent(in), | optional | :: | skip |
subroutine read_string_column(file_id, column, array, default, index, skip)
! Read column of strings to fill a 1d array
!
! Optional arguments: see read_real_column
integer, intent(in) :: file_id
character(len=*), intent(in), optional :: column
character(len=*), dimension(:), intent(out) :: array
character(len=*), intent(in), optional :: default
integer, intent(in), optional :: index, skip
integer i, column_ix
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_string_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)
array(i) = read_csv_item(column_ix, file_id)
end do
end subroutine read_string_column