1.3.6. - Macro Facility
One of spec's most powerful features
is its provision for defining
macros.
Through macros, you can simplify
use of the diffractometer
as well as determine the style and format of the data output.
Through the macro facility, you can customize the
environment to
include any enhancements or specialized requirements for your experiment.
Standard macro sets included in the spec package support
conventional two-circle,
four-circle
and z-axis
diffractometers along with some specialized
liquid surface diffractometers.
These macros control the measurement and the recording
of experimental data and establish
a standard format for ASCII
data files.
An example of a simple macro that can be
used to record a comment
on the printer is
1.FOURC> def com ' 2.quot> on(PRINTER) 3.quot> printf("$*\n") 4.quot> off(PRINTER) 5.quot> '
6.FOURC> Notice the prompt shows the program is expecting
the quote to be closed.
The variable
PRINTER contains a string naming the printer device
used to document the diffractometer operation.
To use the above macro, type:
1.FOURC> com This is a comment. This is a comment.
2.FOURC> The text
This is a comment
is substituted in the
printf()
function for the symbol
$* and is printed on both the screen and the printer.
Each argument following a macro call
is available to the macro
using
$1, $2, ...,
where
$1 refers to the first argument, and so on.
Up to 25 arguments may be used.
An argument is a string
of characters separated by
white space
(spaces and tabs)
or enclosed in single or double quotes,
$* represents all the arguments,
and
$# is the number of arguments.
When a macro definition contains argument
substitution, and
you invoke that macro
with more arguments
than needed, the extra arguments you typed up to the next
;, } or newline
disappear.
However, if the macro does not use argument substitution in
its definition,
text typed following the macro invocation is not thrown away.
To see what a macro contains,
use the command
prdef
to print out the
macro definition.
1.FOURC> prdef com def com '
on(PRINTER)
printf("$*\n")
off(PRINTER)
'
2.FOURC> Notice that the form of the definition, if written to a file, would
be suitable for reading back in as a macro definition.
The standard macro library
is read automatically the first time you run
spec or when you start the program with the
-f flag.
You can get a listing of all the currently defined macros
with the command
lsdef.
1.FOURC> lsdef ALPHA (4) bug (275) hklscan (1639) qdo (10)
AZIMUTH (4) ca (182) hkradial (334) rplot (10)
BETA (4) calcA (7) hlcircle (339) rplot_res (112)
CEN (10) calcE (7) hlradial (333) save (432)
Escan (1448) calcG (7) hscan (139) savegeo (1121)
F_ALPHA (4) calcHKL (7) initdw (42) saveslits (99)
F_AZIMUTH (5) calcL (8) initfx (39) saveusr (0)
F_BETA (4) calcM (7) initnec (44) savmac (118)
F_OMEGA (5) calcZ (7) initoki (39) scan_head (5)
F_PHI (5) cat (14) inittemp (33) scan_loop (5)
Fheader (0) cd (11) klcircle (339) scan_move (5)
Flabel (2) ci (177) klradial (333) scan_on (192)
Fout (2) cl (22) kscan (139) scan_plot (0)
Ftail (0) com (12) l (16) scan_tail (5)
H (4) comment (184) less (15) set (344)
K (4) config (109) lm (539) set_E (314)
L (4) count (6) lp_plot (674) set_dial (649)
LAMBDA (4) ct (47) ls (13) set_lm (349)
OMEGA (4) cuts (764) lscan (139) setaz (448)
Pheader (0) cz (177) lup (419) setlat (764)
Plabel (2) d (12) mail (16) setmode (927)
Pout (2) d2scan (564) measuretemp (1) setmono (368)
RtoT_0 (162) d3scan (688) mesh (1221) setplot (1119)
RtoT_1 (162) debug (212) mk (175) setpowder (867)
RtoT_2 (161) do (9) move_E (208) setscans (67)
RtoT_3 (163) dscan (95) move_em (8) setsector (1341)
TtoR_0 (160) dtscan (143) mv (175) setslit (464)
TtoR_1 (160) dumbplot (334) mvd (192) setslits (469)
TtoR_2 (159) end_reflex (131) mvr (191) settemp (217)
TtoR_3 (161) freeze (456) mz (268) show_cnts (327)
_check0 (240) g_aa (4) ned (14) showslits (114)
_chk_lim (266) g_al (4) newfile (1165) showtemp (133)
_cleanup2 (0) g_bb (4) newmac (270) splot (8)
_cleanup3 (0) g_be (4) offd (13) splot_res (150)
_count (158) g_cc (4) offp (12) startgeo (45)
_do (479) g_chi0 (5) offsim (126) starttemp (225)
_getcut (8) g_chi1 (5) offt (10) startup (245)
_head (1363) g_frz (4) ond (12) te (105)
_hkl_lim (84) g_ga (4) onp (11) teramp (458)
_hklline (1254) g_h0 (5) onsim (127) th2th (141)
_hklmesh (638) g_h1 (5) ont (9) tscan (732)
_loop (413) g_haz (5) or0 (549) tw (742)
_mo_loop (175) g_k0 (5) or1 (551) u (10)
_mot (124) g_k1 (5) or_swap (320) uan (23)
_move (37) g_kaz (5) p (8) ubr (31)
_pcount (132) g_l0 (5) pa (1301) uct (364)
_plot_scale (392) g_l1 (5) pl (176) umk (31)
_pmove (131) g_laz (5) pl_CFWHM (10) umv (19)
_scanabort (102) g_mo_d (5) pl_COM (10) umvr (20)
_setcut (8) g_mo_s (5) pl_FWHM (10) unfreeze (39)
_settemp (1) g_mode (4) pl_LHMX (10) upl (24)
_tail (83) g_om0 (4) pl_MAX (10) uwm (694)
_update1 (204) g_om1 (5) pl_MAXX (10) vi (13)
_update2 (255) g_phi0 (5) pl_MIN (10) vt52_rplot (1190)
_update4 (370) g_phi1 (5) pl_MINX (10) vt52plot (914)
_var (171) g_sect (4) pl_SUM (10) w (12)
a2scan (1172) get_E (74) pl_SUMSQ (11) wa (231)
a3scan (1439) getvar (65) pl_UHMX (10) waitall (7)
add_reflex (408) gpset (123) pl_xMAX (11) waitcount (7)
an (173) gt101_rplot(1190) pl_xMIN (11) waitmove (7)
ansi_rplot (1196) gt101plot (915) plot (40) wh (48)
ansiplot (933) h (4) plot_res (435) whats (744)
ascan (865) help (24) prcmd (42) wm (1232)
beep (12) hi (7) pts (87) yesno (162)
beg_reflex (283) hkcircle (339) pwd (11)
br (175) hklmesh (1095) qcomment (176)
2.FOURC>
Each macro is listed
as well as the number of characters in its definition.
Some macros have zero length -- their definitions are assigned
during the course of an experiment.
In the standard library,
macros that are only used within other macros
(and not meant to be referenced directly by the user)
begin with an underscore.
Another macro handling command allows you to remove
a macro definition.
1.FOURC> undef com
2.FOURC> prdef com com: undefined.
3.FOURC>
There are several
special
macro names.
If a macro named
cleanup
is defined, it will be
automatically invoked whenever there is an error
or
^C
interrupt.
This macro can be defined
to print a message, update a file, return motors to a starting position, etc.
For example, in the standard macro
library,
something like the following is defined for the duration
of a scan:
def cleanup '
comment "Scan aborted after %g points." NPTS
undef cleanup
'
Similarly, a macro named
cleanup1 can be defined, which behaves the same way.
However, if
cleanup exists, it will be run first.
Also
begin_mac, end_mac and
prompt_mac have special meaning.
(text forthcoming ...)
|