HP Fortran for OpenVMS
User Manual


Previous Contents Index

1.3 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, enter:


$ 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, enter 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.4 Creating and Running a Program Using a Module and Separate Function

Example 1-2 shows a sample HP 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.4.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 enter 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.4.2 Running the Sample Program

If the current default directory contains the file named CALC you can run the program by entering 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.4.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, enter the following command:


$ RUN CALC_DEBUG

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

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

HP 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 describes some of the software tools you can use when developing (implementing) and testing a program:

Table 1-1 Tools for Program Development and Testing
Task or Activity Tool and Description
Manage source files Use the 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 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 HP 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:


Chapter 2
Compiling HP Fortran Programs

This chapter describes:

2.1 Functions of the Compiler

The primary functions of the HP Fortran compiler are to:

When the compiler creates an object file, it provides the linker with the following information:

For More Information:

On the OpenVMS Linker, see Chapter 3.

2.2 FORTRAN Command Syntax, Use, and Examples

The FORTRAN command initiates compilation of a source program.

The command has the following form:

FORTRAN [/qualifiers] file-spec-list[/qualifiers]

/qualifiers

Indicates either special actions to be performed by the compiler or special properties of input or output files.

file-spec-list

Specifies the source files containing the program units to be compiled. You can specify more than one source file:

When compiling source files with the default optimization (or additional optimizations), concatenating source files allows full interprocedure optimizations to occur.

In interactive mode, you can also enter the file specification on a separate line by entering the command FORTRAN, followed by a carriage return. The system responds with the following prompt:


 _File:

Enter the file specification immediately after the prompt and then press Return.

2.2.1 Specifying Input Files and Source Form

If you omit the file type on the FORTRAN command line, the compiler searches first for a file with a file type of F90. If a file with a file type of F90 is not found, it then searches for file with a file type of FOR and then F.

For example, the following FORTRAN command line shows how file type searching occurs:


$ FORTRAN PROJ_ABC

This FORTRAN command searches for the following files:

  1. It searches first for PROJ_ABC.F90.
  2. If PROJ_ABC.F90 does not exist, it then searches for PROJ_ABC.FOR.
  3. If PROJ_ABC.F90 and PROJ_ABC.FOR do not exist, it then searches for PROJ_ABC.F.

Indicate the Fortran 90 source form used in your source files by using certain file types or a command-line qualifier:

For example, if you specify a file as PROJ_BL1.F90 on an FORTRAN command line (and omit the /SOURCE_FORM=FIXED qualifier), the FORTRAN command assumes the file PROJ_BL1.F90 contains free-form source code.

2.2.2 Specifying Multiple Input Files

When you specify a list of input files on the FORTRAN command line, you can use abbreviated file specifications for those files that share common device names, directory names, or file names.

The system applies temporary file specification defaults to those files with incomplete specifications. The defaults applied to an incomplete file specification are based on the previous device name, directory name, or file name encountered in the list.

The following FORTRAN command line shows how temporary defaults are applied to a list of file specifications:


$ FORTRAN USR1:[ADAMS]T1,T2,[JACKSON]SUMMARY,USR3:[FINAL]

The preceding FORTRAN command compiles the following files:


USR1:[ADAMS]T1.F90 (or .FOR or .F) 
USR1:[ADAMS]T2.F90 (or .FOR  or .F) 
USR1:[JACKSON]SUMMARY.F90 (or .FOR or .F) 
USR3:[FINAL]SUMMARY.F90 (or .FOR or .F) 

To override a temporary default with your current default directory, specify the directory as a null value. For example:


$ FORTRAN [OMEGA]T1, []T2

The empty brackets indicate that the compiler is to use your current default directory to locate T2.

FORTRAN qualifiers typically apply to the entire FORTRAN command line. One exception is the /LIBRARY qualifier, which specifies that the file specification it follows is a text library (positional qualifier). The /LIBRARY qualifier is discussed in Section 2.3.27.

You can specify multiple files on the FORTRAN command line. You can separate the multiple source file specifications with:

If you use multiple FORTRAN commands to compile multiple HP Fortran source files that are linked together into the same program, you must be consistent when specifying any qualifiers that affect run-time results. For example, suppose you do the following:

  1. Specify /FLOAT=IEEE_FLOAT on one command line
  2. Specify /FLOAT=G_FLOAT on another command line
  3. Link the resulting object files together into a program

When you run the program, the values returned for floating-point numbers in a COMMON block will be unpredictable. For qualifiers related only to compile-time behavior (such as /LIST and /SHOW), this restriction does not apply.


Previous Next Contents Index