# NAG Fortran Compiler Release 6.1 Release Note

NAG Fortran Compiler Release 6.1 Release Note

# NAG Fortran Compiler Release 6.1 Release Note

## 1 Introduction

Release 6.1 of the NAG Fortran Compiler is a minor update.

Customers upgrading from a previous release of the NAG Fortran Compiler will need a new licence key for this release.

### 1.1 Compatibility with Release 6.0

Release 6.1 of the NAG Fortran Compiler is compatible with Release 6.0 except that programs that use allocatable arrays of “Parameterised Derived Type” will need to be recompiled (this only affects module variables and dummy arguments).

### 1.2 Compatibility with Releases 5.3.1, 5.3 and 5.2

Release 6.1 of the NAG Fortran Compiler is fully compatible with Release 5.3.1. It is also fully compatible with Releases 5.3 and 5.2, except that on Windows, modules or procedures whose names begin with a dollar sign (\$) need to be recompiled.

For a program that uses the new “Parameterised Derived Types” feature, it is strongly recommended that all parts of the program that may allocate, deallocate, initialise or copy a polymorphic variable whose dynamic type might be a parameterised derived type, should be compiled with Release 6.1.

### 1.3 Compatibility with Release 5.1

Release 6.1 of the NAG Fortran Compiler is compatible with NAGWare f95 Release 5.1 except that:
• programs or libraries that use the CLASS keyword, or which contain types that will be extended, need to be recompiled;
• the following 64-bit platforms, when the -abi=64 option (the default) is used, are binary incompatible and all programs and libraries need to be recompiled: NPL6A51NA, NPMI651NA.

### 1.4 Compatibility with Earlier Releases

Except as noted, the NAG Fortran Compiler release 6.1 is compatible with NAGWare f90 Releases 2.1 and 2.2, as well as with all NAGWare f95 Releases from 1.0 to 5.0, except as noted below.

The following incompatibilities were introduced in Release 5.1:

• The value returned by STAT=, on an ALLOCATE or DEALLOCATE statement, may differ from the pre-5.1 value in some cases. For further information see the F90_STAT module documentation.
• Programs that used type extension (EXTENDS attribute) in 5.0 need to be recompiled.
• Formatted output for IEEE infinities and NaNs is different, and now conforms to Fortran 2003.
• List-directed output of a floating-point zero now uses F format, as required by Fortran 2003, instead of E format.
• An i/o or format error encounted during NAMELIST input will now skip the erroneous record. This behaviour is the same as all other formatted input operations including list-directed.

## 2 New Features Summary

Release 6.1 includes several new features from the Fortran 2003 and 2008 standards, and some other common extensions.

This release also contains minor performance enhancements and other enhancements.

## 3 New Fortran 2003 Features

• Rounding mode edit descriptors in formats (FORMAT statement and character string formats) are supported. These change the i/o rounding mode during execution of the READ or WRITE statement; at the end of the statement, the i/o rounding mode reverts to the default for that unit (the same as happens with the ROUND= specifier in a READ or WRITE statement). These rounding mode edit descriptors are:
RC
same as Round='Compatible', this rounds to the nearest value — when two values are equally close, it is rounded away from zero;
RD
same as Round='Down', this rounds towards −∞;
RN
same as Round='Nearest', this rounds to the nearest value — when two values are equally close, it is rounded to the even one;
RP
same as Round='Processor_Dependent', the effects of this rounding mode are not standardised;
RU
same as Round='Up', this rounds towards +∞;
RZ
same as Round='Zero', this rounds towards zero.
• The input/output rounding mode now affects input.
• Length type parameters are now supported for derived types. A length type parameter can be used within a derived type to determine the character length or array bounds of a component; it cannot be used to determine the kind of a component.

These act similarly to character length, i.e.

• values for length type parameters can be non-constant specification expressions;
• dummy arguments can have assumed length type parameters (‘*’);
• allocatable and pointer variables can have deferred length type parameters (‘:’).

In the initial release these are subject to some restrictions; in particular, nested derived types cannot both have length type parameters, and only one component can have a size that depends on length type parameters. These restrictions will be lifted in due course.

## 4 New Fortran 2008 Features

• The target of a rank-remapping pointer assignment can be a multi-dimensional array, so long as it is “simply contiguous” (a term which means both that the array is contiguous, and that the contiguity is easily knowable at compile time).

For example:

  Real, Target :: x(100,100)
Real, Pointer :: p(:)
p(1:Size(x,1)*11) => x(:,20:30) ! A contiguous slice of a contiguous array.

• The real and imaginary parts of a COMPLEX object can be accessed using the complex part designators ‘%RE’ and ‘%IM’. For example, given
   COMPLEX,PARAMETER :: c = (1,2), ca(2) = [ (3,4),(5,6) ]

