Python Interface to MAPL: Difference between revisions
(7 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
== GEOS-5 Application with Fortran Root Component == | == GEOS-5 Application with Fortran Root Component == | ||
In this example, the very top root component is implemented entirely in a shared library. | In this example of a GEOS-5 application written in Python, the very top root component is implemented entirely in a shared library. | ||
import MAPL | import MAPL | ||
if __name == "__main__": | if __name == "__main__": | ||
# Instantiate the root component | # Instantiate the root component | ||
# ------------------------------ | # ------------------------------ | ||
gcs = MAPL.GridComp(lib='/some/path/ | gcs = MAPL.GridComp(lib='/some/path/libGEOSgcs.so') | ||
# Instantiate MAPL | # Instantiate MAPL | ||
# ---------------- | # ---------------- | ||
mapl = MAPL(root=gcs) | mapl = MAPL(root=gcs) | ||
# Run the cap | # Run the cap | ||
# ----------- | # ----------- | ||
Line 32: | Line 27: | ||
== GEOS-5 Application with Python Root Component == | == GEOS-5 Application with Python Root Component == | ||
In this example, the very top root component is implemented in Python. | In this example, the very top root component is now implemented in Python. | ||
import MAPL | import MAPL | ||
Line 43: | Line 33: | ||
if __name == "__main__": | if __name == "__main__": | ||
# Instantiate the Python root component | # Instantiate the Python root component | ||
# ------------------------------------- | # ------------------------------------- | ||
gcs = GEOSgcs(rc='gcs.rc') | gcs = GEOSgcs(rc='gcs.rc') | ||
# Instantiate MAPL | # Instantiate MAPL | ||
# ---------------- | # ---------------- | ||
mapl = MAPL(root=gcs) | mapl = MAPL(root=gcs) | ||
# Run the cap | # Run the cap | ||
# ----------- | # ----------- | ||
Line 62: | Line 52: | ||
import MAPL | import MAPL | ||
class GridComp(MAPL.GridComp): | class GridComp(MAPL.GridComp): | ||
""" | """ | ||
Line 98: | Line 88: | ||
In this example, the '''GEOSgcs''' component is implemented in Python, with its children, components '''ANA''' and '''GCM''', also implemented in Python. | In this example, the '''GEOSgcs''' component is implemented in Python, with its children, components '''ANA''' and '''GCM''', also implemented in Python. | ||
import MAPL | import MAPL | ||
import GEOSana | import GEOSana | ||
import GEOSgcm | import GEOSgcm | ||
class GridComp(MAPL.GridComp): | class GridComp(MAPL.GridComp): | ||
""" | """ | ||
Implements the GEOSgcs component by subclassing MAPL.GridComp. | Implements the GEOSgcs component by subclassing MAPL.GridComp. | ||
""" | """ | ||
def SetServices(self): | def SetServices(self): | ||
""" | """ | ||
SetServices for a composite component. | SetServices for a composite component. | ||
""" | """ | ||
# Instantiate Children component | # Instantiate Children component | ||
# ------------------------------ | # ------------------------------ | ||
ana = GEOSana() | ana = GEOSana() | ||
gcm = GEOSgcm() | gcm = GEOSgcm() | ||
# Adopt children | # Adopt children | ||
# -------------- | # -------------- | ||
Line 136: | Line 125: | ||
In this case we implement the standard '''Run()''' method, but inherit '''Initialize()''' and '''Finalize()''' from the base class '''MAPL.GridComp''' | In this case we implement the standard '''Run()''' method, but inherit '''Initialize()''' and '''Finalize()''' from the base class '''MAPL.GridComp''' | ||
def Run(self,clock): | |||
""" | |||
Implementation of a simple run method. | |||
""" | |||
# Run the base class method | # Run the base class method | ||
# ------------------------- | # ------------------------- | ||
MAPL.GridComp.__Run__(self) | MAPL.GridComp.__Run__(self,clock) | ||
# Retrieve some data from a state | # Retrieve some data from a state | ||
# ------------------------------- | # ------------------------------- | ||
uwnd, vwnd, = self.Export.GetPointer(['UWND', 'VWND']) | uwnd, vwnd, = self.Export.GetPointer(['UWND', 'VWND']) | ||
# Print states | |||
# ------------ | |||
self.Internal.print() | |||
self.Import.print() | |||
sllf.Export.print() | |||
# Just print it | # Just print it | ||
# ------------- | # ------------- | ||
print "u-wind = ", uwnd.min(), uwnd.max() | print "u-wind = ", uwnd.min(), uwnd.max() | ||
print "v-wind = ", vwnd.min(), vwnd.max() | print "v-wind = ", vwnd.min(), vwnd.max() |