You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect (or confusing?) indexing in "if ( any(fert_cft(begg:endg,cft_ub+1:)" in surfrdUtilsMod.F90 #3032
so in the if statements we likely need to replace cft_ub+1 with npcropmin, though testing will tell us more.
General bug information
CTSM version you are using: ctsm5.3 but this goes back to ctsm5.1
Does this bug cause significantly incorrect results in the model's science?
This bug makes the above if statements useless and their error checks null. This means that users could have been running with .not. use_crop and non-zero prognostic crop amounts inadvertently.
if ( any(wt_cft(begg:endg,cft_ub+1:) /=0.0_r8) )then
call endrun(msg = subname//' without prognostic crops (use_crop=F) and weight of CFT of prognostic crop'//&
' is not zero as expected'// errMsg(sourcefile, __LINE__))
end if
if ( any(fert_cft(begg:endg,cft_ub+1:) /=0.0_r8) )then
call endrun(msg = subname//' without prognostic crops (use_crop=F) and fertilizer of prognostic crop'// &
' is not zero as expected'// errMsg(sourcefile, __LINE__))
end if
end if
So they're checking that no PFTs above the crop PFTs have area or fertilizer read in. This is unnecessary because we have assertions at the top ensuring that there are no such PFTs:
The checks in question presumably don't segfault because the compilers see those allocations and/or assertions and thus optimize these checks away. There's thus an argument that we should just delete these checks. However, we might want to leave them in so that, if those protections go away, these checks kick in.
I think it'd be best to leave them in but add an explanatory comment.
changed the title [-]Incorrect indexing in "if ( any(fert_cft(begg:endg,cft_ub+1:)" in surfrdUtilsMod.F90[/-][+]Incorrect (or confusing?) indexing in "if ( any(fert_cft(begg:endg,cft_ub+1:)" in surfrdUtilsMod.F90[/+]on Mar 27, 2025
I don't understand this: 'However, we might want to leave them in so that,
if those protections go away, these checks kick in.'
why would you ever check an array outside its bounds?
I believe the checks were meant to ensure that no prognostic crop
information was left after shifting the weights and fertilizer to the
generic crops. So having the check with npcropmin presumably would be
correct. But it's going to trigger in that case, because fert_cft isn't
treated properly above.
I'm open to additional feedback here, and this is my plan currently:
(When I get to this issue) I will run various scenarios (mainly I'm thinking Sp vs. BgcCrop) where I output the index values and the contents of these variables to see what's really happening. I hope this helps me determine any necessary changes to the code plus comments that I should add that explain the code's behavior.
Activity
wwieder commentedon Mar 27, 2025
In the SE meeting there was some uncertainty if this is actually a bug, although correcting to
npcropmincould be more clear?swensosc commentedon Mar 27, 2025
samsrabin commentedon Mar 27, 2025
Here is the context for those checks:
CTSM/src/main/surfrdUtilsMod.F90
Lines 515 to 524 in 3fe643a
So they're checking that no PFTs above the crop PFTs have area or fertilizer read in. This is unnecessary because we have assertions at the top ensuring that there are no such PFTs:
CTSM/src/main/surfrdUtilsMod.F90
Lines 453 to 454 in 3fe643a
And also, as @swensosc pointed out, the allocations of those variables stop at
cft_ub:CTSM/src/main/clm_initializeMod.F90
Lines 242 to 243 in 3fe643a
The checks in question presumably don't segfault because the compilers see those allocations and/or assertions and thus optimize these checks away. There's thus an argument that we should just delete these checks. However, we might want to leave them in so that, if those protections go away, these checks kick in.
I think it'd be best to leave them in but add an explanatory comment.
[-]Incorrect indexing in "if ( any(fert_cft(begg:endg,cft_ub+1:)" in surfrdUtilsMod.F90[/-][+]Incorrect (or confusing?) indexing in "if ( any(fert_cft(begg:endg,cft_ub+1:)" in surfrdUtilsMod.F90[/+]swensosc commentedon Mar 27, 2025
swensosc commentedon Mar 27, 2025
slevis-lmwg commentedon Mar 27, 2025
I'm open to additional feedback here, and this is my plan currently:
(When I get to this issue) I will run various scenarios (mainly I'm thinking Sp vs. BgcCrop) where I output the index values and the contents of these variables to see what's really happening. I hope this helps me determine any necessary changes to the code plus comments that I should add that explain the code's behavior.