Skip to content

Commit

Permalink
Merge pull request #8 from climbfuji/update_gsd_develop_from_master_2…
Browse files Browse the repository at this point in the history
…0200903

Update gsd/develop from master 2020/10/01
  • Loading branch information
DomHeinzeller authored Oct 2, 2020
2 parents 0b84bec + e2b612a commit 7b8df4b
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 110 deletions.
Empty file removed .gitmodules
Empty file.
125 changes: 75 additions & 50 deletions scripts/ccpp_prebuild.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import subprocess
import sys

CCPP_STAGES = [ 'init', 'run', 'finalize' ]

CCPP_ERROR_FLAG_VARIABLE = 'ccpp_error_flag'
CCPP_ERROR_MSG_VARIABLE = 'ccpp_error_message'
CCPP_LOOP_COUNTER = 'ccpp_loop_counter'
Expand Down
150 changes: 118 additions & 32 deletions scripts/metadata_parser.py

Large diffs are not rendered by default.

42 changes: 37 additions & 5 deletions scripts/metadata_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
An example argument table is shown below (aside from the python comment
character at the start of each line).
[ccpp-table-properties]
name = <name>
type = scheme
relative_path = <relative path>
dependencies = <dependencies>
[ccpp-arg-table]
name = <name>
type = scheme
Expand Down Expand Up @@ -94,6 +100,7 @@
import os
import re
# CCPP framework imports
from common import CCPP_STAGES
from metavar import Var, VarDictionary
from parse_tools import ParseObject, ParseSource, register_fortran_ddt_name
from parse_tools import ParseInternalError, ParseSyntaxError, CCPPError
Expand Down Expand Up @@ -170,7 +177,7 @@ class MetadataHeader(ParseSource):
<_sre.SRE_Match object at 0x...>
"""

__header_start__ = re.compile(r"(?i)\s*\[\s*ccpp-arg-table\s*\]")
__header_start__ = re.compile(r"(?i)\s*\[\s*(ccpp-table-properties|ccpp-arg-table)\s*\]")

__var_start__ = re.compile(r"^\[\s*("+FORTRAN_ID+r"|"+LITERAL_INT+r"|"+FORTRAN_SCALAR_REF+r")\s*\]$")

Expand All @@ -191,7 +198,7 @@ class MetadataHeader(ParseSource):

def __init__(self, parse_object=None,
title=None, type_in=None, module=None, var_dict=None,
logger=None):
property_table=False, logger=None):
self._pobj = parse_object
"""If <parse_object> is not None, initialize from the current file and
location in <parse_object>.
Expand Down Expand Up @@ -223,7 +230,7 @@ def __init__(self, parse_object=None,
self._variables.add_variable(var)
# End for
else:
self.__init_from_file__(parse_object, logger)
self.__init_from_file__(parse_object, property_table, logger)
# End if
# Categorize the variables
self._var_intents = {'in' : list(), 'out' : list(), 'inout' : list()}
Expand All @@ -234,13 +241,16 @@ def __init__(self, parse_object=None,
# End if
# End for

def __init_from_file__(self, parse_object, logger):
def __init_from_file__(self, parse_object, property_table, logger):
# Read the table preamble, assume the caller already figured out
# the first line of the header using the table_start method.
curr_line, curr_line_num = self._pobj.next_line()
self._table_title = None
self._header_type = None
self._module_name = None
self._dependencies = []
relative_path_local = ''
self._property_table = property_table
while (curr_line is not None) and (not self.variable_start(curr_line)) and (not MetadataHeader.table_start(curr_line)):
for property in self.parse_config_line(curr_line):
# Manually parse name, type, and module properties
Expand All @@ -262,6 +272,12 @@ def __init_from_file__(self, parse_object, logger):
else:
self._module_name = value
# End if
elif key == 'dependencies':
if not(value == "None" or value == ""):
# Remove trailing comma, remove white spaces from each list element
self._dependencies += [ v.strip() for v in value.rstrip(",").split(",") ]
elif key == 'relative_path':
relative_path_local = value.strip()
else:
raise ParseSyntaxError("metadata table start property",
token=value, context=self._pobj)
Expand All @@ -278,6 +294,9 @@ def __init_from_file__(self, parse_object, logger):
elif self.header_type == "ddt":
register_fortran_ddt_name(self.title)
# End if
# Add relative path to dependencies
if self.dependencies and relative_path_local:
self._dependencies = [ os.path.join(relative_path_local, v) for v in self.dependencies]
# Initialize our ParseSource parent
super(MetadataHeader, self).__init__(self.title,
self.header_type, self._pobj)
Expand Down Expand Up @@ -490,6 +509,16 @@ def header_type(self):
'Return the type of structure this header documents'
return self._header_type

@property
def dependencies(self):
'Return the dependencies of the metadata scheme properties table'
return self._dependencies

@property
def property_table(self):
'Return True iff table is a ccpp-table-properties table'
return self._property_table

@classmethod
def is_blank(cls, line):
"Return True iff <line> is a valid config format blank or comment line"
Expand Down Expand Up @@ -526,7 +555,10 @@ def parse_metadata_file(cls, filename):
curr_line, curr_line_num = parse_obj.curr_line()
while curr_line is not None:
if MetadataHeader.table_start(curr_line):
mheaders.append(MetadataHeader(parse_obj))
if '[ccpp-table-properties]' in curr_line:
mheaders.append(MetadataHeader(parse_obj, property_table=True))
else:
mheaders.append(MetadataHeader(parse_obj))
curr_line, curr_line_num = parse_obj.curr_line()
else:
curr_line, curr_line_num = parse_obj.next_line()
Expand Down
2 changes: 1 addition & 1 deletion scripts/metavar.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def __init__(self, prop_dict, source, invalid_ok=False, logger=None):
of a Var object with invalid properties.
In order to prevent silent failures, invalid_ok requires a logger
in order to take effect."""
if source.type is 'SCHEME':
if source.type == 'SCHEME':
required_props = Var.__required_var_props
master_propdict = Var.__var_propdict
else:
Expand Down
37 changes: 16 additions & 21 deletions scripts/mkstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import xml.etree.ElementTree as ET

from common import encode_container
from common import CCPP_STAGES
from common import CCPP_ERROR_FLAG_VARIABLE, CCPP_ERROR_MSG_VARIABLE, CCPP_LOOP_COUNTER
from common import CCPP_BLOCK_NUMBER, CCPP_BLOCK_COUNT, CCPP_BLOCK_SIZES, CCPP_INTERNAL_VARIABLES
from common import CCPP_HORIZONTAL_DIMENSION, CCPP_HORIZONTAL_LOOP_EXTENT
Expand All @@ -23,12 +24,6 @@

###############################################################################

#STANDARD_VARIABLE_TYPES = [ 'character', 'integer', 'logical', 'real' ]

#CCPP_ERROR_FLAG_VARIABLE = 'error_flag'

CCPP_STAGES = [ 'init', 'run', 'finalize' ]

# Maximum number of dimensions of an array allowed by the Fortran 2008 standard
FORTRAN_ARRAY_MAX_DIMS = 15

Expand Down Expand Up @@ -921,7 +916,7 @@ def write(self, metadata_request, metadata_define, arguments):
subroutine_name = scheme_name + '_' + ccpp_stage
container = encode_container(module_name, scheme_name, subroutine_name)
# Skip entirely empty routines
if not arguments[module_name][scheme_name][subroutine_name]:
if not arguments[scheme_name][subroutine_name]:
continue
error_check = ''
args = ''
Expand All @@ -930,7 +925,7 @@ def write(self, metadata_request, metadata_define, arguments):
# First identify all dimensions needed to handle the arguments
# and add them to the list of required variables for the cap
additional_variables_required = []
for var_standard_name in arguments[module_name][scheme_name][subroutine_name]:
for var_standard_name in arguments[scheme_name][subroutine_name]:
if not var_standard_name in metadata_define.keys():
raise Exception('Variable {standard_name} not defined in host model metadata'.format(
standard_name=var_standard_name))
Expand All @@ -943,22 +938,22 @@ def write(self, metadata_request, metadata_define, arguments):
dim = int(dim)
except ValueError:
if not dim in local_vars.keys() and \
not dim in additional_variables_required + arguments[module_name][scheme_name][subroutine_name]:
not dim in additional_variables_required + arguments[scheme_name][subroutine_name]:
logging.debug("Adding dimension {} for variable {}".format(dim, var_standard_name))
additional_variables_required.append(dim)

# If blocked data structures need to be converted, add necessary variables
if ccpp_stage in ['init', 'finalize'] and CCPP_INTERNAL_VARIABLES[CCPP_BLOCK_NUMBER] in var.local_name:
if not CCPP_BLOCK_COUNT in local_vars.keys() \
and not CCPP_BLOCK_COUNT in additional_variables_required + arguments[module_name][scheme_name][subroutine_name]:
and not CCPP_BLOCK_COUNT in additional_variables_required + arguments[scheme_name][subroutine_name]:
logging.debug("Adding variable {} for handling blocked data structures".format(CCPP_BLOCK_COUNT))
additional_variables_required.append(CCPP_BLOCK_COUNT)
if not CCPP_HORIZONTAL_LOOP_EXTENT in local_vars.keys() \
and not CCPP_HORIZONTAL_LOOP_EXTENT in additional_variables_required + arguments[module_name][scheme_name][subroutine_name]:
and not CCPP_HORIZONTAL_LOOP_EXTENT in additional_variables_required + arguments[scheme_name][subroutine_name]:
logging.debug("Adding variable {} for handling blocked data structures".format(CCPP_HORIZONTAL_LOOP_EXTENT))
additional_variables_required.append(CCPP_HORIZONTAL_LOOP_EXTENT)
if not CCPP_HORIZONTAL_DIMENSION in local_vars.keys() \
and not CCPP_HORIZONTAL_DIMENSION in additional_variables_required + arguments[module_name][scheme_name][subroutine_name]:
and not CCPP_HORIZONTAL_DIMENSION in additional_variables_required + arguments[scheme_name][subroutine_name]:
logging.debug("Adding variable {} for handling blocked data structures".format(CCPP_HORIZONTAL_DIMENSION))
additional_variables_required.append(CCPP_HORIZONTAL_DIMENSION)

Expand All @@ -973,7 +968,7 @@ def write(self, metadata_request, metadata_define, arguments):
conditional = ''
# Find all words in the conditional, for each of them look for a matching
# standard name in the list of known variables
items = FORTRAN_CONDITIONAL_REGEX.findall(var.active.lower())
items = FORTRAN_CONDITIONAL_REGEX.findall(var.active)
for item in items:
if item in FORTRAN_CONDITIONAL_REGEX_WORDS:
conditional += item
Expand All @@ -990,18 +985,18 @@ def write(self, metadata_request, metadata_define, arguments):
conditional += var2.local_name
# Add to list of required variables for the cap
if not item in local_vars.keys() \
and not item in additional_variables_required + arguments[module_name][scheme_name][subroutine_name]:
and not item in additional_variables_required + arguments[scheme_name][subroutine_name]:
logging.debug("Adding variable {} for handling conditionals".format(item))
additional_variables_required.append(item)
# Conditionals are identical per requirement, no need to test for consistency again
if not var_standard_name in conditionals.keys():
conditionals[var_standard_name] = conditional

# Extract all variables needed (including indices for components/slices of arrays)
for var_standard_name in additional_variables_required + arguments[module_name][scheme_name][subroutine_name]:
for var_standard_name in additional_variables_required + arguments[scheme_name][subroutine_name]:
# Pick the correct variable for this module/scheme/subroutine
# from the list of requested variable, if it is in that list
if var_standard_name in arguments[module_name][scheme_name][subroutine_name]:
if var_standard_name in arguments[scheme_name][subroutine_name]:
for var in metadata_request[var_standard_name]:
if container == var.container:
break
Expand Down Expand Up @@ -1105,7 +1100,7 @@ def write(self, metadata_request, metadata_define, arguments):

# The remainder of this loop deals with adding variables to the argument list
# for this subroutine, not required for the additional dimensions and variables
if not var_standard_name in arguments[module_name][scheme_name][subroutine_name]:
if not var_standard_name in arguments[scheme_name][subroutine_name]:
continue

# kind_string is used for automated unit conversions, i.e. foo_kind_phys
Expand Down Expand Up @@ -1258,7 +1253,7 @@ def write(self, metadata_request, metadata_define, arguments):
actions_out=actions_out.rstrip('\n'))

# Add to argument list if required
if var_standard_name in arguments[module_name][scheme_name][subroutine_name]:
if var_standard_name in arguments[scheme_name][subroutine_name]:
arg = '{local_name}={var_name},'.format(local_name=var.local_name, var_name=tmpvar.local_name)

# Unit conversions without converting blocked data structures
Expand Down Expand Up @@ -1308,11 +1303,11 @@ def write(self, metadata_request, metadata_define, arguments):
actions_out=actions_out.rstrip('\n'))

# Add to argument list if required
if var_standard_name in arguments[module_name][scheme_name][subroutine_name]:
if var_standard_name in arguments[scheme_name][subroutine_name]:
arg = '{local_name}={var_name},'.format(local_name=var.local_name, var_name=tmpvar.local_name)

# Ordinary variables, no blocked data or unit conversions
elif var_standard_name in arguments[module_name][scheme_name][subroutine_name]:
elif var_standard_name in arguments[scheme_name][subroutine_name]:
# Add to argument list if required
arg = '{local_name}={var_name},'.format(local_name=var.local_name,
var_name=local_vars[var_standard_name]['name'])
Expand All @@ -1321,7 +1316,7 @@ def write(self, metadata_request, metadata_define, arguments):
args += arg
length += len(arg)
# Split args so that lines don't exceed 260 characters (for PGI)
if length > 70 and not var_standard_name == arguments[module_name][scheme_name][subroutine_name][-1]:
if length > 70 and not var_standard_name == arguments[scheme_name][subroutine_name][-1]:
args += ' &\n '
length = 0
args = args.rstrip(',')
Expand Down
12 changes: 11 additions & 1 deletion src/ccpp_types.meta
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[ccpp-table-properties]
name = ccpp_types
type = module
dependencies =

[ccpp-arg-table]
name = ccpp_types
type = module
Expand All @@ -9,9 +14,14 @@
type = ccpp_t

########################################################################
[ccpp-table-properties]
name = ccpp_t
type = ddt
dependencies =

[ccpp-arg-table]
name = ccpp_t
type = scheme
type = ddt
[errflg]
standard_name = ccpp_error_flag
long_name = error flag for error handling in CCPP
Expand Down

0 comments on commit 7b8df4b

Please sign in to comment.