Fortran Line Continuation for Long Vector

FORTRAN 77 - A look back.

16.2 Obsolescent Source Form

  • FORTRAN was one of the first major computer languages developed, in fact, the origin of FORTRAN dates prior to the use of keyboards and monitors!
  • The program would be delivered to the computer in the form of punch cards.
  • Each punch card had a fixed length of 80 columns, and one character, number, or symbol could be typed in each column.
  • A fixed-source form FORTRAN statement still reflects the structure of the punched computer card.
    • Columns 1 through 5 are reserved for statement labels.  A statement label may be located anywhere within columns 1 through 5 .
    • A letter C or an * placed in column 1 indicates that the statement is a comment.
    • Column 6 is used to indicate  that the statements is a continuation of the previous statement/line.  A FORTRAN 77 statement may be up to 40 lines long!
    • Columns 7-72 contain the FORTRAN instructions.  Instructions may be placed freely anywhere within this area.  Indentation was a good idea in FORTRAN 77 just as it is now in FORTRAN 90.
    • Columns 73-80 are ignored by the compiler and may be used by the programming for any desired purpose.  In the days when programs were saved on decks (yes, I said decks) of punched cards, this field was used to number the cards to ensure they were fed in the correct order.
    • Software exists to convert from fixed-source form (F77) to free-form (F90).

The first line represents Column 7 and the second line represents Column 73.

The green button below will compile and execute the code.

PRINT, WRITE, and READ

  • Both PRINT and WRITE statements can be used to display messages on the standard output device.
  • WRITE permits more flexibility as to where we print and how we format the output.
  • READ can be similar to either the PRINT or the WRITE.  The format as we have seen in FORTRAN 90 provides for more destinations than just the keyboard.

Implicit Types

We have formed a good habit in FORTRAN 90, using IMPLICIT NONE.  This forces us to declare variables before we use them, but, this is not completely necessary and it was a common practice in FORTRAN 77 to just start using variables.

        PROGRAM testtypes  C      *** I, J, K, L, M, N, WILL BE INTEGERS ***         more = 3 C      *** ALL OTHERS WILLBE A REAL VALUE ***         someval = 3.33         otherval = 3                PRINT *, "more is ", more         PRINT *, "someval is ", someval         PRINT *, "otherval is ", otherval              END      

Variable Declarations - LIMIT OF 6 CHARACTERS!

        PROGRAM helloWorld          CHARACTER*12 howdy          INTEGER x          INTEGER y          REAL avg                    x = 3          y = 2          avg = (x + y) / 2                    PRINT *, 'Average of ', x, ' and ', y, ' is = ', avg          howdy = 'Hello World!'          PRINT *, howdy          WRITE(*,*) howdy        END      
Output
              

Constants

        PROGRAM testtypes          REAL PI         PARAMETER(PI = 3.14159)                PRINT *, 'PI = ', PI              END      

Subroutines

        PROGRAM sumNums          INTEGER x          INTEGER y           CALL SUM2(x, y)          PRINT *, 'Sum is = ', x+y        END         SUBROUTINE SUM2(x, y)          INTEGER x          INTEGER y           PRINT *, 'Enter a value for x: '          READ *, x          PRINT *, 'Enter a value for y: '          READ *, y           PRINT *, 'Sum is = ', x+y        END      
  • Note that there is no intent. You can assume that the "intent" is INOUT in this case.
  • Recursion (direct or indirect) not permitted!

Functions

        PROGRAM sumNums          INTEGER x          INTEGER y          INTEGER z          INTEGER SUM2           z = SUM2(x, y)          PRINT *, 'Sum is = ', z          PRINT *, 'x is = ', x          PRINT *, 'y is = ', y                  END         INTEGER FUNCTION SUM2(x, y)          INTEGER x          INTEGER y           PRINT *, 'Enter a value for x: '          READ *, x          PRINT *, 'Enter a value for y: '          READ *, y           SUM2 = x + y          RETURN        END      

  • Note, it appears with the function (as seen with the subroutine) that the "intent" of the arguments would be similar to INOUT.

