Fortran User's Guide

Appendix C Fortran 90 Features and Differences

This appendix shows some of the major features differences between:

Features

Sun Fortran 90 provides the following features.

Tabs in the Source

f90 allows the tab character in fixed-form source and in free-form source. Standard Fortran 90 does not allow tabs.

The tab character is not converted to a blank, so the visual placement of tabbed statements depends on the utility you use to edit or display text.

Fixed-Form Source

Free-Form Source

f90 treats a tab and a blank character as equivalent, except in literal strings.

Continuation Line Limits

f90 and f77 allow 99 continuation lines (1 initial and 98 continuation lines). Standard Fortran 90 allows 19 for fixed-form and 39 for free-form.

Fixed-Form Source Lines

In fixed-form source, lines can be longer than 72 characters. Columns 73 through 96 are ignored. Standard Fortran 90 allows 72-character lines.

Directives

f90 allows directive lines starting with CDIR$, !DIR$, CMIC$, or !MIC$. They look like comments but are not. For full details on directives, see "Directives". Standard Fortran 90 has no directives.

Tab Form

The tab form source text is defined as follows:

Example: The tab form source on the left is treated as shown on the right.


!^IUses of tabs
^ICHARACTER *3 A = 'A'
^IINTEGER B = 2
^IREAL C = 3.0
^IWRITE(*,9) A, B, C
9^IFORMAT(1X, A3,
^I1 I3,
^I2 F9.1 )
^IEND
!       Uses of tabs
        CHARACTER *3 A = 'A'
        INTEGER B = 2
        REAL C = 3.0
        WRITE(*,9) A, B, C
9       FORMAT(1X, A3,
       1 I3,
       2 F9.1 )
        END

In the example above, "^I" is a way of indicating the tab character, and the line starting with "1" and "2" are continuation lines. The coding is shown to illustrate various tab situations, and not to advocate any one style.

Source Form Assumed

The source form assumed by f90 depends on options, directives, and suffixes.

Table C-1 F90 Source Form Command-line options

Option  

Action  

-fixed

Interpret all source files as Fortran fixed form

-free

Interpret all source files as Fortran free form

If the -free or -fixed option is used, that overrides the file name suffix.

Table C-2 F90 File name suffixes

Suffix  

Source Form  

.f90

Fortran free-form source files

.f

Fortran fixed-form source files or

ANSI standard FORTRAN 77 source files 

.for

Same as .f.

.ftn

Same as .f.

other 

None--file name is passed to the linker 

If either a FREE or FIXED directive is used, that overrides the option and file name suffix.

Mixing Forms

Some mixing of source forms is allowed.

Case

Sun Fortran 90 is case insensitive. That means that a variable AbcDeF is treated as if it were spelled abcdef, or abcdeF, etc. "Compatibility with FORTRAN 77"

Boolean Type

f90 supports constants and expressions of Boolean type. There are no Boolean variables or arrays, and there is no Boolean type statement.

Miscellaneous Rules Governing Boolean Type

Alternate Forms of Boolean Constants

f90 allows a Boolean constant (octal, hexadecimal, or Hollerith) in the following alternate forms (no binary). Variables cannot be declared Boolean. Standard Fortran does not allow these forms.

Octal

ddddddB, where d is any octal digit

Within an I/O format specification, the letter B indicates binary digits; elsewhere it indicates octal digits.

Hexadecimal

X'ddd' or X"ddd", where d is any hexadecimal digit

Hollerith

Accepted forms for Hollerith data are:

nH...

'...'H

"..."H

nL...

'...'L

"..."L

nR...

'...'R

"..."R

Above, "..." is a string of characters and n is the character count.

Examples: Octal and hexadecimal constants.

Boolean Constant 

Internal Octal for 32-bit word 

 0B 00000000000
 77740B 00000077740
 X"ABE" 00000005276
 X"-340" 37777776300
 X'1 2 3' 00000000443
 X'FFFFFFFFFFFFFFFF' 37777777777

Examples: Octal and hexadecimal in assignment statements.

 i = 1357B
 j = X"28FF"
 k = X'-5A'

Use of an octal or hexadecimal constant in an arithmetic expression can produce undefined results and do not generate syntax errors.

Alternate Contexts of Boolean Constants

f90 allows BOZ constants in the places other than DATA statements.

B'bbb'

O'ooo'

