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.


4.1 Language Features and Extensions

Forte Developer Fortran 95 compiler provides the following source langauge features and extensions to the Fortran 95 standard.

4.1.1 Continuation Line Limits

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

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

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:

Source file:

^Iprint *, "Tab on next line 
^I1this  continuation line starts with a tab."
^Iend

Running the code:

Tab on next line                                             this  continuation 
 line starts with a tab.

4.1.3 Source Form Assumed

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.

TABLE 4-1 F95 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, 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.

4.1.3.1 Mixing Forms

Some mixing of source forms is allowed.

  • In the same f95 command, some source files can be fixed form, some free.
  • In the same file, free form can be mixed with fixed form by using !DIR$ FREE and !DIR$ FIXED directives.

4.1.3.2 Case

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.

4.1.4 Known Limits

A single Fortran 95 program unit can define up to 65,535 derived types and 16,777,215 distinct constants.

4.1.5 Boolean Type

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

4.1.5.1 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 LOGICAL statement, but no BOOLEAN statement.
    • A logical variable, constant, or expression represents only two values, .TRUE. or .FALSE. A Boolean variable, constant, or expression can represent any binary value.
    • Logical entities are invalid in arithmetic, relational, or bitwise logical expressions. Boolean entities are valid in all three.

4.1.5.2 Alternate Forms of Boolean Constants

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.

Octal

ddddddB, where d is any octal digit

  • You can use the letter B or b.
  • 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 B indicates binary digits; elsewhere it indicates octal digits.

Hexadecimal

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

  • There can be 1 to 8 hexadecimal digits (0 through 9, A-F).
  • Any of the letters can be uppercase or lowercase (X, x, A-F, a-f).
  • 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.
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.

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

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.

4.1.5.3 Alternate Contexts of Boolean Constants

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

4.1.6 Abbreviated Size Notation for Numeric Data Types

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.

TABLE 4-2 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 four-byte floating-point

REAL*8

REAL(KIND=8)

REAL(8)

IEEE double-precision eight-byte floating-point

REAL*16

REAL(KIND=16)

REAL(16)

IEEE quad-precision sixteen-byte floating-point

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)

COMPLEX*32

COMPLEX(KIND=16)

COMPLEX(16)

Quad-precision complex (sixteen bytes each part)


4.1.7 Size and Alignment of Data Types

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.

TABLE 4-3 Default Data Sizes and Alignments (in Bytes)

Fortran 95 Data Type

Size

Default
Alignment

Alignment in
COMMON

BYTE X

CHARACTER X

CHARACTER*n X

1

1

n

1

1

1

1

1

1

COMPLEX X

COMPLEX*8 X

DOUBLE COMPLEX X

COMPLEX*16 X

COMPLEX*32 X

8

8

16

16

32

4

4

8

8

8/16

4

4

4

4

4

DOUBLE PRECISION X

REAL X

REAL*4 X

REAL*8 X

REAL*16 X

8

4

4

8

16

8

4

4

8

8/16

4

4

4

4

4

INTEGER X

INTEGER*2 X

INTEGER*4 X

INTEGER*8 X

4

2

4

8

4

2

4

8

4

2

4

4

LOGICAL X

LOGICAL*1 X

LOGICAL*2 X

LOGICAL*4 X

LOGICAL*8 X

4

1

2

4

8

4

1

2

4

8

4

1

2

4

4


Note the following:

  • REAL*16 and COMPLEX*32: in 64-bit environments (compiling with -xarch=v9 or v9a) the default alignment is on 16-byte (rather than 8-byte) boundaries, as indicated by 8/16 in the table.
  • Arrays and structures align according to their elements or fields. An array aligns the same as the array element. A structure aligns the same as the field with the widest alignment.

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.

4.1.8 Cray Pointers

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.

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


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.

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

4.1.8.3 Cray Pointers and Fortran 95 Pointers

Cray pointers are declared as follows:

POINTER ( pointer_name, pointee_name [array_spec] )

