next up previous contents index
Next: ``KEYBOARD'' Interface Commands for Up: Appendix B: FIT2D Macro Previous: Variables


More Complicated Macros

More complicated, and powerful macros can be produced. Probably, the best manner in which to produce such macros, is to produce a normal macro, by carrying out the series of data analysis operations once, and then editting the macro file to add, for example, a loop to repeat the operation for a whole series of files.

``Do'' loops may be added to the macro to allow counted looping controlled by integer variables. This is best illustrated with an example. The following macro will input and display a series of files FILE_1010.DAT, FILE_1020.DAT, to FILE_1100.DAT, in binary format.

%!*\ BEGINNING OF IO MACRO FILE
%!*\
%!*\ This is a comment line
%!*\
DO #COUNT = 10, 100, 10
   I2C
   #COUNT
   no
   3
   #CVALUE
   CONCATENATION
   FILE_1
   #CVALUE
   #CVALUE
   CONCATENATION
   #CVALUE
.DAT
   #CVALUE
   INPUT DATA
   BINARY (UNFORMATTED)
   #CVALUE
   768
   512
   INTEGER (2-BYTE)
   yes
   no
   PLOT DATA
END DO
%!*\ END OF IO MACRO FILE

The looping is controlled by the DO loop, which works like the Fortran-90 Do loop. The loop variable, in this case #COUNT starting with the first value, and will be incremented up until the second value, in steps defined by the third value. The loop ends when the END DO statement is found. Here the commands within the loop have been indented, with the exception of an input string, where we don't want any preceeding blanks.

To form the file name the commands I2C and CONCATENATE have been used. I2C converts the loop integer counter to a character string with a fixed number of characters, so zeros will preceed low numbers. CONCATENATE is used to build up the file names from a fixed prefix, the changing numerical part, and the fixed file exetension. The variable #CVALUE is set with the file name and used within the INPUT command.

Macros can be made interactive, and given a ``Graphical User Interface'', using the QUESTION command. Thus, the simple example above can be made much more sophisticated and versatile, by getting the user to click on the first and last file in a file series, and by using the DEDUCE FILE SEQUENCE command to define values of variables which define the loop, and the parts of the file name. The following example shows such a macro:

%!*\ BEGINNING OF GUI MACRO FILE
%!*\
%!*\ fit2d_display.mac : Inputs a series of images and displays together
%!*\
QUESTION
%!*\
%!*\ Definition of interactive input of a value
%!*\ Data value type
INPUT FILE
%!*\ User prompt
CLICK ON FIRST FILE OF SEQUENCE
%!*\ Give default
y
n
%!*\ Help text (up to 100 lines)
This is the first file in a sequence
of files to be displayed.
\\
%!*\ Program variable
#START_FILE
%!*\
%!*\ End of Definition
%!*\
QUESTION
%!*\
%!*\ Definition of interactive input of a value
%!*\ Data value type
INPUT FILE
%!*\ User prompt
CLICK ON LAST FILE OF SEQUENCE
%!*\ Give default
y
y
%!*\ Default value
G93001.bsl
%!*\ Help text (up to 100 lines)
Click on last file in sequence to be
treated.
\\
%!*\ Program variable
#END_FILE
MESSAGE
FILE SEQUENCE DEFINED
\\
%!*\
%!*\ End of Definition
%!*\
DEDUCE FILE SEQUENCE
#START_FILE
#END_FILE
%!*\
%!*\ Loop through files, input and display them 
%!*\
DO #COUNT = ##START, ##END, 10
%!*\
%!*\ Form current file name
%!*\
%!*\
   I2C
   #COUNT
   ##VARIABLE
   ##NUM_CHARS
   #SCOUNT
   CONCAT
   ##PREFIX
   #SCOUNT
   #FILE_IN
   CONCAT
   #FILE_IN
   ##POSTFIX
   #FILE_IN
   CONCAT
   #FILE_IN
   ##EXTENSION
   #FILE_IN
%!*\
%!*\ Input image
%!*\
   INPUT DATA
   BINARY
   #FILE_IN
   768
   512
   INTEGER (2-BYTE)
   YES
   NO
%!*\ Display image
   PLOT
END DO
%!*\ END OF IO MACRO FILE

Here ##START, ##END, ##VARIABLE, ##NUM_CHARS are variables which have been defined automatically by the command DEDUCE FILE SEQUENCE; see Section 15.25, Page [*]. It may be noticed that the MESSAGE command has been used to provide some user feed-back on the progress of the macro. Note: The step of 10 has been left in the macro, as the files exist, only in step of 10.

The above example can be made even more flexible with further user input with the QUESTION command (see Section 15.77, Page [*]) e.g. to define the size of the image to input.


next up previous contents index
Next: ``KEYBOARD'' Interface Commands for Up: Appendix B: FIT2D Macro Previous: Variables
Andrew Hammersley
2004-01-09