|Fortran User's Guide|
Fortran 95 Features and Differences
This appendix shows some of the major features differences between:
Features and Extensions
Sun WorkShop 6 Fortran 95 provides the following features.
Continuation Line Limits
f77allow 99 continuation lines (1 initial and 98 continuation lines). Standard Fortran 95 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, but everything beyond column 73 is ignored. Standard Fortran 95 only allows 72-character lines.
f95allows directive lines starting with
C$OMP, or !
MIC$. For a summary of directives, see Appendix E. Standard Fortran 95 does not consider directives.
The tab form of
f95fixed-format source text is defined as follows:
- A tab in any of columns 1 through 6 makes the line as a tab form source line.
- A comment indicator or a statement number may precede the tab.
- If a tab is the first nonblank character, then:
- If the character after the tab is anything other than a nonzero digit, then the text following the tab is an initial line.
- If there is a nonzero digit after the first tab, the line is a continuation line. The text following the nonzero digit is the next part of the statement.
f95default maximum line length is 72 columns for fixed form and 132 for free form. Use the
-ecompiler option (page 55) to extend the lines in fixed-format source to 132 columns.
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, C9^IFORMAT(1X, A3,^I1 I3,^I2 F9.1 )^IEND ! Uses of tabsCHARACTER *3 A = 'A'INTEGER B = 2REAL C = 3.0WRITE(*,9) A, B, C9 FORMAT(1X, A3,1 I3,2 F9.1 )END
In the example above, "
" is a way of indicating the tab character, and the linestarting 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
f95depends on options, directives, and suffixes.
TABLE C-1 F95 Source Form Command-line options
Interpret all source files as Fortran fixed form
Interpret all source files as Fortran free form
-fixedoption is used, it overrides the file name suffix. If either a
FIXEDdirective is used, it overrides the option and file name suffix.
Some mixing of source forms is allowed.
- In the same
f95command, some source files can be fixed form, some free.
- In the same file, free form can be mixed with fixed form by using directives.
- In the same program unit, tab form can be mixed with free or fixed form.
Sun Fortran 95 is case insensitive by default. That means that a variable
AbcDeFis treated as if it were spelled
abcdef. Compile with the
-Uoption to have the compiler treat upper and lower case as unique.
A single Fortran 95 program unit can define up to 65,535 derived types and 16,777,215 distinct constants.
f95supports 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
- Masking--A bitwise logical expression has a Boolean result; each of its bits is the result of one or more logical operations on the corresponding bits of the operands.
- For binary arithmetic operators, and for relational operators:
- If one operand is Boolean, the operation is performed with no conversion.
- If both operands are Boolean, the operation is performed as if they were integers.
- No user-specified function can generate a Boolean result, although some (nonstandard) intrinsics can.
- Boolean and logical types differ as follows:
- Variables, arrays, and functions can be of logical type, but they cannot be Boolean type.
- There is a
LOGICALstatement, but no
- A logical variable or constant represents only one value. A Boolean constant can represent as many as 32 values.
- A logical expression yields one value. A Boolean expression can yield as many as 32 values.
- Logical entities are invalid in arithmetic, relational, or bitwise logical expressions. Boolean entities are valid in all three.
Alternate Forms of Boolean Constants
f95allows 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.
B, where d is any octal digit
- You can use the letter
- There can be 1 to 11 octal digits (0 through 7).
- 11 octal digits represent a full 32-bit word, with the leftmost digit allowed to be 0, 1, 2, or 3.
- Each octal digit specifies three bit values.
- The last (right most) digit specifies the content of the right most three bit positions (bits 29, 30, and 31).
- If less than 11 digits are present, the value is right-justified--it represents the right most bits of a word: bits n through 31. The other bits are 0.
- Blanks are ignored.
Within an I/O format specification, the letter
Bindicates binary digits; elsewhere it indicates octal digits.
", where d is any hexadecimal digit
- There can be 1 to 8 hexadecimal digits (0 through 9,
- Any of the letters can be uppercase or lowercase (
- The digits must be enclosed in either apostrophes or quotes.
- Blanks are ignored.
- The hexadecimal digits may be preceded by a + or - sign.
- 8 hexadecimal digits represent a full 32-bit word and the binary equivalents correspond to the contents of each bit position in the 32-bit word.
- If less than 8 digits are present, the value is right-justified--it represents the right most bits of a word: bits n through 31. The other bits are 0.
Above, "..." is a string of characters and n is the character count.
- A Hollerith constant is type Boolean.
- If any character constant is in a bitwise logical expression, the expression is evaluated as Hollerith.
- A Hollerith constant can have 1 to 4 characters.
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
If these are assigned to a real variable, no type conversion occurs.
Standard Fortran allows these only in
Abbreviated Size Notation for Numeric Data Types
f95allows the following nonstandard type declaration forms in declaration statements, function statements, and
TABLE C-2 Size Notation for Numeric Data Types
One-byte signed integers
Two-byte signed integers
Four-byte signed integers
IEEE single-precision floating-point (Four-byte)
IEEE double-precision floating-point (Eight-byte) REAL*16 REAL(KIND=16) REAL(16) IEEE quad-precision floating-point (Sixteen-byte)
Single-precision complex (Four-bytes each part)
Double-precision complex (Eight-bytes each part) COMPLEX*32 COMPLEX(KIND=16) COMPLEX(16) Quad-precision complex (Sixteen-bytes each part)
The form in column one is nonstandard Fortran 95, though in common use. The kind numbers in column two can vary by vendor.
A Cray pointer is a variable whose value is the address of another entity, which is called the pointee.
f95supports Cray pointers; Standard Fortran 95 does not.
Where pointer_name, pointee_name, and array_spec are as follows:
Pointer to the corresponding pointee_name. pointer_name contains the address of pointee_name. Must be: a scalar variable name (but not a derived type) 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 non-constant bounds), or assumed-size.
The above example declares Cray pointer
pand its pointee
b, and Cray pointer
qand its pointee
The above example declares Cray pointer
ixand its pointee
x; and declares
xto be an array of dimensions
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:
The two kinds of pointers cannot be mixed.
Features of Cray Pointers
- Whenever the pointee is referenced,
f95uses the current value of the pointer as the address of the pointee.
- The Cray pointer type statement declares both the pointer and the pointee.
- The Cray pointer is of type Cray pointer.
- The value of a Cray pointer occupies one storage unit. Its range of values depends on the size of memory for the machine in use.
- The Cray pointer can appear in a
COMMONlist or as a dummy argument.
- The Cray pointee has no address until the value of the Cray pointer is defined.
- If an array is named as a pointee, it is called a pointee array.
- Its array declarator can appear in:
- If the array declarator is in a subprogram, the dimensioning can refer to:
- The size of each dimension is evaluated on entrance to the subprogram, not when the pointee is referenced.
Restrictions on Cray Pointers
- pointee_name must not be a variable typed
- If pointee_name is an array declarator, it must be explicit shape, (constant or non-constant bounds), or assumed-size.
- An array of Cray pointers is not allowed.
- A Cray pointer cannot be:
- Pointed to by another Cray pointer or by a Fortran pointer.
- A component of a structure.
- Declared to be any other data type.
- A Cray pointer cannot appear in:
Restrictions on Cray Pointees
- A Cray pointee cannot appear in a
- A Cray pointee cannot be a dummy argument.
- A Cray pointee cannot be a function value.
- A Cray pointee cannot be a structure or a structure component.
- A Cray pointee cannot be of a derived type.
Usage of Cray Pointers
Cray pointers can be assigned values as follows:
q = 0
p = q + 100
- Cray pointers are not integers. You cannot assign them to a real variable.
LOCfunction (nonstandard) can be used to define a Cray pointer.
p = LOC( x )
Example: Use Cray pointers as described above.
SUBROUTINE sub ( n )COMMON pool(100000)INTEGER blk(128), word64REAL a(1000), b(n), c(100000-n-1000)POINTER ( pblk, blk ), (ia, a ), ( ib, b ), &( ic, c ), ( address, word64 )DATA address / 64 /pblk = 0ia = LOC( pool )ib = ia + 4000ic = ib + n...
Remarks about the above example:
word64refers to the contents of absolute address 64
blkis an array that occupies the first 128 words of memory
ais an array of length 1000 located in blank common
aand is of length
care associated with
word64is the same as
blk(17)because Cray pointers are byte address and the integer elements of
blkare each 4 bytes long
Optimization and Cray Pointers
For purposes of optimization,
f95assumes 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:
- A Cray pointer has two pointees, or
- Two Cray pointers are given the same value
Note The programmer is responsible for preventing such association.
These kinds of association are sometimes done deliberately, as in array equivalencing, but then results can differ depending on whether optimization is turned on or off.
chave the same pointer, assigning 2.0 to
cgives the same value to
bprints out as 2.0, even though it was assigned 1.0.
f95supports some intrinsic procedures which are extensions beyond the standard.
TABLE C-3 Nonstandard Intrinsics Name Definition Function Type Argument Types Arguments Notes
Cotangent real real ([X=]x) P, E
Positive difference double precision double precision ([X=]x,[Y=]y) P, E
Get the number of leading 0 bits integer Boolean, integer, real, or pointer ([I=]i) NP, I
Get the number of set bits integer Boolean, integer, real, or pointer ([I=]i) NP, I
Calculate bit population parity integer Boolean, integer, real, or pointer ([X=]x) NP, I
Notes on the above table: 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
f95generates inline code for the intrinsic procedure.
Some I/O extensions that appear in Sun Fortran 77 have been added to the Fortran 95 compiler:
- NAMELIST Input Format:
- The group name may be preceded by
&on input. The
&is the only form accepted by the Fortran 95 standard, and is what is written by NAMELIST output.
$as the symbol terminating input except if the last data item in the group is
CHARACTERdata, in which case the
$is treated as input data.
- Allows NAMELIST input to start in the first column of a record.
OPEN(...,FORM='BINARY')treats the file as binary data without record marks:
- Opening a file with
FORM='BINARY'has roughly the same effect as
FORM='UNFORMATTED', except that no record lengths are embedded in the file. Without this data, there is no way to tell where one record begins, or ends. Thus, it is impossible to
FORM='BINARY'file, because there is no way of telling where to backspace to. A
'BINARY'file will read as much data as needed to fill the variables on the input list.
WRITEstatement: Data is written to the file in binary, with as many bytes transferred as specified by the output list.
READstatement: Data is read into the variables on the input list, transferring as many bytes as required by the list. Because there are no record marks on the file, there will be no "end-of-record" error detection. The only errors detected are "end-of-file" or abnormal system errors.
INQUIREon a file opened with
RECL= AND NEXTREC=
BACKSPACEstatement: Not allowed--returns an error.
ENDFILEstatement: Truncates file at current position, as usual.
REWINDstatement: Repositions file to beginning of data, as usual.
- Recursive I/O possible on different units (this is because the
f95I/O library is "MT-Warm").
RECL=2147483646(231-2) is the default record length on sequential formatted, list directed, and namelist output.
DECODEare recognized and implemented as described in the FORTRAN 77 Language Reference Manual.
- Naming of scratch files is the same as with
- Non-advancing I/O is enabled with
ADVANCE='NO', as in:
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
f77). To switch to Cray-style directives, use the
-mp=craycompiler command-line flag.
A complete summary of Fortran directives appears in Appendix E.
Form of Special
!DIR$in columns 1 through 5.
- Directives are listed in columns 7 and beyond.
- Columns beyond 72 are ignored.
- An initial directive line has a blank in column 6.
- A continuation directive line has a nonblank in column 6.
!DIR$followed by a space anywhere in the line.
!DIR$characters are the first nonblank characters in the line
- Directives are listed after the space.
- An initial directive line has a blank, tab, or newline in the position immediately after the
- A continuation directive line has a character other than a blank, tab, or newline in the position immediately after the
!DIR$in columns 1 through 5 works for both free-form source and fixed-form source.
These directives specify the source form of lines following the directive line.
They apply to the rest of the file in which they appear, or until the next
FIXEDdirective is encountered.
- They allow you to switch source forms within a source file.
- They allow you to switch source forms for an
INCLUDEfile. You insert the directive at the start of the
INCLUDEfile. After the
INCLUDEfile has been processed, the source form reverts back to the form being used prior to processing the
- Each must appear alone on a compiler directive line (not continued).
- Each can appear anywhere in your source code. Other directives must appear within the program unit they affect.
A parallelization directive is a special comment that directs the compiler to attempt to parallelize the next DO loop. These are summarized in Appendix E and described in the Fortran Programming Guide.
f77Sun and Cray style parallelization directives, as well as the OpenMP Fortran API directives.
Note Fortran parallelization features require a Sun WorkShop HPC license.
Compatibility with FORTRAN 77
Standard-conforming, fixed-format (filename
.f) FORTRAN 77 source code is compatible with Sun Fortran 95. Use of non-standard extensions, such as VMS Fortran features, are not compatible and may not compile with Sun Fortran 95.
f77compiler allows up to 20 array subscripts while
f90only allows 7.
- To mix
f95object binaries, link with
libf77compat, and not with
libF77. For example, perform the link step with f95 even even if the main program is an
cat m.f95CHARACTER*74 :: c = 'This is a test.'CALL echo1( c )END
cat s.fSUBROUTINE echo1( a )CHARACTER*74 aPRINT*, aRETURNEND
f77 -c -silent s.f
f95 m.f95 s.o -lf77compat
a.outThis is a test.demo%
f95main calls a routine from the FORTRAN 77 library.
cat tdtime.f95REAL e, dtime, t(2)e = dtime( t )DO i = 1, 100000as = as + cos(sqrt(float(i)))END DOe = dtime( t )PRINT *, 'elapsed:', e, ', user:', t(1), ', sys:', t(2)END
a.outelapsed: 0.14 , user: 0.14 , sys: 0.0E+0demo%
f95are generally I/O compatible for binary I/O, since
f95links to the
Such compatibility includes the following two situations:
- In the same program, you can write some records in
f95, then read them in
f95program can write a file. Then an
f77program can read it.
The numbers read back in may or may not equal the numbers written out.
- Floating-point formatted
- 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.
- 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:
- Example: '0.333333343' as compared to '0.333333'
- The above results are from
The Fortran 95 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
EXTERNALstatement to make
f95use your function rather than the intrinsic one.
Fortran 95 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
Future releases of
f95are intended to be source code compatible with this release.
Module information files generated by this release of
f95are not guaranteed to be compatible with future releases.
On Solaris systems, routines written in C can be combined with Fortran programs, since these languages have common calling conventions.
Compiling a file containing a Fortran 95
MODULEgenerates a module file (
.modfile) for every
MODULEencountered in the source. The file name is derived from the name of the
xyz.mod(all lowercase) will be created for
By default, such files are usually sought in the current working directory. The
-Mdir option allows you to tell
f95to seek them in an additional location.
.modfiles cannot be stored into an archive file, or concatenated into a single file.
Sun Microsystems, Inc.
Copyright information. All rights reserved.
|Library | Contents | Previous | Next | Index|