One <Label> : <total> Error <residual> conservation line. With
budget_on the residual closes the budget — (total − ref) + out −
src — and the cumulative outflux / surface source are appended;
without it the residual is raw drift total − ref and the line is
byte-identical to the pre-budget format. label is a 4-char tag
(Mass / Salt / Heat) so the colons align.
Robustness note: when budget_on = .false. the out/src arguments
are zeroed locally before the residual is formed, so a caller that
passes non-zero accumulators for an inactive quantity cannot silently
corrupt the raw-drift line with the budget correction.
PR-32 residual_exact: when present, the caller has already formed
(total − ref) in FIXED POINT (efp_real_diff) rather than double
subtraction — used in place of (total - ref) here. The
budget_on out/src correction, the format strings, and
relative_drift’s guard are otherwise UNCHANGED (SS5.4: “the
format strings, the budget_on zeroing logic and the relative_drift
guard are unchanged”). Absent ⇒ byte-identical to pre-PR-32.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | label | |||
| real(kind=wp), | intent(in) | :: | total | |||
| real(kind=wp), | intent(in) | :: | ref | |||
| real(kind=wp), | intent(in) | :: | q_out | |||
| real(kind=wp), | intent(in) | :: | q_src | |||
| logical, | intent(in) | :: | budget_on | |||
| real(kind=wp), | intent(in), | optional | :: | residual_exact |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=256), | private | :: | line | ||||
| real(kind=wp), | private | :: | out_eff | ||||
| real(kind=wp), | private | :: | residual | ||||
| real(kind=wp), | private | :: | src_eff |
subroutine emit_drift_line(label, total, ref, q_out, q_src, budget_on, residual_exact) !! One `<Label> : <total> Error <residual>` conservation line. With !! `budget_on` the residual closes the budget — `(total − ref) + out − !! src` — and the cumulative outflux / surface source are appended; !! without it the residual is raw drift `total − ref` and the line is !! byte-identical to the pre-budget format. `label` is a 4-char tag !! (Mass / Salt / Heat) so the colons align. !! !! Robustness note: when `budget_on = .false.` the `out`/`src` arguments !! are zeroed locally before the residual is formed, so a caller that !! passes non-zero accumulators for an inactive quantity cannot silently !! corrupt the raw-drift line with the budget correction. !! !! PR-32 `residual_exact`: when present, the caller has already formed !! `(total − ref)` in FIXED POINT (`efp_real_diff`) rather than double !! subtraction — used in place of `(total - ref)` here. The !! `budget_on` out/src correction, the format strings, and !! `relative_drift`'s guard are otherwise UNCHANGED (SS5.4: "the !! format strings, the budget_on zeroing logic and the relative_drift !! guard are unchanged"). Absent ⇒ byte-identical to pre-PR-32. character(len=*), intent(in) :: label real(wp), intent(in) :: total, ref, q_out, q_src logical, intent(in) :: budget_on real(wp), intent(in), optional :: residual_exact character(len=256) :: line real(wp) :: residual, out_eff, src_eff ! Zero the budget terms when the budget is inactive so the raw-drift ! residual is exact even if the caller passes non-zero accumulators. if (budget_on) then out_eff = q_out src_eff = q_src else out_eff = 0.0_wp src_eff = 0.0_wp end if if (present(residual_exact)) then residual = residual_exact + out_eff - src_eff else residual = (total - ref) + out_eff - src_eff end if if (budget_on) then write (line, "(' ',A,' : ',ES16.9,' Error ',ES10.3,& &' out ',ES10.3,' src ',ES10.3)") & label, total, relative_drift(residual, ref), out_eff, src_eff else write (line, "(' ',A,' : ',ES16.9,' Error ',ES10.3)") & label, total, relative_drift(residual, ref) end if call logger%info(trim(line)) end subroutine emit_drift_line