Download
(right-click and "save as")
#
# @author: Phoenix Integration
# @description: Converts array of measurements in meters to measures in feet.
#
variable: inputs double[] input
variable: outputs double[] output
variable: withUnits string[] output
# ------------------------------------------
script: language="python"
def run():
# Implement run sharing
wrapper.getRunShare().lock()
convertIN(PHXRowFieldFile.GENERATE)
convertOUT(PHXRowFieldFile.PARSE)
wrapper.getRunShare().unlock()
def convertIN(mode):
# Editors note: RowFieldFile pulls the correct directory
# from wrapper.getDirectory() or wrapper.getRunShare().getDirectory()
file = new PHXRowFieldFile(wrapper, int(mode))
file.setTemplateFile('convert.in.template')
file.setFileToGenerateOrParse('convert.in')
# Read in a 4x4 2D array
size = [4, 4]
inputs.resize( size )
file.transferArray(inputs, 1, 4, 1, 4, True, '', 2)
//Actually generate a file if we are told to
if mode == PHXRowFieldFile.GENERATE:
file.generate()
def convertOUT(mode):
file = new PHXRowFieldFile(wrapper, int(mode))
file.setFileToGenerateOrParse('convert.out')
# Make the outputs array 2D
size = [1, 1]
outputs.resize( size )
# Transfer array as being resizable, having no Fortran formatting,
# and being 2D.
file.transferArray(outputs, 1, -1, 1, -1, True, '', 2)
# Create an array that is the outputs, with each element having the
# units "ft." appended.
withUnits.resize( outputs.getDimensions() )
for i in range(outputs.getLength(0)):
for i in range( outputs.getLength(1)):
index = [i, j]
withUnits.setValue(index, '%s ft.' % outputs.getValue(index))
# Actually generate a file if we are told to
if mode == PHXRowFieldFile.GENERATE:
file.generate()
try:
convertIN(PHXRowFieldFile.READ_TEMPLATE)
convertOUT(PHXRowFieldFile.READ_TEMPLATE)
except RuntimeError:
pass