Hilbert Graphs
Volume Number: 3
Issue Number: 9
Column Tag: Fortran's World
Printing Hilbert Graphs 
By Mark McBride, Contributing Editor, Oxford, OH
After an extended absence from writing for MacTutor, I have found time to
develop new articles using Fortran on the Mac. The absence arose from developing of
an educational application in LightSpeed Pascal for use in my 400 level college course.
If only Fortran could have that type of development environment, I might never have
switched to Pascal for start from scratch Mac applications. A final release version of
that educational project should be finished by the summer (i.e., real soon now!). In
the meantime, Microsoft released version 2.2 in the Fall of 1986 and other individuals
picked up some of the slack (thanks for the article on controls in the April 1987
issue). This month’s article provides errata for Version 2.2, an overview of an
“Extras” disk available from Absoft, and a small application which illustrates using
the Print Manager, pictures, and procptr’s from within Fortran.
Extras Disk
Available from Absoft (the company which developed Microsoft Fortran for the
Mac) is a disk call “Extras.” This disk contains additional example programs and
subroutines that were not included in the Version 2.2 release. In particular the file
contains:
gpsl: An alternative spool.sub which is compatible with the Laserwriter.
Macxrf: A Fortran source file cross referencer.
ctlprc: A method for using toolbox filter procedures, including a sample program
using scroll bars.
splown: An additional, more flexible, interface to spool.sub. Three examples are
provided.
prdrag: An example program for use of the prport.sub routine which allows calls to
the Print Manager.
gpprnt: An example program of how to send a grafport to the printer.
scrdump: An example program of how to dump the current screen to the printer.
date: Assembly language routines for easy manipulation of the date and time
records available with the Mac.
errata: Errata for the include files and toolbx.par files.
If you are interested in this disk contact Absoft Tech Support at (904)
423-7587. [Most of these files have been placed on the source code disk for this
issue. I find it interesting that Microsoft never bo thered to tell anyone about these
errors, or correct them! -Ed] Several of the files are of interest for this month’s
article. First, Listing 1 provides the errata for the include files. The last line of
several of the include files mysteriously disappeared in the 2.2 release. Second,
Listing 2 provides errors in the trap descriptors. These must be changed in both the
toolbx.par file and the appropriate include files. One of these changes is for ‘HUnlock’
which is used in this month’s program. Listing 3 gives my modified version of the
prdefs.inc file that provides definitions for the print record structures, used with the
prprt.sub routine. Listing 4 gives the assembly code for the routine ctlprc.sub and the
associated link file. This routine provides the “glue” to return a pointer to a Fortran
procedure, which allows the use of filterprocs and control tracking procs. Discussion
of the use of this routine is given below in the Hilbert graph program. In listing 5, is a
little assembly routine to reset the randseed, since the Editor couldn’t find a copy of
a5Glob.inc that is supposed to provide access to the quickdraw globals. Finally, in
listings 6,7 and 8 is the actual Hilbert program for this month!
Fig. 1 Our Fortran Program prints Hilbert Graphs on a Laser
Hilbert Graph Program
This month’s program illustrates several Mac user interface features in a
Fortran program: use of the Print Manager via the subroutine prport.sub, use of
filter procedures via the subroutine ctlprc.sub, use of dialogs with the default button,
use of pictures, and the addition of color to your printed Imagewriter II output.
The printgraph program has four salient features:
1. initialization of the program structures including a random order hilbert curve
in pict format and use of common variables for the toolbox structures.
2. a short event loop to detect menu selections and a subroutine to process the menu
selection.
3. a print subroutine which prints the hilbert picture via a graphport which is also
Laserwriter compatible.
4. use of a background procedure during printing which allows the user to cancel
the print in progress
The first two processes are straight forward and/or have been covered
extensively in other MacTutor articles. The Hilbert curve is drawn using an
adaptation to Fortran of an algorithm presented by Michael Anderson (Byte, June
1986:137-148). The routine draws the curve once as a picture (OPENPICTURE,
CLOSEPICTURE). This allows the program to quickly redraw the graph to any grafport
(window or printer) by a call to DRAWPICTURE. Before the picture is drawn, the
order, the color, and the linesize of the Hilbert curve are set randomly.
The structure of the printgraph program keeps most of the toolbox related
variables accessible to all routines through a common block. The use of the common
block substantially reduced the resulting source code, given the source code intensity
of Fortran when using ‘implicit none.’ An additional advantage of the common block
approach (at least for me) is the ability to keep variable declarations grouped and
clear for the toolbox related variables. A disadvantage of the approach is that include