fortran to C converter?

Frank Davis 912/386-3889 FMD%TIFTON.BITNET at uga.cc.uga.edu
Fri Aug 12 11:29:09 EDT 1994


Hello Mike,

>Hello - Can anyone point me to a fortran to C converter, preferably
>public domain?

I use the f2c translator that comes with Linux.  Thought I would give
a little more info on how I use f2c.

Being that I am so efficient at making mistakes, I have found a few
techniques that help find some of my defects.

Actually, the f2c translator from AT&T can help locate mistakes in
multi-module FORTRAN programs, e.g. rim.   I'm not sure if anyone is
maintaining rim and I hate to list errors in public, but the rim DBMS
FORTRAN source has a classic example of argument mismatch between modules.

I guess in the good ol' days, projects were broken up to help reduce
compile times.  Today, even with your average PC, those big projects
don't seem to take as much computer time to compile/run.

Not only is the f2c a good translator, but it's also a good "software
engineering" tool.  For multi-module FORTRAN programs, just copy all
the modules into one big C program and let the C preprocessor do a
syntax check.  Here's an example with rim, as supplied in the GRASS 4.1.3
src.related subdirectory:


 ------------------  rim makefile ---------------------

# create a RIMFORS environment variable that lists all the needed modules
#  in rim.

RIMFORS = \
adddat.f amsg.f   ascan.f  ascchr.f ascdat.f asctxt.f atoi.f   ator.f   \
attadd.f attdel.f attget.f attnew.f attpag.f attput.f blkchg.f blkcln.f \
etc...


# now, just add a few rules to create a big FORTRAN program.
#  the f2c translator will call the C compiler to catch arg mismatches.


xxxrim.f:       $(RIMFORS) rim.f
                cat rim.f $(RIMFORS) > xxxrim.f

xxxrim.o:       xxxrim.f
                $(F77) $(FFLAGS) -Nx400 -Nn802 xxxrim.f

rim:            xxxrim.o $(EXTRA)
                $(F77) -o rim xxxrim.o $(EXTRA) $(F2C_LIBS)

 ---------------------------------------------------------


Here's a problem:

 =====================  pject.f  =================

      SUBROUTINE PJECT(*)
      INCLUDE 'syspar.d'
C
C     PERFORM PHYSICAL PROJECTIONS ON EXISTING RELATIONS.
C
C     PROJECT RNAME2 FROM RNAME1 USING ATTR1 ATTR2...ATTRN
C       ... WHERE CONDITION
C
C
C
...
...
      IF(.NOT.TOKTYP(2,KXNAME)) THEN           <=== line number 60
        CALL WARN(7,ASCTXT(IDP(2)),0)          <=== too few args for asctxt
        GO TO 999
      ENDIF
...
 ============================================


Oops, asctxt( ) needs 3 args.  Wonder what asctxt( ) does with junk args
from the stack?

 ===================  asctxt.f   ================

      SUBROUTINE ASCTXT(ATXT,LTXT,CSTR)
      INCLUDE 'syspar.d'
C
C     RETURN THE ASCII-TEXT EQUIVALENT OF CSTR
C
C        ATXT -- PLACE TO PUT ASCII-TEXT
C        LXTX -- LENGTH OF ATXT
C        CSTR -- CHARACTER STRING
C
...
 =========================================

Best Regards,
Frank Davis
fmd at tifton.cpes



More information about the grass-user mailing list