Skip to content

Commit

Permalink
scripts/mkcap.py: remove legacy code, add new attributes 'dimension' …
Browse files Browse the repository at this point in the history
…and 'active' (preliminary name)
  • Loading branch information
climbfuji committed May 27, 2020
1 parent 2f0ca12 commit 2635916
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions scripts/mkcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ def __init__(self, **kwargs):
self._units = None
self._local_name = None
self._type = None
self._rank = None
self._dimensions = []
self._container = None
self._kind = None
self._intent = None
self._optional = None
self._active = None
self._target = None
self._actions = { 'in' : None, 'out' : None }
for key, value in kwargs.items():
Expand Down Expand Up @@ -83,19 +84,24 @@ def type(self):
def type(self, value):
self._type = value

@property
def dimensions(self):
'''Get the dimensions of the variable.'''
return self._dimensions

@dimensions.setter
def dimensions(self, value):
if not type(value) is list:
raise TypeError('Invalid type for variable property dimensions, must be a list')
self._dimensions = value

@property
def rank(self):
'''Get the rank of the variable.'''
return self._rank

@rank.setter
def rank(self, value):
if not isinstance(value, int):
raise TypeError('Invalid type for variable property rank, must be integer')
if (value == 0):
self._rank = ''
if len(self._dimensions) == 0:
return ''
else:
self._rank = '('+ ','.join([':'] * value) +')'
return '('+ ','.join([':'] * len(self._dimensions)) +')'

@property
def kind(self):
Expand All @@ -119,7 +125,7 @@ def intent(self, value):

@property
def optional(self):
'''Get the optional of the variable.'''
'''Get the optional attribute of the variable.'''
return self._optional

@optional.setter
Expand All @@ -128,6 +134,17 @@ def optional(self, value):
raise ValueError('Invalid value {0} for variable property optional'.format(value))
self._optional = value

@property
def active(self):
'''Get the active attribute of the variable.'''
return self._active

@active.setter
def active(self, value):
if not isinstance(value, str):
raise ValueError('Invalid value {0} for variable property active, must be a string'.format(value))
self._active = value

@property
def target(self):
'''Get the target of the variable.'''
Expand All @@ -153,7 +170,7 @@ def actions(self):

@actions.setter
def actions(self, values):
if type(value)==dict:
if type(values)==dict:
for key in values.keys():
if key in ['in', 'out'] and isstring(values[key]):
self._actions[key] = values[key]
Expand All @@ -174,11 +191,13 @@ def compatible(self, other):
(self.kind.startswith('len=') and other.kind == 'len=*'):
return self.standard_name == other.standard_name \
and self.type == other.type \
and self.rank == other.rank
and self.rank == other.rank \
and self.active == other.active
return self.standard_name == other.standard_name \
and self.type == other.type \
and self.kind == other.kind \
and self.rank == other.rank
and self.rank == other.rank \
and self.active == other.active

def convert_to(self, units):
"""Generate action to convert data in the variable's units to other units"""
Expand Down Expand Up @@ -260,29 +279,17 @@ def print_debug(self):
units = {s.units} *
local_name = {s.local_name}
type = {s.type} *
dimensions = {s.dimensions}
rank = {s.rank} *
kind = {s.kind} *
intent = {s.intent}
optional = {s.optional}
active = {s.active} *
target = {s.target}
container = {s.container}
actions = {s.actions}'''
return str.format(s=self)

@classmethod
def from_table(cls, columns, data):
var = cls()
var.standard_name = data[columns.index('standard_name')]
var.long_name = data[columns.index('long_name')]
var.units = data[columns.index('units')]
var.local_name = data[columns.index('local_name')]
var.rank = int(data[columns.index('rank')])
var.type = data[columns.index('type')]
var.kind = data[columns.index('kind')]
var.intent = data[columns.index('intent')]
var.optional = data[columns.index('optional')]
return var

class CapsMakefile(object):

header='''
Expand Down

0 comments on commit 2635916

Please sign in to comment.