Skip to content

Commit

Permalink
Cleaning up code for local time avgflag
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronny Meier committed May 26, 2021
1 parent 483eda7 commit 4ec41d4
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions src/main/histFileMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1480,18 +1480,14 @@ subroutine hist_update_hbuf_field_1d (t, f, bounds)
read(avgflag(2:6), *) tod
do k = beg1d_out, end1d_out
if (field_gcell(k) /= spval) then

local_secpl = secs + grc%londeg(k)/degpsec
local_secpl = mod(local_secpl,isecspday)

weight = calc_weight_local_time(local_secpl, tod)

if (weight > 0) then
if (nacs(k,1) == 0) hbuf(k,1) = 0._r8
hbuf(k,1) = hbuf(k,1) + field_gcell(k)*real(weight)
nacs(k,1) = nacs(k,1) + weight
end if

else
if (nacs(k,1) == 0) hbuf(k,1) = spval
end if
Expand Down Expand Up @@ -1605,9 +1601,7 @@ subroutine hist_update_hbuf_field_1d (t, f, bounds)
nacs(k,1) = 1
end do
case ('L') ! Local solar time

read(avgflag(2:6), *) tod

if ( end1d .eq. ubound(field,1) ) then
k_offset = 0
else
Expand All @@ -1623,10 +1617,8 @@ subroutine hist_update_hbuf_field_1d (t, f, bounds)
end if
else
local_secpl = secs + grc%londeg(k)/degpsec

end if
local_secpl = mod(local_secpl,isecspday)

if (valid) then
weight = calc_weight_local_time(local_secpl, tod)
if (weight > 0 .and. field(k+k_offset) /= spval) then
Expand Down Expand Up @@ -1886,21 +1878,16 @@ subroutine hist_update_hbuf_field_2d (t, f, bounds, num2d)
do j = 1,num2d
do k = beg1d_out, end1d_out
if (field_gcell(k,j) /= spval) then

local_secpl = secs + grc%londeg(k)/degpsec
local_secpl = mod(local_secpl,isecspday)

weight = calc_weight_local_time(local_secpl, tod)

if (weight > 0) then
if (nacs(k,j) == 0) hbuf(k,j) = 0._r8
hbuf(k,j) = hbuf(k,j) + field_gcell(k,j)*real(weight)
nacs(k,j) = nacs(k,j) + weight
end if

else
if (nacs(k,j) == 0) hbuf(k,j) = spval

end if
end do
end do
Expand Down Expand Up @@ -2020,7 +2007,6 @@ subroutine hist_update_hbuf_field_2d (t, f, bounds, num2d)
case ('L') ! Local solar time
read(avgflag(2:6), *) tod
do j = 1,num2d

do k = beg1d, end1d
valid = .true.
if (check_active) then
Expand All @@ -2033,7 +2019,6 @@ subroutine hist_update_hbuf_field_2d (t, f, bounds, num2d)
local_secpl = secs + grc%londeg(k)/degpsec
end if
local_secpl = mod(local_secpl,isecspday)

if (valid) then
weight = calc_weight_local_time(local_secpl, tod)

Expand Down Expand Up @@ -2071,15 +2056,15 @@ function calc_weight_local_time(local_secpl, tod) result(weight)
use clm_time_manager, only : get_step_size
!
! !ARGUMENTS:
integer :: weight ! function result
integer :: weight ! function result
integer, intent(inout) :: local_secpl ! seconds into current date in local time
integer, intent(in) :: tod ! Desired local solar time of output in seconds
integer, intent(in) :: tod ! Desired local solar time of output in seconds

!
! !LOCAL VARIABLES:

character(len=*), parameter :: subname = 'calc_weight_local_time'
integer :: dtime ! timestep size [seconds]
integer :: dtime ! timestep size [seconds]
!-----------------------------------------------------------------------

weight = 0
Expand All @@ -2088,14 +2073,12 @@ function calc_weight_local_time(local_secpl, tod) result(weight)
if (tod < dtime .and. local_secpl > isecspday-dtime ) then
local_secpl = local_secpl - isecspday
end if

if (local_secpl >= tod - dtime .and. local_secpl < tod ) then
weight = dtime-tod+local_secpl
else if (local_secpl >= tod .and. local_secpl < tod + dtime ) then
weight = dtime+tod-local_secpl
end if


end function calc_weight_local_time

!-----------------------------------------------------------------------
Expand Down Expand Up @@ -5772,7 +5755,6 @@ function avgflag_valid(avgflag, blank_valid) result(valid)
else
valid = .false.
end if

else
valid = .false.
end if
Expand Down

0 comments on commit 4ec41d4

Please sign in to comment.