check_int_range Subroutine

public subroutine check_int_range(values, name, range, index)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: values(:)
character, intent(in) :: name
integer, intent(in) :: range(2)
integer, intent(in), optional :: index

Calls

proc~~check_int_range~~CallsGraph proc~check_int_range check_int_range 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_error log_error proc~check_int_range->proc~log_error proc~log_message log_message 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_error->proc~log_message 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~~check_int_range~~CalledByGraph proc~check_int_range check_int_range proc~read_integer_column read_integer_column proc~read_integer_column->proc~check_int_range 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 check_int_range(values, name, range, index)
    ! Check if the integer array values is within (/lower, upper/) range and terminate
    ! with name if not. values must be a 1D array but a single
    ! value can also be checked by passing (/value/) and an optional index to report.
    ! Examples:
    !  call check_int_range((/1, 2, 3/), "array", (/0, 2/))
    !  call check_int_range((/3/), "val", (/0, 2/))
    !  call check_int_range((/3/), "array", (/0, 2/), index=100)
    integer, intent(in) :: values(:)
    character(*), intent(in) :: name
    integer, intent(in) :: range(2)
    integer, intent(in), optional :: index

    integer i, nv, counter

    if (range(1) >= range(2)) &
      call log_error("check_int_range", "range is not (/lower, upper/) values", &
        ints=range)
    counter = 0
    nv = size(values)
    do i = 1, nv
      if (values(i) < range(1) .or. values(i) > range(2)) then
          ! Only print value if not single cell array
          if (nv > 1) call log_warn('check_int_range', name, i1=i, int=values(i))
          counter = counter + 1
      endif
    end do
    ! Array with counted out of range values, indeces reported above
    if (counter > 0 .and. nv > 1) call out_of_range_error(name, int_range=range, counter=counter)
    ! Single value with index
    if (counter == 1 .and. present(index)) &
      call out_of_range_error(name, int_range=range, int_value=values(1), index=index)
    ! Single value without index
    if (counter == 1) call out_of_range_error(name, int_range=range, int_value=values(1))
  end subroutine check_int_range