read_real_column Subroutine

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

Arguments

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

Calls

proc~~read_real_column~~CallsGraph proc~read_real_column read_real_column proc~input_type_conversion_error input_type_conversion_error proc~read_real_column->proc~input_type_conversion_error proc~move_lines move_lines proc~read_real_column->proc~move_lines proc~log_error log_error proc~read_real_column->proc~log_error proc~check_range check_range proc~read_real_column->proc~check_range proc~read_csv_item read_csv_item proc~read_real_column->proc~read_csv_item proc~header_column_index header_column_index proc~read_real_column->proc~header_column_index proc~input_error_column_not_found input_error_column_not_found proc~read_real_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~check_range->proc~log_error proc~log_warn log_warn proc~check_range->proc~log_warn proc~out_of_range_error out_of_range_error proc~check_range->proc~out_of_range_error 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_real_column~~CalledByGraph proc~read_real_column read_real_column proc~snow_read_input snow_read_input proc~snow_read_input->proc~read_real_column proc~reservoir_read_storage_file reservoir_read_storage_file proc~reservoir_read_storage_file->proc~read_real_column proc~crop_read_management_input crop_read_management_input proc~crop_read_management_input->proc~read_real_column proc~crop_read_input crop_read_input proc~crop_read_input->proc~read_real_column proc~evapotranspiration_read_input evapotranspiration_read_input proc~evapotranspiration_read_input->proc~read_real_column proc~river_read_input river_read_input proc~river_read_input->proc~read_real_column proc~catchment_read_subcatch_params catchment_read_subcatch_params proc~catchment_read_subcatch_params->proc~read_real_column proc~management_read_ctrl management_read_ctrl proc~management_read_ctrl->proc~read_real_column proc~subbasin_read_climate subbasin_read_climate proc~subbasin_read_climate->proc~read_real_column proc~erosion_read_input erosion_read_input proc~erosion_read_input->proc~read_real_column proc~subbasin_read_input subbasin_read_input proc~subbasin_read_input->proc~read_real_column proc~reservoir_read_control_file reservoir_read_control_file proc~reservoir_read_control_file->proc~read_real_column proc~reservoir_read_month_file reservoir_read_month_file proc~reservoir_read_month_file->proc~read_real_column proc~time_initialise_year time_initialise_year proc~time_initialise_year->proc~read_real_column proc~landuse_read_input landuse_read_input proc~landuse_read_input->proc~read_real_column proc~management_read_time_series management_read_time_series proc~management_read_time_series->proc~read_real_column proc~hydrotope_read_input hydrotope_read_input proc~hydrotope_read_input->proc~read_real_column proc~groundwater_read_input groundwater_read_input proc~groundwater_read_input->proc~read_real_column proc~erosion_initialise erosion_initialise proc~erosion_initialise->proc~erosion_read_input proc~reservoir_initialise reservoir_initialise proc~reservoir_initialise->proc~reservoir_read_storage_file proc~reservoir_initialise->proc~reservoir_read_control_file proc~reservoir_initialise->proc~reservoir_read_month_file proc~initialise initialise proc~initialise->proc~crop_read_input proc~initialise->proc~erosion_initialise proc~initialise->proc~reservoir_initialise proc~snow_initialise snow_initialise proc~initialise->proc~snow_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~groundwater_initialise groundwater_initialise proc~initialise->proc~groundwater_initialise proc~evapotranspiration_initialise evapotranspiration_initialise proc~initialise->proc~evapotranspiration_initialise proc~hydrotope_initialise hydrotope_initialise proc~initialise->proc~hydrotope_initialise proc~landuse_initialise landuse_initialise proc~initialise->proc~landuse_initialise proc~river_initialise river_initialise proc~initialise->proc~river_initialise proc~subbasin_initialise subbasin_initialise proc~initialise->proc~subbasin_initialise proc~management_initialise management_initialise proc~initialise->proc~management_initialise proc~snow_initialise->proc~snow_read_input proc~catchment_initialise_parameters->proc~catchment_read_subcatch_params proc~crop_initialise->proc~crop_read_management_input proc~groundwater_initialise->proc~groundwater_read_input proc~evapotranspiration_initialise->proc~evapotranspiration_read_input proc~management_read_wu_inout management_read_wu_inout proc~management_read_wu_inout->proc~management_read_time_series proc~time_process_years time_process_years proc~time_process_years->proc~time_initialise_year proc~time_process_month time_process_month proc~time_process_years->proc~time_process_month proc~hydrotope_initialise->proc~hydrotope_read_input proc~landuse_initialise->proc~landuse_read_input proc~river_initialise->proc~river_read_input proc~subbasin_initialise->proc~subbasin_read_input proc~time_process_day time_process_day proc~time_process_day->proc~subbasin_read_climate proc~management_initialise->proc~management_read_ctrl proc~management_initialise->proc~management_read_wu_inout proc~time_process_month->proc~time_process_day program~swim swim program~swim->proc~initialise program~swim->proc~time_process_years

Contents

Source Code


Source Code

  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