批量处理
您可以在批处理模式下运行 Tecplot 360 来创建图形,而无需在屏幕上显示任何图形界面。当需要处理多个文件进行打印或导出时,这可以节省时间。在批处理模式下,Tecplot 360 可以在您的工作站本地执行,或通过终端远程执行(仅限 Linux)。
批量处理设置
-
创建一个宏文件来控制批处理过程。您可以通过以下方式完成此操作:录制 Tecplot 360 会话,或使用任意文本编辑器。请参阅Macros.
-
根据需要创建布局和样式表文件。
-
准备数据文件。
-
在非批处理模式下运行 Tecplot 360 来调试宏文件。
| 仅当文件以布局或样式表开头时,宏才更可能向前兼容(即适用于未来版本)。更多信息请参考脚本指南。 |
当您在批处理模式下启动 Tecplot 360 时,需要提供要执行的宏文件名。启动批处理模式的最小命令如下:
tec360 -b -p mymacrofile.mcr
该-b标志指示 Tecplot 360 以批处理模式运行,而-p告诉 Tecplot 360 运行其后指定的文件名(本例中为 mymacrofile.mcr)。
如果宏文件使用-p扩展名,则可以省略该标志(因此在上面的示例中可以省略)。.mcr批量处理模式与 Linux |
有关 Linux 批处理模式命令行参数的信息,请参阅
。如果在批处理模式下运行时遇到任何问题,请参阅Tecplot 360 Command Line指南以获取更多信息。Rendering and Export Troubleshooting批量处理模式与 Windows
在 Windows 下,从命令行或通过
文件调用 Tecplot 360 时会立即返回,而不会像 Linux 和 Mac 那样等待应用程序完成工作。.bat然而,在使用批处理模式时,通常需要等待 Tecplot 360 完成一个操作后再继续下一个。为此,请在命令前加上
。例如:start /wait。例如:
start /wait tec360 -b -p mymacrofile.mcr
批处理模式与宏
在 Mac 上运行批处理模式时,必须调用可执行文件的完整路径:
"/Applications/Tecplot 360 EX 2025 R2/Tecplot 360 EX 2025 R2.app/Contents/MacOS/Tecplot 360 EX 2025 R2" -b mymacro.mcr
如果要在批处理模式下处理多个文件,建议为完整的可执行文件路径设置别名。设置别名时,请在终端中输入以下命令:~/.bashrc:
alias tec360='"/Applications/Tecplot 360 EX 2025 R2/Tecplot 360 EX 2025 R2.app/Contents/MacOS/Tecplot 360 EX 2025 R2"'
定义别名后,在批处理模式下运行宏将更加便捷。只需添加 -b 标志,后跟要使用的宏即可:
tec360 -b mymacro.mcr
有关在 Mac 上设置别名以及通过命令行运行 Tecplot 的更多信息,请参阅Installation Guide.
使用布局文件进行批处理
将布局文件与批处理结合使用既强大又灵活,也是推荐的操作流程。通过布局文件,您可以在单个文件中使用一个或多个帧来组织绘图。布局文件管理数据集,并可在运行时通过命令行或加载布局文件的宏进行动态修改。
布局文件必须包含与所加载数据兼容的$!READDATASET宏指令。创建此类布局的最简单方法是:先将与待处理文件类似的文件加载到 Tecplot 360 中,按需设置绘图样式后保存布局。布局中$!READDATASET指令指定的文件名将被命令行中指定的文件名覆盖(见下文)。 |
例如,要在批处理模式下执行以下任务序列:
-
从用户提供的文件名加载数据文件。
-
创建特定样式的绘图。
-
生成绘图的 PostScript 文件。
可按如下方式设置批处理脚本:
-
获取一个具有代表性的待绘图数据文件。
-
创建所需绘图样式的布局文件。(本例中将文件命名为batch.lay).
-
使用文本编辑器创建以下宏(本例中将此宏命名为batch.mcr):
#!MC 1410 $!EXPORTSETUP EXPORTFORMAT = PS PRINTRENDERTYPE = VECTOR $!PRINTSETUP PALETTE = MONOCHROME $!EXPORT EXPORTREGION = CURRENTFRAME $!Quit
-
使用以下命令在批处理模式下运行任务:
tec360 -b -p batch.mcr -y psoutput.ps batch.lay mydatafile
tec360 -b |
以批处理模式启动 Tecplot 360 |
-p |
指示 Tecplot 360 使用以下宏文件。(注意:如果宏文件使用.mcr扩展名,则无需此参数)。 |
batch.mcr |
Macro file |
-y |
指示 Tecplot 360 使用以下导出文件 |
psoutput.ps |
导出文件 |
batch.lay |
要使用的布局文件 |
mydatafile |
要使用的数据文件;覆盖布局中指定的文件 |
多数据文件处理
在Batch Processing Using a Layout File中,我们设置 Tecplot 360 处理用户提供的数据文件(一个或多个)并创建单个输出文件。如果需要对大量输入文件(每次一个)重复上述过程,可以通过循环实现:在 Tecplot 360 外部使用操作系统的 shell 循环结构,或在 Tecplot 360 内部使用 Tecplot 宏语言中的流程控制命令。
Looping outside of Tecplot 360
以下示例展示了在两个不同操作系统中,通过操作系统循环启动 Tecplot 360 的命令文件。Tecplot 360 处理五个名为dnn.plt的数据文件,并创建十个名为dnn.out的输出文件,其中nn从 1 到 10。
Looping operations in Tecplot 360
在Looping Outside Tecplot 360中,我们设置 Tecplot 360 使用 shell 进行循环处理多个数据文件。此过程存在两个缺点:
-
Shell 语言在不同操作系统之间不可移植。
-
处理每个数据集时,Tecplot 360 必须反复启动和停止。
A more efficient approach is to loop through data files internally within Tecplot 360. Here, both the layout file and data files are named within the macro. The command line for this example is simple, as shown below:
tec360 -b -p batch.mcr
where the macrobatch.mcrcontains:
#!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 $!OPENLAYOUTThe command loadsbatch.laybut replaces the data file referenced in the layout withALTDATALOADINSTRUCTIONSthe filename in the subcommand.$!EXPORTSETUPThe command is used in two places. Initially, it sets the export format, and later it only changes the filename to be exported.$!EXPORTThe command performs the actual export operation.
| If you wish to generate multiple different plots using the same dataset, a style sheet is more efficient than a layout file. |
Batch Diagnostics
Each time Tecplot 360 runs in batch mode, it creates a file defined by the name in theBATCHLOGFILEenvironment variable; if this environment variable is not defined, it uses a file namedbatch.login the directory where Tecplot 360 was launched. If the name given in theBATCHLOGFILEenvironment variable is a relative path, the startup directory of Tecplot 360 is automatically prepended. Real-time records of operations performed in Tecplot 360, along with warnings and error messages, are sent to thebatch.logfile.
Batch Conversion to SZL Format
Two command-line options of Tecplot 360-o和-convertallow you to more easily convert existing datasets to SZL (Tecplot's high-performance subzone data format, with file extension.szplt). Since it is command-line driven, this feature is suitable for converting large numbers of files without user intervention, or as a step in solver post-processing.
When launched using these two options, Tecplot 360 does not require a license, so you can perform data file conversion on any available workstation without concern. Only Tecplot 360 installation is needed.
In a restricted batch session launched via-o或-convert, Tecplot 360 can read data files (using any of its data loader plugins) 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.
In most cases, you will want to use the-ooption for SZL conversion. For more information on scenarios where theWriting SZL Files With Macrosoption is used, please refer to-convert。
Loading Data Files by Name
The -oThe option outputs any loaded data to the specified.szpltoutput file. Simply add-ofollowed by the output file name or path to the command line typically used for loading data. Tecplot 360 will then write the data to SZL format (and exit) instead of displaying graphics in the workspace. For example, if you typically use the following command line to start exploring data in two Tecplot.pltfiles:
tec360 file1.plt file2.plt
You can instead use the following command line to have Tecplot 360 convert these data files into a single.szpltfile:
tec360 file1.plt file2.plt -o output.szplt
If your data is in a non-Tecplot format, it may not be possible to load all data into Tecplot 360 at once via a simple command line as described above. Some formats (e.g., CGNS) support loading multiple files but require all files to belong to the same case, with additional cases needing further load operations. Other loaders do not support multiple files at all and require all subsequent loads to be appended after the first load. In such cases, you can record a macro to load the data.
Loading Data Files with Macros
Create a macro to load part or all of the data when one or more of the following conditions are met:
-
The data cannot be loaded via a single command line because the data is distributed across multiple files and the required loader does not support loading all files via a single command line.
-
The file names of the data files do not allow Tecplot 360 to clearly determine the correct data loader. (However, in some cases, you can directly rename the files.)
-
You need to set advanced options for the loader to successfully load the data. In other words, in the "Load Data" dialog, you need to use the "Open with Advanced Options" command (accessed by clicking the menu triangle next to the "Open" button) or check the "Advanced Options" checkbox.
Simply follow the process you typically use with the Tecplot 360 graphical user interface to record a macro for loading data. For more information on recording macros, seeMacro Creation。
The recorded loading process can include multiple load operations with additional options, any number of different file formats, and the selection of advanced loader options. After recording the macro, specify it on the command line when callingtec360. As before, simply add-ofollowed by the SZL file name to be created:
tec360 loaddata.mcr -o output.szplt
The recorded macro contains fixed file names and directory paths for the loaded files, making it difficult to use the macro for other data files. We will address this later with some simple macro modifications.
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. Therefore, instead of creating a single macro that loads multiple files, you can record multiple macros, each loading one data file, and then specify only the macros actually needed for a specific project. For example:
tec360 loaddata1.mcr loaddata2.mcr loaddata3.mcr -o output.szplt
Combined with the techniques in the following sections that allow macros to load data files other than those recorded, you can create a macro "toolkit" for converting various types of files you typically handle.
There is one issue with using multiple macros on the command line. When you record a load operation, the resulting macro may contain an instruction telling the loader to erase any loaded data. When you attempt to load data, the second macro file specified will erase the data loaded by the first macro, and so on for the third, fourth macros, wasting time and making it appear that only the last macro loaded data.
Fortunately, this is easy to fix. Simply load the macro into any text editor (Notepad.exewill do), find any line containing:READDATAOPTION = NEWChange it toREADDATAOPTION = APPENDinstead. Such macros will work correctly even if specified first on the command line, because each conversion is a completely new Tecplot 360 session starting with no data loaded.
Mixing Macros and Data Files
A macro is just another data file: Tecplot 360 happens to execute it as instructions. Therefore, you can mix data files and macros on the command line to load data, using macros only for files that cannot be loaded directly by specification. Files are processed in the order they appear on the command line. For example:
tec360 cube.plt loadcircle.mcr -o output.szplt
This will loadcube.plt(a regular Tecplot data file), then executeloadcircle.mcr, the macro may load another data file (or even multiple files). The loaded data is then written tooutput.szplt.
Using Relative Paths
As mentioned earlier, the file paths you load and save become part of the recorded macro. The macro will always load the input file with the same name and in the same directory as when it was recorded. Similarly, the output file will always be saved with the same name and in the same directory as when the macro was recorded.
If you have set up your simulation workflow so that the solver always generates output files with the same name, but each case is in a different directory, you only need to edit the recorded macro to use relative paths. This way, the macro will work with files in the current directory (regardless of the directory), and you simply need to switch to the directory containing the files to be converted before executing the conversion.
For example, here is a simple macro,loadcube.mcr, which we recorded to load a single.pltfile. (The actual macro might be longer, because loading a.pltfile doesn't even require a macro, but we'll keep it simple here.)
#!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 include the definition of the variableMFBD, which points to the current (or working) directory that was active when the macro was recorded. Since we loadedcube.pltfrom the desktop folder (which is also the working directory), the macro uses theMFBDvariable in theREADDATASETcommand. If we load a data file from a directory other than the working directory, theREADDATASETcommand will include the full path (for example, on Windows, it might start withC:\). Below is what the macro looks like whencube.pltis located 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 theMFBDvariable, so we can remove theVarSetcommand and the correspondingRemoveVarcommand (though keeping them won't hurt). We will also remove everything except the file name from theREADDATASET and WRITEDATASETcommands. We will also changeREADDATAOPTION到APPEND, as described in the previous section. Below is the modified macro.
#!MC 1410 $!READDATASET '"cube.plt" ' READDATAOPTION = NEW RESETSTYLE = YES VARLOADMODE = BYNAME ASSIGNSTRANDIDS = YES VARNAMELIST = '"X" "Y" "Z"'
This macro now reads thecube.pltfile from the current (or working) directory. Save it asloadcube.mcrAfter that, the conversion can be invoked as follows:
cd C:/path/to/files tec360 C:/path/to/loadcube.mcr -o output.szplt
Note that when invoking the conversion, you must specifyconvert.mcrthe full path, as it is not in the working directory. If the Tecplot 360bindirectory is not in the systemPATHvariable, you must also providetec360the full path to the executable. (For simplicity, our example assumestec360is located inPATH.)
Using Environment Variables in Loader Macros
. When the data files to be converted may have different names but the same format and require the same loader options, you can write a macro that accepts paths specified externally. The most straightforward method is to set environment variables before starting Tecplot 360. The macro file then uses these environment variables as input file paths. Here, we will use the variableINFILEalong with the macro from the previous section. Since it no longer only loadscube.plt, we will name the macroloaddata.mcrinstead ofloadcube.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
Absolute or relative paths can be used in environment variables; relative paths are always relative to the current or working directory.
If the file loading process requires specifying multiple input files for the macro, simply add oneINFILEvariable for each file, appending numbers, e.g.,INFILE1, INFILE2, etc., and modify the macro accordingly. If using multiple macros, use different variables in each macro to avoid conflicts.
A Batch File for Conversion
The command-line instructions from the previous section can be placed in a batch file (Windows) or shell script (Linux or Mac) to specify all necessary paths in a single command line. This file (convert.bat or convert.sh) can be placed in the same directory asloaddata.mcrfrom the previous section, as long as that directory is in the systemPATH.
Windows — convert.bat:
SET INFILE=%1 tec360 loaddata.mcr -o %2
Now you can 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
Createconvert.shAfter creation, execute the following command to make it executable:
chmod +x convert.sh
Then the script can be invoked as follows:
convert.sh /path/to/input/file.plt /path/to/output/file.szplt
The same technique can be applied to other macro files and filenames; you simply need to set the environment variables required by each macro based on the script parameters.%1, %2etc., used in Windows batch files$1, $2etc., used in Linux or Macbashscripts).
Writing SZL Files With Macros
The main difference between the two is:-o
and -convertWhen you use-o, Tecplot 360 writes the SZL data for you; whereas when using-convert, you need to write the data file through a macro. All the macro usage methods we learned earlier still apply, and the following are valid application scenarios:
-
A single macro loads all data and writes simultaneously to.szplt file.
-
You specify the filename via the command line to load partial data, then load the remaining data through one or more macros, with the last macro writing simultaneously toszplt file.
-
Same as above, but the macro that writes toszpltfile is a separate macro.
-
A set of macros reads multiple data files and writes multiple .szplt files in a single Tecplot 360 operation
READDATAOPTION = NEWUsed to reinitialize each set of loaded files). -
Any other combination of data files and macros you can think of.
You can create a macro that writes to.szpltfile by recording the save operation, but the necessary commands are provided here for reference:
#!MC 1410 $!EXTENDEDCOMMAND COMMANDPROCESSORID = 'Tecplot Subzone Data Tools' COMMAND = 'WRITEDATASET FILENAME="C:\Users\kelvin\Desktop\out.szplt"'
You can adjust this macro to use relative paths or environment variables, just as we did when creating macros for loading data. Here is the macro rewritten using environment variables:OUTFILE:
#!MC 1410 $!EXTENDEDCOMMAND COMMANDPROCESSORID = 'Tecplot Subzone Data Tools' COMMAND = 'WRITEDATASET FILENAME="|$OUTFILE|"'
The scenarios for using -convert instead of -o are relatively limited. One possible use is to write multiple copies of the .szplt file.szpltfile, for example to create backups (although usingCOPY or cpshell command might be better).
Another use case might be to automatically name files based on certain attributes of the loaded data,szpltwithout needing to manually specify the name. Note that when using the-convertprovided restricted macro environment, you can check andAUXDATASET, AUXFRAME或AUXZONEuse built-in variables (or combinations thereof) to name files, for example:
#!MC 1410 $!EXTENDEDCOMMAND COMMANDPROCESSORID = 'Tecplot Subzone Data Tools' COMMAND = 'WRITEDATASET FILENAME="|AUXDATASET:caseid| |DATE|.szplt"'
VariableDATASETFNAMEcontains the full path of the loaded data file, which can be used to make the output file have the same base name as the input file. Since this variable may contain multiple paths when loading multiple files, we recommend always using an index to specify the desired path; otherwise, allallpaths of the loaded files will be substituted into the command, causing the save to fail.
#!MC 1410 $!EXTENDEDCOMMAND COMMANDPROCESSORID = 'Tecplot Subzone Data Tools' COMMAND = 'WRITEDATASET FILENAME="|DATASETFNAME[1]|.szplt"'
You can use|DATASETFNAME[2]|, |DATASETFNAME[3]|etc. to reference the path of a specific file, indexed by load order.
For a complete list of available macro variables, please refer to the Scripting Guide for more information.