the designators c%re and c%im have the values 1 and 2 respectively, and ca%re and ca%im are arrays with the values [ 3,5 ] and [ 4,6 ] respectively. In the case of variables, for example
   COMPLEX :: v, va(10)

the real and imaginary parts can also be assigned to directly; the statement
   va%im = 0

will set the imaginary part of each element of va to zero without affecting the real part.
• The argument to the C_LOC function in the ISO_C_BINDING intrinsic module can be an assumed-shape array, an array pointer, and have character length greater than one. For example, the reference to C_LOC in
  Subroutine s(a)
Character(*),Target :: array(:)
Type(C_ptr) cp
cp = C_loc(array)

is allowed, as long as array is contiguous at runtime.
• The FORALL construct now has an optional type specifier in the initial statement of the construct, which can be used to specify the type (which must be INTEGER) and kind of the index variables. When this is specified, the existence or otherwise of any entity in the outer scope that has the same name as an index variable does not affect the index variable in any way. For example,
  Complex i(100)
Real x(200)
...
Forall (Integer :: i=1:Size(x)) x(i) = i

• The DO CONCURRENT construct is a DO loop with restrictions and semantics intended to allow efficient execution. The iterations of a DO CONCURRENT construct may be executed in any order, and possibly even in parallel. The loop index variables are local to the construct.

The DO CONCURRENT header has similar syntax to the FORALL header, including the ability to explicitly specify the type and kind of the loop index variables, and including the scalar mask.

The restrictions on the DO CONCURRENT construct are:

• no branch is allowed from within the construct to outside of it (this includes the RETURN and STOP statements, but ERROR STOP is allowed);
• the EXIT statement cannot be used to terminate the loop;
• the CYCLE statement cannot refer to an outer loop;
• there must be no dependencies between loop iterations, and if a variable is assigned to by any iteration, it is not allowed to be referenced by another iteration unless that iteration assigns it a value first;
• all procedures referenced within the construct must be pure;
• no reference to IEEE_GET_FLAG or IEEE_SET_HALTING_MODE is allowed.

For example,

  Integer vsub(n)
...
Do Concurrent (i=1:n)
! Safe because vsub has no duplicate values.
x(vsub(i)) = i
End Do

• The new elemental intrinsic functions BESSEL_J0, BESSEL_Y0, BESSEL_J1 and BESSEL_Y1 compute the Bessel functions J0, Y0, J1 and Y1 respectively. There is a single argument X, which must be of type Real; the result of the function has the same type and kind. For BESSEL_Y0 and BESSEL_Y1 the argument X must be positive. For example, BESSEL_J0(1.5) is approximately 0.5118276, BESSEL_Y0(1.5) is approximately 0.3824489, BESSEL_J1(1.5) is approximately 0.5579365 and BESSEL_Y1(1.5) is approximately -0.4123086.
• The new intrinsic functions BESSEL_JN and BESSEL_YN compute the Bessel functions Jn and Yn respectively. These functions come in two forms: an elemental form and a transformational form.

The elemental form has two arguments: N, the order of the function to compute, and X, the argument of the Bessel function. BESSEL_JN(0,X) is identical to BESSEL_J0(X), etc..

The transformational form has three scalar arguments: N1, N2 and X. The result is a vector of size MAX(N2-N1+1,0), containing approximations to the Bessel functions of orders N1 to N2 applied to X.

For example, BESSEL_JN(5,7.5) is approximately 0.283474, BESSEL_YN(5,7.5) is approximately 0.175418, BESSEL_JN(3,5,7.5) is approximately [ -0.258061, 0.023825, 0.283474 ] and BESSEL_YN(3,5,7.5) is approximately [ 0.159708, 0.314180, 0.175418 ].

• The standard intrinsic module ISO_FORTRAN_ENV now contains the function COMPILER_VERSION. This function is pure, has no arguments, and returns a scalar default character string that identifies the version of the compiler that was used to compile the source file. This function may be used in a constant expression, e.g. to initialise a variable or named constant with this information. For example,
  Module version_info
Use Iso_Fortran_Env
Character(Len(Compiler_Version())) :: compiler = Compiler_Version()
End Module
Program show_version_info
Use version_info
Print *,compiler
End Program

This program will print something like
 NAG Fortran Compiler Release 6.1(Tozai) Build 6105

• The standard intrinsic module ISO_FORTRAN_ENV now contains the function COMPILER_OPTIONS. This function is pure, has no arguments, and returns a scalar default character string that identifies the options supplied to the compiler when the source file was compiled. This function may be used in a constant expression, e.g. to initialise a variable or named constant with this information. For example,
  Module options_info
