[comp.sys.sun] FORTRAN inside C -- I/O init for UNIX

gplan@umb.umb.edu (George A. Planansky) (09/02/89)

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.  

1. where and how do f_init() and f_exit() really go?

2. how do I tell cc, or f77, where to find/ resolve these objects?

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).  

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

	program fmain
	call cmain
	end

	for:

	#include <stdio.h>
	cmain()
	{
	...
	fsub_()
	}

	with:
	subroutine fsub()
	...
	end

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

Please send your enlightening replies to me, and I will summarize if there
is interest.

email to : gplan@ra.umb.edu

George Planansky
Atmosphere Environment Research
Cambridge MA
(617) 547-6207

perl%step@uunet.uu.net (Robert Perlberg) (10/04/89)

In article <1330@brazos.Rice.edu>, gplan@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!"