Compute Canada

How do I use the NAG F90 Library?

Please note: The FAQ pages at the HPCVL website are continuously being revised. Some pages might pertain to an older configuration of the system. Please let us know if you encounter problems or inaccuracies, and we will correct the entries.

The NAG F90 library is a completely rewritten version of the Fortran library and uses the Fortran 90 extension of Fortran on all levels. For instance, array operations make use of the extended abilities of Fortran 90, and all programs have a modular structure. The libraries are only available as static archives, and reside in/opt/nag/fnsol04dcl.

One consequence of the Fortran 90 modular program structure is that data and methods residing in modules need to be compiled before they are available for other Fortran routines via the use command. All the modules needed for use with the NAG F90 library reside in /opt/nag/fnsol04dcl/nagfl90_modules. Here is a typical set of compile/link calls:

Compiling:

f90 -c -dalign -M/opt/nag/fnsol04dcl/nagfl90_modules program.f90

Linking (static):

f90 -o program.exe -dalign -M/opt/nag/fnsol04dcl/nagfl90_modules \
-lsocket -lnsl -lintl -xlic_lib=sunperf program.o /opt/nag/fnsol04dcl/lib/libnagfl90_spl.a

Linking (dynamic):

f90 -o program.exe -dalign -M/opt/nag/fnsol04dcl/nagfl90_modules \
-lsocket -lnsl -lintl -xlic_lib=sunperf program.o \ -Bdynamic -L/opt/nag/fnsol04dcl/lib \
-R/opt/nag/fnsol04dcl/lib -lnagfl90_spl

The -M option in the above lines serves to let the compiler/linker know where the module files associated with the F90 library reside.

Examples for the usage of the F90 libraries may be found in /opt/nag/fnsol04dcl/examples/source. There is a considerable difference in the way the F90 library is used from its Fortran counterpart. One diference is the usage of modules. For instance, the routine nag_gen_lin_sol solves systems of linear equations and requires the use of several modules:

PROGRAM test USE nag_examples_io, ONLY : nag_std_in, nag_std_out USE nag_gen_lin_sys,
ONLY : nag_gen_lin_sol (...) INTRINSIC KIND (...) REAL (wp),
ALLOCATABLE :: a(:,:), b(:) (...) READ (nag_std_in,*) READ (nag_std_in,*) n
READ (nag_std_in,*) trans ALLOCATE (a(n,n),b(n)) READ (nag_std_in,*) (a(i,:),i=1,n)
READ (nag_std_in,*) b CALL nag_gen_lin_sol(a,b,trans=trans,bwd_err=bwd_err,
fwd_err=fwd_err,rcond=rcond) (...) DEALLOCATE (a,b) END PROGRAM nag_gen_lin_sys_ex01

Note that the array a in the above example is dynamically allocated and needs to be deallocated at the end of the program. I/O occurs with units that are defined in modules. The intrinsic function kind has to be declared as such and is used to determine the type of a given variable.