Using Fortran 77 and NAG's Fortran Library
The document NAG Fortran Library contains an overview of NAG and information on its use that should be read prior to reading this document. The discussion below assumes that you have configured your UNIX account as described in that document.
In this example, we have a simple Fortran 77 program in the file gammaTest.f. You can see the listing of this file below. It is a modified version of the example program from NAG that tests the gamma function s14aaf. With this file in the current directory this example consists of the following steps.nagshell Starts a shell setup for NAG.
make gammaTest Compiles the gammaTest.f file and makes an executable file called gammaTest. gammaTest Runs the Gamma Function test. exit Exits the NAG shell and returns to the starting environment.
The output from a sample terminal session is shown below, followed by a discussion of the steps.
The nagshell alias and environmental variables used below will be available only if you made the UNIX configuration changes suggested Getting Started with NAG: Setting Up Your UNIX Account.
<100>% nagshell <1>% make gammaTest f77 -dalign -xtarget=ultra -mt -o gammaTest gammaTest.f \ -L/opt/nag/aslir6/flso619da -lnag-spl -xlic_lib=sunperf -lsocket -lnsl -lintl gammaTest.f: MAIN: <2>% ./gammaTest 5.000D+00 2.400D+01 0 <3>% exit exit <101>%
- The nagshell command starts a new shell with the correct environment for the NAG Fortran Library.
- The sample Fortran 77 program which invokes the gamma function is in the file named gammaTest.
- 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 the f77 compiler in your path.
- The command ./gammaTest runs the executable, and it reports the correct result.
- Finally, exit returns to the parent shell (command number <101>) with the environment restored.
The gammaTest.f sample program
* S14AAF Example Program Text * Mark 14 Revised. NAG Copyright 1989. * .. Parameters .. INTEGER NIN, NOUT PARAMETER (NIN=5,NOUT=6) * .. Local Scalars .. DOUBLE PRECISION X, Y INTEGER IFAIL * .. External Functions .. DOUBLE PRECISION S14AAF EXTERNAL S14AAF * .. Executable Statements .. X = 5.0 IFAIL = 1 * Y = S14AAF(X,IFAIL) * WRITE (NOUT,99999) X, Y, IFAIL STOP * 99999 FORMAT (1X,1P,2D12.3,I7) END