TweetFollow Us on Twitter

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.

For example, the McFace call:

Call McFace(0, 4, 2, 3, 2, 2, -6, 0, 0, 0, 0)

will (1) Specify no I/O because of the initial 0, (2) the 4,2 specifies bringing a text edit window to the front, (3) the 3,2 moves the text insertion bar to the end of the text in the window, (4) finally the 2,-6 causes a return to the user’s code without updating the contents of MAC. The trailing zeroes are present since McFace can have up to 5 macro calls at one time. McFace must be called, like all Fortran subroutines, with a fixed number of arguments, so the last 2 unused macro slots must be zero-filled.

Without repeating the McFace documentation this gives some of the flavor of how McFace is used. The calls to McFace look more obscure than they really are, since about 6-8 different combinations of macros suffice to start out converting generic Fortan to a Mac interface.

Converting the Sieve

Listing 1 shows the “generic” Sieve of Eratosthenes, as supplied with the compiler by Absoft. Running this program brings up the “glass teletype” window that is defined by the Fortran runtime library. The user interface is nonexistent; what the user sees is unchanged from that of a conventional computer. The totally un-Mac-like output is shown in Screen 1.

Listing 2 shows the same code with the modifications needed to attach McFace to the existing code. The modifications are minimal: (1) There is some initialization code (2) I/O is trapped and routed through McFace by using a Fortran “internal file”, as described above. Characters are written to variable MAC rather than to an assigned I/O channel. Support for the standard Apple, File and Edit menus is automatically handled by McFace. The part of the code that is used to add McFace is in boldface, while the old “generic” Sieve code is in plain text. Screen 2 shows the user interface presented by the code of listing 2. For a very small amount of work, the user has essentially the full Mac interface! Much larger Fortan code can be adapted along the general lines shown here. The only disadvantage to this approach, as can be seen from the listing, is that McFace related code gets sprinkled throughout the old ANSI Fortran code.

Listing 3 shows a more complete adaptation of the Sieve for use with McFace. Here, McFace calls are not distributed throughout the existing Fortran code. Instead, the Sieve program has been converted to a subroutine that does no I/O. Communication with the main routine (a McFace shell) is done by passing an argument. This is a clean general solution to porting existing Fortran code to the Mac. The routines that do the real work are kept to simple ANSI Fortran, while McFace serves as the interface between the Fortran code and the Macintosh environment. Again, McFace related code is in boldface. Screen 3 shows the output of this code, which is almost identical to that of listing 2, except for the addition of an “About Sieve” alert. The advantage of using a McFace shell with standard Fortran subroutines for each menu entry is that every application has essentially the same structure, except for the application specific menu entries and resources. Writing new applications becomes quite trivial, since the standard shell is providing all the Mac-specific support features.

Notice that the use of a McFace shell allows the Sieve to be converted to a Menu driven system which incorporates the event orientation that all Mac programs should have. Events are actually trapped by McFace, which in turn reports Menu events back to the Fortran program so that the appropriate part of the user’s code is run. McFace takes care of handling Activate, Update, Scrolling, Auto-scrolling, Text Edit and SystemClick events, so that the work that is done by the application Fortran code is greatly reduced.

The menus, windows and alerts in McFace are all resources. Therefore, further customization of the McFace environment can be achieved by using ResEdit on McFace’s resources. This is nice for adjusting size, position and title of the McFace windows. One can also include new resources to be used for your own alerts, as shown in Listing 3 and Screen 3.


Like any other programming tool, McFace has both strengths and weaknesses. Here are some of each:

The ease of use of McFace is easily its biggest strength. To make the minimal modifications to the Sieve, which was the first thing I did with McFace, took about 20 minutes from the time that I first opened the documentation.

McFace provides enough built in functionality that writing new applications with McFace really takes less work than using the glass teletype environment supplied with Fortran. Once one application has been written with McFace, the subsequent ones are very easy.

At 134K, McFace is not small. McFace provides a tremendous gain in functionality over plain MacFortran, but it costs a lot of memory. This is a trade-off that was made deliberately, since the use of a single subroutine is what makes using McFace so simple. Under switcher or with a ram cache or ram disc you need to leave at least 256K of memory for any application that uses McFace. Big programs will require more. The space that McFace takes up on disc can be reduced by allowing more than one program to use McFace via Fortran’s link-at-runtime capability.

The macro commands bundle a lot of functionality into a single subroutine call. So much, in fact, that it is sometimes unclear to a naive user what all the effects of the call will be. However, the macro calls are well thought out, so the best way to learn McFace is to just dive in and try running and modifying the sample programs that are included. When I did not understand all the effects of a call to McFace, I got unexpected behavior, but no crashes.

