Fortran is a programming language that is used heavily in groundwater flow and contaminant transport numerical modeling.

To get started with Fortran, you will need a compiler, a text editor, and a shell; I suggest gfortran (compiler) and notepad++ (text editor), both are free, and detailed information on how to set up your operating system (Windows/Mac/Linux) can be found here https://fortran-lang.org/en/learn/os_setup/. For a shell, I use the command prompt on my Windows 10 operating system.

The typical order for running Fortran, for me, is as follows:

1) write code in notepad++ (gobucks)

2) compile code using gfortran via the command prompt {gfortran gobucks.f95 -o gobucks}, 3) execute code via the command prompt {gobucks}, and 4) write results to a text file via the command prompt {gobucks>C:\Users\wendy\fortran\gobucks.txt}

5) view results in a text file

In an effort to teach Fortran for groundwater modeling, I have updated pre-Fortran 90/95 code from Wang and Anderson (1982) to Fortran 90/95 in the .txt files below; many of the pre-Fortran 90/95 statements in Wang and Anderson are obsolescent or deleted, but the fundamentals of the code remain highly relevant today. To run the .txt files below, you must first save them as .f95 files, then compile and execute them; you can also write their results back to a .txt file.

Note 1: I have included original code for relatively simple examples of groundwater flow and solute transport.

Note 2: I have included original code for input files for MODFLOW-2005.

**Updated code from Wang and Anderson (1982)**

- Fig. 2.7 (finite difference solution for steady-state flow in two dimensions with constant head boundaries using Gauss-Seidel iteration, see pre-Fortran 90/95 code in Figure 2.7 from W&A, 1982)
- Fig. 2.7 nogoto (same as above but without “go to” statement, plus some extra analyses for more insight)
- Fig. 2.10 (finite difference solution for steady-state flow in two dimensions with constant head boundary at top and no flow boundaries at left, right, and bottom using Gauss-Seidel iteration, see pre-Fortran 90/95 code in Figure 2.10 from W&A, 1982)
- Fig. 2.10 nogoto (same as above but without “go to” statement, plus some extra analyses for more insight)
- Fig. 3.5 nogoto (finite difference solution for steady-state flow to a pumping well in two dimensions with constant head/radial boundary at top and right and no flow/symmetry boundaries at bottom and left using Gauss-Seidel iteration with successive over relation, see pre-Fortran 90/95 code in Figure 3.5 from W&A, 1982)
- Fig. 3.10 nogoto (finite difference solution for steady-state flow in two dimensions with constant head boundaries at left and right and no flow/symmetry boundaries at top and bottom for unconfined flow using Gauss-Seidel iteration with successive over relation, see pre-Fortran 90/95 code in Figure 3.10 from W&A, 1982)
- Fig. 4.2 nogoto (finite difference solution for transient flow in one dimension with constant head boundary at left/input and instantaneous change in head at right/output using fully explicit scheme, see pre-Fortran 90/95 code in Figure 4.2 from W&A, 1982)
- Fig. 4.6 nogoto (finite difference solution for transient flow to a pumping well in two dimensions with no flow boundaries at top, bottom, left, and right using implicit (Crank-Nicolson) scheme, see pre-Fortran 90/95 code in Figure 4.6 from W&A, 1982)

**Original code for groundwater flow and solute transport**

- 1D SS SpecHead (finite difference solution for steady-state flow in one dimension with specified head (Dirichlet) boundaries at inlet and outlet using Gauss-Seidel iteration for the following cases: 1) homogeneous, high K, high q, 2) homogeneous low K, low q, 3) heterogeneous, low to high K , and 4) heterogeneous, high to low K), note that the code uses the arithmetic, as opposed to the harmonic, inter-cell/nodal mean of the hydraulic conductivity)
- 1D SS SpecFlow (finite difference solution for steady-state flow in one dimension with specified flow (Neumann) boundaries at inlet and outlet using Gauss-Seidel iteration for the following cases: 1) homogeneous, high K, low dh, 2) homogeneous low K, high dh, 3) heterogeneous, low to high K , and 4) heterogeneous, high to low K), note that the code uses the arithmetic, as opposed to the harmonic, inter-cell/nodal mean of the hydraulic conductivity)
- 1D TR RXN (finite difference solution for solute transport (advection, dispersion, first-order decay, and linear equilibrium sorption) in one dimension with specified concentration (Dirichlet) boundary at inlet and specified concentration flux (Neumann) at outlet using explicit forward-difference scheme for five different cases of dispersion, decay, and sorption, plus a standard base case, so 16 simulations total)
- More code on the way for transient flow and solute transport, stay tuned!

**Original code for input files for MODFLOW-2005**

- The .txt files below can be saved as their labeled extensions and run on MODFLOW-2005 but you’ll have to make your own Name File (.nam); these are relatively easy to make by hand in notepad. The .txt files can also be saved as .f95 files and you can change the inputs however you want to run your own custom flow model. Finally, the .txt files below run the same flow simulations as the 1dssflow file does above; this allows you to compare hand-written finite difference code to the gold standard code of the USGS 🙂