next up previous contents
Next: Simple example of a Up: Simple example of Subroutine Previous: Simple example of Subroutine

Solution

Note INTENT is not essential as it may not have been covered in the course so far.

External procedure version:

    SUBROUTINE Summy2(res,x,y)
     IMPLICIT NONE
     REAL, INTENT(IN) :: x, y 
     REAL, INTENT(OUT) :: res
      res = x+y
    END SUBROUTINE Summy2

    PROGRAM Main
     IMPLICIT NONE
     REAL  :: answer

      CALL Summy2(answer,2.6,3.1)
      PRINT*, answer
      CALL Summy2(answer,6.1,9.2)
      PRINT*, answer
      CALL Summy2(answer,.1,.555)
      PRINT*, answer

    END PROGRAM Main

Internal procedure version,

    PROGRAM Main
     IMPLICIT NONE
     REAL  :: answer

      CALL Summy2(answer,2.6,3.1)
      PRINT*, answer
      CALL Summy2(answer,6.1,9.2)
      PRINT*, answer
      CALL Summy2(answer,.1,.555)
      PRINT*, answer

    CONTAINS

     SUBROUTINE Summy2(res,x,y)
      REAL, INTENT(IN) :: x, y 
      REAL, INTENT(OUT) :: res
       res = x+y
     END SUBROUTINE Summy2

    END PROGRAM Main

There is no need laboriously type out the interfaces if the procedures are internal.


next up previous contents
Next: Simple example of a Up: Simple example of Subroutine Previous: Simple example of Subroutine

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 14:10:26 GMT 1996