From f5ab22cacb0d212112fae859e8c2d09f5639ff54 Mon Sep 17 00:00:00 2001 From: Stephen Price Date: Fri, 11 Jul 2025 11:22:16 -0500 Subject: [PATCH] Fix logic around g2x and x2g vector index calculation Calculate all g2x and x2g indices at the same time based on first_time logic, which is necessary when x2g and g2x calculations are split between calls to budgets1 and budgets2. --- driver-mct/main/seq_diag_mct.F90 | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/driver-mct/main/seq_diag_mct.F90 b/driver-mct/main/seq_diag_mct.F90 index 7aa58dcf5c90..3c3872d48e50 100644 --- a/driver-mct/main/seq_diag_mct.F90 +++ b/driver-mct/main/seq_diag_mct.F90 @@ -1355,15 +1355,24 @@ subroutine seq_diag_glc_mct( glc, frac_g, infodata, do_x2g, do_g2x ) ip = p_inst - if( present(do_g2x))then ! do fields from glc to coupler (g2x_) + if (first_time) then - if (first_time) then + ! we calc these both first rather then in their respective "if" constructs + ! below to avoid g2x indices not getting calculated (because the call to + ! x2g and g2x happen separately, in budgets1 and budgets2, respectively). - index_g2x_Fogg_rofl = mct_aVect_indexRA(g2x_g,'Fogg_rofl') - index_g2x_Fogg_rofi = mct_aVect_indexRA(g2x_g,'Fogg_rofi') - index_g2x_Figg_rofi = mct_aVect_indexRA(g2x_g,'Figg_rofi') + ! indices needed for g2x + index_g2x_Fogg_rofl = mct_aVect_indexRA(g2x_g,'Fogg_rofl') + index_g2x_Fogg_rofi = mct_aVect_indexRA(g2x_g,'Fogg_rofi') + index_g2x_Figg_rofi = mct_aVect_indexRA(g2x_g,'Figg_rofi') - end if + ! indices needed for x2g + index_x2g_Flgl_qice = mct_aVect_indexRA(x2g_g,'Flgl_qice') + index_g2x_Sg_icemask = mct_avect_indexRA(g2x_g,'Sg_icemask') + + end if + + if( present(do_g2x))then ! do fields from glc to coupler (g2x_) ic = c_glc_gr kArea = mct_aVect_indexRA(dom_g%data,afldname) @@ -1382,13 +1391,6 @@ subroutine seq_diag_glc_mct( glc, frac_g, infodata, do_x2g, do_g2x ) if( present(do_x2g))then ! do fields from coupler to glc (x2g_) - if (first_time) then - - index_x2g_Flgl_qice = mct_aVect_indexRA(x2g_g,'Flgl_qice') - index_g2x_Sg_icemask = mct_avect_indexRA(g2x_g,'Sg_icemask') - - end if - l2gacc_lx_cnt_avg = prep_glc_get_l2gacc_lx_cnt_avg() ! counter for how many times SMB flux accumulation has occured ic = c_glc_gs kArea = mct_aVect_indexRA(dom_g%data,afldname)