From 04dcca4a0581b9565674e106174b3e1eb63d3d75 Mon Sep 17 00:00:00 2001 From: Marshall Ward Date: Thu, 11 Jul 2019 10:32:19 -0400 Subject: [PATCH] Bugfix: Pure pot. density coord diags w/ one layer For experiments with a single layer (e.g. unit_tests), the "pure potential density coordinate" diagnostics (h_Rlay, uh_Rlay, ...) would apply an interpolation to extend values into the mixed layers. However, most of this subroutine assumes at least two layers, including some "nz / 2" divisions which reduce to zero, and memory accesses to levels greater than nz. Overall, this calculation does not make much sense when there is one layer, for both physical and computational reasons. Normally the `nkmb` parameter is changed from zero to `nz` when not in isopycnal mode, applying the interpolation across the entire column, which avoids the interpolating loops and simply transfers the layered values to the diagnostic. We resolve this issue by only apply "nkmb = z" when there is more than one layer, and transfer values regardless of the mode. --- src/diagnostics/MOM_diagnostics.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diagnostics/MOM_diagnostics.F90 b/src/diagnostics/MOM_diagnostics.F90 index 45cfb0ac68..952e3c8b49 100644 --- a/src/diagnostics/MOM_diagnostics.F90 +++ b/src/diagnostics/MOM_diagnostics.F90 @@ -275,7 +275,7 @@ subroutine calculate_diagnostic_fields(u, v, h, uh, vh, tv, ADp, CDp, p_surf, & ! nkmb = nz, on the expectation that loops nkmb+1,nz will not iterate. ! This behavior is ANSI F77 but some compiler options can force at least ! one iteration that would break the following one-line workaround! - if (nkmb==0) nkmb = nz + if (nkmb==0 .and. nz > 1) nkmb = nz if (loc(CS)==0) call MOM_error(FATAL, & "calculate_diagnostic_fields: Module must be initialized before used.")