From 906851fc93e7f0af42455a706879f77bd1fc9fef Mon Sep 17 00:00:00 2001 From: peverwhee Date: Thu, 9 Jul 2026 15:58:41 -0600 Subject: [PATCH 1/4] make get index and find index routines case insensitive --- capgen/generator/host_constituents.py | 3 +- capgen/src/ccpp_scheme_utils.F90 | 35 +++++++++++++++++-- end-to-end-tests/advection/test_host_data.F90 | 2 +- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/capgen/generator/host_constituents.py b/capgen/generator/host_constituents.py index 6109bb10..f895b2a8 100644 --- a/capgen/generator/host_constituents.py +++ b/capgen/generator/host_constituents.py @@ -418,7 +418,7 @@ def _wrap_method_subs(host_dict) -> List[str]: 'ccpp_const_get_index', 'const_index', [ ('stdname', 'character(len=*), intent(in) :: stdname', - 'standard_name=stdname'), + 'standard_name=to_lower(stdname)'), ('const_index', 'integer, intent(out) :: const_index', 'index=const_index'), ], @@ -580,6 +580,7 @@ def _generate_host_constituents( lines.append('module {}'.format(_HOST_CONST_MOD)) lines.append('') lines.append('{}use ccpp_kinds, only: kind_phys'.format(_INDENT)) + lines.append('{}use ccpp_scheme_utils, only: to_lower'.format(_INDENT)) lines.append('{}use {}, only: &'.format(_INDENT, _CONST_PROP_MOD)) lines.append('{}{}, &'.format(_INDENT * 2, _CONST_DDT)) lines.append('{}{}, &'.format(_INDENT * 2, _CONST_PROP_TYPE)) diff --git a/capgen/src/ccpp_scheme_utils.F90 b/capgen/src/ccpp_scheme_utils.F90 index d4de6499..73d01bb3 100644 --- a/capgen/src/ccpp_scheme_utils.F90 +++ b/capgen/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 ! Utility to 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/end-to-end-tests/advection/test_host_data.F90 b/end-to-end-tests/advection/test_host_data.F90 index 4bcb753b..991a61ce 100644 --- a/end-to-end-tests/advection/test_host_data.F90 +++ b/end-to-end-tests/advection/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 be37601abcb171c98e7a7a060b30dffdcf8f7813 Mon Sep 17 00:00:00 2001 From: peverwhee Date: Thu, 9 Jul 2026 16:27:08 -0600 Subject: [PATCH 2/4] move to_lower to constituent mod --- capgen/generator/host_constituents.py | 2 +- capgen/src/ccpp_constituent_prop_mod.F90 | 35 ++++++++++++++++++++++++ capgen/src/ccpp_scheme_utils.F90 | 32 +--------------------- 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/capgen/generator/host_constituents.py b/capgen/generator/host_constituents.py index f895b2a8..72ce6db6 100644 --- a/capgen/generator/host_constituents.py +++ b/capgen/generator/host_constituents.py @@ -580,7 +580,7 @@ def _generate_host_constituents( lines.append('module {}'.format(_HOST_CONST_MOD)) lines.append('') lines.append('{}use ccpp_kinds, only: kind_phys'.format(_INDENT)) - lines.append('{}use ccpp_scheme_utils, only: to_lower'.format(_INDENT)) + lines.append('{}use ccpp_constituent_prop_mod, only: to_lower'.format(_INDENT)) lines.append('{}use {}, only: &'.format(_INDENT, _CONST_PROP_MOD)) lines.append('{}{}, &'.format(_INDENT * 2, _CONST_DDT)) lines.append('{}{}, &'.format(_INDENT * 2, _CONST_PROP_TYPE)) diff --git a/capgen/src/ccpp_constituent_prop_mod.F90 b/capgen/src/ccpp_constituent_prop_mod.F90 index dbe33f84..fdcd67b7 100644 --- a/capgen/src/ccpp_constituent_prop_mod.F90 +++ b/capgen/src/ccpp_constituent_prop_mod.F90 @@ -211,6 +211,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 @@ -2676,4 +2679,36 @@ 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/capgen/src/ccpp_scheme_utils.F90 b/capgen/src/ccpp_scheme_utils.F90 index 73d01bb3..d91f0580 100644 --- a/capgen/src/ccpp_scheme_utils.F90 +++ b/capgen/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 @@ -120,34 +120,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 c8ae6e13bb04d8de9eebfa31b4658438dc11ef59 Mon Sep 17 00:00:00 2001 From: peverwhee Date: Thu, 9 Jul 2026 16:51:48 -0600 Subject: [PATCH 3/4] lowercase instantiated standard names --- capgen/src/ccpp_constituent_prop_mod.F90 | 2 +- end-to-end-tests/advection/cld_liq.F90 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/capgen/src/ccpp_constituent_prop_mod.F90 b/capgen/src/ccpp_constituent_prop_mod.F90 index fdcd67b7..ad401ce9 100644 --- a/capgen/src/ccpp_constituent_prop_mod.F90 +++ b/capgen/src/ccpp_constituent_prop_mod.F90 @@ -419,7 +419,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/end-to-end-tests/advection/cld_liq.F90 b/end-to-end-tests/advection/cld_liq.F90 index c0d00a43..53cd68c1 100644 --- a/end-to-end-tests/advection/cld_liq.F90 +++ b/end-to-end-tests/advection/cld_liq.F90 @@ -30,7 +30,7 @@ subroutine cld_liq_register(dyn_const, errmsg, errcode) 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 9cb9a6ffaaa1e601a3aec63782905ebaf5b321b2 Mon Sep 17 00:00:00 2001 From: peverwhee Date: Thu, 9 Jul 2026 17:05:05 -0600 Subject: [PATCH 4/4] fix formatting --- capgen/src/ccpp_constituent_prop_mod.F90 | 29 +++++++++--------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/capgen/src/ccpp_constituent_prop_mod.F90 b/capgen/src/ccpp_constituent_prop_mod.F90 index ad401ce9..060277d2 100644 --- a/capgen/src/ccpp_constituent_prop_mod.F90 +++ b/capgen/src/ccpp_constituent_prop_mod.F90 @@ -2683,30 +2683,23 @@ end subroutine ccpt_set_water_species function to_lower(str) - implicit none + character(len=*), intent(in) :: str ! String to convert to lower case + character(len=len(str)) :: to_lower - ! !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 + ! 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