Skip to content

Commit

Permalink
fix: module and local variable name conflicts in time_interp (#1125)
Browse files Browse the repository at this point in the history
Co-authored-by: mlee03 <[email protected]>
  • Loading branch information
mlee03 and mlee03 authored Feb 1, 2023
1 parent 485d631 commit 35a5f2a
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions time_interp/time_interp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,18 @@ subroutine time_interp_frac ( Time, weight )
type(time_type), intent(in) :: Time
real , intent(out) :: weight !< fractional time

integer :: year, month, day, hour, minute, second
integer :: yr, mo, dy, hour, minute, second
type(time_type) :: Year_beg, Year_end


if ( .not. module_is_initialized ) call time_interp_init

! ---- compute fractional time of year -----

call get_date (Time, year, month, day, hour, minute, second)
call get_date (Time, yr, mo, dy, hour, minute, second)

Year_beg = set_date(year , 1, 1)
Year_end = set_date(year+1, 1, 1)
Year_beg = set_date(yr , 1, 1)
Year_end = set_date(yr+1, 1, 1)

weight = real( (Time - Year_beg) // (Year_end - Year_beg) )

Expand Down Expand Up @@ -338,27 +338,27 @@ subroutine time_interp_year ( Time, weight, year1, year2 )
real , intent(out) :: weight !< fractional time between midpoints of year1 and year2
integer , intent(out) :: year1, year2

integer :: year, month, day, hour, minute, second
integer :: yr, mo, dy, hour, minute, second
type (time_type) :: Mid_year, Mid_year1, Mid_year2


if ( .not. module_is_initialized ) call time_interp_init()

call get_date (Time, year, month, day, hour, minute, second)
call get_date (Time, yr, mo, dy, hour, minute, second)

! mid point of current year
Mid_year = year_midpt(year)
Mid_year = year_midpt(yr)

if ( Time >= Mid_year ) then
! current time is after mid point of current year
year1 = year
year2 = year+1
year1 = yr
year2 = yr+1
Mid_year2 = year_midpt(year2)
weight = real( (Time - Mid_year) // (Mid_year2 - Mid_year) )
else
! current time is before mid point of current year
year2 = year
year1 = year-1
year2 = yr
year1 = yr-1
Mid_year1 = year_midpt(year1)
weight = real( (Time - Mid_year1) // (Mid_year - Mid_year1) )
endif
Expand All @@ -381,12 +381,12 @@ subroutine time_interp_month ( Time, weight, year1, year2, month1, month2 )
real , intent(out) :: weight
integer , intent(out) :: year1, year2, month1, month2

integer :: year, month, day, hour, minute, second, &
integer :: yr, mo, dy, hour, minute, second, &
mid_month, cur_month, mid1, mid2

if ( .not. module_is_initialized ) call time_interp_init()

call get_date (Time, year, month, day, hour, minute, second)
call get_date (Time, yr, mo, dy, hour, minute, second)

! mid point of current month in seconds
mid_month = days_in_month(Time) * halfday
Expand All @@ -395,8 +395,8 @@ subroutine time_interp_month ( Time, weight, year1, year2, month1, month2 )

if ( cur_month >= mid_month ) then
! current time is after mid point of current month
year1 = year; month1 = month
year2 = year; month2 = month+1
year1 = yr; month1 = mo
year2 = yr; month2 = mo+1
if (month2 > monyear) then
year2 = year2+1; month2 = 1
endif
Expand All @@ -405,8 +405,8 @@ subroutine time_interp_month ( Time, weight, year1, year2, month1, month2 )
weight = real(cur_month - mid1) / real(mid1+mid2)
else
! current time is before mid point of current month
year2 = year; month2 = month
year1 = year; month1 = month-1
year2 = yr; month2 = mo
year1 = yr; month1 = mo-1
if (month1 < 1) then
year1 = year1-1; month1 = monyear
endif
Expand Down Expand Up @@ -442,19 +442,19 @@ subroutine time_interp_day ( Time, weight, year1, year2, month1, month2, day1, d
real , intent(out) :: weight
integer , intent(out) :: year1, year2, month1, month2, day1, day2

integer :: year, month, day, hour, minute, second, sday
integer :: yr, mo, dy, hour, minute, second, sday

if ( .not. module_is_initialized ) call time_interp_init()

call get_date (Time, year, month, day, hour, minute, second)
call get_date (Time, yr, mo, dy, hour, minute, second)

! time into current day in seconds
sday = second + secmin*minute + sechour*hour

if ( sday >= halfday ) then
! current time is after mid point of day
year1 = year; month1 = month; day1 = day
year2 = year; month2 = month; day2 = day + 1
year1 = yr; month1 = mo; day1 = dy
year2 = yr; month2 = mo; day2 = dy + 1
weight = real(sday - halfday) / real(secday)

if (day2 > days_in_month(Time)) then
Expand Down Expand Up @@ -841,34 +841,34 @@ end subroutine time_interp_list
! private routines
!#######################################################################

function year_midpt (year)
function year_midpt (yr)

integer, intent(in) :: year
integer, intent(in) :: yr
type (time_type) :: year_midpt, year_beg, year_end


year_beg = set_date(year , 1, 1)
year_end = set_date(year+1, 1, 1)
year_beg = set_date(yr , 1, 1)
year_end = set_date(yr+1, 1, 1)

year_midpt = (year_beg + year_end) / 2

end function year_midpt

!#######################################################################

function month_midpt (year, month)
function month_midpt (yr, mo)

integer, intent(in) :: year, month
integer, intent(in) :: yr, mo
type (time_type) :: month_midpt, month_beg, month_end

! --- beginning of this month ---
month_beg = set_date(year, month, 1)
month_beg = set_date(yr, mo, 1)

! --- start of next month ---
if (month < 12) then
month_end = set_date(year, month+1, 1)
if (mo < 12) then
month_end = set_date(yr, mo+1, 1)
else
month_end = set_date(year+1, 1, 1)
month_end = set_date(yr+1, 1, 1)
endif

month_midpt = (month_beg + month_end) / 2
Expand Down

0 comments on commit 35a5f2a

Please sign in to comment.