Compaq Fortran
User Manual for
OpenVMS Alpha Systems


Previous Contents Index


Chapter 1
Getting Started

Compaq Fortran (formerly DEC Fortran 90 and DIGITAL Fortran 90) conforms to:

Compaq Fortran supports all of the deleted features of the Fortran 95 standard.

Compaq Fortran also includes partial support for the High Performance Fortran Language Specification.

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.

The ANSI committee X3J3 is currently answering questions of interpretation of Fortran 90 ands 95 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 provides a number of extensions to the Fortran 90 and 95 standards. Compaq Fortran extensions to the latest Fortran standard are generally provided for compatibility with Compaq Fortran 77 extensions to the ANSI FORTRAN-77 standard.

When creating new programs that need to be standard-conforming for portability reasons, you should avoid or minimize the use of extensions to the latest Fortran standard. Extensions to the appropriate Fortran standard are identified visually in the Compaq Fortran Language Reference Manual, which defines the Compaq Fortran language.

This chapter provides information on the following topics:

1.1 The Compaq Fortran Programming Environment

The following aspects of Fortran 90/95 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/95 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 the Extensible Versatile Editor (EVE). For instance, to use EVE to edit the file HELLO.F90, type:


$ EDIT HELLO.F90

The following FORTRAN command compiles the program named HELLO.F90. The LINK command links the compiled object file into an executable program file named HELLO.EXE:


$ FORTRAN HELLO.F90
$ LINK HELLO

In this example, because all external routines used by this program reside in standard OpenVMS libraries searched by the LINK command, additional libraries or object files are not specified on the LINK command line.

To run the program, type the RUN command and the program name:


$ RUN HELLO

If the executable program is not in your current default directory, specify the directory before the file name. Similarly, if the executable program resides on a different device than your current default device, specify the device name and directory name before the file name.

For More Information:

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

Example 1-2 shows a sample Compaq Fortran main program using free-form source 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  (*,'(BN,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 files might be compiled separately and then linked together, using the following commands:


$ FORTRAN ARRAY_CALC.F90
$ FORTRAN CALC_AVER.F90
$ FORTRAN MAIN.F90
$ LINK/EXECUTABLE=CALC.EXE MAIN, ARRAY_CALC, CALC_AVER

In this sequence of FORTRAN commands:

To allow more optimizations to occur (such as the inline expansion of called subprograms), compile the entire set of three source files together using a single FORTRAN command:


$ FORTRAN/OBJECT=CALC.OBJ ARRAY_CALC.F90 + CALC_AVER.F90 + MAIN.F90

The order in which the file names are specified is significant. This FORTRAN command:

When you omit the file type on the FORTRAN command line, the FORTRAN command searches for a file with the F90 file type before a file with the FOR or F file type, so you can type the previous command (without file types) as follows:


$ FORTRAN/OBJECT=CALC.OBJ ARRAY_CALC + CALC_AVER + MAIN

Use a LINK command to link the single object file into an executable program:


$ LINK CALC

When you omit the file type on the LINK command line, the Linker searches for a file with a file type of OBJ. Unless you will specify a library on the LINK command line, you can omit the OBJ file type.

1.3.2 Running the Sample Program

If the current default directory contains the file named CALC you can run the program by typing the RUN command followed by its name:


$ RUN CALC

When you omit the file type on the RUN command line, the image activator searches for a file with a file type of EXE (you can omit the EXE file type).

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 using the OpenVMS Debugger, compile and link with the /DEBUG qualifier to request additional symbol table information for source line debugging in the object and executable program files. The following FORTRAN command names the object file CALC_DEBUG.OBJ. The LINK command then creates the program file CALC_DEBUG.EXE with full debugging information:


$ FORTRAN/DEBUG/OBJECT=CALC_DEBUG.OBJ/NOOPTIMIZE ARRAY_CALC + CALC_AVER + MAIN
$ LINK/DEBUG CALC_DEBUG

The OpenVMS debugger has a character-cell interface and a windowing interface (available with the DECwindows Motif product). To debug an executable program named CALC_DEBUG.EXE, type the following command:


$ RUN CALC_DEBUG

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

1.4 Program Development Stages and Tools

This manual primarily addresses the program development activities associated with implementation and testing phases. For information about topics usually considered during application design, specification, and maintenance, see your operating system documentation or appropriate commercially published documentation.

Compaq Fortran provides the standard features of a compiler and the OpenVMS operating system provides a linker.

Use a LINK command to link the object file into an executable program.

Table 1-1 lists and describes some of the software tools you can use when developing (implementing) and testing a program:

Table 1-1 Main Tools for Program Development and Testing
Task or Activity Tool and Description
Manage source files Use the Compaq Code Management System (CMS).
Create and modify source files Use a text editor, such as the EDIT command to use the EVE editor. You can also use the optional Language-Sensitive Editor (LSE). For more information using OpenVMS text editors, see the OpenVMS User's Manual.
Analyze source code Use DCL commands such as SEARCH and DIFFERENCES.
Build program (compile and link) You can use the FORTRAN and LINK commands to create small programs, perhaps using command procedures, or use the Compaq Module Management System (MMS) to build your application in an automated fashion.

For more information on the FORTRAN and LINK commands, see Chapter 2 and Chapter 3 respectively.

Debug and Test program Use the OpenVMS Debugger to debug your program or run it for general testing. For more information on the OpenVMS Debugger, see Chapter 4 in this manual.
Analyze performance To perform program timings and profiling of code, use the LIB$ xxxx_TIMER routines, a command procedure, or the Performance Coverage Analyzer (PCA).

For more information on timing and profiling Compaq Fortran code, see Chapter 5.

To perform other program development functions at various stages of program development, use the following DCL commands:

For More Information:


Previous Next Contents Index