DIGITAL Fortran 90
User Manual for
DIGITAL UNIX Systems


Previous Contents Index


Chapter 1
Getting Started

DIGITAL Fortran 90 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 DIGITAL Fortran 90 may result in changes in future releases of the DIGITAL Fortran 90 compiler, even if the changes produce incompatibilities with earlier releases of DIGITAL Fortran 90.

DIGITAL Fortran 90 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.

DIGITAL Fortran 90 provides a number of extensions to the Fortran 90 Standard. DIGITAL Fortran 90 extensions to the Fortran 90 standard are generally provided for compatibility with DIGITAL 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 90 standard. Extensions to the Fortran 90 standard are identified visually in the DIGITAL Fortran Language Reference Manual, which defines the DIGITAL Fortran 90 language.

This chapter provides:

Note

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 DIGITAL Fortran 90 Programming Environment

The following aspects of Fortran 90 are relevant to the compilation environment and should be considered before extensive coding begins:

For More Information:

1.2 Commands to Create and Run an Executable Program

Example 1-1 shows a short Fortran 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 . For instance, to use vi to edit the file hello.f90 , type:


% vi hello.f90

The following f90 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 automatically passes a standard default list of DIGITAL UNIX and DIGITAL Fortran 90 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 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 not in your current directory path, specify the directory path in addition to the file name.

1.3 Creating and Running a Program Using a Module and Separate Function

Example 1-2 shows a sample Fortran 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 

  1. The USE statement accesses the module ARRAY_CALCULATOR. This module contains the function declaration for CALC_AVERAGE (use association).
  2. The 5-element array is passed to the function CALC_AVERAGE, which returns the value to the variable AVERAGE for printing.

Example 1-3 shows the module referenced by the main program. This example program shows more Fortran 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:

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:

1.3.2 Running the Sample Program

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

1.3.3 Debugging the Sample Program

To debug a program with the DIGITAL 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 DIGITAL UNIX Version 4.0, type the following command:


% ladebug calc_debug

The DIGITAL UNIX operating system provides the Ladebug debugger and the dbx debugger, both of which can be used to debug DIGITAL Fortran 90 programs.

For more information on running the program within the debugger, see Chapter 4.

1.4 The f90 Command and Related Software Components

DIGITAL Fortran 90 provides the standard features of a compiler and linker. DIGITAL Fortran 90 also supports the use of preprocessors and other compilers.

Compiling and linking are usually done by a single f90 command. The f90 command allows you to use:

1.4.1 The f90 Command Driver Program

The f90 command invokes a driver program that is the actual user interface to the DIGITAL Fortran 90 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 DIGITAL Fortran 90 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 compiler. The cc 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.


Previous Next Contents Index