Using the NAG Compiler with the NAG Fortran Library (Mark 26) on Windows

Posted on
1 Feb 2018

Introduction

The NAG Fortran Compiler is an excellent compiler for checking and running your Fortran code. We use it extensively here at NAG to ensure that our code for the library complies with the current Fortran standards.

Personally, whenever I have a user problem report that I can’t resolve by inspection my first instinct is to run the user's code with the Compiler. Frequently this identifies the error immediately.

As I am a Windows user, I am able to make use of the Integrated Development Environment (IDE) for the compiler that is provided to our Windows users. We call this IDE ‘NAG Fortran Builder’. One of the nice features of this IDE is its ease of use with the prevailing NAG libraries. To do this the user normally specifies a ‘NAG Library Project’ at creation time; thereafter the relevant settings are made to the compiler, so that either the Windows 64-bit or Windows 32-bit DLLs are used.

At points in the NAG cycle a situation arises where the latest Fortran Builder is released. It automatically picks up the then current NAG libraries and uses the MKL versions of these libraries in a NAG Library Application Project. (To use a 'vanilla' non-MKL library use a Console Application Project and follow the advice below.) Information about the current libraries is embedded within Fortran Builder. This information includes documentation, interface blocks and example program information, all of which is mark-dependent. Subsequently a new NAG Library is released and so our Windows users would want to use the latest library from Fortran Builder. Some guidance is given on this within the relevant Users’ Note. This note attempts to gather together and expand on this information.

New Fortran Builder Projects

Fortran Builder may be set to work in 64-bit or 32-bit mode and to link to the corresponding NAG Fortran Libraries. At Fortran Builder 6.1 we expected these to be FLW6I26DEL or FLDLL26DEL respectively and the rest of this note is written with these specific implementations in mind. Please note though that Fortran Builder 6.2 is optimized to use the Mark 26 Library, FLW6I26DEL in 64-bit mode, so the changes suggested below are unnecessary if you have Fortran Builder 6.2. Should you only have a Mark 25 library then 6.2 of Fortran Builder will link against that.

Fortran Builder Mode Mark Product Codes
6.1 64-bit 25 FLW6I25DEL & others
  32-bit 25 FLDLL254ML & others
6.2 64-bit 26
25
FLW6I26DEL
FLW6I25DEL & FLW6I25DCL
  32-bit 25 FLDLL254ML

To use a Mark 26 Library with Fortran Builder 6.1 using FLW6I26DEL (64-bit):

  1. Open a Console Application (not a NAG Library Application)
  2. Go to Project Settings via the Project menu
  3. Click the Directories tab, then click the Include tab
  4. Add the include directory install dir\nag_interface_blocks_nagfor (where install dir should be replaced with the full path to the NAG Library installation directory on your machine. Note that you should not put any quotation marks around the directory name even though it may include spaces)
  5. Exit from the Directories tab, then click the Link tab
  6. Add a link library, for example install dir\bin\FLW6I26DE_nag.dll (note that you must link to the DLL itself, not the associated import library)
  7. Build the project and run your program in the usual way

{If you have a 64-bit integer version of the Mark 24 Library FLW6I24DDL then the –i8 option must be set under the Fortran Compiler / Additional Options tab also}

To use a Mark 26 Library with Fortran Builder 6.1 using FLDLL26DEL (32-bit):

  1. Open a Console Application (not a NAG Library Application)
  2. Go to Project Settings via the Project menu
  3. Click the Directories tab, then click the Include tab
  4. Add the include directory install dir\nag_interface_blocks_nagfor (note that you should not put any quotation marks around the directory name even though it may include spaces)
  5. Exit from the Directories tab, then click the Link tab
  6. Add a link library, for example install dir\lib\FLDLL26DE_nag.lib
  7. Click the Basic Settings tab, and tick the DLL Compatibility check box - this turns on the -compatible flag to ensure that the compiler uses the same stdcall calling convention used to build the library. (This is a step not required in 64-bit mode where DLLs are already compatible.)
  8. Build the project and run your program in the usual way

In both cases, if you build your project in Debug mode (the default), it is not possible to use the Undefined variables option which is accessible on the Fortran Compiler / Runtime Check tab of Project Settings. This is because the NAG Library was not compiled with this option.

Also in both cases, should you want to link to the NAG Library in all future Console Application projects tick the 'Set as Default' option.

Please note that if you had decided to set these new library settings as defaults and you subsequently form a new ‘NAG_Library Application’ project by mistake then numerous warning messages will be generated on compilation. This is because of incompatibilities with the interface blocks. You may recover from this by unticking the ‘Use the NAG Fortran Library’ box under Project Settings/Basic Settings. If Fortran Builder is unable to find a supported NAG Library then it won’t let you create a NAG Library Application project.

Existing Fortran Builder Projects

If a Fortran Builder project already exists and has linked to the NAG Library then the chances are that it will be a ‘NAG Library Application’ project. If you still have the Mark 24 libraries on your system then these are the libraries that will be accessed and used.

You may however wish to use the latest, Mark 26, Library, either to get an updated version of the relevant routines or to exploit the new functionality on offer with Mark 26. Under these circumstances the project needs to be changed.

Unfortunately this entails a number of steps for each project that you need to convert:

  • unticking the ‘Use the NAG Fortran Library’ box under Project Settings/Basic Settings.
  • Now repeat steps b) to g) or b) to h) for the relevant library as described above.

An alternative, if you have already set up the default console application to incorporate NAG Library, Mark 24, is to simply recreate the project as a Console Application.

Updating the NAG Help file available from Fortran Builder

You will require administrator privileges to do this, and you may well decide not to tamper in this manner, but it is possible to access the Mark 26 Help file directly from Fortran Builder. The process involves copying the help file provided on the documentation page into the bin directory of Fortran Builder. This location is typically C:\Program Files (x86)\NAG\EFBuilder 6.1\bin. We suggest you rename the existing help file nagdoc_fl24.chm to xnagdoc_fl24.chm. Now copy nagdoc_fl26.chm from the library into the .\bin directory and trick Fortran Builder by renaming nagdoc_fl26.chm to nagdoc_fl24.chm.

This works, but unless you feel strongly that this is what you need, it is not a process we recommend. The help file can always be accessed from the appropriate library directory rather than from Fortran Builder.

Updating the example program templates

Any tampering with the Fortran Builder files to access the Mark 24 example templates is even less recommended than the procedure for the documentation outline above. The relevant directories are below C:\Program Files (x86)\NAG\EFBuilder 6.1\bin\resource\fldll244m.

It is our view that you (the user) should note that each of the libraries is provided with example programs, data and results and we suggest that you ought to simply copy the ones that you want into your project source directory. (It may seem obvious, but copying the files means that the original will still be available for use another time.)

This article was first published on our blog on 28 November 2013, it has now been updated for using NAG's Fortran Compiler at Release 6.1 with Mark 26 of the NAG Fortran Library. Written by David Sayers, NAG Principal Technical Consultant