[comp.lang.fortran] Replace Fortran libraries

sivaram@hplred.HP.COM (S. Sivaramakrishnan) (03/15/91)

Assume you have a machine whose Fortran libraries have been "lost".  However,
this machine has a Fortran compiler, a C compiler and C libraries.  You
would like to run some fortran code which has a few common library
calls - read/write, open/close of files etc.  Can this be reasonably
accomplished? How?

Ideally, this would be an automated process where (say) a fortran write
is converted into one or more C printf statements with suitable format
conversions.

I have no problem with some changes to the fortran source, eg. defining a
"new_write" function that replaces all "write" calls to yield the desired
effect.

Sivaram

jerry@violet.berkeley.edu (Jerry Berkman) (03/22/91)

In article <3410001@hplred.HP.COM> sivaram@hplred.HP.COM (S. Sivaramakrishnan) writes:
>
>Assume you have a machine whose Fortran libraries have been "lost".  However,
>this machine has a Fortran compiler, a C compiler and C libraries.  You
>would like to run some fortran code which has a few common library
>calls - read/write, open/close of files etc.  Can this be reasonably
>accomplished? How?
>
>Ideally, this would be an automated process where (say) a fortran write
>is converted into one or more C printf statements with suitable format
>conversions.
>
>I have no problem with some changes to the fortran source, eg. defining a
>"new_write" function that replaces all "write" calls to yield the desired
>effect.
>
>Sivaram

A general automated solution is very difficult, and probably not worth doing.
Fortran formatted I/O includes a number of descriptors for which there
is no equivalent in C's printf, e.g. "p" for scale factor,
"bn","bz" for blank fill mode, "t", "tl", "tr" for tabbing,
"x" for skipping, ":" for stop if no more data, and "l" for logical.
In addition, "a" picks up the length from the variable declaration
so you have to parse the declarations to figure out if it's "a1",
"a2", etc.  Then Fortran has repeat counts and parentheses;
it would be a real pain to automatically translate things like the
following into calls on printf:

	write(12,8000) (ivec(i),xvec(i),i=1,n)
8000	format( 4(i5,f8.2), 2x, 4(i5,f8.2) )

Also Fortran knows and uses the dimension of it's arguments while
printf does not, e.g.:

	integer ivec(6), jvec(3)
	complex cvec(5)
	real xvec(5)

	write(12,8010) ivec, cvec, jvec, xvec
8010	format( 6i5, 10f8.2, 3i6 / 5f8.2 )

Then there is the rule that the format is repeated
as needed from the rightmost zero level left parentheses.
These are just the problems I can think of for formatted writes;
and I'm sure I left some out.  

So you will have to use a fairly restricted subset of Fortran write
statements if you want to do anything automatically.

	- Jerry Berkman, U.C. Berkeley, jerry@violet.berkeley.edu
	  (415)642-4804

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (03/22/91)

In article <1991Mar22.001551.28932@agate.berkeley.edu>, jerry@violet.berkeley.edu (Jerry Berkman) writes:
> In article <3410001@hplred.HP.COM> sivaram@hplred.HP.COM (S. Sivaramakrishnan) writes:
> >Assume you have a machine whose Fortran libraries have been "lost".  However,
> >this machine has a Fortran compiler, a C compiler and C libraries.  You
> >would like to run some fortran code which has a few common library
> >calls - read/write, open/close of files etc.  Can this be reasonably
> >accomplished? How?

There is a simple solution:  pick up a copy of "f2c" and convert the
Fortran code to C.  The f2c sources include the Fortran library,
including formatted transput.
-- 
Seen from an MVS perspective, UNIX and MS-DOS are hard to tell apart.