Use Iso_Fortran_Env
Character(Len(Compiler_Options())) :: compiler = Compiler_Options()
End Module
Program show_options_info
Use options_info
Print *,compiler
End Program

If compiled with the options -C=array -C=pointer -O, this program will print something like
 -C=array -C=pointer -O


## 5 Other Extensions

• The -dusty option now downgrades the error message for a missing required comma in the FORMAT statement to a warning message. (Previously this produced a syntax error.) For example, when an edit descriptor is followed by a character string with no separating comma.
• The ATAN, ATAN2, DIM, MOD, and MODULO intrinsic functions can be used on REAL arguments of differing kinds, and except for ATAN and ATAN2, on INTEGER arguments of differing kinds. It is still not permitted to mix INTEGER and REAL arguments in the same intrinsic function reference. The kind of the result is the same as that of mixed-kind arithmetic; that is, the same kind as the argument with the largest range if INTEGER and the same kind as the argument with the largest precision if REAL.

For example, in

   Subroutine s(a,b)
Use Iso_Fortran_Env
Real(Real32) a
Real(Real64) b
Print *,Mod(a,b)
End Subroutine

this will print the modulus of a and b after converting all of them to Real(Real64); that is, the same value as Mod(Real(a,Real64),b).
• The SIGN intrinsic function can be used on INTEGER or REAL arguments of differing kind. This feature is part of the draft Fortran 2015 standard.

It is still not permitted to mix INTEGER and REAL arguments in the same intrinsic function reference. The kind of the result is the same as that of the first argument (the argument that supplied the magnitude of the result); the kind of the second argument (which supplies only the sign of the result) does not affect the kind of the result.

For example, in

   Subroutine s(a,b)
Use Iso_Fortran_Env
Real(Real32) a
Real(Real64) b
Print *,Sign(a,b)
End Subroutine

this will print the Real(Real32) value with the magnitude of a and the sign of b; this has the same value as Sign(a,Real(Sign(1.0_Real64,b),Real32)).
• The ERROR STOP statement is now permitted to appear within a pure subprogram. This feature is part of the draft Fortran 2015 standard. Being able to use ERROR STOP in this way makes it possible to produce sensible error messages from a pure procedure; for example,

  Pure Integer Function f(n)
Integer,Intent(In) :: n
If (n==0) Error Stop 'n is equal to zero'
f = Huge(f)/n
End Function


• When an explicit interface is available, an error is reported for an actual argument that is a character function when its length is different from that of the dummy argument (assumed-length dummies can match any fixed-length actual argument, but a variable-length character function is only compatible when both the actual and dummy have variable length).
• A zero-sized array argument to the C_LOC function from the intrinsic module ISO_C_BINDING is now detected as an error, both at compile time, and at runtime when the -C=array option is used.
• Reference via an array object to a type-bound procedure with the NOPASS attribute is now detected as an error. This requirement was added to Fortran 2003 by Corrigendum 1 (interpretation request F03/0016), and is constraint C1230 in Fortran 2008.
• Integer overflow in the SIGN intrinsic function is now detected, both at compile time and, with the -C=intovf option, at runtime. Integer overflow occurs when the first argument to SIGN is the most negative number of that kind of integer, -1_kind-HUGE(0_kind), and the second argument is non-negative.
• Shape checking (with the -C=array option) for calls to elemental subroutines is now more reliable when some arguments are expressions rather than variables. In particular, this is now effective for elemental defined assignment.
• Invocation of an internal procedure via a dangling procedure pointer (that is, a procedure pointer that was assigned by a host instance that has since returned), is now detected by the -C=calls option.

## 7 Miscellaneous enhancements

• The polish tool (invoked with “nagfor =polish”) has two additional options for controlling comment wrapping. The -nowrap_comments option will, if comments are being indented, indent the comment normally, but will not wrap it when it is longer than the maximum line length. This may be useful when comments contain ASCII art diagrams etc. The -wrap_comments option is the default, and will wrap comments the same as in previous releases.
• The new polish option -align_right_continuation will right-align continuation ampersands at the end of continued lines (provided no inline comment is present). The default (no alignment) can be confirmed with the -noalign_right_continuation option. No special treatment, other than the rules for spacing tokens, will be applied to continuation ampersands at the end of lines. For example (with -align_right_continuation -width=50),
    Program align_example
Real :: square_root_of_two = sqrt(2.0)

Print *, 'The difference is',                &
square_root_of_two*square_root_of_two -    &
2.0000
End Program align_example

