! exf6.f90 define and use functions and subroutines module functions ! inside here, usually compiled as a separate file public :: fun contains function func(t) result (r) real, intent(in) :: t ! declare parameter types real :: r ! declare result type r = t + 1.0 ! last value stored in result is returned end function func subroutine subr(A) real, dimension(:), intent (in out) :: A ! declare parameter type integer :: n n = size(A) do i = 1,n A(i) = A(i) + 1.0 end do end subroutine subr end module functions program exf6 use functions ! makes available func and subr real, dimension(1:5) :: a = (/ 1.0, 2.0, 3.0, 4.0, 5.0 /) real :: x = 1.0 real :: y print *, "exf6.f90 define and use functions and subroutines" y = func(x) print *, "y=funct(x)=", y call subr(a) print *, "call subr(a) a=", a end program exf6