Statement Functions

        PROGRAM sumNums          INTEGER x          INTEGER y          INTEGER z          INTEGER SUM2 *        *** STATEMENT FUNCTION DEFINITION ***          SUM2(x, y) = x + y           PRINT *, 'Enter a value for x: '          READ *, x          PRINT *, 'Enter a value for y: '          READ *, y                    z = SUM2(x, y)          PRINT *, 'Sum is = ', z          PRINT *, 'x is = ', x          PRINT *, 'y is = ', y        END      

Iterative Loops

        PROGRAM printNums          INTEGER x           DO 10 x = 1, 5             PRINT *, 'x = ', x 10       CONTINUE        END      

Selection

FORTRAN 77 Operator Meaning FORTRAN 90 Operator
.LT. LESS THAN <
.GT. GREATER THAN >
.LE. LESS THAN OR EQUAL TO <=
.GE. GREATER THAN OR EQUAL TO >=
.EQ. EQUAL TO ==
.NE. NOT EQUAL TO /=
        PROGRAM testNum          INTEGER x           PRINT *, 'Enter a value for x: '          READ *, x                    IF (x .LT. 0) THEN             PRINT *, 'Value is negative'          ELSEIF (x .EQ. 0) THEN             PRINT *, 'Value is zero'          ELSE             PRINT *, 'Value is positive'          ENDIF                  END      
  • SELECT CASE is FORTRAN 90 only!

Conditional Loops

  • FORTRAN 77 has a loop similar to the DO WHILE in FORTRAN 90
        PROGRAM testNum          INTEGER x           PRINT *, 'Enter a value for x: '          READ *, x           10       IF (x .LT. 5) THEN             PRINT *, 'x = ', x             x = x + 1                          GO TO 10          ENDIF                     END      

Above we see a pre-test loop, the condition is tested before the loop is executed.  Below, we see a post-test loop in which the condition that continues the loop is evaluated at the end of an iteration.

        PROGRAM testNum          INTEGER x           PRINT *, 'Enter a value for x: '          READ *, x  *        *** START OF POST-TEST LOOP *** 10          PRINT *, 'x = ', x             x = x + 1             IF (x .LT. 5) GO TO 10                     END      

Arrays in FORTRAN 77

For the most part, arrays behave quite similarly in FORTRAN 90 and 77.

The biggest change is that FORTRAN 77 doesn't allow whole array operations.

  • Want to print the entire array?  Do it element by element!

COMMON Blocks

  • FORTRAN 77's version of what was to become the FORTRAN 90 MODULE.

A COMMON block of memory locations can be made available to any and all program units.

        PROGRAM testNum          INTEGER x          INTEGER y          INTEGER z          COMMON x, y                  x = 5          y = 7          z = 3          PRINT *, 'In program before CALL'          PRINT *, 'x = ', x          PRINT *, 'y = ', y          PRINT *, 'z = ', z           CALL swap                    PRINT *, 'In program after CALL'          PRINT *, 'x = ', x          PRINT *, 'y = ', y          PRINT *, 'z = ', z                     END         SUBROUTINE swap          INTEGER x          INTEGER y          INTEGER z                  COMMON x, y                    PRINT *, 'In sub before CHANGE'          PRINT *, 'x = ', x          PRINT *, 'y = ', y          PRINT *, 'z = ', z          z = 4          x = 0          y = 0                    PRINT *, 'In sub after CHANGE'          PRINT *, 'x = ', x          PRINT *, 'y = ', y          PRINT *, 'z = ', z         END      

Summary of FORTRAN 90 "new" Features

  1. Enhanced Array Operations (whole array operations).
  2. Modules
  3. User-Defined Types
  4. Pointers
  5. New Selection (SELECT CASE) and Repetition (DO WHILE) Constructs
  6. Free-Form!

Additional FORTRAN 77 Link

  • http://www.strath.ac.uk/CC/Courses/fortran.html

charbonneauanscialtat.blogspot.com

Source: https://web.ics.purdue.edu/~cs154/lectures/lecture024.htm

0 Response to "Fortran Line Continuation for Long Vector"

إرسال تعليق

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel