Previous | Contents | Index |
Compaq Fortran conforms to American National Standard Fortran 90 (ANSI X3.198-1992)1 and includes support for the High Performance Fortran Language Specification.
The ANSI committee X3J3 is currently answering questions of interpretation of Fortran 90 language features. Any answers given by the ANSI committee that are related to features implemented in Compaq Fortran may result in changes in future releases of the Compaq Fortran compiler, even if the changes produce incompatibilities with earlier releases of Compaq Fortran.
Compaq Fortran also includes support for programs that conform to the previous Fortran standards (ANSI X3.9-1978 and ANSI X3.0-1966), the International Standards Organization standard ISO 1539-1980 (E), the Federal Information Processing Institute standard FIPS 69-1, and the Military Standard 1753 Language Specification.
Compaq Fortran provides a number of extensions to the Fortran 95/90 standards. Compaq Fortran extensions to the Fortran 95/90 standards are generally provided for compatibility with Compaq Fortran extensions to the ANSI FORTRAN-77 standard and to support the High Performance Fortran (HPF) Language Specification.2
When creating new programs that need to be standard-conforming for portability reasons, you should avoid or minimize the use of extensions to the Fortran 95/90 standards. Extensions to the Fortran 95/90 standards are identified visually in the Compaq Fortran Language Reference Manual, which defines the Compaq Fortran language.
1 This is the same as International Standards Organization standard ISO/IEC 1539:1991 (E).2 High Performance Fortran Language Specification, Version 1.1, Technical Report CRPC-TR-92225, Center for Research on Parallel Computation, Rice University, Houston, TX USA. |
1.1 The Compaq Fortran Programming Environment
The following aspects of Compaq Fortran are relevant to the compilation environment and should be considered before extensive coding begins:
% limit stacksize stacksize 4096 kbytes % limit stacksize 32676 % limit stacksize stacksize 32676 kbytes |
% limit stacksize unlimited |
$ ulimit -s 4096 $ ulimit -s 32676 $ ulimit -s 32676 |
% limit descriptor descriptors 100 files % limit descriptor 4096 % limit descriptor descriptors 4096 files |
$ ulimit -n 2048 $ ulimit -n 4096 $ ulimit -n 4096 |
Example 1-1 shows a short Fortran 95/90 main program using free form source.
Example 1-1 Sample Main Program |
---|
! File hello.f90 PROGRAM HELLO_TEST print *, 'hello world' print *, ' ' END PROGRAM HELLO_TEST |
To create and revise your source files, use a text editor, such as vi or emacs . On Linux systems, the peco editor is available. For instance, to use vi to edit the file hello.f90 , type:
% vi hello.f90 |
The following command compiles the program named hello.f90 and automatically uses ld to link the main program into an executable program file named a.out :
% f90 hello.f90 |
The f90 command (or on Linux systems, the fort command) automatically passes a standard default list of Compaq Tru64 UNIX and Compaq Fortran libraries to the ld linker. In this example, because all external routines used by this program reside in these standard libraries, additional libraries or object files are not specified on the f90 (or fort ) command line.
If your path definition includes the directory containing a.out , you can run the program by simply typing its name:
% a.out |
If the executable image is in your current directory, specify:
% ./a.out |
If the executable image is not in a directory in your path definition and it is not in your current directory, then specify its full path. For example:
% /usr/disk5/mcdonald/a.out |
Example 1-2 shows a sample Fortran 95/90 main program using free source form that uses a module and an external subprogram.
The function CALC_AVERAGE is contained in a separately created file and depends on the module ARRAY_CALCULATOR for its interface block.
Example 1-2 Sample Main Program that Uses a Module and Separate Function |
---|
! File: main.f90 ! This program calculates the average of five numbers PROGRAM MAIN USE ARRAY_CALCULATOR (1) REAL, DIMENSION(5) :: A = 0 REAL :: AVERAGE PRINT *, 'Type five numbers: ' READ (*,'(F10.3)') A AVERAGE = CALC_AVERAGE(A) (2) PRINT *, 'Average of the five numbers is: ', AVERAGE END PROGRAM MAIN |
Example 1-3 shows the module referenced by the main program. This example program shows more Fortran 95/90 features, including an interface block and an assumed-shape array.
Example 1-3 Sample Module |
---|
! File: array_calc.f90. ! Module containing various calculations on arrays. MODULE ARRAY_CALCULATOR INTERFACE FUNCTION CALC_AVERAGE(D) REAL :: CALC_AVERAGE REAL, INTENT(IN) :: D(:) END FUNCTION CALC_AVERAGE END INTERFACE ! Other subprogram interfaces... END MODULE ARRAY_CALCULATOR |
Example 1-4 shows the function declaration CALC_AVERAGE referenced by the main program.
Example 1-4 Sample Separate Function Declaration |
---|
! File: calc_aver.f90. ! External function returning average of array. FUNCTION CALC_AVERAGE(D) REAL :: CALC_AVERAGE REAL, INTENT(IN) :: D(:) CALC_AVERAGE = SUM(D) / UBOUND(D, DIM = 1) END FUNCTION CALC_AVERAGE |
1.3.1 Commands to Create the Executable Program
During the early stages of program development, the three sample
program files might be compiled separately and then linked together,
using the following commands:
% f90 -c array_calc.f90 % f90 -c calc_aver.f90 % f90 -c main.f90 % f90 -o calc main.o array_calc.o calc_aver.o |
In this sequence of f90 commands (or on a Linux system, fort commands):
To allow more optimizations to occur (such as the inline expansion of called subprograms), the entire set of three source files can be compiled and linked together with a single f90 command:
% f90 -o calc array_calc.f90 calc_aver.f90 main.f90 |
The order in which the file names are specified is significant. This f90 command:
If your path definition includes the directory containing calc , you can run the program by simply typing its name:
% calc |
When running the sample program, the PRINT and READ statements in the main program result in the following dialogue between user and program:
Type five numbers: 55.5 4.5 3.9 9.0 5.6 Average of the five numbers is: 15.70000 |
To debug a program with the Compaq Ladebug Debugger, compile the source files with the -g and -ladebug options to request additional symbol table information for source line debugging in the object and executable program files. The following f90 command also uses the -o option to name the executable program file calc_debug :
% f90 -g -ladebug -o calc_debug array_calc.f90 calc_aver.f90 main.f90 |
The Ladebug debugger has a character-cell interface ( ladebug command) and a windowing interface.
For instance, to use the character-cell interface to debug an executable program named calc_debug on a system running Compaq Tru64 UNIX, type the following command:
% ladebug calc_debug |
The Compaq Tru64 UNIX operating system provides the Ladebug debugger and the dbx debugger, both of which can be used to debug Compaq Fortran programs. On Linux Alpha systems, the Compaq Fortran CD-ROM includes the Ladebug debugger. You can also download it from the Web site whose URL is http://www.compaq.com/linux.
For more information on running the program within the debugger, see
Chapter 4.
1.4 The f90 or fort Command and Related Software Components
Compaq Fortran provides the standard features of a compiler and linker. Compaq Fortran also supports the use of preprocessors and other compilers.
Compiling and linking are usually done by a single f90 or fort command. The f90 or fort command allows you to use:
The f90 or fort command invokes a driver program that is the actual user interface to the Compaq Fortran compiler. It accepts a list of command options and file names, and causes one or more programs (preprocessor, compiler, assembler, or linker) to process each file.
After the Compaq Fortran compiler processes the appropriate files to create one or more object files, the driver program passes a list of files, certain options, and other information to the cc or ccc compiler. The cc or ccc compiler processes relevant non-Fortran files and information (including running cpp ) and passes certain information (such as .o object files) to the ld linker.
The f90 command executes each related program (preprocessor, compiler, assembler, or linker) in a sequential manner. If the cpp preprocessor is used, cpp is executed once for each file.
If any processor does not return a normal status, further processing is
discontinued and the
f90
command displays a message identifying the program (and its returned
status, in hexadecimal) before terminating its own execution.
1.4.2 cpp and Other Preprocessors
When you use a preprocessor for Compaq Fortran source files, the output files the preprocessor creates are used as input source files by the Compaq Fortran compiler. Preprocessors include:
When the
f90
or
fort
command driver passes object and other files to the C compiler, the
cc
or
ccc
command applies the
cpp
preprocessor to files that it recognizes, such as any file with a
.c
suffix.
1.4.3 Compaq Fortran Compiler
The Compaq Fortran compiler provides the following primary functions:
The object file created by the compiler contains information used by the linker, including the following:
The file name of the Compaq Fortran compiler is decfort90 , which may appear in certain messages.
Previous | Next | Contents | Index |