Research Article

SPOT: A DSL for Extending Fortran Programs with Metaprogramming

Algorithm 13

The Fortran program for calculating the value of Pi.
(1)program CalculatePI
(2)integer n, i
(3)real*8 t, x, pi, f, a
(4)f(a) = 4.d0 /(1.d0 + a*a)
(5)pi = 0.0d0
(6)n = 100000
(7)t = 1.0d0/n
(8)do i = 1, n
(9)   x = t  *  (i    0.5d0)
(10)pi = pi + f(x)
(11)  end do
(12)  print *, "The value of pi is ", pi
(13)end