Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some error checking in PartitionWoodFluxes #1263

Closed
billsacks opened this issue Jan 22, 2021 · 2 comments · Fixed by #1814
Closed

Add some error checking in PartitionWoodFluxes #1263

billsacks opened this issue Jan 22, 2021 · 2 comments · Fixed by #1814
Labels
bfb bit-for-bit code health improving internal code structure to make easier to maintain (sustainability) good first issue good for first-time contributors simple easy for anyone to work on

Comments

@billsacks
Copy link
Member

After #1262 is resolved, I'd like to add some error checking to help prevent errors like this in the future. In particular, in the following code:

if (pprod_tot > 0) then
pprod10_frac = pprod10 / pprod_tot
pprod100_frac = pprod100 / pprod_tot
else
! Avoid divide by 0
pprod10_frac = 0._r8
pprod100_frac = 0._r8
end if
! Note that the patch-level fluxes are expressed per unit gridcell area. So, to go
! from patch-level fluxes to gridcell-level fluxes, we simply add up the various
! patch contributions, without having to multiply by any area weightings.
this%dwt_prod10_gain_grc(g) = this%dwt_prod10_gain_grc(g) + &
dwt_wood_product_gain_patch(p) * pprod10_frac
this%dwt_prod100_gain_grc(g) = this%dwt_prod100_gain_grc(g) + &
dwt_wood_product_gain_patch(p) * pprod100_frac

I'd like to refactor this and add an assertion:

  • Move the final block (which does the addition of fluxes) into the if
  • Change the else block: don't bother setting frac (because now nothing will happen after that else block, with the above change); but instead, call endrun if dwt_wood_product_gain_patch(p) > 0
@billsacks billsacks added the code health improving internal code structure to make easier to maintain (sustainability) label Jan 22, 2021
@billsacks
Copy link
Member Author

Blocked: depends on #1262

@billsacks billsacks added the blocked: dependency Wait to work on this until dependency is resolved label Jan 22, 2021
@billsacks billsacks removed the blocked: dependency Wait to work on this until dependency is resolved label Apr 14, 2021
@billsacks
Copy link
Member Author

Since #1262 is fixed, this is unblocked.

@billsacks billsacks added the good first issue good for first-time contributors label Jul 1, 2022
@samsrabin samsrabin added simple easy for anyone to work on bfb bit-for-bit labels Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bfb bit-for-bit code health improving internal code structure to make easier to maintain (sustainability) good first issue good for first-time contributors simple easy for anyone to work on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants