- What is Fortran? — Introduction & Overview
- A Deep History of Fortran (1957–2026)
- Key Features of Fortran
- Fortran Syntax — Complete Guide
- Data Types, Variables & Constants
- Operators & Expressions
- Input / Output & Formatted Printing
- Control Structures — Conditionals & Loops
- Arrays — 1D, 2D, Dynamic & String Arrays
- Functions, Subroutines & Modules
- Pointers & Memory Management
- File I/O in Fortran
- Object-Oriented Programming in Fortran
- Parallel & Concurrent Programming
- Installation Guide — Windows, macOS, Linux, Termux (32 & 64-bit)
- How to Compile & Run Fortran Programs
- Advantages & Disadvantages
- Fortran vs Python vs C++ vs MATLAB
- Real-World Use Cases & Notable Projects
- Learning Resources, Tools & Community
- Frequently Asked Questions
Fortran — short for Formula Translation — is one of the oldest and most enduring high-level programming languages ever created. First developed by IBM in 1957, Fortran is nearly 69 years old in 2026 yet still ranks consistently in the top 15 most-used programming languages worldwide on the TIOBE Index. That is a staggering achievement in a field where technologies often become obsolete within a decade.
Fortran was built with a single clear purpose: translate complex mathematical formulas into efficient machine code — hence the name. Before Fortran, programmers wrote in assembly language, which was tedious, error-prone, and tightly bound to hardware. Fortran changed computing forever by introducing the concept of a high-level compiled programming language that was both readable by humans and fast enough for serious computation.
Today Fortran remains the gold standard for high-performance scientific computing, numerical simulations, weather prediction, climate modeling, computational physics, aerospace engineering, and financial computing. Institutions including NASA, NOAA, CERN, and the world’s top supercomputing centers run massive Fortran codebases refined over decades.
Despite competition from Python, C++, and MATLAB, Fortran retains its position because of unmatched numerical computation performance, native array-based syntax, built-in support for parallel and concurrent programming, and decades of optimized mathematical libraries. With compiler optimizations, Fortran matches or exceeds C and C++ performance in scientific workloads.
Fortran is a statically typed, compiled, multi-paradigm language supporting structured, procedural, and — since Fortran 2003 — full object-oriented programming. It features strong typing, case insensitivity, and a clean syntax many engineers find easier to read than C or C++. Complex numbers are supported natively, array handling is first-class, and do concurrent loops enable parallel execution without any external libraries. The standard file extension for modern Fortran is .f90 and the primary free compiler is GFortran, part of the GNU Compiler Collection.
The story of Fortran is inseparable from the story of modern computing. To understand why it matters in 2026 we must trace its nearly seven-decade evolution.
Origins trace to John W. Backus, a computer scientist at IBM who found assembly language programming frustratingly slow. In 1953 he proposed a project to develop a practical alternative. His team worked over three years — the first Fortran compiler successfully compiled its first full program in 1958. Backus also co-created the Backus-Naur Form (BNF), a formal syntax notation still universally used today, earning him the 1977 ACM Turing Award — computer science’s highest honor.
Modern Fortran (90 and later) is a feature-rich language that continues to evolve. Its core capabilities explain why it remains competitive in 2026 despite its age.
Fortran compilers are the most optimizing ever built. With -O3, Fortran matches or exceeds C++ in numerical benchmarks.
Arrays are first-class citizens. Matrix addition, slicing, and reshaping are built into the language — no imports needed.
The COMPLEX data type is built-in — essential for electrical engineering, quantum mechanics, and signal processing.
DO CONCURRENT, co-arrays, and OpenMP/MPI support let Fortran scale from a laptop to the world’s fastest supercomputers.
ISO_C_BINDING module allows seamless calling of C functions from Fortran, giving access to the entire Unix/Linux ecosystem.
Modules allow clean separation of interfaces, data, and implementation — supporting large-scale software architecture.
Strong static typing with IMPLICIT NONE catches type errors at compile time — critical for scientific accuracy.
Full OOP since Fortran 2003: type extension (inheritance), polymorphism, type-bound procedures, and abstract types.
Beyond these highlights, Fortran supports generic programming through interfaces and operator overloading, precision control via the KIND parameter system, dynamic memory allocation with ALLOCATABLE, and over 100 intrinsic functions for mathematics, strings, and arrays. The Fortran Package Manager (FPM) at fpm.fortran-lang.org modernizes the ecosystem with dependency management similar to Python’s pip or Rust’s cargo.
Fortran syntax is clean and readable compared to languages like C++ or Rust. The language is case insensitive, does not use semicolons to end statements, and uses meaningful keywords like end program, end do, and end if to close blocks — making nested code easy to visually parse. Every program begins with program name and ends with end program name. The critical statement implicit none must always appear immediately after the program declaration to disable legacy implicit typing.
Comments: Use ! — everything after on that line is ignored.
Line continuation: End a line with & and continue on the next.
Case insensitive: INTEGER, integer, and Integer are identical to the compiler.
Variable declarations: Always at the top of program/subroutine, before executable statements.
No semicolons: Statements end at the newline. Semicolons only needed for multiple statements on one line.
Fortran provides five intrinsic data types. Understanding them — especially the difference between integer and real division — prevents some of the most common Fortran bugs.
| Data Type | Keyword | Example Values | Default Precision | Use Case |
|---|---|---|---|---|
| Integer | INTEGER | -42, 0, 1000 | 32-bit (KIND=4) | Counters, indices, loop variables |
| Real (Float) | REAL | 3.14, -0.001, 1.0e6 | Single (6–7 sig. digits) | Scientific measurements |
| Double Precision | REAL(KIND=8) | 3.14159265358979d0 | Double (15–16 sig. digits) | High-accuracy simulations |
| Complex | COMPLEX | (2.0, -4.0) | Two REALs combined | Electrical engineering, quantum physics |
| Logical | LOGICAL | .TRUE., .FALSE. | 1 byte typically | Boolean conditions, flags |
| Character | CHARACTER(LEN=n) | “Hello, World!” | n bytes (user-defined) | Labels, filenames, user input |
In Fortran, dividing two integers performs integer division and truncates the result. The expression 9 / 5 gives 1, not 1.8. Write 9.0 / 5.0 or 9. / 5. to get a real result. This is the source of many silent bugs in temperature conversions and scaling factors.
Fortran provides arithmetic, relational, logical, and string operators. Unlike most languages, Fortran supports word-based relational operators such as .EQ., .NE., .GT. alongside their symbolic equivalents ==, /=, >. Both forms are valid in Fortran 90+.
| Category | Operator | Alternative | Meaning | Example |
|---|---|---|---|---|
| Arithmetic | + | — | Addition | a + b |
| – | — | Subtraction | a – b | |
| * | — | Multiplication | a * b | |
| / | — | Division | a / b | |
| ** | — | Exponentiation | x ** 2 | |
| Relational | == | .EQ. | Equal to | a == b |
| /= | .NE. | Not equal to | a /= b | |
| > | .GT. | Greater than | a > b | |
| < | .LT. | Less than | a < b | |
| >= | .GE. | Greater or equal | a >= b | |
| <= | .LE. | Less or equal | a <= b | |
| Logical | .AND. | — | Both true | a .AND. b |
| .OR. | — | Either true | a .OR. b | |
| .NOT. | — | Negate | .NOT. a | |
| String | // | — | Concatenation | “Hello” // ” World” |
Fortran has two primary I/O statements: PRINT and WRITE for output, and READ for input. The asterisk * refers to the standard I/O unit — equivalent to unit 5 for stdin and unit 6 for stdout. Fortran’s powerful FORMAT statements give precise control over column widths, decimal places, and spacing for scientific output tables.
| Format Code | Meaning | Example |
|---|---|---|
| Iw | Integer, width w | I5 → integer in 5 spaces |
| Fw.d | Float, width w, d decimals | F12.3 → 12 wide, 3 decimal places |
| Ew.d | Scientific notation | E12.4 → e.g., 1.2345E+03 |
| Aw | Character string, width w | A20 → string in 20 spaces |
| nX | n blank spaces | 2X → two spaces |
| / | New line | / → move to next line |
Fortran provides IF-THEN-ELSE-END IF, SELECT CASE (switch/case equivalent), DO loops (for loops), and DO WHILE loops. These constructs can be labeled for use with CYCLE and EXIT in nested loops.
Arrays are Fortran’s most powerful feature. Unlike C/C++, Fortran treats arrays as first-class objects — add, multiply, or compare entire arrays with single operations, slice them cleanly, reshape, and allocate dynamically. Array indices start at 1 by default, though custom lower/upper bounds can be set — invaluable when modelling Cartesian coordinates where negative indices are meaningful.
sum(arr) — Sum of all elements · product(arr) — Product · maxval(arr) / minval(arr) — Max/Min value · size(arr) — Total elements · shape(arr) — Dimensions array · rank(arr) — Number of dimensions · reshape(arr,[r,c]) — Reshape · transpose(m) — Transpose · matmul(A,B) — Matrix multiply · dot_product(A,B) — Dot product
Fortran distinguishes functions (return a single value) from subroutines (return multiple values through output arguments). Both are defined after the contains keyword. The intent(in), intent(out), and intent(inout) attributes enforce data-flow direction, preventing accidental modification of inputs.
Fortran supports type-safe pointers through the pointer attribute. A pointer can alias a target variable or point to heap memory. The target attribute must be on any variable a pointer can point to. Use => for association and nullify to disassociate.
Fortran has excellent built-in file I/O using OPEN, READ, WRITE, and CLOSE. Each file needs a unique unit number (positive integer above 9). Status options: new, old, replace, scratch, unknown.
Since Fortran 2003 the language supports full OOP through derived types with type-bound procedures, type extension (inheritance), abstract types, and deferred bindings for polymorphism. The percent sign % is the member accessor (equivalent to . in C++ or Python).
The DO CONCURRENT construct (Fortran 2008+) allows the compiler to automatically parallelize or vectorize loop iterations — enabling SIMD, multi-core, or GPU execution with no external libraries. For distributed-memory HPC, Fortran programs use OpenMP and MPI via standard library bindings.
The most widely used free Fortran compiler is GFortran, part of the GNU Compiler Collection (GCC). It is available on all platforms, completely free and open-source, and supports Fortran 77 through Fortran 2018 with partial Fortran 2023 support. Commercial options include Intel Fortran Compiler (ifx/ifort) and NVIDIA HPC SDK for GPU computing.
Method 1 — MSYS2 (Recommended)
Download from msys2.org, open MSYS2 MINGW64 terminal:
Method 2 — WSL2 (Ubuntu inside Windows):
Method 1 — Homebrew (Easiest, Recommended):
Method 2 — MacPorts:
sudo xattr -rd com.apple.quarantine /usr/local/gfortran64-bit installation:
32-bit on 64-bit Ubuntu:
Fedora / RHEL 8+ / Rocky Linux:
module load GCC/12.3.0 then gfortran --versionpacman -Si gcc-fortranStep 1: Install Termux from F-Droid (NOT Play Store): f-droid.org/packages/com.termux
Step 2: Update & install GFortran:
sudo ln -s /usr/local/bin/gfortran13 /usr/local/bin/gfortranCompiling a Fortran program transforms source code into a machine-executable binary. Understanding compiler flags gives you control over optimization levels, debugging, 32/64-bit targeting, and linking to external libraries.
| Flag | Purpose | When to Use |
|---|---|---|
| -O0 | No optimization | Debugging only |
| -O2 | Recommended optimization | Most programs |
| -O3 | Aggressive optimization | Production scientific code |
| -g | Debug symbols | GDB debugging sessions |
| -Wall | All warnings | Always during development |
| -m32 | Compile for 32-bit | Legacy or embedded targets |
| -m64 | Compile for 64-bit | Default on modern systems |
| -fopenmp | Enable OpenMP | Shared-memory parallelism |
| -llapack -lblas | Link math libraries | Linear algebra programs |
| -std=f2018 | Enforce Fortran 2018 | Portability / compliance |
After nearly seven decades of real-world deployment at the highest levels of scientific computing, Fortran has well-established strengths and weaknesses. Understanding both is essential before choosing it for your project.
- Exceptional numerical performance — GFortran with -O3 routinely matches or exceeds C and C++ in scientific benchmarks thanks to decades of compiler optimization research specifically targeting numerical patterns.
- Native array syntax — whole-array operations, matrix addition, slicing, and reshaping are built into the language without any imports, producing highly optimized SIMD machine code automatically.
- Complex number support built in — no workarounds needed for electrical engineering, quantum mechanics, signal processing, and fluid dynamics where imaginary arithmetic is routine.
- Built-in parallelism with DO CONCURRENT — enables multi-core and SIMD execution without any external threading libraries by simply declaring loop iterations as independent.
- Massive proven scientific library ecosystem — BLAS, LAPACK, FFTPACK, and NETLIB represent billions of hours of numerical testing. These are the gold standard for numerical computing worldwide and are used under the hood by NumPy, MATLAB, and R.
- Clean readable syntax — no semicolons, meaningful block-closing keywords (end do, end if, end program), required variable declarations; easy to read even for non-programmers.
- Strong static typing with IMPLICIT NONE — catches type errors at compile time, critical for mission-critical simulations where runtime errors can invalidate entire research projects.
- Column-major array storage — aligns naturally with mathematical conventions and enables cache-efficient numerical algorithms.
- World-class compiler support — GFortran (free), Intel Fortran, Cray Fortran, NVIDIA HPC SDK (PGI) provide best-in-class optimization for every major platform.
- Seamless GDB integration — Fortran programs compile with standard debug symbols and work perfectly with GDB, Valgrind, and all standard debugging tools.
- C interoperability via ISO_C_BINDING — call any C function and share data structures, giving access to every Unix system call and third-party C library.
- Runs everywhere — Windows, macOS, Linux, BSD, Android (Termux), embedded systems, and the world’s fastest supercomputers, all from the same source code.
- Full OOP since 2003 — type extension, polymorphism, abstract interfaces, and type-bound procedures make large-scale Fortran software architecturally sound.
- Active development — Fortran 2023 recently finalized, GFortran development continues, fortran-lang.org community maintains newsletters, FPM package manager, and active discourse.
- Strong job market in niche domains — weather forecasting, climate modeling, aerospace, defense, nuclear physics, and computational chemistry all have significant Fortran codebases and real job postings.
- Steep learning curve for modern software engineers — 1-based arrays, column-major order, IMPLICIT NONE, INTENT attributes, and fixed-format legacy code feel alien to developers from Python, JavaScript, or Java backgrounds.
- Limited standard library for general-purpose tasks — Fortran’s intrinsic library is world-class for math but thin for JSON/XML, networking, HTTP, GUI, and database connectivity.
- Small general-purpose package ecosystem — FPM helps but the package count is tiny compared to Python’s PyPI or Node’s npm.
- Legacy code burden — much production Fortran is FORTRAN 77 style (fixed-format, all-caps, 6-character variable names) and is difficult to refactor or understand without historical context.
- Case insensitivity can hide bugs — variables named TEMP and temp are treated identically, causing unexpected aliasing in mixed-case codebases.
- Poor GUI and web support — building web servers, REST APIs, or desktop applications in Fortran is technically possible but deeply impractical. Python, Go, or Rust are far better choices.
- Verbose OOP compared to Python or Ruby — type extension, CONTAINS blocks, explicit INTENT declarations, and module management make Fortran OOP considerably more wordy than modern languages.
- Compilation required for every change — unlike Python or MATLAB you cannot run code interactively line-by-line, slowing exploratory data analysis and rapid prototyping.
- Smaller community than Python or JavaScript — fewer Stack Overflow answers, fewer beginner-friendly tutorials, and less Google-able error messages compared to mainstream languages.
- Implicit typing trap without IMPLICIT NONE — beginners who forget it will encounter baffling silent bugs where mistyped variable names create new unintended variables instead of compile errors.
- No multi-return values from functions — unlike Python tuples, Fortran functions return one value. Multiple outputs require subroutines with INTENT(OUT) arguments, which is less intuitive.
- Weaker string handling — fixed-length character arrays, manual TRIM operations, and limited string manipulation intrinsics make text processing much more cumbersome than Python.
Choosing the right language for scientific computing depends on your performance needs, productivity priorities, existing ecosystem, and domain conventions. Here is a detailed comparison of Fortran against the three most common alternatives encountered in scientific and engineering computing in 2026.
| Feature | Fortran | Python (NumPy) | C++ | MATLAB |
|---|---|---|---|---|
| Raw Numerical Performance | ★★★★★ Fastest | ★★★ With NumPy | ★★★★★ Comparable | ★★★ Vectorized |
| Ease of Learning | Moderate | Very Easy | Difficult | Easy |
| Native Array Syntax | Built-in | Via NumPy | Manual / Eigen | Built-in |
| Complex Numbers | Native type | Via cmath/NumPy | std::complex<> | Native |
| Built-in Parallelism | DO CONCURRENT + MPI/OpenMP | multiprocessing, Dask | OpenMP / TBB / MPI | Parallel Toolbox |
| Static Typing | Yes — strongly typed | Dynamic (hints optional) | Yes | Dynamic |
| Memory Management | Manual ALLOCATE/DEALLOCATE | Automatic GC | Manual / RAII | Automatic |
| Scientific Libraries | BLAS, LAPACK (gold standard) | NumPy, SciPy, Matplotlib | Eigen, FFTW, Armadillo | Toolboxes |
| General Package Ecosystem | Limited | Massive (PyPI) | Large | MATLAB only |
| License Cost | Free (GFortran) | Free (Open Source) | Free (GCC/Clang) | Expensive license |
| OOP Support | Since 2003 (verbose) | Yes — clean | Yes — full | Limited |
| HPC / Supercomputer Use | Dominant | Growing | Common | Limited |
| Interactive / REPL | No | Yes — Jupyter, IPython | No | Yes |
| TIOBE Rank (2026) | ~Top 15 | Top 3 | Top 5 | ~Top 20 |
Choose Fortran when your problem is numerically intensive and performance is critical, when you are extending an existing Fortran scientific codebase, when your target is an HPC cluster, or when you work in atmospheric science, climate modeling, computational physics, quantum chemistry, or aerospace engineering where Fortran is the domain standard.
Fortran’s real-world impact is staggering. The following domains and projects show where it genuinely excels and continues to be actively written and maintained in 2026 — not legacy systems, but active development on some of the most important software in human history.
| Domain | Notable Projects / Systems | Why Fortran |
|---|---|---|
| Climate Modeling | NCAR CESM, GFDL CM4, UK Met Office Unified Model | Billions of floating-point ops per timestep demand maximum numerical performance |
| Weather Prediction | ECMWF IFS, NOAA GFS, WRF (Weather Research & Forecasting) | Real-time forecasting on massive HPC clusters — Fortran + MPI is the standard |
| Computational Physics | VASP (quantum chemistry), LAMMPS, NAMD | Molecular dynamics and quantum simulations require extreme numerical precision |
| Linear Algebra | BLAS, LAPACK, ScaLAPACK | The world’s standard numerical linear algebra libraries — still Fortran at their core, used by NumPy, MATLAB, and R |
| Aerospace | NASA NASTRAN, FLUENT, OVERFLOW CFD solver | Computational fluid dynamics and structural analysis demand peak floating-point throughput |
| Nuclear Engineering | MCNP, RELAP, SCALE | Particle transport simulations need extreme performance and decades of validated results |
| Seismology | SPECFEM3D, OpenSWPC | 3D wave propagation models running on HPC clusters |
| Financial Computing | Risk management systems at major banks | Huge legacy quantitative finance Fortran codebases still in production |
| Supercomputing | Top 500 supercomputers including Frontier (ORNL) | Fortran applications run on the world’s fastest computers using millions of CPU cores |
A critical insight: when Python’s NumPy calls numpy.linalg.solve(), it ultimately calls highly optimized Fortran (BLAS/LAPACK) under the hood. In this sense, almost every scientist already uses Fortran without knowing it.
The Fortran community in 2026 is active, welcoming, and genuinely modern. Here are the best resources for getting started and advancing your skills.
| Resource Type | Name / URL | Description |
|---|---|---|
| Official Website | fortran-lang.org | Modern community site with tutorials, package index, news, and best practices |
| Package Manager | fpm.fortran-lang.org | Fortran Package Manager (FPM) — modern dependency management |
| Online Playground | play.fortran-lang.org | Browser-based Fortran IDE — no installation needed |
| Compiler Explorer | godbolt.org | Compile and inspect assembly from GFortran, Intel Fortran, and others |
| Compiler Docs | gcc.gnu.org/onlinedocs/gfortran | Complete official GFortran documentation including all flags and extensions |
| Language Reference | fortranwiki.org | Comprehensive Fortran language reference wiki with examples |
| Community Forum | fortran-lang.discourse.group | Active Q&A forum — very welcoming to beginners |
| Standards Committee | j3-fortran.org | Official J3 Fortran standards committee — tracks proposals and approved features |
| Numerical Libraries | netlib.org | Repository of classic Fortran scientific libraries: BLAS, LAPACK, FFTPACK |
| IDE Extension | VS Code + Modern Fortran extension | Syntax highlighting, IntelliSense, and integrated GFortran compilation |
| Language Server | pip install fortls | Fortran Language Server — works with VS Code, Vim, Emacs |
| HPC Training | hprc.tamu.edu/training | Free HPC training including Fortran courses with hands-on cluster access |
| Newsletter | fortran-lang.org/newsletter | Monthly community updates on language developments, packages, and events |
Absolutely. Fortran consistently ranks in the top 15 languages by usage. It dominates weather forecasting, climate modeling, computational physics, and aerospace. The top 500 supercomputers run Fortran workloads daily. BLAS and LAPACK — numerical libraries powering NumPy, MATLAB, and R — are written in Fortran. The language receives active standards development, with Fortran 2023 recently finalized.
Fortran is not typically recommended as a first language for general software development. However, if you are studying mechanical engineering, atmospheric science, computational physics, or similar disciplines, learning Fortran first makes excellent sense — it is likely what you will encounter professionally, and its clean syntax and strict typing teach excellent programming discipline.
Without IMPLICIT NONE, Fortran automatically types any variable beginning with letters I through N as INTEGER and all others as REAL. A typo creating TEMPRAURE instead of TEMPERATURE silently creates a new variable rather than throwing an error — a catastrophic source of bugs in scientific code. IMPLICIT NONE forces explicit declaration of every variable, catching typos at compile time. Always use it.
FORTRAN 77 used fixed-format source code (code had to begin at column 7), all uppercase, no dynamic arrays, no modules, and no recursion. Fortran 90 introduced free-format source, allocatable arrays, modules, recursion, array operations, and modern control structures. FORTRAN 77-style code is considered legacy — all new Fortran should be written in Fortran 90 or later style using .f90 files.
Yes. Using Termux on Android (installed from F-Droid, not the Play Store), install GFortran with pkg install gcc-fortran and compile/run full Fortran programs on your phone or tablet. Works on both ARM64 (64-bit) and ARMv7 (32-bit) Android devices without root access. Verify your architecture with uname -m.
Fortran is consistently 10x–100x faster than pure Python for numerical computations. Compared to C++, Fortran performance is essentially equivalent for most numerical workloads and sometimes surpasses C++ because Fortran’s assumption of no pointer aliasing allows more aggressive compiler optimizations. For array operations, Fortran’s native syntax can generate better SIMD code than C++ with std::vector.
Functions return a single value and are called inline in expressions: result = square(x). Subroutines do not return a value through the function mechanism — they are called with the CALL keyword and communicate results via INTENT(OUT) arguments: call compute(x, y, result). Use functions for one output; use subroutines for multiple outputs or when modifying input data in place.
Use .f90 for all modern Fortran code (Fortran 90, 95, 2003, 2008, 2018, 2023). The extension does not lock you to Fortran 90 — it tells the compiler to use free-format source. Legacy .f and .for extensions indicate fixed-format FORTRAN 77 style. Specific version extensions (.f95, .f03, .f08) are also valid. When in doubt use .f90.
0 Comments