Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add active attribute and update true/false logic in metavar.py, update example metadata table in metadata_table.py #396

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions scripts/metadata_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
[ccpp-table-properties]
name = <name>
type = scheme
relative_path = <relative path>
dependencies = <dependencies>

[ccpp-arg-table]
name = <name>
type = scheme
Expand All @@ -71,21 +74,21 @@
type = integer
dimensions = ()
intent = in
[ ix ]
[ ix ]
standard_name = horizontal_loop_dimension
long_name = horizontal dimension
units = index | type = integer | dimensions = ()
intent = in
...
[ errmsg]
[ errmsg]
standard_name = ccpp_error_message
long_name = error message for error handling in CCPP
units = none
type = character
len = *
dimensions = ()
intent = out
[ ierr ]
[ ierr ]
standard_name = ccpp_error_flag
long_name = error flag for error handling in CCPP
type = integer
Expand Down
19 changes: 15 additions & 4 deletions scripts/metavar.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ class VariableProperty(object):
'q(:,:,index_of_water_vapor_specific_humidity)'
"""

__true_vals = ['t', 'true', '.true.']
__false_vals = ['f', 'false', '.false.']

def __init__(self, name_in, type_in, valid_values_in=None,
optional_in=False, default_in=None, default_fn_in=None,
check_fn_in=None, mult_entry_ok=False):
Expand Down Expand Up @@ -408,9 +411,11 @@ def valid_value(self, test_value, prop_dict=None, error=False):
pass
elif self.type is bool:
if isinstance(test_value, str):
valid_val = ((test_value in ['True', 'False']) or
(test_value.lower() in
['t', 'f', '.true.', '.false.']))
if test_value.lower() in VariableProperty.__true_vals + VariableProperty.__false_vals:
valid_val = test_value.lower() in VariableProperty.__true_vals
else:
valid_val = None # i.e., pass
# end if
else:
valid_val = not not test_value # pylint: disable=unneeded-not
elif self.type is str:
Expand Down Expand Up @@ -457,6 +462,10 @@ class Var(object):

>>> Var.get_prop('dimensions').valid_value(['Bob', 'Ray'])
['Bob', 'Ray']
>>> Var.get_prop('active')
'.true.'
>>> Var.get_prop('active').valid_value('flag_for_aerosol_physics')
'flag_for_aerosol_physics'
>>> Var({'local_name' : 'foo', 'standard_name' : 'hi_mom', 'units' : 'm/s', 'dimensions' : '()', 'type' : 'real', 'intent' : 'in'}, ParseSource('vname', 'SCHEME', ParseContext())).get_prop_value('long_name')
'Hi mom'
>>> Var({'local_name' : 'foo', 'standard_name' : 'hi_mom', 'units' : 'm/s', 'dimensions' : '()', 'type' : 'real', 'intent' : 'in'}, ParseSource('vname', 'SCHEME', ParseContext())).get_prop_value('intent')
Expand Down Expand Up @@ -520,7 +529,9 @@ class Var(object):
check_fn_in=check_default_value),
VariableProperty('persistence', str, optional_in=True,
valid_values_in=['timestep', 'run'],
default_in='timestep')]
default_in='timestep'),
VariableProperty('active', str, optional_in=True,
default_in='.true.')]

# XXgoldyXX: v debug only
__to_add = VariableProperty('valid_values', str,
Expand Down