next up previous contents
Next: 10 The ifeffit command-line program Up: IFEFFIT Tutorial Previous: 8 Saving data and logging your


9 Defining and Using Macros

Macros are named sequence of IFEFFIT commands which can be run by simply typing the macro name. Macros are primarily designed to cut down on typing for repetitive tasks and to make IFEFFIT easier to use and customize. While not going far enough to making IFEFFIT a real programming language, macros offer some flexibility normally associated with batch processing languages.

A macro is defined with the macro keyword, after which comes a series of commands as you would type them to the command line and ending with end macro. As a simple example, defining a macro named make_ps would look like this would be

 macro make_ps
   plot(device="/ps",file= "ifeffit.ps")
 end macro
Now, typing the new command make_ps will create a postscript file named ifeffit.ps of the current plot. This macro is only one line long, which doesn't save much typing, but we'll get to longer examples below. First, let's add an optional argument: what if you want the Postscript file to be named something other than ifeffit.ps, since multiple executions would just keep overwriting this file? For this, you can supply macro arguments, which are variables named $1, $2,..., $9 that are expanded in place as text strings by the first, second, ..., ninth arguments when the macro is run. The definition look like this
 macro make_ps
   plot(device="/ps",file= "$1")
 end macro
and would be invoked by make_ps data_01.ps or make_ps my_fit.ps. OK, but now what happens if you don't give an argument? Well, the argument $1 would be "", so that would be the same as saying ...,file=""), which would create the default file ifeffit.ps.

You can also define a default parameter for the macro at its definition, by including the default value on the ``macro'' line. That is,

 macro make_ps  other.ps
   plot(device="/ps",file= "$1")
 end macro
the default value for $1 will be other.ps. The value for this parameter can still be overridden by saying make_ps data_01.ps.

Macros can be of arbitrary length (though the total number of macro lines in memory is fixed at 2048 lines). In addition, if the first line of a macro definition is a plain text string, this will be used as the macro documentation, and will be shown with show @macros. A more typical macro may look like this

 macro do_pre_edge  a
    "Read File, Calculate Pre-Edge, Plot, Write File"
    read_data($1.xmu,  type = xmu,  group = my)
    pre_edge(my.energy, my.xmu)
    my.norm = my.pre / edge_step
    $title1 = 'normalized, pre-edge subtracted data'
    write_data(file = $1.pre, $title1,  energy, pre, norm, xmu)
 end macro
More example macros are included in the main IFEFFIT distribution.


next up previous contents
Next: 10 The ifeffit command-line program Up: IFEFFIT Tutorial Previous: 8 Saving data and logging your
Matt Newville
2001-10-05