Using Fortran 77 and CTT's older FNL Numerical Library

Although using f90 with CTT is preferable, you can still use f77 with CTT's Fortran Numerical Library, FNL. This will be illustrated with the use of the mathematical gamma function evaluated at x=5.

The output from a sample terminal session is shown below, followed by a discussion of the steps. This example is run using the Sun Studio 9 compilers; the f77 source file is in gammaTest.f. The cttshell alias and environment variables used below are available if you have made the suggested UNIX configuration changes described Getting Started with CTT: Setting Up Your UNIX Account.

setenv commands in setup files
CTT_DIR /opt/vni/CTT6.1
LDLIBS "$LINK_FNL_SMP"
<100>% cttshell 
<1>% touch gammaTest.f 
<2>% make gammaTest 
f90 -openmp=noopt -ftrap=%none -xtarget=generic
-M/opt/vni/CTT6.1/include/solaris -o gammaTest gammaTest.f
-R/opt/vni/CTT6.1/lib/lib.solaris -L/opt/vni/CTT6.1/lib/lib.solaris
-Bdynamic -limsl -limslsmp -xlic_lib=sunperf -ldl -lnsl -lsocket
<3>% ./gammaTest 
GAMMA( 5.000) = 24.000 
<4>% exit 
<101>%
  • The cttshell command starts a new shell with the correct environment for all CTT products.
  • The sample Fortran 77 program that invokes the gamma function is stored in a file named gammaTest.f (whose listing is below).
  • Since the make command is to be used to compile and link the Fortran 77 program to the FNL routines, the link libraries environment variable LDLIBS must be set appropriately to $LINK_FNL.
  • The make gammaTest command finds the Fortran 77 source file and creates the executable "gammaTest". Since the source file has an ".f" extension, make uses a suffix rule to invoke an f90 compiler. (The specific compiler used is the one defined by the environment variable F90, which has been set to the Sun Stuidio 9 compiler. This compiler is able to compile programs written in Fortran 77.)
  • The Fortran 77 source program is touched so that its modification time is newer than the executable. That forces the make command to recompile gammaTest.f.
  • The executable is run and it reports the correct result.
  • Finally, exiting the shell returns us to the parent shell (command number <101>) with its previous environment variable and alias definitions.

Listing of the gammaTest.f sample program

C-----------------------------------------------------------------------
C IMSL Name: GAMMA/DGAMMA (Single/Double precision version) 
C 
C Purpose: Evaluate the complete gamma function. 
C 
C Usage: GAMMA(X) 
C 
C Example 1: 
C                              Declare variables 
      INTEGER NOUT 
      REAL GAMMA, VALUE, X 
      EXTERNAL GAMMA, UMACH 
C                              Compute 
      X = 5.0
      VALUE = GAMMA(X) 
C                              Print the results 
      CALL UMACH (2, NOUT) 
      WRITE (NOUT,99999) X, VALUE 
99999 FORMAT (' GAMMA(', F6.3, ') = ', F6.3) 
END