read_logical_column Subroutine

public subroutine read_logical_column(file_id, column, array, default, index, skip)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: file_id
character(len=*), intent(in), optional :: column
logical, intent(out), dimension(:):: array
logical, intent(in), optional :: default
integer, intent(in), optional :: index
integer, intent(in), optional :: skip

Calls

proc~~read_logical_column~~CallsGraph proc~read_logical_column read_logical_column proc~input_type_conversion_error input_type_conversion_error proc~read_logical_column->proc~input_type_conversion_error proc~move_lines move_lines proc~read_logical_column->proc~move_lines proc~log_error log_error proc~read_logical_column->proc~log_error proc~read_csv_item read_csv_item proc~read_logical_column->proc~read_csv_item proc~header_column_index header_column_index proc~read_logical_column->proc~header_column_index proc~input_error_column_not_found input_error_column_not_found proc~read_logical_column->proc~input_error_column_not_found proc~input_type_conversion_error->proc~log_error proc~log_message log_message proc~log_error->proc~log_message proc~header_column_index->proc~move_lines proc~header_column_index->proc~input_error_column_not_found proc~input_error_column_not_found->proc~log_error proc~log_write log_write proc~log_message->proc~log_write proc~log_format_message log_format_message proc~log_message->proc~log_format_message proc~to_string to_string proc~log_write->proc~to_string proc~date_time_str date_time_str proc~log_format_message->proc~date_time_str proc~colourise colourise proc~log_format_message->proc~colourise proc~string_index string_index proc~colourise->proc~string_index

Called by

proc~~read_logical_column~~CalledByGraph proc~read_logical_column read_logical_column proc~reservoir_read_control_file reservoir_read_control_file proc~reservoir_read_control_file->proc~read_logical_column proc~reservoir_initialise reservoir_initialise proc~reservoir_initialise->proc~reservoir_read_control_file proc~initialise initialise proc~initialise->proc~reservoir_initialise program~swim swim program~swim->proc~initialise

Contents

Source Code


Source Code

  subroutine read_logical_column(file_id, column, array, default, index, skip)
    ! Read column of logical 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)
    integer, intent(in) :: file_id
    character(len=*), intent(in), optional :: column
    logical, dimension(:), intent(out) :: array
    logical, intent(in), optional :: default
    integer, intent(in), optional :: index, skip
    integer i, column_ix
    character(len=read_line_buffer_size) str_value
    integer temp, ios

    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_logical_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) temp
      if (ios /= 0 .or. .not. (temp == 1 .or. temp == 0)) &
        call input_type_conversion_error(file_id, str_value, "0/1 logical", i+1, &
          column_ix)
      array(i) = temp == 1
    end do
  end subroutine read_logical_column