Skip to content
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
c1c6a2a
Merge pull request #307 from climbfuji/update_master_from_gsl_develop…
climbfuji Jul 2, 2020
c5ede56
Merge pull request #6 from climbfuji/update_gsd_develop_from_ncar_mas…
DomHeinzeller Jul 8, 2020
fa73899
Merge branch 'master' of https://github.com/NCAR/ccpp-framework into …
climbfuji Aug 6, 2020
0b84bec
Merge pull request #7 from climbfuji/update_gsd_develop_from_ncar_master
DomHeinzeller Aug 7, 2020
20cc39d
Merge branch 'master' of https://github.com/NCAR/ccpp-framework into …
climbfuji Sep 3, 2020
fd95673
Remove empty .gitmodules
climbfuji Sep 16, 2020
867ce98
Merge branch 'master' of https://github.com/NCAR/ccpp-framework into …
climbfuji Oct 1, 2020
e2b612a
Merge branch 'remove_empty_gitmodules' of https://github.com/climbfuj…
climbfuji Oct 1, 2020
7b8df4b
Merge pull request #8 from climbfuji/update_gsd_develop_from_master_2…
DomHeinzeller Oct 2, 2020
d6cbf7d
scripts/mkstatic.py: add support for unblocked variables in init and …
climbfuji Oct 14, 2020
c171472
scripts/mkstatic.py: variables stored in blocked data structures but …
climbfuji Oct 14, 2020
bede544
Merge pull request #9 from climbfuji/support_unblocked_variables-in_i…
DomHeinzeller Oct 15, 2020
51b910f
Merge branch 'master' of https://github.com/NCAR/ccpp-framework into …
climbfuji Nov 18, 2020
e8c40fb
Merge pull request #10 from climbfuji/update_gsd_develop_from_master_…
DomHeinzeller Nov 20, 2020
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
119 changes: 58 additions & 61 deletions scripts/mkstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,8 +1106,9 @@ def write(self, metadata_request, metadata_define, arguments):
# kind_string is used for automated unit conversions, i.e. foo_kind_phys
kind_string = '_' + local_vars[var_standard_name]['kind'] if local_vars[var_standard_name]['kind'] else ''

# Convert blocked data in init and finalize steps
if ccpp_stage in ['init', 'finalize'] and CCPP_INTERNAL_VARIABLES[CCPP_BLOCK_NUMBER] in local_vars[var_standard_name]['name']:
# Convert blocked data in init and finalize steps - only required for variables with block number and horizontal_dimension
if ccpp_stage in ['init', 'finalize'] and CCPP_INTERNAL_VARIABLES[CCPP_BLOCK_NUMBER] in local_vars[var_standard_name]['name'] \
and CCPP_HORIZONTAL_DIMENSION in var.dimensions:
# Reuse existing temporary variable, if possible
if local_vars[var_standard_name]['name'] in tmpvars.keys():
# If the variable already has a local variable (tmpvar), reuse it
Expand All @@ -1122,59 +1123,50 @@ def write(self, metadata_request, metadata_define, arguments):
tmpvar_cnt += 1
tmpvar = copy.deepcopy(var)
tmpvar.local_name = 'tmpvar{0}'.format(tmpvar_cnt)
# Only variables that contain a horizontal dimension are supported at this time.
if not tmpvar.dimensions:
#actions_in = ???
#actions_out = ???
raise Exception("Cannot handle blocked data for variables w/o a horizontal dimension: {}".format(
var_standard_name))
else:
# Create string for allocating the temporary array by converting the dimensions
# (in standard_name format) to local names as known to the host model
alloc_dimensions = []
for dim in tmpvar.dimensions:
# This is not supported/implemented: tmpvar would have one dimension less
# than the original array, and the metadata requesting the variable would
# not pass the initial test that host model variables and scheme variables
# have the same rank.
if dim == CCPP_BLOCK_NUMBER:
raise Exception("{} cannot be part of the dimensions of variable {}".format(
CCPP_BLOCK_NUMBER, var_standard_name))
#
# Create string for allocating the temporary array by converting the dimensions
# (in standard_name format) to local names as known to the host model
alloc_dimensions = []
for dim in tmpvar.dimensions:
# This is not supported/implemented: tmpvar would have one dimension less
# than the original array, and the metadata requesting the variable would
# not pass the initial test that host model variables and scheme variables
# have the same rank.
if dim == CCPP_BLOCK_NUMBER:
raise Exception("{} cannot be part of the dimensions of variable {}".format(
CCPP_BLOCK_NUMBER, var_standard_name))
else:
# Handle dimensions like "A:B", "A:3", "-1:Z"
if ':' in dim:
dims = dim.split(':')
try:
dim0 = int(dims[0])
except ValueError:
dim0 = metadata_define[dims[0]][0].local_name
try:
dim1 = int(dims[1])
except ValueError:
dim1 = metadata_define[dims[1]][0].local_name
# Single dimensions
else:
# Handle dimensions like "A:B", "A:3", "-1:Z"
if ':' in dim:
dims = dim.split(':')
try:
dim0 = int(dims[0])
except ValueError:
dim0 = metadata_define[dims[0]][0].local_name
try:
dim1 = int(dims[1])
except ValueError:
dim1 = metadata_define[dims[1]][0].local_name
# Single dimensions
else:
dim0 = 1
try:
dim1 = int(dim)
except ValueError:
dim1 = metadata_define[dim][0].local_name
alloc_dimensions.append('{}:{}'.format(dim0,dim1))

