From 7e9c758c0e81d176ef38c8ff04b88b5b8f4f69a3 Mon Sep 17 00:00:00 2001 From: Rob Waters Date: Mon, 6 Jul 2026 14:07:00 +0100 Subject: [PATCH 1/4] made co2_interactive a module level variable, gets around being unallocated sometimes --- .../core/top_level/ukca_main1-ukca_main1.F90 | 4 ++-- src/science/core/chemistry/ukca_chemistry_ctl.F90 | 14 +++++++++++--- .../core/chemistry/ukca_chemistry_ctl_col_mod.F90 | 8 ++++++++ .../core/chemistry/ukca_chemistry_ctl_full_mod.F90 | 14 +++++++++++--- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/control/core/top_level/ukca_main1-ukca_main1.F90 b/src/control/core/top_level/ukca_main1-ukca_main1.F90 index 044776f..30e826f 100644 --- a/src/control/core/top_level/ukca_main1-ukca_main1.F90 +++ b/src/control/core/top_level/ukca_main1-ukca_main1.F90 @@ -2368,7 +2368,7 @@ SUBROUTINE ukca_main1(error_code_ptr, timestep_number, current_time, & atm_mebr_mol, & atm_h2_mol, & H_plus_3d_arr, & - zdryrt, zwetrt, nlev_with_ddep, L_stratosphere, co2_interactive, & + zdryrt, zwetrt, nlev_with_ddep, L_stratosphere, & l_firstchem & ) @@ -2442,7 +2442,7 @@ SUBROUTINE ukca_main1(error_code_ptr, timestep_number, current_time, & atm_mebr_mol, & atm_h2_mol, & H_plus_3d_arr, & - zdryrt, zwetrt, nlev_with_ddep, co2_interactive, L_stratosphere, & + zdryrt, zwetrt, nlev_with_ddep, L_stratosphere, & l_firstchem & ) END IF diff --git a/src/science/core/chemistry/ukca_chemistry_ctl.F90 b/src/science/core/chemistry/ukca_chemistry_ctl.F90 index 4f61281..15c833c 100644 --- a/src/science/core/chemistry/ukca_chemistry_ctl.F90 +++ b/src/science/core/chemistry/ukca_chemistry_ctl.F90 @@ -61,7 +61,7 @@ SUBROUTINE ukca_chemistry_ctl( & atm_mebr_mol, & atm_h2_mol, & H_plus, & - zdryrt, zwetrt, nlev_with_ddep, co2_interactive, & + zdryrt, zwetrt, nlev_with_ddep, & L_stratosphere, firstcall & ) @@ -88,6 +88,7 @@ SUBROUTINE ukca_chemistry_ctl( & USE ukca_config_constants_mod, ONLY: avogadro USE ukca_config_specification_mod, ONLY: ukca_config USE ukca_ntp_mod, ONLY: ntp_type, dim_ntp, name2ntpindex +USE ukca_environment_fields_mod, ONLY: co2_interactive USE yomhook, ONLY: lhook, dr_hook USE parkind1, ONLY: jprb, jpim USE ereport_mod, ONLY: ereport @@ -118,7 +119,6 @@ SUBROUTINE ukca_chemistry_ctl( & REAL, INTENT(IN) :: zdryrt(theta_field_size,jpdd) ! dry dep rate REAL, INTENT(IN) :: zwetrt(tot_n_pnts,jpdw) ! wet dep rate REAL, INTENT(IN) :: photol_rates(tot_n_pnts,jppj) -REAL, INTENT(IN) :: co2_interactive(tot_n_pnts) REAL, INTENT(OUT) :: shno3_3d(tot_n_pnts) REAL, INTENT(IN OUT) :: q(tot_n_pnts) ! water vapour REAL, INTENT(IN OUT) :: tracer(tot_n_pnts,ntracers) ! tracer MMR @@ -305,7 +305,15 @@ SUBROUTINE ukca_chemistry_ctl( & IF (ANY(speci(:) == 'CO2 ')) THEN ! Copy the CO2 concentration into the asad module as VMR IF (ukca_config%l_chem_environ_co2_fld) THEN - co2_1d(:) = co2_interactive(kcs:kce)/c_co2 + + ! co2_interactive should be allocated if config option on + IF (.NOT. ALLOCATED(co2_interactive)) THEN + errcode = 1 + CALL ereport(ModuleName//':'//RoutineName, errcode, & + 'ERROR: co2_interactive array not allocated') + END IF + + co2_1d(:) = RESHAPE(co2_interactive(:,:,k), [theta_field_size]) / c_co2 ELSE co2_1d(:) = rmdi END IF diff --git a/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 b/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 index d892256..554b8da 100644 --- a/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 +++ b/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 @@ -342,6 +342,14 @@ SUBROUTINE ukca_chemistry_ctl_col( & IF (ANY(speci(:) == 'CO2 ')) THEN ! Copy the CO2 concentration into the asad module as VMR IF (ukca_config%l_chem_environ_co2_fld) THEN + + ! co2_interactive should be allocated if config option on + IF (.NOT. ALLOCATED(co2_interactive)) THEN + errcode = 1 + CALL ereport(ModuleName//':'//RoutineName, errcode, & + 'ERROR: co2_interactive array not allocated') + END IF + co2_1d(:) = co2_interactive(j,i,:)/c_co2 ELSE co2_1d(:) = rmdi diff --git a/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 b/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 index bc84636..937d72e 100644 --- a/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 +++ b/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 @@ -62,7 +62,7 @@ SUBROUTINE ukca_chemistry_ctl_full( & atm_h2_mol, & H_plus, & zdryrt, zwetrt, nlev_with_ddep, L_stratosphere, & - co2_interactive, firstcall & + firstcall & ) USE asad_mod, ONLY: advt, cdt_diag, ctype, & @@ -89,6 +89,7 @@ SUBROUTINE ukca_chemistry_ctl_full( & USE ukca_config_constants_mod, ONLY: avogadro USE ukca_config_specification_mod, ONLY: ukca_config USE ukca_ntp_mod, ONLY: ntp_type, dim_ntp, name2ntpindex +USE ukca_environment_fields_mod, ONLY: co2_interactive USE yomhook, ONLY: lhook, dr_hook USE parkind1, ONLY: jprb, jpim @@ -122,7 +123,6 @@ SUBROUTINE ukca_chemistry_ctl_full( & REAL, INTENT(IN) :: zdryrt(theta_field_size,jpdd) ! dry dep rate REAL, INTENT(IN) :: zwetrt(tot_n_pnts,jpdw) ! wet dep rate REAL, INTENT(IN) :: photol_rates(tot_n_pnts,jppj) -REAL, INTENT(IN) :: co2_interactive(tot_n_pnts) REAL, INTENT(OUT) :: shno3(tot_n_pnts) REAL, INTENT(IN OUT) :: q(tot_n_pnts) ! water vapour REAL, INTENT(IN OUT) :: tracer(tot_n_pnts,ntracers) ! tracer MMR @@ -248,7 +248,15 @@ SUBROUTINE ukca_chemistry_ctl_full( & IF (ANY(speci(:) == 'CO2 ')) THEN ! Copy the CO2 concentration into the asad module as VMR IF (ukca_config%l_chem_environ_co2_fld) THEN - co2_1d(:) = co2_interactive(:)/c_co2 + + ! co2_interactive should be allocated if config option on + IF (.NOT. ALLOCATED(co2_interactive)) THEN + errcode = 1 + CALL ereport(ModuleName//':'//RoutineName, errcode, & + 'ERROR: co2_interactive array not allocated') + END IF + + co2_1d(:) = RESHAPE(co2_interactive, [tot_n_pnts]) / c_co2 ELSE co2_1d(:) = rmdi END IF From d7bd9d5cf2d30d0c1143ab474fab147f265aacf3 Mon Sep 17 00:00:00 2001 From: Rob Waters Date: Mon, 6 Jul 2026 14:46:30 +0100 Subject: [PATCH 2/4] allocatable intent a better option --- .../core/top_level/ukca_main1-ukca_main1.F90 | 7 ++++--- src/science/core/chemistry/ukca_chemistry_ctl.F90 | 14 ++++++++++---- .../core/chemistry/ukca_chemistry_ctl_col_mod.F90 | 8 ++++++-- .../core/chemistry/ukca_chemistry_ctl_full_mod.F90 | 11 ++++++++--- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/control/core/top_level/ukca_main1-ukca_main1.F90 b/src/control/core/top_level/ukca_main1-ukca_main1.F90 index 30e826f..6df0be3 100644 --- a/src/control/core/top_level/ukca_main1-ukca_main1.F90 +++ b/src/control/core/top_level/ukca_main1-ukca_main1.F90 @@ -2369,7 +2369,7 @@ SUBROUTINE ukca_main1(error_code_ptr, timestep_number, current_time, & atm_h2_mol, & H_plus_3d_arr, & zdryrt, zwetrt, nlev_with_ddep, L_stratosphere, & - l_firstchem & + co2_interactive, l_firstchem & ) ELSE IF (ukca_config%l_ukca_asad_columns) THEN @@ -2406,7 +2406,7 @@ SUBROUTINE ukca_main1(error_code_ptr, timestep_number, current_time, & atm_mebr_mol, & atm_h2_mol, & H_plus_3d_arr, & - zdryrt, zwetrt, nlev_with_ddep & + zdryrt, zwetrt, nlev_with_ddep, co2_interactive & ) ELSE @@ -2442,7 +2442,8 @@ SUBROUTINE ukca_main1(error_code_ptr, timestep_number, current_time, & atm_mebr_mol, & atm_h2_mol, & H_plus_3d_arr, & - zdryrt, zwetrt, nlev_with_ddep, L_stratosphere, & + zdryrt, zwetrt, nlev_with_ddep, & + co2_interactive, L_stratosphere, & l_firstchem & ) END IF diff --git a/src/science/core/chemistry/ukca_chemistry_ctl.F90 b/src/science/core/chemistry/ukca_chemistry_ctl.F90 index 15c833c..c728f33 100644 --- a/src/science/core/chemistry/ukca_chemistry_ctl.F90 +++ b/src/science/core/chemistry/ukca_chemistry_ctl.F90 @@ -61,7 +61,7 @@ SUBROUTINE ukca_chemistry_ctl( & atm_mebr_mol, & atm_h2_mol, & H_plus, & - zdryrt, zwetrt, nlev_with_ddep, & + zdryrt, zwetrt, nlev_with_ddep, co2_interactive, & L_stratosphere, firstcall & ) @@ -88,7 +88,7 @@ SUBROUTINE ukca_chemistry_ctl( & USE ukca_config_constants_mod, ONLY: avogadro USE ukca_config_specification_mod, ONLY: ukca_config USE ukca_ntp_mod, ONLY: ntp_type, dim_ntp, name2ntpindex -USE ukca_environment_fields_mod, ONLY: co2_interactive + USE yomhook, ONLY: lhook, dr_hook USE parkind1, ONLY: jprb, jpim USE ereport_mod, ONLY: ereport @@ -119,6 +119,11 @@ SUBROUTINE ukca_chemistry_ctl( & REAL, INTENT(IN) :: zdryrt(theta_field_size,jpdd) ! dry dep rate REAL, INTENT(IN) :: zwetrt(tot_n_pnts,jpdw) ! wet dep rate REAL, INTENT(IN) :: photol_rates(tot_n_pnts,jppj) + +! must be allocatable as passed unallocated from main if l_chem_environ_co2_fld +! is false +REAL, INTENT(IN), ALLOCATABLE :: co2_interactive(row_length,rows,model_levels) + REAL, INTENT(OUT) :: shno3_3d(tot_n_pnts) REAL, INTENT(IN OUT) :: q(tot_n_pnts) ! water vapour REAL, INTENT(IN OUT) :: tracer(tot_n_pnts,ntracers) ! tracer MMR @@ -302,6 +307,7 @@ SUBROUTINE ukca_chemistry_ctl( & ! Put tracer mmr into 1-D array for use in ASAD chemical solver zq(:) = q(kcs:kce)/c_h2o + ! CO2 as species IF (ANY(speci(:) == 'CO2 ')) THEN ! Copy the CO2 concentration into the asad module as VMR IF (ukca_config%l_chem_environ_co2_fld) THEN @@ -309,7 +315,7 @@ SUBROUTINE ukca_chemistry_ctl( & ! co2_interactive should be allocated if config option on IF (.NOT. ALLOCATED(co2_interactive)) THEN errcode = 1 - CALL ereport(ModuleName//':'//RoutineName, errcode, & + CALL ereport(ModuleName//':'//RoutineName, errcode, & 'ERROR: co2_interactive array not allocated') END IF @@ -318,7 +324,7 @@ SUBROUTINE ukca_chemistry_ctl( & co2_1d(:) = rmdi END IF - END IF ! CO2 as species + END IF ! Convert mmr into vmr for tracers. Pass data from the tracer 3D array, ! unwrap it and pass into the 1D zftr array before calling ASAD_CDRIVE. diff --git a/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 b/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 index 554b8da..ab6fdab 100644 --- a/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 +++ b/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 @@ -61,7 +61,7 @@ SUBROUTINE ukca_chemistry_ctl_col( & atm_mebr_mol, & atm_h2_mol, & H_plus_3d_arr, & - zdryrt, zwetrt, nlev_with_ddep & + zdryrt, zwetrt, nlev_with_ddep, co2_interactive & ) USE asad_mod, ONLY: advt, cdt_diag, ctype, & @@ -90,7 +90,6 @@ SUBROUTINE ukca_chemistry_ctl_col( & USE ukca_config_specification_mod, ONLY: ukca_config USE ukca_ntp_mod, ONLY: ntp_type, dim_ntp, name2ntpindex -USE ukca_environment_fields_mod, ONLY: co2_interactive USE yomhook, ONLY: lhook, dr_hook USE parkind1, ONLY: jprb, jpim @@ -141,6 +140,11 @@ SUBROUTINE ukca_chemistry_ctl_col( & REAL, INTENT(IN) :: zdryrt(row_length,rows,jpdd) ! dry dep rate REAL, INTENT(IN) :: zwetrt(row_length,rows,model_levels,jpdw) ! wet dep rate REAL, INTENT(IN) :: photol_rates(row_length,rows,model_levels,jppj) + +! must be allocatable as passed unallocated from main if l_chem_environ_co2_fld +! is false +REAL, INTENT(IN), ALLOCATABLE :: co2_interactive(row_length,rows,model_levels) + REAL, INTENT(OUT) :: shno3_3d(row_length,rows,model_levels) REAL, INTENT(IN OUT) :: q(row_length,rows,model_levels) ! water vapour REAL, INTENT(IN OUT) :: tracer(row_length,rows,model_levels, & diff --git a/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 b/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 index 937d72e..2ef53f4 100644 --- a/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 +++ b/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 @@ -62,7 +62,7 @@ SUBROUTINE ukca_chemistry_ctl_full( & atm_h2_mol, & H_plus, & zdryrt, zwetrt, nlev_with_ddep, L_stratosphere, & - firstcall & + co2_interactive, firstcall & ) USE asad_mod, ONLY: advt, cdt_diag, ctype, & @@ -89,7 +89,6 @@ SUBROUTINE ukca_chemistry_ctl_full( & USE ukca_config_constants_mod, ONLY: avogadro USE ukca_config_specification_mod, ONLY: ukca_config USE ukca_ntp_mod, ONLY: ntp_type, dim_ntp, name2ntpindex -USE ukca_environment_fields_mod, ONLY: co2_interactive USE yomhook, ONLY: lhook, dr_hook USE parkind1, ONLY: jprb, jpim @@ -123,6 +122,11 @@ SUBROUTINE ukca_chemistry_ctl_full( & REAL, INTENT(IN) :: zdryrt(theta_field_size,jpdd) ! dry dep rate REAL, INTENT(IN) :: zwetrt(tot_n_pnts,jpdw) ! wet dep rate REAL, INTENT(IN) :: photol_rates(tot_n_pnts,jppj) + +! must be allocatable as passed unallocated from main if l_chem_environ_co2_fld +! is false +REAL, INTENT(IN), ALLOCATABLE :: co2_interactive(row_length,rows,model_levels) + REAL, INTENT(OUT) :: shno3(tot_n_pnts) REAL, INTENT(IN OUT) :: q(tot_n_pnts) ! water vapour REAL, INTENT(IN OUT) :: tracer(tot_n_pnts,ntracers) ! tracer MMR @@ -245,6 +249,7 @@ SUBROUTINE ukca_chemistry_ctl_full( & zprt1d(:,:) = photol_rates(:,:) END IF +! CO2 as species IF (ANY(speci(:) == 'CO2 ')) THEN ! Copy the CO2 concentration into the asad module as VMR IF (ukca_config%l_chem_environ_co2_fld) THEN @@ -260,7 +265,7 @@ SUBROUTINE ukca_chemistry_ctl_full( & ELSE co2_1d(:) = rmdi END IF -END IF ! CO2 as species +END IF ! Retrieve tropospheric heterogeneous rates from previous time step IF (ukca_config%l_ukca_trophet) THEN From fcf298305a055f59736482d4ee279a1733b8dde7 Mon Sep 17 00:00:00 2001 From: Rob Waters Date: Mon, 6 Jul 2026 14:52:01 +0100 Subject: [PATCH 3/4] added to the contributors.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index de11f63..d97caad 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -9,3 +9,4 @@ | JoeCartonKelly-MO | Joseph Carton-Kelly | Met Office | 2026-04-15 | | yg460-cam | Yao Ge | University of Cambridge | 2026-04-17 | | theabro | Nathan Luke Abraham | NCAS & University of Cambridge | 2026-03-19 | +| RobWatersMet | Rob Waters | NCAS & University of Cambridge | 2026-07-06 | From 0af93f602634f1bed99296cbba9097c5e87d01e4 Mon Sep 17 00:00:00 2001 From: Rob Waters Date: Mon, 6 Jul 2026 16:02:00 +0100 Subject: [PATCH 4/4] had to use deferred shape --- src/science/core/chemistry/ukca_chemistry_ctl.F90 | 2 +- src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 | 2 +- src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/science/core/chemistry/ukca_chemistry_ctl.F90 b/src/science/core/chemistry/ukca_chemistry_ctl.F90 index c728f33..0b12f02 100644 --- a/src/science/core/chemistry/ukca_chemistry_ctl.F90 +++ b/src/science/core/chemistry/ukca_chemistry_ctl.F90 @@ -122,7 +122,7 @@ SUBROUTINE ukca_chemistry_ctl( & ! must be allocatable as passed unallocated from main if l_chem_environ_co2_fld ! is false -REAL, INTENT(IN), ALLOCATABLE :: co2_interactive(row_length,rows,model_levels) +REAL, INTENT(IN), ALLOCATABLE :: co2_interactive(:,:,:) REAL, INTENT(OUT) :: shno3_3d(tot_n_pnts) REAL, INTENT(IN OUT) :: q(tot_n_pnts) ! water vapour diff --git a/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 b/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 index ab6fdab..65b4d6d 100644 --- a/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 +++ b/src/science/core/chemistry/ukca_chemistry_ctl_col_mod.F90 @@ -143,7 +143,7 @@ SUBROUTINE ukca_chemistry_ctl_col( & ! must be allocatable as passed unallocated from main if l_chem_environ_co2_fld ! is false -REAL, INTENT(IN), ALLOCATABLE :: co2_interactive(row_length,rows,model_levels) +REAL, INTENT(IN), ALLOCATABLE :: co2_interactive(:,:,:) REAL, INTENT(OUT) :: shno3_3d(row_length,rows,model_levels) REAL, INTENT(IN OUT) :: q(row_length,rows,model_levels) ! water vapour diff --git a/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 b/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 index 2ef53f4..9ecfcff 100644 --- a/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 +++ b/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.F90 @@ -125,7 +125,7 @@ SUBROUTINE ukca_chemistry_ctl_full( & ! must be allocatable as passed unallocated from main if l_chem_environ_co2_fld ! is false -REAL, INTENT(IN), ALLOCATABLE :: co2_interactive(row_length,rows,model_levels) +REAL, INTENT(IN), ALLOCATABLE :: co2_interactive(:,:,:) REAL, INTENT(OUT) :: shno3(tot_n_pnts) REAL, INTENT(IN OUT) :: q(tot_n_pnts) ! water vapour