Fortran User's Guide

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.