check_range Subroutine

public subroutine check_range(values, name, range, index, closed)

Arguments

Type IntentOptional AttributesName
real(kind=dp), intent(in) :: values(:)
character, intent(in) :: name
real(kind=dp), intent(in) :: range(2)
integer, intent(in), optional :: index
character(len=1), intent(in), optional :: closed

Calls

proc~~check_range~~CallsGraph proc~check_range check_range 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~log_error log_error proc~check_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_range~~CalledByGraph proc~check_range check_range proc~input_nc_read_grid input_nc_read_grid proc~input_nc_read_grid->proc~check_range proc~soil_read_input soil_read_input proc~soil_read_input->proc~check_range proc~read_real_column read_real_column proc~read_real_column->proc~check_range 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~evapotranspiration_read_input evapotranspiration_read_input proc~evapotranspiration_read_input->proc~read_real_column proc~management_read_ctrl management_read_ctrl proc~management_read_ctrl->proc~read_real_column proc~groundwater_read_input groundwater_read_input proc~groundwater_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~soil_initialise soil_initialise proc~soil_initialise->proc~soil_read_input proc~river_read_input river_read_input proc~river_read_input->proc~read_real_column proc~reservoir_read_month_file reservoir_read_month_file proc~reservoir_read_month_file->proc~read_real_column proc~subbasin_read_climate subbasin_read_climate proc~subbasin_read_climate->proc~read_real_column proc~input_nc_initialise input_nc_initialise proc~input_nc_initialise->proc~input_nc_read_grid 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~subbasin_read_input subbasin_read_input proc~subbasin_read_input->proc~read_real_column proc~landuse_read_input landuse_read_input proc~landuse_read_input->proc~read_real_column proc~hydrotope_read_input hydrotope_read_input proc~hydrotope_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~erosion_read_input erosion_read_input proc~erosion_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~time_initialise_year time_initialise_year proc~time_initialise_year->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_month_file proc~reservoir_initialise->proc~reservoir_read_control_file proc~initialise initialise proc~initialise->proc~soil_initialise proc~initialise->proc~input_nc_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~landuse_initialise landuse_initialise proc~initialise->proc~landuse_initialise proc~crop_initialise crop_initialise proc~initialise->proc~crop_initialise proc~evapotranspiration_initialise evapotranspiration_initialise proc~initialise->proc~evapotranspiration_initialise proc~hydrotope_initialise hydrotope_initialise proc~initialise->proc~hydrotope_initialise proc~groundwater_initialise groundwater_initialise proc~initialise->proc~groundwater_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~landuse_initialise->proc~landuse_read_input proc~crop_initialise->proc~crop_read_management_input proc~evapotranspiration_initialise->proc~evapotranspiration_read_input proc~hydrotope_initialise->proc~hydrotope_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~groundwater_initialise->proc~groundwater_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 check_range(values, name, range, index, closed)
    ! Check if the real 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.
    ! The closed optional argument specifies the inclusion/exclusion of the bounds:
    ! closed="l"/"u"/"n" means lower/upper/neither is included, default is both.
    ! Examples:
    !  call check_range((/1., 2., 3./), "array", (/0., 2./))
    !  call check_range((/2./), "val", (/0., 2./), closed="n")
    !  call check_range((/3./), "array", (/0., 2./), index=100)
    real(dp), intent(in) :: values(:)
    character(*), intent(in) :: name
    real(dp), intent(in) :: range(2)
    integer, intent(in), optional :: index
    character(len=1), intent(in), optional :: closed

    integer i, nv, counter
    real(dp) va
    logical clsd(2)

    if (range(1) >= range(2)) &
      call log_error("check_range", "range is not (/lower, upper/) values", reals=range)
    clsd = .True.
    if (present(closed)) then
      if (closed == "n") clsd = .False.
      if (closed == "l") clsd(2) = .False.
      if (closed == "u") clsd(1) = .False.
    end if
    counter = 0
    nv = size(values)
    do i = 1, nv
      va = values(i)
      ! check range depending on range closure
      if ((clsd(1) .and. va < range(1)) .or. (.not.clsd(1) .and. va <= range(1)) .or. &
          (clsd(2) .and. va > range(2)) .or. (.not.clsd(2) .and. va >= range(2))) then
          if (nv > 1) &
            call log_warn('check_range', name, i1=i, real=va)
          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, range, counter=counter)
    ! Single value with index
    if (counter == 1 .and. present(index)) &
      call out_of_range_error(name, range, va, index=index)
    ! Single value without index
    if (counter == 1) call out_of_range_error(name, range, values(1))
  end subroutine check_range