@@ -141,7 +141,7 @@ class VarBase:
141
141
__pointer_type_str = "pointer"
142
142
143
143
def __init__ (self , elem_node , local_name , dimensions , known_types ,
144
- type_default , units_default = "" , kind_default = '' ,
144
+ type_default , units_default = "" , kind_default = '' , dycore = '' ,
145
145
protected = False , index_name = '' , local_index_name = '' ,
146
146
local_index_name_str = '' , alloc_default = 'none' ,
147
147
tstep_init_default = False ):
@@ -154,6 +154,7 @@ def __init__(self, elem_node, local_name, dimensions, known_types,
154
154
self .__standard_name = elem_node .get ('standard_name' )
155
155
self .__long_name = ''
156
156
self .__initial_value = ''
157
+ self .__initial_value_match = 0
157
158
self .__initial_val_vars = set ()
158
159
self .__ic_names = None
159
160
self .__elements = []
@@ -183,7 +184,30 @@ def __init__(self, elem_node, local_name, dimensions, known_types,
183
184
if attrib .tag == 'long_name' :
184
185
self .__long_name = attrib .text
185
186
elif attrib .tag == 'initial_value' :
186
- self .__initial_value = attrib .text
187
+ # Figure out if we should use this initial_value
188
+ # If the number of matching attributes is greater than the
189
+ # default or a previous match, pick this one
190
+ matches = 0
191
+ if not attrib .keys ():
192
+ self .__initial_value = attrib .text
193
+ # end if (no attributes, this is the default)
194
+ for att in attrib .keys ():
195
+ # Check each attribute (for now, this is only the dycore)
196
+ if att == 'dyn' :
197
+ dycore_list = attrib .get ('dyn' ).lower ().split (',' )
198
+ if dycore in dycore_list :
199
+ matches += 1
200
+ # end if (dycore matches)
201
+ # end if (check the dycore)
202
+ # end for
203
+ if matches == self .__initial_value_match and matches != 0 :
204
+ emsg = f"Unclear which initial_value to use for { local_name } . There are at least two configurations with { matches } matching attributes"
205
+ raise CCPPError (emsg )
206
+ elif matches > self .__initial_value_match :
207
+ # Use this initial_value (for now)
208
+ self .__initial_value_match = matches
209
+ self .__initial_value = attrib .text
210
+ # end if (number of matches)
187
211
elif attrib .tag == 'ic_file_input_names' :
188
212
#Separate out string into list:
189
213
self .__ic_names = [x .strip () for x in attrib .text .split (' ' ) if x ]
@@ -488,16 +512,16 @@ class Variable(VarBase):
488
512
###############################################################################
489
513
# pylint: disable=too-many-instance-attributes
490
514
"""Registry variable
491
- >>> Variable(ET.fromstring('<variable kind="kind_phys" local_name="u" standard_name="east_wind" type="real" units="m s-1"><dimensions>ccpp_constant_one:horizontal_dimension:two</dimensions></variable>'), TypeRegistry(), VarDict("foo", "module", None), None) #doctest: +IGNORE_EXCEPTION_DETAIL
515
+ >>> Variable(ET.fromstring('<variable kind="kind_phys" local_name="u" standard_name="east_wind" type="real" units="m s-1"><dimensions>ccpp_constant_one:horizontal_dimension:two</dimensions></variable>'), TypeRegistry(), VarDict("foo", "module", None), 'se', None) #doctest: +IGNORE_EXCEPTION_DETAIL
492
516
Traceback (most recent call last):
493
517
CCPPError: Illegal dimension string, ccpp_constant_one:horizontal_dimension:two, in u, step not allowed.
494
- >>> Variable(ET.fromstring('<variable kind="kind_phys" local_name="u" standard_name="east_wind" type="real" units="m s-1"><dims>horizontal_dimension</dims></variable>'), TypeRegistry(), VarDict("foo", "module", None), None) #doctest: +IGNORE_EXCEPTION_DETAIL
518
+ >>> Variable(ET.fromstring('<variable kind="kind_phys" local_name="u" standard_name="east_wind" type="real" units="m s-1"><dims>horizontal_dimension</dims></variable>'), TypeRegistry(), VarDict("foo", "module", None), 'se', None) #doctest: +IGNORE_EXCEPTION_DETAIL
495
519
Traceback (most recent call last):
496
520
CCPPError: Unknown Variable content, dims
497
- >>> Variable(ET.fromstring('<variable kkind="kind_phys" local_name="u" standard_name="east_wind" type="real" units="m s-1"></variable>'), TypeRegistry(), VarDict("foo", "module", None), None) #doctest: +IGNORE_EXCEPTION_DETAIL
521
+ >>> Variable(ET.fromstring('<variable kkind="kind_phys" local_name="u" standard_name="east_wind" type="real" units="m s-1"></variable>'), TypeRegistry(), VarDict("foo", "module", None), 'se', None) #doctest: +IGNORE_EXCEPTION_DETAIL
498
522
Traceback (most recent call last):
499
523
CCPPError: Bad variable attribute, 'kkind', for 'u'
500
- >>> Variable(ET.fromstring('<variable kind="kind_phys" local_name="u" standard_name="east_wind" type="real" units="m s-1" allocatable="target"><dimensions>horizontal_dimension vertical_dimension</dimensions></variable>'), TypeRegistry(), VarDict("foo", "module", None), None) #doctest: +IGNORE_EXCEPTION_DETAIL
524
+ >>> Variable(ET.fromstring('<variable kind="kind_phys" local_name="u" standard_name="east_wind" type="real" units="m s-1" allocatable="target"><dimensions>horizontal_dimension vertical_dimension</dimensions></variable>'), TypeRegistry(), VarDict("foo", "module", None), 'se', None) #doctest: +IGNORE_EXCEPTION_DETAIL
501
525
Traceback (most recent call last):
502
526
CCPPError: Dimension, 'vertical_dimension', not found for 'u'
503
527
"""
@@ -511,7 +535,7 @@ class Variable(VarBase):
511
535
"phys_timestep_init_zero" , "standard_name" ,
512
536
"type" , "units" , "version" ]
513
537
514
- def __init__ (self , var_node , known_types , vdict , logger ):
538
+ def __init__ (self , var_node , known_types , vdict , dycore , logger ):
515
539
# pylint: disable=too-many-locals
516
540
"""Initialize a Variable from registry XML"""
517
541
local_name = var_node .get ('local_name' )
@@ -588,7 +612,7 @@ def __init__(self, var_node, known_types, vdict, logger):
588
612
# Initialize the base class
589
613
super ().__init__ (var_node , local_name ,
590
614
my_dimensions , known_types , ttype ,
591
- protected = protected )
615
+ dycore = dycore , protected = protected )
592
616
593
617
for attrib in var_node :
594
618
# Second pass, only process array elements
@@ -1090,7 +1114,7 @@ def __init__(self, ddt_node, known_types, var_dict, dycore):
1090
1114
varname = attrib .text
1091
1115
include_var = True
1092
1116
attrib_dycores = [x .strip ().lower () for x in
1093
- attrib .get ('dycore ' , default = "" ).split (',' )
1117
+ attrib .get ('dyn ' , default = "" ).split (',' )
1094
1118
if x ]
1095
1119
if attrib_dycores and (dycore not in attrib_dycores ):
1096
1120
include_var = False
@@ -1226,6 +1250,7 @@ def __init__(self, file_node, known_types, dycore,
1226
1250
self .__use_statements = []
1227
1251
self .__generate_code = gen_code
1228
1252
self .__file_path = file_path
1253
+ self .__dycore = dycore
1229
1254
for obj in file_node :
1230
1255
if obj .tag in ['variable' , 'array' ]:
1231
1256
self .add_variable (obj , logger )
@@ -1252,7 +1277,7 @@ def add_variable(self, var_node, logger):
1252
1277
"""Create a Variable from <var_node> and add to this File's
1253
1278
variable dictionary"""
1254
1279
newvar = Variable (var_node , self .__known_types , self .__var_dict ,
1255
- logger )
1280
+ self . __dycore , logger )
1256
1281
self .__var_dict .add_variable (newvar )
1257
1282
1258
1283
def add_ddt (self , newddt , logger = None ):
0 commit comments