leonfoks / coretran

An easy to follow library to make Fortran easier in general with wrapped interfaces, sorting routines, kD-Trees, and other algorithms to handle scientific data and concepts. The library contains core fortran routines and object-oriented classes.
BSD 3-Clause "New" or "Revised" License
97 stars 12 forks source link

Mean example is broken #5

Closed milancurcic closed 6 years ago

milancurcic commented 6 years ago

There are typos and illegal names in the native Fortran version of the mean which do not allow it to compile.

Below is the correct code:

program theMean_program
use, intrinsic :: iso_fortran_env, only: real64, int32
implicit none
real(real64), allocatable :: a(:)
real(real64) :: theMean
! Some parameters to handle everything
integer(int32) :: i, istat, N
N=1000

! Allocate a and check for errors
allocate(a(N), stat=istat)
if (istat /= 0) then
  stop "Could not allocate a"
endif

! Create numbers from 1 to N
a = [(real(i,kind=real64), i=1,N)]

! Compute the mean
theMean = sum(a)/real(N,kind=real64)

! Deallocate memory
deallocate(a, stat=istat)
if (istat /= 0) then
  stop "Could not deallocate a"
endif
end program

(I did not test the coretran variant)

leonfoks commented 6 years ago

Argh, of course. Im sure I have many Fortran typos in the documentation examples...

Thanks for letting me know, its now fixed.