Z'zzz'

B"bbb"

O"ooo"

Z"zzz"

If these are assigned to a real variable, no type conversion occurs.

Standard Fortran allows these only in DATA statements.

Abbreviated Size Notation for Numeric Data Types

f90 allows the following nonstandard type declaration forms in declaration statements, function statements, and IMPLICIT statements.

Table C-3 Size Notation for Numeric Data Types

Nonstandard 

Declarator 

Short Form 

Meaning 

INTEGER*1INTEGER(KIND=1)INTEGER(1)

One-byte signed integers  

INTEGER*2INTEGER(KIND=2)INTEGER(2)

Two-byte signed integers  

INTEGER*4INTEGER(KIND=4)INTEGER(4)

Four-byte signed integers  

LOGICAL*1LOGICAL(KIND=1)LOGICAL(1)

One-byte logicals  

LOGICAL*2LOGICAL(KIND=2)LOGICAL(2)

Two-byte logicals  

LOGICAL*4LOGICAL(KIND=4)LOGICAL(4)

Four-byte logicals  

REAL*4REAL(KIND=4)REAL(4)

IEEE single-precision floating-point (Four-byte) 

REAL*8REAL(KIND=8)REAL(8)

IEEE double-precision floating-point (Eight-byte) 

COMPLEX*8COMPLEX(KIND=4)COMPLEX(4)

Single-precision complex (Four-bytes each part) 

COMPLEX*16COMPLEX(KIND=8)COMPLEX(8)

Double-precision complex (Eight-bytes each part) 

The form in column one is nonstandard Fortran 90, though in common use. The kind numbers in column two can vary by vendor.

Cray Pointers

A Cray pointer is a variable whose value is the address of another entity, which is called the pointee.

f90 supports Cray pointers; Standard Fortran 90 does not.

Syntax

The Cray POINTER statement has the following format:


POINTER  ( pointer_name, pointee_name [array_spec] ), ...

Where pointer_name, pointee_name, and array_spec are as follows:

pointer_name

Pointer to the corresponding pointee_name.

pointer_name contains the address of pointee_name.

Must be: a scalar variable name (but not a structure) 

Cannot be: a constant, a name of a structure, an array, or a 

function 

pointee_name

Pointee of the corresponding pointer_name

Must be: a variable name, array declarator, or array name 

array_spec

If array_spec is present, it must be explicit shape, (constant or nonconstant bounds), or assumed-size.

Example: Declare Cray pointers to two pointees.


	POINTER ( p, b ),  ( q, c )

The above example declares Cray pointer p and its pointee b, and Cray pointer q and its pointee c.

Example: Declare a Cray pointer to an array.


	 POINTER ( ix, x(n, 0:m) )

The above example declares Cray pointer ix and its pointee x; and declares x to be an array of dimensions n by m-1.

Purpose of Cray Pointers

You can use pointers to access user-managed storage by dynamically associating variables to particular locations in a block of storage.

Cray pointers allow accessing absolute memory locations.

Cray pointers do not provide convenient manipulation of linked lists because (for optimization purposes) it is assumed that no two pointers have the same value.

Cray Pointers and Fortran Pointers

Cray pointers are declared as follows:

POINTER ( pointer_name, pointee_name [array_spec] )

Fortran pointers are declared as follows:

POINTER object_name

The two kinds of pointers cannot be mixed.

Features of Cray Pointers

Restrictions on Cray Pointers

Restrictions on Cray Pointees

Usage of Cray Pointers

Cray pointers can be assigned values as follows:

Example: Use Cray pointers as described above.


	SUBROUTINE  sub ( n )
	COMMON pool(100000)
	INTEGER blk(128), word64
	REAL a(1000), b(n), c(100000-n-1000)
	POINTER ( pblk, blk ), (ia, a ), ( ib, b ), &
			( ic, c ), ( address, word64 )
	DATA address / 64 /
	pblk = 0
	ia = LOC( pool )
	ib = ia + 1000
	ic = ib + n
	...

Remarks about the above example:

Optimization and Cray Pointers

For purposes of optimization, f90 assumes the storage of a pointee is never overlaid on the storage of another variable--it assumes that a pointee is not associated with another variable.

Such association could occur in either of two ways:

These kinds of association are sometimes done deliberately, such as for equivalencing arrays, but then results can differ depending on whether optimization is turned on or off.

