FORTRAN Reference Manual

Program Units
FORTRAN Reference Manual528615-001
4-11
Using Adjustable Dimensions for Arrays and String
Variables
The following subroutine, HEADING, prints a page heading. The alternate entry point,
DETAIL, prints the values of four variables which comprise the data lines of the report.
SUBROUTINE heading (product, price, amount, salesman)
1 WRITE (*,2)
2 FORMAT ('1',T50, 'SALES REPORT FOR MARCH'//T55, 'FREMONT')
ENTRY detail (product, price, amount, salesman)
4 WRITE (*,5) product, price, amount, salesman
5 FORMAT (T5, I6, T4, F10.2, T4, I5, T4, A)
END
A line count in the calling program determines whether the subroutine executes from
statement 1 or statement 4:
PROGRAM MAIN
.
IF (line count .GT. 45) THEN
CALL heading (prod, cost, amt, sales)
ELSE
CALL detail (prod, cost, amt, sales)
END IF
.
END
Using Adjustable Dimensions for Arrays and
String Variables
If you use an array as an actual argument to a subroutine or function call, the size and
type of the associated array in the subroutine or function must correspond to the actual
array. The following example uses a subroutine to calculate the average test score for
a class of up to one hundred students. The program stores the test scores in the one
dimensional array RESULT: