July 12, 2019

Basic SPP programming

Some people say you should learn a new programming language every year. Few people would be likely to choose SPP, and I don't intend to go too far with it, but I am finding it useful to write some simple programs to help me understand aspects of things as I migrate software out of the IRAF environment.

The best resource I have found is a 76 page guide written by Rob Seaman in 1992 entitled "An Introductory User’s Guide to IRAF SPP Programming". What I am writing here is largely a cheat sheet abstracted from that nice document.

SPP is basically a mongrel FORTRAN with a strong connection to RATFOR. An SPP source file has an ".x" extension and is compiled with the "xc" command. You are supposed to be able to run "xc" outside of the IRAF cl, but the current linux version of IRAF has some kind of bug and you get the error:

inp.c:13:10: fatal error: f2c.h: No such file or directory
   13 | #include "f2c.h"
      |          ^~~~~~~
I don't explicitly include f2c.h, so this is some wart in the current setup of the IRAF system. The workaround is to run mkiraf in whatever work directory you are using, and then launch the cl and type xc inside the CL, then you don't get the above error.

Compiling yields a file with the ".e" extension. In my case the file hello.x compiles to hello.e. Simply typing hello in the CL yields:

vocl> inp
ERROR: task `inp' not found
Seaman's guide explains what you need to do, namely:
task $inp = inp.e
inp
If you try running inp.e outside of the CL by typing "./inp.e" you are greeted with a prompt. Some kind of IRAF startup wrapper is running, and is probably documented somewhere. You really aren't supposed to do things this way. I have found you can type the name of your "task" to this prompt and it will run. When it exits, you are returned to this prompt and you need to type ^D to get out of whatever this is. There is some way to build things to run as "external tasks" outside of IRAF, but that is beyond anything I care to do.

Some examples

The simple hello world program looks like this:
# HELLO -- Sample program introducing SPP.
task hello = t_hello_world
procedure t_hello_world ()
begin
    call printf ("Hello, world!\n")
end
Notice that this defines a task which ought to correspond to the name of the file, or at least that is a convention that will avoid unnecessary confusion. There is plenty of necessary confusion, so it is best to avoid adding to it. The following program loops forever reading and displaying what is read:
task inp = t_inp

procedure t_inp ()

define SZ_BUF 128
char buf[SZ_BUF]

begin
    while ( 1 < 2 ) {
	call clgstr ( "?", buf, SZ_BUF )
	call printf ("Hello: %s\n")
	call pargstr ( buf )
    }
end


Have any comments? Questions? Drop me a line!

Tom's home page / tom@mmto.org