subroutine read_real_column(file_id, column, array, default, index, skip, range, closed)
! Read column of real values to fill a 1d array
!
! Optional arguments:
! -------------------
! column : Name of column to read
! default : Value to fill array if column not found, raises error otherwise
! index : Read column by position/index, since the header is not read
! the column is read from the current line onwards
! skip : Skip rows after header (column parsed) or current position (index)
! range(2) : Check (/lower, upper/) range, column name is required
! closed : Open or closed range, "l"/"u"/"n" lower/upper/neiter, default both
integer, intent(in) :: file_id
character(len=*), intent(in), optional :: column
real(dp), dimension(:), intent(out) :: array
real(dp), intent(in), optional :: default, range(2)
integer, intent(in), optional :: index, skip
character(len=1), intent(in), optional :: closed
integer i, column_ix, ios
character(len=read_line_buffer_size) str_value
character(len=1) clsd
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_real_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)
read(str_value, *, iostat=ios) array(i)
if (ios /= 0) &
call input_type_conversion_error(file_id, str_value, "real", i+1, column_ix)
end do
! Check ranges
if (present(range) .and. present(column)) then
clsd = "b"
if (present(closed)) clsd = closed
call check_range(array, trim(column), range, closed=clsd)
end if
end subroutine read_real_column