Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | iyr |
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