Getting Started with NAG: Setting Up Your UNIX Account

The document NAG Fortran Library contains an overview of NAG and information on its use that should be read prior to reading this document.

Mark 19 of the NAG Fortran Library from Nag Ltd. is installed in the directory /opt/nag/aslir6/flso619da. This installation directory will be referred to as $NAG_DIR throughout this document. Note that NAG and its compilers are only available on Strauss and not on Copland. The configuration changes to your UNIX account suggested in this document will only affect your computing environment when you are on Strauss.

This documentation assumes that your UNIX account's configuration ("dot") files are based on Client Support & Services' recommended configuration files: .cshrc, .login, .localalias, and .localenv. These files are found in the /opt/proto directory. Typing the UNIX command:


will cause your current configuration files to be renamed (for backup purposes) and replaced with the standard configuration files. The system will display the names of the renamed and replacement files.

Configuration changes to identify the NAG library location

Add the following lines to your ~/.localenv file:

# NAG Fortran Library
setenv NAG_DIR /opt/nag/aslir6/flso619da

These commands cause the NAG_DIR environment variable to be set properly each time you start a session on Strauss. When a new version of NAG is installed, you will need to update these lines.

Configuration changes to define the UNIX environment for the NAG library

Creating some aliases (user-defined commands) in your ~/.localalias file will reduce future typing needed to use NAG and to find the example programs. Add the following lines to create a new alias that starts a shell having all relevant environment variables set.

alias nagshell "(setenv NEED_NAG; newgrp \!*)" 
if $?NEED_NAG then 
  setenv FC f77 
  setenv FFLAGS "-dalign -xtarget=ultra -mt" 
  setenv LDLIBS "-L$NAG_DIR -lnag-spl -xlic_lib=sunperf -lsocket -lnsl -lintl"
  alias exampleList "ls -x $NAG_DIR/examples/source" 
  alias exampleGet 'set nagex=`basename \!*`;\ 
     cp $NAG_DIR/examples/*/${nagex}.* .;ls ${nagex}.*' 
  alias exampleRun "touch ${nagex}.d;cat ${nagex}.d* | ./${nagex}"
  alias exampleCmp 'cmp - ${nagex}.r && echo "Program Results Match"'
  alias exampleClean '\rm ${nagex}*' 

The next time you log on to Strauss, you will be able to start a NAG-configured shell with the command


To associate the new shell with a different group project id (e.g., a UNIX group assigned to a class), type the following command instead:

  nagshell project

where project is your 4-digit group project number.


The comands in your ~/.localalias file between the if and the endif will only be executed when NEED_NAG is set.  These will set three environmental variables and five aliases just for the NAG-configured shell.

FC Environmental variable containing the Fortran compiler needed for the NAG library.
FFLAGS Environmental variable containing the required Fortran compiler flags.
LDLIBS Environmental variable containing the required loader flags needed at the end of your compile command.
exampleList Alias to list all the available example programs.
exampleGet Alias to make a copy of an example program.
exampleRun Alias to run an example program, after you "make" the executable.
exampleCmp Alias to compare the output with the supplied example output.
exampleClean Alias to remove all files associated with a NAG example.

These three environment variables are the ones used by the make command to "make" an executable. Name your Fortran program with the suffix .f and type make basename using the base name (your file name without the suffix).

Example Session

The following example does 8 tasks using these shell commands:

    <1>Displays the current nag directory.
    <2>Looks for an example from chapter g11.
    <3>Copies one of the examples in the list.
    <4>"Makes" the example.
    <5>Runs the example.
    <6>Runs the example again and compares the output against the official result file.
    <7>Removes all the files used to run this example.
    <8>Exits the shell.
<99>% nagshell
<1>% echo $NAG_DIR 
<2>% exampleList | grep g11
g10cafe.f g10zafe.f g11aafe.f g11bafe.f g11bbfe.f g11bcfe.f g11cafe.f 
g11safe.f g11sbfe.f g12aafe.f g12bafe.f g12zafe.f g13aafe.f g13abfe.f 
<3>% exampleGet g11cafe 
g11cafe.d g11cafe.f g11cafe.r
<4>% make g11cafe 
f77 -dalign -xtarget=ultra -mt -o g11cafe g11cafe.f -L/opt/nag/aslir6/flso619da
 -lnag-spl -xlic_lib=sunperf -lsocket -lnsl -lintl
<5>% exampleRun
 G11CAF Example Program Results 

 Deviance =    0.5475D+01 

  Strata     No. Cases   No. Controls
     1           2           2 
     2           1           2 

  Parameter      Estimate      Standard Error 
     1           -0.5223           1.3901 
     2           -0.2674           0.8473 
<6>% exampleRun | exampleCmp 
Program Results Match
<7>% exampleClean 
<8>% exit