FortLab framework introduction

FortLab is a software tool development framework on which developers can build a new kernel extraction and analysis tool for Fortran applications.

Fortlab Framework Overview

_static/Fortlab_Framework.png

Above Figure shows a high-level view of the framework. At the core of the framework, FortLab built-in applications exist. Each built-in applications provides core features of kernel extraction and analysis capabilities. The applications can be used in a Python script as a part of another application. Or they can directly run on shell as a sub-command of “fortlab” command.

Creating a FortLab Application

The functionality of the framework is implemented as a form of FortLab application. While the application exists within the framework, it acts as if it is an independent application as explained in the following section.

Following code shows a simple example of a FortLab application that reads a name as a command-line argument and greets with the name.

 1     class Hello(App):
 2       "greet a name"
 3       _name_ = "hello"
 4       _version_ = "0.1.0"
 5
 6       def __init__(self, mgr):
 7         self.add_argument("name", help="input name")
 8
 9       def perform(self, args):
10         print("Hello "+args.name["_"])

At line 1, “App” class is imported from the “fortlab” Python module. At line 2 a new class “Hello” is created from the “App” class. Line 3 has a short description of the application. “_name_” in line 4 sets the name of this application. The name is used as a sub-command of “fortlab” in command-line. “_version_” at line 5 sets the version of this implementation. “__init__” function at line 6 is optional. Within the function, user can define the command-line argument as shown in line 7-8. The “add_argument” function is almost similar to the interface of Python’s “argparse” standard module. “perform” function at line 9 is the entry of the application’s execution and it is mandatory. The “args” arguments of the function is the way to receive user’s input at command-line. There is no special restriction on what to add in the body of the “perform” function. In this case, a greeting string is printed with the input name. Line 10 shows how to access the user’s input through the “args” variable. The square bracket notation is used to indicate the argument type conversion method. The underline string in the brackets indicates “No conversion”, and therefore, “args.name” is a type of string.

Running a FortLab Application in command-line

Following bash commands show how to run the application (“app”) that we created in the above code and the output from the run. In line 1, “fortlab” is used as a shell command. The double dashes separate the command from the sub-command. Next, a path to a file that contains the app follows. The framework automatically detects the app in the Python module-level objects. If there exists more than one apps in the module, a hash mark “#” with a class name can be used to specify a particular app class in the module. The output of the run shows in line 2. Line 3 to the end demonstrates the framework’s capabilities that show version and usage of the app on screen. Note that the version and the short description in the Hello class are shown in the screen output, which are generated by the framework.

 1     >> fortlab -- hello.py world
 2     Hello world
 3     >> fortlab -- hello.py --version
 4     hello 0.1.0
 5     >> fortlab -- hello.py --help
 6     usage: fortlab-hello [-h] [--version]
 7                          name
 8     greet a name
 9
10     positional arguments:
11       name         input name
12
13     optional arguments:
14       -h, --help   show this help message
15       --version    show program's version