See the first 100 lines or so of s1r4.c.
