HP 3000 Manuals

FORTRAN Vocabulary [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation


HP FORTRAN 77/iX Reference

FORTRAN Vocabulary 

A FORTRAN source file is composed of one or more program units.  Each of
the program units is constructed from characters grouped into lines and
statements.

Sample FORTRAN Source File 

Figure 1-1  shows a sample FORTRAN source file, consisting of one main
program unit (exone) and one subprogram unit (nfunc).  The line numbers
are shown for reference only and do not appear in the source file.  The
definitions of the FORTRAN source file terms that follow refer to the
sample program in Figure 1-1 .
__________________________________________________________________________
|                                                                        |
|      1         $LIST ON                                                |
|      2               PROGRAM exone                                     |
|      3         C     This program shows program structure.             |
|      4         C     The purpose of the program is to compute          |
|      5         C     the sum of the first n integers using             |
|      6         C     a function subprogram unit.                       |
|      7         C                                                       |
|      8               INTEGER*4 sum,nfunc   ! Specification statement.  |
|      9         *                                                       |
|     10               WRITE(6,'('' Enter value-->'')')    ! Prompt user.|
|     11               READ *,n             ! Enter integer limit to sum.|
|     12         *     Compute sum in subprogram nfunc.                  |
|     13               sum=nfunc(n)         ! Invoke subprogram.         |
|     14               WRITE(6,33) n,sum                                 |
|     15            33 FORMAT(" Sum of the first ",I6,                   |
|     16              1 " integers = ",I10)  ! Continuation line.        |
|     17               STOP                                              |
|     18               END                                               |
|     19         *                                                       |
|     20         *     Function subprogram unit follows.                 |
|     21               INTEGER*4 FUNCTION nfunc(k)                       |
|     22         D     PRINT *, 'nfunc called, k = ', k                  |
|     23               nfunc = 0                                         |
|     24               DO i = 1,k           ! Loop to compute sum.       |
|     25                   nfunc = nfunc+i                               |
|     26               END DO                                            |
|     27               RETURN           ! Return value in function name. |
|     28               END                                               |
__________________________________________________________________________

          Figure 1-1.  Sample FORTRAN Source File 

FORTRAN Terms 

Executable Program    

                     An executable program is one that can be used as a
                     self-contained computing procedure.  An executable
                     program consists of one main program and its
                     subprograms, if any.  (Figure 1-1  shows an
                     executable program in its entirety.)

Program Unit          

                     A program unit is a group of statements organized as
                     a main program, a subprogram, or a block data
                     subprogram.  (In Figure 1-1 , exone and nfunc are
                     program units.)

Main Program          

                     A main program is a set of statements and comments
                     beginning with a PROGRAM statement or any other
                     statement except a FUNCTION, SUBROUTINE, or BLOCK
                     DATA statement, and ending with an END statement.
                     (In Figure 1-1 , lines 1 through 18 are a main
                     program.)

Subprogram            

                     A FORTRAN subprogram is a set of statements and
                     comments headed by a FUNCTION, SUBROUTINE, or BLOCK
                     DATA statement.  When headed by a FUNCTION
                     statement, it is called a function subprogram (In
                     Figure 1-1 , see lines 21 through 28); when
                     headed by a SUBROUTINE statement, it is called a
                     subroutine subprogram; and when headed by a BLOCK
                     DATA statement, it is called a block data
                     subprogram.  Subprograms can also be written in
                     other languages, such as Pascal or C.

Line                  

                     A line is a string of up to 72 characters.  All
                     characters must be from the HP ASCII character set,
                     described in Appendix D. The character positions in
                     a line are called columns, and are consecutively
                     numbered 1, 2, 3,..., 72 from left to right.  (In
                     Figure 1-1 , 1 through 28 are lines.)

Initial Line          

                     An initial line is not a comment line or a
                     continuation line, and contains the digit 0 or a
                     blank in column 6.  Columns 1 through 5 can contain
                     a statement label or blanks.  (In Figure 1-1 ,
                     lines 2, 8, 10, 11, 13, 14, 15, 17, 18, and 21
                     through 28 are initial lines.)

Continuation Line     

                     A continuation line is a subsequent line of a
                     multiple line statement.  A continuation line
                     contains any characters other than the digit 0 or a
                     blank in column 6, and does not contain the
                     character C, *, or $ in column 1.  Any characters
                     can appear in columns 2 through 5.  A tab character
                     in column 1 through 6 and immediately followed by a
                     digit from 1 to 9 is also a continuation indicator
                     to the compiler; there must be blanks or nothing
                     before the tab character.  A line that is longer
                     than 72 characters must use a continuation character
                     and be continued on the next line.

                     A continuation line can follow only an initial
                     statement line or another continuation line (unless
                     separated from an initial line or continuation line
                     by a comment line).  By default, a statement can
                     have up to 19 continuation lines.  If the
                     CONTINUATIONS compiler directive is specified, a
                     statement can have up to 99 contnuation lines.  (In
                     Figure 1-1 , line 16 is a continuation line.)

Statement            A statement is an initial line optionally followed
                     by continuation lines.  The statement is written in
                     columns 7 through 72.  The order of the characters
                     in the statement is columns 7 through 72 of the
                     first line, columns 7 through 72 of the first
                     continuation line, and so on.  (In Figure 1-1 ,
                     lines 2, 8, 10, 11, 13 through 18, and 21 through 28
                     are statements.)

Directive Line        

                     A directive line contains a $ in column 1, and the
                     text of the directive to the compiler in columns 2
                     through 72.  (Refer to Chapter 8 for a list of the
                     valid compiler directives.)  A directive line can be
                     continued.  (In Figure 1-1 , line 1 is a
                     directive line.)

Comment Line          

                     A comment line is marked by a C, an !, or an * in
                     column 1.  (In Figure 1-1 , lines 3 through 7, 9,
                     12, 19, and 20 are comment lines.)

                     An exclamation point (!)  in columns 7 through 72
                     signifies an end-of-line comment.  This is an
                     extension to the ANSI 77 standard.  (In Figure 1-1
                     , lines 8, 10, 11, 13, 16, 23, and 27 contain
                     end-of-line comments.)

Debug Line            

                     A debug line is marked by a D in column 1.  It acts
                     as either a statement or a comment line, depending
                     on the current setting of the DEBUG compiler
                     directive.  (In Figure 1-1 , line 22 is a debug
                     line).



MPE/iX 5.0 Documentation