The Application Input Module
Application input is primarily specified in a basic python script (also called a module). As with any executable python script, it typically contains the following:
A pre-amble on the top of the file with import statements.
A body where application parameters are set.
A closing section, detailing how the script will be executed when executed on the command line.
Import statements
The first module that should be imported is the one that implements the target application’s input parameters and execution framework. There are two different ways to achieve this, as described in Global application import and Local application import respectively.
Global application import
In this case, all symbols from the application module app_type
is imported:
from application.app_type import *
where app_type
should be replaced with the required application type. The symbols which are made available with this
statement differs slightly between applications, but always includes at least the following:
Symbol |
Description |
---|---|
|
Set of input parameters for the application. |
|
The application driver routine. |
Note
The drawback of this method is that a global parameters
set is used, which can cause problems when the same
application type is imported more than one in another script. This is discussed further in
Creating an Application Parameter Set.
Local application import
In this case, only the application module is imported:
import application.app_type as app
where app_type
should be replaced with the required application type. Symbols can now be accessed from the
app
alias, for example app.parameters
and app.main
. See Creating an Application Parameter Set
for more information on how this is used to create a local (unique) parameter set for the application.
System imports
Since the application input is likely to use other system resources, these should be imported next:
from core import *
The modules and variables made available through this statement, is described in System interface basics. You can also import any standard python module, or other external package. For example,
import math
will make the entire python math available.
Relative imports
The application might also need to import data or methods from other applications, or other modules within the larger local package structure. Importing an existing model is the most common occurrence. Assuming the larger package has the following structure:
ROOT
|-my_config.cfg
MY_REACTOR
|-model
|-configurations
| |-my_configuration.py
|-projects
|-my_app.py
To import the model form my_configurations.py in my_app.py, add
from ..configurations.my_configuration import model
Note
When using relative imports the script can only be executed in package mode, which is automatically used when invoking the oscar5 wrapper script.
Input module body
The body of the application
Making the script executable
The final part of any application script contains a the statement that will determine how the application is executed in a terminal prompt. It depends on how the application was imported:
When using the Global application import option, it is simply:
if __name__ == '__main__':
main()
While, using the Local application import option requires:
if __name__ == '__main__':
app.main(parameters=my_parameters)
where my_parameters
should be replaced with whatever you named your local parameter set
(see Creating a unique parameter set).
Note
The if
statement wrapping the main
method will prevent application launch when the script is imported.