diff --git a/scripts/suite_objects.py b/scripts/suite_objects.py index 96d6649c..dda5b23f 100755 --- a/scripts/suite_objects.py +++ b/scripts/suite_objects.py @@ -1410,10 +1410,17 @@ def write_var_debug_check(self, var, internal_var, cldicts, outfile, errcode, er if not dimensions: if not intent == 'out': internal_var_lname = internal_var.get_prop_value('local_name') - outfile.write(f"if ({conditional}) then", indent) - outfile.write(f"! Assign value of {local_name} to internal_var", indent+1) - outfile.write(f"{internal_var_lname} = {local_name}", indent+1) - outfile.write(f"end if", indent) + tmp_indent = indent + if conditional != '.true.': + tmp_indent = indent + 1 + outfile.write(f"if {conditional} then", indent) + # end if + outfile.write(f"! Assign value of {local_name} to {internal_var}", tmp_indent) + outfile.write(f"{internal_var_lname} = {local_name}", tmp_indent) + outfile.write('',indent) + if conditional != '.true.': + outfile.write(f"end if", indent) + # end if # For arrays, check size of array against dimensions in metadata, then assign # the lower and upper bounds to the internal_var variable if the intent is in/inout else: @@ -1479,24 +1486,38 @@ def write_var_debug_check(self, var, internal_var, cldicts, outfile, errcode, er ubound_string = '(' + ','.join(ubound_strings) + ')' # Write size check - outfile.write(f"if ({conditional}) then", indent) - outfile.write(f"! Check size of array {local_name}", indent+1) - outfile.write(f"if (size({local_name}{dim_string}) /= {array_size}) then", indent+1) - outfile.write(f"write({errmsg}, '(a)') 'In group {self.__group.name} before {self.__subroutine_name}:'", indent+2) - outfile.write(f"write({errmsg}, '(2(a,i8))') 'for array {local_name}, expected size ', {array_size}, ' but got ', size({local_name})", indent+2) - outfile.write(f"{errcode} = 1", indent+2) - outfile.write(f"return", indent+2) - outfile.write(f"end if", indent+1) - outfile.write(f"end if", indent) + tmp_indent = indent + if conditional != '.true.': + tmp_indent = indent + 1 + outfile.write(f"if {conditional} then", indent) + # end if + outfile.write(f"! Check size of array {local_name}", tmp_indent) + outfile.write(f"if (size({local_name}{dim_string}) /= {array_size}) then", tmp_indent) + outfile.write(f"write({errmsg}, '(a)') 'In group {self.__group.name} before {self.__subroutine_name}:'", tmp_indent+1) + outfile.write(f"write({errmsg}, '(2(a,i8))') 'for array {local_name}, expected size ', {array_size}, ' but got ', size({local_name})", tmp_indent+1) + outfile.write(f"{errcode} = 1", tmp_indent+1) + outfile.write(f"return", tmp_indent+1) + outfile.write(f"end if", tmp_indent) + if conditional != '.true.': + outfile.write(f"end if", indent) + # end if + outfile.write('',indent) # Assign lower/upper bounds to internal_var (scalar) if intent is not out if not intent == 'out': internal_var_lname = internal_var.get_prop_value('local_name') - outfile.write(f"if ({conditional}) then", indent) - outfile.write(f"! Assign lower/upper bounds of {local_name} to internal_var", indent+1) - outfile.write(f"{internal_var_lname} = {local_name}{lbound_string}", indent+1) - outfile.write(f"{internal_var_lname} = {local_name}{ubound_string}", indent+1) - outfile.write(f"end if", indent) + tmp_indent = indent + if conditional != '.true.': + tmp_indent = indent + 1 + outfile.write(f"if {conditional} then", indent) + # end if + outfile.write(f"! Assign lower/upper bounds of {local_name} to {internal_var}", tmp_indent+1) + outfile.write(f"{internal_var_lname} = {local_name}{lbound_string}", tmp_indent+1) + outfile.write(f"{internal_var_lname} = {local_name}{ubound_string}", tmp_indent+1) + if conditional != '.true.': + outfile.write(f"end if", indent) + # end if + outfile.write('',indent) def add_var_transform(self, var, compat_obj, vert_dim): """Register any variable transformation needed by for this Scheme. @@ -1571,7 +1592,7 @@ def write_var_transform(self, var, dummy, rindices, lindices, compat_obj, rvar_lname=dummy, lvar_indices=rindices, rvar_indices=lindices) - outfile.write(stmt, indent+1) + outfile.write(stmt, indent) def write(self, outfile, errcode, errmsg, indent): # Unused arguments are for consistent write interface @@ -1585,23 +1606,29 @@ def write(self, outfile, errcode, errmsg, indent): is_func_call=True, subname=self.subroutine_name) + outfile.write('', indent) outfile.write('if ({} == 0) then'.format(errcode), indent) # Write debug checks (operating on variables # coming from the group's call list) for (var, internal_var) in self.__var_debug_checks: - stmt = self.write_var_debug_check(var, internal_var, cldicts, outfile, errcode, errmsg, indent) - + stmt = self.write_var_debug_check(var, internal_var, cldicts, outfile, errcode, errmsg, indent+1) # Write any reverse (pre-Scheme) transforms. + outfile.write('! Compute reverse (pre-scheme) transforms', indent+1) for (dummy, var, rindices, lindices, compat_obj) in self.__reverse_transforms: - tstmt = self.write_var_transform(var, dummy, rindices, lindices, compat_obj, outfile, indent, False) + tstmt = self.write_var_transform(var, dummy, rindices, lindices, compat_obj, outfile, indent+1, False) # Write the scheme call. stmt = 'call {}({})' + outfile.write('',indent+1) + outfile.write('! Call scheme', indent+1) outfile.write(stmt.format(self.subroutine_name, my_args), indent+1) # Write any forward (post-Scheme) transforms. + outfile.write('',indent+1) + outfile.write('! Compute forward (post-scheme) transforms', indent+1) for (var, dummy, lindices, rindices, compat_obj) in self.__forward_transforms: - tstmt = self.write_var_transform(var, dummy, rindices, lindices, compat_obj, outfile, indent, True) + tstmt = self.write_var_transform(var, dummy, rindices, lindices, compat_obj, outfile, indent+1, True) # + outfile.write('', indent) outfile.write('end if', indent) def schemes(self): diff --git a/test/var_compatibility_test/effr_calc.F90 b/test/var_compatibility_test/effr_calc.F90 index d01408c6..b877e99a 100644 --- a/test/var_compatibility_test/effr_calc.F90 +++ b/test/var_compatibility_test/effr_calc.F90 @@ -15,15 +15,17 @@ module effr_calc !> \section arg_table_effr_calc_run Argument Table !! \htmlinclude arg_table_effr_calc_run.html !! - subroutine effr_calc_run(ncol, nlev, effrr_in, effrl_inout, & - effri_out, effrs_inout, errmsg, errflg) + subroutine effr_calc_run(ncol, nlev, effrr_in, effrg_in, effrl_inout, & + effri_out, effrs_inout, has_graupel, errmsg, errflg) integer, intent(in) :: ncol integer, intent(in) :: nlev real(kind_phys), intent(in) :: effrr_in(:,:) + real(kind_phys), intent(in) :: effrg_in(:,:) real(kind_phys), intent(inout) :: effrl_inout(:,:) real(kind_phys), intent(out) :: effri_out(:,:) real(8),intent(inout) :: effrs_inout(:,:) + logical, intent(in) :: has_graupel character(len=512), intent(out) :: errmsg integer, intent(out) :: errflg !---------------------------------------------------------------- @@ -32,11 +34,13 @@ subroutine effr_calc_run(ncol, nlev, effrr_in, effrl_inout, & real(kind_phys), parameter :: re_qc_max = 50. ! microns real(kind_phys), parameter :: re_qi_avg = 75. ! microns real(kind_phys) :: effrr_local(ncol,nlev) + real(kind_phys) :: effrg_local(ncol,nlev) errmsg = '' errflg = 0 effrr_local = effrr_in + if (has_graupel) effrg_local = effrg_in effrl_inout = min(max(effrl_inout,re_qc_min),re_qc_max) effri_out = re_qi_avg effrs_inout = effrs_inout + 10.0 ! in micrometer diff --git a/test/var_compatibility_test/effr_calc.meta b/test/var_compatibility_test/effr_calc.meta index 78243ce9..14687f21 100644 --- a/test/var_compatibility_test/effr_calc.meta +++ b/test/var_compatibility_test/effr_calc.meta @@ -26,6 +26,14 @@ kind = kind_phys intent = in top_at_one = .true. +[effrg_in] + standard_name = effective_radius_of_stratiform_cloud_graupel + long_name = effective radius of cloud graupel in micrometer + units = um + dimensions = (horizontal_loop_extent,vertical_layer_dimension) + type = real + kind = kind_phys + intent = in [effrl_inout] standard_name = effective_radius_of_stratiform_cloud_liquid_water_particle long_name = effective radius of cloud liquid water particle in micrometer @@ -51,6 +59,13 @@ kind = 8 intent = inout top_at_one = .true. +[has_graupel] + standard_name = flag_indicating_cloud_microphysics_has_graupel + long_name = flag indicating that the cloud microphysics produces graupel + units = flag + dimensions = () + type = logical + intent = in [ errmsg ] standard_name = ccpp_error_message long_name = Error message for error handling in CCPP diff --git a/test/var_compatibility_test/run_test b/test/var_compatibility_test/run_test index ac86bf6f..9239c5d1 100755 --- a/test/var_compatibility_test/run_test +++ b/test/var_compatibility_test/run_test @@ -131,17 +131,21 @@ module_list="effr_calc" #dependencies="" suite_list="var_compatibility_suite" required_vars_var_compatibility="ccpp_error_code,ccpp_error_message" +required_vars_var_compatibility="${required_vars_var_compatibility},effective_radius_of_stratiform_cloud_graupel" required_vars_var_compatibility="${required_vars_var_compatibility},effective_radius_of_stratiform_cloud_ice_particle" required_vars_var_compatibility="${required_vars_var_compatibility},effective_radius_of_stratiform_cloud_liquid_water_particle" required_vars_var_compatibility="${required_vars_var_compatibility},effective_radius_of_stratiform_cloud_rain_particle" required_vars_var_compatibility="${required_vars_var_compatibility},effective_radius_of_stratiform_cloud_snow_particle" +required_vars_var_compatibility="${required_vars_var_compatibility},flag_indicating_cloud_microphysics_has_graupel" required_vars_var_compatibility="${required_vars_var_compatibility},horizontal_dimension" required_vars_var_compatibility="${required_vars_var_compatibility},horizontal_loop_begin" required_vars_var_compatibility="${required_vars_var_compatibility},horizontal_loop_end" required_vars_var_compatibility="${required_vars_var_compatibility},vertical_layer_dimension" -input_vars_var_compatibility="effective_radius_of_stratiform_cloud_liquid_water_particle" +input_vars_var_compatibility="effective_radius_of_stratiform_cloud_graupel" +input_vars_var_compatibility="${input_vars_var_compatibility},effective_radius_of_stratiform_cloud_liquid_water_particle" input_vars_var_compatibility="${input_vars_var_compatibility},effective_radius_of_stratiform_cloud_rain_particle" input_vars_var_compatibility="${input_vars_var_compatibility},effective_radius_of_stratiform_cloud_snow_particle" +input_vars_var_compatibility="${input_vars_var_compatibility},flag_indicating_cloud_microphysics_has_graupel" input_vars_var_compatibility="${input_vars_var_compatibility},horizontal_dimension" input_vars_var_compatibility="${input_vars_var_compatibility},horizontal_loop_begin" input_vars_var_compatibility="${input_vars_var_compatibility},horizontal_loop_end" diff --git a/test/var_compatibility_test/test_host.F90 b/test/var_compatibility_test/test_host.F90 index 25129405..12215bd1 100644 --- a/test/var_compatibility_test/test_host.F90 +++ b/test/var_compatibility_test/test_host.F90 @@ -351,10 +351,12 @@ program test character(len=cs), target :: test_parts1(1) = (/ 'radiation ' /) - character(len=cm), target :: test_invars1(3) = (/ & + character(len=cm), target :: test_invars1(5) = (/ & 'effective_radius_of_stratiform_cloud_rain_particle ', & 'effective_radius_of_stratiform_cloud_liquid_water_particle', & - 'effective_radius_of_stratiform_cloud_snow_particle ' /) + 'effective_radius_of_stratiform_cloud_snow_particle ', & + 'effective_radius_of_stratiform_cloud_graupel ', & + 'flag_indicating_cloud_microphysics_has_graupel '/) character(len=cm), target :: test_outvars1(5) = (/ & 'ccpp_error_code ', & @@ -363,13 +365,15 @@ program test 'effective_radius_of_stratiform_cloud_liquid_water_particle', & 'effective_radius_of_stratiform_cloud_snow_particle ' /) - character(len=cm), target :: test_reqvars1(6) = (/ & + character(len=cm), target :: test_reqvars1(8) = (/ & 'ccpp_error_code ', & 'ccpp_error_message ', & 'effective_radius_of_stratiform_cloud_rain_particle ', & 'effective_radius_of_stratiform_cloud_ice_particle ', & 'effective_radius_of_stratiform_cloud_liquid_water_particle', & - 'effective_radius_of_stratiform_cloud_snow_particle ' /) + 'effective_radius_of_stratiform_cloud_snow_particle ', & + 'effective_radius_of_stratiform_cloud_graupel ', & + 'flag_indicating_cloud_microphysics_has_graupel '/) type(suite_info) :: test_suites(1) logical :: run_okay diff --git a/test/var_compatibility_test/test_host_data.F90 b/test/var_compatibility_test/test_host_data.F90 index 9a17eb4f..b17fb916 100644 --- a/test/var_compatibility_test/test_host_data.F90 +++ b/test/var_compatibility_test/test_host_data.F90 @@ -8,17 +8,19 @@ module test_host_data real(kind_phys), dimension(:,:), allocatable :: & effrr, & ! effective radius of cloud rain effrl, & ! effective radius of cloud liquid water - effri ! effective radius of cloud ice + effri, & ! effective radius of cloud ice + effrg ! effective radius of cloud graupel end type physics_state public allocate_physics_state contains - subroutine allocate_physics_state(cols, levels, state) + subroutine allocate_physics_state(cols, levels, state, has_graupel) integer, intent(in) :: cols integer, intent(in) :: levels type(physics_state), intent(out) :: state + logical, intent(in) :: has_graupel if (allocated(state%effrr)) then deallocate(state%effrr) @@ -35,6 +37,13 @@ subroutine allocate_physics_state(cols, levels, state) end if allocate(state%effri(cols, levels)) + if (has_graupel) then + if (allocated(state%effrg)) then + deallocate(state%effrg) + end if + allocate(state%effrg(cols, levels)) + endif + end subroutine allocate_physics_state end module test_host_data diff --git a/test/var_compatibility_test/test_host_data.meta b/test/var_compatibility_test/test_host_data.meta index 4a98245f..1d29572c 100644 --- a/test/var_compatibility_test/test_host_data.meta +++ b/test/var_compatibility_test/test_host_data.meta @@ -25,3 +25,11 @@ dimensions = (horizontal_dimension,vertical_layer_dimension) type = real kind = kind_phys +[effrg] + standard_name = effective_radius_of_stratiform_cloud_graupel + long_name = effective radius of cloud graupel in meter + units = m + dimensions = (horizontal_dimension,vertical_layer_dimension) + type = real + kind = kind_phys + active = (flag_indicating_cloud_microphysics_has_graupel) diff --git a/test/var_compatibility_test/test_host_mod.F90 b/test/var_compatibility_test/test_host_mod.F90 index b0501c0c..2761d9fa 100644 --- a/test/var_compatibility_test/test_host_mod.F90 +++ b/test/var_compatibility_test/test_host_mod.F90 @@ -13,6 +13,7 @@ module test_host_mod integer, parameter :: pver = 4 type(physics_state) :: phys_state real(kind_phys) :: effrs(ncols, pver) + logical, parameter :: mp_has_graupel = .true. public :: init_data public :: compare_data @@ -22,11 +23,14 @@ module test_host_mod subroutine init_data() ! Allocate and initialize state - call allocate_physics_state(ncols, pver, phys_state) + call allocate_physics_state(ncols, pver, phys_state, mp_has_graupel) phys_state%effrr = 1.0E-3 ! 1000 microns, in meter phys_state%effrl = 1.0E-4 ! 100 microns, in meter phys_state%effri = 5.0E-5 ! 50 microns, in meter effrs = 5.0E-4 ! 500 microns, in meter + if (mp_has_graupel) then + phys_state%effrg = 2.5E-4 ! 250 microns, in meter + endif end subroutine init_data diff --git a/test/var_compatibility_test/test_host_mod.meta b/test/var_compatibility_test/test_host_mod.meta index 0aff8e2f..7789dbed 100644 --- a/test/var_compatibility_test/test_host_mod.meta +++ b/test/var_compatibility_test/test_host_mod.meta @@ -28,3 +28,9 @@ dimensions = (horizontal_dimension,vertical_layer_dimension) type = real kind = kind_phys +[mp_has_graupel] + standard_name = flag_indicating_cloud_microphysics_has_graupel + long_name = flag indicating that the cloud microphysics produces graupel + units = flag + dimensions = () + type = logical diff --git a/test/var_compatibility_test/test_reports.py b/test/var_compatibility_test/test_reports.py index 4c8f9da6..a56457bc 100755 --- a/test/var_compatibility_test/test_reports.py +++ b/test/var_compatibility_test/test_reports.py @@ -70,7 +70,9 @@ def usage(errmsg=None): _INPUT_VARS_VAR_ACTION = ["horizontal_loop_begin", "horizontal_loop_end", "horizontal_dimension", "vertical_layer_dimension", "effective_radius_of_stratiform_cloud_liquid_water_particle", "effective_radius_of_stratiform_cloud_rain_particle", - "effective_radius_of_stratiform_cloud_snow_particle"] + "effective_radius_of_stratiform_cloud_snow_particle", + "effective_radius_of_stratiform_cloud_graupel", + "flag_indicating_cloud_microphysics_has_graupel"] _OUTPUT_VARS_VAR_ACTION = ["ccpp_error_code", "ccpp_error_message", "effective_radius_of_stratiform_cloud_ice_particle", "effective_radius_of_stratiform_cloud_liquid_water_particle",