Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!cs.utexas.edu!uwm.edu!bionet!agate!violet.berkeley.edu!jerry From: jerry@violet.berkeley.edu (Jerry Berkman) Newsgroups: comp.lang.fortran Subject: Re: Replace Fortran libraries Message-ID: <1991Mar22.001551.28932@agate.berkeley.edu> Date: 22 Mar 91 00:15:51 GMT References: <3410001@hplred.HP.COM> Sender: usenet@agate.berkeley.edu (USENET Administrator) Organization: University of California, Berkeley Lines: 52 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