McFace
Volume Number: 3
Issue Number: 7
Column Tag: Fortran's World
McFace Fixes MS Fortran 
By Chuck Bouldin, Gaithersburg, MD
Fortran Toolbox Access with McFace
Most programmers who use Fortran on the Macintosh do so because:(1) they
already know Fortran, (2) they have a lot of existing code that they want to run on the
Mac, or (3) they want to add Macintosh features to existing programs. So far, the
articles on MacFortran have dealt mainly with adding toolbox and Mac-specific
features to Fortran programs. From earlier articles, it is clear that adding Mac-style
features to existing Fortran code is not easy to do. In this article I discuss the use of
McFace, a large, high level, “glue” subroutine that greatly simplifies adding Mac
features to Fortran programs.
McFace is particularly useful for porting existing Fortran applications, adding to
the existing code the Mac “look and feel”. Apple is now pushing “desktop engineering”
and 68020 upgrades are becoming commonplace, so it is important to find an easy
means to port the large body of existing Fortran engineering and scientific code, while
adding the user interface features required in a good Macintosh application.
McFace is a single, large (134K, whew!) subroutine that allows easy access to
much of the Mac toolbox. The user interface is reduced to a single subroutine call with
arguments that are used to pick out the various functions supplied by McFace. By
making very small additions to existing Fortran source, it is easy to add support for
the standard Apple, File and Edit menus, text editing of input and output streams, desk
accessory support, and a graphics window. Graphics can be written to the screen and
saved as Bitmaps or quickdraw pictures, allowing automatic handling of update events
in the graphics window. With slightly more effort, existing Fortran can have dialogue
boxes, alerts, and custom menus added. Conversion of existing programs to the event
orientation of the Mac world is simplified. McFace also takes care of a lot of memory
management automatically.
McFace is an external subroutine that, when called, is automatically linked in by
Fortran’s runtime linking system. Thus, McFace need not be explicitly linked to a
Fortran program that is under development, but can be “hard” linked after the final
compilation. The use of runtime linking allows multiple applications to share one copy
of McFace. McFace also has the Fortran Toolbx subroutine linked to it and contains
resources. Because of this, the McFace subroutine must reside in the System folder of
an HFS system.
In order to show how McFace works, it is best to do an example. Starting with the
generic Fortran code for the famous Sieve of Eratosthenes benchmark, we will convert
it to a Mac interface using McFace. This is done in two stages in order to show the
hierarchy of McFace additions that can be made to generic Fortran code. Unfortunately,
even if you have Fortran, you aren’t going to be able to run any of this code unless you
also get McFace. Therefore, I intend to show the listings in order to illustrate how
simple the code is in structure, while still letting you have a Mac interface on your
Fortran programs. The three versions of the Sieve presented here are all functionally
the same; they differ only in the user interface. To illustrate how the user interface
changes as McFace additions are made, I have included copies of the output screens for
each version of the program.
How it Works
Before diving in an a specific example, it is worthwhile to say a few general
things about how McFace works. The main feature that makes the concept of McFace
possible is the ability of Fortran to do input and output to “internal” files. That is,
reads and writes can take place from a variable rather than from an i/o channel such
as unit 5. McFace is able to intercept Fortran i/o by reassigning i/o to a specified
internal file, in this case a character variable called MAC. McFace then acts as an
intermediary that sits between the generic Fortran code and the new user interface
possibilities of the Macintosh. McFace also adds a Common block to your applications so
that communication between McFace and your code can be maintained through a few
variables in Common.
A generic call to McFace has the form: Call McFace( 11 integer arguments).
The first argument controls whether any character I/O is done, and, if so, to what
window. The contents of the character variable “MAC” are used to shuttle character
information between your Fortran code and McFace. The next 10 arguments are
organized into 5 pairs. Each pair of numbers selects one of McFace’s high-level
functions, or macros, for execution. This structure can be terse and a little cryptic,
but it lets you pack a lot of power into a single call to McFace.