read_integer_column Subroutine

public subroutine read_integer_column(file_id, column, array, default, index, skip, range)

Arguments

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

Calls

proc~~read_integer_column~~CallsGraph proc~read_integer_column read_integer_column proc~input_type_conversion_error input_type_conversion_error proc~read_integer_column->proc~input_type_conversion_error proc~move_lines move_lines proc~read_integer_column->proc~move_lines proc~check_int_range check_int_range proc~read_integer_column->proc~check_int_range proc~log_error log_error proc~read_integer_column->proc~log_error proc~read_csv_item read_csv_item proc~read_integer_column->proc~read_csv_item proc~header_column_index header_column_index proc~read_integer_column->proc~header_column_index proc~input_error_column_not_found input_error_column_not_found proc~read_integer_column->proc~input_error_column_not_found proc~input_type_conversion_error->proc~log_error proc~check_int_range->proc~log_error proc~log_warn log_warn proc~check_int_range->proc~log_warn proc~out_of_range_error out_of_range_error proc~check_int_range->proc~out_of_range_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_warn->proc~log_message proc~out_of_range_error->proc~log_error proc~to_string to_string proc~out_of_range_error->proc~to_string 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~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_integer_column~~CalledByGraph proc~read_integer_column read_integer_column proc~crop_read_management_input crop_read_management_input proc~crop_read_management_input->proc~read_integer_column proc~crop_read_input crop_read_input proc~crop_read_input->proc~read_integer_column proc~catchment_read_subcatch_params catchment_read_subcatch_params proc~catchment_read_subcatch_params->proc~read_integer_column proc~management_read_ctrl management_read_ctrl proc~management_read_ctrl->proc~read_integer_column proc~reservoir_read_control_file reservoir_read_control_file proc~reservoir_read_control_file->proc~read_integer_column proc~subbasin_read_routing subbasin_read_routing proc~subbasin_read_routing->proc~read_integer_column proc~subbasin_read_input subbasin_read_input proc~subbasin_read_input->proc~read_integer_column proc~landuse_read_input landuse_read_input proc~landuse_read_input->proc~read_integer_column proc~hydrotope_read_input hydrotope_read_input proc~hydrotope_read_input->proc~read_integer_column proc~reservoir_initialise reservoir_initialise proc~reservoir_initialise->proc~reservoir_read_control_file proc~initialise initialise proc~initialise->proc~crop_read_input proc~initialise->proc~reservoir_initialise proc~catchment_initialise_parameters catchment_initialise_parameters proc~initialise->proc~catchment_initialise_parameters proc~crop_initialise crop_initialise proc~initialise->proc~crop_initialise proc~hydrotope_initialise hydrotope_initialise proc~initialise->proc~hydrotope_initialise proc~landuse_initialise landuse_initialise proc~initialise->proc~landuse_initialise proc~subbasin_initialise subbasin_initialise proc~initialise->proc~subbasin_initialise proc~management_initialise management_initialise proc~initialise->proc~management_initialise proc~catchment_initialise_parameters->proc~catchment_read_subcatch_params proc~crop_initialise->proc~crop_read_management_input proc~hydrotope_initialise->proc~hydrotope_read_input proc~landuse_initialise->proc~landuse_read_input proc~subbasin_initialise->proc~subbasin_read_routing proc~subbasin_initialise->proc~subbasin_read_input proc~management_initialise->proc~management_read_ctrl program~swim swim program~swim->proc~initialise

Contents

Source Code


Source Code

  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