I don’t know why I even started down this path, but anyways I felt the urge today to break out some Fortran. The problem is that I acquired Microsoft Fortran 5.0 in university, however… it’s on 5 1/4†diskettes!!!
So that wasn’t going to happen.
So I figured there had to be some kind of GNU Fortran compiler, and there is.. G77. However it needs to be tied into a release of GCC. Which sounds great, but I was hoping to build this on a few different platforms, and on my AMD 64 platform it’s GCC 3.3 (SUA), and on my NeXT it’s 2.5.8.. Even in the notes it says you’ll need about 100MB of space to build it, which is also a nice way of saying it’ll take FOREVER.
Then I remembered something we used on the RS/6000 because it was more ‘combatable’ then the Microsoft stuff, as it was derived from the first Unix Fortran compilers… f2c.
First you’ll need the source, which thankfully is still up on the original site This part is a bit tedious as the source is not in a single easy to get file. You’ll need to get the source from here. Once you’ve downloaded the files, I’d recommend saving them somewhere else.. You don’t want to have to right click like wild to get them… Alternatively I’ll host them all here to save someone all that effort.
Building f2c is really quite simple on any UNIX’like platform. First you’ll need the f2c source, and unpack it somewhere…. Then you *MAY* have to adjust the makefile.u for the CC/CFLAGS variables as your C compiler may not be gcc or cc, also you may or may not want the –O flags (optimize). On my NeXT I turned off the optimizations, since this is a 33Mhz machine, and I don’t want to wait all day, and I ran it with –O0 -pipe. Then just simply run
make –f makefile.u f2c
bash-2.01$ make -f makefile.u f2c
cc -c -O0 -pipe main.c
cc -c -O0 -pipe init.c
cc -c -O0 -pipe gram.c
cc -c -O0 -pipe lex.c
cc -c -O0 -pipe proc.c
cc -c -O0 -pipe equiv.c
cc -c -O0 -pipe data.c
cc -c -O0 -pipe format.c
cc -c -O0 -pipe expr.c
cc -c -O0 -pipe exec.c
cc -c -O0 -pipe intr.c
cc -c -O0 -pipe io.c
cc -c -O0 -pipe misc.c
cc -c -O0 -pipe error.c
cc -c -O0 -pipe mem.c
cc -c -O0 -pipe names.c
cc -c -O0 -pipe output.c
cc -c -O0 -pipe p1output.c
cc -c -O0 -pipe pread.c
cc -c -O0 -pipe put.c
cc -c -O0 -pipe putpcc.c
cc -c -O0 -pipe vax.c
cc -c -O0 -pipe formatdata.c
cc -c -O0 -pipe parse_args.c
cc -c -O0 -pipe niceprintf.c
cc -c -O0 -pipe cds.c
if cc sysdeptest.c; then echo ‘/*OK*/’ > sysdep.hd; elif cc -DNO_MKDTEMP sysdept
est.c; then echo ‘#define NO_MKDTEMP’ >sysdep.hd; else echo ‘#define NO_MKDTEMP’
>sysdep.hd; echo ‘#define NO_MKSTEMP’ >>sysdep.hd; fi
ld: Undefined symbols:
_mkdtemp
rm -f a.out
cc -c -O0 -pipe sysdep.c
cc -c -O0 -pipe version.c
cc main.o init.o gram.o lex.o proc.o equiv.o data.o format.o expr.o exec.o int
r.o io.o misc.o error.o mem.o names.o output.o p1output.o pread.o put.o putpcc.
o vax.o formatdata.o parse_args.o niceprintf.o cds.o sysdep.o version.o -o f2c
All being well, you’ll have a new & exciting f2c executable. I manually just copy the f2c into /usr/local/bin & the f2c.h to /usr/local/include.
Next you’ll need the f2c io library. Thankfully this one IS zipped up and it’s available here. Alternatively I’ve got a copy here (better). *NOTE that the ‘official’ version of the lib doesn’t extract to a sub directory… Grr Extract the library source, and again you may need to modify the makefile to suit your compiler (CC/CFLAGS). Then go ahead and make the library.
make –f makefile.u
cc -c -DSkip_f2c_Undefs -O0 -pipe etime_.c
ld -r -x -o etime_.xxx etime_.o
mv etime_.xxx etime_.o
ar r libf2c.a f77vers.o i77vers.o main.o s_rnge.o abort_.o exit_.o getarg_.o iar
gc_.o getenv_.o signal_.o s_stop.o s_paus.o system_.o cabs.o ctype.o derf_.o der
fc_.o erf_.o erfc_.o sig_die.o uninit.o pow_ci.o pow_dd.o pow_di.o pow_hh.o pow_
ii.o pow_ri.o pow_zi.o pow_zz.o c_abs.o c_cos.o c_div.o c_exp.o c_log.o c_sin.o
c_sqrt.o z_abs.o z_cos.o z_div.o z_exp.o z_log.o z_sin.o z_sqrt.o r_abs.o r_acos
.o r_asin.o r_atan.o r_atn2.o r_cnjg.o r_cos.o r_cosh.o r_dim.o r_exp.o r_imag.o
r_int.o r_lg10.o r_log.o r_mod.o r_nint.o r_sign.o r_sin.o r_sinh.o r_sqrt.o r_
tan.o r_tanh.o d_abs.o d_acos.o d_asin.o d_atan.o d_atn2.o d_cnjg.o d_cos.o d_co
sh.o d_dim.o d_exp.o d_imag.o d_int.o d_lg10.o d_log.o d_mod.o d_nint.o d_prod.o
d_sign.o d_sin.o d_sinh.o d_sqrt.o d_tan.o d_tanh.o i_abs.o i_dim.o i_dnnt.o i_
indx.o i_len.o i_mod.o i_nint.o i_sign.o lbitbits.o lbitshft.o h_abs.o h_dim.o h
_dnnt.o h_indx.o h_len.o h_mod.o h_nint.o h_sign.o l_ge.o l_gt.o l_le.o l_lt.o h
l_ge.o hl_gt.o hl_le.o hl_lt.o ef1asc_.o ef1cmc_.o f77_aloc.o s_cat.o s_cmp.o s_
copy.o backspac.o close.o dfe.o dolio.o due.o endfile.o err.o fmt.o fmtlib.o fte
ll_.o iio.o ilnw.o inquire.o lread.o lwrite.o open.o rdfmt.o rewind.o rsfe.o rsl
i.o rsne.o sfe.o sue.o typesize.o uio.o util.o wref.o wrtfmt.o wsfe.o wsle.o wsn
e.o xwsne.o dtime_.o etime_.o
ar: creating libf2c.a
ranlib libf2c.a
This will take longer then f2c.. Or at least it did on my NeXT.
Then I just copied the library libf2c.a into /usr/local/lib then ran ranlib over the library again.
Ok now we should be able to build a FORTRAN program. Let’s try something small.
program hello
print *, ‘Hello!’
end
I’ve tried to preserve the leading 6 blank spaces. You should be able to copy the above program, and save it as hello.f Now we should be able to translate, compile and run the program!
bash-2.01$ f2c hello.f
hello.f:
MAIN hello:
bash-2.01$ cc hello.c -lf2c -o hello
bash-2.01$ file hello
hello: Mach-O executable (for architecture m68k) not stripped
bash-2.01$ ./hello
Hello!
Awesome! Now let’s try something much bigger, say some old Fortran source to the old ‘dungeon’ game, better known as Zork! This source is available all over the place as dungeon-2.5.6.tar.gz, and I’ll provide a link as well here.
Download, and extract the files (gzip –dc dungeon-2.5.6.tar.gz|tar –xvf –) and you’ll have your dungeon directory. Building this should be pretty simple, if the above program built and ran without errors. On my SUA (Vista) machine, I had to force the –I/usr/local/include flags to find the f2c.h.. So you may need some tweaking it all depends.
Again on my NeXT I changed the CFLAGS to –O0 –pipe. On my Vista SUA I had to specify that CC=gcc.
Once done, go ahead and run make.
\ar d libdungeon.a dmain.o np2.o
\ranlib libdungeon.a
cc -s -o dungeon dmain.o np2.o -L. -ldungeon -lf2c -lm
f2c -A -C -Nn802 textcnv.f
textcnv.f:
MAIN:
cc -O0 -pipe -c textcnv.c
cc -o textcnv textcnv.o –lf2c
If all went well that should be how the last lines look. We should now have a dungeon executable!
bash-2.01$ file dungeon
dungeon: Mach-O executable (for architecture m68k)
Awesome!
So let’s enter the game, shall we?
bash-2.01$ ./dungeon
Welcome to Dungeon. This version created 30-AUG-90.
You are in an open field west of a big white house with a boarded
front door.
There is a small mailbox here.
>
So, now we have built the f2c translation package, and managed to build a trivial hello world program, and something a little more complex like Dungeon/Zork.
Now I can play with my numerical recipes book with my pseudo Fortran kit.