FORTRAN inside C -- I/O init for UNIX

Robert Perlberg number1!perl%step at uunet.uu.net
Wed Oct 4 03:59:10 AEST 1989


In article <1330 at brazos.Rice.edu>, gplan at umb.umb.edu (George A. Planansky) writes:
> I want to put a C wrapper around Fortran utilities, to make command line
> parsing and so on easy.  The Sun FORTRAN programmer's guide, section 11.3
> (The C-FORTRAN Interface), page 186 (revision A 6 May 1988), says, with
> regard to execution that starts with the C main and so does not do the
> FORTRAN I/O library initializations for a FORTRAN subroutine that it
> calls:
> 
> 	The C program should initialize I/O by inserting the
> 	following line at the start of the program:
> 
> 		call f_init()
> 
> 	This establishes the preconnection of units 0, 5, 6.
> 
> This does not look like C code to me, or, to cc -- I nonetheless did put
> the line in some plausible places, but it didn't take.  

It looks like Sun got a little confused with their languages.  The line
should read:

	f_init();

> 3. in general, in Unix (Sun OS and 4.3BSD), how do you compile FORTRAN
> subroutines, to run under a C main(argc, argv) ?  The Sun manual says:
> 
> 	cc main.c fsub.f -lF77 -lI77 -lU77 -lc -lm
> 
> Are these libraries and that invocation standard in 4.3?  I would like to
> run the same stuff on our Suns (3/60's, 3/280, OS 4.01) and our Alliant
> fx40 (4.3 BSD essentially).  

As far as I know, yes.  I have used the same command on ONYX (System
III) and MASSCOMP (System III/4.2), although I sometimes had to
rearrange the order of the libraries, and I also had to repeat some of
the libraries (I remember the command on the MASSCOMP being something
like "-lfpp -lI77 -lU77 -lF77 -lU77 -lI77 -lfpp").

> Alliant's FORTRAN manual tells me that, to get the I/O stuff, I need to
> put a FORTRAN wrapper around my C-wrapper

> But this defeats my intention, of using C's command line arguments.  How
> else can I get the necessary I/O or init stuff?

I don't know whether the f_init(), f_exit() stuff is "standard", but I
have seen it on a number of systems.  Sun FORTRAN also has a couple of
functions for command line processing (I think they are called IARGC()
and GETARG()) which I have also seen on other systems.  I mention that
not to imply that it isn't easier to do it in C, but just so that you
are aware that command line processing is not impossible in FORTRAN
without C's help.

Robert Perlberg
Dean Witter Reynolds Inc., New York
phri!{dasys1 | philabs | mancol}!step!perl
	-- "I am not a language ... I am a free man!"



More information about the Comp.sys.sun mailing list