Skip to content

Commit 6c494b2

Browse files
Capgen in SCM: Multiple instances of local_name in Group Cap (#631)
Description: Allow for multiple instances of the same local_name being used in the Group cap for two situations: a) with different standard_names b) in different DDTs . User interface changes?: No Fixes: #629 Testing: Added to var_compatibility_test to exercise feature. This PR contains changes included in #630 --------- Co-authored-by: Dom Heinzeller <dom.heinzeller@icloud.com>
1 parent aed2471 commit 6c494b2

File tree

14 files changed

+114
-7
lines changed

14 files changed

+114
-7
lines changed

scripts/metavar.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,12 +1677,37 @@ def add_variable(self, newvar, run_env, exists_ok=False, gen_unique=False,
16771677
context=newvar.context)
16781678
# end if
16791679
# end if
1680+
# Check if local_name exists in Group. If applicable, Create new
1681+
# variable with unique name. There are two instances when new names are
1682+
# created:
1683+
# - Same <local_name> used in different DDTs.
1684+
# - Different <standard_name> using the same <local_name> in a Group.
1685+
# During the Group analyze phase, <gen_unique> is True.
16801686
lname = newvar.get_prop_value('local_name')
16811687
lvar = self.find_local_name(lname)
16821688
if lvar is not None:
1689+
# Check if <lvar> is part of a different DDT than <newvar>.
1690+
# The API uses the full variable references when calling the Group Caps,
1691+
# <lvar.call_string(self))> and <newvar.call_string(self)>.
1692+
# Within the context of a full reference, it is allowable for local_names
1693+
# to be the same in different data containers.
1694+
newvar_callstr = newvar.call_string(self)
1695+
lvar_callstr = lvar.call_string(self)
1696+
if newvar_callstr and lvar_callstr:
1697+
if newvar_callstr != lvar_callstr:
1698+
if not gen_unique:
1699+
exists_ok = True
1700+
# end if
1701+
# end if
1702+
# end if
16831703
if gen_unique:
16841704
new_lname = self.new_internal_variable_name(prefix=lname)
16851705
newvar = newvar.clone(new_lname)
1706+
# Local_name needs to be the local_name for the new
1707+
# internal variable, otherwise multiple instances of the same
1708+
# local_name in the Group cap will all be overwritten with the
1709+
# same local_name
1710+
lname = new_lname
16861711
elif not exists_ok:
16871712
errstr = 'Invalid local_name: {} already registered{}'
16881713
cstr = context_string(lvar.source.context, with_comma=True)