Example: b and c have the same pointer.


	POINTER ( p, b ),  ( p, c )
	REAL x, b, c
	p = LOC( x )
	b = 1.0
	c = 2.0
	PRINT *, b
	...

Above, because b and c have the same pointer, assigning 2.0 to c gives the same value to b. Therefore b prints out as 2.0, even though it was assigned 1.0.

Cray Character Pointers

If a pointee is declared as a character type, its Cray pointer is a Cray character pointer.

Purpose of Cray Character Pointers

A Cray character pointer is a special data type that allows f90 to maintain character strings by keeping track of the following:

An assignment to a Cray character pointer alters all three. That is, when you change what it points to, all three change.

Declaration of Cray Character Pointers

For a pointee that has been declared with an assumed length character type, the Cray pointer declaration statement declares the pointer to be a Cray character pointer.

  1. Before the Cray pointer declaration statement, declare the pointee as a character type with an assumed length.

  2. Declare a Cray pointer to that pointee.

  3. Assign a value to the Cray character pointer.

You can use functions CLOC or FCD, both nonstandard intrinsics.

Example: Declare Ccp to be a Cray character pointer and use CLOC to make it point to character string s.


	CHARACTER*(*) a
	POINTER ( Ccp, a )
	CHARACTER*80  :: s = "abcdefgskooterwxyz"
	Ccp = CLOC( s )

Operations on Cray Character Pointers

You can do the following operations with Cray character pointers:

 Ccp1 + i
 Ccp1 - i
 i + Ccp1
 Ccp1 = Ccp2
Ccp1 relational_operator Ccp2

where Ccp1 and Ccp2 are Cray character pointers and i is an integer.

Restrictions on Cray Character Pointers and Pointees

All restrictions to Cray pointers also apply to Cray character pointers. In addition, the following apply:

Intrinsics

f90 supports some intrinsic procedures which are extensions beyond the standard.

Table C-4 Nonstandard Intrinsics

 

 

  Type

 

 

Name 

Definition 

Function 

Arguments 

Arguments 

Notes 

CLOC

Get Fortran character descriptor (FCD)

Cray character pointer 

character 

([C=]c)

NP, I 

COT

Cotangent 

real 

real 

([X=]x)

P, E 

DDIM

Positive difference 

double precision 

double precision 

([X=]x,[Y=]y)

P, E 

FCD

Create Cray character pointer in Fortran character descriptor (FCD) format

Cray pointer 

i: integer    or Cray pointer 

j: integer 

([I=]i,[J=]j)

i: word address of first character 

j: character length 

NP, I 

LEADZ

Get the number of leading 0 bits 

integer 

Boolean, integer, real, or pointer 

([I=]i)

NP, I 

POPCNT

Get the number of set bits 

integer 

Boolean, integer, real, or pointer 

([I=]i)

NP, I 

POPPAR

Calculate bit population parity 

integer 

Boolean, integer, real, or pointer 

([X=]x)

NP, I 

Notes on the above table: 

The name can be passed as an argument. 

NP 

The name cannot be passed as an argument. 

External code for the intrinsic is called at run time. 

f90 generates inline code for the intrinsic procedure.

Directives

A compiler directive directs the compiler to do some special action. Directives are also called pragmas.

A compiler directive is inserted into the source program as one or more lines of text. Each line looks like a comment, but has additional characters that identify it as more than a comment for this compiler. For most other compilers, it is treated as a comment, so there is some code portability.

Sun-style directives are the default with f90 (and f77). To switch to Cray-style directives, use the -mp=cray compiler command-line flag.

Form of General Directive Lines

General directives have the following syntax.


!DIR$ d1, d2, ...

A general directive line is defined as follows.

The form varies for fixed-form and free-form source as follows.

Fixed-Form Source

Free-Form Source

Thus, !DIR$ in columns 1 through 5 works for both free-form source and fixed-form source.

FIXED and FREE Directives

These directives specify the source form of lines following the directive line.

Scope

They apply to the rest of the file in which they appear, or until the next FREE or FIXED directive is encountered.

Uses

Restrictions

The FREE/FIXED directives:

Example: A FREE directive.


!DIR$ FREE
	DO i = 1, n
		a(i) = b(i) * c(i)
	END DO

Parallelization Directives

