Batch Processing

You can run Tecplot 360 in batch mode to create plots without displaying any graphics to the screen. This saves time when processing multiple files for printing or export. In batch mode, Tecplot 360 can be executed locally on your workstation computer or remotely using a terminal (Linux only).

Batch Processing Setup

  1. Create a macro file to control the batch processing. You may do this either by using Scripting→Record Macro and recording a Tecplot 360 session, or by using any text editor. See Macros.

  2. Create layout and stylesheet files, as necessary.

  3. Prepare data files.

  4. Debug the macro file by running Tecplot 360 while not in batch mode.

Macros are more likely to be forward compatible (i.e. work with future releases) only if the file is started with a layout or stylesheet. Refer to the Scripting Guide for more information.

When you launch Tecplot 360 in batch mode, you provide the name of a macro file to execute. The minimal command to launch Tecplot 360 in batch mode is as follows:

tec360 -b -p mymacrofile.mcr

The -b flag instructs Tecplot 360 to run in batch mode and the -p tells Tecplot 360 to run the filename that follows (mymacrofile.mcr in this case).

The -p flag can be omitted if the macro file uses the .mcr extension (thus in the example above it could be omitted).

Batch Mode and Linux

See Tecplot 360 Command Line for information on batch mode command line arguments for Linux. If you have any issues with running in batch mode, see the Rendering and Export Troubleshooting guide for more information.

Batch Mode and Windows

Under Windows, invoking Tecplot 360 from the command line or in a .bat file returns immediately rather than waiting for the application to finish working, as is normal on Linux and Mac.

When using batch mode, however, you generally want to wait until Tecplot 360 has finished one operation before proceeding with the next. To do this, precede the command with start /wait. For example:

start /wait tec360 -b -p mymacrofile.mcr

Batch Mode and Mac

When running batch mode on a Mac, the full path to the executable must be called:

"/Applications/Tecplot 360 EX 2024 R1/Tecplot 360 EX 2024 R1.app/Contents/MacOS/Tecplot 360 EX 2024 R1" -b mymacro.mcr

If you are running many files in batch mode, it may be helpful to set up an alias for the full executable path. To set up an alias, type the following in ~/.bashrc:

alias tec360='"/Applications/Tecplot 360 EX 2024 R1/Tecplot 360 EX 2024 R1.app/Contents/MacOS/Tecplot 360 EX 2024 R1"'

With the alias defined, running macros in batch mode becomes easier. Simply add the -b flag followed by the macro you wish to use:

tec360 -b mymacro.mcr

For more information on setting an alias and running Tecplot from the command line in Mac see the Installation Guide.

Batch Processing Using a Layout File

Combining layout files with batch processing is both powerful and flexible, and is also the recommended procedure. With layout files, you can organize a plot using one or more frames in a single file. The layout file manages datasets and can be altered on the fly, either on the command line or within a macro that loads the layout file.

The layout file must contain a $!READDATASET macro instruction compatible with the data being loaded. The easiest way to create such a layout is to load a file similar to the file(s) you wish to process into Tecplot 360, then set up the plot as desired and save the layout. The filename specified in the layout’s $!READDATASET instruction will be overridden by the filename specified on the command line (see below).

For example, to do the following sequence of tasks in batch mode:

  • Load a data file from a user-supplied file name.

  • Create a specific style of plot.

  • Create a PostScript file of the plot.

You can set up the batch script as follows:

  1. Obtain a representative data file to be plotted.

  2. Create a layout of the style of plot you want. (For this example, name the file batch.lay).

  3. Use a text editor to create the following macro (For this example call this macro batch.mcr):

    #!MC 1410
    $!EXPORTSETUP
      EXPORTFORMAT = PS
      PRINTRENDERTYPE = VECTOR
    $!PRINTSETUP
      PALETTE = MONOCHROME
    $!EXPORT
      EXPORTREGION = CURRENTFRAME
    $!Quit
  4. Use the following command to run the job in batch mode:

tec360 -b -p batch.mcr -y psoutput.ps batch.lay mydatafile

tec360 -b

Launches Tecplot 360 in batch mode

-p

Tells Tecplot 360 to use the following macro file. (Note: This is not needed if the macro file uses the .mcr extension).

