! The subroutine must have a name. The naming
! conventions are the same as for any other variable.
! The name cannot be the same as any other variable
! or subroutine currently in use by your program
! b, h and a are called the subroutine arguments (more
! precisely, these are called dummy arguments).
! They are how the subroutine interfaces with the main
! program (or other subroutine that calls it).
! A subroutine can have any number of arguments. These
! can be any variable type and can be scalars or arrays.
! The variable names in the subroutine do not have to have
! the same names as those in the calling routine (subroutines
! would have little use if these were true).
! We still want to USE the const module and impose the
! IMPLICIT NONE requirement
! Each of the dummy variables should be given an INTENT
! attribute. There are 3 types of dummy argument INTENT
! INTENT(IN) => this is used for a variable that is an 'input'
! to the subroutine. Variables with this intent
! cannot be changed by the subroutine
! INTENT(OUT) => this is used for a variable that is an 'output'
! from the routine. The subroutine MUST assign a
! value to any variable that is given this intent
! INTENT(INOUT) => This is used for a variable that has one value
! coming into the subroutine and may (or may not)
! have a different value coming out.
! For this routine, we think of the dummy arguments for base and height
! as inputs, so they should be given the INTENT(IN) attribute
REAL(KIND=dp),INTENT(IN) :: b,h
! The area is an output, so we give this dummy argument INTENT(OUT)
REAL(KIND=dp),INTENT(OUT) :: a
! All of the above statements are part of the subroutine header section
! The executable section of the subroutine starts below
! Compute the area
a = b*h/2
! The RETURN statement forces the subroutine to return to whatever routine
! called it.
! In this specific case, it is technically not needed because there is no other
! option except to return to the calling routine.
! Older fortran programs were required to have this statement so you often see
! it at the end of all subroutines.
! We end the subroutine in a manner similar to how we end the main program.
END SUBROUTINE tri_area