Changeset 5412 for branches/uq/examples/graph
- Timestamp:
- May 4, 2015, 5:14:03 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/uq/examples/graph/graph.py
r3177 r5412 7 7 # 8 8 # ====================================================================== 9 # AUTHOR: M ichael McLennan, Purdue University10 # Copyright (c) 20 04-2012HUBzero Foundation, LLC9 # AUTHOR: Martin Hunt, Purdue University 10 # Copyright (c) 2015 HUBzero Foundation, LLC 11 11 # 12 12 # See the file "license.terms" for information on usage and … … 14 14 # ====================================================================== 15 15 16 # Note: You will not see stdout and stderr when this 17 # tool is run by Rappture. You can either run this tool from the command 18 # line by passing in a driver xml file like this: 19 # ~/rap/rappture/examples/graph> python graph.py driver1234.xml 20 # 21 # or you can redirect stdout and stderr to files by uncommenting the 22 # two lines after the import sys 23 16 24 import Rappture 25 import numpy as np 17 26 import sys 18 from math import *19 27 20 io = Rappture.library(sys.argv[1]) 28 # uncomment these for debugging 29 # sys.stderr = open('graph.err', 'w') 30 # sys.stdout = open('graph.out', 'w') 21 31 22 xmin = float(io.get('input.number(min).current')) 23 xmax = float(io.get('input.number(max).current')) 24 formula = io.get('input.string(formula).current') 32 io = Rappture.PyXml(sys.argv[1]) 33 34 # When reading from xml, all values are strings 35 xmin = float(io['input.number(min).current'].value) 36 xmax = float(io['input.number(max).current'].value) 37 formula = io['input.string(formula).current'].value 25 38 print 'formula = %s' % formula 26 npts = 10027 39 28 io.put('output.curve(result).about.label','Formula: Y vs X',append=0) 29 io.put('output.curve(result).yaxis.label','Y') 30 io.put('output.curve(result).xaxis.label','X') 40 curve = io['output.curve(result)'] 41 curve['about.label'] = 'Formula: Y vs X' 42 curve['yaxis.label'] = 'Y' 43 curve['xaxis.label'] = 'X' 31 44 32 for i in range(npts): 33 x = (xmax-xmin)/npts * i + xmin; 34 35 io.put('output.curve(result).component.xy', '%g %g\n' % (x,y), append=1)45 num_points = 100 46 x = np.linspace(xmin, xmax, num_points) 47 y = eval(formula) 48 curve['component.xy'] = (x, y) 36 49 37 Rappture.result(io) 50 # Done. Write out the xml file for Rappture. 51 io.close()
Note: See TracChangeset
for help on using the changeset viewer.