A parallelization directive is a special comment that directs the compiler to attempt to parallelize the next DO loop. Currently there is only one parallel directive, DOALL.

The DOALL directive tells the compiler to parallelize the next loop it finds, if possible.

Form of Parallelization Directive Lines

Parallel directives have the following syntax.


!MIC$ DOALL [general parameters] [scheduling parameter]

A parallelization directive line is defined as follows.

The form varies for fixed-form and free-form source as follows.

Fixed

Free

Thus, !MIC$ in columns 1 through 5 works for both free and fixed.

Example: Directive with continuation lines (DOALL directive and parameters.)


C$PAR DOALL
!MIC$&   SHARED( a, b, c, n )
!MIC$&   PRIVATE( i )
	DO i = 1, n
		a(i) = b(i) * c(i)
	END DO

Example: Same directive and parameters, with no continuation lines.


C$PAR DOALL  SHARED( a, b, c, n )  PRIVATE( i )
	DO i = 1, n
		a(i) = b(i) * c(i)
	END DO

Compatibility with FORTRAN 77

Source

Standard-conforming FORTRAN 77 source code is compatible with Sun Fortran 90. Use of non-standard extensions, such as VMS Fortran features, are not compatible and may not compile with Sun Fortran 90.

Both f77 and f90 treat all source lines as if they were lowercase (except in quoted character strings. However, unlike f77, f90 has no -U option to force the compiler to be sensitive to both upper and lower case. This may present a problem when mixing f77 and f90 compiled routines. Since a routine compiled by f90 will treat CALL XyZ the same as CALL XYz, and treat them both as if they were CALL xyz, care must be taken to rearrange the way these calls are made. A similar situation will exist when trying to define entry points in f90 compiled routines that are differentiated by case. The clue to potential problems would be the need to use -U with f77.

Linking with f77-Compiled Routines

Example: f90 main calls a routine from the FORTRAN 77 library.


demo% cat tdtime.f90
        REAL e, dtime, t(2)
        e = dtime( t )
        DO i = 1, 100000
           as = as + cos(sqrt(float(i)))
        END DO
        e = dtime( t )
        PRINT *, 'elapsed:', e, ', user:', t(1), ', sys:', t(2)
        END
demo% f90 tdtime.f90
demo% a.out
elapsed: 0.14 , user: 0.14 , sys: 0.0E+0
demo% 

See dtime(3F).

I/O

f77 and f90 are generally I/O compatible for binary I/O, since f90 links to the f77 compatibility library.

Such compatibility includes the following two situations:

The numbers read back in may or may not equal the numbers written out.

Intrinsics

The Fortran 90 standard supports the following new intrinsic functions that FORTRAN 77 does not have.

If you use one of these names in your program, you must add an EXTERNAL statement to make f90 use your function rather than the intrinsic one.

Fortran 90 intrinsics:

"ADJUSTL,ADJUSTR,ALL,ALLOCATED,ANY,BIT_SIZE,COUNT,CSHIFT, DIGITS,DOT_PRODUCT,EOSHIFT,EPSILON,EXPONENT,HUGE,KIND, LBOUND,LEN_TRIM,MATMUL,MAXEXPONENT,MAXLOC,MAXVAL,MERGE, MINEXPONENT,MINLOC,MINVAL,NEAREST,PACK,PRECISION,PRESENT, PRODUCT,RADIX,RANGE,REPEAT,RESHAPE,RRSPACING,SCALE,SCAN, SELECTED_INT_KIND,SELECTED_REAL_KIND,SET_EXPONENT,SHAPE, SIZE,SPACING,SPREAD,SUM,TINY,TRANSFER,TRANSPOSE,UBOUND, UNPACK,VERIFY"

Forward Compatibility

Future releases of f90 are intended to be source code compatible with this release.

Module information files generated by this release of f90 are not guaranteed to be compatible with future releases.

Mixing Languages

On Solaris systems, routines written in C can be combined with Fortran programs, since these languages have common calling conventions.

Module Files

Compiling a file containing a Fortran 90 MODULE generates a module file (.mod file) for every MODULE encountered in the source. The file name is derived from the name of the MODULE; file xyz.mod (all lowercase) will be created for MODULE xyz.

By default, such files are usually sought in the current working directory. The -Mdir option allows you to tell f90 to seek them in an additional location.

The .mod files cannot be stored into an archive file, or concatenated into a single file.