DCL:MATH1: Summary: FORTRAN77 Standard
When trying to write a versatile subroutine in FORTRAN with numerous cases in
mind, the number of arguments may seem to grow endlessly. Only two or three of
the arguments are actually important, but many more seemingly unimportant
arguments fill the list, and makes the task of writing call...a most
tedious one.
The ENTRY statement may be the answer in such cases. The ENTRY statement is used to execute a subroutine from mid course.
*----------- main program ----------- REAL X(10) ....... CALL TABLE(X, 10) ....... END *------------------------------- SUBROUTINE TABLE(X,N) REAL X(N) DATA IOU /6/ SAVE WRITE(IOU,'(10F12.4)') X RETURN ENTRY IOUSET(IOU0) IOU = IOU0 RETURN END
This subroutine table is used to output a 1-D array x. When
only table is called, the array is outputted to device(6) specified by
the DATA statement. The array can be outputted on other devices such as
files, if the iou is rewritten by calling iouset before
calling table. In other words, 2 entrances are created for a single
subroutine: one for providing only the variable to print and one for setting
other parameters.
It should be noted here that the arguments specified by the SUBROUTINE or the ENTRY statement can only be used when entered through these statements. For example, when the program is entered through the ENTRY statement (when IOUSET is called), variable n cannot be inquired. Similarly, when TABLE is called, iou0 cannot be inquired, so iou must be assigned when iouset is called. Furthermore, SAVE and DATA statements are required in these programs.