C H A P T E R 4 |
Fortran 95 Features and Differences |
This appendix shows some of the major features differences between standard Fortran 95 and Forte Developer Fortran 95.
Forte Developer Fortran 95 compiler provides the following source langauge features and extensions to the Fortran 95 standard.
f95 allows 99 continuation lines (1 initial and 99 continuation lines). Standard Fortran 95 allows 19 for fixed-form and 39 for free-form.
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.
Tabs in f95 force the rest of the line to be padded out to column 72. This may cause unexpected results if the tab appears within a character string that is continued onto the next line:
^Iprint *, "Tab on next line ^I1this continuation line starts with a tab." ^Iend Tab on next line this continuation line starts with a tab. |
The source form assumed by f95 depends on options, directives, and suffixes.
Files with a .f or .F suffix are assumed to be in fixed format. Files with a .f90, .f95, .F90, or .F95 suffix are assumed to be in free format.
If the -free or -fixed option is used, it overrides the file name suffix. If either a !DIR$ FREE or !DIR$ FIXED directive is used, it overrides the option and file name suffix.
Some mixing of source forms is allowed.
Sun Fortran 95 is case insensitive by default. That means that a variable AbcDeF is treated as if it were spelled abcdef. Compile with the -U option 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.
f95 supports constants and expressions of Boolean type. There are no Boolean variables or arrays, and there is no Boolean type statement.
f95 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.
ddddddB, where d is any octal digit
Within an I/O format specification, the letter B indicates binary digits; elsewhere it indicates octal digits.
X'ddd' or X"ddd", where d is any hexadecimal digit
Accepted forms for Hollerith data are:
Above, "..." is a string of characters and n is the character count.
Examples: Octal and hexadecimal constants.
Examples: Octal and hexadecimal in assignment statements.
Use of an octal or hexadecimal constant in an arithmetic expression can produce undefined results and do not generate syntax errors.
f95 allows BOZ constants in the places other than DATA statements.
If these are assigned to a real variable, no type conversion occurs.
Standard Fortran allows these only in DATA statements.
f95 allows the following nonstandard type declaration forms in declaration statements, function statements, and IMPLICIT statements. The form in column one is nonstandard Fortran 95, though in common use. The kind numbers in column two can vary by vendor.
Storage and alignment are always given in bytes. Values that can fit into a single byte are byte-aligned.
The size and alignment of types depends on various compiler options and platforms, and how variables are declared. The default maximum alignment in COMMON blocks is to 4-byte boundaries.
Default data alignment and storage allocation can be changed by compiling with special options, such as -aligncommon, -f, -dalign, -dbl_align_all, -xmemalign,, and -xtypemap. The default descriptions in this manual assume that these options are not in force.
The following table summarizes the default size and alignment, ignoring other aspects of types and options.
Options -f or -dalign force alignment of all 8, 16, or 32-byte data onto 8-byte boundaries. Option -dbl_align_all causes all data to be aligned on 8-byte boundaries. Programs that depend on the use of these options may not be portable.
A Cray pointer is a variable whose value is the address of another entity, called the pointee.
f95 supports Cray pointers; Standard Fortran 95 does not.
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:
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.
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 are declared as follows:
POINTER ( pointer_name, pointee_name [array_spec] )
Fortran 95 pointers are declared as follows:
The two kinds of pointers cannot be mixed.
Cray pointers can be assigned values as follows:
Example: Use Cray pointers as described above.
Remarks about the above example:
Recent decisions by the Fortran 95 standards organizations have extended the data entities allowed for the ALLOCATABLE attribute. Previously this attribute was limited to locally stored array variables. It is now allowed with:
Allocatable entities remain forbidden in all places where they may be storage-associated: COMMON blocks and EQUIVALENCE statements. Allocatable array components may appear in SEQUENCE types, but objects of such types are then prohibited from COMMON and EQUIVALENCE.
The f95 compiler recognizes the VALUE type declaration attribute. This attribute has been proposed for the Fortran 2000 standard.
Specifying a subprogram dummy input argument with this attribute indicates that the actual argument is passed "by value". The following example demonstrates the use of the VALUE attribute with a C main program calling a Fortran 95 subprogram with a literal value as an argument:
C code: #include <stdlib.h> int main(int ac, char *av[]) { to_fortran(2); } Fortran code: subroutine to_fortran(i) integer, value :: i print *, i end |
A new "stream" I/O scheme has been proposed as part of the Fortran 2000 draft standard. Stream I/O access treats a data file as a continuous sequence of bytes, addressable by a positive integer starting from 1. Declare a stream I/O file with the ACCESS='STREAM' specifier on the OPEN statement. File positioning to a byte address requires a POS=scalar_integer_expression specifier on a READ or WRITE statement. The INQUIRE statement accepts ACCESS='STREAM', a specifier STREAM=scalar_character_variable, and POS=scalar_integer_variable.
Three new Fortran 2000 formatted I/O specifiers have been implemented in f95. They may appear on OPEN, READ, WRITE, PRINT, and INQUIRE statements:
When used in INQUIRE statements, these specifiers declare a character variable for returning the current values.
New edit descriptors DP, DC, RP, and RC change the defaults within a single FORMAT statement to decimal point, decimal comma, processor-defined rounding, and compatible rounding respectively. For example:
prints a comma instead of a period in the F10.3 output item.
See also the -iorounding compiler command-line option for changing the floating-point rounding modes on formatted I/O. (-iorounding=mode.)
To aid the migration of programs from f77, f95 accepts VAX Fortran STRUCTURE and UNION statements, a precursor to the "derived types" in Fortran 95. For syntax details see the FORTRAN 77 Language Reference manual.
The field declarations within a STRUCTURE can be one of the following:
As with f77, a POINTER statement cannot be used as a field declaration.
Some I/O extensions that appeared in Forte Developer Fortran 77 are now part of the Fortran 95 compiler:
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 parallelization directives are the default with f95 -explicitpar. To switch to Cray-style directives, use the -mp=cray compiler command-line flag. Explicit parallelization with OpenMP directives requires compiling with -openmp.
A complete summary of Fortran directives appears in Appendix D.
f95 recognizes its own special directives in addition to those described in Chapter 2. These have the following syntax:
!DIR$ d1, d2, ... |
The !DIR$ characters are the first nonblank characters in the line (actually, non-whitespace).
Thus, !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 FREE or FIXED directive is encountered.
!DIR$ FREE DO i = 1, n a(i) = b(i) * c(i) END DO |
A parallelization directive is a special comment that directs the compiler to attempt to parallelize the next DO loop. These are summarized in Appendix D and described in the chapter on parallelization in the Fortran Programming Guide. f95 recognizes both Sun and Cray style parallelization directives, as well as the OpenMP Fortran API directives. OpenMP parallelization is described in the Forte Developer OpenMP API User's Guide.
Compiling a file containing a Fortran 95 MODULE generates a module interface 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.
Compilation also generates a .o module implementation object file for the source file containing the MODULE statements. Link with the module implementation object file along with the all other object files to create an executable.
The compiler creates module interface files and implementation object files in the directory specified by the -moddir=dir flag or the MODDIR evironment variable. If not specified, the compiler writes .mod files in the current working directory.
The compiler looks in the current working directory for the interface files when compiling USE modulename statements. The -Mpath option allows you to give the compiler an additional path to search. Module implementation object files must be listed explicitly on the command line for the link step.
Typically, programmers define one MODULE per file and assign the same name to the MODULE and the source file containing it. However, this is not a requirement.
In this example, all the files are compiled at once. The module source files appear first before their use in the main program.
demo% cat mod_one.f90 MODULE one ... END MODULE demo% cat mod_two.f90 MODULE two ... END MODULE demo% cat main.f90 USE one USE two ... END demo% f95 -o main mod_one.f90 mod_two.f90 main.f90 |
Compilation creates the files:
The next example compiles each unit separately and links them together.
demo% f95 -c mod_one.f90 mod_two.f90 demo% f95 -c main.f90 demo% f95 -o main main.o mod_one.o mod_two.o |
When compiling main.f90, the compiler searches the current directory for one.mod and two.mod. These must be compiled before compiling any files that reference the modules on USE statements. The link step requires the module implementation object files mod_one.o and mod_two.o appear along with all other object files to create the executable.
With the release of the Forte Developer 7 Fortran 95 compiler, .mod files can be stored into an archive (.a) file. An archive must be explicitly specified in a -Mpath flag on the command line for it to be searched for modules. The compiler does not search archive files by default.
Only .mod files with the same names that appear on USE statements will be searched. For example, the Fortran 95 statement USE mymod causes the compiler to search for the module file mymod.mod by default.
While searching, the compiler gives higher priority to the directory where the module files are being written. This can be controlled by the -moddir=dir option flag and the MODDIR environment variable. This implies that if only the -Mpath option is specified, the current directory will be searched for modules first, before the directories and files listed on the -M flag.
The -use=list flag forces one or more implicit USE statements into each subprogram or module subprogram compiled with this flag. By using the flag, it is not necessary to modify source programs when a module or module file is required for some feature of a library or application.
Compiling with -use=module_name has the effect of adding a USE module_name to each subprogram or module being compiled. Compiling with -use=module_file_name has the effect of adding a USE module_name for each of the modules contained in the module_file_name file.
Use the fdumpmod(1) command to display information about the contents of a module information file.
demo% fdumpmod mods.mod GROUP v8 version 0.16 mods.mod X v8 version 0.16 mods.mod |
The dumpmod command will display information about modules in a single .mod file, files formed by concatenating .mod files, and in .a archives of .mod files. The display includes the name of the module, the target architecture, and a version number. See the fdumpmod(1) man page for details.
f95 supports some intrinsic procedures that are extensions beyond the standard.
See the Fortran Library Reference for a more complete discussion of intrinsics, including those from Fortran 77 that are recognized by the Fortran 95 compiler.
Future releases of f95 are intended to be source code compatible with this release.
Module information files generated by this release of f95 are 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.See the C-Fortran Interface chapter in the Fortran Programming Guide for details on how to interoperate between C and Fortran routines.
Copyright © 2002, Sun Microsystems, Inc. All rights reserved.