Text output is limited to <32K because of the use of Text Edit Records in the text output windows. Some operations, such as Text Output, are slower with McFace than with a straight Fortran program. Speed is still acceptable, however.

I think the “macro” commands in McFace should not accessed by number. Instead, I think there should be a parameter file which uses the Fortran PARAMETER statement to define symbolic equivalents to the macro numbers. This is exactly what is done in all the Fortran include files for Toolbox access. In early revisions of McFace there have already been inconsistent changes in the macro numbers between versions, which caused me to recode some of my programs. Use of a PARAMETER file would have made converting between revisions completely transparent. Use of parameters would also make McFace calls more self documenting. A PARAMETER file should at least be included as an option for the user.

Except for the size of McFace, and possibly, the use of parameters, these are only minor quibbles. The author, Dan Kampmeier is constantly improving McFace and adding features and functionality. He readily responds to input from users. Most of the deficencies of Fortran for Macintosh programming are eliminated by McFace. [Thank you Dan Kampmeier, for doing Microsoft’s job! Between McFace and the CLR Libraries, maybe Microsoft will learn how to they SHOULD have done their programming products! -Ed]


McFace is a single external subroutine that acts as a Fortran “extender”. With very little effort generic Fortran programs can be converted to run with a full Mac interface.

The outstanding feature of McFace is its simplicity of use. The major drawback is the 134K of size that it adds to an application. However, this subroutine handles almost all of the Toolbox programming that you will ever need to do from Fortran.

Conversion of existing Fortran code to a Mac interface can almost be reduced to a cookbook translation process, at least for a first iteration. Fine tuning and addition of features is simple and is added by McFace’s ability to work with user designed resources. In short, if you have been frustrated by the difficulty of writing true Mac applications in Fortran, then McFace will probably solve your problems.

McFace is available from Dan Kampmeier or Tensor labs. There is probably an advertisement for it in this issue of MacTutor.

Listing 1
*       Sieve of Eratosthenes
        logical*2 flags(8191)
        integer*2 i,j,k,count,iter,prime
        n = long(362)                   ! 60 Hz counter
        do 92 iter = 1,10
           do 10 i = 1,8191
10            flags(i) = .true.
           do 91 i = 1,8191
              if (.not. flags(i)) go to 91
              prime = i + i + 3
              count = count + 1
              k = i + prime
              if (k .gt. 8191) go to 91
              do 60 j = k, 8191, prime
60               flags(j) = .false.
91          continue
92      continue
        write (9,*) count,” primes in”,(long(362)-n)/60.0,” seconds”

Screen 1

Listing 2
*       Sieve of Eratosthenes
        logical*2 flags(8191)
        integer*2 i,j,k,count,iter,prime
c McFace Initialization Code
    include HFS VOLUME:FORTRAN 2.2:INCLUDE FILES:McVariables
    storage(232) = 10240!at least 10K of memory for stack expansion
    storage(240) = 3        !up to 5 text editors
    MAC = “About Sieve...”   !”About Program”
    call McFace(0,2,-6,0,0,0,0,0,0,0,0)     !initialize variables
c bring up editor #1, move insertion bar to end,return without reading:
        call McFace(0,4,2,3,2,2,-6,0,0,0,0)
c The code that does the work
        n = long(362)                   ! 60 Hz counter
        do 92 iter = 1,10
           do 10 i = 1,8191
10            flags(i) = .true.
           do 91 i = 1,8191
              if (.not. flags(i)) go to 91
              prime = i + i + 3
              count = count + 1
              k = i + prime
              if (k .gt. 8191) go to 91
              do 60 j = k, 8191, prime
60               flags(j) = .false.
91          continue
92      continue
        write (MAC,198) count,(long(362)-n)/60.0
198     FORMAT(I6, ‘ primes in ‘, f4.2, ‘ seconds’)
        call McFace(-1,2,-6,0,0,0,0,0,0,0,0)
c Include McFace Variables
        include HFS VOLUME:FORTRAN 2.2:INCLUDE FILES:McMemory

Screen 2

Listing 3
*   McFace Shell to run
*   Sieve of Eratosthenes example
       integer*2 nprimes
c  McFace Initialization Code
 storage(232) = 20240 !at least 20K of memory for stack              
 storage(240) = 3  !up to 2 text editors
   MAC = “About Sieve...”  !”About Program” 
   call McFace(0,2,-6,0,0,0,0,0,0,0,0) !initialize variables
c  Add a custom menu for the Sieve
   file = ‘Sieve’
   MAC = ‘Do Sieve;Write Test’
   call McFace(0,-1,0,2,-6,0,0,0,0,0,0)