batch.mcr

Macro file

-y

Tells Tecplot 360 to use the following export file

psoutput.ps

Export file

batch.lay

Layout file to use

mydatafile

Data file to use; overrides the file specified in the layout

Multiple Data File Processing

In Batch Processing Using a Layout File, we set up Tecplot 360 to process a user-supplied data file (or files) and create a single output file. If the above procedure is to be repeated for a large number of input files (one at a time), you can do this by using a loop: either outside Tecplot 360 in the operating system using your shell’s looping constructs, or within Tecplot 360 using the flow-of-control commands in the Tecplot macro language.

Looping Outside Tecplot 360

The following examples show the command files for launching Tecplot 360 in an operating system loop on two different operating systems. Tecplot 360 processes five data files named dnn.plt and creates ten output files named dnn.out where nn goes from 1 to 10.

Looping Outside Tecplot 360 (Linux)

Create a shell script with the following commands:

#!/bin/sh
n=1
while test $n -le 10
do
  tec360 -b -p batch.mcr -y d$n.out batch.lay d$n.plt
  n=`expr $n+1`
done

Looping Outside Tecplot 360 (Windows)

Create a batch file with the following commands:

for %%f in (d1 d2 d3 d4 d5 d6 d7 d8 d9 d10)
do tec360 -b -p batch.mcr -y %%f.out batch.lay %%f.plt

Looping Inside Tecplot 360

In Looping Outside Tecplot 360 we set up Tecplot 360 to process multiple data files using the shell to do the looping. There are two drawbacks to this procedure:

  • The shell languages are not portable between different operating systems.

  • Tecplot 360 must be repeatedly started and stopped to process each dataset.

A more efficient approach is to loop through the data files inside Tecplot 360. Here, the layout file and the data files are all named within the macro. The command line in this example is simple, as follows:

tec360 -b -p batch.mcr

Where the macro batch.mcr contains:

#!MC 1410
$!EXPORTSETUP EXPORTFORMAT = PS
$!PRINTSETUP PALETTE = MONOCHROME
$!LOOP 10
  $!OPENLAYOUT "batch.lay"
    ALTDATALOADINSTRUCTIONS = "d|LOOP|.plt"
  $!EXPORTSETUP PRINTRENDERTYPE = VECTOR
  $!EXPORTSETUP EXPORTFNAME = "d|LOOP|.out"
  $!EXPORT
    EXPORTREGION = CURRENTFRAME
$!ENDLOOP
$!QUIT

The $!OPENLAYOUT command loads in batch.lay but replaces the data file referenced in the layout with the file names in the ALTDATALOADINSTRUCTIONS sub-command. The $!EXPORTSETUP command is used in two places. Initially it is used to set the export format. Later it is used just to change the name of the file to export to. The $!EXPORT command does the actual exporting.

If you want to make many different plots using the same dataset, stylesheets will be more efficient than layout files.

Batch Processing Diagnostics

Each time Tecplot 360 is run in batch mode, it creates a file defined by the name in the BATCHLOGFILE environment variable, or, if the environment variable is not defined, by a file named batch.log in the directory where Tecplot 360 was started. If the name given in the BATCHLOGFILE environment variable is a relative path, the directory name where Tecplot 360 was started is prefixed. A running commentary on actions performed in Tecplot 360, as well as warning and error messages, are sent to the batch.log file.

Batch Converting to SZL Format

Two of Tecplot 360’s command line options, -o and -convert, allow you to more easily convert your existing datasets to SZL, Tecplot’s high-performance subzone data format (filename extension .szplt). Since it is command-line driven, this capability is suitable for converting large numbers of files without user intervention, or as a step in solver postprocessing.

Tecplot 360 does not require a license when launched with either of these options, so you can perform data file conversion on any available workstation without concern. Only a Tecplot 360 installation is required.

In a restricted batch session started with -o or -convert, Tecplot 360 can read data files (using any of its data loader add-ons) and write data in SZL format, but cannot perform most other operations. As with all batch operations, there is no graphical user interface; batch conversion is strictly a command-line function.

Most of the time, you’ll want to use the -o option for SZL conversion. See Writing SZL Files With Macros for more information on the use cases for the -convert option.

