Monday 12 August 2019

Fortran on the Raspberry Pi

Introduction

My first programming job was in Fortran (Fortran 77 on an HP-150 with an HPIB connection to an I/O board). I have not used Fortran for probably thirty years but thought I should have a look at trying it on the Raspberry Pi.
Fortran is not just a very long lived language, unlike COBOL which has survived because core parts of the financial sector have stable working elements that they do not want disturbed, Fortran is still a developing system - its continued use in high powered mathematical processing celebrates the origin of its name "Formula translation".

Installation

Make sure that the operating system is up to date:
sudo apt-get update
sudo apt-get upgrade
Then install GFortran:
sudo apt-get install gfortran

First program

I added a Fortran directory to my Documents directory for source code.
Here is a simple "Hello World" program:

program helloworld
print *,"Hello World"
end program helloworld

Create the file in your favourite editor and save it into the directory.
In the terminal window, change the current directory to the saved location.
Compile using:
gfortran -o helloworld ./helloworld.f90
In the terminal enter the following:
./helloworld
The program will then print Hello World.

Using the Geany IDE

Geany is a default install on Raspbian, and makes it a lot easier to write programs than a simple text editor.
The application can be found by clicking on the Applications Menu/Programming/Geany Programming Editor.

Enter the program code (there is syntax highlighting once you have named the file with a suitable suffix, in this case: .f90 for Fortran 90).
To build and execute the program, click on Build/Execute. Geany will build then execute the code in a shell.



References
https://en.wikipedia.org/wiki/Fortran
https://gcc.gnu.org/fortran/
https://gcc.gnu.org/wiki/GFortran
https://en.wikipedia.org/wiki/IEEE-488
https://en.wikipedia.org/wiki/HP-150
https://en.wikipedia.org/wiki/Geany
https://geany.org/