Rappture.Library constructors Rappture.Library() Rappture.Library(lib2) methods lib.loadXml(xmltext) lib.loadFile(filename) lib.value(key[, ...]) lib.diff(lib2) lib.remove(key) lib.xml() lib.outcome() lib.error() lib.result(status) lib.contains() --------------------------------------- Rappture.Library() Purpose: construct an empty Rappture Library object Input Arguments: 0 Return Value: empty Rappture Library object Notes: None Code Example: {{{ lib = Rappture.Library() }}} Rappture.Library(lib2) Purpose: construct a copy of a Rappture Library object Input Arguments: 1 1. lib2 - Rappture Library object to be copied Return Value: copy of a Rappture Library object Notes: None Code Example: {{{ lib2 = Rappture.Library() lib = Rappture.Library(lib2) }}} lib.loadXml(xmltext) Purpose: parse the Rappture1.1 xml data in "xmltext". populate this library object with the Rappture objects described in the xml data. Input Arguments: 1 1. xmltext - string of Rappture1.1 xml data Return Value: status of the object Notes: None Code Example: {{{ xmltext = """ Press Simulate to view results. @tool/fermi @driver Temperature of the environment. K 0K 500K 300K """ lib = Rappture.Library() lib.loadXml(xmltext) }}} lib.loadFile(filename) Purpose: read the file "filename" and parse the Rappture1.1 xml data found inside of it. populate this library object with the Rappture objects described in the xml data. Input Arguments: 1 1. filename - name of file containing Rappture1.1 xml data Return Value: status of the object Notes: None Code Example: {{{ data = """ Press Simulate to view results. @tool/fermi @driver Temperature of the environment. K 0K 500K 300K """ filename = "driver1234.xml" fp = open(filename,"w") fp.write(data) fp.close() lib = Rappture.Library() lib.loadFile(filename) }}} lib.value(key[, ...]) Purpose: retrieve the value of the object named "key" and return it to the user. If there are hints, pass them along to the object being retrieved to tell it how the value should be configured. Input Arguments: at least 1 1. key - name of the object being retrieved 2. ... - hints listed as strings Return Value: value of the object named key Notes: hints are listed as strings of the form "hintKey=hintVal". hintKey is the key for the hint and hintVal is the value to be applied to the hint. generally, unrecognized hints are ignored. the hints should be listed as comma separated strings in the function's argument list. Code Example: {{{ data = """ Press Simulate to view results. @tool/fermi @driver Temperature of the environment. K 0K 500K 300K """ lib = Rappture::Library() lib.loadXml(data) temp = lib.value("temperature","units=F") print "temp = %s\n" % (temp) # temp = 80.33 }}} lib.diff(lib2) Purpose: find the difference between two library objects Input Arguments: 1 1. lib2 - other object used in comparison Return Value: List of differences Notes: None Code Example: {{{ data1 = """ Press Simulate to view results. @tool/fermi @driver Temperature of the environment. K 0K 500K 300K Environment cm 4cm 183cm 72cm Icks hafra doec weple 33 """ data2 = """ Press Simulate to view results. @tool/fermi @driver Icks hafra doec weple 33 Energy at center of distribution. eV -10eV 10eV 0eV Environment cm 4cm 183cm 109cm """ lib1 = Rappture::Library() lib1.loadXml(data1) lib2 = Rappture::Library() lib2.loadXml(data2) diffs = lib1.diff(lib2) # - input.number(temperature) 300K # c input.number(forel) 72cm 109cm # + input.number(Ef) 0eV }}} lib.remove(key) Purpose: remove the object from this library named "key" Input Arguments: 1 1. key - name of the object to remove Return Value: None Notes: The object is removed and it's memory is deleted Code Example: {{{ data = """ Press Simulate to view results. @tool/fermi @driver Temperature of the environment. K 0K 500K 300K Energy at center of distribution. eV -10eV 10eV 0eV """ lib = Rappture::Library() lib.loadXml(data) lib.remove("Ef") print lib.xml() # # # # Press Simulate to view results. # @tool/fermi @driver # # # # # # Temperature of the environment. # # K # 0K # 500K # 300K # # # }}} lib.xml() Purpose: return the Rappture1.1 xml representation of the objects stored in this library. Input Arguments: 0 Return Value: None Notes: user is responsible for free'ing returned memory? Code Example: {{{ data = """ Press Simulate to view results. @tool/fermi @driver Temperature of the environment. K 0K 500K 300K """ lib = Rappture::Library() lib.loadXml(data) print lib.xml() # # # # Press Simulate to view results. # @tool/fermi @driver # # # # # # Temperature of the environment. # # K # 0K # 500K # 300K # # # }}} lib.outcome() Purpose: return the status of the object Input Arguments: 0 Return Value: status of the object Notes: None Code Example: {{{ data = """ Press Simulate to view results. @tool/fermi @driver Temperature of the environment. K 0K 500K 300K """ lib = Rappture::Library() lib.loadXml(data) if (lib.error() != 0) { print "there was an error while loading xml data" outcome = lib.outcome() sys.stderr.write(outcome.context()) sys.stderr.write(outcome.remark()) } }}} lib.error() Purpose: return the status of the object Input Arguments: 0 Return Value: status of the object Notes: None Code Example: {{{ data = """ Press Simulate to view results. @tool/fermi @driver Temperature of the environment. K 0K 500K 300K """ lib = Rappture::Library() lib.loadXml(data) if (lib.error() != 0) { print "there was an error while loading xml data" outcome = lib.outcome() sys.stderr.write(outcome.context()) sys.stderr.write(outcome.remark()) } }}} lib.result(status) Purpose: write the stored objects to a data file and signal the end of processing. Input Arguments: 1 1. int status - status of the simulation Return Value: None Notes: currently data file are written out as Rappture1.1 xml. this function generates the RAPPTURE-RUN=> signal. Code Example: {{{ data = """ Press Simulate to view results. @tool/fermi @driver Temperature of the environment. K 0K 500K 300K """ lib = Rappture::Library() lib.loadXml(data) lib.result() # internal xml objects free'd # driver file written to disk # =RAPPTURE-RUN=>driver1234.xml signal sent to stdout }}} lib.contains() Purpose: return a list of the Rappture objects stored in this library. Input Arguments: 0 Return Value: list of the Rappture objects stored in this library. Notes: None Code Example: {{{ data = """ Press Simulate to view results. @tool/fermi @driver Temperature of the environment. K 0K 500K 300K Energy at center of distribution. eV -10eV 10eV 0eV """ lib = Rappture::Library() lib.loadXml(data) xmlObjs = lib.contains() len xmlObjs # 2 # xmlObjs contains objects (pointers or copies of objects?) print xmlObjs # ::Rappture::Number ::Rappture::Number foreach obj in xmlObjs { obj.vvalue() } # 300 # 0 }}}