Loading Data Files by Name

The -o option outputs any loaded data to the specified .szplt output file. Just add -o followed by the output filename or path to whatever command line you would normally use to load your data. Tecplot 360 will then write that data in SZL format (and exit) instead of displaying a plot in its workspace. For example, if you usually start exploring data in two Tecplot .plt files using the following command line:

tec360 file1.plt file2.plt

You can instead have Tecplot 360 convert those data files to a single .szplt file using the following command line:

tec360 file1.plt file2.plt -o output.szplt

If your data is in a non-Tecplot format, you may or may not be able to load it all into Tecplot 360 using a single, simple command line of the type shown. Some formats (e.g. CGNS) support loading multpile files, but require that the files all be part of a single case, and require additional cases to be appended via further load operations. Other loaders do not support multiple files at all and require all loads after the first to be appended. In such cases, you can record a macro to load your data.

Loading Data Files with Macros

Create a macro to load some or all of your data when one or more of the following apply:

  • The data cannot be loaded using a single command line because it is in multiple files and the required loader does not support loading all of them using a single command line.

  • The data files do not have filenames that allow Tecplot 360 to unambiguously determine the correct loader for the data. (In some cases, though, you can simply rename the files.)

  • You need to set the loader’s advanced options to successfully load the data. In other words, in the Load Data dialog, you use the Open with Advanced Options command (accessed by clicking the menu triangle next to the Open button) or mark the Advanced Options checkbox.

Simply record a macro that loads the data, using the procedure you normally use with the Tecplot 360 graphical user interface. See Macro Creation for more information on recording macros.

The loading procedure you record can include multiple load operations using the append option, any number of different file formats, and selection of advanced loader options. After you have recorded the macro, specify it on the command line when invoking tec360. As with the previous case, simply add -o followed by the name of SZL file to be created:

tec360 loaddata.mcr -o output.szplt

Your recorded macro contains fixed file names and directory paths for the files you loaded, which makes it difficult to use the macro with other data files. We will see how to address this with a few simple changes to the macro shortly.

Using Multiple Macros to Load Files

Tecplot 360 allows you to specify multiple macros on the command line, which will be executed in the order they appear in the command. Instead of creating one macro that loads multiple files, then, you could record multiple macros, each loading one data file, then specify just the ones you actually need for a given project. For example:

tec360 loaddata1.mcr loaddata2.mcr loaddata3.mcr -o output.szplt

Combined with the techniques in the following sections to allow the macros to load data files other than the ones used when recording the macro, this lets you create a macro "tool set" for converting the various kinds of files you typically work with.

There is one hitch to using multiple macros on the command line. When you record a load operation, the resulting macro may include an instruction telling the loader to erase any data that has already been loaded. When you attempt to load your data, the second macro file specified will erase the data loaded by the first, and so on for the third, fourth, etc., wasting time and making it seem like only the last macro loaded anything.

Fortunately, this is easy to fix. Simply load the macro into any text editor (Notepad.exe will do) and find any lines that says READDATAOPTION = NEW. Change it to say READDATAOPTION = APPEND instead. Such a macro will still work fine even when specified first on the command line, because each conversion is a new Tecplot 360 session that begins with no data loaded.

Mixing Macros and Data Files

Macros are just another kind of data file: one that Tecplot 360 happens to execute as instructions. For this reason, it is possible to mix data files and macros on the command line to load your data, using macros only for files that can’t be loaded by specifying them directly. Files are processed in the order they appear on the command line. For example:

tec360 cube.plt loadcircle.mcr -o output.szplt

This loads cube.plt (a regular Tecplot data file) and then executes loadcircle.mcr, which, presumably, loads another data file (or even multiple files). The loaded data are then written to output.szplt.

Using Relative Paths

As we mentioned, the paths of the files you loaded and saved become a part of recorded macros. The macro will then always load input files with the same names, and in the same directory, as the file(s) used when the macro was recorded. The output file, similarly, is always given exactly the same name and stored in the same directory as the one you wrote while recording the macro.

If you have set up your simulation process so that the solver always produces an output file of the same name, but in a different directory for each case, you can simply edit the recorded macro to use relative paths. Then the macro will work with files in the current directory, whatever it may be, and you can simply change to the directory that contains the file you wish to convert before performing the conversion.