c  bring up editor #1, move insertion bar to end,
c  and return without reading:
   call McFace(0,4,2,3,2,2,-6,0,0,0,0)
c  Loop that just waits for menu command
 call McFace(0,0,0,0,0,0,0,0,0,0,0)
   select case (MAC)
 case(‘About’)    !open “About “ alert call McFace(0,10,4,0,0,0,0,0,0,0,0)
       case(‘Do Sieve’)
     n1 = long(362)  ! 60 Hz counter. Start
        call Sieve(nprimes)
     n2 = long(362)   ! 60 Hz counter. Stop
     deltat = (n2-n1)/60.0
        write (MAC,198) nprimes, deltat
198 FORMAT(I6, ‘ primes in ‘, f4.2, ‘ seconds’)
        call McFace(-1,4,2,2,-6,0,0,0,0,0,0)
 case default

    end select
c       Sieve of Eratosthenes subroutine
c       Just generic Fortran code, converted to a subroutine

        subroutine Sieve(count)
        logical*2 flags(8191)
        integer*2 i,j,k,count,iter,prime
        n = long(362)                   ! 60 Hz counter
        do 92 iter = 1,10
           do 10 i = 1,8191
10            flags(i) = .true.
           do 91 i = 1,8191
              if (.not. flags(i)) go to 91
              prime = i + i + 3
              count = count + 1
              k = i + prime
              if (k .gt. 8191) go to 91
              do 60 j = k, 8191, prime
60               flags(j) = .false.
91          continue
92      continue
 dt = (long(362)-n)/60.0
Apple Inc.
Microsoft Corpora
Google Inc.

MacTech Search:
Community Search:

Software Updates via MacUpdate

Ember 1.8.2 - Versatile digital scrapboo...
Ember (formerly LittleSnapper) is your digital scrapbook of things that inspire you: websites, photos, apps or other things. Just drag in images that you want to keep, organize them into relevant... Read more
Tonality Pro 1.1.2 - Professional-grade...
Tonality Pro gives you the power to create stunning and dramatic black & white images. This is a complete monochrome image editor with more than 150 one-click style presets, totally unique... Read more
VueScan 9.4.49 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
OS X Server 4.0 - For OS X 10.10 Yosemit...
Designed for OS X and iOS devices, OS X Server makes it easy to share files, schedule meetings, synchronize contacts, develop software, host your own website, publish wikis, configure Mac, iPhone,... Read more
TotalFinder 1.6.12 - Adds tabs, hotkeys,...
TotalFinder is a universally acclaimed navigational companion for your Mac. Enhance your Mac's Finder with features so smart and convenient, you won't believe you ever lived without them. Tab-based... Read more
BusyCal 2.6.3 - Powerful calendar app wi...
BusyCal is an award-winning desktop calendar that combines personal productivity features for individuals with powerful calendar sharing capabilities for families and workgroups. BusyCal's unique... Read more
calibre 2.7 - Complete e-library managem...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital... Read more
Skitch 2.7.3 - Take screenshots, annotat...
With Skitch, taking, annotating, and sharing screenshots or images is as fun as it is simple.Communicate and collaborate with images using Skitch and its intuitive, engaging drawing and annotating... Read more
Delicious Library 3.3.2 - Import, browse...
Delicious Library allows you to import, browse, and share all your books, movies, music, and video games with Delicious Library. Run your very own library from your home or office using our... Read more
Art Text 2.4.8 - Create high quality hea...
Art Text is an OS X application for creating high quality textual graphics, headings, logos, icons, Web site elements, and buttons. Thanks to multi-layer support, creating complex graphics is no... Read more

Latest Forum Discussions

See All

