Executing Batch Job Files in IDL
Batch files in IDL are .PRO
files that contain a series of single IDL statements, executed in order. Batch files are not programs - they cannot be compiled and run. Instead, IDL interprets and executes each statement inside of a batch file sequentially, as if you had entered them directly at the IDL command prompt.
You can run IDL in non-interactive mode (batch mode) by entering the character @ followed by the name of a file containing IDL executive commands and statements.
To enter batch mode from the IDL command line, type:
@filename
at the IDL prompt, where filename is the name of the batch file. (Note that the @ symbol must be the first character on the line in order for it to be interpreted properly.) IDL reads commands inside the specified file until the end of the file is reached.
Note: Batch files can be nested by placing a call to one batch file within another, or they can call functions or routines.
If filename does not include a file extension, IDL searches the current working directory and the directories specified by the !PATH system variable for a file with filename as its base, with the file extension .pro. If filename.pro is not found in a given directory, IDL searches for filename with no extension in that directory. If filename is found (with or without the .PRO
extension), the file is executed and the search ends. If filename includes a full path specification, IDL does not search the directories in !PATH.
Batch execution can be terminated before the end of the file, with control returning to interactive mode without exiting IDL, by calling the STOP procedure from the batch file. Calling the EXIT procedure from the batch procedure has the usual effect of terminating IDL.
Interpretation of Batch Statements
Each line of a batch file is interpreted exactly as if it was entered from the keyboard at the IDL command line. In batch mode, IDL executes each statement before reading the next statement. This differs from the interpretation of programs compiled using .RNEW or .RUN, in which all statements in a program are compiled as a single unit and then executed.
Labels are illegal in the batch mode because each statement is compiled and executed independently.
Multiline statements must be continued on the next line using the $ continuation character, because IDL terminates every interactive mode statement not ending with $ by an END statement. A common mistake is to include a multiple-line block statement in a batch file as shown below:
; This will not work in batch mode.
FOR I = 1, 10 DO BEGIN
A = X[I]
...
...
ENDFOR
In batch mode, IDL compiles and executes each line separately, causing syntax errors in the above example because no matching ENDFOR is found on the line containing the BEGIN statement when the line is compiled. The above example could be made to work by writing the block of statements as a single line using the $ (continuation) and & (multiple commands on a single line) characters.
Example
An example of an IDL executive command line that initiates batch execution:
@myfile
This command causes the file myfile.pro
to be used for statement and command input. If this file is not in the current directory, the directories specified by !PATH are also searched.
An example of the contents of a batch file called in.pro
follows:
PRINT, 'Job started'
n = 100
TASK1, n
;TASK2
;TASK3
PRINT, 'Job complete'
Note there is no END statement in the batch file, above. The job of the batch file in.pro
is to line up the tasks to execute. In this case we named them TASK1, TASK2, etc., each of which is an IDL program. This example uses procedures to represent the tasks, but any program type will work. The program TASK1 that was called in the batch file (above) executes a single task:
PRO TASK1, n
COMPILE_OPT idl2
IF n EQ !null THEN n = 100
x = FINDGEN(n)
p = PLOT(x, /BUFFER, TITLE='Plot #000')
p.SAVE, 'plot000.png', RESOLUTION=96
FOR i=1, n-1 DO BEGIN
si = STRING(i, FORMAT='(i3.3)')
p.TITLE = 'Plot #' + si
p.SETDATA, x + i
p.SAVE, 'plot' + si + '.png', RESOLUTION=96
ENDFOR
p.CLOSE
END
See Also
Command-line Options for IDL Startup, Include Files, IDL Build Properties, Overview of IDL Program Types, Starting A Runtime Application, Special Characters