1.5.3 ENTRY Statement

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.