input_nc_find_time Subroutine

public subroutine input_nc_find_time(iyr)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: iyr

Calls

proc~~input_nc_find_time~~CallsGraph proc~input_nc_find_time input_nc_find_time proc~log_debug log_debug proc~input_nc_find_time->proc~log_debug proc~log_error log_error proc~input_nc_find_time->proc~log_error proc~log_message log_message proc~log_debug->proc~log_message 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~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~~input_nc_find_time~~CalledByGraph proc~input_nc_find_time input_nc_find_time proc~input_nc_initialise input_nc_initialise proc~input_nc_initialise->proc~input_nc_find_time proc~initialise initialise proc~initialise->proc~input_nc_initialise program~swim swim program~swim->proc~initialise

Contents

Source Code


Source Code

  subroutine input_nc_find_time(iyr)
    integer, intent(in) :: iyr
    integer ndays_offset, y, d
    logical :: time_not_found = .true.

    ! should be replaced by common switch from cod - file
    integer :: ileap = 1

    ndays_offset = (iyr - NC_REF_YEAR) * 365 + NC_OFFSET_DAYS
    ! add leap years
    if (ileap == 1) then
      do y = NC_REF_YEAR, iyr - 1
        if ((MOD(y, 4) == 0 .AND. MOD(y, 100) > 0) .OR. MOD(y, 400) == 0) then
          ndays_offset = ndays_offset + 1
        endif
      enddo
    endif

    if (NC_DEBUG) call log_debug("input_nc_find_time", &
      'Searching for netCDF time index', int=ndays_offset)
    do d = 1, nc_nrecs
      if (ndays_offset == nc_time_ix(d)) then
        nc_nday = d
        time_not_found = .false.
        if (NC_DEBUG) call log_debug("input_nc_find_time", 'Found time index at', int=d)
        exit ! break from do loop
      endif
    enddo
    ! stop if time index not found
    if (time_not_found) then
      call log_error("input_nc_find_time", &
        'Cant find time index in climate netCDF file (start, ref. year):', i1=iyr, &
        i2=NC_REF_YEAR, int=ndays_offset)
    endif
  end subroutine input_nc_find_time