Our department has a 2-seat floating licence for the NAG Fortran 7.1 version for OS X (Mac) and a 1-seat floating license for version 7.2 for Linux . On a Mac machine (desktop/laptop) with Intel CPUs download the disk image file npmi671na_macx64_7138.dmg or on an ARM processore machine use npma871na_macarm64_7138.dmg that contains NAGFOR 7.1 (7138) that has been improved to stop at floating point exceptions despite the incomplete hardware support of the ARM chip. This is the latest version that our current license is valid for. (Newer versions can be obtained from the NAG download page). Open it

open npm*_macx64*.dmg

and from the command line run the install script (as admin):

sudo -s /Volumes/NAG_Fortran-macarm64/INSTALL.sh

and go through the installation steps.

If you have a NAG license key file, remember to place it into

/usr/local/lib/NAG_Fortran/nag.key

Alternatively set the NAG_KUSARI_FILE to point to the license server. For example, under csh or tcsh, use

setenv NAG_KUSARI_FILE server.machine.university.edu:

in the .cshrc file. Under ksh or bash use

export NAG_KUSARI_FILE=server.machine.university.edu:

The actual name of the server machine can be obtained from Gabor Toth. You will need to use VPN to access the license server remotely. For Windows Subsystem Linux (WSL) you may need to put the following two lines into the .wslconfig file in the Windows (!) home directory to make VPN work:
[wsl2]
networkingMode=mirrored
Try checking the available licenses:
  nagfor -xlicinfo
  NAG Fortran Compiler Release 7.1(Hanzomon) Build 7138
  FLOATING licence, 2 total, 1 in use, perpetual (licence from server)
  Kusari version is 2.2(101)
If the executable does not run because it is not from the App Store, then open Security settings under System Settings, and provide permission to run it.

It is recommended to use the MPICH version of the MPI library that is available from Share/MPI which is configured for nagfor.

On the solsticedisk machine NAGFOR is installed with the OpenMPI library. You need to set the following environment variables (under csh/tcsh):

setenv MPI_HOME /usr/lib64/openmpi         # where OpenMPI is installed
setenv LD_LIBRARY_PATH ${MPI_HOME}/lib     # needed for runtime libraries
setenv PATH "${MPI_HOME}/bin:${PATH}"      # to access mpif90, mpiexec etc.
setenv OMPI_LDFLAGS "-L${LD_LIBRARY_PATH}" # for linking
setenv OMPI_FC nagfor                      # for compilation
setenv OMPI_FCFLAGS ' '                    # for compilation
or under ksh or bash use
export MPI_HOME=/usr/lib64/openmpi         # where OpenMPI is installed
export LD_LIBRARY_PATH=${MPI_HOME}/lib     # needed for runtime libraries
export PATH="${MPI_HOME}/bin:${PATH}"      # to access mpif90, mpiexec etc.
export OMPI_LDFLAGS="-L${LD_LIBRARY_PATH}" # for linking
export OMPI_FC=nagfor                      # for compilation
export OMPI_FCFLAGS=' '                    # for compilation
before compilation. You can define aliases
alias load_nagfor "setenv OMPI_FC nagfor; setenv OMPI_FCFLAGS ' '"
alias load_gfortran "unsetenv OMPI_FC; unsetenv OMPI_FCFLAGS"
to switch between nagfor and gfortran (for ksh etc the syntax is alias A=B).

NAGFOR translates the Fortran code into C, which is then compiled with a C compiler. The 7.1 version running on a Mac assumes that the C compiler named "gcc" is Apple's clang compiler in /usr/bin/gcc as opposed to the original GNU gcc compiler. If you wish to use the original GNU gcc compiler, it needs to be installed, it has to be in the path before /usr/bin/ and it needs to be selected with the -Wc=`which gcc` flag passed to nagfor.

In addtion the clang specific compiler flag "-fbracket-depth=..." needs to be removed from the call to gcc. This can be done by calling the gcc Perl script that removes the offending switch. Place this script into a directory in the path, for example ~/bin/, so that "which gcc" finds this instead of Apple's /usr/bin/gcc or the original GNU gcc compiler. Remember to make the script executable with

chmod +x gcc

In addition put a link "g++" pointing at the the desired version of the GNU g++ compiler:

ln -s `which g++-12-mp` ~/bin/g++

so that mpicxx uses the GNU g++ compiler instead of the Apple version.

To use the nagfor compiler with GNU gcc, install the SWMF or any of the SWMF models with

Config.pl -install -compiler=nagfor,gcc_mpicc

To use nagfor with Apple's clang compiler, use

Config.pl -install -compiler=nagfor,clang_mpicc

or simply

Config.pl -install

as this compiler combination is actually the default on Mac OS.