Fortran Numerical Weather Prediction Models
High-performance computational models for operational-scale atmospheric simulation
Why Fortran for Numerical Weather Prediction?
Despite being one of the oldest programming languages, Fortran (FORmula TRANslation) remains the dominant language for operational numerical weather prediction (NWP) and climate modeling. Major centers like ECMWF, NCEP, UK Met Office, and Mรฉtรฉo-France all use Fortran for their core models.
๐ Performance
Fortran compilers produce highly optimized machine code. 5-20% faster than C/C++ for array-heavy numerical computations. Critical when running on supercomputers.
๐ Array Operations
Native multi-dimensional array syntax. Whole-array operations, slicing, and intrinsic functions designed for scientific computing from the ground up.
โก Parallelization
Excellent support for OpenMP (shared memory) and MPI (distributed memory) parallelism. Modern Fortran includes coarrays for parallel programming.
๐๏ธ Legacy & Stability
Decades of optimized numerical libraries (BLAS, LAPACK, FFTW). Proven algorithms refined over 60+ years of scientific computing.
Real-World Usage
WRF (Weather Research and Forecasting), MPAS (Model for Prediction Across Scales), CAM (Community Atmosphere Model), and the ECMWF IFS are all written primarily in Fortran 90/95/2003/2008.
Setup Instructions
1. Install Fortran Compiler
We recommend gfortran (GNU Fortran compiler), which is free, open-source, and supports modern Fortran standards (2003, 2008, 2018).
sudo apt-get install gfortran
# Or use Windows Subsystem for Linux (WSL)
2. Verify Installation
3. Basic Compilation
Standard compilation command structure:
1Primitive Equations Model (3D)
Scientific Background
This model solves the full 3D primitive equations โ the fundamental equations governing atmospheric motion. It's based on the approach used in WRF (Weather Research and Forecasting Model), the most widely-used mesoscale NWP model globally.
Governing Equations
In pressure coordinates (p), the primitive equations are:
Model Features
Grid Configuration
- 64ร64 horizontal grid points
- 20 vertical levels (ฯ-coordinates)
- Arakawa C-grid (staggered)
- 2000 km ร 2000 km domain
Numerical Methods
- 3rd-order Runge-Kutta time integration
- Centered finite differences (space)
- Semi-implicit scheme for stability
- 60-second time step
Physics Parameterizations
- Planetary boundary layer (YSU scheme)
- Radiation (simplified LW/SW)
- Microphysics (Kessler warm rain)
- Surface fluxes (Monin-Obukhov)
Initial Conditions
- Baroclinic wave perturbation
- Midlatitude jet stream
- Realistic temperature profile
- Water vapor distribution
Compilation Instructions
How to Run
Expected Output
The model will:
- Print domain configuration (grid size, spacing, time step)
- Display initialization information
- Output diagnostics every 20 time steps showing:
- Integration time (hours)
- Maximum wind speeds (u, v components)
- Temperature range and extremes
- Energy conservation metrics
- Confirm successful completion with total integration time
Runtime: Approximately 1-5 minutes on a modern CPU (depends on optimization level). With parallelization, can be reduced to under 1 minute.
๐ Output Files (if implemented)
Full versions would write netCDF or binary output files containing 3D fields of u, v, w, temperature, pressure, geopotential at each output time. These can be visualized with tools like NCL, Python (xarray), or VAPOR.
2Shallow Water Equations Model (2D)
Scientific Background
The shallow water equations are a simplified set of equations describing fluid motion in a thin layer. Despite their simplicity, they capture many essential atmospheric phenomena and are widely used for testing numerical methods, studying atmospheric waves, and teaching NWP fundamentals.
The Equations
On an f-plane (constant latitude), the shallow water equations are:
Atmospheric Phenomena Captured
Geostrophic Adjustment
How an initially imbalanced flow adjusts to geostrophic equilibrium through emission of inertia-gravity waves
Rossby Waves
Planetary-scale waves fundamental to weather patterns. Responsible for meandering jet stream and blocking patterns.
Kelvin Waves
Coastally-trapped waves important in equatorial dynamics and tropical meteorology
Inertia-Gravity Waves
Fast waves that adjust pressure and velocity fields. Important for numerical stability considerations.
Model Configuration
- 128 ร 128 horizontal points
- 1000 km ร 1000 km domain
- ~7.8 km grid spacing
- Leapfrog time integration
- Centered finite differences
- 60-second time step
- Periodic boundary conditions
- ฮฒ-plane approximation (f = fโ + ฮฒy)
- Mean depth Hโ = 1000 m
- fโ = 10โปโด sโปยน (mid-latitude)
- Geostrophically balanced vortex
- Gaussian height anomaly
- 100 m amplitude, 100 km radius
Compilation Instructions
How to Run
Expected Output
The model outputs:
- Header: Grid size, domain dimensions, time step, integration length
- Progress updates every 100 time steps (every ~1.7 hours) showing:
- Current time (hours)
- Total energy (kinetic + potential) [conserved quantity]
- Total enstrophy (potential vorticity squared) [conserved quantity]
- Maximum height deviation from mean
- Summary: List of output fields that would be written (u, v, h, vorticity, divergence)
Runtime: Under 1 minute on modern hardware.
๐ฌ What to Observe
Energy Conservation: Total energy should remain nearly constant (variations < 0.1%). Large deviations indicate numerical instability.
Vortex Evolution: The initial vortex will evolve, possibly spawning Rossby waves that propagate westward (negative phase speed).
Enstrophy: Should also be approximately conserved in inviscid flow.
Performance Tips & Optimization
๐ Compiler Optimization Flags
These flags can provide 2-5ร speedup compared to unoptimized code.
โก Parallelization with OpenMP
Add OpenMP directives to parallelize loops across multiple CPU cores:
Compile with: -fopenmp
๐ฏ Array Layout Optimization
Fortran stores arrays in column-major order. For optimal cache performance, access arrays with the first index varying fastest in innermost loops:
๐ Profiling Your Code
Use gprof to identify performance bottlenecks:
๐ Distributed Memory: MPI
For very large domains or operational-scale models, use MPI (Message Passing Interface) to distribute the computation across multiple compute nodes. This requires domain decomposition and explicit message passing between processes. Libraries like MPI-Fortran make this feasible.
Advanced Topics & Extensions
๐ Modifying the Models
Once you understand the basics, try these extensions:
- Add output to netCDF files using netCDF-Fortran library
- Implement different initial conditions (tropical cyclone, mountain wave)
- Add topography to the shallow water model
- Implement different numerical schemes (semi-Lagrangian, spectral methods)
- Add tracer transport (passive scalar advection)
๐ฌ Testing Numerical Methods
These models are excellent testbeds for:
- Comparing explicit vs. implicit time integration schemes
- Testing conservation properties of different advection schemes
- Evaluating numerical dispersion and diffusion
- Studying CFL stability conditions
๐ Further Reading
- Durran (2010): Numerical Methods for Fluid Dynamics โ comprehensive treatment
- Lauritzen et al.: Numerical Techniques for Global Atmospheric Models
- Kalnay (2003): Atmospheric Modeling, Data Assimilation and Predictability
- WRF Documentation: Technical notes on operational NWP implementation
๐ Learning Path
- Start with shallow water model (simpler, 2D, illustrates key concepts)
- Understand the primitive equations derivation (see Part II of course)
- Study the primitive equations model implementation
- Experiment with different parameters, initial conditions
- Implement extensions and additional physics
- Progress to full-scale community models (WRF, MPAS)
Additional Resources
Community NWP Models (Fortran-based):
- WRF: Weather Research and Forecasting Model โ most widely used mesoscale model
- MPAS: Model for Prediction Across Scales โ unstructured mesh, variable resolution
- CAM: Community Atmosphere Model โ climate modeling
- COSMO: Consortium for Small-scale Modeling
Online Tutorials:
- Modern Fortran tutorial: fortran-lang.org
- WRF online tutorial and documentation
- NCAR CESM tutorial (climate modeling)
Computing Resources:
- XSEDE (academic supercomputing access in the US)
- Cloud computing (AWS, Google Cloud) with HPC instances
- University cluster computing facilities