Here is a slightly expanded version of the things we talked about in class.  The last two items were not discussed but you can find information about them in any of the many

help files on the FORTRAN languages.  You can do a google search or look on the BURKS site or CDs. 

 

 

Parameter passing in FORTRAN is all pass by reference (pass by address)

 

What kinds of statements would you expect to find in a programming language

 

1. Assignment statement 

            Variable = expression

 

2. Conditional Statement – a selection statement

    Example 1 (form and code)

 

              If statement

                         If (Boolean condition) DOTHIS

 

            IF (X .LT. O.O) GO TO 7

                 NUMNEG = NUMNEG+ 1

                 GO TO 8

7                      NUMPOS = NUMPOS + 1

8                       ICOUNT = ICOUNT + 1

 

 

    Example 2 (form and code)   -  ARITHMETIC IF

 

If (arithmetic value) label, label2, label3

           

            Goes to statement labeled 25 if I < 0; goes to statement labeled 365 if I = 0; goes

            to statement labeled  43 if I > 0

            IF (I) 25, 365, 43

 

 

     Example 3 (form and code)  - COMPUTED GO TO

             GO T0 (label1, label2, label3, label4) , variableName

 

 

             Goes to statement labled 23 if J = 1; goes to statement labeled 45 if  J = 2,  goes

             to statement labeled 73 if J = 3;  etc. 

 

             GO TO (23,45,73,98 104), J

      

       Note:  examples 2 and 3 are scheduled to be DEPRECATED

 

Relational operators

   .EQ.

   .NE.

   .GT.

   .GE.

   .LT.

   .LE.

 

Variable Names which begin with the letters I – N are by default, integer variables

Variable names which being with any other letter are by defaults, real.

 

Data types

INTEGER       

REAL

LOGICAL

                        Logical values are .TRUE.   .FALSE.

COMPLEX

DOUBLE PRECISION

 

Array declarations

DIMENSION A(3)

DIMENSION X(4,5)

 

Array A has 3 locations   A(1), A(2), A(3)

Array X has 20 locations in 4 rows and 5 columns

 

 

 

3. RETURN statement

    Returns from functions or subroutines (the 2 kinds of subprograms)

 

 

4.      INPUT statement   (form and code)

The 5 specifies the default input device.  The label refers to the associated format statement

        READ (5,label) list of variables to be read

 

 

               READ (5, 12) X,I

          12 FORMAT (F2.1, I3)

 

 

    5.    OUTPUT statement   (form and code)  - more below

The 6 specifies the default output device.  The label refers to the associated

Format statement.  The F in F4.1 specifies that it’s a fixed point number; the I in

I3 specifies that it is an integer.  The integer following the F and the I specifies

the number of columns to be used.  The .1 in F4.1  specifies that only one place

after the decimal point is to be shown

 

WRITE (6, label ) list of variables to be printed

 

    WRITE (6,13) X,I

 13           FORMAT (1X, F4.1,I5)

 

    6.   LOOP statement  (form and code)

          DO label variableName = startvalue, endvalue, modificationValue

             …

label  CONTINUE

 

          DO 10  M = 5, 13, 1

            ...

            ...

10    CONTINUE

 

  1. DATA statement

used to specify the initial values of certain variables at compile time

can not be used during program execution (run time)

 

DATA X/2.16/,Y/31.8/,I/26/

 

  1. FORTRAN use of columns
    1. Comment statement

C in column 1 was usual    

! in column 1 for Lahey FORTRAN

    1. Labels

numbers in columns 1 through 5

    1. Continuation card

entry in column 6

    1. Program statements

columns 7 through 72

    1. Sequencing

columns 73-80

    1. Data

in any columns

 

  1. Statement functions

have the general form:    name (a1, a2 . ..... an) =  F(a1, a2 . ..... an)

The parenthesized variables on the left side represent the arguments to the function.

The entire right side is an expression which specifies the value of the function

          P(X) = (A*X + B)*X + C

  1. Subprograms

FORTRAN has three types of subprograms:  statement functions (already described) subroutines and functions. !  Subroutines return zero, one or many values through the parameter list. !  FORTRAN parameters are passed by reference (address) The code for functions and subroutines subprograms should physically follow the code for ! the main program

 

Here is the form of a parameterless subroutine.

 

         SUBROUTINE  PRINTHI

             WRITE (6, 10)

10       FORMAT (1X, ‘  HI ‘)

    RETURN

             END

 

The calling statement in the main program for the above subroutine would b!  Note that the word subroutine does NOT appear in the call statement

           

            CALL PRINTHI

 

Below is the skeleton for a subroutine with parameters.  By default, the values this subprogram expects to receive are real (i.e. fixed point) values.  If you intend to pass in integers you must add a line directly following the subroutine  declaration  which declares  X,Y, and Z as integers  (i.e.   INTEGER X,Y,Z)

Unlike Java, changes that are made to the formal parameters (inside the subroutine)! are reflected (affect) the actual (calling) parameters.

 

          SUBROUTINE  SORXYZ (X, Y, Z)

...

...

           RETURN

           END

 

FORTRAN functions return a single value and return it by assigning the value to the function name (inside the function).  Recursion was  not available  in early FORTRAN and we will not be using it in our FORTRAN programs. 

By default, function names indicate the type of the return value.

 

The function  below finds the sum of the three numbers X, Y, and Z which are assumed to be real (floating point) numbers.  If you want them !   to be integers, you must declare them as integers inside the function.

 

           FUNCTION SUM (X,Y,Z)

           SUM = X + Y + Z

            RETURN

            END

 

  1. Exception handling

END = label

ERR = label

  1. DIMENSION statements

for declaring arrays 

  1. FORMAT descriptors

L    for Logical

F ...for fixed point

I    for integer

E ...for exponential data

F    for complex

D   for double precision

H   for characters

  1. Carriage control characters – for output

1x   a blank space

‘ ‘   (a blank space)  - advance 1 line  (i.e. newline, or single space)

‘0’  advance 2 lines   (i.e. double space)

‘-‘    advance 3 lines  - not all compilers

‘1’    advance to top of next page

‘+’    do not advance to a new line (i.e. overstrike)

  1. STOP statement

stops the execution of the program

can occur anywhere in the program

can occur in more than one place, the one reached first stops the program

it’s not good form to have multiple stop statements

  1. END statement

stops the compilation process of a unit

non-executable statement 

  1. CONTINUE statement

non-executable statement

generally used to mark the end of a DO loop and to affix the label to 

  1.  
  2. Graduate Students

COMMON statements

IMPLICIT statements

EQUIVALENCE statements