Rami Ismail Opens Up distribute​() for D...
Rami Ismail Opens Up distribute​() for Developers Posted by Jessica Fisher on October 24th, 2014 [ permalink ] Rami Ismail, Chief Executive of Business and Development at indie game studio | Read more »
Great Hitman GO Goes on Sale and Gets Ne...
Great Hitman GO Goes on Sale and Gets New Update – Say That Three Times Fast Posted by Jessica Fisher on October 24th, 2014 [ permalink ] | Read more »
Rival Stars Basketball Review
Rival Stars Basketball Review By Jennifer Allen on October 24th, 2014 Our Rating: :: RESTRICTIVE BUT FUNUniversal App - Designed for iPhone and iPad Rival Stars Basketball is a fun mixture of basketball and card collecting but its... | Read more »
Rubicon Development Makes Over a Dozen o...
Rubicon Development Makes Over a Dozen of Their Games Free For This Weekend Only Posted by Jessica Fisher on October 24th, 2014 [ permalink ] | Read more »
I Am Dolphin Review
I Am Dolphin Review By Jennifer Allen on October 24th, 2014 Our Rating: :: NEARLY FIN-TASTICUniversal App - Designed for iPhone and iPad Swim around and eat nearly everything that moves in I Am Dolphin, a fun Ecco-ish kind of game... | Read more »
nPlayer looks to be the ultimate choice...
Developed by Newin Inc, nPlayer may seem like your standard video player – but is aiming to be the best in its field by providing high quality video play performance and support for a huge number of video formats and codecs. User reviews include... | Read more »
Fighting Fantasy: Caverns of the Snow Wi...
Fighting Fantasy: Caverns of the Snow Witch Review By Jennifer Allen on October 24th, 2014 Our Rating: :: CLASSY STORYTELLINGUniversal App - Designed for iPhone and iPad Fighting Fantasy: Caverns of the Snow Witch is a sterling... | Read more »
A Few Days Left (Games)
A Few Days Left 1.01 Device: iOS Universal Category: Games Price: $3.99, Version: 1.01 (iTunes) Description: Screenshots are in compliance to App Store's 4+ age rating! Please see App Preview for real game play! **Important: Make... | Read more »
Toca Boo (Education)
Toca Boo 1.0.2 Device: iOS Universal Category: Education Price: $2.99, Version: 1.0.2 (iTunes) Description: BOO! Did I scare you!? My name is Bonnie and my family loves to spook! Do you want to scare them back? Follow me and I'll... | Read more »
Intuon (Games)
Intuon 1.1 Device: iOS Universal Category: Games Price: $.99, Version: 1.1 (iTunes) Description: Join the battle with your intuition in a new hardcore game Intuon! How well do you trust your intuition? Can you find a needle in a... | Read more »

Price Scanner via

Weekend sale: 13-inch 128GB MacBook Air for $...
Best Buy has the 2014 13-inch 1.4GHz 128GB MacBook Air on sale for $849.99, or $150 off MSRP, on their online store. Choose free home shipping or free local store pickup (if available). Price valid... Read more
Nimbus Note Cross=Platform Notes Utility
Nimbus Note will make sure you never forget or lose your valuable data again. Create and edit notes, save web pages, screenshots and any other type of data – and share it all with your friends and... Read more
NewerTech’s Snuglet Makes MagSafe 2 Power Con...
NewerTech has introduced the Snuglet, a precision-manufactured ring designed to sit inside your MagSafe 2 connector port, providing a more snug fit to prevent your power cable from unintentional... Read more
Apple Planning To Sacrifice Gross Margins To...
Digitimes Research’s Jim Hsiao says its analysts believe Apple is planning to sacrifice its gross margins to save its tablet business, which has recently fallen into decline. They project that Apple’... Read more
Who’s On Now? – First Instant-Connect Search...
It’s nighttime and your car has broken down on the side of the highway. You need a tow truck right away, so you open an app on your iPhone, search for the closest tow truck and send an instant... Read more
13-inch 2.5GHz MacBook Pro on sale for $949,...
Best Buy has the 13″ 2.5GHz MacBook Pro available for $949.99 on their online store. Choose free shipping or free instant local store pickup (if available). Their price is $150 off MSRP. Price is... Read more
Save up to $125 on Retina MacBook Pros
B&H Photo has the new 2014 13″ and 15″ Retina MacBook Pros on sale for up to $125 off MSRP. Shipping is free, and B&H charges NY sales tax only. They’ll also include free copies of Parallels... Read more
Apple refurbished Time Capsules available sta...
The Apple Store has certified refurbished Time Capsules available for up to $60 off MSRP. Apple’s one-year warranty is included with each Time Capsule, and shipping is free: - 2TB Time Capsule: $255... Read more
Textilus New Word, Notes and PDF Processor fo...
Textilus is new word-crunching, notes, and PDF processor designed exclusively for the iPad. I haven’t had time to thoroughly check it out yet, but it looks great and early reviews are positive.... Read more
WD My Passport Pro Bus-Powered Thunderbolt RA...
WD’s My Passport Pro RAID solution is powered by an integrated Thunderbolt cable for true portability and speeds as high as 233 MB/s. HighlightsOverviewSpecifications Transfer, Back Up And Edit In... Read more

Jobs Board

*Apple* Solutions Consultant - Apple Inc. (U...
…important role that the ASC serves is that of providing an excellent Apple Customer Experience. Responsibilities include: * Promoting Apple products and solutions Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.