Showing posts with label Geany. Show all posts
Showing posts with label Geany. Show all posts

Saturday, 18 April 2020

Ada on the Raspberry Pi

Introduction

The computer language  known as Ada was the result of a US Department of Defense competition to develop a computer language to replace the numerous computer languages used in existing defence projects. The competition was won by a team lead by a French team lead by Jean Ichbiah.

Installation

As with installing any new piece of software , you should update and upgrade the current installation
sudo apt update
sudo apt upgrade
sudo apt-get install gnat

As of 18/04/2020 it installed version 6.1.

Hello World

For simplicity, I used the Geany Program Editor to write my first Ada program.

Create a new file called helloworld.adb, I created a folder called Ada in my Documents folder to take the code. For later work, it is best to create a folder for the source code - compiling and building create a number of files.

In the new file enter the following.
-- My first ADA program
with Ada.Text_Io;
use Ada.Text_Io;
procedure HelloWorld is
begin
   Put_Line("Hello World");
end HelloWorld;
The two hyphens start a comment.
The with tells the compiler what package to use. The contents of the package are made visible to this program by the use.
The procedure has a name (HelloWorld) and the code is bounded by the begin - end.
The put_line is a procedure from the package Ada.Text_Io that takes a string parameter and outputs the string followed by a new line character to the standard output.

Compile and Build

Geany handles all the complicated parameters for compilation and building. The options can be found under the Build menu option. Alternatively the function key F8 compiles and F9 Builds.

Execution

Though there is an execute option in the Geany Build menu, the code executes and then disappears.
To see the result of the program start a terminal window and navigate to the folder with the source code.
The executable file has no suffix but has the name of the source file. Prefix the filename with ./ and press return:
pi@somepi:~/Documents/ADA $ ./helloworld
Hello World
pi@somepi:~/Documents/ADA $ 

References

https://www.adaic.org/learn/materials/#introtoada
https://askubuntu.com/questions/421084/how-do-i-install-the-ada-compiler
http://www.getadanow.com/#get_raspberry_pi
http://www.getadanow.com/#step2
https://en.wikipedia.org/wiki/Ada_(programming_language)

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/