program serial_pi
implicit none

character(8) :: c1
integer :: intvall, i 
integer, parameter:: factor = 500000000
double precision :: f, sum, h, mypi, t1, rtc, timenow

call getarg(1, c1)
read (c1, '(i8)') intvall ! Intvall = nr of intervalls in each process
intvall= factor         
write(6,*) 'intvall=',intvall

sum =0.0
h = 1.d0/(intvall)
t1=timenow()

do i=0,intvall
 sum = sum + f(h*(i))
end do
t1=timenow()-t1

mypi=sum*h
  print *, 'Time = ', t1
  print *,'pi= ',mypi,' err= ', (atan(1.q0)*4.q0-mypi)/atan(1.q0)*4.q0
end program 

double precision function f(x)
implicit none
double precision x

 f = 4.0/(1.0+x*x)
end function f