Skip to content

Commit

Permalink
icepack_shortwave: zero-initialize local variables for shortwave comp…
Browse files Browse the repository at this point in the history
…onents

In shortwave_ccsm3, the local variables 'l_fswthru_{v,i}d{r,f}' are sent
to 'absorbed_solar' and then the arguments 'fswthru_{v,i}d{r,f}' are
reset to the values of the respective local variables.

However, the call to 'absorbed_solar' is conditional on 'aicen(n) >
puny', so it's possible that not all elements of the arrays are set
after the call to absorbed_solar. This lead to uninitialized values in
'fswthru_{v,i}d{r,f}' and thus potential crashes if compiling with NaNs
initialization.

Fix that by initializing the local variables to zero.

In run_dEdd, the equivalent local variables 'l_fswthrun_{v,i}d{r,f}' are
sent to 'shortwave_dEdd' as arguments 'fswthru_{v,i}d{r,f}', outside of
any 'if' statement, and these arguments are zero-initialized in
'shortwave_dEdd', also outside of any 'if' statement. So in this case
there is no risk that uninitialized values will creep in the
'fswthrun_{v,i}d{r,f}' arrays when they are reset to the values of
'l_fswthrun_{v,i}d{r,f}' at the end of 'run_dEdd'. But to be on the safe
side with regards to potential future code changes, also zero-initialize
these local variables.

For the same reason, also zero-initialize the equivalent local variables
in icepack_step_radiation.
  • Loading branch information
phil-blain committed Mar 23, 2022
1 parent ed85a61 commit c477637
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions columnphysics/icepack_shortwave.F90
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ subroutine shortwave_ccsm3 (aicen, vicen, &
allocate(l_fswthru_idr(ncat))
allocate(l_fswthru_idf(ncat))

l_fswthru_vdr = c0
l_fswthru_vdf = c0
l_fswthru_idr = c0
l_fswthru_idf = c0

! For basic shortwave, set coszen to a constant between 0 and 1.
coszen = p5 ! sun above the horizon

Expand Down Expand Up @@ -963,6 +968,11 @@ subroutine run_dEdd(dt, ncat, &
allocate(l_fswthrun_idr(ncat))
allocate(l_fswthrun_idf(ncat))

l_fswthrun_vdr = c0
l_fswthrun_vdf = c0
l_fswthrun_idr = c0
l_fswthrun_idf = c0

linitonly = .false.
if (present(initonly)) then
linitonly = initonly
Expand Down Expand Up @@ -4143,6 +4153,11 @@ subroutine icepack_step_radiation (dt, ncat, &
allocate(l_fswthrun_idr(ncat))
allocate(l_fswthrun_idf(ncat))

l_fswthrun_vdr = c0
l_fswthrun_vdf = c0
l_fswthrun_idr = c0
l_fswthrun_idf = c0

hin = c0
hbri = c0
linitonly = .false.
Expand Down

0 comments on commit c477637

Please sign in to comment.