Fortran
Installing Fortran on Ubuntu in TIDE
Fortran
Fortran (Formula Translation) is a compiled imperative programming language optimized for numeric computing, matrix algebra, and scientific engineering simulations. It remains a foundational language for High-Performance Computing (HPC), weather prediction, fluid dynamics, and aerospace design.
Installation
The standard open-source compiler on Linux is GNU Fortran (gfortran), part of the GNU Compiler Collection (GCC).
Option 1: Installing GFortran via APT (Recommended)
Update package lists and install gfortran along with essential build tools:
apt update
apt install -y gfortran build-essentialOption 2: Installing Fortran Package Manager (fpm)
fpm is the official package manager and build tool for modern Fortran development:
curl -s https://raw.githubusercontent.com/fortran-lang/fpm/main/install.sh | bash
export PATH=$PATH:$HOME/.local/binVerification
Confirm that gfortran is installed and ready to compile:
gfortran --versionWriting and Compiling Code
Writing a Modern Fortran Source File
Create a file named hello.f90:
program hello
implicit none
print *, "Hello, World from Fortran in TIDE!"
end program helloCompiling and Executing with GFortran
Compile the source file into a native binary:
gfortran hello.f90 -o hello
./helloTo compile with compiler optimizations (e.g. for numerical benchmarks):
gfortran -O3 -march=native hello.f90 -o hello_opt
./hello_optBuilding Projects with fpm
Initialize, build, and run structured Fortran projects with fpm:
fpm new hello_app
cd hello_app
fpm run