• The new polish option -character_decl=style has been added to control the style of CHARACTER declarations. The style argument must be one of the following:
Asis
This leaves the style unchanged, except that a non-default -kind_keyword= option will be obeyed. This is the default.
Keywords
This produces declarations using LEN= to specify the length (if the length appears), and KIND= to specify the kind (if the kind appears).
Kind_Keyword_Only
This produces declarations using KIND= to specify the kind (if the kind appears) and omits the LEN= for the length.
No_Keywords
This produces declarations with no keywords for either the length or kind.
If the style is anything other than Asis, the obsolescent “CHARACTER*length” form will be changed to the modern “CHARACTER(length)” form. If both the length and kind appear in the input, the length will appear first in the output.

For example, given the input:

      Character*7 seven
Character(Kind=iso_10646,Len=:),Allocatable :: name

the output with each option is as follows.

With -character_decl=Asis:

      Character *7 seven
Character (Kind=iso_10646, Len=:), Allocatable :: name

With -character_decl=Keywords:
      Character (Len=7) seven
Character (Len=:, Kind=iso_10646), Allocatable :: name

With -character_decl=Kind_Keyword_Only:
      Character (7) seven
Character (:, Kind=iso_10646), Allocatable :: name

With -character_decl=No_Keywords:
      Character (7) seven
Character (:, iso_10646), Allocatable :: name

• The new polish option -commas_in_formats=X has been added to control the use of optional commas in FORMAT statements; X must be one of the following:
Asis
The input FORMAT statements are left unmodified with respect to optional commas.
Insert
Commas are inserted into every allowable position in FORMAT statements. This is the default.
Remove
All optional commas are deleted from FORMAT statements.
For example, given the input:
100   Format (1P1F2.1, 1X/, :1P, E2.1)

the output with each option is as follows.

With -commas_in_formats=Asis:

100   Format (1P1F2.1, 1X/, :1P, E2.1)

With -commas_in_formats=Insert or with no -commas_in_formats option supplied:
100   Format (1P, 1F2.1, 1X, /, :, 1P, E2.1)

With -commas_in_formats=Remove:
100   Format (1P1F2.1, 1X/:1PE2.1)

• The accuracy of the quad-precision versions of the intrinsic functions ATANH and TANH has been improved.
• The performance of the quad-precision versions of the intrinsic functions EXP and LOG has been improved.
• The interface generator (“nagfor =interfaces”) is now able to produce interface blocks for entry points in external subprograms. Additionally, the tool no longer adds irrelevant (but harmless) additional declarations to any interface block being output. For example, given the code
Subroutine sub(a)
Real, Intent (In) :: a, b
Print *, a
Return
Entry entry(b)
Print *, b**2
Return
End Subroutine

an interface module of the form
    Module interfaces
! Interface module generated on ...
Interface
Subroutine entry(b)
Real, Intent (In) :: b
End Subroutine
Subroutine sub(a)
Real, Intent (In) :: a
End Subroutine
End Interface
End Module

is created.
• When using the tracing-capable memory allocator, the total amount of memory that may be allocated can be limited using the NAGFORTRAN_MTRACE_OPTIONS environment variable. The ‘limit=N’ option limits the maximum memory allocated to N MiB (mebibytes), but only if the program was built with a tracing option (minimally, -mtrace=off). Exceeding the memory limit will result in a normal “out of memory” condition, which if it occurs in an ALLOCATE statement, can be captured by a STAT= clause. Note that the memory limit applies to the overall memory usage including automatic variables and compiler-generated array temporaries.

For example, with the program

    Program big
Real,Pointer :: x(:,:,:)
Allocate(x(100,1024,1024))
x = 1
Print *,Sum(x)
End Program

and a NAGFORTRAN_MTRACE_OPTIONS environment variable setting of ‘size,limit=50’, the program will produce output similar to
  [Allocated item 1 (size 65537) = Z'2430010']
[Allocated item 2 (size 65537) = Z'2440030']
[Allocated item 3 (size 65537) = Z'2450050']
[Allocation (size 419430384) at line 3 of big.f90 failed - memory limit (50 MiB) exceeded]
Runtime Error: bigalloc.f90, line 3: ALLOCATE failed: Out of memory
Program terminated by fatal error
[Deallocated item 2 (size 65537, at Z'2440030')]
[Deallocated item 3 (size 65537, at Z'2450050')]
[Deallocated item 1 (size 65537, at Z'2430010')]

• A precision unifier tool is now included with the compiler system. This tool unifies the precision of floating-point and complex entities in Fortran source files. It is accessed with “nagfor =unifyprecision”.
• When preprocessing Fortran files with fpp, the macro __NAG_COMPILER_RELEASE is defined to be the integer corresponding to the current compiler release; for release 6.1 (Tozai), this value is 61. Similarly, the macro __NAG_COMPILER_BUILD is defined to be the build number. For release 6.1, this number will have a value greater than 6100.