Skip to content
Tutorials Center
My learning

Topics

Fortran Tutorial

Learn Fortran step by step: 39 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Fortran? Meet Fortran, the oldest high-level language still used for weather models, physics and supercomputers. Learn its history, standards, strengths and what you will build.
  2. 2 Installing a Fortran Compiler Install gfortran on Windows, macOS or Linux, compile and run a Fortran program from the command line, and learn the most useful compiler flags for beginners.
  3. 3 Your First Fortran Program Write and understand your first Fortran program: program, implicit none, declarations, assignments, print and write, comments, and a simple area calculator.
  4. 4 Program Structure and Source Form Understand how a Fortran program is organized: specification and execution parts, program units, naming rules, free-form vs fixed-form source, and good style.

Language Basics

  1. 5 Variables and Data Types Learn Fortran's five intrinsic types integer, real, complex, logical and character, how to declare variables and constants with parameter, and how to initialize them.
  2. 6 Kinds and Precision Control the size and precision of Fortran numbers with kind parameters: selected_real_kind, selected_int_kind, iso_fortran_env, double precision and literal suffixes.
  3. 7 Operators and Expressions Learn Fortran's arithmetic, relational, logical and character operators, precedence rules, integer division, exponentiation and mixed-type expressions with examples.
  4. 8 Characters and Strings Work with text in Fortran: fixed-length character variables, substrings, concatenation, trim, len_trim, index, adjustl, comparisons and allocatable deferred-length strings.
  5. 9 Reading and Writing Basics Learn Fortran print, write and read statements, list-directed output, format descriptors I, F, ES, A and X, line control with slash, advance=no and reading numbers from the keyboard.

Control Flow

  1. 10 The if Statement and Logical Expressions Make decisions in Fortran with the single-line if, if-then-else blocks, else if chains, nested ifs, logical operators and safe comparisons of real numbers.
  2. 11 The select case Statement Use Fortran's select case to choose between many alternatives: single values, lists, ranges, case default, character selectors, and why there is no fall-through.
  3. 12 do Loops Repeat work in Fortran with counted do loops, steps and countdowns, do while, endless do with exit, nested loops, the trip count rule and implied do loops for printing.
  4. 13 exit, cycle and Named Constructs Control loops precisely in Fortran: exit and cycle, naming constructs to leave outer loops, the block construct, stop and error stop, and an introduction to do concurrent.

Arrays and Numerics

  1. 14 Arrays: The Basics Learn Fortran arrays from scratch: declaring 1D and 2D arrays, custom lower bounds, array constructors, implied do loops, column-major storage, size, shape and reshape.
  2. 15 Array Sections and Whole-Array Operations Slice Fortran arrays with start:end:stride sections, operate on whole arrays without loops, use elemental functions, row and column sections of matrices and vector subscripts.
  3. 16 Array Intrinsic Functions Master Fortran's array intrinsic functions: sum, product, maxval, minloc, count, any, all, dot_product, matmul, transpose, pack, spread, cshift and the dim and mask arguments.
  4. 17 where and Masking Apply operations only to selected array elements with where, elsewhere, masked assignment, merge, pack and unpack, and learn why forall gave way to do concurrent.
  5. 18 Allocatable Arrays Create arrays whose size is chosen at run time with Fortran allocatable arrays: allocate, deallocate, allocated, stat, automatic reallocation on assignment, source, mold and move_alloc.
  6. 19 Numeric Intrinsics and Floating-Point Behavior Use Fortran's math intrinsics sqrt, exp, log, sin, atan2, hypot, mod, nint and complex functions, and understand rounding, NaN, Infinity, epsilon and ieee_arithmetic.

Procedures and Modules

  1. 20 Subroutines and Functions in Fortran Learn how Fortran splits work into functions and subroutines: the result clause, call statements, internal procedures, and how arguments are passed by reference.
  2. 21 Argument Intent, Optional and Keyword Arguments Use intent(in), intent(out) and intent(inout), optional arguments with present(), and keyword calls to write safe, self-documenting Fortran procedures.
  3. 22 Fortran Modules and the use Statement Organize Fortran code with modules: share constants, variables and procedures, control visibility with private and public, rename with use, and compile in order.
  4. 23 Interfaces, Generic Procedures and Operator Overloading Use interface blocks to write generic procedures that accept several types, overload operators, pass procedures as arguments, and describe external code.
  5. 24 Recursion, Pure and Elemental Procedures Write recursive Fortran procedures with the recursive keyword and result clause, and use pure and elemental to make side-effect-free, array-friendly functions.

Derived Types and Pointers

  1. 25 Derived Types in Fortran Group related data with Fortran derived types: define types, build constructors, access components with %, use default values, nest types and keep arrays of structures.
  2. 26 Fortran Pointers, Targets and Allocatables Understand Fortran pointers and the target attribute, pointer assignment with =>, associated(), allocatable arrays versus pointers, and build a linked list safely.
  3. 27 Type-Bound Procedures and Object-Oriented Fortran Attach procedures to derived types with the contains section, call them with the object%method syntax, use passed-object dummies, constructors and final procedures.
  4. 28 Inheritance, Polymorphism and Abstract Types Extend derived types with extends, override type-bound procedures, write abstract types with deferred procedures, and use class(*), select type and polymorphic arrays.

File I/O and Formatting

  1. 29 Formatted Output and Edit Descriptors in Fortran Control Fortran output with format specifiers: I, F, E, ES, A, L, X and slash descriptors, repeat counts, reversion, internal writes and tidy tables of numbers.
  2. 30 Reading and Writing Files in Fortran Work with files in Fortran: open and close units, newunit, status and action, read until end of file with iostat, check errors, rewind, inquire and use scratch files.
  3. 31 Namelists, Stream Access and Unformatted Files Read configuration with Fortran namelists, write fast unformatted binary files, use direct and stream access, and exchange data safely between programs.

Parallel and Scientific Computing

  1. 32 do concurrent, Array Operations and Vectorization Write fast, parallel-friendly Fortran: whole-array syntax, where and forall masks, do concurrent loops with locality, memory layout, and vectorization.
  2. 33 OpenMP Shared-Memory Parallelism in Fortran Parallelize Fortran loops with OpenMP directives: parallel do, private and shared, reduction, critical, atomic, schedule, collapse, and data race pitfalls.
  3. 34 Coarrays: Parallel Programming Built into Fortran Learn Fortran coarrays: images, this_image and num_images, the [ ] cosubscript, sync all, collective subroutines co_sum, critical sections, and compiling with OpenCoarrays.
  4. 35 Fortran and C Interoperability with iso_c_binding Call C from Fortran and Fortran from C with iso_c_binding: bind(c), c_int and c_double kinds, value arguments, C strings, arrays, structs and callbacks.

Projects and Practice

  1. 36 Project: A Statistics Module Build a reusable Fortran statistics module with mean, variance, standard deviation, median, correlation and histogram, then test it against known values.
  2. 37 Project: 1D Heat Diffusion Simulation Simulate heat flow along a rod in Fortran with an explicit finite-difference scheme: array slices, stability limit, boundary conditions, output files and plotting.
  3. 38 Project: A Linear System Solver Write a linear equation solver in Fortran: Gaussian elimination with partial pivoting, matmul checks, residuals, singular matrices, and comparison with LAPACK dgesv.
  4. 39 Fortran Practice Problems with Solutions Ten Fortran exercises on procedures, modules, derived types, file I/O and numerical methods, each with hints, a full solution and a runnable Python check.