Previous PageNext Page

2.6. Batch

Batch processing is an effective way to automate repetitive tasks. All of the main display and processing functions can be saved in a batch file to be used later. The batch file is written in ASCII text format, and can be easily edited. Variables, if-then statements, for-next loops, and goto-label jumps can be used in a batch file.

2.6.1. Creating and using batch files

To create a batch file, select Batch Record from the menu. You will be asked to give a filename to the batch file. After this, each WinDisp3.5 command that you execute will be saved to the batch file. When you are finished recording, select Batch Stop in the menu.

These commands can now be executed again by selecting Batch Play and specifying the name of the file.

To see what the batch file looks like, and to make changes to it, use Batch Edit.

If you want to execute the commands one at a time, use Batch Debug; with this option you can also change parameters in each step before executing them.

See the example at the left.

2.6.2. Batch file format

The basic format for a command in a batch file is:

where Function is the menu command and "Parameters" are the parameters associated with this command. The "Parameters" are listed, separated by commas, in the same order as in the dialog box corresponding to the menu command.

For example, a command to display an image might look like this:

It is important to note:

2.6.3. Using variables

Repetitive tasks can be simplified by using variables in a batch file. For example, dekad images (every 10 days) can be given file names similar to the one shown on the previous page (dc97073.af), substituting variables for the month and dekad. The month and dekad will be stored as variables and used to specify the correct file name.
The user will then be prompted to enter the number of the month and dekad for the image desired. The responses will be read into the batch file to identify the image to display.

The dialog would look like this:

After replacing the variables by the values attributed to them, (%Month% by 07 and %Dekad% by 3), the command line becomes:

It is important to note:

2.6.4. If-then statements

With the command Batch If, an if-then statement can be used in a batch file as an error check, and allows the user to validate values for the variables. In programming procedures the commands of an if-then statement are indented to improve the readability.


The example above is an if-then clause delimited by the commands Batch If Begin and Batch If End. Here the variable %Dekad% is used to select the image that will be loaded. The first line checks that the value attributed to this variable is between 1 and 3. If the value is valid, the following line is executed by WinDisp3.5, and Batch If Else is not executed. If the value is not valid, the Batch If Else is executed.

This statement can be useful in automatically adapting names of variables when an error is detected as in section 2.6.3. For example, if the variable %Month% must contain two digits to be valid, but the user enters only one digit (1 to 9 for the months January to September), the if-then statement will place a 0 before the digit to correct the entry:

With the help of if-then statements, expressions to evaluate variables can be written in a batch file. Some of the frequently used symbols are used in the following example:

It is important to note:

2.6.5. For-next loops

To repeat the same command for a series of files (for example, the same type of image for different dates) the for-next loop can be adapted. The example below shows how a for-next loop is used to display images of three consecutive dekads:

Note that in for-next loops the value of the increment (the last parameter in the Batch For Begin line), can be negative, allowing you to have a command like the following:

WinDisp3.5 can execute loops placed within loops as well as within if-then statements.
For example:

2.6.6. Goto Label jumps

In certain cases, you will want to go from one location to another within a batch. A simple example would be if you ask the user if he wants to repeat the batch and display another image. The batch would resemble the following:

2.6.7. Batch files calling batch files

WinDisp3.5 is capable of calling up one batch from another. Simply save a Batch Play command within a batch, and this batch will execute the other. For example, the following batch executes Mybatch.cmd, then requires the user to rerun the batch a second time:

It is important to note:

2.6.8. Operators used in batch language

Parentheses must delimit each expression.

= Equal to
>= Greater than or equal to
<= Less than or equal to
> Greater than
< Less than
<> Not equal to
& And
| Or

Previous PageTop Of PageNext Page
This manual was prepared by the Global Information and Early Warning System of the United Nations Food and Agriculture Organization
© FAO/GIEWS - 1999
E-mail: Giews1@fao.org