Previous Next Contents Index Doc Set Home


Fortran 90 Features and Differences

C


This appendix shows some of the major features differences between:


Standards

This Fortran is an enhanced ANSI Standard Fortran development system.


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 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

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

Continuation Line Limits

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

Fixed-Form Source of 96 Characters

In fixed-form source, lines can be 96 characters long. Columns 73 through 96 are ignored. Standard Fortran 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" on page 140. Standard Fortran has no directives.

Source Form Assumed

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

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

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.

Sun Fortran 90 is case insensitive at this release (1.2). That means that a variable AbcDeF is treated as if it were spelled abcdef, or abcdeF, etc. See Compatibility with FORTRAN 77 on page 145.

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

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

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-1 Size Notation for Numeric Data Types

Nonstandard
Declarator
Short Form
Meaning
INTEGER*1
INTEGER(KIND=1)
INTEGER(1)
One-byte signed integers 
INTEGER*2
INTEGER(KIND=2)
INTEGER(2)
Two-byte signed integers 
INTEGER*4
INTEGER(KIND=4)
INTEGER(4)
Four-byte signed integers 
LOGICAL*1
LOGICAL(KIND=1)
LOGICAL(1)
One-byte logicals 
LOGICAL*2
LOGICAL(KIND=2)
LOGICAL(2)
Two-byte logicals 
LOGICAL*4
LOGICAL(KIND=4)
LOGICAL(4)
Four-byte logicals 
REAL*4
REAL(KIND=4)
REAL(4)
IEEE single-precision 
floating-point (Four-byte)
REAL*8
REAL(KIND=8)
REAL(8)
IEEE double-precision 
floating-point (Eight-byte)
COMPLEX*8
COMPLEX(KIND=4)
COMPLEX(4)
Single-precision complex 
(Four-bytes each part)
COMPLEX*16
COMPLEX(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.


Note - For release 1.2 of f90, INTEGER with KIND= 1, 2, or 4, are each 4 bytes long and align on 4-byte boundaries.

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 does not support them.

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

Its array declarator can appear in:


Note - Cray pointees can be of type character, but their Cray pointers are different from other Cray pointers. The two kinds cannot be mixed in the same expression.
Usage of Cray Pointers

Cray pointers can be assigned values as follows:

Example: q = 0

Example: p = q + 100

Example: p = LOC( x )

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:

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:


Note - The programmer responsible for preventing such association.
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-2 Nonstandard Intrinsics



Type




Name
Definition
Function
Arguments
Arguments
Remark
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:

Note
Meaning

P

The name can be passed as an argument.

NP

The name cannot be passed as an argument.

E

External code for the intrinsic is called at run time.

I

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.

General Directives

Currently there are only two general directives, FREE and FIXED. These directives tell the compiler to assume free-form source or fixed-form source.

Some other parallel directives are included which are not described in detail because they are not guaranteed to be in the next release.

Table  C-3 General Directives Guaranteed Only in the Current Release

Directive

TASK, NOTASK

SUPPRESS( var1, var2, ... )

TASKCOMMON( cb1, cb2, ... )

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

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

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.

Some other parallel directives are included which are not described in detail because they are not guaranteed to be in the next release.

Table  C-4 Parallel Directives Guaranteed Only in the Current Release

Directive

CASE, END CASE

PARALLEL, END PARALLEL

DO PARALLEL, END DO

GUARD, END GUARD

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

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.

However, this release of Fortran 90 (1.2) treats all source lines as if they were lowercase (except in quoted character strings. Unline f77, there is no -U option to force f90 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 diffentiated by case. The clue to potential problems would be the need to use -U with f77.

Executables

Libraries compiled and linked in FORTRAN 77 under Solaris 2.x run in the Fortran 4.2 environment.

Libraries

Example: f90 main and f77 subroutine.

demo% cat m.f90
CHARACTER*74 :: c = 'This is a test.'
   CALL echo1( c )
END
demo$ cat s.f
	SUBROUTINE echo1( a )
	CHARACTER*74 a
	PRINT*, a
	RETURN
	END
demo% f77 -c -silent s.f
demo% f90 m.f90 s.o
demo% a.out
 This is a test.
demo% 

Example: f90 main calls a routine from the libF77 library.

demo% cat tdtime.f90
        REAL e, dtime, t(2)
        e = dtime( t )
        DO i = 1, 10000
                k = k+1
        END DO
        e = dtime( t )
        PRINT *, 'elapsed:', e, ', user:', t(1), ', sys:', t(2)
        END
demo% f90 tdtime.f90
demo% a.out
 elapsed:6.405999884E-3, user:5.943499971E-3, sys:4.625000001E-4
demo% 

See dtime(3f).

I/O

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

Such compatibility includes the following two situations:

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

The numbers read back in do equal the numbers written out.

The numbers read back in can be different from the numbers written out. This is caused by slightly different base conversion routines, or by different conventions for uppercase/lowercase, spaces, plus or minus signs, and so forth.

Examples: 1.0e12, 1.0E12, 1.0E+12

The numbers read back in can be different from the numbers written out. This can be caused by various layout conventions with commas, spaces, zeros, repeat factors, and so forth.

Example: '0.0' as compared to '.0'

Example: ' 7' as compared to '7'

Example: '3, 4, 5' as compared to '3 4 5'

Example: '3*0' as compared to '0 0 0'

The above results are from: integer::v(3)=(/0,0,0/); print *,v

Example: '0.333333343' as compared to '0.333333'

The above results are from PRINT *, 1.0/3.0

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.

ADJUSTL
LEN_TRIM
SELECTED_INT_KIND
ADJUSTR
MAXEPONENT
SELECTED_REAL_KIND
ALLOCATED
MINEXPONENT
SET_EXPONENT
ASSOCIATED
NEAREST
SHAPE
BIT_SIZE
PRECISION
SIZE
DIGITS
PRESENT
SPACING
EPSILON
RADIX
TINY
EXPONENT
RANGE
TRANSFER
FRACTION
REPEAT
TRIM
HUGE
RRSPACING
UBOUND
KIND
SCALE
VERIFY
LBOUND
SCAN

The Fortran 90 standard supports the following new array intrinsic functions.

ALL
MAXLOC
RESHAPE
ANY
MAXVAL
SPREAD
COUNT
MERGE
SUM
CSHIFT
MINLOC
TRANSPOSE
DOT_PRODUCT
MINVAL
UNPACK
EOSHIFT
PACK

MATMUL
PRODUCT


Forward Compatibility

The next release of f90 is intended to be source code compatible with this release.

However, any libraries created with this release of f90, are not guaranteed to be compatible with the next release.


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 (.M file) in addition to the .o file.

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 .M files cannot be stored into an archive file. If you have many .M files in some directory, and you want to reduce the number of such files (to reduce clutter), you can concatenate them into one large .M file.


Previous Next Contents Index Doc Set Home