fv Scripting Guide
Because fv and POW are written in Tcl, they are inherently scriptable. So long as one knows the necessary data structures and function calls, everything fv does can be controlled by a user-created Tcl script running inside of fv. This, however, is a formidable task. Plus, fv's internal behavior and data are subject to change with each new release.
To make scripting possible, then, a simplified (and hence limited) script interface has been added to fv. It consists of a small set of commands which perform the basic operations of opening FITS files and displaying their contents. Future versions should contain more capabilities.
(Note: This method of scripting fv replaces an earlier method. Although the older method still can be used, it is deprecated.)
Operational Summary
There are several ways to access fv's scripting commands. The simplest is to write a Tcl script which uses the commands directly and then have fv execute it. Give the script a ".fv" filename extension so that fv can recognize it. This method requires the user to open the file interactively within fv (using the same method as opening a FITS file). This scripting method is useful for implementing macros which can perform certain common operations at the user's request.
Alternatively, fv can be scripted by other programs, allowing those programs to make use of fv's capabilities remotely. These programs, however, do not need to be written in Tcl so long as they can communicate with fv. Currently fv supports XPA on unix platforms and AppleScript on MacOS for communication:
The XPA messaging system (http://hea-www.harvard.edu/RD/xpa/) developed by the SAO/HEAD R&D group implements a method of communicating between two programs running on unix platforms. Communication occurs either through standalone programs (ie, xpaget and xpaset), a C subroutine library, or a Tcl extension. fv uses the Tcl extension to make its scripting commands available, but the calling program can use any of the XPA methods to access the commands. The XPA software is not distributed with fv and must be obtained and built by the user. (Use '--with-tcl=$FV/lib' when configuring XPA to have it build the tcl extension; if not installing XPA into the fv directories, using '--prefix=$FV', one must also set the LD_LIBRARY_PATH environment variable to point to the directory containing libtclxpa.so.)
AppleScript (http://www.apple.com/applescript), the English-like language on all Macintosh computers (circa MacOS 7.5 and up), can also be used to control fv remotely. (Actually, any program on the Mac can control fv through the use of Apple Events.) Using the do script command, Tcl code can be passed to fv. Due to how Tcl's do script command and fv's scripting commands are implemented, fv commands must be prefixed with the fvCmds:: namespace specifier.
Many scripting commands also can be used as inquiries. Inquiries and commands are implemented using the same syntax, differing only in that commands supply the necessary parameters to perform an action, whereas inquiries leave them off indicating fv should return the current settings. When used with XPA, inquiries must use the xpaget tool and commands the xpaset tool.
Command Summary
preference | parameter | valid value |
open preference panel | open | N/A |
close preference panel | close | N/A |
minimize preference panel | minimize | N/A |
iconify preference panel | iconify | N/A |
select preference page | page | App, Keywords, Tables, Graphs, and Colors |
display File Selection | fileSelection | Open, Close |
color choice | activebackground | red, green, #cccccc, etc |
color choice | activeforeground | red, green, #cccccc, etc |
color choice | background | red, green, #cccccc, etc |
color choice | checkbuttoncolor | red, green, #cccccc, etc |
color choice | foreground | red, green, #cccccc, etc |
graph display | displayer | ds9, pow, saotng |
graph display | graphsize | 300x300, 500x300, 300x500 500x500, 700x500, 500x700 700x700 |
desk topy help | help | N/A |
auto-plot primary image | autoplotprimary | 0 - deselect 1 - select |
automatic format keys | autoreformatkeys | 0 - deselect 1 - select |
automatic update checksum | autoupdatechecksum | 0 - never 1 - if exist 2 - always |
display Fits file only | dispfitsonly | 0 - deselect 1 - select |
left justify string | leftjustifystring | 0 - right 1 - left |
protect required keyword | protectedkeys | 0 - deselect 1 - select |
show desktop manager | usedesktopmanager | 0 - deselect 1 - select |
use WCS info | wcsinfo | 0 - deselect 1 - selects |
write history key after modification | writehiskey | 0 - deselect 1 - select |
Window Management | winmanagement | Keep, Hid, Close |
Examples
The following commands will open 2 files and display their contents in several ways.
open ngc1316r.fit rate.fit # open 2 files included with fv select rate.fit # select one of files display header 1 # Open window of first extension's keywords display curve 1 time rate # Plot a curve of time vs rate in POW pow bounds 720 -30 950 300 # Resize graph's bounding box select ngc1316r.fit # Select other file display image 0 # Plot image set x [version] # Get fv's version numberType the preceding lines (without the comments) into a text file, name it commands.fv, then run it: either put it in the command line when starting fv (eg, "fv commands.fv") or open the file with the Open File menu item.
Using XPA from a Unix shell, one would do the following:
xpaset -p fv open ngc1316r.fit rate.fit xpaset -p fv select rate.fit xpaset -p fv display header 1 xpaset -p fv display curve 1 time rate xpaset -p fv pow bounds 720 -30 950 300 xpaset -p fv select ngc1316r.fit xpaset -p fv display image 0 xpaget fv versionThe -p option tells xpaset to not read any data from stdin. One can instead use stdin to send a series of Tcl commands en masse, using the command...
cat commands.fv | xpaset fv tclThis latter method allows one to insert real Tcl commands into the command sequence, whereas the individual xpaget/xpaset calls are restricted to the specific scripting commands.
Finally, if using AppleScript, the commands are...
tell application "fv" activate do script "fvCmds::open ngc1316r.fit rate.fit" do script "fvCmds::select rate.fit" do script "fvCmds::display header 1" do script "fvCmds::display curve 1 time rate" do script "fvCmds::pow bounds 720 -30 950 300" do script "fvCmds::select ngc1316r.fit" do script "fvCmds::display image 0" do script "fvCmds::version" set x to the result end tellNote that AppleScript will actually start fv if it isn't already running.
Additional examples of scripting can be found in the sample_scripts directory within the fv distribution.