# Padding of additional dimensions - before and after the horizontal dimension;
# same as for scalars, variables w/o a horizontal dimension are not supported.
try:
hdim_index = tmpvar.dimensions.index(CCPP_HORIZONTAL_DIMENSION)
except ValueError:
raise Exception("Cannot handle blocked data for variables w/o a horizontal dimension: {}".format(
var_standard_name))
dimpad_before = '' + ':,'*(len(tmpvar.dimensions[:hdim_index]))
dimpad_after = '' + ',:'*(len(tmpvar.dimensions[hdim_index+1:]))
# Add necessary local variables for looping over blocks
var_defs_manual.append('integer :: ib, nb')
# Define actions before, depending on intent
if var.intent in [ 'in', 'inout' ]:
actions_in = '''
dim0 = 1
try:
dim1 = int(dim)
except ValueError:
dim1 = metadata_define[dim][0].local_name
alloc_dimensions.append('{}:{}'.format(dim0,dim1))

# Padding of additional dimensions - before and after the horizontal dimension
hdim_index = tmpvar.dimensions.index(CCPP_HORIZONTAL_DIMENSION)
dimpad_before = '' + ':,'*(len(tmpvar.dimensions[:hdim_index]))
dimpad_after = '' + ',:'*(len(tmpvar.dimensions[hdim_index+1:]))

# Add necessary local variables for looping over blocks
var_defs_manual.append('integer :: ib, nb')

# Define actions before, depending on intent
if var.intent in [ 'in', 'inout' ]:
actions_in = '''
allocate({tmpvar}({dims}))
ib = 1
do nb=1,{block_count}
Expand All @@ -1189,15 +1181,16 @@ def write(self, metadata_request, metadata_define, arguments):
dimpad_before=dimpad_before,
dimpad_after=dimpad_after,
)
else:
actions_in = '''
else:
actions_in = '''
allocate({tmpvar}({dims}))
'''.format(tmpvar=tmpvar.local_name,
dims=','.join(alloc_dimensions),
)
# Define actions after, depending on intent
if var.intent in [ 'inout', 'out' ]:
actions_out = '''

# Define actions after, depending on intent
if var.intent in [ 'inout', 'out' ]:
actions_out = '''
ib = 1
do nb=1,{block_count}
{var} = {tmpvar}({dimpad_before}ib:ib+{block_size}-1{dimpad_after})
Expand All @@ -1211,8 +1204,8 @@ def write(self, metadata_request, metadata_define, arguments):
dimpad_before=dimpad_before,
dimpad_after=dimpad_after,
)
else:
actions_out = '''
else:
actions_out = '''
deallocate({tmpvar})
'''.format(tmpvar=tmpvar.local_name)

Expand Down Expand Up @@ -1256,6 +1249,10 @@ def write(self, metadata_request, metadata_define, arguments):
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)

# Variables stored in blocked data structures but without horizontal dimension not supported at this time (doesn't make sense anyway)
elif ccpp_stage in ['init', 'finalize'] and CCPP_INTERNAL_VARIABLES[CCPP_BLOCK_NUMBER] in local_vars[var_standard_name]['name']:
raise Exception("Variables stored in blocked data structures but without horizontal dimension not supported at this time: {}".format(var_standard_name))

# Unit conversions without converting blocked data structures
elif var.actions['in'] or var.actions['out']:
actions_in = ''
Expand Down