From e557cdb68fbaca595ecf6d65043f7ce053ef5e47 Mon Sep 17 00:00:00 2001 From: peverwhee Date: Thu, 9 Jul 2026 16:11:25 -0600 Subject: [PATCH 1/6] make constituent lookup routines case insensitive --- scripts/constituents.py | 3 ++- scripts/host_cap.py | 8 ------ src/ccpp_scheme_utils.F90 | 35 ++++++++++++++++++++++++-- test/advection_test/test_host_data.F90 | 2 +- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/scripts/constituents.py b/scripts/constituents.py index e7e182c0..c8597d3c 100644 --- a/scripts/constituents.py +++ b/scripts/constituents.py @@ -741,6 +741,7 @@ def write_host_routines(cap, host, reg_funcname, init_funcname, num_const_funcna substmt = f"subroutine {const_index_func}" cap.blank_line() cap.write(f"{substmt}(stdname, const_index, {err_dummy_str})", 1) + cap.write("use ccpp_scheme_utils, only: to_lower", 2) cap.comment("Set to the constituent array index " + \ "for .", 2) cap.comment("If is not found, set to -1 " + \ @@ -755,7 +756,7 @@ def write_host_routines(cap, host, reg_funcname, init_funcname, num_const_funcna # end for cap.blank_line() cap.write(f"call {const_obj_name}%const_index(const_index, " + \ - f"stdname, {obj_err_callstr})", 2) + f"to_lower(stdname), {obj_err_callstr})", 2) cap.write(f"end {substmt}", 1) @staticmethod diff --git a/scripts/host_cap.py b/scripts/host_cap.py index fb2e7012..76de0278 100644 --- a/scripts/host_cap.py +++ b/scripts/host_cap.py @@ -242,14 +242,6 @@ def constituent_model_const_props(host_model): hstr = f"{host_model.name}_model_const_properties" return unique_local_name(hstr, host_model) -############################################################################### -def constituent_model_const_index(host_model): -############################################################################### - """Return the name of the interface that returns the array index of - a constituent array given its standard name""" - hstr = f"{host_model.name}_const_get_index" - return unique_local_name(hstr, host_model) - ############################################################################### def add_constituent_vars(cap, host_model, suite_list, run_env): ############################################################################### diff --git a/src/ccpp_scheme_utils.F90 b/src/ccpp_scheme_utils.F90 index d4de6499..3d17e5b4 100644 --- a/src/ccpp_scheme_utils.F90 +++ b/src/ccpp_scheme_utils.F90 @@ -12,6 +12,7 @@ module ccpp_scheme_utils public :: ccpp_initialize_constituent_ptr ! Used by framework to initialize public :: ccpp_constituent_index ! Lookup index constituent by name public :: ccpp_constituent_indices ! Lookup indices of consitutents by name + public :: to_lower ! Convert string to lowercase !! Private module variables & interfaces @@ -81,7 +82,7 @@ subroutine ccpp_constituent_index(standard_name, const_index, errcode, errmsg) call check_initialization(caller=subname, errcode=errcode, errmsg=errmsg) if (status_ok(errcode)) then - call constituent_obj%const_index(const_index, standard_name, & + call constituent_obj%const_index(const_index, to_lower(standard_name), & errcode, errmsg) else const_index = int_unassigned @@ -110,7 +111,7 @@ subroutine ccpp_constituent_indices(standard_names, const_inds, errcode, errmsg) do indx = 1, size(standard_names) ! For each std name in , find the const. index call constituent_obj%const_index(const_inds(indx), & - standard_names(indx), errcode, errmsg) + to_lower(standard_names(indx)), errcode, errmsg) if (errcode /= 0) then exit end if @@ -119,4 +120,34 @@ subroutine ccpp_constituent_indices(standard_names, const_inds, errcode, errmsg) end if end subroutine ccpp_constituent_indices + function to_lower(str) + + implicit none + + ! !INPUT/OUTPUT PARAMETERS: + character(len=*), intent(in) :: str ! String to convert to lower case + character(len=len(str)) :: to_lower + + !----- local ----- + integer :: i ! Index + integer :: aseq ! ascii collating sequence + integer :: upper_to_lower ! integer to convert case + character(len=1) :: ctmp ! Character temporary + + !------------------------------------------------------------------------------- + ! + !------------------------------------------------------------------------------- + + upper_to_lower = iachar("a") - iachar("A") + + do i = 1, len(str) + ctmp = str(i:i) + aseq = iachar(ctmp) + if ( aseq >= iachar("A") .and. aseq <= iachar("Z") ) & + ctmp = achar(aseq + upper_to_lower) + to_lower(i:i) = ctmp + end do + + end function to_lower + end module ccpp_scheme_utils diff --git a/test/advection_test/test_host_data.F90 b/test/advection_test/test_host_data.F90 index f360ad79..00c08c22 100644 --- a/test/advection_test/test_host_data.F90 +++ b/test/advection_test/test_host_data.F90 @@ -16,7 +16,7 @@ module test_host_data !! \htmlinclude arg_table_test_host_data.html integer, public, parameter :: num_consts = 3 character(len=32), public, parameter :: std_name_array(num_consts) = (/ & - 'specific_humidity ', & + 'SPECIFIC_HUMIDITY ', & 'cloud_liquid_dry_mixing_ratio', & 'cloud_ice_dry_mixing_ratio ' /) character(len=32), public, parameter :: const_std_name = std_name_array(1) From d666730523791906c2bfb84dc8b7c5664a5414da Mon Sep 17 00:00:00 2001 From: peverwhee Date: Thu, 9 Jul 2026 16:17:50 -0600 Subject: [PATCH 2/6] move to_lower to const mod --- scripts/constituents.py | 2 +- src/ccpp_constituent_prop_mod.F90 | 36 +++++++++++++++++++++++++++++++ src/ccpp_scheme_utils.F90 | 33 +--------------------------- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/scripts/constituents.py b/scripts/constituents.py index c8597d3c..c1bf7016 100644 --- a/scripts/constituents.py +++ b/scripts/constituents.py @@ -741,7 +741,7 @@ def write_host_routines(cap, host, reg_funcname, init_funcname, num_const_funcna substmt = f"subroutine {const_index_func}" cap.blank_line() cap.write(f"{substmt}(stdname, const_index, {err_dummy_str})", 1) - cap.write("use ccpp_scheme_utils, only: to_lower", 2) + cap.write("use ccpp_constituent_prop_mod, only: to_lower", 2) cap.comment("Set to the constituent array index " + \ "for .", 2) cap.comment("If is not found, set to -1 " + \ diff --git a/src/ccpp_constituent_prop_mod.F90 b/src/ccpp_constituent_prop_mod.F90 index d881e308..7b2dceb0 100644 --- a/src/ccpp_constituent_prop_mod.F90 +++ b/src/ccpp_constituent_prop_mod.F90 @@ -202,6 +202,9 @@ module ccpp_constituent_prop_mod procedure :: constituent_props_ptr => ccp_constituent_props_ptr end type ccpp_model_constituents_t + ! Public interfaces + public to_lower + ! Private interfaces private to_str private initialize_errvars @@ -2633,4 +2636,37 @@ subroutine ccpt_set_water_species(this, water_flag, errcode, errmsg) end subroutine ccpt_set_water_species + !####################################################################### + + function to_lower(str) + + implicit none + + ! !INPUT/OUTPUT PARAMETERS: + character(len=*), intent(in) :: str ! String to convert to lower case + character(len=len(str)) :: to_lower + + !----- local ----- + integer :: i ! Index + integer :: aseq ! ascii collating sequence + integer :: upper_to_lower ! integer to convert case + character(len=1) :: ctmp ! Character temporary + + !------------------------------------------------------------------------------- + ! + !------------------------------------------------------------------------------- + + upper_to_lower = iachar("a") - iachar("A") + + do i = 1, len(str) + ctmp = str(i:i) + aseq = iachar(ctmp) + if ( aseq >= iachar("A") .and. aseq <= iachar("Z") ) & + ctmp = achar(aseq + upper_to_lower) + to_lower(i:i) = ctmp + end do + + end function to_lower + + end module ccpp_constituent_prop_mod diff --git a/src/ccpp_scheme_utils.F90 b/src/ccpp_scheme_utils.F90 index 3d17e5b4..b3f1bd3e 100644 --- a/src/ccpp_scheme_utils.F90 +++ b/src/ccpp_scheme_utils.F90 @@ -3,7 +3,7 @@ module ccpp_scheme_utils ! Module of utilities available to CCPP schemes use ccpp_constituent_prop_mod, only: ccpp_model_constituents_t, & - int_unassigned + int_unassigned, to_lower implicit none private @@ -12,7 +12,6 @@ module ccpp_scheme_utils public :: ccpp_initialize_constituent_ptr ! Used by framework to initialize public :: ccpp_constituent_index ! Lookup index constituent by name public :: ccpp_constituent_indices ! Lookup indices of consitutents by name - public :: to_lower ! Convert string to lowercase !! Private module variables & interfaces @@ -120,34 +119,4 @@ subroutine ccpp_constituent_indices(standard_names, const_inds, errcode, errmsg) end if end subroutine ccpp_constituent_indices - function to_lower(str) - - implicit none - - ! !INPUT/OUTPUT PARAMETERS: - character(len=*), intent(in) :: str ! String to convert to lower case - character(len=len(str)) :: to_lower - - !----- local ----- - integer :: i ! Index - integer :: aseq ! ascii collating sequence - integer :: upper_to_lower ! integer to convert case - character(len=1) :: ctmp ! Character temporary - - !------------------------------------------------------------------------------- - ! - !------------------------------------------------------------------------------- - - upper_to_lower = iachar("a") - iachar("A") - - do i = 1, len(str) - ctmp = str(i:i) - aseq = iachar(ctmp) - if ( aseq >= iachar("A") .and. aseq <= iachar("Z") ) & - ctmp = achar(aseq + upper_to_lower) - to_lower(i:i) = ctmp - end do - - end function to_lower - end module ccpp_scheme_utils From 8f398ebc057d478c0274cbfef33e0461ee40816c Mon Sep 17 00:00:00 2001 From: peverwhee Date: Thu, 9 Jul 2026 16:45:30 -0600 Subject: [PATCH 3/6] lowercase stdnames by default upon instantiation --- src/ccpp_constituent_prop_mod.F90 | 2 +- test/advection_test/cld_liq.F90 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ccpp_constituent_prop_mod.F90 b/src/ccpp_constituent_prop_mod.F90 index 7b2dceb0..dc737d38 100644 --- a/src/ccpp_constituent_prop_mod.F90 +++ b/src/ccpp_constituent_prop_mod.F90 @@ -410,7 +410,7 @@ subroutine ccp_instantiate(this, std_name, long_name, diag_name, units, & else errcode = 0 errmsg = '' - this%var_std_name = trim(std_name) + this%var_std_name = trim(to_lower(std_name)) end if if (errcode == 0) then this%var_long_name = trim(long_name) diff --git a/test/advection_test/cld_liq.F90 b/test/advection_test/cld_liq.F90 index cb02cf11..ce799082 100644 --- a/test/advection_test/cld_liq.F90 +++ b/test/advection_test/cld_liq.F90 @@ -30,7 +30,7 @@ subroutine cld_liq_register(dyn_const, errmsg, errflg) errmsg = 'Error allocating dyn_const in cld_liq_register' return end if - call dyn_const(1)%instantiate(std_name="dyn_const3_wrt_moist_air_and_condensed_water", long_name='dyn const3', & + call dyn_const(1)%instantiate(std_name="DYN_const3_wrt_moist_air_and_condensed_water", long_name='dyn const3', & diag_name='DYNCONST3', units='kg kg-1', default_value=1._kind_phys, & vertical_dim='vertical_layer_dimension', advected=.true., & water_species=.true., mixing_ratio_type='dry', & From bbe3e9808bbef73daef50857ca6830ef5bde8d23 Mon Sep 17 00:00:00 2001 From: peverwhee Date: Thu, 9 Jul 2026 16:57:44 -0600 Subject: [PATCH 4/6] attempt to appease codee --- src/ccpp_constituent_prop_mod.F90 | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/ccpp_constituent_prop_mod.F90 b/src/ccpp_constituent_prop_mod.F90 index dc737d38..ce2868f2 100644 --- a/src/ccpp_constituent_prop_mod.F90 +++ b/src/ccpp_constituent_prop_mod.F90 @@ -2640,30 +2640,23 @@ end subroutine ccpt_set_water_species function to_lower(str) - implicit none - - ! !INPUT/OUTPUT PARAMETERS: - character(len=*), intent(in) :: str ! String to convert to lower case + character(len=*), intent(in) :: str ! String to convert to lower case character(len=len(str)) :: to_lower - !----- local ----- - integer :: i ! Index - integer :: aseq ! ascii collating sequence + ! Local variables + integer :: i ! Index + integer :: aseq ! ascii collating sequence integer :: upper_to_lower ! integer to convert case - character(len=1) :: ctmp ! Character temporary - - !------------------------------------------------------------------------------- - ! - !------------------------------------------------------------------------------- + character(len=1) :: ctmp ! Character temporary upper_to_lower = iachar("a") - iachar("A") do i = 1, len(str) - ctmp = str(i:i) - aseq = iachar(ctmp) - if ( aseq >= iachar("A") .and. aseq <= iachar("Z") ) & - ctmp = achar(aseq + upper_to_lower) - to_lower(i:i) = ctmp + ctmp = str(i:i) + aseq = iachar(ctmp) + if ( aseq >= iachar("A") .and. aseq <= iachar("Z") ) & + ctmp = achar(aseq + upper_to_lower) + to_lower(i:i) = ctmp end do end function to_lower From 43771059c978896c5ee539ac6635812c41e98735 Mon Sep 17 00:00:00 2001 From: peverwhee Date: Thu, 9 Jul 2026 16:59:49 -0600 Subject: [PATCH 5/6] attempt 2 --- src/ccpp_constituent_prop_mod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ccpp_constituent_prop_mod.F90 b/src/ccpp_constituent_prop_mod.F90 index ce2868f2..b7067e51 100644 --- a/src/ccpp_constituent_prop_mod.F90 +++ b/src/ccpp_constituent_prop_mod.F90 @@ -2641,7 +2641,7 @@ end subroutine ccpt_set_water_species function to_lower(str) character(len=*), intent(in) :: str ! String to convert to lower case - character(len=len(str)) :: to_lower + character(len=len(str)) :: to_lower ! Local variables integer :: i ! Index @@ -2654,8 +2654,8 @@ function to_lower(str) do i = 1, len(str) ctmp = str(i:i) aseq = iachar(ctmp) - if ( aseq >= iachar("A") .and. aseq <= iachar("Z") ) & - ctmp = achar(aseq + upper_to_lower) + if (aseq >= iachar("A") .and. aseq <= iachar("Z")) & + ctmp = achar(aseq + upper_to_lower) to_lower(i:i) = ctmp end do From 4dced1650f417dfdff598d5d21c7e1abbfbe84bb Mon Sep 17 00:00:00 2001 From: peverwhee Date: Thu, 9 Jul 2026 17:28:42 -0600 Subject: [PATCH 6/6] remove whitespace --- src/ccpp_constituent_prop_mod.F90 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ccpp_constituent_prop_mod.F90 b/src/ccpp_constituent_prop_mod.F90 index b7067e51..e46fda6e 100644 --- a/src/ccpp_constituent_prop_mod.F90 +++ b/src/ccpp_constituent_prop_mod.F90 @@ -2661,5 +2661,4 @@ function to_lower(str) end function to_lower - end module ccpp_constituent_prop_mod