For example, here is a simple macro, loadcube.mcr, that we recorded to load a single .plt file. (A real macro would probably be longer, since you don’t even need a macro to load a .plt file, but let’s keep it simple.)

#!MC 1410
$!VarSet |MFBD| = 'C:\Users\kelvin\Desktop'
$!READDATASET '"|MFBD|\cube.plt" '
  READDATAOPTION = NEW
  RESETSTYLE = YES
  VARLOADMODE = BYNAME
  ASSIGNSTRANDIDS = YES
  VARNAMELIST = '"X" "Y" "Z"'
$!RemoveVar |MFBD|

All recorded macros contain a definition of the variable MFBD, which refers to the current (or working) directory that was in effect when the macro was recorded. Since we loaded cube.plt from our Desktop folder, which was also the working directory, the macro uses the MFBD variable in the READDATASET command. If we had loaded our data file from a directory other than the working directory, the READDATASET command would have the full path (for example, on Windows, it would probably start with C:\). Here’s what the macro looks like when cube.plt is in `C:\:

#!MC 1410
$!VarSet |MFBD| = 'C:\Users\kelvin\Desktop'
$!READDATASET '"C:\cube.plt" '
  READDATAOPTION = NEW
  RESETSTYLE = YES
  VARLOADMODE = BYNAME
  ASSIGNSTRANDIDS = YES
  VARNAMELIST = '"X" "Y" "Z"'
$!RemoveVar |MFBD|

We don’t actually need the MFBD variable for our purposes, so we can remove the VarSet command and the corresponding RemoveVar command. (It doesn’t hurt to leave them, however.) We will also remove everything but the filename from the READDATASET and WRITEDATASET commands. We will also change the READDATAOPTION to APPEND, as suggested in the preceding section. Here is the macro after these changes.

#!MC 1410
$!READDATASET '"cube.plt" '
  READDATAOPTION = NEW
  RESETSTYLE = YES
  VARLOADMODE = BYNAME
  ASSIGNSTRANDIDS = YES
  VARNAMELIST = '"X" "Y" "Z"'

This macro now reads the cube.plt file from the current (or working) directory. After saving it as loadcube.mcr, you can invoke the conversion as follows:

cd C:/path/to/files
tec360 C:/path/to/loadcube.mcr -o output.szplt

Note that, when invoking the conversion, we must specify the full path to convert.mcr since it is not in the working directory. If the Tecplot 360 bin directory is not in your system’s PATH variable, you must also supply the full path to the tec360 executable. (For simplicity, our examples assume tec360 is in your PATH.)

Using Environment Variables in Loader Macros

When the data files you want to convert may have different names, but are in the same format and need the same loader options, it is possible to write a macro that accepts paths specified outside of the macro. The most straightforward way to do this is to set environment variables before launching Tecplot 360. The macro file then uses these environment variables as the input file path(s). Here, we will use the variable INFILE with the macro from the preceding section. Since it will no longer load only cube.plt, we will name the macro loaddata.mcr rather than loadcube.mcr.

#!MC 1410
$!READDATASET '"|$INFILE|" '
  READDATAOPTION = APPEND
  RESETSTYLE = YES
  VARLOADMODE = BYNAME
  ASSIGNSTRANDIDS = YES
  VARNAMELIST = '"X" "Y" "Z"'
$!EXTENDEDCOMMAND
  COMMANDPROCESSORID = 'Tecplot Subzone Data Tools'
  COMMAND = 'WRITEDATASET FILENAME="|$OUTFILE|"'

To invoke it, set the environment variables before starting the conversion:

Windows:

SET INFILE=C:\path\to\cube.plt
tec360 C:\path\to\loaddata.mcr -o output.szplt

Linux or Mac (bash shell):

INFILE=/path/to/cube.plt
tec360 /path/to/loaddata.mcr -o output.szplt

Either absolute or relative paths may be used in environment variables; relative paths are, as always, relative to the current or working directory.

If your file loading process requires you to specify more than one input file to a macro, simply add an INFILE variable for each, appending numbers such as INFILE1, INFILE2, etc. and change your macro accordingly. If you will be using multiple macros, use different variables in each so that they don’t conflict.

A Batch File for Conversion

The command line instructions in the preceding section can be put into a batch file (Windows) or a shell script (Linux or Mac) so that you can specify all the necessary paths in a single command line. This file (convert.bat or convert.sh) can be placed in the same directory as our loaddata.mcr from the preceding section, as long as that directory is in your system’s PATH.

Windows — convert.bat:

SET INFILE=%1
tec360 loaddata.mcr -o %2

Now you may invoke it as follows:

convert.bat C:\path\to\input\file.plt C:\path\to\output\file.szplt

Linux or Mac OS — convert.sh:

#!/usr/bin/env bash
INFILE=$1
tec360 loaddata.mcr -o $2

After creating convert.sh, execute the command below to make it executable:

chmod +x convert.sh

The script may then be invoked as follows:

convert.sh /path/to/input/file.plt /path/to/output/file.szplt

The same technique can be used with additional macro files and additional filenames; you will simply need to set the environment variable(s) needed by each macro based on the arguments to the script (%1, %2, etc. in Windows batch files or $1, $2, etc. in Linux or Mac bash scripts).

Writing SZL Files With Macros

The principal difference between -o and -convert is that when you use -o, Tecplot 360 writes SZL data for you, whereas with -convert, you write the data file using a macro. All that we have already learned about using macros still applies; the following are valid scenarios:

  • A single macro loads all the data and also writes a .szplt file.

  • You load some data by specifying the filenames on the command line and the rest by specifying one or more macros, the last of which also writes the .szplt file.

  • Same as above, except the macro that writes the .szplt file is a separate macro.

  • A group of macros reads multiple groups of data files and writes mulipte .szplt files in a single Tecplot 360 operation (READDATAOPTION = NEW is used to start fresh for each group of loaded files).

  • Any other combination of data files and macros you can imagine.

You can create a macro file that writes a .szplt file by recording a save operation, but here, for the record, is the necessary command:

#!MC 1410
$!EXTENDEDCOMMAND
  COMMANDPROCESSORID = 'Tecplot Subzone Data Tools'
  COMMAND = 'WRITEDATASET FILENAME="C:\Users\kelvin\Desktop\out.szplt"'

You can adapt this macro to use relative paths or an environment variable, as we have already done with the macros we created to load data. Here is the macro rewritten to use the environment variable OUTFILE:

#!MC 1410
$!EXTENDEDCOMMAND
  COMMANDPROCESSORID = 'Tecplot Subzone Data Tools'
  COMMAND = 'WRITEDATASET FILENAME="|$OUTFILE|"'

The circumstances in which you might use -convert instead of -o are fairly limited. One use might be to write multiple copies of the .szplt file, for example to make a backup (though using the COPY or cp shell command is probably better).

Another use might be to automatically name the .szplt file based on some attribute of the loaded data, rather than requiring a name to be specified. Keep in mind that in the restricted macro environment provided when using -convert, the ability to inspect and analyze data is extremely limited. However, you could name a file based on the date, or on an auxiliary data element (using the AUXDATASET, AUXFRAME, or AUXZONE intristic variables) — or a combination of these:, such as

#!MC 1410
$!EXTENDEDCOMMAND
  COMMANDPROCESSORID = 'Tecplot Subzone Data Tools'
  COMMAND = 'WRITEDATASET FILENAME="|AUXDATASET:caseid| |DATE|.szplt"'

The variable DATASETFNAME contains the full paths of loaded data file(s) and can be used to give the output file the same base name as an input file. Since this variable can contain multiple paths if you have loaded multiple files, we recommend always using an index with it to specify which path you want; otherwise, the paths of all loaded files are substituted into the command, which will cause the save to fail.

#!MC 1410
$!EXTENDEDCOMMAND
  COMMANDPROCESSORID = 'Tecplot Subzone Data Tools'
  COMMAND = 'WRITEDATASET FILENAME="|DATASETFNAME[1]|.szplt"'

You may use |DATASETFNAME[2]|, |DATASETFNAME[3]|, and so on to refer to the path of a specific file, indexed by loading sequence.

For a full list of available macro variables, see the Scripting Guide for more information.