scripts/suite_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ def manage_variable(self, newvar):
22732273
ParseSource(_API_SOURCE_NAME,
22742274
_API_LOCAL_VAR_NAME, newvar.context),
22752275
self.run_env)
2276-
self.add_variable(local_var, self.run_env, exists_ok=True)
2276+
self.add_variable(local_var, self.run_env, exists_ok=True, gen_unique=True)
22772277
# Finally, make sure all dimensions are accounted for
22782278
emsg = self.add_variable_dimensions(local_var, _API_LOCAL_VAR_TYPES,
22792279
adjust_intent=True,

test/var_compatibility_test/effr_diag.F90

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ end subroutine effr_diag_init
3636
!> \section arg_table_effr_diag_run Argument Table
3737
!! \htmlinclude arg_table_effr_diag_run.html
3838
!!
39-
subroutine effr_diag_run( effrr_in, errmsg, errflg)
39+
subroutine effr_diag_run( effrr_in, scalar_var, errmsg, errflg)
4040

4141
real(kind_phys), intent(in) :: effrr_in(:,:)
42+
integer, intent(in) :: scalar_var
4243
character(len=512), intent(out) :: errmsg
4344
integer, intent(out) :: errflg
4445
!----------------------------------------------------------------
@@ -49,6 +50,10 @@ subroutine effr_diag_run( effrr_in, errmsg, errflg)
4950

5051
call cmp_effr_diag(effrr_in, effrr_min, effrr_max)
5152

53+
if (scalar_var .ne. 380) then
54+
errmsg = 'ERROR: effr_diag_run(): scalar_var should be 380'
55+
errflg = 1
56+
endif
5257
end subroutine effr_diag_run
5358

5459
subroutine cmp_effr_diag(effr, effr_min, effr_max)

test/var_compatibility_test/effr_diag.meta

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
kind = kind_phys
4242
intent = in
4343
top_at_one = True
44+
[ scalar_var ]
45+
standard_name = scalar_variable_for_testing_c
46+
long_name = unused scalar variable C
47+
units = m
48+
dimensions = ()
49+
type = integer
50+
intent = in
4451
[ errmsg ]
4552
standard_name = ccpp_error_message
4653
long_name = Error message for error handling in CCPP

test/var_compatibility_test/effr_post.F90

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ end subroutine effr_post_init
3636
!> \section arg_table_effr_post_run Argument Table
3737
!! \htmlinclude arg_table_effr_post_run.html
3838
!!
39-
subroutine effr_post_run( effrr_inout, errmsg, errflg)
39+
subroutine effr_post_run( effrr_inout, scalar_var, errmsg, errflg)
4040

4141
real(kind_phys), intent(inout) :: effrr_inout(:,:)
42+
real(kind_phys), intent(in) :: scalar_var
4243
character(len=512), intent(out) :: errmsg
4344
integer, intent(out) :: errflg
4445
!----------------------------------------------------------------
@@ -50,6 +51,11 @@ subroutine effr_post_run( effrr_inout, errmsg, errflg)
5051
! Do some post-processing on effrr...
5152
effrr_inout(:,:) = effrr_inout(:,:)*1._kind_phys
5253

54+
if (scalar_var .ne. 1013.0) then
55+
errmsg = 'ERROR: effr_post_run(): scalar_var should be 1013.0'
56+
errflg = 1
57+
endif
58+
5359
end subroutine effr_post_run
5460

5561
end module effr_post

test/var_compatibility_test/effr_post.meta

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
type = real
4141
kind = kind_phys
4242
intent = inout
43+
[ scalar_var ]
44+
standard_name = scalar_variable_for_testing_b
45+
long_name = unused scalar variable B
46+
units = m
47+
dimensions = ()
48+
type = real
49+
kind = kind_phys
50+
intent = in
4351
[ errmsg ]
4452
standard_name = ccpp_error_message
4553
long_name = Error message for error handling in CCPP

test/var_compatibility_test/effr_pre.F90

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ end subroutine effr_pre_init
3535
!> \section arg_table_effr_pre_run Argument Table
3636
!! \htmlinclude arg_table_effr_pre_run.html
3737
!!
38-
subroutine effr_pre_run( effrr_inout, errmsg, errflg)
38+
subroutine effr_pre_run( effrr_inout, scalar_var, errmsg, errflg)
3939

4040
real(kind_phys), intent(inout) :: effrr_inout(:,:)
41+
real(kind_phys), intent(in) :: scalar_var
4142
character(len=512), intent(out) :: errmsg
4243
integer, intent(out) :: errflg
4344
!----------------------------------------------------------------
@@ -49,6 +50,11 @@ subroutine effr_pre_run( effrr_inout, errmsg, errflg)
4950
! Do some pre-processing on effrr...
5051
effrr_inout(:,:) = effrr_inout(:,:)*1._kind_phys
5152

53+
if (scalar_var .ne. 273.15) then
54+
errmsg = 'ERROR: effr_pre_run(): scalar_var should be 273.15'
55+
errflg = 1
56+
endif
57+
5258
end subroutine effr_pre_run
5359

5460
end module effr_pre

test/var_compatibility_test/effr_pre.meta

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
type = real
4141
kind = kind_phys
4242
intent = inout
43+
[ scalar_var ]
44+
standard_name = scalar_variable_for_testing_a
45+
long_name = unused scalar variable A
46+
units = m
47+
dimensions = ()
48+
type = real
49+
kind = kind_phys
50+
intent = in
4351
[ errmsg ]
4452
standard_name = ccpp_error_message
4553
long_name = Error message for error handling in CCPP

test/var_compatibility_test/run_test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ required_vars_var_compatibility="${required_vars_var_compatibility},horizontal_d
144144
required_vars_var_compatibility="${required_vars_var_compatibility},horizontal_loop_begin"
145145
required_vars_var_compatibility="${required_vars_var_compatibility},horizontal_loop_end"
146146
required_vars_var_compatibility="${required_vars_var_compatibility},scalar_variable_for_testing"
147+
required_vars_var_compatibility="${required_vars_var_compatibility},scalar_variable_for_testing_a"
148+
required_vars_var_compatibility="${required_vars_var_compatibility},scalar_variable_for_testing_b"
149+
required_vars_var_compatibility="${required_vars_var_compatibility},scalar_variable_for_testing_c"
147150
required_vars_var_compatibility="${required_vars_var_compatibility},scheme_order_in_suite"
148151
required_vars_var_compatibility="${required_vars_var_compatibility},vertical_layer_dimension"
149152
input_vars_var_compatibility="cloud_graupel_number_concentration"
@@ -158,6 +161,9 @@ input_vars_var_compatibility="${input_vars_var_compatibility},horizontal_dimensi
158161
input_vars_var_compatibility="${input_vars_var_compatibility},horizontal_loop_begin"
159162
input_vars_var_compatibility="${input_vars_var_compatibility},horizontal_loop_end"
160163
input_vars_var_compatibility="${input_vars_var_compatibility},scalar_variable_for_testing"
164+
input_vars_var_compatibility="${input_vars_var_compatibility},scalar_variable_for_testing_a"
165+
input_vars_var_compatibility="${input_vars_var_compatibility},scalar_variable_for_testing_b"
166+
input_vars_var_compatibility="${input_vars_var_compatibility},scalar_variable_for_testing_c"
161167
input_vars_var_compatibility="${input_vars_var_compatibility},scheme_order_in_suite"
162168
input_vars_var_compatibility="${input_vars_var_compatibility},vertical_layer_dimension"
163169
output_vars_var_compatibility="ccpp_error_code,ccpp_error_message"

test/var_compatibility_test/test_host.F90

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,16 @@ program test
351351

352352
character(len=cs), target :: test_parts1(1) = (/ 'radiation ' /)
353353

354-
character(len=cm), target :: test_invars1(9) = (/ &
354+
character(len=cm), target :: test_invars1(12) = (/ &
355355
'effective_radius_of_stratiform_cloud_rain_particle ', &
356356
'effective_radius_of_stratiform_cloud_liquid_water_particle', &
357357
'effective_radius_of_stratiform_cloud_snow_particle ', &
358358
'effective_radius_of_stratiform_cloud_graupel ', &
359359
'cloud_graupel_number_concentration ', &
360360
'scalar_variable_for_testing ', &
361+
'scalar_variable_for_testing_a ', &
362+
'scalar_variable_for_testing_b ', &
363+
'scalar_variable_for_testing_c ', &
361364
'scheme_order_in_suite ', &
362365
'flag_indicating_cloud_microphysics_has_graupel ', &
363366
'flag_indicating_cloud_microphysics_has_ice '/)
@@ -374,7 +377,7 @@ program test
374377
'scheme_order_in_suite '/)
375378

376379

377-
character(len=cm), target :: test_reqvars1(13) = (/ &
380+
character(len=cm), target :: test_reqvars1(16) = (/ &
378381
'ccpp_error_code ', &
379382
'ccpp_error_message ', &
380383
'effective_radius_of_stratiform_cloud_rain_particle ', &
@@ -385,6 +388,9 @@ program test
385388
'cloud_graupel_number_concentration ', &
386389
'cloud_ice_number_concentration ', &
387390
'scalar_variable_for_testing ', &
391+
'scalar_variable_for_testing_a ', &
392+
'scalar_variable_for_testing_b ', &
393+
'scalar_variable_for_testing_c ', &
388394
'scheme_order_in_suite ', &
389395
'flag_indicating_cloud_microphysics_has_graupel ', &
390396
'flag_indicating_cloud_microphysics_has_ice '/)

0 commit comments

Comments
 (0)