Member-only story

Fortran Code Guessing Game

A thinking-out-loud analysis of Fortran code. What could a programmer accustomed to various modern languages figure out about a Fortran code snippet?

Erik Engheim
4 min readMar 11, 2021

In one of my recent articles, I wrote a snippet of Fortran code to argue that the programming languages of old are not that different from the ones we use today. One could guess a lot of what is written there if one has some exposure to some different languages. I am writing this for the benefit of one of my readers, Matthew, but I thought it might be of general interest. So here is the Fortran code:

function sort( array )
real, dimension(:) :: array
real, dimension(size(array)) :: sort

real :: temp
integer :: i, j
integer, dimension(1) :: pos

!
! Retrieve the lowest elements one by one
!
sort = array
do i = 1,size(sort)
pos = minloc( sort(i:) )
j = i + pos(1) - 1
temp = sort(j)
sort(j) = sort(i)
sort(i) = temp
enddo
end function

Without looking up anything about Fortran, I will try to guess what everything means here based on other languages I use. I promise you that I have never written a line of Fortran code in my life or ever been taught Fortran.

Start and End of Function

--

--

Erik Engheim
Erik Engheim

Written by Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

Responses (7)