Fortran 95 pointers are declared as follows:

POINTER object_name

The two kinds of pointers cannot be mixed.

4.1.8.4 Features of Cray Pointers

  • Whenever the pointee is referenced, f95 uses 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 on 32-bit processors, and two storage units on 64-bit SPARC V9 processors.
  • The Cray pointer can appear in a COMMON list 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:
    • A separate type statement
    • A separate DIMENSION statement
    • The pointer statement itself
  • If the array declarator is in a subprogram, the dimensioning can refer to:
    • Variables in a common block, or
    • Variables that are dummy arguments
  • The size of each dimension is evaluated on entrance to the subprogram, not when the pointee is referenced.

4.1.8.5 Restrictions on Cray Pointers

  • pointee_name must not be a variable typed CHARACTER*(*).
  • 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:
    • A PARAMETER statement or in a type declaration statement that includes the PARAMETER attribute.
    • A DATA statement.

4.1.8.6 Restrictions on Cray Pointees

  • A Cray pointee cannot appear in a SAVE, DATA, EQUIVALENCE, COMMON, or PARAMETER statement.
  • 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.

4.1.8.7 Usage of Cray Pointers

Cray pointers can be assigned values as follows:

  • Set to an absolute address
Example: q = 0
  • Assigned to or from integer variables, plus or minus expressions
Example: p = q + 100
  • Cray pointers are not integers. You cannot assign them to a real variable.
  • The LOC function (nonstandard) can be used to define a Cray pointer.
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 + 4000
	ic = ib + n
	...

Remarks about the above example:

  • word64 refers to the contents of absolute address 64
  • blk is an array that occupies the first 128 words of memory
  • a is an array of length 1000 located in blank common
  • b follows a and is of length n
  • c follows b
  • a, b, and c are associated with pool
  • word64 is the same as blk(17) because Cray pointers are byte address and the integer elements of blk are each 4 bytes long

4.1.9 Other Language Extensions

4.1.9.1 Extended ALLOCATABLE Attribute

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:

  • array components of structures
  • dummy arrays
  • array function results

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.

4.1.9.2 VALUE Attribute (Fortran 2000)

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

4.1.9.3 Stream I/O (Fortran 2000)

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.

4.1.9.4 Formatted I/O Features From Fortran 2000

Three new Fortran 2000 formatted I/O specifiers have been implemented in f95. They may appear on OPEN, READ, WRITE, PRINT, and INQUIRE statements:

  • DECIMAL=['POINT'|'COMMA']
Change the default decimal editing mode. The default uses a period to separate the whole number and decimal parts of a floating-point number formatted with D, E, EN, ES, F, and G editing. 'COMMA' changes the default to use comma instead of a period, to print, for example, 123,456. The default is 'POINT', which uses a period, to print, for example, 123.456.
  • ROUND=['PROCESSOR_DEFINED' | 'COMPATIBLE']
Set the default rounding mode for formatted I/O D, E, EN, ES, F, and G editing. With 'COMPATIBLE', the value resulting from data conversion is the one closer to the two nearest represetnations, or the value away from zero if the value is halfway between them. With 'PROCESSOR_DEFINED', the rounding mode is dependent on the processor's default mode, and is the compiler default if ROUND is not specified.
As an example, WRITE(*,'(f11.4)') 0.11115 prints 0.1111 in default mode, and 0.1112 in 'COMPATIBLE' mode.
  • IOMSG=character-variable
Returns an error message as a string in the specified character variable. This is the same error message that would appear on standard output. Users should allocated a character buffer large enough to hold the longest message. (CHARACTER*256 should be sufficient.)

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:

WRITE(*,'(I5,DC,F10.3)') N, W

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

4.1.9.5 STRUCTURE and UNION (VAX Fortran)

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:

  • A substructure -- either another STRUCTURE declaration, or a record that has been previously defined.
  • A UNION declaration.
  • A TYPE declaration, which can include initial values.
  • A derived type having the SEQUENCE attribute. (This is particular to f95 only.)

As with f77, a POINTER statement cannot be used as a field declaration.

f95 also allows:

  • Either `.' or `%' can be used as a structure field dereference symbol:
    struct.field or struct%field.
  • Structures can appear in a formatted I/O statement.
  • Structures can be initialized in a PARAMETER statement; the format is the same as a derived type initialization.
  • Structures can appear as components in a derived type, but the derived type must be declared with the SEQUENCE attribute.

4.1.10 I/O Extensions

Some I/O extensions that appeared in Forte Developer Fortran 77 are now part of the Fortran 95 compiler:

  • NAMELIST Input Format:
The group name may be preceded by $ or & on input. The & is the only form accepted by the Fortran 95 standard, and is what is written by NAMELIST output.
Accepts $ as the symbol terminating input except if the last data item in the group is CHARACTER data, 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 BACKSPACE a FORM='BINARY' file, because there is no way of telling where to backspace to. A READ on a 'BINARY' file will read as much data as needed to fill the variables on the input list.
    • WRITE statement: Data is written to the file in binary, with as many bytes transferred as specified by the output list.
    • READ statement: 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.
    • INQUIRE statement: INQUIRE on a file opened with FORM="BINARY" returns:
FORM="BINARY"
ACCESS="SEQUENTIAL"
DIRECT="NO"
FORMATTED="NO"
UNFORMATTED="YES"
RECL= AND NEXTREC=
are undefined
    • BACKSPACE statement: Not allowed--returns an error.
    • ENDFILE statement: Truncates file at current position, as usual.
    • REWIND statement: Repositions file to beginning of data, as usual.
  • Recursive I/O possible on different units (this is because the f95 I/O library is "MT-Warm").
  • RECL=2147483646 (231-2) is the default record length on sequential formatted, list directed, and namelist output.
  • ENCODE and DECODE are recognized and implemented as described in the FORTRAN 77 Language Reference Manual.
  • Non-advancing I/O is enabled with ADVANCE='NO', as in:
write(*,'(a)',ADVANCE='NO') 'n= '
read(*,*) n


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

4.2.1 Form of Special f95 Directive Lines

f95 recognizes its own special directives in addition to those described in Chapter 2. These have the following syntax:

!DIR$ d1, d2, ...

4.2.1.1 Fixed-Form Source

  • Put CDIR$ or !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.

4.2.1.2 Free-Form Source

  • Put !DIR$ followed by a space anywhere in the line.

The !DIR$ characters are the first nonblank characters in the line (actually, non-whitespace).

  • Directives are listed after the space.
  • An initial directive line has a blank, tab, or newline in the position immediately after the !DIR$.
  • A continuation directive line has a character other than a blank, tab, or newline in the position immediately after the !DIR$.

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

4.2.2 FIXED and FREE Directives

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

4.2.2.1 Scope

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

4.2.2.2 Uses

  • They allow you to switch source forms within a source file.
  • They allow you to switch source forms for an INCLUDE file. You insert the directive at the start of the INCLUDE file. After the INCLUDE file has been processed, the source form reverts back to the form being used prior to processing the INCLUDE file.

4.2.2.3 Restrictions

The FREE/FIXED directives:

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

Example: A FREE directive.

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

4.2.3 Parallelization Directives

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.


4.3 Module Files

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:

main
main.o
one.mod
mod_one.o
two.mod
mod_two.o

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.

4.3.1 Searching for Modules

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.

4.3.2 The -use=list Option 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.

4.3.3 The fdumpmod Command

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.


4.4 Intrinsics

f95 supports some intrinsic procedures that are extensions beyond the standard.

TABLE 4-4 Nonstandard Intrinsics

Name

Definition

Function Type

Argument Types

Arguments

Notes

COT

Cotangent

real

real

([X=]x)

P, E

DDIM

Positive difference

double precision

double precision

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

P, E

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:

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

f95 generates inline code for the intrinsic procedure.


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.


4.5 Forward Compatibility

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.


4.6 Mixing Languages

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.