You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand the advantage of demonstrating the power of coretran on a very simple example, however the native Fortran code for the mean example is unnecessarily verbose and misrepresents the level of verbosity of Fortran. The following can make it much more succinct:
No need to explicitly allocate - use automatic allocation on assignment.
No need to explicitly deallocate at the end of the program - let the array get cleaned-up by the compiler.
No need to explicitly re-cast integer to real - let the compiler do the type coercion.
The equivalent and correct example:
program theMean_program
use, intrinsic:: iso_fortran_env, only: real64, int32
implicit nonereal(real64), allocatable :: a(:)
real(real64) :: theMean
integer(int32) :: i, istat, N
N=1000
! Create numbers from 1to N
a = [(real(i,kind=real64), i=1,N)]
! Compute the mean
theMean =sum(a)/N
end program
The text was updated successfully, but these errors were encountered:
Thanks for the great points and I agree that the small example doesn't even do the idea of coretran any justice let alone newer aspects of Fortran. I've been meaning to update this for a while.
In my opinion, I would consider your use of the very succinct aspects of Fortran to be modern. Since i'm coming from a back ground of teaching modern Fortran to people who are not used to modern Fortran at all, I left the older styles in. This makes the example more accessible to people who get confused by implicit do loops on assignment and even vectorized notation.
Perhaps I should just take out the comparison of "old" and "coretran" code, and simply show some examples of using coretran like in the rest of the docs.
I've had some weird memory issues when relying on automatic allocation and large codes. So I like to be explicit with allocation and deallocation.
I once thought the same thing about letting clean up deallocate out-of-scope variables. Then I said the same thing at a class up at NCAR in Boulder. The response was "and you trust it?" So i've been explicit about deallocating memory ever since.
I'm mainly explicit about conversions because I hate getting warnings when i'm compiling code under debug flags. Plus the more explicit you are the better....right?
I understand the advantage of demonstrating the power of coretran on a very simple example, however the native Fortran code for the mean example is unnecessarily verbose and misrepresents the level of verbosity of Fortran. The following can make it much more succinct:
The equivalent and correct example:
The text was updated successfully, but these errors were encountered: