Batch Processing
Volume Number: 9
Issue Number: 5
Column Tag: Jörg's Folder
Batch Processing with Apple Events 
Solutions for a specific batch task
By Jörg Langowski, MacTech Magazine Regular Contributing Author
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
This column was initiated by a reader’s question:
“Dear Jörg,
I am looking for a way to simulate batch files on the mac. I need to run two
Fortran programs sequentially, then open Excel and run a macro on the results. What
should I use? Can it be done? If you can solve this I'll subscribe!”
Homer Bartlett, Microstar Inc.
Well, we always welcome new subscribers, and your question is actually of very
general interest; so this month I’ll write about ‘batch processing with Apple Events’.
This is actually a rather ambitious title for what we’ll be doing, sending a couple of
Apple Events to other programs to make them do their things; but didn’t the headline
catch your eye? So there.
I have found three principal ways to install a way of ‘batch processing’ like
Homer Bartlett asked for. a) you write a Fortran program that sends an ‘oapp’ Apple
Event to each of the two programs that you want to execute. These two programs leave
intermediate results in files. Then, the Fortran program opens Excel (again via an
Apple Event), and makes Excel execute a macro file. How this is done, you’ll see soon.
b) you write a Fortran program that calls the two other programs via Apple Events as
before, but the intermediate results are left in edition files that can be handled by
System 7’s Edition Manager. Excel 3.0 and higher supports Subscribe and Publish; if
an Excel worksheet is opened that subscribes to those edition files, the data will
automatically be updated when the edition is modified. And, last one and easiest one, c)
you control everything from Excel - the execution of the two Fortran programs and the
following running of the macro. I’ll give you examples for all three of these
procedures.
First of all, let’s write two little Fortran programs that calculate our ‘results’
and write them to files. They’re at the start of the example: one calculates a sine curve,
the other an exponential, and the Excel macro will later open the files and read them
into a worksheet where the results are multiplied and displayed in a graph.
Opening an application from Fortran
Language Systems Fortran provides a rather convenient interface to the four
basic required Apple Events. There is a routine F_SendEvent that takes 3 parameters:
first a character*4 constant which is the Apple event ID, then a string that specifies
the target application and finally an optional document name (also a string). Thus, to
open Microsoft Excel from a Fortran program, you might include the line
call F_SendEvent(‘oapp’,’Microsoft Excel’,’’)