Compose-3030: Using Compose and OML in Batch Mode

This tutorial explains how to:
  • Use the Compose console mode.
  • Use the Compose batch mode.
  • Pass input arguments to a script executed in batch mode.
  • Save output to text file when running in batch mode.

Running Console Mode in Compose

In addition to the graphical, interactive mode described in previous tutorials, can also be used in Console mode. Console mode is basically a non-graphical mode that exposes, the OML command prompt in a shell.

From this prompt, all supported OML commands can be executed, with the exception of all GUI-related commands, such as plots.

  1. To open Compose in console mode, go to All Programs > Altair 2020.1 > Compose 2020.1.
  2. A command window with the Compose application running in Console mode is open as shown below:

    From here, all commands (except plot-related) are available. Type any command at the prompt and press ENTER to evaluate them immediately.

  3. You can also run a script or function file in Console mode using the run function.

    Assume a script named myscript.oml exists under D:/Test and contains these commands:

    M1 = rand(5,5);
    disp(M1)

    Run this in Console mode, and check the results:

Running OML Command/Script in Console Mode

The Console mode, which is described above, can also be used by passing either commands or scripts to the application from a standard shell.

  1. From the Windows Start menu, select Run, type cmd and then press ENTER.

    This launches the Windows Command Prompt. Use the command prompt to run OML commands, script files or a combination of both in Compose.

  2. At the command prompt, enter the following (replace <installation_dir> with your actual installation location) and press ENTER.
    cd <installation_dir>\

    This changes the directory to the location in the installation where the Compose_Console.bat file is located.

  3. For short help on Compose_Console.bat arguments, type the following in the command prompt: Compose_Console.bat –help
    -e Execute the OML command then quit.
    -f foo.oml Load and execute the OML script called foo.oml.
    -help Give the list of supported optional arguments.
    -version Give the version of Compose.
  4. OML commands can be directly executed using the –e option. Following the Compose_Console.bat command, type –e "Any valid OML command". For example:
    Compose_Console.bat –e disp(rand(3,3))

    This prints a 3x3 matrix in the command prompt:

    Use quotes to run multiple commands and/or commands including spaces.

  5. OML scripts can be directly executed using the –f option. Following the .bat command, type –f and the path to the file MatrixDemo.oml. This should look like the following:

    Compose_Console.bat –f <installation_dir>\tutorials\MatrixDemo.oml

    Press ENTER to run the file. Notice how all the output is displayed to the command prompt. Also, the output is the same as what was displayed in Compose in the OML Command window when the script file was evaluated.

Pass an Argument to a Script

Sometimes, arguments may need to be passed into a script file or function in batch mode. This can be achieved by using both –f and –e arguments:
Compose_Console.bat –e input arguments –f script.oml
You can define input arguments between –e and –f, and they will be inherited into the script afterward. Run the example below:
Compose_Console.bat –e t=[0:0.1:20];initial=[0;0]; –f
<installation_dir>\tutorials\ode45_noplot.oml

The script file ode45_noplot.oml is located under <installation_dir>/tutorials/. Note that if you run the script file directly in the Compose GUI, it will prompt that variable t and initial are not defined. See the result when running the correct command in batch:

Save the Output to a File

  1. Continue previous example, and add > output.txt at the end of previous command:
    Compose_Console.bat –e t=[0:0.1:20];initial=[0;0]; –f
    <installation_dir\tutorials\ode45_noplot.oml  C:/output.txt

    After the –f, the paths to the two files are listed. After the two files, there is a > with another file listed. This indicates that the output from the previous files should be exported to this file. This file needs to be in a folder with write access.

  2. Press ENTER to run the file in batch mode. This time, there isn’t any output written to the command prompt:
  3. Open the file output.txt in a text editor. This file contains the output from ode45_noplot.oml script that was run in batch mode:

Running Tcl Scripts in Batch Mode

Besides the Console mode, which is described above, Compose can be used in 'true' batch mode by just passing either commands or scripts to the application from a standard shell.

Compose also supports running scripts in full batch mode. The batch mode can be executed using the *.bat file which resides in:

<installation_dir\hwx\Compose_Batch.bat

Pass the name of the script to be executed by using the –f argument, the same as for Console mode.

Compose also supports also multiple languages. To run a Tcl script in batch, enter the following:

<installation_dir\hwx\Compose_Batch.bat –f <TCL file with .tcl extension
See the result of running basic.tcl in batch mode:

basic.tcl can be found in <installation_dir/tutorials/.