Using Fortran or C code in Rev

Richard K. Herz herz at ucsd.edu
Wed Nov 6 13:35:01 EST 2002


Bill Vlahos <bvlahos at mac.com> wrote:

> A co-worker asked me how to use existing fortran or C code within a
> Revolution application (or called by a Revolution application)?

There are two options I'm aware of: (1) communicate between Rev and compiled
program via disk files (acceptable if the compiled program takes at least a
second or two to run), (2) build an external (if running on locked volumes
or if compiled program executes very fast).

Option (1) I'm doing this with MC and a Fortran program on Windows.  The MC
GUI writes inputs to a disk file, tells the system shell to run the Fortran
exe, then reads in the output files and displays results.  To get the
Windows OS shell command, "get the shellCommand" in Rev.

For "command.com" on, e.g., Win 98, use start command's /m option to
minimize the shell console window, plus set hideConsoleWindows to true in
Rev. For list of start options, enter "start" in command.com console window.

For "cmd.exe" on, e.g., Win XP, use start command's /min or /b option to
hide the shell console window, plus set hideConsoleWindows to true in Rev.
for list of start options, enter "help start" in cmd.exe console window.
(command.com also available but different behavior than on Win 98)

Combine two or more shell commands in one Rev get shell() by using the "&"
character, as you have to do with a path with spaces in the name.  For
example, for the shellCommand "cmd.exe", in order to execute "C:\Path with
spaces in name\myprog.exe", since"cd" is immune to spaces in path but
"start" isn't, use

get shell("cd C:\Path with spaces in name & start /min /high /wait
myprog.exe")

Command.com on Win 98 returns executable output to the console (e.g., print
* from Fortran and STOP) to the Rev "it" variable on completion so that you
can check for a good run.  Cmd.exe on Win XP doesn't seem to return anything
to Rev, so I delete old output files before a run and then check for new
good output files after the run.

AppleScript should do the job on Macs.

Option (2):  I've only found the "glue" files needed to build XCMDs and
XFCNs written in C, C++ and Pascal.  To make a Fortran program into an XCMD,
the thing to do would be to write a C program that calls the Fortran
executable and then build that package into an XCMD using the C glue files.
I you translate the glue files into Fortran, please let us know!

Rich Herz
herz at ucsd.edu







More information about the use-livecode mailing list