Simple question about functions

Welcome to the forum. Yes, there is, using elemental functions, for a scalar and conformable array arguments of any rank. Here is an example:

module m
implicit none
integer, parameter :: dp = kind(1.0d0)
contains
elemental function half_square(x) result(y)
real(kind=dp), intent(in) :: x
real(kind=dp)             :: y
y = 0.5_dp*x**2
end function half_square
end module m
!
program main
use m, only: dp, half_square
implicit none
print*,half_square(real([1,4,9],kind=dp)) ! output: 0.5 8. 40.5
end program main
8 Likes