Learning Fortran – a blast from the past

Intro to Fortran – are you tolerably familiar with BASIC?

Over the weekend, I was clearing out some old paperwork and I found the notes from one of the assessed practical sessions at University.  Although I was studying biochemistry, an understanding of basic programming was essential, with many extra optional uncredited courses available.  It was a simple chemical reactions task and we could use BASIC or Fortran to code the solution.  I’d been coding in BASIC since I was a child1 so decided to go for the Fortran option as what’s the point in doing something easy….

Rereading through these notes is an absolute treat and a real indication of where we were as a society before computers became mainstream.  This was only the 1990s and I remember being aghast that a girl from a comprehensive school in the Midlands had more experience with programming than most of my year, the majority of whom were from private schools.

What I really find funny in retrospect is how we were taught to use computers.  They were presented as complex machines that we had to understand every part of before we could use them.  My five year old daughter doesn’t need to be told  – she discovers features by exploration2.  Looking back at these notes, after being told to turn the computer on “at the mains”3, there is the gem of a sentence:

Before you do anything else, let’s look at the way you communicate with the computer – the keyboard

Whilst putting me back to thinking of the transparent aluminium scene in Star Trek IV : The Voyage Home which pre-dates these notes by a decade, the notes go on to make the comparison to a typewriter.  I wonder how many people just accept the keyboard layouts without really thinking about why the letters are arranged in the way they are.  And who knew that hitting RETURN means “that’s the end of this message” 😉  By the end of page 1, there’s a warning that the notes will soon stop reminding you to press RETURN.

I love the fact that rather than just telling you the commands to use, there is also an explanation “CAT (short for CATalogue)” as well as a translation of a simple three line addition program into its equivalent machine code.  I feel sometimes that people who have learned to code post millennium are missing out on a fundamental understanding at this level.  Relying on expanding resources to allow their systems to run.  The best programmers understand computational efficiency at some level, even if they don’t understand machine code itself.

There is also a great set of rules on how to make your code “good”  – a lot of people who are self taught would do well to follow.

Coding guidelines for Fortran, some less applicable for today, but the basis of some good practises

One of the things that I always found a little backwards about Fortran is that you state that you are going to write something before you define what it is:

     B=SQRT(A)

     WRITE(*,1) A,B

1    FORMAT(‘ The square root of ‘,F5.1,’ is ‘,F8.4)

This goes against everything else that seems to make sense to me.  At the point of the write statement, ‘1’ is undefined.  But that’s something for the compiler to resolve… Note the extra space at the start of the print out which was required by line printers as it was a control character (although not for the new “modern” dot matrix printers 🙂 ).  The formatting definition which should feel familiar to anyone who has covered a low level language is ‘F’ which is the format for a real number and we’ve defined our variables to start with letters between A and H4 so they are both real without the need for further assignment.  Let’s just take a second to think about the name of a variable influencing its type…  The numbers after the F show the number of columns to allow for the number followed by the number of decimal places.  So you had to make sure that your numbers were in the expected range to avoid unexpected results… 🙂

Once the intro guide has assumed you’ve mastered I/O and compiling Fortran it steps up with “simple loops” and another of my favourite statements:

Computers are not clever.  Their power arises from their ability to do simple things rapidly and repeatedly.

This is something else we would do well to keep in mind, although one could say the same things about our neurons…

I could happily reminisce through the whole document, but if you’d like to learn more about Fortran and, as a bonus,  see what state of the art web design was back in the 90s then Michigan University’s pages are still up (animated under construction gifs and textured backgrounds anyone?).

While I’ve never had to use Fortran since that single afternoon, it was fun.  The more programming languages you learn the better you understand their strengths and weaknesses and give you the option to use the correct tool for the job.

Before the machines learn to write their own code that is 😉

  1.  My dad brought home the BBC Micro every holiday and then we got our own Acorn Electron.
  2. When she’s ready, she’ll learn how to bend it to her will rather than just playing games.
  3. Back in the day where everyone not only turned off but unplugged electrical devices when not in use…
  4.  Variables starting with O to Z would also be defined as real.
janet

Dr Janet is a Molecular Biochemistry graduate from Oxford University with a doctorate in Computational Neuroscience from Sussex. I’m currently studying for a third degree in Mathematics with Open University.


During the day, and sometimes out of hours, I work as a Chief Science Officer. You can read all about that on my LinkedIn page.


Published by

janet

Dr Janet is a Molecular Biochemistry graduate from Oxford University with a doctorate in Computational Neuroscience from Sussex. I’m currently studying for a third degree in Mathematics with Open University.

During the day, and sometimes out of hours, I work as a Chief Science Officer. You can read all about that on my LinkedIn page.